X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/98919134f0cb50ca160ec60452ed2ac27b1a0617..0571b62b887f2d9b02084e027e01c1d4881a4713:/src/common/datetime.cpp diff --git a/src/common/datetime.cpp b/src/common/datetime.cpp index 5781bebe92..2adec8c242 100644 --- a/src/common/datetime.cpp +++ b/src/common/datetime.cpp @@ -88,7 +88,9 @@ #include "wx/datetime.h" -const long wxDateTime::TIME_T_FACTOR = 1000l; +// ---------------------------------------------------------------------------- +// wxXTI +// ---------------------------------------------------------------------------- #if wxUSE_EXTENDED_RTTI @@ -106,35 +108,11 @@ wxCUSTOM_TYPE_INFO(wxDateTime, wxToStringConverter , wxFromStringCon #endif // wxUSE_EXTENDED_RTTI -// + // ---------------------------------------------------------------------------- // conditional compilation // ---------------------------------------------------------------------------- -#if defined(HAVE_STRPTIME) && defined(__GLIBC__) && \ - ((__GLIBC__ == 2) && (__GLIBC_MINOR__ == 0)) - // glibc 2.0.7 strptime() is broken - the following snippet causes it to - // crash (instead of just failing): - // - // strncpy(buf, "Tue Dec 21 20:25:40 1999", 128); - // strptime(buf, "%x", &tm); - // - // so don't use it - #undef HAVE_STRPTIME -#endif // broken strptime() - -#if defined(HAVE_STRPTIME) && defined(__DARWIN__) && defined(_MSL_USING_MW_C_HEADERS) && _MSL_USING_MW_C_HEADERS - // configure detects strptime as linkable because it's in the OS X - // System library but MSL headers don't declare it. - -// char *strptime(const char *, const char *, struct tm *); - // However, we DON'T want to just provide it here because we would - // crash and/or overwrite data when strptime from OS X tries - // to fill in MW's struct tm which is two fields shorter (no TZ stuff) - // So for now let's just say we don't have strptime - #undef HAVE_STRPTIME -#endif - #if defined(__MWERKS__) && wxUSE_UNICODE #include #endif @@ -203,11 +181,6 @@ wxCUSTOM_TYPE_INFO(wxDateTime, wxToStringConverter , wxFromStringCon #endif #endif // !WX_TIMEZONE && !WX_GMTOFF_IN_TM -// everyone has strftime except Win CE unless VC8 is used -#if !defined(__WXWINCE__) || defined(__VISUALC8__) - #define HAVE_STRFTIME -#endif - // NB: VC8 safe time functions could/should be used for wxMSW as well probably #if defined(__WXWINCE__) && defined(__VISUALC8__) @@ -335,14 +308,15 @@ static const long MILLISECONDS_PER_DAY = 86400000l; // (i.e. JDN(Jan 1, 1970) = 2440587.5) static const long EPOCH_JDN = 2440587l; -// used only in asserts -#ifdef __WXDEBUG__ +// these values are only used in asserts so don't define them if asserts are +// disabled to avoid warnings about unused static variables +#if wxDEBUG_LEVEL // the date of JDN -0.5 (as we don't work with fractional parts, this is the // reference date for us) is Nov 24, 4714BC static const int JDN_0_YEAR = -4713; static const int JDN_0_MONTH = wxDateTime::Nov; static const int JDN_0_DAY = 24; -#endif // __WXDEBUG__ +#endif // wxDEBUG_LEVEL // the constants used for JDN calculations static const long JDN_OFFSET = 32046l; @@ -358,6 +332,8 @@ static const wxDateTime::wxDateTime_t gs_cumulatedDays[2][MONTHS_IN_YEAR] = { 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335 } }; +const long wxDateTime::TIME_T_FACTOR = 1000l; + // ---------------------------------------------------------------------------- // global data // ---------------------------------------------------------------------------- @@ -375,8 +351,8 @@ wxDateTime::Country wxDateTime::ms_country = wxDateTime::Country_Unknown; // private functions // ---------------------------------------------------------------------------- -// debugger helper: shows what the date really is -#ifdef __WXDEBUG__ +// debugger helper: this function can be called from a debugger to show what +// the date really is extern const char *wxDumpDate(const wxDateTime* dt) { static char buf[128]; @@ -388,7 +364,6 @@ extern const char *wxDumpDate(const wxDateTime* dt) return buf; } -#endif // Debug // get the number of days in the given month of the given year static inline @@ -407,7 +382,8 @@ wxDateTime::wxDateTime_t GetNumOfDaysInMonth(int year, wxDateTime::Month month) // returns the time zone in the C sense, i.e. the difference UTC - local // (in seconds) -static int GetTimeZone() +// NOTE: not static because used by datetimefmt.cpp +int GetTimeZone() { // set to true when the timezone is set static bool s_timezoneSet = false; @@ -451,7 +427,7 @@ static long GetTruncatedJDN(wxDateTime::wxDateTime_t day, (year > JDN_0_YEAR) || ((year == JDN_0_YEAR) && (mon > JDN_0_MONTH)) || ((year == JDN_0_YEAR) && (mon == JDN_0_MONTH) && (day >= JDN_0_DAY)), - _T("date out of range - can't convert to JDN") + wxT("date out of range - can't convert to JDN") ); // make the year positive to avoid problems with negative numbers division @@ -477,10 +453,11 @@ static long GetTruncatedJDN(wxDateTime::wxDateTime_t day, - JDN_OFFSET; } -#ifdef HAVE_STRFTIME +#ifdef wxHAS_STRFTIME // this function is a wrapper around strftime(3) adding error checking -static wxString CallStrftime(const wxString& format, const tm* tm) +// NOTE: not static because used by datetimefmt.cpp +wxString CallStrftime(const wxString& format, const tm* tm) { wxChar buf[4096]; // Create temp wxString here to work around mingw/cygwin bug 1046059 @@ -490,7 +467,7 @@ static wxString CallStrftime(const wxString& format, const tm* tm) if ( !wxStrftime(buf, WXSIZEOF(buf), format, tm) ) { // if the format is valid, buffer must be too small? - wxFAIL_MSG(_T("strftime() failed")); + wxFAIL_MSG(wxT("strftime() failed")); buf[0] = '\0'; } @@ -499,42 +476,7 @@ static wxString CallStrftime(const wxString& format, const tm* tm) return s; } -#endif // HAVE_STRFTIME - -#ifdef HAVE_STRPTIME - -#if wxUSE_UNIX && !defined(HAVE_STRPTIME_DECL) - // configure detected that we had strptime() but not its declaration, - // provide it ourselves - extern "C" char *strptime(const char *, const char *, struct tm *); -#endif - -// Unicode-friendly strptime() wrapper -static const wxStringCharType * -CallStrptime(const wxStringCharType *input, const char *fmt, tm *tm) -{ - // the problem here is that strptime() returns pointer into the string we - // passed to it while we're really interested in the pointer into the - // original, Unicode, string so we try to transform the pointer back -#if wxUSE_UNICODE_WCHAR - wxCharBuffer inputMB(wxConvertWX2MB(input)); -#else // ASCII - const char * const inputMB = input; -#endif // Unicode/Ascii - - const char *result = strptime(inputMB, fmt, tm); - if ( !result ) - return NULL; - -#if wxUSE_UNICODE_WCHAR - // FIXME: this is wrong in presence of surrogates &c - return input + (result - inputMB.data()); -#else // ASCII - return result; -#endif // Unicode/Ascii -} - -#endif // HAVE_STRPTIME +#endif // wxHAS_STRFTIME // if year and/or month have invalid values, replace them with the current ones static void ReplaceDefaultYearMonthWithCurrent(int *year, @@ -559,8 +501,9 @@ static void ReplaceDefaultYearMonthWithCurrent(int *year, } } -// fll the struct tm with default values -static void InitTm(struct tm& tm) +// fill the struct tm with default values +// NOTE: not static because used by datetimefmt.cpp +void InitTm(struct tm& tm) { // struct tm may have etxra fields (undocumented and with unportable // names) which, nevertheless, must be set to 0 @@ -571,106 +514,6 @@ static void InitTm(struct tm& tm) tm.tm_isdst = -1; // auto determine } -// parsing helpers -// --------------- - -// return the month if the string is a month name or Inv_Month otherwise -static wxDateTime::Month GetMonthFromName(const wxString& name, int flags) -{ - wxDateTime::Month mon; - for ( mon = wxDateTime::Jan; mon < wxDateTime::Inv_Month; wxNextMonth(mon) ) - { - // case-insensitive comparison either one of or with both abbreviated - // and not versions - if ( flags & wxDateTime::Name_Full ) - { - if ( name.CmpNoCase(wxDateTime:: - GetMonthName(mon, wxDateTime::Name_Full)) == 0 ) - { - break; - } - } - - if ( flags & wxDateTime::Name_Abbr ) - { - if ( name.CmpNoCase(wxDateTime:: - GetMonthName(mon, wxDateTime::Name_Abbr)) == 0 ) - { - break; - } - } - } - - return mon; -} - -// return the weekday if the string is a weekday name or Inv_WeekDay otherwise -static wxDateTime::WeekDay GetWeekDayFromName(const wxString& name, int flags) -{ - wxDateTime::WeekDay wd; - for ( wd = wxDateTime::Sun; wd < wxDateTime::Inv_WeekDay; wxNextWDay(wd) ) - { - // case-insensitive comparison either one of or with both abbreviated - // and not versions - if ( flags & wxDateTime::Name_Full ) - { - if ( name.CmpNoCase(wxDateTime:: - GetWeekDayName(wd, wxDateTime::Name_Full)) == 0 ) - { - break; - } - } - - if ( flags & wxDateTime::Name_Abbr ) - { - if ( name.CmpNoCase(wxDateTime:: - GetWeekDayName(wd, wxDateTime::Name_Abbr)) == 0 ) - { - break; - } - } - } - - return wd; -} - -/* static */ -struct tm *wxDateTime::GetTmNow(struct tm *tmstruct) -{ - time_t t = GetTimeNow(); - return wxLocaltime_r(&t, tmstruct); -} - -// scans all digits (but no more than len) and returns the resulting number -static bool GetNumericToken(size_t len, - const wxStringCharType*& p, - unsigned long *number) -{ - size_t n = 1; - wxString s; - while ( wxIsdigit(*p) ) - { - s += *p++; - - if ( len && ++n > len ) - break; - } - - return !s.empty() && s.ToULong(number); -} - -// scans all alphabetic characters and returns the resulting string -static wxString GetAlphaToken(const wxStringCharType*& p) -{ - wxString s; - while ( wxIsalpha(*p) ) - { - s += *p++; - } - - return s; -} - // ============================================================================ // implementation of wxDateTime // ============================================================================ @@ -737,7 +580,7 @@ void wxDateTime::Tm::AddMonths(int monDiff) mon = (wxDateTime::Month)(mon + monDiff); - wxASSERT_MSG( mon >= 0 && mon < MONTHS_IN_YEAR, _T("logic error") ); + wxASSERT_MSG( mon >= 0 && mon < MONTHS_IN_YEAR, wxT("logic error") ); // NB: we don't check here that the resulting date is valid, this function // is private and the caller must check it if needed @@ -762,7 +605,7 @@ void wxDateTime::Tm::AddDays(int dayDiff) } wxASSERT_MSG( mday > 0 && mday <= GetNumOfDaysInMonth(year, mon), - _T("logic error") ); + wxT("logic error") ); } // ---------------------------------------------------------------------------- @@ -817,7 +660,7 @@ wxDateTime::TimeZone::TimeZone(wxDateTime::TZ tz) break; default: - wxFAIL_MSG( _T("unknown time zone") ); + wxFAIL_MSG( wxT("unknown time zone") ); } } @@ -825,6 +668,13 @@ wxDateTime::TimeZone::TimeZone(wxDateTime::TZ tz) // static functions // ---------------------------------------------------------------------------- +/* static */ +struct tm *wxDateTime::GetTmNow(struct tm *tmstruct) +{ + time_t t = GetTimeNow(); + return wxLocaltime_r(&t, tmstruct); +} + /* static */ bool wxDateTime::IsLeapYear(int year, wxDateTime::Calendar cal) { @@ -846,7 +696,7 @@ bool wxDateTime::IsLeapYear(int year, wxDateTime::Calendar cal) } else { - wxFAIL_MSG(_T("unknown calendar")); + wxFAIL_MSG(wxT("unknown calendar")); return false; } @@ -874,11 +724,11 @@ int wxDateTime::GetCurrentYear(wxDateTime::Calendar cal) return Now().GetYear(); case Julian: - wxFAIL_MSG(_T("TODO")); + wxFAIL_MSG(wxT("TODO")); break; default: - wxFAIL_MSG(_T("unsupported calendar")); + wxFAIL_MSG(wxT("unsupported calendar")); break; } @@ -894,11 +744,11 @@ wxDateTime::Month wxDateTime::GetCurrentMonth(wxDateTime::Calendar cal) return Now().GetMonth(); case Julian: - wxFAIL_MSG(_T("TODO")); + wxFAIL_MSG(wxT("TODO")); break; default: - wxFAIL_MSG(_T("unsupported calendar")); + wxFAIL_MSG(wxT("unsupported calendar")); break; } @@ -921,7 +771,7 @@ wxDateTime::wxDateTime_t wxDateTime::GetNumberOfDays(int year, Calendar cal) return IsLeapYear(year) ? 366 : 365; default: - wxFAIL_MSG(_T("unsupported calendar")); + wxFAIL_MSG(wxT("unsupported calendar")); break; } @@ -933,7 +783,7 @@ wxDateTime::wxDateTime_t wxDateTime::GetNumberOfDays(wxDateTime::Month month, int year, wxDateTime::Calendar cal) { - wxCHECK_MSG( month < MONTHS_IN_YEAR, 0, _T("invalid month") ); + wxCHECK_MSG( month < MONTHS_IN_YEAR, 0, wxT("invalid month") ); if ( cal == Gregorian || cal == Julian ) { @@ -947,76 +797,105 @@ wxDateTime::wxDateTime_t wxDateTime::GetNumberOfDays(wxDateTime::Month month, } else { - wxFAIL_MSG(_T("unsupported calendar")); + wxFAIL_MSG(wxT("unsupported calendar")); return 0; } } +namespace +{ + +// helper function used by GetEnglish/WeekDayName(): returns 0 if flags is +// Name_Full and 1 if it is Name_Abbr or -1 if the flags is incorrect (and +// asserts in this case) +// +// the return value of this function is used as an index into 2D array +// containing full names in its first row and abbreviated ones in the 2nd one +int NameArrayIndexFromFlag(wxDateTime::NameFlags flags) +{ + switch ( flags ) + { + case wxDateTime::Name_Full: + return 0; + + case wxDateTime::Name_Abbr: + return 1; + + default: + wxFAIL_MSG( "unknown wxDateTime::NameFlags value" ); + } + + return -1; +} + +} // anonymous namespace + +/* static */ +wxString wxDateTime::GetEnglishMonthName(Month month, NameFlags flags) +{ + wxCHECK_MSG( month != Inv_Month, wxEmptyString, "invalid month" ); + + static const char *monthNames[2][MONTHS_IN_YEAR] = + { + { "January", "February", "March", "April", "May", "June", + "July", "August", "September", "October", "November", "December" }, + { "Jan", "Feb", "Mar", "Apr", "May", "Jun", + "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" } + }; + + const int idx = NameArrayIndexFromFlag(flags); + if ( idx == -1 ) + return wxString(); + + return monthNames[idx][month]; +} + /* static */ wxString wxDateTime::GetMonthName(wxDateTime::Month month, wxDateTime::NameFlags flags) { - wxCHECK_MSG( month != Inv_Month, wxEmptyString, _T("invalid month") ); -#ifdef HAVE_STRFTIME +#ifdef wxHAS_STRFTIME + wxCHECK_MSG( month != Inv_Month, wxEmptyString, wxT("invalid month") ); + // notice that we must set all the fields to avoid confusing libc (GNU one // gets confused to a crash if we don't do this) tm tm; InitTm(tm); tm.tm_mon = month; - return CallStrftime(flags == Name_Abbr ? _T("%b") : _T("%B"), &tm); -#else // !HAVE_STRFTIME - wxString ret; - switch(month) + return CallStrftime(flags == Name_Abbr ? wxT("%b") : wxT("%B"), &tm); +#else // !wxHAS_STRFTIME + return GetEnglishMonthName(month, flags); +#endif // wxHAS_STRFTIME/!wxHAS_STRFTIME +} + +/* static */ +wxString wxDateTime::GetEnglishWeekDayName(WeekDay wday, NameFlags flags) +{ + wxCHECK_MSG( wday != Inv_WeekDay, wxEmptyString, wxT("invalid weekday") ); + + static const char *weekdayNames[2][DAYS_PER_WEEK] = { - case Jan: - ret = (flags == Name_Abbr ? wxT("Jan"): wxT("January")); - break; - case Feb: - ret = (flags == Name_Abbr ? wxT("Feb"): wxT("Febuary")); - break; - case Mar: - ret = (flags == Name_Abbr ? wxT("Mar"): wxT("March")); - break; - case Apr: - ret = (flags == Name_Abbr ? wxT("Apr"): wxT("April")); - break; - case May: - ret = (flags == Name_Abbr ? wxT("May"): wxT("May")); - break; - case Jun: - ret = (flags == Name_Abbr ? wxT("Jun"): wxT("June")); - break; - case Jul: - ret = (flags == Name_Abbr ? wxT("Jul"): wxT("July")); - break; - case Aug: - ret = (flags == Name_Abbr ? wxT("Aug"): wxT("August")); - break; - case Sep: - ret = (flags == Name_Abbr ? wxT("Sep"): wxT("September")); - break; - case Oct: - ret = (flags == Name_Abbr ? wxT("Oct"): wxT("October")); - break; - case Nov: - ret = (flags == Name_Abbr ? wxT("Nov"): wxT("November")); - break; - case Dec: - ret = (flags == Name_Abbr ? wxT("Dec"): wxT("December")); - break; - } - return ret; -#endif // HAVE_STRFTIME/!HAVE_STRFTIME + { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", + "Saturday" }, + { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" }, + }; + + const int idx = NameArrayIndexFromFlag(flags); + if ( idx == -1 ) + return wxString(); + + return weekdayNames[idx][wday]; } /* static */ wxString wxDateTime::GetWeekDayName(wxDateTime::WeekDay wday, wxDateTime::NameFlags flags) { - wxCHECK_MSG( wday != Inv_WeekDay, wxEmptyString, _T("invalid weekday") ); -#ifdef HAVE_STRFTIME +#ifdef wxHAS_STRFTIME + wxCHECK_MSG( wday != Inv_WeekDay, wxEmptyString, wxT("invalid weekday") ); + // 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!) @@ -1033,35 +912,10 @@ wxString wxDateTime::GetWeekDayName(wxDateTime::WeekDay wday, (void)mktime(&tm); // ... and call strftime() - return CallStrftime(flags == Name_Abbr ? _T("%a") : _T("%A"), &tm); -#else // !HAVE_STRFTIME - wxString ret; - switch(wday) - { - case Sun: - ret = (flags == Name_Abbr ? wxT("Sun") : wxT("Sunday")); - break; - case Mon: - ret = (flags == Name_Abbr ? wxT("Mon") : wxT("Monday")); - break; - case Tue: - ret = (flags == Name_Abbr ? wxT("Tue") : wxT("Tuesday")); - break; - case Wed: - ret = (flags == Name_Abbr ? wxT("Wed") : wxT("Wednesday")); - break; - case Thu: - ret = (flags == Name_Abbr ? wxT("Thu") : wxT("Thursday")); - break; - case Fri: - ret = (flags == Name_Abbr ? wxT("Fri") : wxT("Friday")); - break; - case Sat: - ret = (flags == Name_Abbr ? wxT("Sat") : wxT("Saturday")); - break; - } - return ret; -#endif // HAVE_STRFTIME/!HAVE_STRFTIME + return CallStrftime(flags == Name_Abbr ? wxT("%a") : wxT("%A"), &tm); +#else // !wxHAS_STRFTIME + return GetEnglishWeekDayName(wday, flags); +#endif // wxHAS_STRFTIME/!wxHAS_STRFTIME } /* static */ @@ -1080,7 +934,7 @@ void wxDateTime::GetAmPmStrings(wxString *am, wxString *pm) // assert, even though it is a perfectly legal use. if ( am ) { - if (wxStrftime(buffer, sizeof(buffer)/sizeof(wxChar), _T("%p"), &tm) > 0) + if (wxStrftime(buffer, WXSIZEOF(buffer), wxT("%p"), &tm) > 0) *am = wxString(buffer); else *am = wxString(); @@ -1088,13 +942,14 @@ void wxDateTime::GetAmPmStrings(wxString *am, wxString *pm) if ( pm ) { tm.tm_hour = 13; - if (wxStrftime(buffer, sizeof(buffer)/sizeof(wxChar), _T("%p"), &tm) > 0) + if (wxStrftime(buffer, WXSIZEOF(buffer), wxT("%p"), &tm) > 0) *pm = wxString(buffer); else *pm = wxString(); } } + // ---------------------------------------------------------------------------- // Country stuff: date calculations depend on the country (DST, work days, // ...), so we need to know which rules to follow. @@ -1112,24 +967,24 @@ wxDateTime::Country wxDateTime::GetCountry() struct tm tmstruct; struct tm *tm = wxLocaltime_r(&t, &tmstruct); - wxString tz = CallStrftime(_T("%Z"), tm); - if ( tz == _T("WET") || tz == _T("WEST") ) + wxString tz = CallStrftime(wxT("%Z"), tm); + if ( tz == wxT("WET") || tz == wxT("WEST") ) { ms_country = UK; } - else if ( tz == _T("CET") || tz == _T("CEST") ) + else if ( tz == wxT("CET") || tz == wxT("CEST") ) { ms_country = Country_EEC; } - else if ( tz == _T("MSK") || tz == _T("MSD") ) + else if ( tz == wxT("MSK") || tz == wxT("MSD") ) { ms_country = Russia; } - else if ( tz == _T("AST") || tz == _T("ADT") || - tz == _T("EST") || tz == _T("EDT") || - tz == _T("CST") || tz == _T("CDT") || - tz == _T("MST") || tz == _T("MDT") || - tz == _T("PST") || tz == _T("PDT") ) + else if ( tz == wxT("AST") || tz == wxT("ADT") || + tz == wxT("EST") || tz == wxT("EDT") || + tz == wxT("CST") || tz == wxT("CDT") || + tz == wxT("MST") || tz == wxT("MDT") || + tz == wxT("PST") || tz == wxT("PDT") ) { ms_country = USA; } @@ -1228,7 +1083,7 @@ wxDateTime wxDateTime::GetBeginDST(int year, Country country) if ( !dt.SetToLastWeekDay(Sun, Mar, year) ) { // weird... - wxFAIL_MSG( _T("no last Sunday in March?") ); + wxFAIL_MSG( wxT("no last Sunday in March?") ); } dt += wxTimeSpan::Hours(1); @@ -1271,7 +1126,7 @@ wxDateTime wxDateTime::GetBeginDST(int year, Country country) if ( !dt.SetToLastWeekDay(Sun, Apr, year) ) { // weird... - wxFAIL_MSG( _T("no first Sunday in April?") ); + wxFAIL_MSG( wxT("no first Sunday in April?") ); } } else if ( year > 2006 ) @@ -1282,7 +1137,7 @@ wxDateTime wxDateTime::GetBeginDST(int year, Country country) if ( !dt.SetToWeekDay(Sun, 2, Mar, year) ) { // weird... - wxFAIL_MSG( _T("no second Sunday in March?") ); + wxFAIL_MSG( wxT("no second Sunday in March?") ); } } else @@ -1290,7 +1145,7 @@ wxDateTime wxDateTime::GetBeginDST(int year, Country country) if ( !dt.SetToWeekDay(Sun, 1, Apr, year) ) { // weird... - wxFAIL_MSG( _T("no first Sunday in April?") ); + wxFAIL_MSG( wxT("no first Sunday in April?") ); } } @@ -1337,7 +1192,7 @@ wxDateTime wxDateTime::GetEndDST(int year, Country country) if ( !dt.SetToLastWeekDay(Sun, Oct, year) ) { // weirder and weirder... - wxFAIL_MSG( _T("no last Sunday in October?") ); + wxFAIL_MSG( wxT("no last Sunday in October?") ); } dt += wxTimeSpan::Hours(1); @@ -1370,7 +1225,7 @@ wxDateTime wxDateTime::GetEndDST(int year, Country country) if ( !dt.SetToWeekDay(Sun, 1, Nov, year) ) { // weird... - wxFAIL_MSG( _T("no first Sunday in November?") ); + wxFAIL_MSG( wxT("no first Sunday in November?") ); } } else @@ -1380,7 +1235,7 @@ wxDateTime wxDateTime::GetEndDST(int year, Country country) if ( !dt.SetToLastWeekDay(Sun, Oct, year) ) { // weirder and weirder... - wxFAIL_MSG( _T("no last Sunday in October?") ); + wxFAIL_MSG( wxT("no last Sunday in October?") ); } } @@ -1427,7 +1282,7 @@ wxDateTime& wxDateTime::Set(const struct tm& tm) tm2.tm_sec)); } - wxFAIL_MSG( _T("mktime() failed") ); + wxFAIL_MSG( wxT("mktime() failed") ); *this = wxInvalidDateTime; @@ -1450,13 +1305,13 @@ wxDateTime& wxDateTime::Set(wxDateTime_t hour, second < 62 && minute < 60 && millisec < 1000, - _T("Invalid time in wxDateTime::Set()") ); + wxT("Invalid time in wxDateTime::Set()") ); // get the current date from system struct tm tmstruct; struct tm *tm = GetTmNow(&tmstruct); - wxDATETIME_CHECK( tm, _T("wxLocaltime_r() failed") ); + wxDATETIME_CHECK( tm, wxT("wxLocaltime_r() failed") ); // make a copy so it isn't clobbered by the call to mktime() below struct tm tm1(*tm); @@ -1490,12 +1345,12 @@ wxDateTime& wxDateTime::Set(wxDateTime_t day, second < 62 && minute < 60 && millisec < 1000, - _T("Invalid time in wxDateTime::Set()") ); + wxT("Invalid time in wxDateTime::Set()") ); ReplaceDefaultYearMonthWithCurrent(&year, &month); wxDATETIME_CHECK( (0 < day) && (day <= GetNumberOfDays(month, year)), - _T("Invalid date in wxDateTime::Set()") ); + wxT("Invalid date in wxDateTime::Set()") ); // the range of time_t type (inclusive) static const int yearMinInRange = 1970; @@ -1634,7 +1489,7 @@ unsigned long wxDateTime::GetAsDOS() const time_t ticks = GetTicks(); struct tm tmstruct; struct tm *tm = wxLocaltime_r(&ticks, &tmstruct); - wxCHECK_MSG( tm, ULONG_MAX, _T("time can't be represented in DOS format") ); + wxCHECK_MSG( tm, ULONG_MAX, wxT("time can't be represented in DOS format") ); long year = tm->tm_year; year -= 80; @@ -1666,7 +1521,7 @@ unsigned long wxDateTime::GetAsDOS() const wxDateTime::Tm wxDateTime::GetTm(const TimeZone& tz) const { - wxASSERT_MSG( IsValid(), _T("invalid wxDateTime") ); + wxASSERT_MSG( IsValid(), wxT("invalid wxDateTime") ); time_t time = GetTicks(); if ( time != (time_t)-1 ) @@ -1680,7 +1535,7 @@ wxDateTime::Tm wxDateTime::GetTm(const TimeZone& tz) const tm = wxLocaltime_r(&time, &tmstruct); // should never happen - wxCHECK_MSG( tm, Tm(), _T("wxLocaltime_r() failed") ); + wxCHECK_MSG( tm, Tm(), wxT("wxLocaltime_r() failed") ); } else { @@ -1695,7 +1550,7 @@ wxDateTime::Tm wxDateTime::GetTm(const TimeZone& tz) const tm = wxGmtime_r(&time, &tmstruct); // should never happen - wxCHECK_MSG( tm, Tm(), _T("wxGmtime_r() failed") ); + wxCHECK_MSG( tm, Tm(), wxT("wxGmtime_r() failed") ); } else { @@ -1738,7 +1593,7 @@ wxDateTime::Tm wxDateTime::GetTm(const TimeZone& tz) const // CREDIT: code below is by Scott E. Lee (but bugs are mine) - wxASSERT_MSG( jdn > -2, _T("JDN out of range") ); + wxASSERT_MSG( jdn > -2, wxT("JDN out of range") ); // calculate the century long temp = (jdn + JDN_OFFSET) * 4 - 1; @@ -1769,8 +1624,8 @@ wxDateTime::Tm wxDateTime::GetTm(const TimeZone& tz) const year -= 4800; // 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( (0 < month) && (month <= 12), wxT("invalid month") ); + wxASSERT_MSG( (1 <= day) && (day < 32), wxT("invalid day") ); // construct Tm from these values Tm tm; @@ -1795,7 +1650,7 @@ wxDateTime::Tm wxDateTime::GetTm(const TimeZone& tz) const wxDateTime& wxDateTime::SetYear(int year) { - wxASSERT_MSG( IsValid(), _T("invalid wxDateTime") ); + wxASSERT_MSG( IsValid(), wxT("invalid wxDateTime") ); Tm tm(GetTm()); tm.year = year; @@ -1806,7 +1661,7 @@ wxDateTime& wxDateTime::SetYear(int year) wxDateTime& wxDateTime::SetMonth(Month month) { - wxASSERT_MSG( IsValid(), _T("invalid wxDateTime") ); + wxASSERT_MSG( IsValid(), wxT("invalid wxDateTime") ); Tm tm(GetTm()); tm.mon = month; @@ -1817,7 +1672,7 @@ wxDateTime& wxDateTime::SetMonth(Month month) wxDateTime& wxDateTime::SetDay(wxDateTime_t mday) { - wxASSERT_MSG( IsValid(), _T("invalid wxDateTime") ); + wxASSERT_MSG( IsValid(), wxT("invalid wxDateTime") ); Tm tm(GetTm()); tm.mday = mday; @@ -1828,7 +1683,7 @@ wxDateTime& wxDateTime::SetDay(wxDateTime_t mday) wxDateTime& wxDateTime::SetHour(wxDateTime_t hour) { - wxASSERT_MSG( IsValid(), _T("invalid wxDateTime") ); + wxASSERT_MSG( IsValid(), wxT("invalid wxDateTime") ); Tm tm(GetTm()); tm.hour = hour; @@ -1839,7 +1694,7 @@ wxDateTime& wxDateTime::SetHour(wxDateTime_t hour) wxDateTime& wxDateTime::SetMinute(wxDateTime_t min) { - wxASSERT_MSG( IsValid(), _T("invalid wxDateTime") ); + wxASSERT_MSG( IsValid(), wxT("invalid wxDateTime") ); Tm tm(GetTm()); tm.min = min; @@ -1850,7 +1705,7 @@ wxDateTime& wxDateTime::SetMinute(wxDateTime_t min) wxDateTime& wxDateTime::SetSecond(wxDateTime_t sec) { - wxASSERT_MSG( IsValid(), _T("invalid wxDateTime") ); + wxASSERT_MSG( IsValid(), wxT("invalid wxDateTime") ); Tm tm(GetTm()); tm.sec = sec; @@ -1861,7 +1716,7 @@ wxDateTime& wxDateTime::SetSecond(wxDateTime_t sec) wxDateTime& wxDateTime::SetMillisecond(wxDateTime_t millisecond) { - wxASSERT_MSG( IsValid(), _T("invalid wxDateTime") ); + wxASSERT_MSG( IsValid(), wxT("invalid wxDateTime") ); // we don't need to use GetTm() for this one m_time -= m_time % 1000l; @@ -1899,7 +1754,7 @@ wxDateTime& wxDateTime::Add(const wxDateSpan& diff) Set(tm); wxASSERT_MSG( IsSameTime(tm), - _T("Add(wxDateSpan) shouldn't modify time") ); + wxT("Add(wxDateSpan) shouldn't modify time") ); return *this; } @@ -1919,7 +1774,7 @@ wxDateTime wxDateTime::SetToWeekOfYear(int year, wxDateTime_t numWeek, WeekDay wd) { wxASSERT_MSG( numWeek > 0, - _T("invalid week number: weeks are counted from 1") ); + wxT("invalid week number: weeks are counted from 1") ); // Jan 4 always lies in the 1st week of the year wxDateTime dt(4, Jan, year); @@ -1983,7 +1838,7 @@ wxDateTime& wxDateTime::SetToLastMonthDay(Month month, wxDateTime& wxDateTime::SetToWeekDayInSameWeek(WeekDay weekday, WeekFlags flags) { - wxDATETIME_CHECK( weekday != Inv_WeekDay, _T("invalid weekday") ); + wxDATETIME_CHECK( weekday != Inv_WeekDay, wxT("invalid weekday") ); int wdayDst = weekday, wdayThis = GetWeekDay(); @@ -2023,7 +1878,7 @@ wxDateTime& wxDateTime::SetToWeekDayInSameWeek(WeekDay weekday, WeekFlags flags) wxDateTime& wxDateTime::SetToNextWeekDay(WeekDay weekday) { - wxDATETIME_CHECK( weekday != Inv_WeekDay, _T("invalid weekday") ); + wxDATETIME_CHECK( weekday != Inv_WeekDay, wxT("invalid weekday") ); int diff; WeekDay wdayThis = GetWeekDay(); @@ -2047,7 +1902,7 @@ wxDateTime& wxDateTime::SetToNextWeekDay(WeekDay weekday) wxDateTime& wxDateTime::SetToPrevWeekDay(WeekDay weekday) { - wxDATETIME_CHECK( weekday != Inv_WeekDay, _T("invalid weekday") ); + wxDATETIME_CHECK( weekday != Inv_WeekDay, wxT("invalid weekday") ); int diff; WeekDay wdayThis = GetWeekDay(); @@ -2074,7 +1929,7 @@ bool wxDateTime::SetToWeekDay(WeekDay weekday, Month month, int year) { - wxCHECK_MSG( weekday != Inv_WeekDay, false, _T("invalid weekday") ); + wxCHECK_MSG( weekday != Inv_WeekDay, false, wxT("invalid weekday") ); // we don't check explicitly that -5 <= n <= 5 because we will return false // anyhow in such case - but may be should still give an assert for it? @@ -2231,7 +2086,7 @@ wxDateTime& wxDateTime::SetToYearDay(wxDateTime::wxDateTime_t yday) { int year = GetYear(); wxDATETIME_CHECK( (0 < yday) && (yday <= GetNumberOfDays(year)), - _T("invalid year day") ); + wxT("invalid year day") ); bool isLeap = IsLeapYear(year); for ( Month mon = Jan; mon < Inv_Month; wxNextMonth(mon) ) @@ -2272,7 +2127,7 @@ double wxDateTime::GetRataDie() const int wxDateTime::IsDST(wxDateTime::Country country) const { wxCHECK_MSG( country == Country_Default, -1, - _T("country support not implemented") ); + wxT("country support not implemented") ); // use the C RTL for the dates in the standard range time_t timet = GetTicks(); @@ -2281,7 +2136,7 @@ int wxDateTime::IsDST(wxDateTime::Country country) const struct tm tmstruct; tm *tm = wxLocaltime_r(&timet, &tmstruct); - wxCHECK_MSG( tm, -1, _T("wxLocaltime_r() failed") ); + wxCHECK_MSG( tm, -1, wxT("wxLocaltime_r() failed") ); return tm->tm_isdst; } @@ -2424,7 +2279,7 @@ size_t wxDateTimeWorkDays::DoGetHolidaysInRange(const wxDateTime& dtStart, { if ( dtStart > dtEnd ) { - wxFAIL_MSG( _T("invalid date range in GetHolidaysInRange") ); + wxFAIL_MSG( wxT("invalid date range in GetHolidaysInRange") ); return 0u; } @@ -2464,7 +2319,7 @@ size_t wxDateTimeWorkDays::DoGetHolidaysInRange(const wxDateTime& dtStart, WXDLLIMPEXP_BASE void wxNextMonth(wxDateTime::Month& m) { - wxASSERT_MSG( m < wxDateTime::Inv_Month, _T("invalid month") ); + wxASSERT_MSG( m < wxDateTime::Inv_Month, wxT("invalid month") ); // no wrapping or the for loop above would never end! m = (wxDateTime::Month)(m + 1); @@ -2472,7 +2327,7 @@ WXDLLIMPEXP_BASE void wxNextMonth(wxDateTime::Month& m) WXDLLIMPEXP_BASE void wxPrevMonth(wxDateTime::Month& m) { - wxASSERT_MSG( m < wxDateTime::Inv_Month, _T("invalid month") ); + wxASSERT_MSG( m < wxDateTime::Inv_Month, wxT("invalid month") ); m = m == wxDateTime::Jan ? wxDateTime::Inv_Month : (wxDateTime::Month)(m - 1); @@ -2480,7 +2335,7 @@ WXDLLIMPEXP_BASE void wxPrevMonth(wxDateTime::Month& m) WXDLLIMPEXP_BASE void wxNextWDay(wxDateTime::WeekDay& wd) { - wxASSERT_MSG( wd < wxDateTime::Inv_WeekDay, _T("invalid week day") ); + wxASSERT_MSG( wd < wxDateTime::Inv_WeekDay, wxT("invalid week day") ); // no wrapping or the for loop above would never end! wd = (wxDateTime::WeekDay)(wd + 1); @@ -2488,7 +2343,7 @@ WXDLLIMPEXP_BASE void wxNextWDay(wxDateTime::WeekDay& wd) WXDLLIMPEXP_BASE void wxPrevWDay(wxDateTime::WeekDay& wd) { - wxASSERT_MSG( wd < wxDateTime::Inv_WeekDay, _T("invalid week day") ); + wxASSERT_MSG( wd < wxDateTime::Inv_WeekDay, wxT("invalid week day") ); wd = wd == wxDateTime::Sun ? wxDateTime::Inv_WeekDay : (wxDateTime::WeekDay)(wd - 1);