X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/299fcbfe98fce39cdc9ab142b65824a175542ff2..78e848cac9c973346dcf598f3c1b942b63dd2821:/src/common/datetime.cpp diff --git a/src/common/datetime.cpp b/src/common/datetime.cpp index 10f35b10fb..d93cb2d179 100644 --- a/src/common/datetime.cpp +++ b/src/common/datetime.cpp @@ -553,9 +553,25 @@ wxDateTime& wxDateTime::Set(const struct tm& tm) struct tm tm2(tm); time_t timet = mktime(&tm2); - if ( timet == (time_t)(-1) ) + if ( timet == (time_t)-1 ) { - wxFAIL_MSG(_T("Invalid time")); + // mktime() rather unintuitively fails for Jan 1, 1970 if the hour is + // 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); + } + } + + wxFAIL_MSG( _T("mktime() failed") ); return ms_InvDateTime; } @@ -688,6 +704,7 @@ wxDateTime::Tm wxDateTime::GetTm(const TimeZone& tz) const } else { + time += tz.GetOffset(); tm = gmtime(&time); } @@ -701,7 +718,7 @@ wxDateTime::Tm wxDateTime::GetTm(const TimeZone& tz) const // remember the time and do the calculations with the date only - this // eliminates rounding errors of the floating point arithmetics - wxLongLong timeMidnight = m_time - GetTimeZone() * 1000; + wxLongLong timeMidnight = m_time + tz.GetOffset() * 1000; long timeOnly = (timeMidnight % MILLISECONDS_PER_DAY).ToLong();