1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: documentation for wxDateTime class
4 // Author: wxWidgets team
6 // Licence: wxWindows license
7 /////////////////////////////////////////////////////////////////////////////
13 wxDateTime class represents an absolute moment in the time.
19 @ref overview_wxdatetimeoverview "Date classes overview", wxTimeSpan,
20 wxDateSpan, wxCalendarCtrl
26 Same as @ref setdate() Set
28 wxDateTime(wxDateTime_t day
, Month month
= Inv_Month
,
29 int Inv_Year
, wxDateTime_t hour
= 0,
30 wxDateTime_t minute
= 0,
31 wxDateTime_t second
= 0,
32 wxDateTime_t millisec
= 0);
35 Here are the trivial accessors. Other functions, which might have to perform
36 some more complicated calculations to find the answer are under the
37 @ref overview_datetimecalculations "Calendar calculations" section.
79 Adds the given date span to this object.
81 wxDateTime
Add(const wxDateSpan
& diff
);
82 wxDateTime
Add(const wxDateSpan
& diff
);
83 wxDateTime
operator+=(const wxDateSpan
& diff
);
87 Some degree of support for the date units used in astronomy and/or history is
88 provided. You can construct a wxDateTime object from a
89 @ref setjdn() JDN and you may also get its JDN,
90 @ref getmodifiedjuliandaynumber() MJD or
91 @ref getratadie() "Rata Die number" from it.
93 @ref wxdatetimejdn() "wxDateTime(double jdn)"
95 @ref setjdn() "Set(double jdn)"
101 GetModifiedJulianDayNumber()
110 The functions in this section perform the basic calendar calculations, mostly
111 related to the week days. They allow to find the given week day in the
112 week with given number (either in the month or in the year) and so on.
114 All (non-const) functions in this section don't modify the time part of the
115 wxDateTime -- they only work with the date part of it.
117 SetToWeekDayInSameWeek()
119 GetWeekDayInSameWeek()
131 @ref wxDateTime::getweekday2 GetWeekDay
150 Constructors and various @c Set() methods are collected here. If you
151 construct a date object from separate values for day, month and year, you
152 should use IsValid() method to check that the
153 values were correct as constructors can not return an error code.
155 @ref wxdatetimedef() wxDateTime
157 @ref wxdatetimetimet() wxDateTime(time_t)
159 @ref wxdatetimetm() "wxDateTime(struct tm)"
161 @ref wxdatetimejdn() "wxDateTime(double jdn)"
163 @ref wxdatetimetime() "wxDateTime(h, m, s, ms)"
165 @ref wxdatetimedate() "wxDateTime(day, mon, year, h, m, s, ms)"
169 @ref settimet() Set(time_t)
171 @ref settm() "Set(struct tm)"
173 @ref setjdn() "Set(double jdn)"
175 @ref settime() "Set(h, m, s, ms)"
177 @ref setdate() "Set(day, mon, year, h, m, s, ms)"
179 @ref setfromdos() "SetFromDOS(unsigned long ddt)"
187 @ref setdate() SetDay
197 @ref operatoreqtimet() operator=(time_t)
199 @ref operatoreqtm() "operator=(struct tm)"
204 Converts the year in absolute notation (i.e. a number which can be negative,
205 positive or zero) to the year in BC/AD notation. For the positive years,
206 nothing is done, but the year 0 is year 1 BC and so for other years there is a
209 This function should be used like this:
211 static int ConvertYearToBC(int year
);
214 These functions carry out arithmetics on the wxDateTime
215 objects. As explained in the overview, either wxTimeSpan or wxDateSpan may be
216 added to wxDateTime, hence all functions are overloaded to accept both
219 Also, both @c Add() and @c Subtract() have both const and non-const
220 version. The first one returns a new object which represents the
221 sum/difference of the original one with the argument while the second form
222 modifies the object to which it is applied. The operators -= and += are
223 defined to be equivalent to the second forms of these functions.
225 @ref addts() Add(wxTimeSpan)
227 @ref addds() Add(wxDateSpan)
229 @ref subtractts() Subtract(wxTimeSpan)
231 @ref subtractds() Subtract(wxDateSpan)
233 @ref subtractdt() Subtract(wxDateTime)
235 @ref addts() oparator+=(wxTimeSpan)
237 @ref addds() oparator+=(wxDateSpan)
239 @ref subtractts() oparator-=(wxTimeSpan)
241 @ref subtractds() oparator-=(wxDateSpan)
246 There are several function to allow date comparison. To supplement them, a few
247 global operators , etc taking wxDateTime are defined.
268 This function does the same as the standard ANSI C @c strftime(3) function.
269 Please see its description for the meaning of @e format parameter.
271 It also accepts a few wxWidgets-specific extensions: you can optionally specify
272 the width of the field to follow using @c printf(3)-like syntax and the
273 format specification @c %l can be used to get the number of milliseconds.
277 wxString
Format(const wxChar
* format
= wxDefaultDateTimeFormat
,
278 const TimeZone
& tz
= Local
);
281 Identical to calling Format() with @c "%x"
282 argument (which means 'preferred date representation for the current locale').
284 wxString
FormatDate();
287 Returns the combined date-time representation in the ISO 8601 format
288 (YYYY-MM-DDTHH:MM:SS). The @e sep parameter default value produces the
289 result exactly corresponding to the ISO standard, but it can also be useful to
290 use a space as seprator if a more human-readable combined date-time
291 representation is needed.
293 @sa FormatISODate(), FormatISOTime(),
296 wxString
FormatISOCombined(char sep
= 'T');
299 This function returns the date representation in the ISO 8601 format
302 wxString
FormatISODate();
305 This function returns the time representation in the ISO 8601 format
308 wxString
FormatISOTime();
311 Identical to calling Format() with @c "%X"
312 argument (which means 'preferred time representation for the current locale').
314 wxString
FormatTime();
317 Transform the date from the given time zone to the local one. If @e noDST is
318 @true, no DST adjustments will be made.
320 Returns the date in the local time zone.
322 wxDateTime
FromTimezone(const TimeZone
& tz
,
323 bool noDST
= @
false);
326 Returns the translations of the strings @c AM and @c PM used for time
327 formatting for the current locale. Either of the pointers may be @NULL if
328 the corresponding value is not needed.
330 static void GetAmPmStrings(wxString
* am
, wxString
* pm
);
333 Returns the date and time in
337 unsigned long GetAsDOS();
340 Get the beginning of DST for the given country in the given year (current one
341 by default). This function suffers from limitations described in
342 @ref overview_tdatedst "DST overview".
346 static wxDateTime
GetBeginDST(int year
= Inv_Year
,
347 Country country
= Country_Default
);
350 Returns the century of this date.
352 int GetCentury(const TimeZone
& tz
= Local
);
355 Returns the current default country. The default country is used for DST
356 calculations, for example.
360 static Country
GetCountry();
363 Get the current month in given calendar (only Gregorian is currently supported).
365 static Month
GetCurrentMonth(Calendar cal
= Gregorian
);
368 Get the current year in given calendar (only Gregorian is currently supported).
370 static int GetCurrentYear(Calendar cal
= Gregorian
);
373 Returns the object having the same date component as this one but time of
376 This function is new since wxWidgets version 2.8.2
380 wxDateTime
GetDateOnly();
383 Returns the day in the given timezone (local one by default).
385 wxDateTime_t
GetDay(const TimeZone
& tz
= Local
);
388 Returns the day of the year (in 1...366 range) in the given timezone
389 (local one by default).
391 wxDateTime_t
GetDayOfYear(const TimeZone
& tz
= Local
);
394 Returns the end of DST for the given country in the given year (current one by
399 static wxDateTime
GetEndDST(int year
= Inv_Year
,
400 Country country
= Country_Default
);
403 Returns the hour in the given timezone (local one by default).
405 wxDateTime_t
GetHour(const TimeZone
& tz
= Local
);
408 Synonym for GetJulianDayNumber().
410 #define double GetJDN() /* implementation is private */
413 Returns the @ref setjdn() JDN corresponding to this date. Beware
416 @sa GetModifiedJulianDayNumber()
418 double GetJulianDayNumber();
421 Returns the copy of this object to which
422 SetToLastMonthDay() was applied.
424 wxDateTime
GetLastMonthDay(Month month
= Inv_Month
,
425 int year
= Inv_Year
);
428 Returns the copy of this object to which
429 SetToLastWeekDay() was applied.
431 wxDateTime
GetLastWeekDay(WeekDay weekday
,
432 Month month
= Inv_Month
,
433 int year
= Inv_Year
);
436 Synonym for GetModifiedJulianDayNumber().
438 #define double GetMJD() /* implementation is private */
441 Returns the milliseconds in the given timezone (local one by default).
443 wxDateTime_t
GetMillisecond(const TimeZone
& tz
= Local
);
446 Returns the minute in the given timezone (local one by default).
448 wxDateTime_t
GetMinute(const TimeZone
& tz
= Local
);
451 Returns the @e Modified Julian Day Number (MJD) which is, by definition,
452 equal to JDN - 2400000.5. The MJDs are simpler to work with as the integral
453 MJDs correspond to midnights of the dates in the Gregorian calendar and not th
454 noons like JDN. The MJD 0 is Nov 17, 1858.
456 double GetModifiedJulianDayNumber();
459 Returns the month in the given timezone (local one by default).
461 Month
GetMonth(const TimeZone
& tz
= Local
);
464 Gets the full (default) or abbreviated (specify @c Name_Abbr name of the
469 static wxString
GetMonthName(Month month
,
470 NameFlags flags
= Name_Full
);
473 Returns the copy of this object to which
474 SetToNextWeekDay() was applied.
476 wxDateTime
GetNextWeekDay(WeekDay weekday
);
480 Returns the number of days in the given year or in the given month of the
483 The only supported value for @e cal parameter is currently @c Gregorian.
485 static wxDateTime_t
GetNumberOfDays(int year
,
486 Calendar cal
= Gregorian
);
487 static wxDateTime_t
GetNumberOfDays(Month month
,
489 Calendar cal
= Gregorian
);
493 Returns the copy of this object to which
494 SetToPrevWeekDay() was applied.
496 wxDateTime
GetPrevWeekDay(WeekDay weekday
);
499 Return the @e Rata Die number of this date.
501 By definition, the Rata Die number is a date specified as the number of days
502 relative to a base date of December 31 of the year 0. Thus January 1 of the
503 year 1 is Rata Die day 1.
508 Returns the seconds in the given timezone (local one by default).
510 wxDateTime_t
GetSecond(const TimeZone
& tz
= Local
);
513 Returns the number of seconds since Jan 1, 1970. An assert failure will occur
514 if the date is not in the range covered by @c time_t type.
519 Returns the current time.
521 static time_t GetTimeNow();
524 Returns broken down representation of the date and time.
526 Tm
GetTm(const TimeZone
& tz
= Local
);
529 Returns the current time broken down. Note that this function returns a
530 pointer to a static buffer that's reused by calls to this function and
531 certain C library functions (e.g. localtime). If there is any chance your
532 code might be used in a multi-threaded application, you really should use
533 the flavour of function GetTmNow()
536 static struct tm
* GetTmNow();
539 Returns the copy of this object to which
540 SetToWeekDay() was applied.
542 wxDateTime
GetWeekDay(WeekDay weekday
, int n
= 1,
543 Month month
= Inv_Month
,
544 int year
= Inv_Year
);
547 Returns the copy of this object to which
548 SetToWeekDayInSameWeek() was
551 wxDateTime
GetWeekDayInSameWeek(WeekDay weekday
,
552 WeekFlags flags
= Monday_First
);
555 Gets the full (default) or abbreviated (specify @c Name_Abbr name of the
560 static wxString
GetWeekDayName(WeekDay weekday
,
561 NameFlags flags
= Name_Full
);
564 Returns the ordinal number of the week in the month (in 1...5 range).
566 As GetWeekOfYear(), this function supports
567 both conventions for the week start. See the description of these
568 @ref overview_wxdatetime "week start" conventions.
570 wxDateTime_t
GetWeekOfMonth(WeekFlags flags
= Monday_First
,
571 const TimeZone
& tz
= Local
);
574 Returns the number of the week of the year this date is in. The first week of
575 the year is, according to international standards, the one containing Jan 4 or,
576 equivalently, the first week which has Thursday in this year. Both of these
577 definitions are the same as saying that the first week of the year must contain
578 more than half of its days in this year. Accordingly, the week number will
579 always be in 1...53 range (52 for non-leap years).
581 The function depends on the @ref overview_wxdatetime "week start" convention
582 specified by the @e flags argument but its results for
583 @c Sunday_First are not well-defined as the ISO definition quoted above
584 applies to the weeks starting on Monday only.
586 wxDateTime_t
GetWeekOfYear(WeekFlags flags
= Monday_First
,
587 const TimeZone
& tz
= Local
);
590 Returns the year in the given timezone (local one by default).
592 int GetYear(const TimeZone
& tz
= Local
);
595 Returns the copy of this object to which
596 SetToYearDay() was applied.
598 wxDateTime
GetYearDay(wxDateTime_t yday
);
601 Returns @true if IsStrictlyBetween()
602 is @true or if the date is equal to one of the limit values.
604 @sa IsStrictlyBetween()
606 bool IsBetween(const wxDateTime
& t1
, const wxDateTime
& t2
);
609 Returns @true if the DST is applied for this date in the given country.
611 #define int IsDST(Country country = Country_Default) /* implementation is private */
614 Returns @true if DST was used n the given year (the current one by
615 default) in the given country.
617 static bool IsDSTApplicable(int year
= Inv_Year
,
618 Country country
= Country_Default
);
621 Returns @true if this date precedes the given one.
623 bool IsEarlierThan(const wxDateTime
& datetime
);
626 Returns @true if the two dates are strictly identical.
628 bool IsEqualTo(const wxDateTime
& datetime
);
631 Returns @true if the date is equal to another one up to the given time
632 interval, i.e. if the absolute difference between the two dates is less than
635 bool IsEqualUpTo(const wxDateTime
& dt
, const wxTimeSpan
& ts
);
638 Returns @true if the given date is later than the date of adoption of the
639 Gregorian calendar in the given country (and hence the Gregorian calendar
640 calculations make sense for it).
642 bool IsGregorianDate(GregorianAdoption country
= Gr_Standard
);
645 Returns @true if this date is later than the given one.
647 bool IsLaterThan(const wxDateTime
& datetime
);
650 Returns @true if the @e year is a leap one in the specified calendar.
652 This functions supports Gregorian and Julian calendars.
654 static bool IsLeapYear(int year
= Inv_Year
,
655 Calendar cal
= Gregorian
);
658 Returns @true if the date is the same without comparing the time parts.
660 bool IsSameDate(const wxDateTime
& dt
);
663 Returns @true if the time is the same (although dates may differ).
665 bool IsSameTime(const wxDateTime
& dt
);
668 Returns @true if this date lies strictly between the two others,
672 bool IsStrictlyBetween(const wxDateTime
& t1
,
673 const wxDateTime
& t2
);
676 Returns @true if the object represents a valid time moment.
681 This function returns @true if the specified (or default) country is one
682 of Western European ones. It is used internally by wxDateTime to determine the
683 DST convention and date and time formatting rules.
685 static bool IsWestEuropeanCountry(Country country
= Country_Default
);
688 Returns @true is this day is not a holiday in the given country.
690 bool IsWorkDay(Country country
= Country_Default
);
693 Same as FromTimezone() but modifies the object
696 wxDateTime
MakeFromTimezone(const TimeZone
& tz
,
697 bool noDST
= @
false);
700 Modifies the object in place to represent the date in another time zone. If
701 @e noDST is @true, no DST adjustments will be made.
703 wxDateTime
MakeTimezone(const TimeZone
& tz
,
704 bool noDST
= @
false);
707 This is the same as calling MakeTimezone() with
708 the argument @c GMT0.
710 wxDateTime
MakeUTC(bool noDST
= @
false);
713 Returns the object corresponding to the current time.
716 Note that this function is accurate up to second:
717 UNow() should be used for better precision
718 (but it is less efficient and might not be available on all platforms).
722 #define static wxDateTime Now() /* implementation is private */
726 This function is like ParseDateTime(), but it
727 only allows the date to be specified. It is thus less flexible then
728 ParseDateTime(), but also has less chances to
729 misinterpret the user input.
731 Returns @NULL if the conversion failed, otherwise return the pointer to
732 the character which stopped the scan.
734 const char * ParseDate(const wxString
& date
,
735 wxString::const_iterator
* end
= @NULL
);
736 const char * ParseDate(const char * date
);
737 const wchar_t * ParseDate(const wchar_t * date
);
742 Parses the string @e datetime containing the date and time in free format.
743 This function tries as hard as it can to interpret the given string as date
744 and time. Unlike wxDateTime::ParseRfc822Date, it
745 will accept anything that may be accepted and will only reject strings which
746 can not be parsed in any way at all.
748 Returns @NULL if the conversion failed, otherwise return the pointer to
749 the character which stopped the scan.
751 const char * ParseDateTime(const wxString
& datetime
,
752 wxString::const_iterator
* end
= @NULL
);
753 const char * ParseDateTime(const char * datetime
);
754 const wchar_t * ParseDateTime(const wchar_t * datetime
);
759 This function parses the string @e date according to the given
760 @e format. The system @c strptime(3) function is used whenever available,
761 but even if it is not, this function is still implemented, although support
762 for locale-dependent format specifiers such as @c "%c", @c "%x" or @c "%X" may
763 not be perfect and GNU extensions such as @c "%z" and @c "%Z" are
764 not implemented. This function does handle the month and weekday
765 names in the current locale on all platforms, however.
767 Please see the description of the ANSI C function @c strftime(3) for the syntax
768 of the format string.
770 The @e dateDef parameter is used to fill in the fields which could not be
771 determined from the format string. For example, if the format is @c "%d" (the
772 ay of the month), the month and the year are taken from @e dateDef. If
773 it is not specified, Today() is used as the
776 Returns @NULL if the conversion failed, otherwise return the pointer to
777 the character which stopped the scan.
779 const char * ParseFormat(const wxString
& date
,
780 const wxString
& format
= wxDefaultDateTimeFormat
,
781 const wxDateTime
& dateDef
= wxDefaultDateTime
,
782 wxString::const_iterator
* end
= @NULL
);
783 const char * ParseFormat(const char * date
,
784 const wxString
& format
= wxDefaultDateTimeFormat
,
785 const wxDateTime
& dateDef
= wxDefaultDateTime
);
786 const wchar_t * ParseFormat(const wchar_t * date
,
787 const wxString
& format
= wxDefaultDateTimeFormat
,
788 const wxDateTime
& dateDef
= wxDefaultDateTime
);
792 This function parses the string containing the date and time in ISO 8601
793 combined format (YYYY-MM-DDTHH:MM:SS). The separator between the date and time
794 parts must be equal to @e sep for the function to succeed.
796 Returns @true if the entire string was parsed successfully, @false
799 bool ParseISOCombined(const wxString
& date
, char sep
= 'T');
802 This function parses the date in ISO 8601 format (YYYY-MM-DD).
804 Returns @true if the entire string was parsed successfully, @false
807 bool ParseISODate(const wxString
& date
);
810 This function parses the time in ISO 8601 format (HH:MM:SS).
812 Returns @true if the entire string was parsed successfully, @false
815 bool ParseISOTime(const wxString
& date
);
819 Parses the string @e date looking for a date formatted according to the RFC
820 822 in it. The exact description of this format may, of course, be found in
821 the RFC (section 5), but, briefly, this is the format used in the headers of
822 Internet email messages and one of the most common strings expressing date in
823 this format may be something like @c "Sat, 18 Dec 1999 00:48:30 +0100".
825 Returns @NULL if the conversion failed, otherwise return the pointer to
826 the character immediately following the part of the string which could be
827 parsed. If the entire string contains only the date in RFC 822 format,
828 the returned pointer will be pointing to a @c NUL character.
830 This function is intentionally strict, it will return an error for any string
831 which is not RFC 822 compliant. If you need to parse date formatted in more
832 free ways, you should use ParseDateTime() or
835 const char * ParseRfc822Date(const wxString
& date
,
836 wxString::const_iterator
* end
= @NULL
);
837 const char * ParseRfc822Date(const char* date
);
838 const wchar_t * ParseRfc822Date(const wchar_t* date
);
843 This functions is like ParseDateTime(), but
844 only allows the time to be specified in the input string.
846 Returns @NULL if the conversion failed, otherwise return the pointer to
847 the character which stopped the scan.
849 const char * ParseTime(const wxString
& time
,
850 wxString::const_iterator
* end
= @NULL
);
851 const char * ParseTime(const char * time
);
852 const wchar_t * ParseTime(const wchar_t * time
);
856 These functions convert wxDateTime objects to and from text. The
857 conversions to text are mostly trivial: you can either do it using the default
858 date and time representations for the current locale (
860 wxDateTime::FormatTime), using the international standard
861 representation defined by ISO 8601 (
864 wxDateTime::FormatISOCombined) or by specifying any
865 format at all and using Format() directly.
867 The conversions from text are more interesting, as there are much more
868 possibilities to care about. The simplest cases can be taken care of with
869 ParseFormat() which can parse any date in the
870 given (rigid) format. wxDateTime::ParseRfc822Date is
871 another function for parsing dates in predefined format -- the one of RFC 822
872 which (still...) defines the format of email messages on the Internet. This
873 format can not be described with @c strptime(3)-like format strings used by
874 Format(), hence the need for a separate function.
876 But the most interesting functions are
879 ParseDateTime(). They try to parse the date
880 ans time (or only one of them) in 'free' format, i.e. allow them to be
881 specified in any of possible ways. These functions will usually be used to
882 parse the (interactive) user input which is not bound to be in any predefined
883 format. As an example, ParseDateTime() can
884 parse the strings such as @c "tomorrow", @c "March first" and even
887 Finally notice that each of the parsing functions is available in several
888 overloads: if the input string is a narrow (@c char *) string, then a
889 narrow pointer is returned. If the input string is a wide string, a wide char
890 pointer is returned. Finally, if the input parameter is a wxString, a narrow
891 char pointer is also returned for backwards compatibility but there is also an
892 additional argument of wxString::const_iterator type in which, if it is not
893 @NULL, an iterator pointing to the end of the scanned string part is returned.
909 wxDateTime::ParseRfc822Date
926 Reset time to midnight (00:00:00) without changing the date.
928 wxDateTime
ResetTime();
931 Sets the date and time from the parameters.
933 #define wxDateTime Set(wxDateTime_t day, Month month = Inv_Month,
935 wxDateTime_t hour
= 0,
936 wxDateTime_t minute
= 0,
937 wxDateTime_t second
= 0,
938 wxDateTime_t millisec
= 0) /* implementation is private */
941 Sets the country to use by default. This setting influences the DST
942 calculations, date formatting and other things.
944 The possible values for @e country parameter are enumerated in
945 @ref overview_wxdatetime "wxDateTime constants section".
949 static void SetCountry(Country country
);
952 Sets the day without changing other date components.
954 wxDateTime
SetDay(wxDateTime_t day
);
957 Sets the date from the date and time in
961 wxDateTime
Set(unsigned long ddt
);
964 Sets the hour without changing other date components.
966 wxDateTime
SetHour(wxDateTime_t hour
);
969 Sets the millisecond without changing other date components.
971 wxDateTime
SetMillisecond(wxDateTime_t millisecond
);
974 Sets the minute without changing other date components.
976 wxDateTime
SetMinute(wxDateTime_t minute
);
979 Sets the month without changing other date components.
981 wxDateTime
SetMonth(Month month
);
984 Sets the second without changing other date components.
986 wxDateTime
SetSecond(wxDateTime_t second
);
989 Sets the date and time of to the current values. Same as assigning the result
990 of Now() to this object.
992 wxDateTime
SetToCurrent();
995 Sets the date to the last day in the specified month (the current one by
998 Returns the reference to the modified object itself.
1000 wxDateTime
SetToLastMonthDay(Month month
= Inv_Month
,
1001 int year
= Inv_Year
);
1004 The effect of calling this function is the same as of calling
1005 @c SetToWeekDay(-1, weekday, month, year). The date will be set to the last
1006 @e weekday in the given month and year (the current ones by default).
1008 Always returns @true.
1010 bool SetToLastWeekDay(WeekDay weekday
, Month month
= Inv_Month
,
1011 int year
= Inv_Year
);
1014 Sets the date so that it will be the first @e weekday following the current
1017 Returns the reference to the modified object itself.
1019 wxDateTime
SetToNextWeekDay(WeekDay weekday
);
1022 Sets the date so that it will be the last @e weekday before the current
1025 Returns the reference to the modified object itself.
1027 wxDateTime
SetToPrevWeekDay(WeekDay weekday
);
1030 Sets the date to the @e n-th @e weekday in the given month of the given
1031 year (the current month and year are used by default). The parameter @e n
1032 may be either positive (counting from the beginning of the month) or negative
1033 (counting from the end of it).
1035 For example, @c SetToWeekDay(2, wxDateTime::Wed) will set the date to the
1036 second Wednesday in the current month and
1037 @c SetToWeekDay(-1, wxDateTime::Sun) -- to the last Sunday in it.
1039 Returns @true if the date was modified successfully, @false
1040 otherwise meaning that the specified date doesn't exist.
1042 bool SetToWeekDay(WeekDay weekday
, int n
= 1,
1043 Month month
= Inv_Month
,
1044 int year
= Inv_Year
);
1047 Adjusts the date so that it will still lie in the same week as before, but its
1048 week day will be the given one.
1050 Returns the reference to the modified object itself.
1052 wxDateTime
SetToWeekDayInSameWeek(WeekDay weekday
,
1053 WeekFlags flags
= Monday_First
);
1056 Set the date to the given @e weekday in the week number @e numWeek of the
1057 given @e year . The number should be in range 1...53.
1059 Note that the returned date may be in a different year than the one passed to
1060 this function because both the week 1 and week 52 or 53 (for leap years)
1061 contain days from different years. See
1062 GetWeekOfYear() for the explanation of how the
1063 year weeks are counted.
1065 static wxDateTime
SetToWeekOfYear(int year
, wxDateTime_t numWeek
,
1066 WeekDay weekday
= Mon
);
1069 Sets the date to the day number @e yday in the same year (i.e., unlike the
1070 other functions, this one does not use the current year). The day number
1071 should be in the range 1...366 for the leap years and 1...365 for
1074 Returns the reference to the modified object itself.
1076 wxDateTime
SetToYearDay(wxDateTime_t yday
);
1079 Sets the year without changing other date components.
1081 wxDateTime
SetYear(int year
);
1084 For convenience, all static functions are collected here. These functions
1085 either set or return the static variables of wxDateSpan (the country), return
1086 the current moment, year, month or number of days in it, or do some general
1087 calendar-related actions.
1089 Please note that although several function accept an extra @e Calendar
1090 parameter, it is currently ignored as only the Gregorian calendar is
1091 supported. Future versions will support other calendars.
1096 IsWestEuropeanCountry()
1106 @ref getcenturystatic() GetCentury
1133 Subtracts another date from this one and returns the difference between them
1136 wxTimeSpan
Subtract(const wxDateTime
& dt
);
1139 Please see the @ref overview_tdatetimezones "time zone overview" for more
1140 information about time zones. Normally, these functions should be rarely used.
1163 Transform the date to the given time zone. If @e noDST is @true, no
1164 DST adjustments will be made.
1166 Returns the date in the new time zone.
1168 wxDateTime
ToTimezone(const TimeZone
& tz
, bool noDST
= @
false);
1171 This is the same as calling ToTimezone() with
1172 the argument @c GMT0.
1174 #define wxDateTime ToUTC(bool noDST = @false) /* implementation is private */
1177 Returns the object corresponding to the midnight of the current day (i.e. the
1178 same as Now(), but the time part is set to 0).
1182 static wxDateTime
Today();
1185 Returns the object corresponding to the current time including the
1186 milliseconds if a function to get time with such precision is available on the
1187 current platform (supported under most Unices and Win32).
1191 #define static wxDateTime UNow() /* implementation is private */
1194 Same as @ref settm() Set.
1196 wxDateTime
operator(const struct tm
& tm
);
1201 @class wxDateTimeWorkDays
1202 @wxheader{datetime.h}
1208 class wxDateTimeWorkDays
1217 @wxheader{datetime.h}
1219 This class is a "logical time span" and is useful for implementing program
1220 logic for such things as "add one month to the date" which, in general,
1221 doesn't mean to add 60*60*24*31 seconds to it, but to take the same date
1222 the next month (to understand that this is indeed different consider adding
1223 one month to Feb, 15 -- we want to get Mar, 15, of course).
1225 When adding a month to the date, all lesser components (days, hours, ...)
1226 won't be changed unless the resulting date would be invalid: for example,
1227 Jan 31 + 1 month will be Feb 28, not (non-existing) Feb 31.
1229 Because of this feature, adding and subtracting back again the same
1230 wxDateSpan will @b not, in general give back the original date: Feb 28 - 1
1231 month will be Jan 28, not Jan 31!
1233 wxDateSpan objects can be either positive or negative. They may be
1234 multiplied by scalars which multiply all deltas by the scalar: i.e.
1235 2*(1 month and 1 day) is 2 months and 2 days. They can
1236 be added together and with wxDateTime or
1237 wxTimeSpan, but the type of result is different for each
1240 Beware about weeks: if you specify both weeks and days, the total number of
1241 days added will be 7*weeks + days! See also GetTotalDays()
1244 Equality operators are defined for wxDateSpans. Two datespans are equal if
1245 and only if they both give the same target date when added to @b every
1246 source date. Thus wxDateSpan::Months(1) is not equal to wxDateSpan::Days(30),
1247 because they don't give the same date when added to 1 Feb. But
1248 wxDateSpan::Days(14) is equal to wxDateSpan::Weeks(2)
1250 Finally, notice that for adding hours, minutes and so on you don't need this
1251 class at all: wxTimeSpan will do the job because there
1252 are no subtleties associated with those (we don't support leap seconds).
1258 @ref overview_wxdatetimeoverview "Date classes overview", wxDateTime
1264 Constructs the date span object for the given number of years, months, weeks
1265 and days. Note that the weeks and days add together if both are given.
1267 wxDateSpan(int years
= 0, int months
= 0, int weeks
= 0,
1272 Returns the sum of two date spans. The first version returns a new object, the
1273 second and third ones modify this object in place.
1275 wxDateSpan
Add(const wxDateSpan
& other
);
1276 wxDateSpan
Add(const wxDateSpan
& other
);
1277 wxDateSpan
operator+=(const wxDateSpan
& other
);
1281 Returns a date span object corresponding to one day.
1285 #define static wxDateSpan Day() /* implementation is private */
1288 Returns a date span object corresponding to the given number of days.
1292 static wxDateSpan
Days(int days
);
1295 Returns the number of days (only, that it not counting the weeks component!)
1303 Returns the number of the months (not counting the years) in this date span.
1308 Returns the combined number of days in this date span, counting both weeks and
1309 days. It still doesn't take neither months nor years into the account.
1311 @sa GetWeeks(), GetDays()
1316 Returns the number of weeks in this date span.
1323 Returns the number of years in this date span.
1328 Returns a date span object corresponding to one month.
1332 static wxDateSpan
Month();
1335 Returns a date span object corresponding to the given number of months.
1339 static wxDateSpan
Months(int mon
);
1343 Returns the product of the date span by the specified @e factor. The
1344 product is computed by multiplying each of the components by the factor.
1346 The first version returns a new object, the second and third ones modify this
1349 wxDateSpan
Multiply(int factor
);
1350 wxDateSpan
Multiply(int factor
);
1351 wxDateSpan
operator*=(int factor
);
1356 Changes the sign of this date span.
1361 wxDateSpan
operator-();
1365 Returns the date span with the opposite sign.
1369 wxDateSpan
Negate();
1372 Sets the number of days (without modifying any other components) in this date
1375 wxDateSpan
SetDays(int n
);
1378 Sets the number of months (without modifying any other components) in this
1381 wxDateSpan
SetMonths(int n
);
1384 Sets the number of weeks (without modifying any other components) in this date
1387 wxDateSpan
SetWeeks(int n
);
1390 Sets the number of years (without modifying any other components) in this date
1393 wxDateSpan
SetYears(int n
);
1397 Returns the difference of two date spans. The first version returns a new
1398 object, the second and third ones modify this object in place.
1400 wxDateSpan
Subtract(const wxDateSpan
& other
);
1401 wxDateSpan
Subtract(const wxDateSpan
& other
);
1402 wxDateSpan
operator+=(const wxDateSpan
& other
);
1406 Returns a date span object corresponding to one week.
1410 static wxDateSpan
Week();
1413 Returns a date span object corresponding to the given number of weeks.
1417 static wxDateSpan
Weeks(int weeks
);
1420 Returns a date span object corresponding to one year.
1424 static wxDateSpan
Year();
1427 Returns a date span object corresponding to the given number of years.
1431 static wxDateSpan
Years(int years
);
1434 Returns @true if this date span is different from the other one.
1436 bool operator!=(wxDateSpan
& other
);
1439 Returns @true if this date span is equal to the other one. Two date spans
1440 are considered equal if and only if they have the same number of years and
1441 months and the same total number of days (counting both days and weeks).
1443 bool operator==(wxDateSpan
& other
);
1449 @wxheader{datetime.h}
1451 wxTimeSpan class represents a time interval.
1457 @ref overview_wxdatetimeoverview "Date classes overview", wxDateTime
1464 Constructs timespan from separate values for each component, with the date
1465 set to 0. Hours are not restricted to 0..24 range, neither are
1466 minutes, seconds or milliseconds.
1469 wxTimeSpan(long hours
, long min
, long sec
, long msec
);
1473 Returns the absolute value of the timespan: does not modify the
1476 #define wxTimeSpan Abs() /* implementation is private */
1495 Returns the sum of two timespans.
1497 wxTimeSpan
Add(const wxTimeSpan
& diff
);
1498 wxTimeSpan
Add(const wxTimeSpan
& diff
);
1499 wxTimeSpan
operator+=(const wxTimeSpan
& diff
);
1503 @ref ctor() wxTimeSpan
1508 Returns the timespan for one day.
1510 #define static wxTimespan Day() /* implementation is private */
1513 Returns the timespan for the given number of days.
1515 static wxTimespan
Days(long days
);
1518 Returns the string containing the formatted representation of the time span.
1519 The following format specifiers are allowed after %:
1529 number of @b Minutes
1534 number of @b Seconds
1539 number of mi@b lliseconds
1554 the percent character
1556 Note that, for example, the number of hours in the description above is not
1557 well defined: it can be either the total number of hours (for example, for a
1558 time span of 50 hours this would be 50) or just the hour part of the time
1559 span, which would be 2 in this case as 50 hours is equal to 2 days and
1562 wxTimeSpan resolves this ambiguity in the following way: if there had been,
1563 indeed, the @c %D format specified preceding the @c %H, then it is
1564 interpreted as 2. Otherwise, it is 50.
1566 The same applies to all other format specifiers: if they follow a specifier of
1567 larger unit, only the rest part is taken, otherwise the full value is used.
1569 wxString
Format(const wxChar
* format
= wxDefaultTimeSpanFormat
);
1577 Returns the difference in number of days.
1582 Returns the difference in number of hours.
1587 Returns the difference in number of milliseconds.
1589 wxLongLong
GetMilliseconds();
1592 Returns the difference in number of minutes.
1597 Returns the difference in number of seconds.
1599 wxLongLong
GetSeconds();
1602 Returns the internal representation of timespan.
1604 wxLongLong
GetValue();
1607 Returns the difference in number of weeks.
1612 Returns the timespan for one hour.
1614 static wxTimespan
Hour();
1617 Returns the timespan for the given number of hours.
1619 static wxTimespan
Hours(long hours
);
1622 Returns @true if two timespans are equal.
1624 bool IsEqualTo(const wxTimeSpan
& ts
);
1627 Compares two timespans: works with the absolute values, i.e. -2
1628 hours is longer than 1 hour. Also, it will return @false if
1629 the timespans are equal in absolute value.
1631 bool IsLongerThan(const wxTimeSpan
& ts
);
1634 Returns @true if the timespan is negative.
1639 Returns @true if the timespan is empty.
1644 Returns @true if the timespan is positive.
1649 Compares two timespans: works with the absolute values, i.e. 1
1650 hour is shorter than -2 hours. Also, it will return @false if
1651 the timespans are equal in absolute value.
1653 bool IsShorterThan(const wxTimeSpan
& ts
);
1656 Returns the timespan for one millisecond.
1658 static wxTimespan
Millisecond();
1661 Returns the timespan for the given number of milliseconds.
1663 static wxTimespan
Milliseconds(long ms
);
1666 Returns the timespan for one minute.
1668 static wxTimespan
Minute();
1671 Returns the timespan for the given number of minutes.
1673 static wxTimespan
Minutes(long min
);
1677 Multiplies timespan by a scalar.
1679 wxTimeSpan
Multiply(int n
);
1680 wxTimeSpan
Multiply(int n
);
1681 wxTimeSpan
operator*=(int n
);
1686 Negate the value of the timespan.
1689 wxTimeSpan
operator-();
1693 Returns timespan with inverted sign.
1695 wxTimeSpan
Negate();
1713 Returns the timespan for one second.
1715 static wxTimespan
Second();
1718 Returns the timespan for the given number of seconds.
1720 static wxTimespan
Seconds(long sec
);
1751 Returns the difference of two timespans.
1753 wxTimeSpan
Subtract(const wxTimeSpan
& diff
);
1754 wxTimeSpan
Subtract(const wxTimeSpan
& diff
);
1755 wxTimeSpan
operator-=(const wxTimeSpan
& diff
);
1774 Returns the timespan for one week.
1776 static wxTimespan
Week();
1779 Returns the timespan for the given number of weeks.
1781 static wxTimespan
Weeks(long weeks
);
1786 @class wxDateTimeHolidayAuthority
1787 @wxheader{datetime.h}
1793 class wxDateTimeHolidayAuthority