From 9aa03e74933f4a61bb0b5d13a9e1ddb280365f14 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 27 Feb 2003 13:01:29 +0000 Subject: [PATCH] fix bug with timezone calculations when WX_GMTOFF_IN_TM si true git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_4_BRANCH@19365 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/changes.txt | 1 + src/common/datetime.cpp | 14 ++++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index e5ccc8e64d..7b71798fdc 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -185,6 +185,7 @@ Unix (GUI): wxBase - compilation with wxUSE_ODBC=1 fixed (dbkeyg.h file was missing in the archive) +- bug in wxDateTime with timezones on systems with tm_gmtoff in struct tm fixed wxGTK: diff --git a/src/common/datetime.cpp b/src/common/datetime.cpp index 3ef1e1e6f1..4c91d36c8b 100644 --- a/src/common/datetime.cpp +++ b/src/common/datetime.cpp @@ -258,7 +258,8 @@ wxDateTime::wxDateTime_t GetNumOfDaysInMonth(int year, wxDateTime::Month month) return daysInMonth[wxDateTime::IsLeapYear(year)][month]; } -// ensure that the timezone variable is set by calling localtime +// returns the time zone in the C sense, i.e. the difference UTC - local +// (in seconds) static int GetTimeZone() { // set to TRUE when the timezone is set @@ -266,20 +267,25 @@ static int GetTimeZone() #ifdef WX_GMTOFF_IN_TM static long gmtoffset = LONG_MAX; // invalid timezone #endif - + wxCRIT_SECT_LOCKER(lock, gs_critsectTimezone); + // ensure that the timezone variable is set by calling localtime if ( !s_timezoneSet ) { // just call localtime() instead of figuring out whether this system // supports tzset(), _tzset() or something else - time_t t = 0; + time_t t = 0; struct tm *tm; tm = localtime(&t); s_timezoneSet = TRUE; + #ifdef WX_GMTOFF_IN_TM - gmtoffset = tm->tm_gmtoff; + // note that GMT offset is the opposite of time zone and so to return + // consistent results in both WX_GMTOFF_IN_TM and !WX_GMTOFF_IN_TM + // cases we have to negate it + gmtoffset = -tm->tm_gmtoff; #endif }