1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of wxDateTime
4 // Author: wxWidgets team
6 // Licence: wxWindows license
7 /////////////////////////////////////////////////////////////////////////////
13 wxDateTime class represents an absolute moment in the time.
15 The type @c wxDateTime_t is typedefed as <tt>unsigned short</tt> and is
16 used to contain the number of years, hours, minutes, seconds and
20 @section datetime_constants Constants
22 Global constant wxDefaultDateTime and synonym for it wxInvalidDateTime are
23 defined. This constant will be different from any valid wxDateTime object.
25 All the following constants are defined inside wxDateTime class (i.e., to
26 refer to them you should prepend their names with "wxDateTime::").
28 Time zone symbolic names:
33 // the time in the current time zone
36 // zones from GMT (= Greenwhich Mean Time): they're guaranteed to be
37 // consequent numbers, so writing something like `GMT0 + offset' is
38 // safe if abs(offset) <= 12
40 // underscore stands for minus
41 GMT_12, GMT_11, GMT_10, GMT_9, GMT_8, GMT_7,
42 GMT_6, GMT_5, GMT_4, GMT_3, GMT_2, GMT_1,
44 GMT1, GMT2, GMT3, GMT4, GMT5, GMT6,
45 GMT7, GMT8, GMT9, GMT10, GMT11, GMT12, GMT13,
46 // Note that GMT12 and GMT_12 are not the same: there is a difference
47 // of exactly one day between them
49 // some symbolic names for TZ
52 WET = GMT0, // Western Europe Time
53 WEST = GMT1, // Western Europe Summer Time
54 CET = GMT1, // Central Europe Time
55 CEST = GMT2, // Central Europe Summer Time
56 EET = GMT2, // Eastern Europe Time
57 EEST = GMT3, // Eastern Europe Summer Time
58 MSK = GMT3, // Moscow Time
59 MSD = GMT4, // Moscow Summer Time
62 AST = GMT_4, // Atlantic Standard Time
63 ADT = GMT_3, // Atlantic Daylight Time
64 EST = GMT_5, // Eastern Standard Time
65 EDT = GMT_4, // Eastern Daylight Saving Time
66 CST = GMT_6, // Central Standard Time
67 CDT = GMT_5, // Central Daylight Saving Time
68 MST = GMT_7, // Mountain Standard Time
69 MDT = GMT_6, // Mountain Daylight Saving Time
70 PST = GMT_8, // Pacific Standard Time
71 PDT = GMT_7, // Pacific Daylight Saving Time
72 HST = GMT_10, // Hawaiian Standard Time
73 AKST = GMT_9, // Alaska Standard Time
74 AKDT = GMT_8, // Alaska Daylight Saving Time
78 A_WST = GMT8, // Western Standard Time
79 A_CST = GMT13 + 1, // Central Standard Time (+9.5)
80 A_EST = GMT10, // Eastern Standard Time
81 A_ESST = GMT11, // Eastern Summer Time
84 NZST = GMT12, // Standard Time
85 NZDT = GMT13, // Daylight Saving Time
87 // Universal Coordinated Time = the new and politically correct name
93 Month names: Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec and
94 Inv_Month for an invalid month are the values of @c wxDateTime::Month enum.
96 Likewise, Sun, Mon, Tue, Wed, Thu, Fri, Sat, and Inv_WeekDay are the values
97 in @c wxDateTime::WeekDay enum.
99 Finally, Inv_Year is defined to be an invalid value for year parameter.
101 GetMonthName() and GetWeekDayName() functions use the following flags:
106 Name_Full = 0x01, // return full name
107 Name_Abbr = 0x02 // return abbreviated name
111 Several functions accept an extra parameter specifying the calendar to use
112 (although most of them only support now the Gregorian calendar). This
113 parameters is one of the following values:
118 Gregorian, // calendar currently in use in Western countries
119 Julian // calendar in use since -45 until the 1582 (or later)
123 Date calculations often depend on the country and wxDateTime allows to set
124 the country whose conventions should be used using SetCountry(). It takes
125 one of the following values as parameter:
130 Country_Unknown, // no special information for this country
131 Country_Default, // set the default country with SetCountry() method
132 // or use the default country with any other
134 Country_WesternEurope_Start,
135 Country_EEC = Country_WesternEurope_Start,
139 Country_WesternEurope_End = UK,
147 Different parts of the world use different conventions for the week start.
148 In some countries, the week starts on Sunday, while in others -- on Monday.
149 The ISO standard doesn't address this issue, so we support both conventions
150 in the functions whose result depends on it (GetWeekOfYear() and
153 The desired behvaiour may be specified by giving one of the following
154 constants as argument to these functions:
159 Default_First, // Sunday_First for US, Monday_First for the rest
160 Monday_First, // week starts with a Monday
161 Sunday_First // week starts with a Sunday
166 @section datetime_static Static Functions
168 All static functions either set or return the static variables of
169 wxDateSpan (the country), return the current moment, year, month or number
170 of days in it, or do some general calendar-related actions.
172 Please note that although several function accept an extra Calendar
173 parameter, it is currently ignored as only the Gregorian calendar is
174 supported. Future versions will support other calendars.
177 These methods are standalone functions named
178 "wxDateTime_<StaticMethodName>" in wxPython.
182 @section datetime_formatting Date Formatting and Parsing
184 The date formatting and parsing functions convert wxDateTime objects to and
185 from text. The conversions to text are mostly trivial: you can either do it
186 using the default date and time representations for the current locale
187 (FormatDate() and FormatTime()), using the international standard
188 representation defined by ISO 8601 (FormatISODate(), FormatISOTime() and
189 FormatISOCombined()) or by specifying any format at all and using Format()
192 The conversions from text are more interesting, as there are much more
193 possibilities to care about. The simplest cases can be taken care of with
194 ParseFormat() which can parse any date in the given (rigid) format.
195 ParseRfc822Date() is another function for parsing dates in predefined
196 format -- the one of RFC 822 which (still...) defines the format of email
197 messages on the Internet. This format can not be described with
198 @c strptime(3)-like format strings used by Format(), hence the need for a
201 But the most interesting functions are ParseTime(), ParseDate() and
202 ParseDateTime(). They try to parse the date and time (or only one of them)
203 in 'free' format, i.e. allow them to be specified in any of possible ways.
204 These functions will usually be used to parse the (interactive) user input
205 which is not bound to be in any predefined format. As an example,
206 ParseDateTime() can parse the strings such as "tomorrow", "March first" and
209 Finally notice that each of the parsing functions is available in several
210 overloads: if the input string is a narrow (@c char *) string, then a
211 narrow pointer is returned. If the input string is a wide string, a wide
212 char pointer is returned. Finally, if the input parameter is a wxString, a
213 narrow char pointer is also returned for backwards compatibility but there
214 is also an additional argument of wxString::const_iterator type in which,
215 if it is not @NULL, an iterator pointing to the end of the scanned string
223 - ::wxDefaultDateTime
225 @see @ref overview_datetime, wxTimeSpan, wxDateSpan, wxCalendarCtrl
231 @name Constructors, Assignment Operators and Setters
233 Constructors and various Set() methods are collected here. If you
234 construct a date object from separate values for day, month and year,
235 you should use IsValid() method to check that the values were correct
236 as constructors can not return an error code.
241 Default constructor. Use one of the Set() functions to initialize the
249 This constructor is named "wxDateTimeFromTimeT" in wxPython.
252 wxDateTime
& wxDateTime(time_t timet
);
256 @beginWxPythonOnly Unsupported. @endWxPythonOnly
258 wxDateTime
& wxDateTime(const struct tm
& tm
);
263 This constructor is named "wxDateTimeFromJDN" in wxPython.
266 wxDateTime
& wxDateTime(double jdn
);
271 This constructor is named "wxDateTimeFromHMS" in wxPython.
274 wxDateTime
& wxDateTime(wxDateTime_t hour
, wxDateTime_t minute
= 0,
275 wxDateTime_t second
= 0, wxDateTime_t millisec
= 0);
280 This constructor is named "wxDateTimeFromDMY" in wxPython.
283 wxDateTime(wxDateTime_t day
, Month month
= Inv_Month
,
284 int year
= Inv_Year
, wxDateTime_t hour
= 0,
285 wxDateTime_t minute
= 0, wxDateTime_t second
= 0,
286 wxDateTime_t millisec
= 0);
289 Reset time to midnight (00:00:00) without changing the date.
291 wxDateTime
& ResetTime();
294 Constructs the object from @a timet value holding the number of seconds
298 This method is named "SetTimeT" in wxPython.
301 wxDateTime
& Set(time_t timet
);
303 Sets the date and time from the broken down representation in the
304 standard @a tm structure.
306 @beginWxPythonOnly Unsupported. @endWxPythonOnly
308 wxDateTime
& Set(const struct tm
& tm
);
310 Sets the date from the so-called Julian Day Number.
312 By definition, the Julian Day Number, usually abbreviated as JDN, of a
313 particular instant is the fractional number of days since 12 hours
314 Universal Coordinated Time (Greenwich mean noon) on January 1 of the
315 year -4712 in the Julian proleptic calendar.
318 This method is named "SetJDN" in wxPython.
321 wxDateTime
& Set(double jdn
);
323 Sets the date to be equal to Today() and the time from supplied
327 This method is named "SetHMS" in wxPython.
330 wxDateTime
& Set(wxDateTime_t hour
, wxDateTime_t minute
= 0,
331 wxDateTime_t second
= 0, wxDateTime_t millisec
= 0);
333 Sets the date and time from the parameters.
335 wxDateTime
& Set(wxDateTime_t day
, Month month
= Inv_Month
,
336 int year
= Inv_Year
, wxDateTime_t hour
= 0,
337 wxDateTime_t minute
= 0, wxDateTime_t second
= 0,
338 wxDateTime_t millisec
= 0);
341 Sets the day without changing other date components.
343 wxDateTime
& SetDay(short unsigned int);
346 Sets the date from the date and time in DOS format.
348 wxDateTime
& SetFromDOS(unsigned long ddt
);
351 Sets the hour without changing other date components.
353 wxDateTime
& SetHour(short unsigned int);
356 Sets the millisecond without changing other date components.
358 wxDateTime
& SetMillisecond(short unsigned int);
361 Sets the minute without changing other date components.
363 wxDateTime
& SetMinute(short unsigned int);
366 Sets the month without changing other date components.
368 wxDateTime
& SetMonth(Month month
);
371 Sets the second without changing other date components.
373 wxDateTime
& SetSecond(short unsigned int);
376 Sets the date and time of to the current values. Same as assigning the
377 result of Now() to this object.
379 wxDateTime
& SetToCurrent();
382 Sets the year without changing other date components.
384 wxDateTime
& SetYear(int year
);
389 wxDateTime
& operator=(time_t timet
);
393 wxDateTime
& operator=(const struct tm
& tm
);
402 Here are the trivial accessors. Other functions, which might have to
403 perform some more complicated calculations to find the answer are under
404 the "Date Arithmetics" section.
409 Returns the date and time in DOS format.
411 long unsigned int GetAsDOS() const;
414 Returns the century of this date.
416 int GetCentury(const TimeZone
& tz
= Local
) const;
419 Returns the day in the given timezone (local one by default).
421 short unsigned int GetDay(const TimeZone
& tz
= Local
) const;
424 Returns the day of the year (in 1...366 range) in the given timezone
425 (local one by default).
427 short unsigned int GetDayOfYear(const TimeZone
& tz
= Local
) const;
430 Returns the milliseconds in the given timezone (local one by default).
432 short unsigned int GetMillisecond(const TimeZone
& tz
= Local
) const;
435 Returns the minute in the given timezone (local one by default).
437 short unsigned int GetMinute(const TimeZone
& tz
= Local
) const;
440 Returns the month in the given timezone (local one by default).
442 Month
GetMonth(const TimeZone
& tz
= Local
) const;
445 Returns the seconds in the given timezone (local one by default).
447 short unsigned int GetSecond(const TimeZone
& tz
= Local
) const;
450 Returns the number of seconds since Jan 1, 1970. An assert failure will occur
451 if the date is not in the range covered by @c time_t type.
453 time_t GetTicks() const;
456 Returns the hour in the given timezone (local one by default).
458 short unsigned int GetHour(const TimeZone
& tz
= Local
) const;
461 Returns the copy of this object to which
462 SetToWeekDay() was applied.
464 wxDateTime
GetWeekDay(WeekDay weekday
, int n
= 1,
465 Month month
= Inv_Month
,
466 int year
= Inv_Year
) const;
469 Returns the ordinal number of the week in the month (in 1...5 range).
470 As GetWeekOfYear(), this function supports
471 both conventions for the week start. See the description of these
472 @ref overview_wxdatetime "week start" conventions.
474 wxDateTime_t
GetWeekOfMonth(WeekFlags flags
= Monday_First
,
475 const TimeZone
& tz
= Local
) const;
478 Returns the number of the week of the year this date is in. The first week of
479 the year is, according to international standards, the one containing Jan 4 or,
480 equivalently, the first week which has Thursday in this year. Both of these
481 definitions are the same as saying that the first week of the year must contain
482 more than half of its days in this year. Accordingly, the week number will
483 always be in 1...53 range (52 for non-leap years).
484 The function depends on the @ref overview_wxdatetime "week start" convention
485 specified by the @a flags argument but its results for
486 @c Sunday_First are not well-defined as the ISO definition quoted above
487 applies to the weeks starting on Monday only.
489 wxDateTime_t
GetWeekOfYear(WeekFlags flags
= Monday_First
,
490 const TimeZone
& tz
= Local
) const;
493 Returns the year in the given timezone (local one by default).
495 int GetYear(const TimeZone
& tz
= Local
) const;
498 Returns the copy of this object to which
499 SetToYearDay() was applied.
501 wxDateTime
GetYearDay(short unsigned int) const;
504 Returns @true if the given date is later than the date of adoption of the
505 Gregorian calendar in the given country (and hence the Gregorian calendar
506 calculations make sense for it).
508 bool IsGregorianDate(GregorianAdoption country
= Gr_Standard
) const;
511 Returns @true if the object represents a valid time moment.
513 bool IsValid() const;
516 Returns @true is this day is not a holiday in the given country.
518 bool IsWorkDay(Country country
= Country_Default
) const;
525 @name Date Comparison
527 There are several functions to allow date comparison. To supplement
528 them, a few global operators, etc taking wxDateTime are defined.
533 Returns @true if this date precedes the given one.
535 bool IsEarlierThan(const wxDateTime
& datetime
) const;
538 Returns @true if the two dates are strictly identical.
540 bool IsEqualTo(const wxDateTime
& datetime
) const;
543 Returns @true if the date is equal to another one up to the given time
544 interval, i.e. if the absolute difference between the two dates is less than
547 bool IsEqualUpTo(const wxDateTime
& dt
, const wxTimeSpan
& ts
) const;
550 Returns @true if this date is later than the given one.
552 bool IsLaterThan(const wxDateTime
& datetime
) const;
555 Returns @true if the date is the same without comparing the time parts.
557 bool IsSameDate(const wxDateTime
& dt
) const;
560 Returns @true if the time is the same (although dates may differ).
562 bool IsSameTime(const wxDateTime
& dt
) const;
565 Returns @true if this date lies strictly between the two others,
569 bool IsStrictlyBetween(const wxDateTime
& t1
,
570 const wxDateTime
& t2
) const;
573 Returns @true if IsStrictlyBetween()
574 is @true or if the date is equal to one of the limit values.
576 @see IsStrictlyBetween()
578 bool IsBetween(const wxDateTime
& t1
, const wxDateTime
& t2
) const;
585 @name Date Arithmetics
587 These functions carry out
588 @ref overview_datetime_arithmetics "arithmetics" on the wxDateTime
589 objects. As explained in the overview, either wxTimeSpan or wxDateSpan
590 may be added to wxDateTime, hence all functions are overloaded to
591 accept both arguments.
593 Also, both Add() and Subtract() have both const and non-const version.
594 The first one returns a new object which represents the sum/difference
595 of the original one with the argument while the second form modifies
596 the object to which it is applied. The operators "-=" and "+=" are
597 defined to be equivalent to the second forms of these functions.
603 oparator+=(wxTimeSpan)
604 oparator-=(wxTimeSpan)
605 oparator-=(wxDateSpan)
611 Adds the given date span to this object.
613 wxDateTime
Add(const wxDateSpan
& diff
);
616 Adds the given date span to this object.
618 const wxDateTime
& Add(const wxDateSpan
& diff
);
621 Adds the given date span to this object.
623 wxDateTime
operator+=(const wxDateSpan
& diff
);
626 Subtracts another date from this one and returns the difference between them
629 wxTimeSpan
Subtract(const wxDateTime
& dt
) const;
636 @name Date Formatting and Parsing
638 See @ref datetime_formatting
643 This function does the same as the standard ANSI C @c strftime(3) function.
644 Please see its description for the meaning of @a format parameter.
645 It also accepts a few wxWidgets-specific extensions: you can optionally specify
646 the width of the field to follow using @c printf(3)-like syntax and the
647 format specification @c %l can be used to get the number of milliseconds.
651 wxString
Format(const wxChar
* format
= wxDefaultDateTimeFormat
,
652 const TimeZone
& tz
= Local
) const;
655 Identical to calling Format() with @c "%x"
656 argument (which means 'preferred date representation for the current locale').
658 wxString
FormatDate() const;
661 Returns the combined date-time representation in the ISO 8601 format
662 (YYYY-MM-DDTHH:MM:SS). The @a sep parameter default value produces the
663 result exactly corresponding to the ISO standard, but it can also be useful to
664 use a space as seprator if a more human-readable combined date-time
665 representation is needed.
667 @see FormatISODate(), FormatISOTime(),
670 wxString
FormatISOCombined(char sep
= 'T') const;
673 This function returns the date representation in the ISO 8601 format
676 wxString
FormatISODate() const;
679 This function returns the time representation in the ISO 8601 format
682 wxString
FormatISOTime() const;
685 Identical to calling Format() with @c "%X"
686 argument (which means 'preferred time representation for the current locale').
688 wxString
FormatTime() const;
691 This function is like ParseDateTime(), but it
692 only allows the date to be specified. It is thus less flexible then
693 ParseDateTime(), but also has less chances to
694 misinterpret the user input.
695 Returns @NULL if the conversion failed, otherwise return the pointer to
696 the character which stopped the scan.
698 const char* ParseDate(const wxString
& date
,
699 wxString::const_iterator
* end
= NULL
);
703 const char* ParseDate(const char* date
);
707 const wchar_t* ParseDate(const wchar_t* date
);
710 Parses the string @a datetime containing the date and time in free format.
711 This function tries as hard as it can to interpret the given string as date
712 and time. Unlike wxDateTime::ParseRfc822Date, it
713 will accept anything that may be accepted and will only reject strings which
714 can not be parsed in any way at all.
715 Returns @NULL if the conversion failed, otherwise return the pointer to
716 the character which stopped the scan.
718 const char* ParseDateTime(const wxString
& datetime
,
719 wxString::const_iterator
* end
= NULL
);
723 const char* ParseDateTime(const char* datetime
);
727 const wchar_t* ParseDateTime(const wchar_t* datetime
);
730 This function parses the string @a date according to the given
731 @e format. The system @c strptime(3) function is used whenever available,
732 but even if it is not, this function is still implemented, although support
733 for locale-dependent format specifiers such as @c "%c", @c "%x" or @c "%X" may
734 not be perfect and GNU extensions such as @c "%z" and @c "%Z" are
735 not implemented. This function does handle the month and weekday
736 names in the current locale on all platforms, however.
737 Please see the description of the ANSI C function @c strftime(3) for the syntax
738 of the format string.
739 The @a dateDef parameter is used to fill in the fields which could not be
740 determined from the format string. For example, if the format is @c "%d" (the
741 ay of the month), the month and the year are taken from @e dateDef. If
742 it is not specified, Today() is used as the
744 Returns @NULL if the conversion failed, otherwise return the pointer to
745 the character which stopped the scan.
747 const char* ParseFormat(const wxString
& date
,
748 const wxString
& format
= wxDefaultDateTimeFormat
,
749 const wxDateTime
& dateDef
= wxDefaultDateTime
,
750 wxString::const_iterator
* end
= NULL
);
754 const char* ParseFormat(const char* date
,
755 const wxString
& format
= wxDefaultDateTimeFormat
,
756 const wxDateTime
& dateDef
= wxDefaultDateTime
);
760 const wchar_t* ParseFormat(const wchar_t* date
,
761 const wxString
& format
= wxDefaultDateTimeFormat
,
762 const wxDateTime
& dateDef
= wxDefaultDateTime
);
765 This function parses the string containing the date and time in ISO 8601
766 combined format (YYYY-MM-DDTHH:MM:SS). The separator between the date and time
767 parts must be equal to @a sep for the function to succeed.
768 Returns @true if the entire string was parsed successfully, @false
771 bool ParseISOCombined(const wxString
& date
, char sep
= 'T');
774 This function parses the date in ISO 8601 format (YYYY-MM-DD).
775 Returns @true if the entire string was parsed successfully, @false
778 bool ParseISODate(const wxString
& date
);
781 This function parses the time in ISO 8601 format (HH:MM:SS).
782 Returns @true if the entire string was parsed successfully, @false
785 bool ParseISOTime(const wxString
& date
);
788 Parses the string @a date looking for a date formatted according to the RFC
789 822 in it. The exact description of this format may, of course, be found in
790 the RFC (section 5), but, briefly, this is the format used in the headers of
791 Internet email messages and one of the most common strings expressing date in
792 this format may be something like @c "Sat, 18 Dec 1999 00:48:30 +0100".
793 Returns @NULL if the conversion failed, otherwise return the pointer to
794 the character immediately following the part of the string which could be
795 parsed. If the entire string contains only the date in RFC 822 format,
796 the returned pointer will be pointing to a @c NUL character.
797 This function is intentionally strict, it will return an error for any string
798 which is not RFC 822 compliant. If you need to parse date formatted in more
799 free ways, you should use ParseDateTime() or
802 const char* ParseRfc822Date(const wxString
& date
,
803 wxString::const_iterator
* end
= NULL
);
805 This function parses the string @a date according to the given..
807 const char* ParseRfc822Date(const char* date
);
809 This function parses the string @a date according to the given..
811 const wchar_t* ParseRfc822Date(const wchar_t* date
);
814 This functions is like ParseDateTime(), but
815 only allows the time to be specified in the input string.
816 Returns @NULL if the conversion failed, otherwise return the pointer to
817 the character which stopped the scan.
819 const char* ParseTime(const wxString
& time
,
820 wxString::const_iterator
* end
= NULL
);
824 const char* ParseTime(const char* time
);
828 const wchar_t* ParseTime(const wchar_t* time
);
835 @name Calendar Calculations
837 The functions in this section perform the basic calendar calculations,
838 mostly related to the week days. They allow to find the given week day
839 in the week with given number (either in the month or in the year) and
842 None of the functions in this section modify the time part of the
843 wxDateTime, they only work with the date part of it.
853 Returns the copy of this object to which
854 SetToLastMonthDay() was applied.
856 wxDateTime
GetLastMonthDay(Month month
= Inv_Month
,
857 int year
= Inv_Year
) const;
860 Returns the copy of this object to which SetToLastWeekDay() was
863 wxDateTime
GetLastWeekDay(WeekDay weekday
,
864 Month month
= Inv_Month
,
865 int year
= Inv_Year
);
868 Returns the copy of this object to which SetToNextWeekDay() was
871 wxDateTime
GetNextWeekDay(WeekDay weekday
) const;
874 Returns the copy of this object to which SetToPrevWeekDay() was
877 wxDateTime
GetPrevWeekDay(WeekDay weekday
) const;
880 Returns the copy of this object to which SetToWeekDayInSameWeek() was
883 wxDateTime
GetWeekDayInSameWeek(WeekDay weekday
,
884 WeekFlags flags
= Monday_First
) const;
887 Sets the date to the last day in the specified month (the current one
890 @returns The reference to the modified object itself.
892 wxDateTime
SetToLastMonthDay(Month month
= Inv_Month
,
893 int year
= Inv_Year
);
896 The effect of calling this function is the same as of calling
897 @c SetToWeekDay(-1, weekday, month, year). The date will be set to the last
898 @a weekday in the given month and year (the current ones by default).
899 Always returns @true.
901 bool SetToLastWeekDay(WeekDay weekday
, Month month
= Inv_Month
,
902 int year
= Inv_Year
);
905 Sets the date so that it will be the first @a weekday following the current
908 @returns The reference to the modified object itself.
910 wxDateTime
& SetToNextWeekDay(WeekDay weekday
);
913 Sets the date so that it will be the last @a weekday before the current
916 @returns The reference to the modified object itself.
918 wxDateTime
& SetToPrevWeekDay(WeekDay weekday
);
921 Sets the date to the @e n-th @a weekday in the given month of the given
922 year (the current month and year are used by default). The parameter @e n
923 may be either positive (counting from the beginning of the month) or negative
924 (counting from the end of it).
926 For example, SetToWeekDay(2, wxDateTime::Wed) will set the date to the
927 second Wednesday in the current month and
928 SetToWeekDay(-1, wxDateTime::Sun) will set the date to the last Sunday
929 in the current month.
931 @returns @true if the date was modified successfully, @false otherwise
932 meaning that the specified date doesn't exist.
934 bool SetToWeekDay(WeekDay weekday
, int n
= 1,
935 Month month
= Inv_Month
, int year
= Inv_Year
);
938 Adjusts the date so that it will still lie in the same week as before,
939 but its week day will be the given one.
941 @returns The reference to the modified object itself.
943 wxDateTime
SetToWeekDayInSameWeek(WeekDay weekday
,
944 WeekFlags flags
= Monday_First
);
947 Sets the date to the day number @a yday in the same year (i.e., unlike the
948 other functions, this one does not use the current year). The day number
949 should be in the range 1...366 for the leap years and 1...365 for
951 Returns the reference to the modified object itself.
953 wxDateTime
& SetToYearDay(short unsigned int);
960 @name Astronomical/Historical Functions
962 Some degree of support for the date units used in astronomy and/or
963 history is provided. You can construct a wxDateTime object from a
964 JDN and you may also get its JDN, MJD or Rata Die number from it.
967 wxDateTime(double jdn)
974 Synonym for GetJulianDayNumber().
976 double GetJDN() const;
979 Returns the @ref setjdn() JDN corresponding to this date. Beware
982 @see GetModifiedJulianDayNumber()
984 double GetJulianDayNumber() const;
987 Synonym for GetModifiedJulianDayNumber().
989 double GetMJD() const;
992 Returns the @e Modified Julian Day Number (MJD) which is, by definition,
993 equal to JDN - 2400000.5. The MJDs are simpler to work with as the integral
994 MJDs correspond to midnights of the dates in the Gregorian calendar and not th
995 noons like JDN. The MJD 0 is Nov 17, 1858.
997 double GetModifiedJulianDayNumber() const;
1000 Return the @e Rata Die number of this date.
1001 By definition, the Rata Die number is a date specified as the number of days
1002 relative to a base date of December 31 of the year 0. Thus January 1 of the
1003 year 1 is Rata Die day 1.
1005 double GetRataDie() const;
1012 @name Time Zone and DST Support
1014 Please see the @ref overview_datetime_timezones "time zone overview"
1015 for more information about time zones. Normally, these functions should
1018 See also GetBeginDST() and GetEndDST().
1023 Transform the date from the given time zone to the local one. If
1024 @a noDST is @true, no DST adjustments will be made.
1026 @returns The date in the local time zone.
1028 wxDateTime
FromTimezone(const TimeZone
& tz
, bool noDST
= false) const;
1031 Returns @true if the DST is applied for this date in the given country.
1033 int IsDST(Country country
= Country_Default
) const;
1036 Same as FromTimezone() but modifies the object in place.
1038 wxDateTime
MakeFromTimezone(const TimeZone
& tz
, bool noDST
= false);
1041 Modifies the object in place to represent the date in another time
1042 zone. If @a noDST is @true, no DST adjustments will be made.
1044 wxDateTime
MakeTimezone(const TimeZone
& tz
, bool noDST
= false);
1047 This is the same as calling MakeTimezone() with the argument @c GMT0.
1049 wxDateTime
& MakeUTC(bool noDST
= false);
1052 Transform the date to the given time zone. If @a noDST is @true, no DST
1053 adjustments will be made.
1055 @returns The date in the new time zone.
1057 wxDateTime
ToTimezone(const TimeZone
& tz
, bool noDST
= false) const;
1060 This is the same as calling ToTimezone() with the argument @c GMT0.
1062 wxDateTime
ToUTC(bool noDST
= false) const;
1071 Converts the year in absolute notation (i.e. a number which can be
1072 negative, positive or zero) to the year in BC/AD notation. For the
1073 positive years, nothing is done, but the year 0 is year 1 BC and so for
1074 other years there is a difference of 1.
1076 This function should be used like this:
1080 int y = dt.GetYear();
1081 printf("The year is %d%s", wxDateTime::ConvertYearToBC(y), y > 0 ? "AD" : "BC");
1084 static int ConvertYearToBC(int year
);
1087 Returns the translations of the strings @c AM and @c PM used for time
1088 formatting for the current locale. Either of the pointers may be @NULL
1089 if the corresponding value is not needed.
1091 static void GetAmPmStrings(wxString
* am
, wxString
* pm
);
1094 Get the beginning of DST for the given country in the given year
1095 (current one by default). This function suffers from limitations
1096 described in the @ref overview_datetime_dst "DST overview".
1100 static wxDateTime
GetBeginDST(int year
= Inv_Year
,
1101 Country country
= Country_Default
);
1104 Returns the end of DST for the given country in the given year (current
1109 static wxDateTime
GetEndDST(int year
= Inv_Year
,
1110 Country country
= Country_Default
);
1113 Get the current century, i.e. first two digits of the year, in given
1114 calendar (only Gregorian is currently supported).
1116 static int GetCentury(int year
);
1119 Returns the current default country. The default country is used for
1120 DST calculations, for example.
1124 static Country
GetCountry();
1127 Get the current month in given calendar (only Gregorian is currently
1130 static Month
GetCurrentMonth(Calendar cal
= Gregorian
);
1133 Get the current year in given calendar (only Gregorian is currently
1136 static int GetCurrentYear(Calendar cal
= Gregorian
);
1139 Gets the full (default) or abbreviated (specify @c Name_Abbr name of
1142 @see GetWeekDayName()
1144 static wxString
GetMonthName(Month month
, NameFlags flags
= Name_Full
);
1147 Returns the number of days in the given year. The only supported value
1148 for @a cal currently is @c Gregorian.
1151 This method is named "GetNumberOfDaysInYear" in wxPython.
1154 static wxDateTime_t
GetNumberOfDays(int year
, Calendar cal
= Gregorian
);
1157 Returns the number of days in the given month of the given year. The
1158 only supported value for @a cal currently is @c Gregorian.
1161 This method is named "GetNumberOfDaysInMonth" in wxPython.
1164 static wxDateTime_t
GetNumberOfDays(Month month
,
1165 int year
= Inv_Year
,
1166 Calendar cal
= Gregorian
);
1169 Returns the current time.
1171 static time_t GetTimeNow();
1174 Returns the current time broken down using the buffer whose adress is
1175 passed to the function with @a tm to store the result.
1177 static struct tm
* GetTmNow(struct tm
*tm
);
1180 Returns the current time broken down. Note that this function returns a
1181 pointer to a static buffer that's reused by calls to this function and
1182 certain C library functions (e.g. localtime). If there is any chance
1183 your code might be used in a multi-threaded application, you really
1184 should use GetTmNow(struct tm *) instead.
1186 static struct tm
* GetTmNow();
1189 Gets the full (default) or abbreviated (specify @c Name_Abbr) name of
1194 static wxString
GetWeekDayName(WeekDay weekday
,
1195 NameFlags flags
= Name_Full
);
1198 Returns @true if DST was used n the given year (the current one by
1199 default) in the given country.
1201 static bool IsDSTApplicable(int year
= Inv_Year
,
1202 Country country
= Country_Default
);
1205 Returns @true if the @a year is a leap one in the specified calendar.
1206 This functions supports Gregorian and Julian calendars.
1208 static bool IsLeapYear(int year
= Inv_Year
,
1209 Calendar cal
= Gregorian
);
1212 This function returns @true if the specified (or default) country is
1213 one of Western European ones. It is used internally by wxDateTime to
1214 determine the DST convention and date and time formatting rules.
1216 static bool IsWestEuropeanCountry(Country country
= Country_Default
);
1219 Returns the object corresponding to the current time.
1224 wxDateTime now = wxDateTime::Now();
1225 printf("Current time in Paris:\t%s\n", now.Format("%c", wxDateTime::CET).c_str());
1228 @note This function is accurate up to seconds. UNow() should be used
1229 for better precision, but it is less efficient and might not be
1230 available on all platforms.
1234 static wxDateTime
Now();
1237 Sets the country to use by default. This setting influences the DST
1238 calculations, date formatting and other things.
1240 The possible values for @a country parameter are enumerated in the
1241 @ref datetime_constants section.
1245 static void SetCountry(Country country
);
1248 Set the date to the given @a weekday in the week number @a numWeek of the
1249 given @a year . The number should be in range 1...53.
1250 Note that the returned date may be in a different year than the one passed to
1251 this function because both the week 1 and week 52 or 53 (for leap years)
1252 contain days from different years. See
1253 GetWeekOfYear() for the explanation of how the
1254 year weeks are counted.
1256 static wxDateTime
SetToWeekOfYear(int year
, wxDateTime_t numWeek
,
1257 WeekDay weekday
= Mon
);
1260 Returns the object corresponding to the midnight of the current day
1261 (i.e. the same as Now(), but the time part is set to 0).
1265 static wxDateTime
Today();
1268 Returns the object corresponding to the current time including the
1269 milliseconds if a function to get time with such precision is available
1270 on the current platform (supported under most Unices and Win32).
1274 static wxDateTime
UNow();
1279 // Uncategorized Functions:
1285 Returns the object having the same date component as this one but time of
1292 wxDateTime
GetDateOnly() const;
1295 Returns broken down representation of the date and time.
1297 Tm
GetTm(const TimeZone
& tz
= Local
) const;
1301 Global instance of an empty wxDateTime object.
1303 @todo wouldn't be better to rename it wxNullDateTime as for the rest of wx global objects
1304 which are initialized to an empty value?
1306 wxDateTime wxDefaultDateTime
;
1311 @class wxDateTimeWorkDays
1312 @wxheader{datetime.h}
1318 class wxDateTimeWorkDays
1328 @wxheader{datetime.h}
1330 This class is a "logical time span" and is useful for implementing program
1331 logic for such things as "add one month to the date" which, in general,
1332 doesn't mean to add 60*60*24*31 seconds to it, but to take the same date
1333 the next month (to understand that this is indeed different consider adding
1334 one month to Feb, 15 -- we want to get Mar, 15, of course).
1336 When adding a month to the date, all lesser components (days, hours, ...)
1337 won't be changed unless the resulting date would be invalid: for example,
1338 Jan 31 + 1 month will be Feb 28, not (non-existing) Feb 31.
1340 Because of this feature, adding and subtracting back again the same
1341 wxDateSpan will @b not, in general give back the original date: Feb 28 - 1
1342 month will be Jan 28, not Jan 31!
1344 wxDateSpan objects can be either positive or negative. They may be
1345 multiplied by scalars which multiply all deltas by the scalar: i.e.
1346 2*(1 month and 1 day) is 2 months and 2 days. They can
1347 be added together and with wxDateTime or
1348 wxTimeSpan, but the type of result is different for each
1351 Beware about weeks: if you specify both weeks and days, the total number of
1352 days added will be 7*weeks + days! See also GetTotalDays()
1355 Equality operators are defined for wxDateSpans. Two datespans are equal if
1356 and only if they both give the same target date when added to @b every
1357 source date. Thus wxDateSpan::Months(1) is not equal to wxDateSpan::Days(30),
1358 because they don't give the same date when added to 1 Feb. But
1359 wxDateSpan::Days(14) is equal to wxDateSpan::Weeks(2)
1361 Finally, notice that for adding hours, minutes and so on you don't need this
1362 class at all: wxTimeSpan will do the job because there
1363 are no subtleties associated with those (we don't support leap seconds).
1368 @see @ref overview_datetime, wxDateTime
1374 Constructs the date span object for the given number of years, months, weeks
1375 and days. Note that the weeks and days add together if both are given.
1377 wxDateSpan(int years
= 0, int months
= 0, int weeks
= 0,
1382 Returns the sum of two date spans. The first version returns a new object, the
1383 second and third ones modify this object in place.
1385 wxDateSpan
Add(const wxDateSpan
& other
);
1386 const wxDateSpan
& Add(const wxDateSpan
& other
);
1387 wxDateSpan
operator+=(const wxDateSpan
& other
);
1391 Returns a date span object corresponding to one day.
1395 static wxDateSpan
Day();
1398 Returns a date span object corresponding to the given number of days.
1402 static wxDateSpan
Days(int days
);
1405 Returns the number of days (only, that it not counting the weeks component!)
1410 int GetDays() const;
1413 Returns the number of the months (not counting the years) in this date span.
1415 int GetMonths() const;
1418 Returns the combined number of days in this date span, counting both weeks and
1419 days. It still doesn't take neither months nor years into the account.
1421 @see GetWeeks(), GetDays()
1423 int GetTotalDays() const;
1426 Returns the number of weeks in this date span.
1430 int GetWeeks() const;
1433 Returns the number of years in this date span.
1435 int GetYears() const;
1438 Returns a date span object corresponding to one month.
1442 static wxDateSpan
Month();
1445 Returns a date span object corresponding to the given number of months.
1449 static wxDateSpan
Months(int mon
);
1453 Returns the product of the date span by the specified @e factor. The
1454 product is computed by multiplying each of the components by the factor.
1455 The first version returns a new object, the second and third ones modify this
1458 wxDateSpan
Multiply(int factor
);
1459 const wxDateSpan
& Multiply(int factor
);
1460 wxDateSpan
operator*=(int factor
);
1465 Changes the sign of this date span.
1470 wxDateSpan
operator-();
1474 Returns the date span with the opposite sign.
1478 wxDateSpan
Negate() const;
1481 Sets the number of days (without modifying any other components) in this date
1484 wxDateSpan
& SetDays(int n
);
1487 Sets the number of months (without modifying any other components) in this
1490 wxDateSpan
& SetMonths(int n
);
1493 Sets the number of weeks (without modifying any other components) in this date
1496 wxDateSpan
& SetWeeks(int n
);
1499 Sets the number of years (without modifying any other components) in this date
1502 wxDateSpan
& SetYears(int n
);
1506 Returns the difference of two date spans. The first version returns a new
1507 object, the second and third ones modify this object in place.
1509 wxDateSpan
Subtract(const wxDateSpan
& other
);
1510 const wxDateSpan
& Subtract(const wxDateSpan
& other
);
1511 wxDateSpan
operator+=(const wxDateSpan
& other
);
1515 Returns a date span object corresponding to one week.
1519 static wxDateSpan
Week();
1522 Returns a date span object corresponding to the given number of weeks.
1526 static wxDateSpan
Weeks(int weeks
);
1529 Returns a date span object corresponding to one year.
1533 static wxDateSpan
Year();
1536 Returns a date span object corresponding to the given number of years.
1540 static wxDateSpan
Years(int years
);
1543 Returns @true if this date span is different from the other one.
1545 bool operator!=(const wxDateSpan
&) const;
1548 Returns @true if this date span is equal to the other one. Two date spans
1549 are considered equal if and only if they have the same number of years and
1550 months and the same total number of days (counting both days and weeks).
1552 bool operator==(const wxDateSpan
&) const;
1559 @wxheader{datetime.h}
1561 wxTimeSpan class represents a time interval.
1566 @see @ref overview_datetime, wxDateTime
1573 Constructs timespan from separate values for each component, with the date
1574 set to 0. Hours are not restricted to 0..24 range, neither are
1575 minutes, seconds or milliseconds.
1578 wxTimeSpan(long hours
, long min
, long sec
, long msec
);
1582 Returns the absolute value of the timespan: does not modify the
1585 wxTimeSpan
Abs() const;
1604 Returns the sum of two timespans.
1606 wxTimeSpan
Add(const wxTimeSpan
& diff
);
1607 const wxTimeSpan
& Add(const wxTimeSpan
& diff
);
1608 wxTimeSpan
operator+=(const wxTimeSpan
& diff
);
1612 @ref ctor() wxTimeSpan
1617 Returns the timespan for one day.
1619 static wxTimespan
Day();
1622 Returns the timespan for the given number of days.
1624 static wxTimespan
Days(long days
);
1627 Returns the string containing the formatted representation of the time span.
1628 The following format specifiers are allowed after %:
1636 number of @b Minutes
1640 number of @b Seconds
1644 number of mi@b lliseconds
1656 the percent character
1658 Note that, for example, the number of hours in the description above is not
1659 well defined: it can be either the total number of hours (for example, for a
1660 time span of 50 hours this would be 50) or just the hour part of the time
1661 span, which would be 2 in this case as 50 hours is equal to 2 days and
1663 wxTimeSpan resolves this ambiguity in the following way: if there had been,
1664 indeed, the @c %D format specified preceding the @c %H, then it is
1665 interpreted as 2. Otherwise, it is 50.
1666 The same applies to all other format specifiers: if they follow a specifier of
1667 larger unit, only the rest part is taken, otherwise the full value is used.
1669 wxString
Format(const wxString
& = wxDefaultTimeSpanFormat
) const;
1677 Returns the difference in number of days.
1679 int GetDays() const;
1682 Returns the difference in number of hours.
1684 int GetHours() const;
1687 Returns the difference in number of milliseconds.
1689 wxLongLong
GetMilliseconds() const;
1692 Returns the difference in number of minutes.
1694 int GetMinutes() const;
1697 Returns the difference in number of seconds.
1699 wxLongLong
GetSeconds() const;
1702 Returns the internal representation of timespan.
1704 wxLongLong
GetValue() const;
1707 Returns the difference in number of weeks.
1709 int GetWeeks() const;
1712 Returns the timespan for one hour.
1714 static wxTimespan
Hour();
1717 Returns the timespan for the given number of hours.
1719 static wxTimespan
Hours(long hours
);
1722 Returns @true if two timespans are equal.
1724 bool IsEqualTo(const wxTimeSpan
& ts
) const;
1727 Compares two timespans: works with the absolute values, i.e. -2
1728 hours is longer than 1 hour. Also, it will return @false if
1729 the timespans are equal in absolute value.
1731 bool IsLongerThan(const wxTimeSpan
& ts
) const;
1734 Returns @true if the timespan is negative.
1736 bool IsNegative() const;
1739 Returns @true if the timespan is empty.
1741 bool IsNull() const;
1744 Returns @true if the timespan is positive.
1746 bool IsPositive() const;
1749 Compares two timespans: works with the absolute values, i.e. 1
1750 hour is shorter than -2 hours. Also, it will return @false if
1751 the timespans are equal in absolute value.
1753 bool IsShorterThan(const wxTimeSpan
& ts
) const;
1756 Returns the timespan for one millisecond.
1758 static wxTimespan
Millisecond();
1761 Returns the timespan for the given number of milliseconds.
1763 static wxTimespan
Milliseconds(long ms
);
1766 Returns the timespan for one minute.
1768 static wxTimespan
Minute();
1771 Returns the timespan for the given number of minutes.
1773 static wxTimespan
Minutes(long min
);
1777 Multiplies timespan by a scalar.
1779 wxTimeSpan
Multiply(int n
);
1780 const wxTimeSpan
& Multiply(int n
);
1781 wxTimeSpan
operator*=(int n
);
1786 Negate the value of the timespan.
1789 wxTimeSpan
operator-();
1793 Returns timespan with inverted sign.
1795 wxTimeSpan
Negate() const;
1813 Returns the timespan for one second.
1815 static wxTimespan
Second();
1818 Returns the timespan for the given number of seconds.
1820 static wxTimespan
Seconds(long sec
);
1851 Returns the difference of two timespans.
1853 wxTimeSpan
Subtract(const wxTimeSpan
& diff
);
1854 const wxTimeSpan
& Subtract(const wxTimeSpan
& diff
);
1855 wxTimeSpan
operator-=(const wxTimeSpan
& diff
);
1874 Returns the timespan for one week.
1876 static wxTimespan
Week();
1879 Returns the timespan for the given number of weeks.
1881 static wxTimespan
Weeks(long weeks
);
1887 @class wxDateTimeHolidayAuthority
1888 @wxheader{datetime.h}
1894 class wxDateTimeHolidayAuthority