1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/datetimefmt.cpp
3 // Purpose: wxDateTime formatting & parsing code
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 1999 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9 // parts of code taken from sndcal library by Scott E. Lee:
11 // Copyright 1993-1995, Scott E. Lee, all rights reserved.
12 // Permission granted to use, copy, modify, distribute and sell
13 // so long as the above copyright and this permission statement
14 // are retained in all copies.
16 // Licence: wxWindows licence
17 ///////////////////////////////////////////////////////////////////////////////
19 // ============================================================================
21 // ============================================================================
23 // ----------------------------------------------------------------------------
25 // ----------------------------------------------------------------------------
27 // For compilers that support precompilation, includes "wx.h".
28 #include "wx/wxprec.h"
34 #if !defined(wxUSE_DATETIME) || wxUSE_DATETIME
38 #include "wx/msw/wrapwin.h"
40 #include "wx/string.h"
43 #include "wx/stopwatch.h" // for wxGetLocalTimeMillis()
44 #include "wx/module.h"
48 #include "wx/thread.h"
49 #include "wx/tokenzr.h"
60 #include "wx/datetime.h"
62 // ============================================================================
63 // implementation of wxDateTime
64 // ============================================================================
66 // ----------------------------------------------------------------------------
67 // helpers shared between datetime.cpp and datetimefmt.cpp
68 // ----------------------------------------------------------------------------
70 extern void InitTm(struct tm
& tm
);
72 extern int GetTimeZone();
74 extern wxString
CallStrftime(const wxString
& format
, const tm
* tm
);
76 // ----------------------------------------------------------------------------
77 // constants (see also datetime.cpp)
78 // ----------------------------------------------------------------------------
80 static const int DAYS_PER_WEEK
= 7;
82 static const int HOURS_PER_DAY
= 24;
84 static const int SEC_PER_MIN
= 60;
86 static const int MIN_PER_HOUR
= 60;
88 // ----------------------------------------------------------------------------
90 // ----------------------------------------------------------------------------
97 #if wxUSE_UNIX && !defined(HAVE_STRPTIME_DECL)
98 // configure detected that we had strptime() but not its declaration,
99 // provide it ourselves
100 extern "C" char *strptime(const char *, const char *, struct tm
*);
103 // strptime() wrapper: call strptime() for the string starting at the given
104 // iterator and fill output tm struct with the results and modify input to
105 // point to the end of the string consumed by strptime() if successful,
106 // otherwise return false and don't modify anything
108 CallStrptime(const wxString
& str
,
109 wxString::const_iterator
& p
,
113 const char *start
= str
.mb_str();
114 start
= wxStringOperations::AddToIter(start
, p
- str
.begin());
116 const char * const end
= strptime(start
, fmt
, tm
);
120 p
+= wxStringOperations::DiffIters(end
, start
);
124 #endif // HAVE_STRPTIME
126 // return the month if the string is a month name or Inv_Month otherwise
127 wxDateTime::Month
GetMonthFromName(const wxString
& name
, int flags
)
129 wxDateTime::Month mon
;
130 for ( mon
= wxDateTime::Jan
; mon
< wxDateTime::Inv_Month
; wxNextMonth(mon
) )
132 // case-insensitive comparison either one of or with both abbreviated
134 if ( flags
& wxDateTime::Name_Full
)
136 if ( name
.CmpNoCase(wxDateTime::
137 GetMonthName(mon
, wxDateTime::Name_Full
)) == 0 )
143 if ( flags
& wxDateTime::Name_Abbr
)
145 if ( name
.CmpNoCase(wxDateTime::
146 GetMonthName(mon
, wxDateTime::Name_Abbr
)) == 0 )
156 // return the weekday if the string is a weekday name or Inv_WeekDay otherwise
157 wxDateTime::WeekDay
GetWeekDayFromName(const wxString
& name
, int flags
)
159 wxDateTime::WeekDay wd
;
160 for ( wd
= wxDateTime::Sun
; wd
< wxDateTime::Inv_WeekDay
; wxNextWDay(wd
) )
162 // case-insensitive comparison either one of or with both abbreviated
164 if ( flags
& wxDateTime::Name_Full
)
166 if ( name
.CmpNoCase(wxDateTime::
167 GetWeekDayName(wd
, wxDateTime::Name_Full
)) == 0 )
173 if ( flags
& wxDateTime::Name_Abbr
)
175 if ( name
.CmpNoCase(wxDateTime::
176 GetWeekDayName(wd
, wxDateTime::Name_Abbr
)) == 0 )
186 // scans all digits (but no more than len) and returns the resulting number
187 bool GetNumericToken(size_t len
,
188 wxString::const_iterator
& p
,
189 unsigned long *number
)
193 while ( wxIsdigit(*p
) )
197 if ( len
&& ++n
> len
)
201 return !s
.empty() && s
.ToULong(number
);
204 // scans all alphabetic characters and returns the resulting string
205 wxString
GetAlphaToken(wxString::const_iterator
& p
)
208 while ( wxIsalpha(*p
) )
216 // parses string starting at given iterator using the specified format and,
217 // optionally, a fall back format (and optionally another one... but it stops
220 // if unsuccessful, returns invalid wxDateTime without changing p; otherwise
221 // advance p to the end of the match and returns wxDateTime containing the
222 // results of the parsing
224 ParseFormatAt(wxString::const_iterator
& p
,
225 const wxString::const_iterator
& end
,
227 // FIXME-VC6: using wxString() instead of wxEmptyString in the
228 // line below results in error C2062: type 'class
229 // wxString (__cdecl *)(void)' unexpected
230 const wxString
& fmtAlt
= wxEmptyString
,
231 const wxString
& fmtAlt2
= wxString())
233 const wxString
str(p
, end
);
234 wxString::const_iterator endParse
;
236 if ( dt
.ParseFormat(str
, fmt
, &endParse
) ||
237 (!fmtAlt
.empty() && dt
.ParseFormat(str
, fmtAlt
, &endParse
)) ||
238 (!fmtAlt2
.empty() && dt
.ParseFormat(str
, fmtAlt2
, &endParse
)) )
240 p
+= endParse
- str
.begin();
242 //else: all formats failed
247 } // anonymous namespace
249 // ----------------------------------------------------------------------------
250 // wxDateTime to/from text representations
251 // ----------------------------------------------------------------------------
253 wxString
wxDateTime::Format(const wxString
& format
, const TimeZone
& tz
) const
255 wxCHECK_MSG( !format
.empty(), wxEmptyString
,
256 _T("NULL format in wxDateTime::Format") );
258 // we have to use our own implementation if the date is out of range of
259 // strftime() or if we use non standard specificators
261 time_t time
= GetTicks();
263 if ( (time
!= (time_t)-1) && !wxStrstr(format
, _T("%l")) )
268 if ( tz
.GetOffset() == -GetTimeZone() )
270 // we are working with local time
271 tm
= wxLocaltime_r(&time
, &tmstruct
);
273 // should never happen
274 wxCHECK_MSG( tm
, wxEmptyString
, _T("wxLocaltime_r() failed") );
278 time
+= (int)tz
.GetOffset();
280 #if defined(__VMS__) || defined(__WATCOMC__) // time is unsigned so avoid warning
281 int time2
= (int) time
;
287 tm
= wxGmtime_r(&time
, &tmstruct
);
289 // should never happen
290 wxCHECK_MSG( tm
, wxEmptyString
, _T("wxGmtime_r() failed") );
294 tm
= (struct tm
*)NULL
;
300 return CallStrftime(format
, tm
);
303 //else: use generic code below
304 #endif // HAVE_STRFTIME
306 // we only parse ANSI C format specifications here, no POSIX 2
307 // complications, no GNU extensions but we do add support for a "%l" format
308 // specifier allowing to get the number of milliseconds
311 // used for calls to strftime() when we only deal with time
312 struct tm tmTimeOnly
;
313 tmTimeOnly
.tm_hour
= tm
.hour
;
314 tmTimeOnly
.tm_min
= tm
.min
;
315 tmTimeOnly
.tm_sec
= tm
.sec
;
316 tmTimeOnly
.tm_wday
= 0;
317 tmTimeOnly
.tm_yday
= 0;
318 tmTimeOnly
.tm_mday
= 1; // any date will do
319 tmTimeOnly
.tm_mon
= 0;
320 tmTimeOnly
.tm_year
= 76;
321 tmTimeOnly
.tm_isdst
= 0; // no DST, we adjust for tz ourselves
323 wxString tmp
, res
, fmt
;
324 for ( wxString::const_iterator p
= format
.begin(); p
!= format
.end(); ++p
)
334 // set the default format
335 switch ( (*++p
).GetValue() )
337 case _T('Y'): // year has 4 digits
341 case _T('j'): // day of year has 3 digits
342 case _T('l'): // milliseconds have 3 digits
346 case _T('w'): // week day as number has only one
351 // it's either another valid format specifier in which case
352 // the format is "%02d" (for all the rest) or we have the
353 // field width preceding the format in which case it will
354 // override the default format anyhow
363 // start of the format specification
364 switch ( (*p
).GetValue() )
366 case _T('a'): // a weekday name
368 // second parameter should be true for abbreviated names
369 res
+= GetWeekDayName(tm
.GetWeekDay(),
370 *p
== _T('a') ? Name_Abbr
: Name_Full
);
373 case _T('b'): // a month name
375 res
+= GetMonthName(tm
.mon
,
376 *p
== _T('b') ? Name_Abbr
: Name_Full
);
379 case _T('c'): // locale default date and time representation
380 case _T('x'): // locale default date representation
383 // the problem: there is no way to know what do these format
384 // specifications correspond to for the current locale.
386 // the solution: use a hack and still use strftime(): first
387 // find the YEAR which is a year in the strftime() range (1970
388 // - 2038) whose Jan 1 falls on the same week day as the Jan 1
389 // of the real year. Then make a copy of the format and
390 // replace all occurrences of YEAR in it with some unique
391 // string not appearing anywhere else in it, then use
392 // strftime() to format the date in year YEAR and then replace
393 // YEAR back by the real year and the unique replacement
394 // string back with YEAR. Notice that "all occurrences of YEAR"
395 // means all occurrences of 4 digit as well as 2 digit form!
397 // the bugs: we assume that neither of %c nor %x contains any
398 // fields which may change between the YEAR and real year. For
399 // example, the week number (%U, %W) and the day number (%j)
400 // will change if one of these years is leap and the other one
403 // find the YEAR: normally, for any year X, Jan 1 of the
404 // year X + 28 is the same weekday as Jan 1 of X (because
405 // the weekday advances by 1 for each normal X and by 2
406 // for each leap X, hence by 5 every 4 years or by 35
407 // which is 0 mod 7 every 28 years) but this rule breaks
408 // down if there are years between X and Y which are
409 // divisible by 4 but not leap (i.e. divisible by 100 but
410 // not 400), hence the correction.
412 int yearReal
= GetYear(tz
);
413 int mod28
= yearReal
% 28;
415 // be careful to not go too far - we risk to leave the
420 year
= 1988 + mod28
; // 1988 == 0 (mod 28)
424 year
= 1970 + mod28
- 10; // 1970 == 10 (mod 28)
427 int nCentury
= year
/ 100,
428 nCenturyReal
= yearReal
/ 100;
430 // need to adjust for the years divisble by 400 which are
431 // not leap but are counted like leap ones if we just take
432 // the number of centuries in between for nLostWeekDays
433 int nLostWeekDays
= (nCentury
- nCenturyReal
) -
434 (nCentury
/ 4 - nCenturyReal
/ 4);
436 // we have to gain back the "lost" weekdays: note that the
437 // effect of this loop is to not do anything to
438 // nLostWeekDays (which we won't use any more), but to
439 // (indirectly) set the year correctly
440 while ( (nLostWeekDays
% 7) != 0 )
442 nLostWeekDays
+= year
++ % 4 ? 1 : 2;
445 // finally move the year below 2000 so that the 2-digit
446 // year number can never match the month or day of the
447 // month when we do the replacements below
451 wxASSERT_MSG( year
>= 1970 && year
< 2000,
452 _T("logic error in wxDateTime::Format") );
455 // use strftime() to format the same date but in supported
458 // NB: we assume that strftime() doesn't check for the
459 // date validity and will happily format the date
460 // corresponding to Feb 29 of a non leap year (which
461 // may happen if yearReal was leap and year is not)
462 struct tm tmAdjusted
;
464 tmAdjusted
.tm_hour
= tm
.hour
;
465 tmAdjusted
.tm_min
= tm
.min
;
466 tmAdjusted
.tm_sec
= tm
.sec
;
467 tmAdjusted
.tm_wday
= tm
.GetWeekDay();
468 tmAdjusted
.tm_yday
= GetDayOfYear();
469 tmAdjusted
.tm_mday
= tm
.mday
;
470 tmAdjusted
.tm_mon
= tm
.mon
;
471 tmAdjusted
.tm_year
= year
- 1900;
472 tmAdjusted
.tm_isdst
= 0; // no DST, already adjusted
473 wxString str
= CallStrftime(*p
== _T('c') ? _T("%c")
477 // now replace the replacement year with the real year:
478 // notice that we have to replace the 4 digit year with
479 // a unique string not appearing in strftime() output
480 // first to prevent the 2 digit year from matching any
481 // substring of the 4 digit year (but any day, month,
482 // hours or minutes components should be safe because
483 // they are never in 70-99 range)
484 wxString
replacement("|");
485 while ( str
.find(replacement
) != wxString::npos
)
488 str
.Replace(wxString::Format("%d", year
),
490 str
.Replace(wxString::Format("%d", year
% 100),
491 wxString::Format("%d", yearReal
% 100));
492 str
.Replace(replacement
,
493 wxString::Format("%d", yearReal
));
497 #else // !HAVE_STRFTIME
498 // Use "%m/%d/%y %H:%M:%S" format instead
499 res
+= wxString::Format(wxT("%02d/%02d/%04d %02d:%02d:%02d"),
500 tm
.mon
+1,tm
.mday
, tm
.year
, tm
.hour
, tm
.min
, tm
.sec
);
501 #endif // HAVE_STRFTIME/!HAVE_STRFTIME
504 case _T('d'): // day of a month (01-31)
505 res
+= wxString::Format(fmt
, tm
.mday
);
508 case _T('H'): // hour in 24h format (00-23)
509 res
+= wxString::Format(fmt
, tm
.hour
);
512 case _T('I'): // hour in 12h format (01-12)
514 // 24h -> 12h, 0h -> 12h too
515 int hour12
= tm
.hour
> 12 ? tm
.hour
- 12
516 : tm
.hour
? tm
.hour
: 12;
517 res
+= wxString::Format(fmt
, hour12
);
521 case _T('j'): // day of the year
522 res
+= wxString::Format(fmt
, GetDayOfYear(tz
));
525 case _T('l'): // milliseconds (NOT STANDARD)
526 res
+= wxString::Format(fmt
, GetMillisecond(tz
));
529 case _T('m'): // month as a number (01-12)
530 res
+= wxString::Format(fmt
, tm
.mon
+ 1);
533 case _T('M'): // minute as a decimal number (00-59)
534 res
+= wxString::Format(fmt
, tm
.min
);
537 case _T('p'): // AM or PM string
539 res
+= CallStrftime(_T("%p"), &tmTimeOnly
);
540 #else // !HAVE_STRFTIME
541 res
+= (tmTimeOnly
.tm_hour
> 12) ? wxT("pm") : wxT("am");
542 #endif // HAVE_STRFTIME/!HAVE_STRFTIME
545 case _T('S'): // second as a decimal number (00-61)
546 res
+= wxString::Format(fmt
, tm
.sec
);
549 case _T('U'): // week number in the year (Sunday 1st week day)
550 res
+= wxString::Format(fmt
, GetWeekOfYear(Sunday_First
, tz
));
553 case _T('W'): // week number in the year (Monday 1st week day)
554 res
+= wxString::Format(fmt
, GetWeekOfYear(Monday_First
, tz
));
557 case _T('w'): // weekday as a number (0-6), Sunday = 0
558 res
+= wxString::Format(fmt
, tm
.GetWeekDay());
561 // case _T('x'): -- handled with "%c"
563 case _T('X'): // locale default time representation
564 // just use strftime() to format the time for us
566 res
+= CallStrftime(_T("%X"), &tmTimeOnly
);
567 #else // !HAVE_STRFTIME
568 res
+= wxString::Format(wxT("%02d:%02d:%02d"),tm
.hour
, tm
.min
, tm
.sec
);
569 #endif // HAVE_STRFTIME/!HAVE_STRFTIME
572 case _T('y'): // year without century (00-99)
573 res
+= wxString::Format(fmt
, tm
.year
% 100);
576 case _T('Y'): // year with century
577 res
+= wxString::Format(fmt
, tm
.year
);
580 case _T('Z'): // timezone name
582 res
+= CallStrftime(_T("%Z"), &tmTimeOnly
);
587 // is it the format width?
589 while ( *p
== _T('-') || *p
== _T('+') ||
590 *p
== _T(' ') || wxIsdigit(*p
) )
597 // we've only got the flags and width so far in fmt
598 fmt
.Prepend(_T('%'));
606 // no, it wasn't the width
607 wxFAIL_MSG(_T("unknown format specificator"));
609 // fall through and just copy it nevertheless
611 case _T('%'): // a percent sign
615 case 0: // the end of string
616 wxFAIL_MSG(_T("missing format at the end of string"));
618 // just put the '%' which was the last char in format
628 // this function parses a string in (strict) RFC 822 format: see the section 5
629 // of the RFC for the detailed description, but briefly it's something of the
630 // form "Sat, 18 Dec 1999 00:48:30 +0100"
632 // this function is "strict" by design - it must reject anything except true
633 // RFC822 time specs.
635 // TODO a great candidate for using reg exps
637 wxDateTime::ParseRfc822Date(const wxString
& date
, wxString::const_iterator
*end
)
639 // TODO: rewrite using iterators instead of wxChar pointers
640 const wxStringCharType
*p
= date
.wx_str();
641 const wxStringCharType
*comma
= wxStrchr(p
, wxS(','));
644 // the part before comma is the weekday
646 // skip it for now - we don't use but might check that it really
647 // corresponds to the specfied date
652 wxLogDebug(_T("no space after weekday in RFC822 time spec"));
660 // the following 1 or 2 digits are the day number
661 if ( !wxIsdigit(*p
) )
663 wxLogDebug(_T("day number expected in RFC822 time spec, none found"));
668 wxDateTime_t day
= (wxDateTime_t
)(*p
++ - _T('0'));
672 day
= (wxDateTime_t
)(day
+ (*p
++ - _T('0')));
675 if ( *p
++ != _T(' ') )
680 // the following 3 letters specify the month
681 wxString
monName(p
, 3);
683 if ( monName
== _T("Jan") )
685 else if ( monName
== _T("Feb") )
687 else if ( monName
== _T("Mar") )
689 else if ( monName
== _T("Apr") )
691 else if ( monName
== _T("May") )
693 else if ( monName
== _T("Jun") )
695 else if ( monName
== _T("Jul") )
697 else if ( monName
== _T("Aug") )
699 else if ( monName
== _T("Sep") )
701 else if ( monName
== _T("Oct") )
703 else if ( monName
== _T("Nov") )
705 else if ( monName
== _T("Dec") )
709 wxLogDebug(_T("Invalid RFC 822 month name '%s'"), monName
.c_str());
716 if ( *p
++ != _T(' ') )
722 if ( !wxIsdigit(*p
) )
728 int year
= *p
++ - _T('0');
730 if ( !wxIsdigit(*p
) )
732 // should have at least 2 digits in the year
737 year
+= *p
++ - _T('0');
739 // is it a 2 digit year (as per original RFC 822) or a 4 digit one?
743 year
+= *p
++ - _T('0');
745 if ( !wxIsdigit(*p
) )
747 // no 3 digit years please
752 year
+= *p
++ - _T('0');
755 if ( *p
++ != _T(' ') )
760 // time is in the format hh:mm:ss and seconds are optional
761 if ( !wxIsdigit(*p
) )
766 wxDateTime_t hour
= (wxDateTime_t
)(*p
++ - _T('0'));
768 if ( !wxIsdigit(*p
) )
774 hour
= (wxDateTime_t
)(hour
+ (*p
++ - _T('0')));
776 if ( *p
++ != _T(':') )
781 if ( !wxIsdigit(*p
) )
786 wxDateTime_t min
= (wxDateTime_t
)(*p
++ - _T('0'));
788 if ( !wxIsdigit(*p
) )
794 min
= (wxDateTime_t
)(min
+ *p
++ - _T('0'));
796 wxDateTime_t sec
= 0;
800 if ( !wxIsdigit(*p
) )
805 sec
= (wxDateTime_t
)(*p
++ - _T('0'));
807 if ( !wxIsdigit(*p
) )
813 sec
= (wxDateTime_t
)(sec
+ *p
++ - _T('0'));
816 if ( *p
++ != _T(' ') )
821 // and now the interesting part: the timezone
822 int offset
wxDUMMY_INITIALIZE(0);
823 if ( *p
== _T('-') || *p
== _T('+') )
825 // the explicit offset given: it has the form of hhmm
826 bool plus
= *p
++ == _T('+');
828 if ( !wxIsdigit(*p
) || !wxIsdigit(*(p
+ 1)) )
834 offset
= MIN_PER_HOUR
*(10*(*p
- _T('0')) + (*(p
+ 1) - _T('0')));
838 if ( !wxIsdigit(*p
) || !wxIsdigit(*(p
+ 1)) )
844 offset
+= 10*(*p
- _T('0')) + (*(p
+ 1) - _T('0'));
855 // the symbolic timezone given: may be either military timezone or one
856 // of standard abbreviations
859 // military: Z = UTC, J unused, A = -1, ..., Y = +12
860 static const int offsets
[26] =
862 //A B C D E F G H I J K L M
863 -1, -2, -3, -4, -5, -6, -7, -8, -9, 0, -10, -11, -12,
864 //N O P R Q S T U V W Z Y Z
865 +1, +2, +3, +4, +5, +6, +7, +8, +9, +10, +11, +12, 0
868 if ( *p
< _T('A') || *p
> _T('Z') || *p
== _T('J') )
870 wxLogDebug(_T("Invalid militaty timezone '%c'"), *p
);
875 offset
= offsets
[*p
++ - _T('A')];
881 if ( tz
== _T("UT") || tz
== _T("UTC") || tz
== _T("GMT") )
883 else if ( tz
== _T("AST") )
885 else if ( tz
== _T("ADT") )
887 else if ( tz
== _T("EST") )
889 else if ( tz
== _T("EDT") )
891 else if ( tz
== _T("CST") )
893 else if ( tz
== _T("CDT") )
895 else if ( tz
== _T("MST") )
897 else if ( tz
== _T("MDT") )
899 else if ( tz
== _T("PST") )
901 else if ( tz
== _T("PDT") )
905 wxLogDebug(_T("Unknown RFC 822 timezone '%s'"), p
);
914 offset
*= MIN_PER_HOUR
;
917 // the spec was correct, construct the date from the values we found
918 Set(day
, mon
, year
, hour
, min
, sec
);
919 MakeFromTimezone(TimeZone::Make(offset
*SEC_PER_MIN
));
921 const size_t endpos
= p
- date
.wx_str();
923 *end
= date
.begin() + endpos
;
925 return date
.c_str() + endpos
;
930 // returns the string containing strftime() format used for short dates in the
931 // current locale or an empty string
932 static wxString
GetLocaleDateFormat()
936 // there is no setlocale() under Windows CE, so just always query the
939 if ( strcmp(setlocale(LC_ALL
, NULL
), "C") != 0 )
942 // The locale was programatically set to non-C. We assume that this was
943 // done using wxLocale, in which case thread's current locale is also
944 // set to correct LCID value and we can use GetLocaleInfo to determine
945 // the correct formatting string:
947 LCID lcid
= LOCALE_USER_DEFAULT
;
949 LCID lcid
= GetThreadLocale();
951 // according to MSDN 80 chars is max allowed for short date format
953 if ( ::GetLocaleInfo(lcid
, LOCALE_SSHORTDATE
, fmt
, WXSIZEOF(fmt
)) )
955 wxChar chLast
= _T('\0');
956 size_t lastCount
= 0;
957 for ( const wxChar
*p
= fmt
; /* NUL handled inside */; p
++ )
967 // these characters come in groups, start counting them
977 // first deal with any special characters we have had
987 // these two are the same as we
988 // don't distinguish between 1 and
1002 wxFAIL_MSG( _T("too many 'd's") );
1007 switch ( lastCount
)
1011 // as for 'd' and 'dd' above
1024 wxFAIL_MSG( _T("too many 'M's") );
1029 switch ( lastCount
)
1041 wxFAIL_MSG( _T("wrong number of 'y's") );
1046 // strftime() doesn't have era string,
1047 // ignore this format
1048 wxASSERT_MSG( lastCount
<= 2,
1049 _T("too many 'g's") );
1053 wxFAIL_MSG( _T("unreachable") );
1060 // not a special character so must be just a separator,
1062 if ( *p
!= _T('\0') )
1064 if ( *p
== _T('%') )
1066 // this one needs to be escaped
1074 if ( *p
== _T('\0') )
1078 //else: GetLocaleInfo() failed, leave fmtDate value unchanged and
1079 // try our luck with the default formats
1081 //else: default C locale, default formats should work
1086 #endif // __WINDOWS__
1089 wxDateTime::ParseFormat(const wxString
& date
,
1090 const wxString
& format
,
1091 const wxDateTime
& dateDef
,
1092 wxString::const_iterator
*end
)
1094 wxCHECK_MSG( !format
.empty(), NULL
, "format can't be empty" );
1099 // what fields have we found?
1100 bool haveWDay
= false,
1110 bool hourIsIn12hFormat
= false, // or in 24h one?
1111 isPM
= false; // AM by default
1113 // and the value of the items we have (init them to get rid of warnings)
1114 wxDateTime_t msec
= 0,
1118 WeekDay wday
= Inv_WeekDay
;
1119 wxDateTime_t yday
= 0,
1121 wxDateTime::Month mon
= Inv_Month
;
1124 wxString::const_iterator input
= date
.begin();
1125 for ( wxString::const_iterator fmt
= format
.begin(); fmt
!= format
.end(); ++fmt
)
1127 if ( *fmt
!= _T('%') )
1129 if ( wxIsspace(*fmt
) )
1131 // a white space in the format string matches 0 or more white
1132 // spaces in the input
1133 while ( wxIsspace(*input
) )
1140 // any other character (not whitespace, not '%') must be
1141 // matched by itself in the input
1142 if ( *input
++ != *fmt
)
1149 // done with this format char
1153 // start of a format specification
1155 // parse the optional width
1157 while ( wxIsdigit(*++fmt
) )
1160 width
+= *fmt
- _T('0');
1163 // the default widths for the various fields
1166 switch ( (*fmt
).GetValue() )
1168 case _T('Y'): // year has 4 digits
1172 case _T('j'): // day of year has 3 digits
1173 case _T('l'): // milliseconds have 3 digits
1177 case _T('w'): // week day as number has only one
1182 // default for all other fields
1187 // then the format itself
1188 switch ( (*fmt
).GetValue() )
1190 case _T('a'): // a weekday name
1193 int flag
= *fmt
== _T('a') ? Name_Abbr
: Name_Full
;
1194 wday
= GetWeekDayFromName(GetAlphaToken(input
), flag
);
1195 if ( wday
== Inv_WeekDay
)
1204 case _T('b'): // a month name
1207 int flag
= *fmt
== _T('b') ? Name_Abbr
: Name_Full
;
1208 mon
= GetMonthFromName(GetAlphaToken(input
), flag
);
1209 if ( mon
== Inv_Month
)
1218 case _T('c'): // locale default date and time representation
1220 #ifdef HAVE_STRPTIME
1223 // try using strptime() -- it may fail even if the input is
1224 // correct but the date is out of range, so we will fall back
1225 // to our generic code anyhow
1226 if ( CallStrptime(date
, input
, "%c", &tm
) )
1232 year
= 1900 + tm
.tm_year
;
1233 mon
= (Month
)tm
.tm_mon
;
1236 else // strptime() failed; try generic heuristic code
1237 #endif // HAVE_STRPTIME
1240 // try the format which corresponds to ctime() output
1241 // first, then the generic date/time formats
1242 const wxDateTime dt
= ParseFormatAt
1246 wxS("%a %b %d %H:%M:%S %Y"),
1250 if ( !dt
.IsValid() )
1264 haveDay
= haveMon
= haveYear
=
1265 haveHour
= haveMin
= haveSec
= true;
1269 case _T('d'): // day of a month (01-31)
1270 if ( !GetNumericToken(width
, input
, &num
) ||
1271 (num
> 31) || (num
< 1) )
1277 // we can't check whether the day range is correct yet, will
1278 // do it later - assume ok for now
1280 mday
= (wxDateTime_t
)num
;
1283 case _T('H'): // hour in 24h format (00-23)
1284 if ( !GetNumericToken(width
, input
, &num
) || (num
> 23) )
1291 hour
= (wxDateTime_t
)num
;
1294 case _T('I'): // hour in 12h format (01-12)
1295 if ( !GetNumericToken(width
, input
, &num
) || !num
|| (num
> 12) )
1302 hourIsIn12hFormat
= true;
1303 hour
= (wxDateTime_t
)(num
% 12); // 12 should be 0
1306 case _T('j'): // day of the year
1307 if ( !GetNumericToken(width
, input
, &num
) || !num
|| (num
> 366) )
1314 yday
= (wxDateTime_t
)num
;
1317 case _T('l'): // milliseconds (0-999)
1318 if ( !GetNumericToken(width
, input
, &num
) )
1322 msec
= (wxDateTime_t
)num
;
1325 case _T('m'): // month as a number (01-12)
1326 if ( !GetNumericToken(width
, input
, &num
) || !num
|| (num
> 12) )
1333 mon
= (Month
)(num
- 1);
1336 case _T('M'): // minute as a decimal number (00-59)
1337 if ( !GetNumericToken(width
, input
, &num
) || (num
> 59) )
1344 min
= (wxDateTime_t
)num
;
1347 case _T('p'): // AM or PM string
1349 wxString am
, pm
, token
= GetAlphaToken(input
);
1351 // some locales have empty AM/PM tokens and thus when formatting
1352 // dates with the %p specifier nothing is generated; when trying to
1353 // parse them back, we get an empty token here... but that's not
1358 GetAmPmStrings(&am
, &pm
);
1359 if (am
.empty() && pm
.empty())
1360 return NULL
; // no am/pm strings defined
1361 if ( token
.CmpNoCase(pm
) == 0 )
1365 else if ( token
.CmpNoCase(am
) != 0 )
1373 case _T('r'): // time as %I:%M:%S %p
1376 if ( !dt
.ParseFormat(wxString(input
, date
.end()),
1377 wxS("%I:%M:%S %p"), &input
) )
1380 haveHour
= haveMin
= haveSec
= true;
1389 case _T('R'): // time as %H:%M
1392 dt
= ParseFormatAt(input
, date
.end(), wxS("%H:%M"));
1393 if ( !dt
.IsValid() )
1405 case _T('S'): // second as a decimal number (00-61)
1406 if ( !GetNumericToken(width
, input
, &num
) || (num
> 61) )
1413 sec
= (wxDateTime_t
)num
;
1416 case _T('T'): // time as %H:%M:%S
1419 dt
= ParseFormatAt(input
, date
.end(), wxS("%H:%M:%S"));
1420 if ( !dt
.IsValid() )
1434 case _T('w'): // weekday as a number (0-6), Sunday = 0
1435 if ( !GetNumericToken(width
, input
, &num
) || (wday
> 6) )
1442 wday
= (WeekDay
)num
;
1445 case _T('x'): // locale default date representation
1446 #ifdef HAVE_STRPTIME
1447 // try using strptime() -- it may fail even if the input is
1448 // correct but the date is out of range, so we will fall back
1449 // to our generic code anyhow
1453 if ( CallStrptime(date
, input
, "%x", &tm
) )
1455 haveDay
= haveMon
= haveYear
= true;
1457 year
= 1900 + tm
.tm_year
;
1458 mon
= (Month
)tm
.tm_mon
;
1464 #endif // HAVE_STRPTIME
1471 // The above doesn't work for all locales, try to query
1472 // Windows for the right way of formatting the date:
1473 fmtDate
= GetLocaleDateFormat();
1474 if ( fmtDate
.empty() )
1475 #endif // __WINDOWS__
1477 if ( IsWestEuropeanCountry(GetCountry()) ||
1478 GetCountry() == Russia
)
1480 fmtDate
= _T("%d/%m/%y");
1481 fmtDateAlt
= _T("%m/%d/%y");
1485 fmtDate
= _T("%m/%d/%y");
1486 fmtDateAlt
= _T("%d/%m/%y");
1491 dt
= ParseFormatAt(input
, date
.end(),
1492 fmtDate
, fmtDateAlt
);
1493 if ( !dt
.IsValid() )
1509 case _T('X'): // locale default time representation
1510 #ifdef HAVE_STRPTIME
1512 // use strptime() to do it for us (FIXME !Unicode friendly)
1514 if ( !CallStrptime(date
, input
, "%X", &tm
) )
1517 haveHour
= haveMin
= haveSec
= true;
1523 #else // !HAVE_STRPTIME
1524 // TODO under Win32 we can query the LOCALE_ITIME system
1525 // setting which says whether the default time format is
1528 // try to parse what follows as "%H:%M:%S" and, if this
1529 // fails, as "%I:%M:%S %p" - this should catch the most
1532 dt
= ParseFormatAt(input
, date
.end(), "%T", "%r");
1533 if ( !dt
.IsValid() )
1545 #endif // HAVE_STRPTIME/!HAVE_STRPTIME
1548 case _T('y'): // year without century (00-99)
1549 if ( !GetNumericToken(width
, input
, &num
) || (num
> 99) )
1557 // TODO should have an option for roll over date instead of
1558 // hard coding it here
1559 year
= (num
> 30 ? 1900 : 2000) + (wxDateTime_t
)num
;
1562 case _T('Y'): // year with century
1563 if ( !GetNumericToken(width
, input
, &num
) )
1570 year
= (wxDateTime_t
)num
;
1573 case _T('Z'): // timezone name
1574 wxFAIL_MSG(_T("TODO"));
1577 case _T('%'): // a percent sign
1578 if ( *input
++ != _T('%') )
1585 case 0: // the end of string
1586 wxFAIL_MSG(_T("unexpected format end"));
1590 default: // not a known format spec
1595 // format matched, try to construct a date from what we have now
1597 if ( dateDef
.IsValid() )
1599 // take this date as default
1600 tmDef
= dateDef
.GetTm();
1602 else if ( IsValid() )
1604 // if this date is valid, don't change it
1609 // no default and this date is invalid - fall back to Today()
1610 tmDef
= Today().GetTm();
1626 // TODO we don't check here that the values are consistent, if both year
1627 // day and month/day were found, we just ignore the year day and we
1628 // also always ignore the week day
1631 if ( mday
> GetNumberOfDays(tm
.mon
, tm
.year
) )
1633 wxLogDebug(_T("bad month day in wxDateTime::ParseFormat"));
1640 else if ( haveYDay
)
1642 if ( yday
> GetNumberOfDays(tm
.year
) )
1644 wxLogDebug(_T("bad year day in wxDateTime::ParseFormat"));
1649 Tm tm2
= wxDateTime(1, Jan
, tm
.year
).SetToYearDay(yday
).GetTm();
1656 if ( haveHour
&& hourIsIn12hFormat
&& isPM
)
1658 // translate to 24hour format
1661 //else: either already in 24h format or no translation needed
1684 // finally check that the week day is consistent -- if we had it
1685 if ( haveWDay
&& GetWeekDay() != wday
)
1687 wxLogDebug(_T("inconsistsnet week day in wxDateTime::ParseFormat()"));
1695 return date
.c_str() + (input
- date
.begin());
1699 wxDateTime::ParseDateTime(const wxString
& date
, wxString::const_iterator
*end
)
1701 // Set to current day and hour, so strings like '14:00' becomes today at
1702 // 14, not some other random date
1703 wxDateTime dtDate
= wxDateTime::Today();
1704 wxDateTime dtTime
= wxDateTime::Today();
1706 wxString::const_iterator
1711 // If we got a date in the beginning, see if there is a time specified
1713 if ( dtDate
.ParseDate(date
, &endDate
) )
1715 // Skip spaces, as the ParseTime() function fails on spaces
1716 while ( endDate
!= date
.end() && wxIsspace(*endDate
) )
1719 const wxString
timestr(endDate
, date
.end());
1720 if ( !dtTime
.ParseTime(timestr
, &endTime
) )
1723 endBoth
= endDate
+ (endTime
- timestr
.begin());
1725 else // no date in the beginning
1727 // check if we have a time followed by a date
1728 if ( !dtTime
.ParseTime(date
, &endTime
) )
1731 while ( endTime
!= date
.end() && wxIsspace(*endTime
) )
1734 const wxString
datestr(endTime
, date
.end());
1735 if ( !dtDate
.ParseDate(datestr
, &endDate
) )
1738 endBoth
= endTime
+ (endDate
- datestr
.begin());
1741 Set(dtDate
.GetDay(), dtDate
.GetMonth(), dtDate
.GetYear(),
1742 dtTime
.GetHour(), dtTime
.GetMinute(), dtTime
.GetSecond(),
1743 dtTime
.GetMillisecond());
1745 // Return endpoint of scan
1749 return date
.c_str() + (endBoth
- date
.begin());
1753 wxDateTime::ParseDate(const wxString
& date
, wxString::const_iterator
*end
)
1755 // this is a simplified version of ParseDateTime() which understands only
1756 // "today" (for wxDate compatibility) and digits only otherwise (and not
1757 // all esoteric constructions ParseDateTime() knows about)
1759 const wxString::const_iterator pBegin
= date
.begin();
1761 wxString::const_iterator p
= pBegin
;
1762 while ( wxIsspace(*p
) )
1765 // some special cases
1769 int dayDiffFromToday
;
1772 { wxTRANSLATE("today"), 0 },
1773 { wxTRANSLATE("yesterday"), -1 },
1774 { wxTRANSLATE("tomorrow"), 1 },
1777 for ( size_t n
= 0; n
< WXSIZEOF(literalDates
); n
++ )
1779 const wxString dateStr
= wxGetTranslation(literalDates
[n
].str
);
1780 size_t len
= dateStr
.length();
1782 const wxString::const_iterator pEnd
= p
+ len
;
1783 if ( wxString(p
, pEnd
).CmpNoCase(dateStr
) == 0 )
1785 // nothing can follow this, so stop here
1789 int dayDiffFromToday
= literalDates
[n
].dayDiffFromToday
;
1791 if ( dayDiffFromToday
)
1793 *this += wxDateSpan::Days(dayDiffFromToday
);
1799 return wxStringOperations::AddToIter(date
.c_str().AsChar(),
1804 // We try to guess what we have here: for each new (numeric) token, we
1805 // determine if it can be a month, day or a year. Of course, there is an
1806 // ambiguity as some numbers may be days as well as months, so we also
1807 // have the ability to back track.
1810 bool haveDay
= false, // the months day?
1811 haveWDay
= false, // the day of week?
1812 haveMon
= false, // the month?
1813 haveYear
= false; // the year?
1815 // and the value of the items we have (init them to get rid of warnings)
1816 WeekDay wday
= Inv_WeekDay
;
1817 wxDateTime_t day
= 0;
1818 wxDateTime::Month mon
= Inv_Month
;
1821 // tokenize the string
1823 static const wxStringCharType
*dateDelimiters
= wxS(".,/-\t\r\n ");
1824 wxStringTokenizer
tok(wxString(p
, date
.end()), dateDelimiters
);
1825 while ( tok
.HasMoreTokens() )
1827 wxString token
= tok
.GetNextToken();
1833 if ( token
.ToULong(&val
) )
1835 // guess what this number is
1841 if ( !haveMon
&& val
> 0 && val
<= 12 )
1843 // assume it is month
1846 else // not the month
1850 // this can only be the year
1853 else // may be either day or year
1855 // use a leap year if we don't have the year yet to allow
1856 // dates like 2/29/1976 which would be rejected otherwise
1857 wxDateTime_t max_days
= (wxDateTime_t
)(
1859 ? GetNumberOfDays(mon
, haveYear
? year
: 1976)
1864 if ( (val
== 0) || (val
> (unsigned long)max_days
) )
1869 else // yes, suppose it's the day
1883 year
= (wxDateTime_t
)val
;
1892 day
= (wxDateTime_t
)val
;
1898 mon
= (Month
)(val
- 1);
1901 else // not a number
1903 // be careful not to overwrite the current mon value
1904 Month mon2
= GetMonthFromName(token
, Name_Full
| Name_Abbr
);
1905 if ( mon2
!= Inv_Month
)
1910 // but we already have a month - maybe we guessed wrong?
1913 // no need to check in month range as always < 12, but
1914 // the days are counted from 1 unlike the months
1915 day
= (wxDateTime_t
)(mon
+ 1);
1920 // could possible be the year (doesn't the year come
1921 // before the month in the japanese format?) (FIXME)
1930 else // not a valid month name
1932 WeekDay wday2
= GetWeekDayFromName(token
, Name_Full
| Name_Abbr
);
1933 if ( wday2
!= Inv_WeekDay
)
1945 else // not a valid weekday name
1948 static const char *ordinals
[] =
1950 wxTRANSLATE("first"),
1951 wxTRANSLATE("second"),
1952 wxTRANSLATE("third"),
1953 wxTRANSLATE("fourth"),
1954 wxTRANSLATE("fifth"),
1955 wxTRANSLATE("sixth"),
1956 wxTRANSLATE("seventh"),
1957 wxTRANSLATE("eighth"),
1958 wxTRANSLATE("ninth"),
1959 wxTRANSLATE("tenth"),
1960 wxTRANSLATE("eleventh"),
1961 wxTRANSLATE("twelfth"),
1962 wxTRANSLATE("thirteenth"),
1963 wxTRANSLATE("fourteenth"),
1964 wxTRANSLATE("fifteenth"),
1965 wxTRANSLATE("sixteenth"),
1966 wxTRANSLATE("seventeenth"),
1967 wxTRANSLATE("eighteenth"),
1968 wxTRANSLATE("nineteenth"),
1969 wxTRANSLATE("twentieth"),
1970 // that's enough - otherwise we'd have problems with
1971 // composite (or not) ordinals
1975 for ( n
= 0; n
< WXSIZEOF(ordinals
); n
++ )
1977 if ( token
.CmpNoCase(ordinals
[n
]) == 0 )
1983 if ( n
== WXSIZEOF(ordinals
) )
1985 // stop here - something unknown
1992 // don't try anything here (as in case of numeric day
1993 // above) - the symbolic day spec should always
1994 // precede the month/year
2000 day
= (wxDateTime_t
)(n
+ 1);
2005 nPosCur
= tok
.GetPosition();
2008 // either no more tokens or the scan was stopped by something we couldn't
2009 // parse - in any case, see if we can construct a date from what we have
2010 if ( !haveDay
&& !haveWDay
)
2012 wxLogDebug(_T("ParseDate: no day, no weekday hence no date."));
2017 if ( haveWDay
&& (haveMon
|| haveYear
|| haveDay
) &&
2018 !(haveDay
&& haveMon
&& haveYear
) )
2020 // without adjectives (which we don't support here) the week day only
2021 // makes sense completely separately or with the full date
2022 // specification (what would "Wed 1999" mean?)
2026 if ( !haveWDay
&& haveYear
&& !(haveDay
&& haveMon
) )
2028 // may be we have month and day instead of day and year?
2029 if ( haveDay
&& !haveMon
)
2033 // exchange day and month
2034 mon
= (wxDateTime::Month
)(day
- 1);
2036 // we're in the current year then
2037 if ( (year
> 0) && (year
<= (int)GetNumberOfDays(mon
, Inv_Year
)) )
2039 day
= (wxDateTime_t
)year
;
2044 //else: no, can't exchange, leave haveMon == false
2050 // if we give the year, month and day must be given too
2051 wxLogDebug(_T("ParseDate: day and month should be specified if year is."));
2059 mon
= GetCurrentMonth();
2064 year
= GetCurrentYear();
2069 // normally we check the day above but the check is optimistic in case
2070 // we find the day before its month/year so we have to redo it now
2071 if ( day
> GetNumberOfDays(mon
, year
) )
2074 Set(day
, mon
, year
);
2078 // check that it is really the same
2079 if ( GetWeekDay() != wday
)
2081 // inconsistency detected
2082 wxLogDebug(_T("ParseDate: inconsistent day/weekday."));
2092 SetToWeekDayInSameWeek(wday
);
2095 // return the pointer to the first unparsed char
2097 if ( nPosCur
&& wxStrchr(dateDelimiters
, *(p
- 1)) )
2099 // if we couldn't parse the token after the delimiter, put back the
2100 // delimiter as well
2107 return wxStringOperations::AddToIter(date
.c_str().AsChar(), p
- pBegin
);
2111 wxDateTime::ParseTime(const wxString
& time
, wxString::const_iterator
*end
)
2113 // first try some extra things
2120 { wxTRANSLATE("noon"), 12 },
2121 { wxTRANSLATE("midnight"), 00 },
2125 for ( size_t n
= 0; n
< WXSIZEOF(stdTimes
); n
++ )
2127 wxString timeString
= wxGetTranslation(stdTimes
[n
].name
);
2128 size_t len
= timeString
.length();
2129 if ( timeString
.CmpNoCase(wxString(time
, len
)) == 0 )
2131 // casts required by DigitalMars
2132 Set(stdTimes
[n
].hour
, wxDateTime_t(0), wxDateTime_t(0));
2135 *end
= time
.begin() + len
;
2137 return time
.c_str() + len
;
2141 // try all time formats we may think about in the order from longest to
2143 static const char *timeFormats
[] =
2145 "%I:%M:%S %p", // 12hour with AM/PM
2146 "%H:%M:%S", // could be the same or 24 hour one so try it too
2147 "%I:%M %p", // 12hour with AM/PM but without seconds
2148 "%H:%M:%S", // and a possibly 24 hour version without seconds
2149 "%X", // possibly something from above or maybe something
2150 // completely different -- try it last
2152 // TODO: parse timezones
2155 for ( size_t nFmt
= 0; nFmt
< WXSIZEOF(timeFormats
); nFmt
++ )
2157 const char *result
= ParseFormat(time
, timeFormats
[nFmt
], end
);
2165 // ----------------------------------------------------------------------------
2166 // Workdays and holidays support
2167 // ----------------------------------------------------------------------------
2169 bool wxDateTime::IsWorkDay(Country
WXUNUSED(country
)) const
2171 return !wxDateTimeHolidayAuthority::IsHoliday(*this);
2174 // ============================================================================
2176 // ============================================================================
2178 wxDateSpan WXDLLIMPEXP_BASE
operator*(int n
, const wxDateSpan
& ds
)
2181 return ds1
.Multiply(n
);
2184 // ============================================================================
2186 // ============================================================================
2188 wxTimeSpan WXDLLIMPEXP_BASE
operator*(int n
, const wxTimeSpan
& ts
)
2190 return wxTimeSpan(ts
).Multiply(n
);
2193 // this enum is only used in wxTimeSpan::Format() below but we can't declare
2194 // it locally to the method as it provokes an internal compiler error in egcs
2195 // 2.91.60 when building with -O2
2206 // not all strftime(3) format specifiers make sense here because, for example,
2207 // a time span doesn't have a year nor a timezone
2209 // Here are the ones which are supported (all of them are supported by strftime
2211 // %H hour in 24 hour format
2212 // %M minute (00 - 59)
2213 // %S second (00 - 59)
2216 // Also, for MFC CTimeSpan compatibility, we support
2217 // %D number of days
2219 // And, to be better than MFC :-), we also have
2220 // %E number of wEeks
2221 // %l milliseconds (000 - 999)
2222 wxString
wxTimeSpan::Format(const wxString
& format
) const
2224 // we deal with only positive time spans here and just add the sign in
2225 // front for the negative ones
2228 wxString
str(Negate().Format(format
));
2232 wxCHECK_MSG( !format
.empty(), wxEmptyString
,
2233 _T("NULL format in wxTimeSpan::Format") );
2236 str
.Alloc(format
.length());
2238 // Suppose we have wxTimeSpan ts(1 /* hour */, 2 /* min */, 3 /* sec */)
2240 // Then, of course, ts.Format("%H:%M:%S") must return "01:02:03", but the
2241 // question is what should ts.Format("%S") do? The code here returns "3273"
2242 // in this case (i.e. the total number of seconds, not just seconds % 60)
2243 // because, for me, this call means "give me entire time interval in
2244 // seconds" and not "give me the seconds part of the time interval"
2246 // If we agree that it should behave like this, it is clear that the
2247 // interpretation of each format specifier depends on the presence of the
2248 // other format specs in the string: if there was "%H" before "%M", we
2249 // should use GetMinutes() % 60, otherwise just GetMinutes() &c
2251 // we remember the most important unit found so far
2252 TimeSpanPart partBiggest
= Part_MSec
;
2254 for ( wxString::const_iterator pch
= format
.begin(); pch
!= format
.end(); ++pch
)
2258 if ( ch
== _T('%') )
2260 // the start of the format specification of the printf() below
2261 wxString
fmtPrefix(_T('%'));
2266 // the number of digits for the format string, 0 if unused
2267 unsigned digits
= 0;
2269 ch
= *++pch
; // get the format spec char
2273 wxFAIL_MSG( _T("invalid format character") );
2279 // skip the part below switch
2284 if ( partBiggest
< Part_Day
)
2290 partBiggest
= Part_Day
;
2295 partBiggest
= Part_Week
;
2301 if ( partBiggest
< Part_Hour
)
2307 partBiggest
= Part_Hour
;
2314 n
= GetMilliseconds().ToLong();
2315 if ( partBiggest
< Part_MSec
)
2319 //else: no need to reset partBiggest to Part_MSec, it is
2320 // the least significant one anyhow
2327 if ( partBiggest
< Part_Min
)
2333 partBiggest
= Part_Min
;
2340 n
= GetSeconds().ToLong();
2341 if ( partBiggest
< Part_Sec
)
2347 partBiggest
= Part_Sec
;
2356 fmtPrefix
<< _T("0") << digits
;
2359 str
+= wxString::Format(fmtPrefix
+ _T("ld"), n
);
2363 // normal character, just copy
2371 #endif // wxUSE_DATETIME