Open GoogleCodeExporter opened 9 years ago
Ok, easier way to reproduce the problem.
From above, do
step 1. create the LA timezone.
step 2. create the formatter
**step 3. create a date with this timestamp: 1320562620000
myDate = new Date(1320562620000)
step 4. use formatter to output
Expected output: 11/05/2011 23:57:00:0000 PDT
Actual output: 11/06/2011 23:57:00:0000 PDT
Using the same version of product and linux ubuntu
Original comment by Mike.For...@gmail.com
on 16 Feb 2012 at 2:06
Proposed Solution: Not 100% Sure on this, but I think this will work. Basically
If the hour difference between the original date and the new time does not
equal the expected amount (calculated based upon offsets of date and timezone),
we assume that it is because the day has changed. Thus we add or subtract a day
accordingly. This code is in the goog.i18n.DateTimeFormat.prototype.format
function.
// in daylight time switch on/off hour, diff adjustment could alter time
// because of timeZone offset change, move 1 day forward or backward.
if (opt_timeZone &&
dateForDate.getTimezoneOffset() != date.getTimezoneOffset()) {
dateChange = diff > 0 ? 1 : -1;
diff += diff > 0 ? -24 * 60 * 60000 : 24 * 60 * 60000;
dateForTime = new Date(date.getTime() + diff);
if (Math.abs(date.getHours() - dateForTime.getHours()) !==
Math.abs(opt_timeZone.getOffset(date) - date.getTimezoneOffset()) / 60) {
dateForDate = new Date(date.getTime() + (dateChange * 24 * 60 * 60000));
}
}
Original comment by Mike.For...@gmail.com
on 16 Feb 2012 at 4:18
So that solution doesn't work 100% of the time. A better solution that I think
will work is just adding
dateForDate = new Date(dateForDate.getTime() + (
dateForDate.getTimezoneOffset() -
date.getTimezoneOffset()) * 60000);
instead of the dateChange assignment and if statement. This will update the day
if it changes based on the time update. This is necessary b\c sometimes the
time update switches the date.
Original comment by Mike.For...@gmail.com
on 16 Apr 2012 at 6:39
Original issue reported on code.google.com by
Mike.For...@gmail.com
on 3 Feb 2012 at 8:49