+#ifdef __WINDOWS__
+
+// Get's current locale's date formatting string and stores it in fmt if
+// the locale is set; otherwise or in case of failure, leaves fmt unchanged
+static void GetLocaleDateFormat(wxString *fmt)
+{
+ // 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
+ wxChar delim[5]; // fields deliminer, 4 chars max
+ if ( GetLocaleInfo(lcid, LOCALE_SDATE, delim, 5) )
+ {
+ wxChar centurybuf[2]; // use %y or %Y, 1 char max
+ wxChar century = 'y';
+ if ( GetLocaleInfo(lcid, LOCALE_ICENTURY, centurybuf, 2) )
+ {
+ if ( centurybuf[0] == _T('1') )
+ century = 'Y';
+ // else 'y' as above
+ }
+
+ wxChar order[2]; // order code, 1 char max
+ if ( GetLocaleInfo(lcid, LOCALE_IDATE, order, 2) )
+ {
+ if ( order[0] == _T('0') ) // M-D-Y
+ {
+ *fmt = wxString::Format(_T("%%m%s%%d%s%%%c"),
+ delim, delim, century);
+ }
+ else if ( order[0] == _T('1') ) // D-M-Y
+ {
+ *fmt = wxString::Format(_T("%%d%s%%m%s%%%c"),
+ delim, delim, century);
+ }
+ else if ( order[0] == _T('2') ) // Y-M-D
+ {
+ *fmt = wxString::Format(_T("%%%c%s%%m%s%%d"),
+ century, delim, delim);
+ }
+ else
+ {
+ wxFAIL_MSG(_T("unexpected GetLocaleInfo return value"));
+ }
+ }
+ }
+ // if we failed, leave fmtDate value unchanged and
+ // try our luck with the default set above
+ }
+}
+
+#endif // __WINDOWS__
+