X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/3897b707bd39c491c820849953431e4a5751fced..fe1bdf10a61ddc1f3455e5a9a22ca04a8f38eec2:/src/common/datetime.cpp diff --git a/src/common/datetime.cpp b/src/common/datetime.cpp index f648ca26f4..7dc3120194 100644 --- a/src/common/datetime.cpp +++ b/src/common/datetime.cpp @@ -63,12 +63,14 @@ #pragma hdrstop #endif +#if !defined(wxUSE_DATETIME) || wxUSE_DATETIME + #ifndef WX_PRECOMP #include "wx/string.h" - #include "wx/intl.h" #include "wx/log.h" #endif // WX_PRECOMP +#include "wx/intl.h" #include "wx/thread.h" #include "wx/tokenzr.h" #include "wx/module.h" @@ -100,7 +102,22 @@ #define WX_TIMEZONE _timezone #elif defined(__MWERKS__) long wxmw_timezone = 28800; - #define WX_TIMEZONE wxmw_timezone; + #define WX_TIMEZONE wxmw_timezone + #elif defined(__DJGPP__) + #include + #include + static long wxGetTimeZone() + { + static long timezone = MAXLONG; // invalid timezone + if (timezone == MAXLONG) + { + struct timeb tb; + ftime(&tb); + timezone = tb.timezone; + } + return timezone; + } + #define WX_TIMEZONE wxGetTimeZone() #else // unknown platform - try timezone #define WX_TIMEZONE timezone #endif @@ -194,7 +211,8 @@ static const wxDateTime::wxDateTime_t gs_cumulatedDays[2][MONTHS_IN_YEAR] = // in the fine tradition of ANSI C we use our equivalent of (time_t)-1 to // indicate an invalid wxDateTime object -static const wxDateTime gs_dtDefault = wxLongLong((long)ULONG_MAX, ULONG_MAX); + +static const wxDateTime gs_dtDefault; const wxDateTime& wxDefaultDateTime = gs_dtDefault; @@ -1067,8 +1085,6 @@ wxDateTime wxDateTime::GetEndDST(int year, Country country) // the values in the tm structure contain the local time wxDateTime& wxDateTime::Set(const struct tm& tm) { - wxASSERT_MSG( IsValid(), _T("invalid wxDateTime") ); - struct tm tm2(tm); time_t timet = mktime(&tm2); @@ -1107,8 +1123,6 @@ wxDateTime& wxDateTime::Set(wxDateTime_t hour, wxDateTime_t second, wxDateTime_t millisec) { - wxASSERT_MSG( IsValid(), _T("invalid wxDateTime") ); - // we allow seconds to be 61 to account for the leap seconds, even if we // don't use them really wxDATETIME_CHECK( hour < 24 && @@ -1141,8 +1155,6 @@ wxDateTime& wxDateTime::Set(wxDateTime_t day, wxDateTime_t second, wxDateTime_t millisec) { - wxASSERT_MSG( IsValid(), _T("invalid wxDateTime") ); - wxDATETIME_CHECK( hour < 24 && second < 62 && minute < 60 && @@ -1249,7 +1261,7 @@ wxDateTime::Tm wxDateTime::GetTm(const TimeZone& tz) const else { time += (time_t)tz.GetOffset(); -#ifdef __VMS__ // time is unsigned so avoid warning +#if defined(__VMS__) || defined(__WATCOMC__) // time is unsigned so avoid warning int time2 = (int) time; if ( time2 >= 0 ) #else @@ -1335,8 +1347,6 @@ wxDateTime::Tm wxDateTime::GetTm(const TimeZone& tz) const // check that the algorithm gave us something reasonable wxASSERT_MSG( (0 < month) && (month <= 12), _T("invalid month") ); wxASSERT_MSG( (1 <= day) && (day < 32), _T("invalid day") ); - wxASSERT_MSG( (INT_MIN <= year) && (year <= INT_MAX), - _T("year range overflow") ); // construct Tm from these values Tm tm; @@ -1816,7 +1826,7 @@ wxString wxDateTime::Format(const wxChar *format, const TimeZone& tz) const { time += (int)tz.GetOffset(); -#ifdef __VMS__ // time is unsigned so avoid the warning +#if defined(__VMS__) || defined(__WATCOMC__) // time is unsigned so avoid warning int time2 = (int) time; if ( time2 >= 0 ) #else @@ -2933,11 +2943,7 @@ const wxChar *wxDateTime::ParseFormat(const wxChar *date, // take this date as default tmDef = dateDef.GetTm(); } -#ifdef __WIN16__ - else if ( m_time != 0 ) -#else - else if ( m_time != wxLongLong(0) ) -#endif + else if ( IsValid() ) { // if this date is valid, don't change it tmDef = GetTm(); @@ -3166,7 +3172,7 @@ const wxChar *wxDateTime::ParseDate(const wxChar *date) // but we already have a month - maybe we guessed wrong? if ( !haveDay ) { - // no need to check in month range as always < 12, but + // no need to check in month range as always < 12, but // the days are counted from 1 unlike the months day = (wxDateTime_t)mon + 1; haveDay = TRUE; @@ -3176,7 +3182,7 @@ const wxChar *wxDateTime::ParseDate(const wxChar *date) // could possible be the year (doesn't the year come // before the month in the japanese format?) (FIXME) break; - } + } } mon = mon2; @@ -3251,7 +3257,7 @@ const wxChar *wxDateTime::ParseDate(const wxChar *date) haveDay = TRUE; - day = n + 1; + day = (wxDateTime_t)(n + 1); } } } @@ -3288,7 +3294,8 @@ const wxChar *wxDateTime::ParseDate(const wxChar *date) mon = (wxDateTime::Month)(day - 1); // we're in the current year then - if ( year <= GetNumOfDaysInMonth(Inv_Year, mon) ) + if ( (year > 0) && + (unsigned)year <= GetNumOfDaysInMonth(Inv_Year, mon) ) { day = year; @@ -3381,8 +3388,12 @@ const wxChar *wxDateTime::ParseTime(const wxChar *time) } } - // try all time formats we may think about starting with the standard one - const wxChar *result = ParseFormat(time, _T("%X")); + // try all time formats we may think about in the order from longest to + // shortest + + // 12hour with AM/PM? + const wxChar *result = ParseFormat(time, _T("%I:%M:%S %p")); + if ( !result ) { // normally, it's the same, but why not try it? @@ -3391,8 +3402,8 @@ const wxChar *wxDateTime::ParseTime(const wxChar *time) if ( !result ) { - // 12hour with AM/PM? - result = ParseFormat(time, _T("%I:%M:%S %p")); + // 12hour with AM/PM but without seconds? + result = ParseFormat(time, _T("%I:%M %p")); } if ( !result ) @@ -3403,8 +3414,8 @@ const wxChar *wxDateTime::ParseTime(const wxChar *time) if ( !result ) { - // 12hour with AM/PM but without seconds? - result = ParseFormat(time, _T("%I:%M %p")); + // just the hour and AM/PM? + result = ParseFormat(time, _T("%I %p")); } if ( !result ) @@ -3415,8 +3426,9 @@ const wxChar *wxDateTime::ParseTime(const wxChar *time) if ( !result ) { - // just the hour and AM/PM? - result = ParseFormat(time, _T("%I %p")); + // parse the standard format: normally it is one of the formats above + // but it may be set to something completely different by the user + result = ParseFormat(time, _T("%X")); } // TODO: parse timezones @@ -3437,6 +3449,19 @@ bool wxDateTime::IsWorkDay(Country WXUNUSED(country)) const // wxTimeSpan // ============================================================================ +// this enum is only used in wxTimeSpan::Format() below but we can't declare +// it locally to the method as it provokes an internal compiler error in egcs +// 2.91.60 when building with -O2 +enum TimeSpanPart +{ + Part_Week, + Part_Day, + Part_Hour, + Part_Min, + Part_Sec, + Part_MSec +}; + // not all strftime(3) format specifiers make sense here because, for example, // a time span doesn't have a year nor a timezone // @@ -3474,15 +3499,7 @@ wxString wxTimeSpan::Format(const wxChar *format) const // should use GetMinutes() % 60, otherwise just GetMinutes() &c // we remember the most important unit found so far - enum TimeSpanPart - { - Part_Week, - Part_Day, - Part_Hour, - Part_Min, - Part_Sec, - Part_MSec - } partBiggest = Part_MSec; + TimeSpanPart partBiggest = Part_MSec; for ( const wxChar *pch = format; *pch; pch++ ) { @@ -3711,4 +3728,4 @@ size_t wxDateTimeWorkDays::DoGetHolidaysInRange(const wxDateTime& dtStart, return holidays.GetCount(); } - +#endif // wxUSE_DATETIME