X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/0308fd61a22323c48aa51d527c6c14b8c55c5b76..c9d59ee7e0cbe4acae6153adafb5ddce9a4e65dd:/src/common/datetime.cpp diff --git a/src/common/datetime.cpp b/src/common/datetime.cpp index dd2d9dbccb..3ac780395f 100644 --- a/src/common/datetime.cpp +++ b/src/common/datetime.cpp @@ -817,10 +817,12 @@ wxString wxDateTime::GetWeekDayName(wxDateTime::WeekDay wday, { wxCHECK_MSG( wday != Inv_WeekDay, _T(""), _T("invalid weekday") ); - // take some arbitrary Sunday + // take some arbitrary Sunday (but notice that the day should be such that + // after adding wday to it below we still have a valid date, e.g. don't + // take 28 here!) tm tm; InitTm(tm); - tm.tm_mday = 28; + tm.tm_mday = 21; tm.tm_mon = Nov; tm.tm_year = 99; @@ -839,7 +841,7 @@ void wxDateTime::GetAmPmStrings(wxString *am, wxString *pm) { tm tm; InitTm(tm); - char buffer[64]; + wxChar buffer[64]; // @Note: Do not call 'CallStrftime' here! CallStrftime checks the return code // and causes an assertion failed if the buffer is to small (which is good) - OR - // if strftime does not return anything because the format string is invalid - OR - @@ -1287,6 +1289,17 @@ wxDateTime& wxDateTime::Set(double jdn) jdn *= MILLISECONDS_PER_DAY; + // JDNs always suppose an UTC date, so bring it back to local time zone + // (also see GetJulianDayNumber() implementation) + long tzDiff = GetTimeZone(); + if ( IsDST() == 1 ) + { + // FIXME: again, we suppose that DST is always one hour + tzDiff -= 3600; + } + + jdn += tzDiff*1000; // tzDiff is in seconds + m_time.Assign(jdn); return *this; @@ -1326,6 +1339,7 @@ wxDateTime& wxDateTime::ResetTime() wxDateTime& wxDateTime::SetFromDOS(unsigned long ddt) { struct tm tm; + InitTm(tm); long year = ddt & 0xFE000000; year >>= 25; @@ -1886,7 +1900,7 @@ wxDateTime& wxDateTime::SetToYearDay(wxDateTime::wxDateTime_t yday) // for Dec, we can't compare with gs_cumulatedDays[mon + 1], but we // don't need it neither - because of the CHECK above we know that // yday lies in December then - if ( (mon == Dec) || (yday < gs_cumulatedDays[isLeap][mon + 1]) ) + if ( (mon == Dec) || (yday <= gs_cumulatedDays[isLeap][mon + 1]) ) { Set(yday - gs_cumulatedDays[isLeap][mon], mon, year); @@ -1903,8 +1917,8 @@ wxDateTime& wxDateTime::SetToYearDay(wxDateTime::wxDateTime_t yday) double wxDateTime::GetJulianDayNumber() const { - // JDN are always expressed for the GMT dates - Tm tm(ToTimezone(GMT0).GetTm(GMT0)); + // JDN are always expressed for the UTC dates + Tm tm(ToTimezone(UTC).GetTm(UTC)); double result = GetTruncatedJDN(tm.mday, tm.mon, tm.year);