]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/datetimefmt.cpp
Fixed wxUSE_STD_DEFAULT==0 compilation.
[wxWidgets.git] / src / common / datetimefmt.cpp
index aa0dd5c83e55f3d77297cdbc2614138845eabfb9..254c7034369f516ddc61a8fb9e6e35960acd9293 100644 (file)
@@ -46,7 +46,6 @@
 #endif // WX_PRECOMP
 
 #include "wx/thread.h"
 #endif // WX_PRECOMP
 
 #include "wx/thread.h"
-#include "wx/tokenzr.h"
 
 #include <ctype.h>
 
 
 #include <ctype.h>
 
@@ -92,41 +91,41 @@ static const int MIN_PER_HOUR = 60;
 namespace
 {
 
 namespace
 {
 
-#ifdef HAVE_STRPTIME
+// all the functions below taking non-const wxString::const_iterator p advance
+// it until the end of the match
 
 
-#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
-
-// strptime() wrapper: call strptime() for the string starting at the given
-// iterator and fill output tm struct with the results and modify input to
-// point to the end of the string consumed by strptime() if successful,
-// otherwise return false and don't modify anything
-bool
-CallStrptime(const wxString& str,
-             wxString::const_iterator& p,
-             const char *fmt,
-             tm *tm)
+// scans all digits (but no more than len) and returns the resulting number
+bool GetNumericToken(size_t len,
+                     wxString::const_iterator& p,
+                     const wxString::const_iterator& end,
+                     unsigned long *number)
 {
 {
-    // convert from iterator to char pointer: this is simple as wxCStrData
-    // already supports this
-    const char * const start = str.c_str() + (p - str.begin());
-
-    const char * const end = strptime(start, fmt, tm);
-    if ( !end )
-        return false;
+    size_t n = 1;
+    wxString s;
+    while ( p != end && wxIsdigit(*p) )
+    {
+        s += *p++;
 
 
-    // convert back from char pointer to iterator: unfortunately we have no way
-    // to do it efficiently currently so create a temporary string just to
-    // compute the number of characters between start and end
-    p += wxString(start, end - start).length();
+        if ( len && ++n > len )
+            break;
+    }
 
 
-    return true;
+    return !s.empty() && s.ToULong(number);
 }
 
 }
 
-#endif // HAVE_STRPTIME
+// scans all alphabetic characters and returns the resulting string
+wxString
+GetAlphaToken(wxString::const_iterator& p,
+              const wxString::const_iterator& end)
+{
+    wxString s;
+    while ( p != end && wxIsalpha(*p) )
+    {
+        s += *p++;
+    }
+
+    return s;
+}
 
 enum
 {
 
 enum
 {
@@ -141,8 +140,16 @@ enum
 // month name or DateLang_English to parse it as a standard English name or
 // their combination to interpret it in any way
 wxDateTime::Month
 // month name or DateLang_English to parse it as a standard English name or
 // their combination to interpret it in any way
 wxDateTime::Month
-GetMonthFromName(const wxString& name, int flags, int lang)
+GetMonthFromName(wxString::const_iterator& p,
+                 const wxString::const_iterator& end,
+                 int flags,
+                 int lang)
 {
 {
+    const wxString::const_iterator pOrig = p;
+    const wxString name = GetAlphaToken(p, end);
+    if ( name.empty() )
+        return wxDateTime::Inv_Month;
+
     wxDateTime::Month mon;
     for ( mon = wxDateTime::Jan; mon < wxDateTime::Inv_Month; wxNextMonth(mon) )
     {
     wxDateTime::Month mon;
     for ( mon = wxDateTime::Jan; mon < wxDateTime::Inv_Month; wxNextMonth(mon) )
     {
@@ -176,13 +183,35 @@ GetMonthFromName(const wxString& name, int flags, int lang)
 
             if ( lang & DateLang_Local )
             {
 
             if ( lang & DateLang_Local )
             {
-                if ( name.CmpNoCase(wxDateTime::GetMonthName(mon,
-                        wxDateTime::Name_Abbr)) == 0 )
+                // some locales (e.g. French one) use periods for the
+                // abbreviated month names but it's never part of name so
+                // compare it specially
+                wxString nameAbbr = wxDateTime::GetMonthName(mon,
+                    wxDateTime::Name_Abbr);
+                const bool hasPeriod = *nameAbbr.rbegin() == '.';
+                if ( hasPeriod )
+                    nameAbbr.erase(nameAbbr.end() - 1);
+
+                if ( name.CmpNoCase(nameAbbr) == 0 )
+                {
+                    if ( hasPeriod )
+                    {
+                        // skip trailing period if it was part of the match
+                        if ( *p == '.' )
+                            ++p;
+                        else // no match as no matching period
+                            continue;
+                    }
+
                     break;
                     break;
+                }
             }
         }
     }
 
             }
         }
     }
 
+    if ( mon == wxDateTime::Inv_Month )
+        p = pOrig;
+
     return mon;
 }
 
     return mon;
 }
 
@@ -191,8 +220,15 @@ GetMonthFromName(const wxString& name, int flags, int lang)
 // flags and lang parameters have the same meaning as for GetMonthFromName()
 // above
 wxDateTime::WeekDay
 // flags and lang parameters have the same meaning as for GetMonthFromName()
 // above
 wxDateTime::WeekDay
-GetWeekDayFromName(const wxString& name, int flags, int lang)
+GetWeekDayFromName(wxString::const_iterator& p,
+                   const wxString::const_iterator& end,
+                   int flags, int lang)
 {
 {
+    const wxString::const_iterator pOrig = p;
+    const wxString name = GetAlphaToken(p, end);
+    if ( name.empty() )
+        return wxDateTime::Inv_WeekDay;
+
     wxDateTime::WeekDay wd;
     for ( wd = wxDateTime::Sun; wd < wxDateTime::Inv_WeekDay; wxNextWDay(wd) )
     {
     wxDateTime::WeekDay wd;
     for ( wd = wxDateTime::Sun; wd < wxDateTime::Inv_WeekDay; wxNextWDay(wd) )
     {
@@ -231,40 +267,10 @@ GetWeekDayFromName(const wxString& name, int flags, int lang)
         }
     }
 
         }
     }
 
-    return wd;
-}
-
-// scans all digits (but no more than len) and returns the resulting number
-bool GetNumericToken(size_t len,
-                     wxString::const_iterator& p,
-                     const wxString::const_iterator& end,
-                     unsigned long *number)
-{
-    size_t n = 1;
-    wxString s;
-    while ( p != end && wxIsdigit(*p) )
-    {
-        s += *p++;
-
-        if ( len && ++n > len )
-            break;
-    }
-
-    return !s.empty() && s.ToULong(number);
-}
-
-// scans all alphabetic characters and returns the resulting string
-wxString
-GetAlphaToken(wxString::const_iterator& p,
-              const wxString::const_iterator& end)
-{
-    wxString s;
-    while ( p != end && wxIsalpha(*p) )
-    {
-        s += *p++;
-    }
+    if ( wd == wxDateTime::Inv_WeekDay )
+        p = pOrig;
 
 
-    return s;
+    return wd;
 }
 
 // parses string starting at given iterator using the specified format and,
 }
 
 // parses string starting at given iterator using the specified format and,
@@ -281,15 +287,13 @@ ParseFormatAt(wxString::const_iterator& p,
               // FIXME-VC6: using wxString() instead of wxEmptyString in the
               //            line below results in error C2062: type 'class
               //            wxString (__cdecl *)(void)' unexpected
               // FIXME-VC6: using wxString() instead of wxEmptyString in the
               //            line below results in error C2062: type 'class
               //            wxString (__cdecl *)(void)' unexpected
-              const wxString& fmtAlt = wxEmptyString,
-              const wxString& fmtAlt2 = wxString())
+              const wxString& fmtAlt = wxEmptyString)
 {
     const wxString str(p, end);
     wxString::const_iterator endParse;
     wxDateTime dt;
     if ( dt.ParseFormat(str, fmt, &endParse) ||
 {
     const wxString str(p, end);
     wxString::const_iterator endParse;
     wxDateTime dt;
     if ( dt.ParseFormat(str, fmt, &endParse) ||
-            (!fmtAlt.empty() && dt.ParseFormat(str, fmtAlt, &endParse)) ||
-                (!fmtAlt2.empty() && dt.ParseFormat(str, fmtAlt2, &endParse)) )
+            (!fmtAlt.empty() && dt.ParseFormat(str, fmtAlt, &endParse)) )
     {
         p += endParse - str.begin();
     }
     {
         p += endParse - str.begin();
     }
@@ -304,17 +308,23 @@ ParseFormatAt(wxString::const_iterator& p,
 // wxDateTime to/from text representations
 // ----------------------------------------------------------------------------
 
 // wxDateTime to/from text representations
 // ----------------------------------------------------------------------------
 
-wxString wxDateTime::Format(const wxString& format, const TimeZone& tz) const
+wxString wxDateTime::Format(const wxString& formatp, const TimeZone& tz) const
 {
 {
-    wxCHECK_MSG( !format.empty(), wxEmptyString,
-                 _T("NULL format in wxDateTime::Format") );
+    wxCHECK_MSG( !formatp.empty(), wxEmptyString,
+                 wxT("NULL format in wxDateTime::Format") );
 
 
+    wxString format = formatp;
+#ifdef __WXOSX__
+    format.Replace("%c",wxLocale::GetInfo(wxLOCALE_DATE_TIME_FMT));
+    format.Replace("%x",wxLocale::GetInfo(wxLOCALE_SHORT_DATE_FMT));
+    format.Replace("%X",wxLocale::GetInfo(wxLOCALE_TIME_FMT));
+#endif
     // we have to use our own implementation if the date is out of range of
     // we have to use our own implementation if the date is out of range of
-    // strftime() or if we use non standard specificators
-#ifdef HAVE_STRFTIME
+    // strftime() or if we use non standard specifiers
+#ifdef wxHAS_STRFTIME
     time_t time = GetTicks();
 
     time_t time = GetTicks();
 
-    if ( (time != (time_t)-1) && !wxStrstr(format, _T("%l")) )
+    if ( (time != (time_t)-1) && !wxStrstr(format, wxT("%l")) )
     {
         // use strftime()
         struct tm tmstruct;
     {
         // use strftime()
         struct tm tmstruct;
@@ -325,7 +335,7 @@ wxString wxDateTime::Format(const wxString& format, const TimeZone& tz) const
             tm = wxLocaltime_r(&time, &tmstruct);
 
             // should never happen
             tm = wxLocaltime_r(&time, &tmstruct);
 
             // should never happen
-            wxCHECK_MSG( tm, wxEmptyString, _T("wxLocaltime_r() failed") );
+            wxCHECK_MSG( tm, wxEmptyString, wxT("wxLocaltime_r() failed") );
         }
         else
         {
         }
         else
         {
@@ -341,7 +351,7 @@ wxString wxDateTime::Format(const wxString& format, const TimeZone& tz) const
                 tm = wxGmtime_r(&time, &tmstruct);
 
                 // should never happen
                 tm = wxGmtime_r(&time, &tmstruct);
 
                 // should never happen
-                wxCHECK_MSG( tm, wxEmptyString, _T("wxGmtime_r() failed") );
+                wxCHECK_MSG( tm, wxEmptyString, wxT("wxGmtime_r() failed") );
             }
             else
             {
             }
             else
             {
@@ -355,7 +365,7 @@ wxString wxDateTime::Format(const wxString& format, const TimeZone& tz) const
         }
     }
     //else: use generic code below
         }
     }
     //else: use generic code below
-#endif // HAVE_STRFTIME
+#endif // wxHAS_STRFTIME
 
     // we only parse ANSI C format specifications here, no POSIX 2
     // complications, no GNU extensions but we do add support for a "%l" format
 
     // we only parse ANSI C format specifications here, no POSIX 2
     // complications, no GNU extensions but we do add support for a "%l" format
@@ -364,12 +374,11 @@ wxString wxDateTime::Format(const wxString& format, const TimeZone& tz) const
 
     // used for calls to strftime() when we only deal with time
     struct tm tmTimeOnly;
 
     // used for calls to strftime() when we only deal with time
     struct tm tmTimeOnly;
+    memset(&tmTimeOnly, 0, sizeof(tmTimeOnly));
     tmTimeOnly.tm_hour = tm.hour;
     tmTimeOnly.tm_min = tm.min;
     tmTimeOnly.tm_sec = tm.sec;
     tmTimeOnly.tm_hour = tm.hour;
     tmTimeOnly.tm_min = tm.min;
     tmTimeOnly.tm_sec = tm.sec;
-    tmTimeOnly.tm_wday = 0;
-    tmTimeOnly.tm_yday = 0;
-    tmTimeOnly.tm_mday = 1;         // any date will do
+    tmTimeOnly.tm_mday = 1;         // any date will do, use 1976-01-01
     tmTimeOnly.tm_mon = 0;
     tmTimeOnly.tm_year = 76;
     tmTimeOnly.tm_isdst = 0;        // no DST, we adjust for tz ourselves
     tmTimeOnly.tm_mon = 0;
     tmTimeOnly.tm_year = 76;
     tmTimeOnly.tm_isdst = 0;        // no DST, we adjust for tz ourselves
@@ -377,7 +386,7 @@ wxString wxDateTime::Format(const wxString& format, const TimeZone& tz) const
     wxString tmp, res, fmt;
     for ( wxString::const_iterator p = format.begin(); p != format.end(); ++p )
     {
     wxString tmp, res, fmt;
     for ( wxString::const_iterator p = format.begin(); p != format.end(); ++p )
     {
-        if ( *p != _T('%') )
+        if ( *p != wxT('%') )
         {
             // copy as is
             res += *p;
         {
             // copy as is
             res += *p;
@@ -388,17 +397,17 @@ wxString wxDateTime::Format(const wxString& format, const TimeZone& tz) const
         // set the default format
         switch ( (*++p).GetValue() )
         {
         // set the default format
         switch ( (*++p).GetValue() )
         {
-            case _T('Y'):               // year has 4 digits
-                fmt = _T("%04d");
+            case wxT('Y'):               // year has 4 digits
+                fmt = wxT("%04d");
                 break;
 
                 break;
 
-            case _T('j'):               // day of year has 3 digits
-            case _T('l'):               // milliseconds have 3 digits
-                fmt = _T("%03d");
+            case wxT('j'):               // day of year has 3 digits
+            case wxT('l'):               // milliseconds have 3 digits
+                fmt = wxT("%03d");
                 break;
 
                 break;
 
-            case _T('w'):               // week day as number has only one
-                fmt = _T("%d");
+            case wxT('w'):               // week day as number has only one
+                fmt = wxT("%d");
                 break;
 
             default:
                 break;
 
             default:
@@ -406,7 +415,7 @@ wxString wxDateTime::Format(const wxString& format, const TimeZone& tz) const
                 // the format is "%02d" (for all the rest) or we have the
                 // field width preceding the format in which case it will
                 // override the default format anyhow
                 // the format is "%02d" (for all the rest) or we have the
                 // field width preceding the format in which case it will
                 // override the default format anyhow
-                fmt = _T("%02d");
+                fmt = wxT("%02d");
         }
 
         bool restart = true;
         }
 
         bool restart = true;
@@ -417,22 +426,22 @@ wxString wxDateTime::Format(const wxString& format, const TimeZone& tz) const
             // start of the format specification
             switch ( (*p).GetValue() )
             {
             // start of the format specification
             switch ( (*p).GetValue() )
             {
-                case _T('a'):       // a weekday name
-                case _T('A'):
+                case wxT('a'):       // a weekday name
+                case wxT('A'):
                     // second parameter should be true for abbreviated names
                     res += GetWeekDayName(tm.GetWeekDay(),
                     // second parameter should be true for abbreviated names
                     res += GetWeekDayName(tm.GetWeekDay(),
-                                          *p == _T('a') ? Name_Abbr : Name_Full);
+                                          *p == wxT('a') ? Name_Abbr : Name_Full);
                     break;
 
                     break;
 
-                case _T('b'):       // a month name
-                case _T('B'):
+                case wxT('b'):       // a month name
+                case wxT('B'):
                     res += GetMonthName(tm.mon,
                     res += GetMonthName(tm.mon,
-                                        *p == _T('b') ? Name_Abbr : Name_Full);
+                                        *p == wxT('b') ? Name_Abbr : Name_Full);
                     break;
 
                     break;
 
-                case _T('c'):       // locale default date and time  representation
-                case _T('x'):       // locale default date representation
-#ifdef HAVE_STRFTIME
+                case wxT('c'):       // locale default date and time  representation
+                case wxT('x'):       // locale default date representation
+#ifdef wxHAS_STRFTIME
                     //
                     // the problem: there is no way to know what do these format
                     // specifications correspond to for the current locale.
                     //
                     // the problem: there is no way to know what do these format
                     // specifications correspond to for the current locale.
@@ -503,7 +512,7 @@ wxString wxDateTime::Format(const wxString& format, const TimeZone& tz) const
                             year -= 28;
 
                         wxASSERT_MSG( year >= 1970 && year < 2000,
                             year -= 28;
 
                         wxASSERT_MSG( year >= 1970 && year < 2000,
-                                      _T("logic error in wxDateTime::Format") );
+                                      wxT("logic error in wxDateTime::Format") );
 
 
                         // use strftime() to format the same date but in supported
 
 
                         // use strftime() to format the same date but in supported
@@ -524,8 +533,8 @@ wxString wxDateTime::Format(const wxString& format, const TimeZone& tz) const
                         tmAdjusted.tm_mon = tm.mon;
                         tmAdjusted.tm_year = year - 1900;
                         tmAdjusted.tm_isdst = 0; // no DST, already adjusted
                         tmAdjusted.tm_mon = tm.mon;
                         tmAdjusted.tm_year = year - 1900;
                         tmAdjusted.tm_isdst = 0; // no DST, already adjusted
-                        wxString str = CallStrftime(*p == _T('c') ? _T("%c")
-                                                                  : _T("%x"),
+                        wxString str = CallStrftime(*p == wxT('c') ? wxT("%c")
+                                                                  : wxT("%x"),
                                                     &tmAdjusted);
 
                         // now replace the replacement year with the real year:
                                                     &tmAdjusted);
 
                         // now replace the replacement year with the real year:
@@ -548,22 +557,22 @@ wxString wxDateTime::Format(const wxString& format, const TimeZone& tz) const
 
                         res += str;
                     }
 
                         res += str;
                     }
-#else // !HAVE_STRFTIME
+#else // !wxHAS_STRFTIME
                     // Use "%m/%d/%y %H:%M:%S" format instead
                     res += wxString::Format(wxT("%02d/%02d/%04d %02d:%02d:%02d"),
                             tm.mon+1,tm.mday, tm.year, tm.hour, tm.min, tm.sec);
                     // Use "%m/%d/%y %H:%M:%S" format instead
                     res += wxString::Format(wxT("%02d/%02d/%04d %02d:%02d:%02d"),
                             tm.mon+1,tm.mday, tm.year, tm.hour, tm.min, tm.sec);
-#endif // HAVE_STRFTIME/!HAVE_STRFTIME
+#endif // wxHAS_STRFTIME/!wxHAS_STRFTIME
                     break;
 
                     break;
 
-                case _T('d'):       // day of a month (01-31)
+                case wxT('d'):       // day of a month (01-31)
                     res += wxString::Format(fmt, tm.mday);
                     break;
 
                     res += wxString::Format(fmt, tm.mday);
                     break;
 
-                case _T('H'):       // hour in 24h format (00-23)
+                case wxT('H'):       // hour in 24h format (00-23)
                     res += wxString::Format(fmt, tm.hour);
                     break;
 
                     res += wxString::Format(fmt, tm.hour);
                     break;
 
-                case _T('I'):       // hour in 12h format (01-12)
+                case wxT('I'):       // hour in 12h format (01-12)
                     {
                         // 24h -> 12h, 0h -> 12h too
                         int hour12 = tm.hour > 12 ? tm.hour - 12
                     {
                         // 24h -> 12h, 0h -> 12h too
                         int hour12 = tm.hour > 12 ? tm.hour - 12
@@ -572,76 +581,77 @@ wxString wxDateTime::Format(const wxString& format, const TimeZone& tz) const
                     }
                     break;
 
                     }
                     break;
 
-                case _T('j'):       // day of the year
+                case wxT('j'):       // day of the year
                     res += wxString::Format(fmt, GetDayOfYear(tz));
                     break;
 
                     res += wxString::Format(fmt, GetDayOfYear(tz));
                     break;
 
-                case _T('l'):       // milliseconds (NOT STANDARD)
+                case wxT('l'):       // milliseconds (NOT STANDARD)
                     res += wxString::Format(fmt, GetMillisecond(tz));
                     break;
 
                     res += wxString::Format(fmt, GetMillisecond(tz));
                     break;
 
-                case _T('m'):       // month as a number (01-12)
+                case wxT('m'):       // month as a number (01-12)
                     res += wxString::Format(fmt, tm.mon + 1);
                     break;
 
                     res += wxString::Format(fmt, tm.mon + 1);
                     break;
 
-                case _T('M'):       // minute as a decimal number (00-59)
+                case wxT('M'):       // minute as a decimal number (00-59)
                     res += wxString::Format(fmt, tm.min);
                     break;
 
                     res += wxString::Format(fmt, tm.min);
                     break;
 
-                case _T('p'):       // AM or PM string
-#ifdef HAVE_STRFTIME
-                    res += CallStrftime(_T("%p"), &tmTimeOnly);
-#else // !HAVE_STRFTIME
+                case wxT('p'):       // AM or PM string
+#ifdef wxHAS_STRFTIME
+                    res += CallStrftime(wxT("%p"), &tmTimeOnly);
+#else // !wxHAS_STRFTIME
                     res += (tmTimeOnly.tm_hour > 12) ? wxT("pm") : wxT("am");
                     res += (tmTimeOnly.tm_hour > 12) ? wxT("pm") : wxT("am");
-#endif // HAVE_STRFTIME/!HAVE_STRFTIME
+#endif // wxHAS_STRFTIME/!wxHAS_STRFTIME
                     break;
 
                     break;
 
-                case _T('S'):       // second as a decimal number (00-61)
+                case wxT('S'):       // second as a decimal number (00-61)
                     res += wxString::Format(fmt, tm.sec);
                     break;
 
                     res += wxString::Format(fmt, tm.sec);
                     break;
 
-                case _T('U'):       // week number in the year (Sunday 1st week day)
+                case wxT('U'):       // week number in the year (Sunday 1st week day)
                     res += wxString::Format(fmt, GetWeekOfYear(Sunday_First, tz));
                     break;
 
                     res += wxString::Format(fmt, GetWeekOfYear(Sunday_First, tz));
                     break;
 
-                case _T('W'):       // week number in the year (Monday 1st week day)
+                case wxT('W'):       // week number in the year (Monday 1st week day)
                     res += wxString::Format(fmt, GetWeekOfYear(Monday_First, tz));
                     break;
 
                     res += wxString::Format(fmt, GetWeekOfYear(Monday_First, tz));
                     break;
 
-                case _T('w'):       // weekday as a number (0-6), Sunday = 0
+                case wxT('w'):       // weekday as a number (0-6), Sunday = 0
                     res += wxString::Format(fmt, tm.GetWeekDay());
                     break;
 
                     res += wxString::Format(fmt, tm.GetWeekDay());
                     break;
 
-                // case _T('x'): -- handled with "%c"
+                // case wxT('x'): -- handled with "%c"
 
 
-                case _T('X'):       // locale default time representation
+                case wxT('X'):       // locale default time representation
                     // just use strftime() to format the time for us
                     // just use strftime() to format the time for us
-#ifdef HAVE_STRFTIME
-                    res += CallStrftime(_T("%X"), &tmTimeOnly);
-#else // !HAVE_STRFTIME
+#ifdef wxHAS_STRFTIME
+                    res += CallStrftime(wxT("%X"), &tmTimeOnly);
+#else // !wxHAS_STRFTIME
                     res += wxString::Format(wxT("%02d:%02d:%02d"),tm.hour, tm.min, tm.sec);
                     res += wxString::Format(wxT("%02d:%02d:%02d"),tm.hour, tm.min, tm.sec);
-#endif // HAVE_STRFTIME/!HAVE_STRFTIME
+#endif // wxHAS_STRFTIME/!wxHAS_STRFTIME
                     break;
 
                     break;
 
-                case _T('y'):       // year without century (00-99)
+                case wxT('y'):       // year without century (00-99)
                     res += wxString::Format(fmt, tm.year % 100);
                     break;
 
                     res += wxString::Format(fmt, tm.year % 100);
                     break;
 
-                case _T('Y'):       // year with century
+                case wxT('Y'):       // year with century
                     res += wxString::Format(fmt, tm.year);
                     break;
 
                     res += wxString::Format(fmt, tm.year);
                     break;
 
-                case _T('Z'):       // timezone name
-#ifdef HAVE_STRFTIME
-                    res += CallStrftime(_T("%Z"), &tmTimeOnly);
+                case wxT('Z'):       // timezone name
+#ifdef wxHAS_STRFTIME
+                    res += CallStrftime(wxT("%Z"), &tmTimeOnly);
 #endif
                     break;
 
                 default:
                     // is it the format width?
 #endif
                     break;
 
                 default:
                     // is it the format width?
-                    fmt.Empty();
-                    while ( *p == _T('-') || *p == _T('+') ||
-                            *p == _T(' ') || wxIsdigit(*p) )
+                    for ( fmt.clear();
+                          *p == wxT('-') || *p == wxT('+') ||
+                            *p == wxT(' ') || wxIsdigit(*p);
+                          ++p )
                     {
                         fmt += *p;
                     }
                     {
                         fmt += *p;
                     }
@@ -649,8 +659,8 @@ wxString wxDateTime::Format(const wxString& format, const TimeZone& tz) const
                     if ( !fmt.empty() )
                     {
                         // we've only got the flags and width so far in fmt
                     if ( !fmt.empty() )
                     {
                         // we've only got the flags and width so far in fmt
-                        fmt.Prepend(_T('%'));
-                        fmt.Append(_T('d'));
+                        fmt.Prepend(wxT('%'));
+                        fmt.Append(wxT('d'));
 
                         restart = true;
 
 
                         restart = true;
 
@@ -658,19 +668,19 @@ wxString wxDateTime::Format(const wxString& format, const TimeZone& tz) const
                     }
 
                     // no, it wasn't the width
                     }
 
                     // no, it wasn't the width
-                    wxFAIL_MSG(_T("unknown format specificator"));
+                    wxFAIL_MSG(wxT("unknown format specifier"));
 
                     // fall through and just copy it nevertheless
 
 
                     // fall through and just copy it nevertheless
 
-                case _T('%'):       // a percent sign
+                case wxT('%'):       // a percent sign
                     res += *p;
                     break;
 
                 case 0:             // the end of string
                     res += *p;
                     break;
 
                 case 0:             // the end of string
-                    wxFAIL_MSG(_T("missing format at the end of string"));
+                    wxFAIL_MSG(wxT("missing format at the end of string"));
 
                     // just put the '%' which was the last char in format
 
                     // just put the '%' which was the last char in format
-                    res += _T('%');
+                    res += wxT('%');
                     break;
             }
         }
                     break;
             }
         }
@@ -688,19 +698,17 @@ wxString wxDateTime::Format(const wxString& format, const TimeZone& tz) const
 bool
 wxDateTime::ParseRfc822Date(const wxString& date, wxString::const_iterator *end)
 {
 bool
 wxDateTime::ParseRfc822Date(const wxString& date, wxString::const_iterator *end)
 {
+    const wxString::const_iterator pEnd = date.end();
     wxString::const_iterator p = date.begin();
 
     // 1. week day
     wxString::const_iterator p = date.begin();
 
     // 1. week day
-    static const int WDAY_LEN = 3;
-    const wxString::const_iterator endWday = p + WDAY_LEN;
-    const wxString wday(p, endWday);
-    if ( GetWeekDayFromName(wday, Name_Abbr, DateLang_English) == Inv_WeekDay )
+    const wxDateTime::WeekDay
+        wd = GetWeekDayFromName(p, pEnd, Name_Abbr, DateLang_English);
+    if ( wd == Inv_WeekDay )
         return false;
     //else: ignore week day for now, we could also check that it really
     //      corresponds to the specified date
 
         return false;
     //else: ignore week day for now, we could also check that it really
     //      corresponds to the specified date
 
-    p = endWday;
-
     // 2. separating comma
     if ( *p++ != ',' || *p++ != ' ' )
         return false;
     // 2. separating comma
     if ( *p++ != ',' || *p++ != ' ' )
         return false;
@@ -720,15 +728,10 @@ wxDateTime::ParseRfc822Date(const wxString& date, wxString::const_iterator *end)
         return false;
 
     // 4. month name
         return false;
 
     // 4. month name
-    static const int MONTH_LEN = 3;
-    const wxString::const_iterator endMonth = p + MONTH_LEN;
-    const wxString monName(p, endMonth);
-    Month mon = GetMonthFromName(monName, Name_Abbr, DateLang_English);
+    const Month mon = GetMonthFromName(p, pEnd, Name_Abbr, DateLang_English);
     if ( mon == Inv_Month )
         return false;
 
     if ( mon == Inv_Month )
         return false;
 
-    p = endMonth;
-
     if ( *p++ != ' ' )
         return false;
 
     if ( *p++ != ' ' )
         return false;
 
@@ -808,7 +811,7 @@ wxDateTime::ParseRfc822Date(const wxString& date, wxString::const_iterator *end)
         return false;
 
     // 7. now the interesting part: the timezone
         return false;
 
     // 7. now the interesting part: the timezone
-    int offset wxDUMMY_INITIALIZE(0);
+    int offset = 0; // just to suppress warnings
     if ( *p == '-' || *p == '+' )
     {
         // the explicit offset given: it has the form of hhmm
     if ( *p == '-' || *p == '+' )
     {
         // the explicit offset given: it has the form of hhmm
@@ -849,7 +852,7 @@ wxDateTime::ParseRfc822Date(const wxString& date, wxString::const_iterator *end)
                 +1, +2, +3, +4, +5, +6, +7, +8, +9, +10, +11, +12, 0
             };
 
                 +1, +2, +3, +4, +5, +6, +7, +8, +9, +10, +11, +12, 0
             };
 
-            if ( *p < _T('A') || *p > _T('Z') || *p == _T('J') )
+            if ( *p < wxT('A') || *p > wxT('Z') || *p == wxT('J') )
                 return false;
 
             offset = offsets[*p++ - 'A'];
                 return false;
 
             offset = offsets[*p++ - 'A'];
@@ -858,27 +861,27 @@ wxDateTime::ParseRfc822Date(const wxString& date, wxString::const_iterator *end)
         {
             // abbreviation
             const wxString tz(p, date.end());
         {
             // abbreviation
             const wxString tz(p, date.end());
-            if ( tz == _T("UT") || tz == _T("UTC") || tz == _T("GMT") )
+            if ( tz == wxT("UT") || tz == wxT("UTC") || tz == wxT("GMT") )
                 offset = 0;
                 offset = 0;
-            else if ( tz == _T("AST") )
+            else if ( tz == wxT("AST") )
                 offset = AST - GMT0;
                 offset = AST - GMT0;
-            else if ( tz == _T("ADT") )
+            else if ( tz == wxT("ADT") )
                 offset = ADT - GMT0;
                 offset = ADT - GMT0;
-            else if ( tz == _T("EST") )
+            else if ( tz == wxT("EST") )
                 offset = EST - GMT0;
                 offset = EST - GMT0;
-            else if ( tz == _T("EDT") )
+            else if ( tz == wxT("EDT") )
                 offset = EDT - GMT0;
                 offset = EDT - GMT0;
-            else if ( tz == _T("CST") )
+            else if ( tz == wxT("CST") )
                 offset = CST - GMT0;
                 offset = CST - GMT0;
-            else if ( tz == _T("CDT") )
+            else if ( tz == wxT("CDT") )
                 offset = CDT - GMT0;
                 offset = CDT - GMT0;
-            else if ( tz == _T("MST") )
+            else if ( tz == wxT("MST") )
                 offset = MST - GMT0;
                 offset = MST - GMT0;
-            else if ( tz == _T("MDT") )
+            else if ( tz == wxT("MDT") )
                 offset = MDT - GMT0;
                 offset = MDT - GMT0;
-            else if ( tz == _T("PST") )
+            else if ( tz == wxT("PST") )
                 offset = PST - GMT0;
                 offset = PST - GMT0;
-            else if ( tz == _T("PDT") )
+            else if ( tz == wxT("PDT") )
                 offset = PDT - GMT0;
             else
                 return false;
                 offset = PDT - GMT0;
             else
                 return false;
@@ -901,387 +904,6 @@ wxDateTime::ParseRfc822Date(const wxString& date, wxString::const_iterator *end)
     return true;
 }
 
     return true;
 }
 
-#ifdef __WINDOWS__
-
-// returns the string containing strftime() format used for short dates in the
-// current locale or an empty string
-static wxString GetLocaleDateFormat()
-{
-    wxString fmtWX;
-
-    // there is no setlocale() under Windows CE, so just always query the
-    // system there
-#ifndef __WXWINCE__
-    if ( strcmp(setlocale(LC_ALL, NULL), "C") != 0 )
-#endif
-    {
-        // The locale was programatically set to non-C. We assume that this was
-        // done using wxLocale, in which case thread's current locale is also
-        // set to correct LCID value and we can use GetLocaleInfo to determine
-        // the correct formatting string:
-#ifdef __WXWINCE__
-        LCID lcid = LOCALE_USER_DEFAULT;
-#else
-        LCID lcid = GetThreadLocale();
-#endif
-        // according to MSDN 80 chars is max allowed for short date format
-        wxChar fmt[81];
-        if ( ::GetLocaleInfo(lcid, LOCALE_SSHORTDATE, fmt, WXSIZEOF(fmt)) )
-        {
-            wxChar chLast = _T('\0');
-            size_t lastCount = 0;
-            for ( const wxChar *p = fmt; /* NUL handled inside */; p++ )
-            {
-                if ( *p == chLast )
-                {
-                    lastCount++;
-                    continue;
-                }
-
-                switch ( *p )
-                {
-                    // these characters come in groups, start counting them
-                    case _T('d'):
-                    case _T('M'):
-                    case _T('y'):
-                    case _T('g'):
-                        chLast = *p;
-                        lastCount = 1;
-                        break;
-
-                    default:
-                        // first deal with any special characters we have had
-                        if ( lastCount )
-                        {
-                            switch ( chLast )
-                            {
-                                case _T('d'):
-                                    switch ( lastCount )
-                                    {
-                                        case 1: // d
-                                        case 2: // dd
-                                            // these two are the same as we
-                                            // don't distinguish between 1 and
-                                            // 2 digits for days
-                                            fmtWX += _T("%d");
-                                            break;
-
-                                        case 3: // ddd
-                                            fmtWX += _T("%a");
-                                            break;
-
-                                        case 4: // dddd
-                                            fmtWX += _T("%A");
-                                            break;
-
-                                        default:
-                                            wxFAIL_MSG( _T("too many 'd's") );
-                                    }
-                                    break;
-
-                                case _T('M'):
-                                    switch ( lastCount )
-                                    {
-                                        case 1: // M
-                                        case 2: // MM
-                                            // as for 'd' and 'dd' above
-                                            fmtWX += _T("%m");
-                                            break;
-
-                                        case 3:
-                                            fmtWX += _T("%b");
-                                            break;
-
-                                        case 4:
-                                            fmtWX += _T("%B");
-                                            break;
-
-                                        default:
-                                            wxFAIL_MSG( _T("too many 'M's") );
-                                    }
-                                    break;
-
-                                case _T('y'):
-                                    switch ( lastCount )
-                                    {
-                                        case 1: // y
-                                        case 2: // yy
-                                            fmtWX += _T("%y");
-                                            break;
-
-                                        case 4: // yyyy
-                                            fmtWX += _T("%Y");
-                                            break;
-
-                                        default:
-                                            wxFAIL_MSG( _T("wrong number of 'y's") );
-                                    }
-                                    break;
-
-                                case _T('g'):
-                                    // strftime() doesn't have era string,
-                                    // ignore this format
-                                    wxASSERT_MSG( lastCount <= 2,
-                                                  _T("too many 'g's") );
-                                    break;
-
-                                default:
-                                    wxFAIL_MSG( _T("unreachable") );
-                            }
-
-                            chLast = _T('\0');
-                            lastCount = 0;
-                        }
-
-                        // not a special character so must be just a separator,
-                        // treat as is
-                        if ( *p != _T('\0') )
-                        {
-                            if ( *p == _T('%') )
-                            {
-                                // this one needs to be escaped
-                                fmtWX += _T('%');
-                            }
-
-                            fmtWX += *p;
-                        }
-                }
-
-                if ( *p == _T('\0') )
-                    break;
-            }
-        }
-        //else: GetLocaleInfo() failed, leave fmtDate value unchanged and
-        //      try our luck with the default formats
-    }
-    //else: default C locale, default formats should work
-
-    return fmtWX;
-}
-
-#endif // __WINDOWS__
-
-#ifdef __WXOSX__
-
-#include "wx/osx/private.h"
-
-// under OSX locale formats are defined using
-// http://unicode.org/reports/tr35/tr35-6.html#Date_Format_Patterns
-// 
-// so we need a translation function, bluntly copied from the windows
-// version above and enhanced with the additional elements needed
-
-static wxString TranslateFromUnicodeFormat( const wxString& fmt)
-{
-
-    wxString fmtWX;
-
-    wxChar chLast = _T('\0');
-    size_t lastCount = 0;
-    for ( wxString::const_iterator p = fmt.begin(); /* NUL handled inside */; p++ )
-    {
-        if ( *p == chLast )
-        {
-            lastCount++;
-            continue;
-        }
-
-        switch ( (char) *p )
-        {
-            // these characters come in groups, start counting them
-            case _T('d'):
-            case _T('M'):
-            case _T('y'):
-            case _T('g'):
-            case _T('h'):
-            case _T('H'):
-            case _T('m'):
-            case _T('s'):
-                chLast = *p;
-                lastCount = 1;
-                break;
-
-            default:
-                // first deal with any special characters we have had
-                if ( lastCount )
-                {
-                    switch ( chLast )
-                    {
-                        case _T('d'):
-                            switch ( lastCount )
-                            {
-                                case 1: // d
-                                case 2: // dd
-                                    // these two are the same as we
-                                    // don't distinguish between 1 and
-                                    // 2 digits for days
-                                    fmtWX += _T("%d");
-                                    break;
-
-                                case 3: // ddd
-                                    fmtWX += _T("%a");
-                                    break;
-
-                                case 4: // dddd
-                                    fmtWX += _T("%A");
-                                    break;
-
-                                default:
-                                    wxFAIL_MSG( _T("too many 'd's") );
-                            }
-                            break;
-
-                        case _T('M'):
-                            switch ( lastCount )
-                            {
-                                case 1: // M
-                                case 2: // MM
-                                    // as for 'd' and 'dd' above
-                                    fmtWX += _T("%m");
-                                    break;
-
-                                case 3:
-                                    fmtWX += _T("%b");
-                                    break;
-
-                                case 4:
-                                    fmtWX += _T("%B");
-                                    break;
-
-                                default:
-                                    wxFAIL_MSG( _T("too many 'M's") );
-                            }
-                            break;
-
-                        case _T('y'):
-                            switch ( lastCount )
-                            {
-                                case 1: // y
-                                case 2: // yy
-                                    fmtWX += _T("%y");
-                                    break;
-
-                                case 4: // yyyy
-                                    fmtWX += _T("%Y");
-                                    break;
-
-                                default:
-                                    wxFAIL_MSG( _T("wrong number of 'y's") );
-                            }
-                            break;
-
-                        case _T('H'):
-                            switch ( lastCount )
-                            {
-                                case 1: // H
-                                case 2: // HH
-                                    fmtWX += _T("%H");
-                                    break;
-
-                                default:
-                                    wxFAIL_MSG( _T("wrong number of 'H's") );
-                            }
-                            break;
-                            
-                       case _T('h'):
-                            switch ( lastCount )
-                            {
-                                case 1: // h
-                                case 2: // hh
-                                    fmtWX += _T("%h");
-                                    break;
-
-                                default:
-                                    wxFAIL_MSG( _T("wrong number of 'h's") );
-                            }
-                            break;
-
-                       case _T('m'):
-                            switch ( lastCount )
-                            {
-                                case 1: // m
-                                case 2: // mm
-                                    fmtWX += _T("%M");
-                                    break;
-
-                                default:
-                                    wxFAIL_MSG( _T("wrong number of 'm's") );
-                            }
-                            break;
-                            
-                       case _T('s'):
-                            switch ( lastCount )
-                            {
-                                case 1: // s
-                                case 2: // ss
-                                    fmtWX += _T("%S");
-                                    break;
-
-                                default:
-                                    wxFAIL_MSG( _T("wrong number of 's's") );
-                            }
-                            break;
-                            
-                        case _T('g'):
-                            // strftime() doesn't have era string,
-                            // ignore this format
-                            wxASSERT_MSG( lastCount <= 2,
-                                          _T("too many 'g's") );
-                            break;
-
-                        default:
-                            wxFAIL_MSG( _T("unreachable") );
-                    }
-
-                    chLast = _T('\0');
-                    lastCount = 0;
-                }
-
-                // not a special character so must be just a separator,
-                // treat as is
-                if ( *p != _T('\0') )
-                {
-                    if ( *p == _T('%') )
-                    {
-                        // this one needs to be escaped
-                        fmtWX += _T('%');
-                    }
-
-                    fmtWX += *p;
-                }
-        }
-
-        if ( *p == _T('\0') )
-            break;
-    }
-
-    return fmtWX;
-}
-
-static wxString GetLocaleDateFormat()
-{
-    wxCFRef<CFLocaleRef> currentLocale( CFLocaleCopyCurrent() );
-    wxCFRef<CFDateFormatterRef> dateFormatter( CFDateFormatterCreate
-        (NULL, currentLocale, kCFDateFormatterShortStyle, kCFDateFormatterNoStyle));
-    wxCFStringRef cfs = wxCFRetain( CFDateFormatterGetFormat(dateFormatter ));
-    return TranslateFromUnicodeFormat(cfs.AsString());
-}
-
-static wxString GetLocaleFullDateFormat()
-{
-    wxCFRef<CFLocaleRef> currentLocale( CFLocaleCopyCurrent() );
-    wxCFRef<CFDateFormatterRef> dateFormatter( CFDateFormatterCreate
-        (NULL, currentLocale, kCFDateFormatterLongStyle, kCFDateFormatterMediumStyle));
-    wxCFStringRef cfs = wxCFRetain( CFDateFormatterGetFormat(dateFormatter ));
-    return TranslateFromUnicodeFormat(cfs.AsString());
-}
-
-
-
-#endif // __WXOSX__
-
 bool
 wxDateTime::ParseFormat(const wxString& date,
                         const wxString& format,
 bool
 wxDateTime::ParseFormat(const wxString& date,
                         const wxString& format,
@@ -1323,13 +945,13 @@ wxDateTime::ParseFormat(const wxString& date,
     const wxString::const_iterator end = date.end();
     for ( wxString::const_iterator fmt = format.begin(); fmt != format.end(); ++fmt )
     {
     const wxString::const_iterator end = date.end();
     for ( wxString::const_iterator fmt = format.begin(); fmt != format.end(); ++fmt )
     {
-        if ( *fmt != _T('%') )
+        if ( *fmt != wxT('%') )
         {
             if ( wxIsspace(*fmt) )
             {
                 // a white space in the format string matches 0 or more white
                 // spaces in the input
         {
             if ( wxIsspace(*fmt) )
             {
                 // a white space in the format string matches 0 or more white
                 // spaces in the input
-                while ( wxIsspace(*input) )
+                while ( input != end && wxIsspace(*input) )
                 {
                     input++;
                 }
                 {
                     input++;
                 }
@@ -1338,7 +960,7 @@ wxDateTime::ParseFormat(const wxString& date,
             {
                 // any other character (not whitespace, not '%') must be
                 // matched by itself in the input
             {
                 // any other character (not whitespace, not '%') must be
                 // matched by itself in the input
-                if ( *input++ != *fmt )
+                if ( input == end || *input++ != *fmt )
                 {
                     // no match
                     return false;
                 {
                     // no match
                     return false;
@@ -1364,16 +986,16 @@ wxDateTime::ParseFormat(const wxString& date,
         {
             switch ( (*fmt).GetValue() )
             {
         {
             switch ( (*fmt).GetValue() )
             {
-                case _T('Y'):               // year has 4 digits
+                case wxT('Y'):               // year has 4 digits
                     width = 4;
                     break;
 
                     width = 4;
                     break;
 
-                case _T('j'):               // day of year has 3 digits
-                case _T('l'):               // milliseconds have 3 digits
+                case wxT('j'):               // day of year has 3 digits
+                case wxT('l'):               // milliseconds have 3 digits
                     width = 3;
                     break;
 
                     width = 3;
                     break;
 
-                case _T('w'):               // week day as number has only one
+                case wxT('w'):               // week day as number has only one
                     width = 1;
                     break;
 
                     width = 1;
                     break;
 
@@ -1386,12 +1008,12 @@ wxDateTime::ParseFormat(const wxString& date,
         // then the format itself
         switch ( (*fmt).GetValue() )
         {
         // then the format itself
         switch ( (*fmt).GetValue() )
         {
-            case _T('a'):       // a weekday name
-            case _T('A'):
+            case wxT('a'):       // a weekday name
+            case wxT('A'):
                 {
                     wday = GetWeekDayFromName
                            (
                 {
                     wday = GetWeekDayFromName
                            (
-                            GetAlphaToken(input, end),
+                            input, end,
                             *fmt == 'a' ? Name_Abbr : Name_Full,
                             DateLang_Local
                            );
                             *fmt == 'a' ? Name_Abbr : Name_Full,
                             DateLang_Local
                            );
@@ -1404,12 +1026,12 @@ wxDateTime::ParseFormat(const wxString& date,
                 haveWDay = true;
                 break;
 
                 haveWDay = true;
                 break;
 
-            case _T('b'):       // a month name
-            case _T('B'):
+            case wxT('b'):       // a month name
+            case wxT('B'):
                 {
                     mon = GetMonthFromName
                           (
                 {
                     mon = GetMonthFromName
                           (
-                            GetAlphaToken(input, end),
+                            input, end,
                             *fmt == 'b' ? Name_Abbr : Name_Full,
                             DateLang_Local
                           );
                             *fmt == 'b' ? Name_Abbr : Name_Full,
                             DateLang_Local
                           );
@@ -1422,80 +1044,49 @@ wxDateTime::ParseFormat(const wxString& date,
                 haveMon = true;
                 break;
 
                 haveMon = true;
                 break;
 
-            case _T('c'):       // locale default date and time  representation
+            case wxT('c'):       // locale default date and time  representation
                 {
                 {
-#ifdef HAVE_STRPTIME
-                    struct tm tm;
+                    wxDateTime dt;
 
 
-                    // try using strptime() -- it may fail even if the input is
-                    // correct but the date is out of range, so we will fall back
-                    // to our generic code anyhow
-                    if ( CallStrptime(date, input, "%c", &tm) )
+#if wxUSE_INTL
+                    const wxString
+                        fmtDateTime = wxLocale::GetInfo(wxLOCALE_DATE_TIME_FMT);
+                    if ( !fmtDateTime.empty() )
+                        dt = ParseFormatAt(input, end, fmtDateTime);
+#endif // wxUSE_INTL
+                    if ( !dt.IsValid() )
                     {
                     {
-                        hour = tm.tm_hour;
-                        min = tm.tm_min;
-                        sec = tm.tm_sec;
-
-                        year = 1900 + tm.tm_year;
-                        mon = (Month)tm.tm_mon;
-                        mday = tm.tm_mday;
+                        // also try the format which corresponds to ctime()
+                        // output (i.e. the "C" locale default)
+                        dt = ParseFormatAt(input, end, wxS("%a %b %d %H:%M:%S %Y"));
                     }
                     }
-                    else // strptime() failed; try generic heuristic code
-#endif // HAVE_STRPTIME
+
+                    if ( !dt.IsValid() )
                     {
                     {
-                        Tm tm;
-#ifdef __WXOSX__
-                        bool hasValidDate = false;
-                        wxString fmtDate = GetLocaleFullDateFormat();
-                        if ( !fmtDate.empty() )
-                        {
-                            const wxDateTime dt = ParseFormatAt
-                                                (
-                                                    input,
-                                                    end,
-                                                    fmtDate
-                                                );
-                            if ( dt.IsValid() )
-                            {
-                                tm = dt.GetTm();
-                                hasValidDate = true;
-                            }
-                        }
-                        
-                        if ( !hasValidDate )
-#endif // __WXOSX__
-                        {
-                            // try the format which corresponds to ctime() output
-                            // first, then the generic date/time formats
-                            const wxDateTime dt = ParseFormatAt
-                                                (
-                                                    input,
-                                                    end,
-                                                    wxS("%a %b %d %H:%M:%S %Y"),
-                                                    wxS("%x %X"),
-                                                    wxS("%X %x")
-                                                );
-                            if ( !dt.IsValid() )
-                                return false;
-                            tm = dt.GetTm();
-                        }
+                        // and finally also the two generic date/time formats
+                        dt = ParseFormatAt(input, end, wxS("%x %X"), wxS("%X %x"));
+                    }
 
 
+                    if ( !dt.IsValid() )
+                        return false;
 
 
-                        hour = tm.hour;
-                        min = tm.min;
-                        sec = tm.sec;
+                    const Tm tm = dt.GetTm();
 
 
-                        year = tm.year;
-                        mon = tm.mon;
-                        mday = tm.mday;
-                    }
+                    hour = tm.hour;
+                    min = tm.min;
+                    sec = tm.sec;
+
+                    year = tm.year;
+                    mon = tm.mon;
+                    mday = tm.mday;
 
                     haveDay = haveMon = haveYear =
                     haveHour = haveMin = haveSec = true;
                 }
                 break;
 
 
                     haveDay = haveMon = haveYear =
                     haveHour = haveMin = haveSec = true;
                 }
                 break;
 
-            case _T('d'):       // day of a month (01-31)
+            case wxT('d'):       // day of a month (01-31)
+            case 'e':           // day of a month (1-31) (GNU extension)
                 if ( !GetNumericToken(width, input, end, &num) ||
                         (num > 31) || (num < 1) )
                 {
                 if ( !GetNumericToken(width, input, end, &num) ||
                         (num > 31) || (num < 1) )
                 {
@@ -1509,7 +1100,7 @@ wxDateTime::ParseFormat(const wxString& date,
                 mday = (wxDateTime_t)num;
                 break;
 
                 mday = (wxDateTime_t)num;
                 break;
 
-            case _T('H'):       // hour in 24h format (00-23)
+            case wxT('H'):       // hour in 24h format (00-23)
                 if ( !GetNumericToken(width, input, end, &num) || (num > 23) )
                 {
                     // no match
                 if ( !GetNumericToken(width, input, end, &num) || (num > 23) )
                 {
                     // no match
@@ -1520,7 +1111,7 @@ wxDateTime::ParseFormat(const wxString& date,
                 hour = (wxDateTime_t)num;
                 break;
 
                 hour = (wxDateTime_t)num;
                 break;
 
-            case _T('I'):       // hour in 12h format (01-12)
+            case wxT('I'):       // hour in 12h format (01-12)
                 if ( !GetNumericToken(width, input, end, &num) ||
                         !num || (num > 12) )
                 {
                 if ( !GetNumericToken(width, input, end, &num) ||
                         !num || (num > 12) )
                 {
@@ -1533,7 +1124,7 @@ wxDateTime::ParseFormat(const wxString& date,
                 hour = (wxDateTime_t)(num % 12);        // 12 should be 0
                 break;
 
                 hour = (wxDateTime_t)(num % 12);        // 12 should be 0
                 break;
 
-            case _T('j'):       // day of the year
+            case wxT('j'):       // day of the year
                 if ( !GetNumericToken(width, input, end, &num) ||
                         !num || (num > 366) )
                 {
                 if ( !GetNumericToken(width, input, end, &num) ||
                         !num || (num > 366) )
                 {
@@ -1545,7 +1136,7 @@ wxDateTime::ParseFormat(const wxString& date,
                 yday = (wxDateTime_t)num;
                 break;
 
                 yday = (wxDateTime_t)num;
                 break;
 
-            case _T('l'):       // milliseconds (0-999)
+            case wxT('l'):       // milliseconds (0-999)
                 if ( !GetNumericToken(width, input, end, &num) )
                     return false;
 
                 if ( !GetNumericToken(width, input, end, &num) )
                     return false;
 
@@ -1553,7 +1144,7 @@ wxDateTime::ParseFormat(const wxString& date,
                 msec = (wxDateTime_t)num;
                 break;
 
                 msec = (wxDateTime_t)num;
                 break;
 
-            case _T('m'):       // month as a number (01-12)
+            case wxT('m'):       // month as a number (01-12)
                 if ( !GetNumericToken(width, input, end, &num) ||
                         !num || (num > 12) )
                 {
                 if ( !GetNumericToken(width, input, end, &num) ||
                         !num || (num > 12) )
                 {
@@ -1565,7 +1156,7 @@ wxDateTime::ParseFormat(const wxString& date,
                 mon = (Month)(num - 1);
                 break;
 
                 mon = (Month)(num - 1);
                 break;
 
-            case _T('M'):       // minute as a decimal number (00-59)
+            case wxT('M'):       // minute as a decimal number (00-59)
                 if ( !GetNumericToken(width, input, end, &num) ||
                         (num > 59) )
                 {
                 if ( !GetNumericToken(width, input, end, &num) ||
                         (num > 59) )
                 {
@@ -1577,33 +1168,33 @@ wxDateTime::ParseFormat(const wxString& date,
                 min = (wxDateTime_t)num;
                 break;
 
                 min = (wxDateTime_t)num;
                 break;
 
-            case _T('p'):       // AM or PM string
+            case wxT('p'):       // AM or PM string
                 {
                 {
-                    wxString am, pm, token = GetAlphaToken(input, end);
+                    wxString am, pm;
+                    GetAmPmStrings(&am, &pm);
 
 
-                    // some locales have empty AM/PM tokens and thus when formatting
-                    // dates with the %p specifier nothing is generated; when trying to
-                    // parse them back, we get an empty token here... but that's not
-                    // an error.
-                    if (token.empty())
-                        break;
+                    // we can never match %p in locales which don't use AM/PM
+                    if ( am.empty() || pm.empty() )
+                        return false;
 
 
-                    GetAmPmStrings(&am, &pm);
-                    if (am.empty() && pm.empty())
-                        return false;  // no am/pm strings defined
-                    if ( token.CmpNoCase(pm) == 0 )
+                    const size_t pos = input - date.begin();
+                    if ( date.compare(pos, pm.length(), pm) == 0 )
                     {
                         isPM = true;
                     {
                         isPM = true;
+                        input += pm.length();
                     }
                     }
-                    else if ( token.CmpNoCase(am) != 0 )
+                    else if ( date.compare(pos, am.length(), am) == 0 )
+                    {
+                        input += am.length();
+                    }
+                    else // no match
                     {
                     {
-                        // no match
                         return false;
                     }
                 }
                 break;
 
                         return false;
                     }
                 }
                 break;
 
-            case _T('r'):       // time as %I:%M:%S %p
+            case wxT('r'):       // time as %I:%M:%S %p
                 {
                     wxDateTime dt;
                     if ( !dt.ParseFormat(wxString(input, end),
                 {
                     wxDateTime dt;
                     if ( !dt.ParseFormat(wxString(input, end),
@@ -1612,14 +1203,14 @@ wxDateTime::ParseFormat(const wxString& date,
 
                     haveHour = haveMin = haveSec = true;
 
 
                     haveHour = haveMin = haveSec = true;
 
-                    Tm tm = dt.GetTm();
+                    const Tm tm = dt.GetTm();
                     hour = tm.hour;
                     min = tm.min;
                     sec = tm.sec;
                 }
                 break;
 
                     hour = tm.hour;
                     min = tm.min;
                     sec = tm.sec;
                 }
                 break;
 
-            case _T('R'):       // time as %H:%M
+            case wxT('R'):       // time as %H:%M
                 {
                     const wxDateTime
                         dt = ParseFormatAt(input, end, wxS("%H:%M"));
                 {
                     const wxDateTime
                         dt = ParseFormatAt(input, end, wxS("%H:%M"));
@@ -1629,13 +1220,13 @@ wxDateTime::ParseFormat(const wxString& date,
                     haveHour =
                     haveMin = true;
 
                     haveHour =
                     haveMin = true;
 
-                    Tm tm = dt.GetTm();
+                    const Tm tm = dt.GetTm();
                     hour = tm.hour;
                     min = tm.min;
                 }
                 break;
 
                     hour = tm.hour;
                     min = tm.min;
                 }
                 break;
 
-            case _T('S'):       // second as a decimal number (00-61)
+            case wxT('S'):       // second as a decimal number (00-61)
                 if ( !GetNumericToken(width, input, end, &num) ||
                         (num > 61) )
                 {
                 if ( !GetNumericToken(width, input, end, &num) ||
                         (num > 61) )
                 {
@@ -1647,7 +1238,7 @@ wxDateTime::ParseFormat(const wxString& date,
                 sec = (wxDateTime_t)num;
                 break;
 
                 sec = (wxDateTime_t)num;
                 break;
 
-            case _T('T'):       // time as %H:%M:%S
+            case wxT('T'):       // time as %H:%M:%S
                 {
                     const wxDateTime
                         dt = ParseFormatAt(input, end, wxS("%H:%M:%S"));
                 {
                     const wxDateTime
                         dt = ParseFormatAt(input, end, wxS("%H:%M:%S"));
@@ -1658,14 +1249,14 @@ wxDateTime::ParseFormat(const wxString& date,
                     haveMin =
                     haveSec = true;
 
                     haveMin =
                     haveSec = true;
 
-                    Tm tm = dt.GetTm();
+                    const Tm tm = dt.GetTm();
                     hour = tm.hour;
                     min = tm.min;
                     sec = tm.sec;
                 }
                 break;
 
                     hour = tm.hour;
                     min = tm.min;
                     sec = tm.sec;
                 }
                 break;
 
-            case _T('w'):       // weekday as a number (0-6), Sunday = 0
+            case wxT('w'):       // weekday as a number (0-6), Sunday = 0
                 if ( !GetNumericToken(width, input, end, &num) ||
                         (wday > 6) )
                 {
                 if ( !GetNumericToken(width, input, end, &num) ||
                         (wday > 6) )
                 {
@@ -1677,78 +1268,45 @@ wxDateTime::ParseFormat(const wxString& date,
                 wday = (WeekDay)num;
                 break;
 
                 wday = (WeekDay)num;
                 break;
 
-            case _T('x'):       // locale default date representation
-#ifdef HAVE_STRPTIME
-                // try using strptime() -- it may fail even if the input is
-                // correct but the date is out of range, so we will fall back
-                // to our generic code anyhow
+            case wxT('x'):       // locale default date representation
                 {
                 {
-                    struct tm tm;
-
-                    if ( CallStrptime(date, input, "%x", &tm) )
-                    {
-                        haveDay = haveMon = haveYear = true;
-
-                        year = 1900 + tm.tm_year;
-                        mon = (Month)tm.tm_mon;
-                        mday = tm.tm_mday;
-
-                        break;
-                    }
-                }
-#endif // HAVE_STRPTIME
-
-                {
-                    wxString fmtDate,
-                             fmtDateAlt;
-
-#if defined( __WINDOWS__ ) || defined( __WXOSX__ )
-                    // The above doesn't work for all locales, try to query
-                    // the OS for the right way of formatting the date:
-                    fmtDate = GetLocaleDateFormat();
+#if wxUSE_INTL
+                    wxString
+                        fmtDate = wxLocale::GetInfo(wxLOCALE_SHORT_DATE_FMT),
+                        fmtDateAlt = wxLocale::GetInfo(wxLOCALE_LONG_DATE_FMT);
+#else // !wxUSE_INTL
+                    wxString fmtDate, fmtDateAlt;
+#endif // wxUSE_INTL/!wxUSE_INTL
                     if ( fmtDate.empty() )
                     if ( fmtDate.empty() )
-#endif // __WINDOWS__
                     {
                         if ( IsWestEuropeanCountry(GetCountry()) ||
                              GetCountry() == Russia )
                         {
                     {
                         if ( IsWestEuropeanCountry(GetCountry()) ||
                              GetCountry() == Russia )
                         {
-                            fmtDate = _T("%d/%m/%y");
-                            fmtDateAlt = _T("%m/%d/%y");
+                            fmtDate = wxS("%d/%m/%Y");
+                            fmtDateAlt = wxS("%m/%d/%Y");
                          }
                         else // assume USA
                         {
                          }
                         else // assume USA
                         {
-                            fmtDate = _T("%m/%d/%y");
-                            fmtDateAlt = _T("%d/%m/%y");
+                            fmtDate = wxS("%m/%d/%Y");
+                            fmtDateAlt = wxS("%d/%m/%Y");
                         }
                     }
 
                         }
                     }
 
-                    const wxDateTime
-                        dt = ParseFormatAt(input, end,
-                                           fmtDate, fmtDateAlt);
-                    Tm tm;
-                    
+                    wxDateTime
+                        dt = ParseFormatAt(input, end, fmtDate, fmtDateAlt);
+
                     if ( !dt.IsValid() )
                     {
                     if ( !dt.IsValid() )
                     {
-                        wxString fmtDateLong = fmtDate;
-                        wxString fmtDateLongAlt = fmtDateAlt;
-                        
+                        // try with short years too
+                        fmtDate.Replace("%Y","%y");
+                        fmtDateAlt.Replace("%Y","%y");
+                        dt = ParseFormatAt(input, end, fmtDate, fmtDateAlt);
 
 
-                        if ( !fmtDateLong.empty() )
-                        {
-                            fmtDateLong.Replace("%y","%Y");
-                            fmtDateLongAlt.Replace("%y","%Y");
-                            const wxDateTime dtLong = ParseFormatAt(input, end,
-                                           fmtDateLong, fmtDateLongAlt);
-                            if ( !dtLong.IsValid() )
-                                return false;
-                                
-                            tm = dtLong.GetTm();
-                        }
-                        else
+                        if ( !dt.IsValid() )
                             return false;
                     }
                             return false;
                     }
-                    else
-                        tm = dt.GetTm();
+
+                    const Tm tm = dt.GetTm();
 
                     haveDay =
                     haveMon =
 
                     haveDay =
                     haveMon =
@@ -1761,30 +1319,25 @@ wxDateTime::ParseFormat(const wxString& date,
 
                 break;
 
 
                 break;
 
-            case _T('X'):       // locale default time representation
-#ifdef HAVE_STRPTIME
+            case wxT('X'):       // locale default time representation
                 {
                 {
-                    // use strptime() to do it for us (FIXME !Unicode friendly)
-                    struct tm tm;
-                    if ( !CallStrptime(date, input, "%X", &tm) )
-                        return false;
-
-                    haveHour = haveMin = haveSec = true;
+#if wxUSE_INTL
+                    wxString fmtTime = wxLocale::GetInfo(wxLOCALE_TIME_FMT),
+                             fmtTimeAlt;
+#else // !wxUSE_INTL
+                    wxString fmtTime, fmtTimeAlt;
+#endif // wxUSE_INTL/!wxUSE_INTL
+                    if ( fmtTime.empty() )
+                    {
+                        // try to parse what follows as "%H:%M:%S" and, if this
+                        // fails, as "%I:%M:%S %p" - this should catch the most
+                        // common cases
+                        fmtTime = "%T";
+                        fmtTimeAlt = "%r";
+                    }
 
 
-                    hour = tm.tm_hour;
-                    min = tm.tm_min;
-                    sec = tm.tm_sec;
-                }
-#else // !HAVE_STRPTIME
-                // TODO under Win32 we can query the LOCALE_ITIME system
-                //      setting which says whether the default time format is
-                //      24 or 12 hour
-                {
-                    // try to parse what follows as "%H:%M:%S" and, if this
-                    // fails, as "%I:%M:%S %p" - this should catch the most
-                    // common cases
                     const wxDateTime
                     const wxDateTime
-                        dt = ParseFormatAt(input, end, "%T", "%r");
+                        dt = ParseFormatAt(input, end, fmtTime, fmtTimeAlt);
                     if ( !dt.IsValid() )
                         return false;
 
                     if ( !dt.IsValid() )
                         return false;
 
@@ -1792,15 +1345,14 @@ wxDateTime::ParseFormat(const wxString& date,
                     haveMin =
                     haveSec = true;
 
                     haveMin =
                     haveSec = true;
 
-                    Tm tm = dt.GetTm();
+                    const Tm tm = dt.GetTm();
                     hour = tm.hour;
                     min = tm.min;
                     sec = tm.sec;
                 }
                     hour = tm.hour;
                     min = tm.min;
                     sec = tm.sec;
                 }
-#endif // HAVE_STRPTIME/!HAVE_STRPTIME
                 break;
 
                 break;
 
-            case _T('y'):       // year without century (00-99)
+            case wxT('y'):       // year without century (00-99)
                 if ( !GetNumericToken(width, input, end, &num) ||
                         (num > 99) )
                 {
                 if ( !GetNumericToken(width, input, end, &num) ||
                         (num > 99) )
                 {
@@ -1815,7 +1367,7 @@ wxDateTime::ParseFormat(const wxString& date,
                 year = (num > 30 ? 1900 : 2000) + (wxDateTime_t)num;
                 break;
 
                 year = (num > 30 ? 1900 : 2000) + (wxDateTime_t)num;
                 break;
 
-            case _T('Y'):       // year with century
+            case wxT('Y'):       // year with century
                 if ( !GetNumericToken(width, input, end, &num) )
                 {
                     // no match
                 if ( !GetNumericToken(width, input, end, &num) )
                 {
                     // no match
@@ -1826,12 +1378,14 @@ wxDateTime::ParseFormat(const wxString& date,
                 year = (wxDateTime_t)num;
                 break;
 
                 year = (wxDateTime_t)num;
                 break;
 
-            case _T('Z'):       // timezone name
-                wxFAIL_MSG(_T("TODO"));
+            case wxT('Z'):       // timezone name
+                // FIXME: currently we just ignore everything that looks like a
+                //        time zone here
+                GetAlphaToken(input, end);
                 break;
 
                 break;
 
-            case _T('%'):       // a percent sign
-                if ( *input++ != _T('%') )
+            case wxT('%'):       // a percent sign
+                if ( *input++ != wxT('%') )
                 {
                     // no match
                     return false;
                 {
                     // no match
                     return false;
@@ -1839,7 +1393,7 @@ wxDateTime::ParseFormat(const wxString& date,
                 break;
 
             case 0:             // the end of string
                 break;
 
             case 0:             // the end of string
-                wxFAIL_MSG(_T("unexpected format end"));
+                wxFAIL_MSG(wxT("unexpected format end"));
 
                 // fall through
 
 
                 // fall through
 
@@ -1943,10 +1497,9 @@ wxDateTime::ParseDateTime(const wxString& date, wxString::const_iterator *end)
 {
     wxCHECK_MSG( end, false, "end iterator pointer must be specified" );
 
 {
     wxCHECK_MSG( end, false, "end iterator pointer must be specified" );
 
-    // Set to current day and hour, so strings like '14:00' becomes today at
-    // 14, not some other random date
-    wxDateTime dtDate = wxDateTime::Today();
-    wxDateTime dtTime = wxDateTime::Today();
+    wxDateTime
+        dtDate,
+        dtTime;
 
     wxString::const_iterator
         endTime,
 
     wxString::const_iterator
         endTime,
@@ -2002,9 +1555,10 @@ wxDateTime::ParseDate(const wxString& date, wxString::const_iterator *end)
     // all esoteric constructions ParseDateTime() knows about)
 
     const wxString::const_iterator pBegin = date.begin();
     // all esoteric constructions ParseDateTime() knows about)
 
     const wxString::const_iterator pBegin = date.begin();
+    const wxString::const_iterator pEnd = date.end();
 
     wxString::const_iterator p = pBegin;
 
     wxString::const_iterator p = pBegin;
-    while ( wxIsspace(*p) )
+    while ( p != pEnd && wxIsspace(*p) )
         p++;
 
     // some special cases
         p++;
 
     // some special cases
@@ -2019,7 +1573,7 @@ wxDateTime::ParseDate(const wxString& date, wxString::const_iterator *end)
         { wxTRANSLATE("tomorrow"),          1 },
     };
 
         { wxTRANSLATE("tomorrow"),          1 },
     };
 
-    const size_t lenRest = date.end() - p;
+    const size_t lenRest = pEnd - p;
     for ( size_t n = 0; n < WXSIZEOF(literalDates); n++ )
     {
         const wxString dateStr = wxGetTranslation(literalDates[n].str);
     for ( size_t n = 0; n < WXSIZEOF(literalDates); n++ )
     {
         const wxString dateStr = wxGetTranslation(literalDates[n].str);
@@ -2059,6 +1613,8 @@ wxDateTime::ParseDate(const wxString& date, wxString::const_iterator *end)
          haveMon = false,       // the month?
          haveYear = false;      // the year?
 
          haveMon = false,       // the month?
          haveYear = false;      // the year?
 
+    bool monWasNumeric = false; // was month specified as a number?
+
     // and the value of the items we have (init them to get rid of warnings)
     WeekDay wday = Inv_WeekDay;
     wxDateTime_t day = 0;
     // and the value of the items we have (init them to get rid of warnings)
     WeekDay wday = Inv_WeekDay;
     wxDateTime_t day = 0;
@@ -2066,18 +1622,23 @@ wxDateTime::ParseDate(const wxString& date, wxString::const_iterator *end)
     int year = 0;
 
     // tokenize the string
     int year = 0;
 
     // tokenize the string
-    size_t nPosCur = 0;
-    static const wxStringCharType *dateDelimiters = wxS(".,/-\t\r\n ");
-    wxStringTokenizer tok(wxString(p, date.end()), dateDelimiters);
-    while ( tok.HasMoreTokens() )
+    while ( p != pEnd )
     {
     {
-        wxString token = tok.GetNextToken();
-        if ( !token )
+        // skip white space and date delimiters
+        if ( wxStrchr(".,/-\t\r\n ", *p) )
+        {
+            ++p;
             continue;
             continue;
+        }
+
+        // modify copy of the iterator as we're not sure if the next token is
+        // still part of the date at all
+        wxString::const_iterator pCopy = p;
 
 
-        // is it a number?
+        // we can have either alphabetic or numeric token, start by testing if
+        // it's the latter
         unsigned long val;
         unsigned long val;
-        if ( token.ToULong(&val) )
+        if ( GetNumericToken(10 /* max length */, pCopy, pEnd, &val) )
         {
             // guess what this number is
 
         {
             // guess what this number is
 
@@ -2141,6 +1702,7 @@ wxDateTime::ParseDate(const wxString& date, wxString::const_iterator *end)
             else if ( isMonth )
             {
                 haveMon = true;
             else if ( isMonth )
             {
                 haveMon = true;
+                monWasNumeric = true;
 
                 mon = (Month)(val - 1);
             }
 
                 mon = (Month)(val - 1);
             }
@@ -2150,7 +1712,7 @@ wxDateTime::ParseDate(const wxString& date, wxString::const_iterator *end)
             // be careful not to overwrite the current mon value
             Month mon2 = GetMonthFromName
                          (
             // be careful not to overwrite the current mon value
             Month mon2 = GetMonthFromName
                          (
-                            token,
+                            pCopy, pEnd,
                             Name_Full | Name_Abbr,
                             DateLang_Local | DateLang_English
                          );
                             Name_Full | Name_Abbr,
                             DateLang_Local | DateLang_English
                          );
@@ -2159,20 +1721,18 @@ wxDateTime::ParseDate(const wxString& date, wxString::const_iterator *end)
                 // it's a month
                 if ( haveMon )
                 {
                 // it's a month
                 if ( haveMon )
                 {
-                    // but we already have a month - maybe we guessed wrong?
-                    if ( !haveDay )
-                    {
-                        // 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;
-                    }
-                    else
-                    {
-                        // could possible be the year (doesn't the year come
-                        // before the month in the japanese format?) (FIXME)
+                    // but we already have a month - maybe we guessed wrong
+                    // when we had interpreted that numeric value as a month
+                    // and it was the day number instead?
+                    if ( haveDay || !monWasNumeric )
                         break;
                         break;
-                    }
+
+                    // assume we did and change our mind: reinterpret the month
+                    // value as a day (notice that there is no need to check
+                    // that it is valid as month values are always < 12, but
+                    // the days are counted from 1 unlike the months)
+                    day = (wxDateTime_t)(mon + 1);
+                    haveDay = true;
                 }
 
                 mon = mon2;
                 }
 
                 mon = mon2;
@@ -2183,7 +1743,7 @@ wxDateTime::ParseDate(const wxString& date, wxString::const_iterator *end)
             {
                 WeekDay wday2 = GetWeekDayFromName
                                 (
             {
                 WeekDay wday2 = GetWeekDayFromName
                                 (
-                                    token,
+                                    pCopy, pEnd,
                                     Name_Full | Name_Abbr,
                                     DateLang_Local | DateLang_English
                                 );
                                     Name_Full | Name_Abbr,
                                     DateLang_Local | DateLang_English
                                 );
@@ -2191,9 +1751,7 @@ wxDateTime::ParseDate(const wxString& date, wxString::const_iterator *end)
                 {
                     // a week day
                     if ( haveWDay )
                 {
                     // a week day
                     if ( haveWDay )
-                    {
                         break;
                         break;
-                    }
 
                     wday = wday2;
 
 
                     wday = wday2;
 
@@ -2202,7 +1760,7 @@ wxDateTime::ParseDate(const wxString& date, wxString::const_iterator *end)
                 else // not a valid weekday name
                 {
                     // try the ordinals
                 else // not a valid weekday name
                 {
                     // try the ordinals
-                    static const char *ordinals[] =
+                    static const char *const ordinals[] =
                     {
                         wxTRANSLATE("first"),
                         wxTRANSLATE("second"),
                     {
                         wxTRANSLATE("first"),
                         wxTRANSLATE("second"),
@@ -2231,8 +1789,11 @@ wxDateTime::ParseDate(const wxString& date, wxString::const_iterator *end)
                     size_t n;
                     for ( n = 0; n < WXSIZEOF(ordinals); n++ )
                     {
                     size_t n;
                     for ( n = 0; n < WXSIZEOF(ordinals); n++ )
                     {
-                        if ( token.CmpNoCase(ordinals[n]) == 0 )
+                        const wxString ord = wxGetTranslation(ordinals[n]);
+                        const size_t len = ord.length();
+                        if ( date.compare(p - pBegin, len, ord) == 0 )
                         {
                         {
+                            p += len;
                             break;
                         }
                     }
                             break;
                         }
                     }
@@ -2259,7 +1820,8 @@ wxDateTime::ParseDate(const wxString& date, wxString::const_iterator *end)
             }
         }
 
             }
         }
 
-        nPosCur = tok.GetPosition();
+        // advance iterator past a successfully parsed token
+        p = pCopy;
     }
 
     // either no more tokens or the scan was stopped by something we couldn't
     }
 
     // either no more tokens or the scan was stopped by something we couldn't
@@ -2335,15 +1897,6 @@ wxDateTime::ParseDate(const wxString& date, wxString::const_iterator *end)
         SetToWeekDayInSameWeek(wday);
     }
 
         SetToWeekDayInSameWeek(wday);
     }
 
-    // return the pointer to the first unparsed char
-    p += nPosCur;
-    if ( nPosCur && wxStrchr(dateDelimiters, *(p - 1)) )
-    {
-        // if we couldn't parse the token after the delimiter, put back the
-        // delimiter as well
-        p--;
-    }
-
     *end = p;
 
     return true;
     *end = p;
 
     return true;
@@ -2369,14 +1922,13 @@ wxDateTime::ParseTime(const wxString& time, wxString::const_iterator *end)
     for ( size_t n = 0; n < WXSIZEOF(stdTimes); n++ )
     {
         const wxString timeString = wxGetTranslation(stdTimes[n].name);
     for ( size_t n = 0; n < WXSIZEOF(stdTimes); n++ )
     {
         const wxString timeString = wxGetTranslation(stdTimes[n].name);
-        const wxString::const_iterator p = time.begin() + timeString.length();
-        if ( timeString.CmpNoCase(wxString(time.begin(), p)) == 0 )
+        if ( timeString.CmpNoCase(wxString(time, timeString.length())) == 0 )
         {
             // casts required by DigitalMars
             Set(stdTimes[n].hour, wxDateTime_t(0), wxDateTime_t(0));
 
             if ( end )
         {
             // casts required by DigitalMars
             Set(stdTimes[n].hour, wxDateTime_t(0), wxDateTime_t(0));
 
             if ( end )
-                *end = p;
+                *end = time.begin() + timeString.length();
 
             return true;
         }
 
             return true;
         }
@@ -2384,12 +1936,12 @@ wxDateTime::ParseTime(const wxString& time, wxString::const_iterator *end)
 
     // try all time formats we may think about in the order from longest to
     // shortest
 
     // try all time formats we may think about in the order from longest to
     // shortest
-    static const char *timeFormats[] =
+    static const char *const timeFormats[] =
     {
         "%I:%M:%S %p",  // 12hour with AM/PM
         "%H:%M:%S",     // could be the same or 24 hour one so try it too
         "%I:%M %p",     // 12hour with AM/PM but without seconds
     {
         "%I:%M:%S %p",  // 12hour with AM/PM
         "%H:%M:%S",     // could be the same or 24 hour one so try it too
         "%I:%M %p",     // 12hour with AM/PM but without seconds
-        "%H:%M:%S",     // and a possibly 24 hour version without seconds
+        "%H:%M",        // and a possibly 24 hour version without seconds
         "%X",           // possibly something from above or maybe something
                         // completely different -- try it last
 
         "%X",           // possibly something from above or maybe something
                         // completely different -- try it last
 
@@ -2473,7 +2025,7 @@ wxString wxTimeSpan::Format(const wxString& format) const
     }
 
     wxCHECK_MSG( !format.empty(), wxEmptyString,
     }
 
     wxCHECK_MSG( !format.empty(), wxEmptyString,
-                 _T("NULL format in wxTimeSpan::Format") );
+                 wxT("NULL format in wxTimeSpan::Format") );
 
     wxString str;
     str.Alloc(format.length());
 
     wxString str;
     str.Alloc(format.length());
@@ -2498,10 +2050,10 @@ wxString wxTimeSpan::Format(const wxString& format) const
     {
         wxChar ch = *pch;
 
     {
         wxChar ch = *pch;
 
-        if ( ch == _T('%') )
+        if ( ch == wxT('%') )
         {
             // the start of the format specification of the printf() below
         {
             // the start of the format specification of the printf() below
-            wxString fmtPrefix(_T('%'));
+            wxString fmtPrefix(wxT('%'));
 
             // the number
             long n;
 
             // the number
             long n;
@@ -2513,16 +2065,16 @@ wxString wxTimeSpan::Format(const wxString& format) const
             switch ( ch )
             {
                 default:
             switch ( ch )
             {
                 default:
-                    wxFAIL_MSG( _T("invalid format character") );
+                    wxFAIL_MSG( wxT("invalid format character") );
                     // fall through
 
                     // fall through
 
-                case _T('%'):
+                case wxT('%'):
                     str += ch;
 
                     // skip the part below switch
                     continue;
 
                     str += ch;
 
                     // skip the part below switch
                     continue;
 
-                case _T('D'):
+                case wxT('D'):
                     n = GetDays();
                     if ( partBiggest < Part_Day )
                     {
                     n = GetDays();
                     if ( partBiggest < Part_Day )
                     {
@@ -2534,12 +2086,12 @@ wxString wxTimeSpan::Format(const wxString& format) const
                     }
                     break;
 
                     }
                     break;
 
-                case _T('E'):
+                case wxT('E'):
                     partBiggest = Part_Week;
                     n = GetWeeks();
                     break;
 
                     partBiggest = Part_Week;
                     n = GetWeeks();
                     break;
 
-                case _T('H'):
+                case wxT('H'):
                     n = GetHours();
                     if ( partBiggest < Part_Hour )
                     {
                     n = GetHours();
                     if ( partBiggest < Part_Hour )
                     {
@@ -2553,7 +2105,7 @@ wxString wxTimeSpan::Format(const wxString& format) const
                     digits = 2;
                     break;
 
                     digits = 2;
                     break;
 
-                case _T('l'):
+                case wxT('l'):
                     n = GetMilliseconds().ToLong();
                     if ( partBiggest < Part_MSec )
                     {
                     n = GetMilliseconds().ToLong();
                     if ( partBiggest < Part_MSec )
                     {
@@ -2565,7 +2117,7 @@ wxString wxTimeSpan::Format(const wxString& format) const
                     digits = 3;
                     break;
 
                     digits = 3;
                     break;
 
-                case _T('M'):
+                case wxT('M'):
                     n = GetMinutes();
                     if ( partBiggest < Part_Min )
                     {
                     n = GetMinutes();
                     if ( partBiggest < Part_Min )
                     {
@@ -2579,7 +2131,7 @@ wxString wxTimeSpan::Format(const wxString& format) const
                     digits = 2;
                     break;
 
                     digits = 2;
                     break;
 
-                case _T('S'):
+                case wxT('S'):
                     n = GetSeconds().ToLong();
                     if ( partBiggest < Part_Sec )
                     {
                     n = GetSeconds().ToLong();
                     if ( partBiggest < Part_Sec )
                     {
@@ -2596,10 +2148,10 @@ wxString wxTimeSpan::Format(const wxString& format) const
 
             if ( digits )
             {
 
             if ( digits )
             {
-                fmtPrefix << _T("0") << digits;
+                fmtPrefix << wxT("0") << digits;
             }
 
             }
 
-            str += wxString::Format(fmtPrefix + _T("ld"), n);
+            str += wxString::Format(fmtPrefix + wxT("ld"), n);
         }
         else
         {
         }
         else
         {