[Win] 17 different JSC tests started to fail in DST
authorbfulgham@apple.com <bfulgham@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 11 Mar 2015 02:34:04 +0000 (02:34 +0000)
committerbfulgham@apple.com <bfulgham@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 11 Mar 2015 02:34:04 +0000 (02:34 +0000)
https://bugs.webkit.org/show_bug.cgi?id=142531

Reviewed by Chris Dumez.

The stock 'GetTimeZoneInformation' call does not always match the actual Daylight
Savings calendar. This results in a period of time when these tests fail.

If available, we should take advantage of the new 'GetTimeZoneInformationForYear',
which accesses a dynamic calendar of DST dates, which is presumbably updated by
Microsoft from year-to-year.

* wtf/DateMath.cpp:
(WTF::timeZoneInformationForYearFunction): New function to conditionally access
some Vista (and newer) functionality.
(WTF::calculateUTCOffset): Call new function (if available) to calculate proper UTC
time offset.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@181360 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WTF/ChangeLog
Source/WTF/wtf/DateMath.cpp

index dae7205..ef0dcb9 100644 (file)
@@ -1,3 +1,23 @@
+2015-03-10  Brent Fulgham  <bfulgham@apple.com>
+
+        [Win] 17 different JSC tests started to fail in DST
+        https://bugs.webkit.org/show_bug.cgi?id=142531
+
+        Reviewed by Chris Dumez.
+
+        The stock 'GetTimeZoneInformation' call does not always match the actual Daylight
+        Savings calendar. This results in a period of time when these tests fail.
+
+        If available, we should take advantage of the new 'GetTimeZoneInformationForYear',
+        which accesses a dynamic calendar of DST dates, which is presumbably updated by
+        Microsoft from year-to-year.
+
+        * wtf/DateMath.cpp:
+        (WTF::timeZoneInformationForYearFunction): New function to conditionally access
+        some Vista (and newer) functionality.
+        (WTF::calculateUTCOffset): Call new function (if available) to calculate proper UTC
+        time offset.
+
 2015-03-10  Alex Christensen  <achristensen@webkit.org>
 
         Use unsigned for HashSet size.
index 91ab950..ebcecac 100644 (file)
@@ -361,19 +361,52 @@ int equivalentYearForDST(int year)
     return year;
 }
 
+#if OS(WINDOWS)
+typedef BOOL(WINAPI* callGetTimeZoneInformationForYear_t)(USHORT, PDYNAMIC_TIME_ZONE_INFORMATION, LPTIME_ZONE_INFORMATION);
+
+static callGetTimeZoneInformationForYear_t timeZoneInformationForYearFunction()
+{
+    static callGetTimeZoneInformationForYear_t getTimeZoneInformationForYear = nullptr;
+
+    if (getTimeZoneInformationForYear)
+        return getTimeZoneInformationForYear;
+
+    HMODULE module = ::GetModuleHandleW(L"kernel32.dll");
+    if (!module)
+        return nullptr;
+
+    getTimeZoneInformationForYear = reinterpret_cast<callGetTimeZoneInformationForYear_t>(::GetProcAddress(module, "GetTimeZoneInformationForYear"));
+
+    return getTimeZoneInformationForYear;
+}
+#endif
+
 static int32_t calculateUTCOffset()
 {
 #if OS(WINDOWS)
     TIME_ZONE_INFORMATION timeZoneInformation;
-    DWORD rc = ::GetTimeZoneInformation(&timeZoneInformation);
-    if (rc == TIME_ZONE_ID_INVALID)
-        return 0;
+    DWORD rc = 0;
+
+    if (callGetTimeZoneInformationForYear_t timeZoneFunction = timeZoneInformationForYearFunction()) {
+        // If available, use the Windows API call that takes into account the varying DST from
+        // year to year.
+        SYSTEMTIME systemTime;
+        ::GetSystemTime(&systemTime);
+        rc = timeZoneFunction(systemTime.wYear, nullptr, &timeZoneInformation);
+        if (rc == TIME_ZONE_ID_INVALID)
+            return 0;
+    } else {
+        rc = ::GetTimeZoneInformation(&timeZoneInformation);
+        if (rc == TIME_ZONE_ID_INVALID)
+            return 0;
+    }
+
+    int32_t bias = timeZoneInformation.Bias;
 
-    int32_t bias = 0;
     if (rc == TIME_ZONE_ID_DAYLIGHT)
-        bias = timeZoneInformation.Bias + timeZoneInformation.DaylightBias;
+        bias += timeZoneInformation.DaylightBias;
     else if (rc == TIME_ZONE_ID_STANDARD || rc == TIME_ZONE_ID_UNKNOWN)
-        bias = timeZoneInformation.Bias + timeZoneInformation.StandardBias;
+        bias += timeZoneInformation.StandardBias;
 
     return -bias * 60 * 1000;
 #else