]> git.saurik.com Git - wxWidgets.git/commitdiff
Use current time, not the Epoch for time zone determination.
authorVadim Zeitlin <vadim@wxwidgets.org>
Sun, 6 Nov 2011 12:06:43 +0000 (12:06 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sun, 6 Nov 2011 12:06:43 +0000 (12:06 +0000)
When deducing the time zone from struct tm tm_gmtoff field, query tm for the
current time and not the Epoch as the DST rules -- and hence the time zone
offset -- could have changed since 1970. This is notably the case for Ireland
which used a different time zone from 1968 to 1971.

Notice that GetTimeZone() still must return the time zone without taking DST
into account, so we explicitly compensate for DST if it's in effect.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@69689 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/common/datetime.cpp

index 790de959aa7fd3cbb732593e4fd087167b1edbe7..c08a5c3fc20f4d160a6bda0ffff4480a333d7475 100644 (file)
@@ -342,7 +342,7 @@ int GetTimeZone()
     {
         // just call wxLocaltime_r() instead of figuring out whether this
         // system supports tzset(), _tzset() or something else
-        time_t t = 0;
+        time_t t = time(NULL);
         struct tm tm;
 
         wxLocaltime_r(&t, &tm);
@@ -352,6 +352,12 @@ int GetTimeZone()
         // consistent results in both WX_GMTOFF_IN_TM and !WX_GMTOFF_IN_TM
         // cases we have to negate it
         gmtoffset = -tm.tm_gmtoff;
+
+        // this function is supposed to return the same value whether DST is
+        // enabled or not, so we need to use an additional offset if DST is on
+        // as tm_gmtoff already does include it
+        if ( tm.tm_isdst )
+            gmtoffset += 3600;
     }
     return (int)gmtoffset;
 #elif defined(__DJGPP__) || defined(__WINE__)