X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/5f287370dd4e5e89d16076958e64bd3870e3a392..599a97e9ab9d9c1fca761d501ef101595e0ae486:/src/common/datetime.cpp diff --git a/src/common/datetime.cpp b/src/common/datetime.cpp index 47607ede47..8cd374b31f 100644 --- a/src/common/datetime.cpp +++ b/src/common/datetime.cpp @@ -92,7 +92,7 @@ #endif // broken strptime() #ifndef WX_TIMEZONE - #if defined(__MINGW32__) || defined(__VISAGECPP__) + #if defined(__BORLANDC__) || defined(__MINGW32__) || defined(__VISAGECPP__) #define WX_TIMEZONE _timezone #else // unknown platform - try timezone #define WX_TIMEZONE timezone @@ -1128,6 +1128,9 @@ wxDateTime& wxDateTime::Set(double jdn) wxDateTime::Tm wxDateTime::GetTm(const TimeZone& tz) const { +#ifdef __VMS__ + int time2; +#endif wxASSERT_MSG( IsValid(), _T("invalid wxDateTime") ); time_t time = GetTicks(); @@ -1146,7 +1149,12 @@ wxDateTime::Tm wxDateTime::GetTm(const TimeZone& tz) const else { time += tz.GetOffset(); - if ( time >= 0 ) +#ifdef __VMS__ /* time is unsigned so VMS gives a warning on the original */ + time2 = (int) time; + if ( time2 >= 0 ) +#else + if ( time >= 0 ) +#endif { tm = gmtime(&time); @@ -1545,7 +1553,7 @@ wxDateTime::wxDateTime_t wxDateTime::GetWeekOfMonth(const TimeZone& tz) const wxDateTime& wxDateTime::SetToYearDay(wxDateTime::wxDateTime_t yday) { int year = GetYear(); - wxCHECK_MSG( (0 < yday) && (yday < GetNumberOfDays(year)), + wxCHECK_MSG( (0 < yday) && (yday <= GetNumberOfDays(year)), ms_InvDateTime, _T("invalid year day") ); bool isLeap = IsLeapYear(year); @@ -1642,6 +1650,9 @@ wxDateTime& wxDateTime::MakeTimezone(const TimeZone& tz) wxString wxDateTime::Format(const wxChar *format, const TimeZone& tz) const { +#ifdef __VMS__ + int time2; +#endif wxCHECK_MSG( format, _T(""), _T("NULL format in wxDateTime::Format") ); time_t time = GetTicks(); @@ -1661,7 +1672,12 @@ wxString wxDateTime::Format(const wxChar *format, const TimeZone& tz) const { time += tz.GetOffset(); - if ( time >= 0 ) +#ifdef __VMS__ /* time is unsigned so VMS gives a warning on the original */ + time2 = (int) time; + if ( time2 >= 0 ) +#else + if ( time >= 0 ) +#endif { tm = gmtime(&time); @@ -2277,7 +2293,7 @@ const wxChar *wxDateTime::ParseRfc822Date(const wxChar* date) // the spec was correct Set(day, mon, year, hour, min, sec); - MakeTimezone(60*offset); + MakeTimezone(60*(wxDateTime_t)offset); return p; } @@ -2400,6 +2416,19 @@ const wxChar *wxDateTime::ParseFormat(const wxChar *date, return (wxChar *)NULL; } + Tm tm = dt.GetTm(); + + haveDay = haveMon = haveYear = + haveHour = haveMin = haveSec = TRUE; + + hour = tm.hour; + min = tm.min; + sec = tm.sec; + + year = tm.year; + mon = tm.mon; + mday = tm.mday; + input = result; } break; @@ -2459,7 +2488,7 @@ const wxChar *wxDateTime::ParseFormat(const wxChar *date, } haveMon = TRUE; - mon = (Month)num; + mon = (Month)(num - 1); break; case _T('M'): // minute as a decimal number (00-59) @@ -2554,6 +2583,7 @@ const wxChar *wxDateTime::ParseFormat(const wxChar *date, min = tm.min; sec = tm.sec; } + break; case _T('w'): // weekday as a number (0-6), Sunday = 0 if ( !GetNumericToken(input, &num) || (wday > 6) ) @@ -2687,14 +2717,14 @@ const wxChar *wxDateTime::ParseFormat(const wxChar *date, break; case _T('Y'): // year with century - if ( !GetNumericToken(input, &num) || !num || (num > 366) ) + if ( !GetNumericToken(input, &num) ) { // no match return (wxChar *)NULL; } - haveYDay = TRUE; - yday = (wxDateTime_t)num; + haveYear = TRUE; + year = (wxDateTime_t)num; break; case _T('Z'): // timezone name @@ -2726,7 +2756,7 @@ const wxChar *wxDateTime::ParseFormat(const wxChar *date, // take this date as default tmDef = dateDef.GetTm(); } - else if ( IsValid() ) + else if ( m_time != 0 ) { // if this date is valid, don't change it tmDef = GetTm(); @@ -2750,11 +2780,25 @@ const wxChar *wxDateTime::ParseFormat(const wxChar *date, // also always ignore the week day if ( haveMon && haveDay ) { + if ( mday > GetNumOfDaysInMonth(tm.year, mon) ) + { + wxLogDebug(_T("bad month day in wxDateTime::ParseFormat")); + + return (wxChar *)NULL; + } + tm.mon = mon; tm.mday = mday; } else if ( haveYDay ) { + if ( yday > GetNumberOfDays(tm.year) ) + { + wxLogDebug(_T("bad year day in wxDateTime::ParseFormat")); + + return (wxChar *)NULL; + } + Tm tm2 = wxDateTime(1, Jan, tm.year).SetToYearDay(yday).GetTm(); tm.mon = tm2.mon;