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.
21 @see @ref overview_wxdatetimeoverview "Date classes overview", wxTimeSpan,
22 wxDateSpan, wxCalendarCtrl
28 Same as @ref setdate() Set
30 wxDateTime(wxDateTime_t day
, Month month
= Inv_Month
,
31 int year
= Inv_Year
, wxDateTime_t hour
= 0,
32 wxDateTime_t minute
= 0,
33 wxDateTime_t second
= 0,
34 wxDateTime_t millisec
= 0);
37 Here are the trivial accessors. Other functions, which might have to perform
38 some more complicated calculations to find the answer are under the
39 @ref overview_datetimecalculations "Calendar calculations" section.
80 Adds the given date span to this object.
82 wxDateTime
Add(const wxDateSpan
& diff
);
83 const wxDateTime
& Add(const wxDateSpan
& diff
);
84 wxDateTime
operator+=(const wxDateSpan
& diff
);
88 Some degree of support for the date units used in astronomy and/or history is
89 provided. You can construct a wxDateTime object from a
90 @ref setjdn() JDN and you may also get its JDN,
91 @ref getmodifiedjuliandaynumber() MJD or
92 @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.
113 All (non-const) functions in this section don't modify the time part of the
114 wxDateTime -- they only work with the date part of it.
115 SetToWeekDayInSameWeek()
117 GetWeekDayInSameWeek()
129 @ref wxDateTime::getweekday2 GetWeekDay
148 Constructors and various @c Set() methods are collected here. If you
149 construct a date object from separate values for day, month and year, you
150 should use IsValid() method to check that the
151 values were correct as constructors can not return an error code.
152 @ref wxdatetimedef() wxDateTime
154 @ref wxdatetimetimet() wxDateTime(time_t)
156 @ref wxdatetimetm() "wxDateTime(struct tm)"
158 @ref wxdatetimejdn() "wxDateTime(double jdn)"
160 @ref wxdatetimetime() "wxDateTime(h, m, s, ms)"
162 @ref wxdatetimedate() "wxDateTime(day, mon, year, h, m, s, ms)"
166 @ref settimet() Set(time_t)
168 @ref settm() "Set(struct tm)"
170 @ref setjdn() "Set(double jdn)"
172 @ref settime() "Set(h, m, s, ms)"
174 @ref setdate() "Set(day, mon, year, h, m, s, ms)"
176 @ref setfromdos() "SetFromDOS(unsigned long ddt)"
184 @ref setdate() SetDay
194 @ref operatoreqtimet() operator=(time_t)
196 @ref operatoreqtm() "operator=(struct tm)"
201 Converts the year in absolute notation (i.e. a number which can be negative,
202 positive or zero) to the year in BC/AD notation. For the positive years,
203 nothing is done, but the year 0 is year 1 BC and so for other years there is a
205 This function should be used like this:
207 static int ConvertYearToBC(int year
);
210 These functions carry out arithmetics() on the wxDateTime
211 objects. As explained in the overview, either wxTimeSpan or wxDateSpan may be
212 added to wxDateTime, hence all functions are overloaded to accept both
214 Also, both @c Add() and @c Subtract() have both const and non-const
215 version. The first one returns a new object which represents the
216 sum/difference of the original one with the argument while the second form
217 modifies the object to which it is applied. The operators -= and += are
218 defined to be equivalent to the second forms of these functions.
219 @ref addts() Add(wxTimeSpan)
221 @ref addds() Add(wxDateSpan)
223 @ref subtractts() Subtract(wxTimeSpan)
225 @ref subtractds() Subtract(wxDateSpan)
227 @ref subtractdt() Subtract(wxDateTime)
229 @ref addts() oparator+=(wxTimeSpan)
231 @ref addds() oparator+=(wxDateSpan)
233 @ref subtractts() oparator-=(wxTimeSpan)
235 @ref subtractds() oparator-=(wxDateSpan)
240 There are several function to allow date comparison. To supplement them, a few
241 global operators , etc taking wxDateTime are defined.
261 This function does the same as the standard ANSI C @c strftime(3) function.
262 Please see its description for the meaning of @a format parameter.
263 It also accepts a few wxWidgets-specific extensions: you can optionally specify
264 the width of the field to follow using @c printf(3)-like syntax and the
265 format specification @c %l can be used to get the number of milliseconds.
269 wxString
Format(const wxChar
* format
= wxDefaultDateTimeFormat
,
270 const TimeZone
& tz
= Local
) const;
273 Identical to calling Format() with @c "%x"
274 argument (which means 'preferred date representation for the current locale').
276 wxString
FormatDate() const;
279 Returns the combined date-time representation in the ISO 8601 format
280 (YYYY-MM-DDTHH:MM:SS). The @a sep parameter default value produces the
281 result exactly corresponding to the ISO standard, but it can also be useful to
282 use a space as seprator if a more human-readable combined date-time
283 representation is needed.
285 @see FormatISODate(), FormatISOTime(),
288 wxString
FormatISOCombined(char sep
= 'T') const;
291 This function returns the date representation in the ISO 8601 format
294 wxString
FormatISODate() const;
297 This function returns the time representation in the ISO 8601 format
300 wxString
FormatISOTime() const;
303 Identical to calling Format() with @c "%X"
304 argument (which means 'preferred time representation for the current locale').
306 wxString
FormatTime() const;
309 Transform the date from the given time zone to the local one. If @a noDST is
310 @true, no DST adjustments will be made.
311 Returns the date in the local time zone.
313 wxDateTime
FromTimezone(const TimeZone
& tz
,
314 bool noDST
= false) const;
317 Returns the translations of the strings @c AM and @c PM used for time
318 formatting for the current locale. Either of the pointers may be @NULL if
319 the corresponding value is not needed.
321 static void GetAmPmStrings(wxString
* am
, wxString
* pm
);
324 Returns the date and time in
328 long unsigned int GetAsDOS() const;
331 Get the beginning of DST for the given country in the given year (current one
332 by default). This function suffers from limitations described in
333 @ref overview_tdatedst "DST overview".
337 static wxDateTime
GetBeginDST(int year
= Inv_Year
,
338 Country country
= Country_Default
);
341 Returns the century of this date.
343 int GetCentury(const TimeZone
& tz
= Local
) const;
346 Returns the current default country. The default country is used for DST
347 calculations, for example.
351 static Country
GetCountry();
354 Get the current month in given calendar (only Gregorian is currently supported).
356 static Month
GetCurrentMonth(Calendar cal
= Gregorian
);
359 Get the current year in given calendar (only Gregorian is currently supported).
361 static int GetCurrentYear(Calendar cal
= Gregorian
);
364 Returns the object having the same date component as this one but time of
371 wxDateTime
GetDateOnly() const;
374 Returns the day in the given timezone (local one by default).
376 short unsigned int GetDay(const TimeZone
& tz
= Local
) const;
379 Returns the day of the year (in 1...366 range) in the given timezone
380 (local one by default).
382 short unsigned int GetDayOfYear(const TimeZone
& tz
= Local
) const;
385 Returns the end of DST for the given country in the given year (current one by
390 static wxDateTime
GetEndDST(int year
= Inv_Year
,
391 Country country
= Country_Default
);
394 Returns the hour in the given timezone (local one by default).
396 short unsigned int GetHour(const TimeZone
& tz
= Local
) const;
399 Synonym for GetJulianDayNumber().
401 double GetJDN() const;
404 Returns the @ref setjdn() JDN corresponding to this date. Beware
407 @see GetModifiedJulianDayNumber()
409 double GetJulianDayNumber() const;
412 Returns the copy of this object to which
413 SetToLastMonthDay() was applied.
415 wxDateTime
GetLastMonthDay(Month month
= Inv_Month
,
416 int year
= Inv_Year
) const;
419 Returns the copy of this object to which
420 SetToLastWeekDay() was applied.
422 wxDateTime
GetLastWeekDay(WeekDay weekday
,
423 Month month
= Inv_Month
,
424 int year
= Inv_Year
);
427 Synonym for GetModifiedJulianDayNumber().
429 double GetMJD() const;
432 Returns the milliseconds in the given timezone (local one by default).
434 short unsigned int GetMillisecond(const TimeZone
& tz
= Local
) const;
437 Returns the minute in the given timezone (local one by default).
439 short unsigned int GetMinute(const TimeZone
& tz
= Local
) const;
442 Returns the @e Modified Julian Day Number (MJD) which is, by definition,
443 equal to JDN - 2400000.5. The MJDs are simpler to work with as the integral
444 MJDs correspond to midnights of the dates in the Gregorian calendar and not th
445 noons like JDN. The MJD 0 is Nov 17, 1858.
447 double GetModifiedJulianDayNumber() const;
450 Returns the month in the given timezone (local one by default).
452 Month
GetMonth(const TimeZone
& tz
= Local
) const;
455 Gets the full (default) or abbreviated (specify @c Name_Abbr name of the
458 @see GetWeekDayName()
460 static wxString
GetMonthName(Month month
,
461 NameFlags flags
= Name_Full
);
464 Returns the copy of this object to which
465 SetToNextWeekDay() was applied.
467 wxDateTime
GetNextWeekDay(WeekDay weekday
) const;
471 Returns the number of days in the given year or in the given month of the
473 The only supported value for @a cal parameter is currently @c Gregorian.
475 static wxDateTime_t
GetNumberOfDays(int year
,
476 Calendar cal
= Gregorian
);
477 static wxDateTime_t
GetNumberOfDays(Month month
,
479 Calendar cal
= Gregorian
);
483 Returns the copy of this object to which
484 SetToPrevWeekDay() was applied.
486 wxDateTime
GetPrevWeekDay(WeekDay weekday
) const;
489 Return the @e Rata Die number of this date.
490 By definition, the Rata Die number is a date specified as the number of days
491 relative to a base date of December 31 of the year 0. Thus January 1 of the
492 year 1 is Rata Die day 1.
494 double GetRataDie() const;
497 Returns the seconds in the given timezone (local one by default).
499 short unsigned int GetSecond(const TimeZone
& tz
= Local
) const;
502 Returns the number of seconds since Jan 1, 1970. An assert failure will occur
503 if the date is not in the range covered by @c time_t type.
505 time_t GetTicks() const;
508 Returns the current time.
510 static time_t GetTimeNow();
513 Returns broken down representation of the date and time.
515 Tm
GetTm(const TimeZone
& tz
= Local
) const;
518 Returns the current time broken down. Note that this function returns a
519 pointer to a static buffer that's reused by calls to this function and
520 certain C library functions (e.g. localtime). If there is any chance your
521 code might be used in a multi-threaded application, you really should use
522 the flavour of function GetTmNow()
525 static struct tm
* GetTmNow();
528 Returns the copy of this object to which
529 SetToWeekDay() was applied.
531 wxDateTime
GetWeekDay(WeekDay weekday
, int n
= 1,
532 Month month
= Inv_Month
,
533 int year
= Inv_Year
) const;
536 Returns the copy of this object to which
537 SetToWeekDayInSameWeek() was
540 wxDateTime
GetWeekDayInSameWeek(WeekDay weekday
,
541 WeekFlags flags
= Monday_First
) const;
544 Gets the full (default) or abbreviated (specify @c Name_Abbr name of the
549 static wxString
GetWeekDayName(WeekDay weekday
,
550 NameFlags flags
= Name_Full
);
553 Returns the ordinal number of the week in the month (in 1...5 range).
554 As GetWeekOfYear(), this function supports
555 both conventions for the week start. See the description of these
556 @ref overview_wxdatetime "week start" conventions.
558 wxDateTime_t
GetWeekOfMonth(WeekFlags flags
= Monday_First
,
559 const TimeZone
& tz
= Local
) const;
562 Returns the number of the week of the year this date is in. The first week of
563 the year is, according to international standards, the one containing Jan 4 or,
564 equivalently, the first week which has Thursday in this year. Both of these
565 definitions are the same as saying that the first week of the year must contain
566 more than half of its days in this year. Accordingly, the week number will
567 always be in 1...53 range (52 for non-leap years).
568 The function depends on the @ref overview_wxdatetime "week start" convention
569 specified by the @a flags argument but its results for
570 @c Sunday_First are not well-defined as the ISO definition quoted above
571 applies to the weeks starting on Monday only.
573 wxDateTime_t
GetWeekOfYear(WeekFlags flags
= Monday_First
,
574 const TimeZone
& tz
= Local
) const;
577 Returns the year in the given timezone (local one by default).
579 int GetYear(const TimeZone
& tz
= Local
) const;
582 Returns the copy of this object to which
583 SetToYearDay() was applied.
585 wxDateTime
GetYearDay(short unsigned int) const;
588 Returns @true if IsStrictlyBetween()
589 is @true or if the date is equal to one of the limit values.
591 @see IsStrictlyBetween()
593 bool IsBetween(const wxDateTime
& t1
, const wxDateTime
& t2
) const;
596 Returns @true if the DST is applied for this date in the given country.
598 int IsDST(Country country
= Country_Default
) const;
601 Returns @true if DST was used n the given year (the current one by
602 default) in the given country.
604 static bool IsDSTApplicable(int year
= Inv_Year
,
605 Country country
= Country_Default
);
608 Returns @true if this date precedes the given one.
610 bool IsEarlierThan(const wxDateTime
& datetime
) const;
613 Returns @true if the two dates are strictly identical.
615 bool IsEqualTo(const wxDateTime
& datetime
) const;
618 Returns @true if the date is equal to another one up to the given time
619 interval, i.e. if the absolute difference between the two dates is less than
622 bool IsEqualUpTo(const wxDateTime
& dt
, const wxTimeSpan
& ts
) const;
625 Returns @true if the given date is later than the date of adoption of the
626 Gregorian calendar in the given country (and hence the Gregorian calendar
627 calculations make sense for it).
629 bool IsGregorianDate(GregorianAdoption country
= Gr_Standard
) const;
632 Returns @true if this date is later than the given one.
634 bool IsLaterThan(const wxDateTime
& datetime
) const;
637 Returns @true if the @a year is a leap one in the specified calendar.
638 This functions supports Gregorian and Julian calendars.
640 static bool IsLeapYear(int year
= Inv_Year
,
641 Calendar cal
= Gregorian
);
644 Returns @true if the date is the same without comparing the time parts.
646 bool IsSameDate(const wxDateTime
& dt
) const;
649 Returns @true if the time is the same (although dates may differ).
651 bool IsSameTime(const wxDateTime
& dt
) const;
654 Returns @true if this date lies strictly between the two others,
658 bool IsStrictlyBetween(const wxDateTime
& t1
,
659 const wxDateTime
& t2
) const;
662 Returns @true if the object represents a valid time moment.
664 bool IsValid() const;
667 This function returns @true if the specified (or default) country is one
668 of Western European ones. It is used internally by wxDateTime to determine the
669 DST convention and date and time formatting rules.
671 static bool IsWestEuropeanCountry(Country country
= Country_Default
);
674 Returns @true is this day is not a holiday in the given country.
676 bool IsWorkDay(Country country
= Country_Default
) const;
679 Same as FromTimezone() but modifies the object
682 wxDateTime
MakeFromTimezone(const TimeZone
& tz
,
686 Modifies the object in place to represent the date in another time zone. If
687 @a noDST is @true, no DST adjustments will be made.
689 wxDateTime
MakeTimezone(const TimeZone
& tz
,
693 This is the same as calling MakeTimezone() with
694 the argument @c GMT0.
696 wxDateTime
& MakeUTC(bool noDST
= false);
699 Returns the object corresponding to the current time.
702 Note that this function is accurate up to second:
703 UNow() should be used for better precision
704 (but it is less efficient and might not be available on all platforms).
708 static wxDateTime
Now();
712 This function is like ParseDateTime(), but it
713 only allows the date to be specified. It is thus less flexible then
714 ParseDateTime(), but also has less chances to
715 misinterpret the user input.
716 Returns @NULL if the conversion failed, otherwise return the pointer to
717 the character which stopped the scan.
719 const char* ParseDate(const wxString
& date
,
720 wxString::const_iterator
* end
= NULL
);
721 const char* ParseDate(const char* date
);
722 const wchar_t* ParseDate(const wchar_t* date
);
727 Parses the string @a datetime containing the date and time in free format.
728 This function tries as hard as it can to interpret the given string as date
729 and time. Unlike wxDateTime::ParseRfc822Date, it
730 will accept anything that may be accepted and will only reject strings which
731 can not be parsed in any way at all.
732 Returns @NULL if the conversion failed, otherwise return the pointer to
733 the character which stopped the scan.
735 const char* ParseDateTime(const wxString
& datetime
,
736 wxString::const_iterator
* end
= NULL
);
737 const char* ParseDateTime(const char* datetime
);
738 const wchar_t* ParseDateTime(const wchar_t* datetime
);
743 This function parses the string @a date according to the given
744 @e format. The system @c strptime(3) function is used whenever available,
745 but even if it is not, this function is still implemented, although support
746 for locale-dependent format specifiers such as @c "%c", @c "%x" or @c "%X" may
747 not be perfect and GNU extensions such as @c "%z" and @c "%Z" are
748 not implemented. This function does handle the month and weekday
749 names in the current locale on all platforms, however.
750 Please see the description of the ANSI C function @c strftime(3) for the syntax
751 of the format string.
752 The @a dateDef parameter is used to fill in the fields which could not be
753 determined from the format string. For example, if the format is @c "%d" (the
754 ay of the month), the month and the year are taken from @e dateDef. If
755 it is not specified, Today() is used as the
757 Returns @NULL if the conversion failed, otherwise return the pointer to
758 the character which stopped the scan.
760 const char* ParseFormat(const wxString
& date
,
761 const wxString
& format
= wxDefaultDateTimeFormat
,
762 const wxDateTime
& dateDef
= wxDefaultDateTime
,
763 wxString::const_iterator
* end
= NULL
);
764 const char* ParseFormat(const char* date
,
765 const wxString
& format
= wxDefaultDateTimeFormat
,
766 const wxDateTime
& dateDef
= wxDefaultDateTime
);
767 const wchar_t* ParseFormat(const wchar_t* date
,
768 const wxString
& format
= wxDefaultDateTimeFormat
,
769 const wxDateTime
& dateDef
= wxDefaultDateTime
);
773 This function parses the string containing the date and time in ISO 8601
774 combined format (YYYY-MM-DDTHH:MM:SS). The separator between the date and time
775 parts must be equal to @a sep for the function to succeed.
776 Returns @true if the entire string was parsed successfully, @false
779 bool ParseISOCombined(const wxString
& date
, char sep
= 'T');
782 This function parses the date in ISO 8601 format (YYYY-MM-DD).
783 Returns @true if the entire string was parsed successfully, @false
786 bool ParseISODate(const wxString
& date
);
789 This function parses the time in ISO 8601 format (HH:MM:SS).
790 Returns @true if the entire string was parsed successfully, @false
793 bool ParseISOTime(const wxString
& date
);
797 Parses the string @a date looking for a date formatted according to the RFC
798 822 in it. The exact description of this format may, of course, be found in
799 the RFC (section 5), but, briefly, this is the format used in the headers of
800 Internet email messages and one of the most common strings expressing date in
801 this format may be something like @c "Sat, 18 Dec 1999 00:48:30 +0100".
802 Returns @NULL if the conversion failed, otherwise return the pointer to
803 the character immediately following the part of the string which could be
804 parsed. If the entire string contains only the date in RFC 822 format,
805 the returned pointer will be pointing to a @c NUL character.
806 This function is intentionally strict, it will return an error for any string
807 which is not RFC 822 compliant. If you need to parse date formatted in more
808 free ways, you should use ParseDateTime() or
811 const char* ParseRfc822Date(const wxString
& date
,
812 wxString::const_iterator
* end
= NULL
);
813 const char* ParseRfc822Date(const char* date
);
814 const wchar_t* ParseRfc822Date(const wchar_t* date
);
819 This functions is like ParseDateTime(), but
820 only allows the time to be specified in the input string.
821 Returns @NULL if the conversion failed, otherwise return the pointer to
822 the character which stopped the scan.
824 const char* ParseTime(const wxString
& time
,
825 wxString::const_iterator
* end
= NULL
);
826 const char* ParseTime(const char* time
);
827 const wchar_t* ParseTime(const wchar_t* time
);
831 These functions convert wxDateTime objects to and from text. The
832 conversions to text are mostly trivial: you can either do it using the default
833 date and time representations for the current locale (
835 wxDateTime::FormatTime), using the international standard
836 representation defined by ISO 8601 (
839 wxDateTime::FormatISOCombined) or by specifying any
840 format at all and using Format() directly.
841 The conversions from text are more interesting, as there are much more
842 possibilities to care about. The simplest cases can be taken care of with
843 ParseFormat() which can parse any date in the
844 given (rigid) format. wxDateTime::ParseRfc822Date is
845 another function for parsing dates in predefined format -- the one of RFC 822
846 which (still...) defines the format of email messages on the Internet. This
847 format can not be described with @c strptime(3)-like format strings used by
848 Format(), hence the need for a separate function.
849 But the most interesting functions are
852 ParseDateTime(). They try to parse the date
853 ans time (or only one of them) in 'free' format, i.e. allow them to be
854 specified in any of possible ways. These functions will usually be used to
855 parse the (interactive) user input which is not bound to be in any predefined
856 format. As an example, ParseDateTime() can
857 parse the strings such as @c "tomorrow", @c "March first" and even
859 Finally notice that each of the parsing functions is available in several
860 overloads: if the input string is a narrow (@c char *) string, then a
861 narrow pointer is returned. If the input string is a wide string, a wide char
862 pointer is returned. Finally, if the input parameter is a wxString, a narrow
863 char pointer is also returned for backwards compatibility but there is also an
864 additional argument of wxString::const_iterator type in which, if it is not
865 @NULL, an iterator pointing to the end of the scanned string part is returned.
880 wxDateTime::ParseRfc822Date
897 Reset time to midnight (00:00:00) without changing the date.
899 wxDateTime
& ResetTime();
902 Sets the date and time from the parameters.
904 wxDateTime
Set(wxDateTime_t day
, Month month
= Inv_Month
,
906 wxDateTime_t hour
= 0,
907 wxDateTime_t minute
= 0,
908 wxDateTime_t second
= 0,
909 wxDateTime_t millisec
= 0);
912 Sets the country to use by default. This setting influences the DST
913 calculations, date formatting and other things.
914 The possible values for @a country parameter are enumerated in
915 @ref overview_wxdatetime "wxDateTime constants section".
919 static void SetCountry(Country country
);
922 Sets the day without changing other date components.
924 wxDateTime
& SetDay(short unsigned int);
927 Sets the date from the date and time in
931 wxDateTime
Set(unsigned long ddt
);
934 Sets the hour without changing other date components.
936 wxDateTime
& SetHour(short unsigned int);
939 Sets the millisecond without changing other date components.
941 wxDateTime
& SetMillisecond(short unsigned int);
944 Sets the minute without changing other date components.
946 wxDateTime
& SetMinute(short unsigned int);
949 Sets the month without changing other date components.
951 wxDateTime
& SetMonth(Month month
);
954 Sets the second without changing other date components.
956 wxDateTime
& SetSecond(short unsigned int);
959 Sets the date and time of to the current values. Same as assigning the result
960 of Now() to this object.
962 wxDateTime
& SetToCurrent();
965 Sets the date to the last day in the specified month (the current one by
967 Returns the reference to the modified object itself.
969 wxDateTime
SetToLastMonthDay(Month month
= Inv_Month
,
970 int year
= Inv_Year
);
973 The effect of calling this function is the same as of calling
974 @c SetToWeekDay(-1, weekday, month, year). The date will be set to the last
975 @a weekday in the given month and year (the current ones by default).
976 Always returns @true.
978 bool SetToLastWeekDay(WeekDay weekday
, Month month
= Inv_Month
,
979 int year
= Inv_Year
);
982 Sets the date so that it will be the first @a weekday following the current
984 Returns the reference to the modified object itself.
986 wxDateTime
& SetToNextWeekDay(WeekDay weekday
);
989 Sets the date so that it will be the last @a weekday before the current
991 Returns the reference to the modified object itself.
993 wxDateTime
& SetToPrevWeekDay(WeekDay weekday
);
996 Sets the date to the @e n-th @a weekday in the given month of the given
997 year (the current month and year are used by default). The parameter @e n
998 may be either positive (counting from the beginning of the month) or negative
999 (counting from the end of it).
1000 For example, @c SetToWeekDay(2, wxDateTime::Wed) will set the date to the
1001 second Wednesday in the current month and
1002 @c SetToWeekDay(-1, wxDateTime::Sun) -- to the last Sunday in it.
1003 Returns @true if the date was modified successfully, @false
1004 otherwise meaning that the specified date doesn't exist.
1006 bool SetToWeekDay(WeekDay weekday
, int n
= 1,
1007 Month month
= Inv_Month
,
1008 int year
= Inv_Year
);
1011 Adjusts the date so that it will still lie in the same week as before, but its
1012 week day will be the given one.
1013 Returns the reference to the modified object itself.
1015 wxDateTime
SetToWeekDayInSameWeek(WeekDay weekday
,
1016 WeekFlags flags
= Monday_First
);
1019 Set the date to the given @a weekday in the week number @a numWeek of the
1020 given @a year . The number should be in range 1...53.
1021 Note that the returned date may be in a different year than the one passed to
1022 this function because both the week 1 and week 52 or 53 (for leap years)
1023 contain days from different years. See
1024 GetWeekOfYear() for the explanation of how the
1025 year weeks are counted.
1027 static wxDateTime
SetToWeekOfYear(int year
, wxDateTime_t numWeek
,
1028 WeekDay weekday
= Mon
);
1031 Sets the date to the day number @a yday in the same year (i.e., unlike the
1032 other functions, this one does not use the current year). The day number
1033 should be in the range 1...366 for the leap years and 1...365 for
1035 Returns the reference to the modified object itself.
1037 wxDateTime
& SetToYearDay(short unsigned int);
1040 Sets the year without changing other date components.
1042 wxDateTime
& SetYear(int year
);
1045 For convenience, all static functions are collected here. These functions
1046 either set or return the static variables of wxDateSpan (the country), return
1047 the current moment, year, month or number of days in it, or do some general
1048 calendar-related actions.
1049 Please note that although several function accept an extra @e Calendar
1050 parameter, it is currently ignored as only the Gregorian calendar is
1051 supported. Future versions will support other calendars.
1057 IsWestEuropeanCountry()
1067 @ref getcenturystatic() GetCentury
1094 Subtracts another date from this one and returns the difference between them
1097 wxTimeSpan
Subtract(const wxDateTime
& dt
) const;
1100 Please see the @ref overview_tdatetimezones "time zone overview" for more
1101 information about time zones. Normally, these functions should be rarely used.
1123 Transform the date to the given time zone. If @a noDST is @true, no
1124 DST adjustments will be made.
1125 Returns the date in the new time zone.
1127 wxDateTime
ToTimezone(const TimeZone
& tz
, bool noDST
= false) const;
1130 This is the same as calling ToTimezone() with
1131 the argument @c GMT0.
1133 wxDateTime
ToUTC(bool noDST
= false) const;
1136 Returns the object corresponding to the midnight of the current day (i.e. the
1137 same as Now(), but the time part is set to 0).
1141 static wxDateTime
Today();
1144 Returns the object corresponding to the current time including the
1145 milliseconds if a function to get time with such precision is available on the
1146 current platform (supported under most Unices and Win32).
1150 static wxDateTime
UNow();
1153 Same as @ref settm() Set.
1155 wxDateTime
operator(const struct tm
& tm
);
1159 Global instance of an empty wxDateTime object.
1161 @todo wouldn't be better to rename it wxNullDateTime as for the rest of wx global objects
1162 which are initialized to an empty value?
1164 wxDateTime wxDefaultDateTime
;
1169 @class wxDateTimeWorkDays
1170 @wxheader{datetime.h}
1176 class wxDateTimeWorkDays
1186 @wxheader{datetime.h}
1188 This class is a "logical time span" and is useful for implementing program
1189 logic for such things as "add one month to the date" which, in general,
1190 doesn't mean to add 60*60*24*31 seconds to it, but to take the same date
1191 the next month (to understand that this is indeed different consider adding
1192 one month to Feb, 15 -- we want to get Mar, 15, of course).
1194 When adding a month to the date, all lesser components (days, hours, ...)
1195 won't be changed unless the resulting date would be invalid: for example,
1196 Jan 31 + 1 month will be Feb 28, not (non-existing) Feb 31.
1198 Because of this feature, adding and subtracting back again the same
1199 wxDateSpan will @b not, in general give back the original date: Feb 28 - 1
1200 month will be Jan 28, not Jan 31!
1202 wxDateSpan objects can be either positive or negative. They may be
1203 multiplied by scalars which multiply all deltas by the scalar: i.e.
1204 2*(1 month and 1 day) is 2 months and 2 days. They can
1205 be added together and with wxDateTime or
1206 wxTimeSpan, but the type of result is different for each
1209 Beware about weeks: if you specify both weeks and days, the total number of
1210 days added will be 7*weeks + days! See also GetTotalDays()
1213 Equality operators are defined for wxDateSpans. Two datespans are equal if
1214 and only if they both give the same target date when added to @b every
1215 source date. Thus wxDateSpan::Months(1) is not equal to wxDateSpan::Days(30),
1216 because they don't give the same date when added to 1 Feb. But
1217 wxDateSpan::Days(14) is equal to wxDateSpan::Weeks(2)
1219 Finally, notice that for adding hours, minutes and so on you don't need this
1220 class at all: wxTimeSpan will do the job because there
1221 are no subtleties associated with those (we don't support leap seconds).
1226 @see @ref overview_wxdatetimeoverview "Date classes overview", wxDateTime
1232 Constructs the date span object for the given number of years, months, weeks
1233 and days. Note that the weeks and days add together if both are given.
1235 wxDateSpan(int years
= 0, int months
= 0, int weeks
= 0,
1240 Returns the sum of two date spans. The first version returns a new object, the
1241 second and third ones modify this object in place.
1243 wxDateSpan
Add(const wxDateSpan
& other
);
1244 const wxDateSpan
& Add(const wxDateSpan
& other
);
1245 wxDateSpan
operator+=(const wxDateSpan
& other
);
1249 Returns a date span object corresponding to one day.
1253 static wxDateSpan
Day();
1256 Returns a date span object corresponding to the given number of days.
1260 static wxDateSpan
Days(int days
);
1263 Returns the number of days (only, that it not counting the weeks component!)
1268 int GetDays() const;
1271 Returns the number of the months (not counting the years) in this date span.
1273 int GetMonths() const;
1276 Returns the combined number of days in this date span, counting both weeks and
1277 days. It still doesn't take neither months nor years into the account.
1279 @see GetWeeks(), GetDays()
1281 int GetTotalDays() const;
1284 Returns the number of weeks in this date span.
1288 int GetWeeks() const;
1291 Returns the number of years in this date span.
1293 int GetYears() const;
1296 Returns a date span object corresponding to one month.
1300 static wxDateSpan
Month();
1303 Returns a date span object corresponding to the given number of months.
1307 static wxDateSpan
Months(int mon
);
1311 Returns the product of the date span by the specified @e factor. The
1312 product is computed by multiplying each of the components by the factor.
1313 The first version returns a new object, the second and third ones modify this
1316 wxDateSpan
Multiply(int factor
);
1317 const wxDateSpan
& Multiply(int factor
);
1318 wxDateSpan
operator*=(int factor
);
1323 Changes the sign of this date span.
1328 wxDateSpan
operator-();
1332 Returns the date span with the opposite sign.
1336 wxDateSpan
Negate() const;
1339 Sets the number of days (without modifying any other components) in this date
1342 wxDateSpan
& SetDays(int n
);
1345 Sets the number of months (without modifying any other components) in this
1348 wxDateSpan
& SetMonths(int n
);
1351 Sets the number of weeks (without modifying any other components) in this date
1354 wxDateSpan
& SetWeeks(int n
);
1357 Sets the number of years (without modifying any other components) in this date
1360 wxDateSpan
& SetYears(int n
);
1364 Returns the difference of two date spans. The first version returns a new
1365 object, the second and third ones modify this object in place.
1367 wxDateSpan
Subtract(const wxDateSpan
& other
);
1368 const wxDateSpan
& Subtract(const wxDateSpan
& other
);
1369 wxDateSpan
operator+=(const wxDateSpan
& other
);
1373 Returns a date span object corresponding to one week.
1377 static wxDateSpan
Week();
1380 Returns a date span object corresponding to the given number of weeks.
1384 static wxDateSpan
Weeks(int weeks
);
1387 Returns a date span object corresponding to one year.
1391 static wxDateSpan
Year();
1394 Returns a date span object corresponding to the given number of years.
1398 static wxDateSpan
Years(int years
);
1401 Returns @true if this date span is different from the other one.
1403 bool operator!=(const wxDateSpan
&) const;
1406 Returns @true if this date span is equal to the other one. Two date spans
1407 are considered equal if and only if they have the same number of years and
1408 months and the same total number of days (counting both days and weeks).
1410 bool operator==(const wxDateSpan
&) const;
1417 @wxheader{datetime.h}
1419 wxTimeSpan class represents a time interval.
1424 @see @ref overview_wxdatetimeoverview "Date classes overview", wxDateTime
1431 Constructs timespan from separate values for each component, with the date
1432 set to 0. Hours are not restricted to 0..24 range, neither are
1433 minutes, seconds or milliseconds.
1436 wxTimeSpan(long hours
, long min
, long sec
, long msec
);
1440 Returns the absolute value of the timespan: does not modify the
1443 wxTimeSpan
Abs() const;
1462 Returns the sum of two timespans.
1464 wxTimeSpan
Add(const wxTimeSpan
& diff
);
1465 const wxTimeSpan
& Add(const wxTimeSpan
& diff
);
1466 wxTimeSpan
operator+=(const wxTimeSpan
& diff
);
1470 @ref ctor() wxTimeSpan
1475 Returns the timespan for one day.
1477 static wxTimespan
Day();
1480 Returns the timespan for the given number of days.
1482 static wxTimespan
Days(long days
);
1485 Returns the string containing the formatted representation of the time span.
1486 The following format specifiers are allowed after %:
1494 number of @b Minutes
1498 number of @b Seconds
1502 number of mi@b lliseconds
1514 the percent character
1516 Note that, for example, the number of hours in the description above is not
1517 well defined: it can be either the total number of hours (for example, for a
1518 time span of 50 hours this would be 50) or just the hour part of the time
1519 span, which would be 2 in this case as 50 hours is equal to 2 days and
1521 wxTimeSpan resolves this ambiguity in the following way: if there had been,
1522 indeed, the @c %D format specified preceding the @c %H, then it is
1523 interpreted as 2. Otherwise, it is 50.
1524 The same applies to all other format specifiers: if they follow a specifier of
1525 larger unit, only the rest part is taken, otherwise the full value is used.
1527 wxString
Format(const wxString
& = wxDefaultTimeSpanFormat
) const;
1535 Returns the difference in number of days.
1537 int GetDays() const;
1540 Returns the difference in number of hours.
1542 int GetHours() const;
1545 Returns the difference in number of milliseconds.
1547 wxLongLong
GetMilliseconds() const;
1550 Returns the difference in number of minutes.
1552 int GetMinutes() const;
1555 Returns the difference in number of seconds.
1557 wxLongLong
GetSeconds() const;
1560 Returns the internal representation of timespan.
1562 wxLongLong
GetValue() const;
1565 Returns the difference in number of weeks.
1567 int GetWeeks() const;
1570 Returns the timespan for one hour.
1572 static wxTimespan
Hour();
1575 Returns the timespan for the given number of hours.
1577 static wxTimespan
Hours(long hours
);
1580 Returns @true if two timespans are equal.
1582 bool IsEqualTo(const wxTimeSpan
& ts
) const;
1585 Compares two timespans: works with the absolute values, i.e. -2
1586 hours is longer than 1 hour. Also, it will return @false if
1587 the timespans are equal in absolute value.
1589 bool IsLongerThan(const wxTimeSpan
& ts
) const;
1592 Returns @true if the timespan is negative.
1594 bool IsNegative() const;
1597 Returns @true if the timespan is empty.
1599 bool IsNull() const;
1602 Returns @true if the timespan is positive.
1604 bool IsPositive() const;
1607 Compares two timespans: works with the absolute values, i.e. 1
1608 hour is shorter than -2 hours. Also, it will return @false if
1609 the timespans are equal in absolute value.
1611 bool IsShorterThan(const wxTimeSpan
& ts
) const;
1614 Returns the timespan for one millisecond.
1616 static wxTimespan
Millisecond();
1619 Returns the timespan for the given number of milliseconds.
1621 static wxTimespan
Milliseconds(long ms
);
1624 Returns the timespan for one minute.
1626 static wxTimespan
Minute();
1629 Returns the timespan for the given number of minutes.
1631 static wxTimespan
Minutes(long min
);
1635 Multiplies timespan by a scalar.
1637 wxTimeSpan
Multiply(int n
);
1638 const wxTimeSpan
& Multiply(int n
);
1639 wxTimeSpan
operator*=(int n
);
1644 Negate the value of the timespan.
1647 wxTimeSpan
operator-();
1651 Returns timespan with inverted sign.
1653 wxTimeSpan
Negate() const;
1671 Returns the timespan for one second.
1673 static wxTimespan
Second();
1676 Returns the timespan for the given number of seconds.
1678 static wxTimespan
Seconds(long sec
);
1709 Returns the difference of two timespans.
1711 wxTimeSpan
Subtract(const wxTimeSpan
& diff
);
1712 const wxTimeSpan
& Subtract(const wxTimeSpan
& diff
);
1713 wxTimeSpan
operator-=(const wxTimeSpan
& diff
);
1732 Returns the timespan for one week.
1734 static wxTimespan
Week();
1737 Returns the timespan for the given number of weeks.
1739 static wxTimespan
Weeks(long weeks
);
1745 @class wxDateTimeHolidayAuthority
1746 @wxheader{datetime.h}
1752 class wxDateTimeHolidayAuthority