int hours = jsdate.getHours();
if ((hours % 24) != (requestedHours % 24)) {
// Hours passed to the constructor don't match the hours in the created JavaScript Date; this
// might be due either because they are outside 0-24 range, there was overflow from
// minutes:secs:millis or because we are in the situation GAP and has to be fixed.
JsDate copy = JsDate.create(jsdate.getTime());
copy.setDate(copy.getDate() + 1);
int timeDiff = jsdate.getTimezoneOffset() - copy.getTimezoneOffset();
// If the time zone offset is changing, advance the hours and
// minutes from the initially requested time by the change amount
if (timeDiff > 0) {
// The requested time falls into a non-existent time range due to
// local time advancing into daylight savings time. If so, push the requested
// time forward out of the non-existent range.
int timeDiffHours = timeDiff / 60;
int timeDiffMinutes = timeDiff % 60;
int day = jsdate.getDate();
int badHours = jsdate.getHours();
if (badHours + timeDiffHours >= 24) {
day++;
}
JsDate newTime = JsDate.create(jsdate.getFullYear(), jsdate.getMonth(),
day, requestedHours + timeDiffHours, jsdate.getMinutes() + timeDiffMinutes,
jsdate.getSeconds(), jsdate.getMilliseconds());
jsdate.setTime(newTime.getTime());
}
return;
}
// Check for situation OVERLAP by advancing the clock by 1 hour and see if getHours() returns