VERIFIED FIXED 5514
Date conversion to local time gets the DST flag wrong for some dates
https://bugs.webkit.org/show_bug.cgi?id=5514
Summary Date conversion to local time gets the DST flag wrong for some dates
mitz
Reported 2005-10-26 09:58:55 PDT
For dates before 1970-01-01 00:00 UTC, conversion to local time takes the DST flag from the same day in a different year. This leads to incorrect results in many cases, since DST cutoff dates are not the same every year. The test case demonstrates this for several time zones: now that bug 4142 is fixed, "new Date(y,m,d)" works as expected, but the conversion back to local time is wrong due to using DST status from the same date in 2002. Since the fix for bug 4142 involves passing negative and large positive values to localtime_r(), I'm not sure why the same isn't done in DateProtoFuncImp::callAsFunction().
Attachments
Testcase (1.07 KB, text/html)
2005-10-26 10:00 PDT, mitz
no flags
Apply the realYearOffset hack only when absolutely necessary (1.35 KB, patch)
2005-10-28 03:08 PDT, mitz
darin: review-
Apply the realYearOffset hack only when absolutely necessary (1.50 KB, patch)
2005-10-28 13:49 PDT, mitz
no flags
Better patch (1.47 KB, patch)
2005-10-29 01:46 PDT, mitz
ggaren: review+
mitz
Comment 1 2005-10-26 10:00:03 PDT
Created attachment 4484 [details] Testcase
Geoffrey Garen
Comment 2 2005-10-26 14:17:11 PDT
Mitz mentioned on IRC that eliminating the yearOffset hack fixes this bug. But that would make the code slightly less portable.
mitz
Comment 3 2005-10-28 03:08:25 PDT
Created attachment 4506 [details] Apply the realYearOffset hack only when absolutely necessary
mitz
Comment 4 2005-10-28 03:11:03 PDT
Comment on attachment 4506 [details] Apply the realYearOffset hack only when absolutely necessary Haven't tested it on any platform other than PPC OS X.
Darin Adler
Comment 5 2005-10-28 10:42:59 PDT
Comment on attachment 4506 [details] Apply the realYearOffset hack only when absolutely necessary This line of code: +const bool time_tIsSigned = isTime_tSigned(); will result in code run at load time. We don't allow that in JavaScriptCore and WebCore. We'll need an alternate approach that does the same thing without a global that requires executing code at library load time.
mitz
Comment 6 2005-10-28 13:49:32 PDT
Created attachment 4510 [details] Apply the realYearOffset hack only when absolutely necessary Initialize time_t limits only the first time they're actually needed.
Geoffrey Garen
Comment 7 2005-10-28 17:25:12 PDT
Here's an idea: static bool isTime_tSigned() { time_t minusOne == -1; return minusOne < 0; }
Geoffrey Garen
Comment 8 2005-10-28 17:26:37 PDT
(In reply to comment #7) s/==/=/
Darin Adler
Comment 9 2005-10-28 18:25:05 PDT
Comment on attachment 4510 [details] Apply the realYearOffset hack only when absolutely necessary Looks good. r=me
mitz
Comment 10 2005-10-29 01:37:00 PDT
(In reply to comment #7) > Here's an idea: > time_t minusOne = -1; Clever! But the above will give a compiler warning if time_t is unsigned. This should work: time_t minusOne = (time_t)(-1);
mitz
Comment 11 2005-10-29 01:46:45 PDT
Created attachment 4517 [details] Better patch
mitz
Comment 12 2005-10-29 01:48:32 PDT
Comment on attachment 4517 [details] Better patch Did as Geoffrey suggested
Note You need to log in before you can comment on or make changes to this bug.