- 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());