From 3d78a53231c655b3a0604a737df353559998d77d Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Wed, 27 Oct 2004 01:06:45 +0000 Subject: [PATCH] The old workaround for the 1-Jan-1970 bug still failed in some timezones. This new workaround seems to work better. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@30107 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/common/datetime.cpp | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/common/datetime.cpp b/src/common/datetime.cpp index 270d110634..9f275a8158 100644 --- a/src/common/datetime.cpp +++ b/src/common/datetime.cpp @@ -1168,16 +1168,11 @@ wxDateTime& wxDateTime::Set(const struct tm& tm) // less than timezone - try to make it work for this case if ( tm2.tm_year == 70 && tm2.tm_mon == 0 && tm2.tm_mday == 1 ) { - // add timezone to make sure that date is in range - tm2.tm_sec -= GetTimeZone(); - - timet = mktime(&tm2); - if ( timet != (time_t)-1 ) - { - timet += GetTimeZone(); - - return Set(timet); - } + return Set((time_t)( + GetTimeZone() + + tm2.tm_hour * MIN_PER_HOUR * SEC_PER_MIN + + tm2.tm_min * SEC_PER_MIN + + tm2.tm_sec)); } wxFAIL_MSG( _T("mktime() failed") ); @@ -1262,7 +1257,10 @@ wxDateTime& wxDateTime::Set(wxDateTime_t day, (void)Set(tm); // and finally adjust milliseconds - return SetMillisecond(millisec); + if (IsValid()) + SetMillisecond(millisec); + + return *this; } else { -- 2.47.2