+ MakeFromTimezone(TimeZone::Make(offset*SEC_PER_MIN));
+
+ const size_t endpos = p - date.wx_str();
+ if ( end )
+ *end = date.begin() + endpos;
+
+ return date.c_str() + endpos;
+}
+
+#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;
+ }
+ }