From: Vadim Zeitlin Date: Sun, 6 Nov 2011 12:06:43 +0000 (+0000) Subject: Use current time, not the Epoch for time zone determination. X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/2673c2394a75a7aa20f47667085db946b4bf3211 Use current time, not the Epoch for time zone determination. 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 --- diff --git a/src/common/datetime.cpp b/src/common/datetime.cpp index 790de959aa..c08a5c3fc2 100644 --- a/src/common/datetime.cpp +++ b/src/common/datetime.cpp @@ -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__)