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.
18 @see @ref overview_wxdatetimeoverview "Date classes overview", wxTimeSpan,
19 wxDateSpan, wxCalendarCtrl
25 Same as @ref setdate() Set
27 wxDateTime(wxDateTime_t day
, Month month
= Inv_Month
,
28 int Inv_Year
, wxDateTime_t hour
= 0,
29 wxDateTime_t minute
= 0,
30 wxDateTime_t second
= 0,
31 wxDateTime_t millisec
= 0);
34 Here are the trivial accessors. Other functions, which might have to perform
35 some more complicated calculations to find the answer are under the
36 @ref overview_datetimecalculations "Calendar calculations" section.
77 Adds the given date span to this object.
79 wxDateTime
Add(const wxDateSpan
& diff
);
80 const wxDateTime
& Add(const wxDateSpan
& diff
);
81 wxDateTime
operator+=(const wxDateSpan
& diff
);
85 Some degree of support for the date units used in astronomy and/or history is
86 provided. You can construct a wxDateTime object from a
87 @ref setjdn() JDN and you may also get its JDN,
88 @ref getmodifiedjuliandaynumber() MJD or
89 @ref getratadie() "Rata Die number" from it.
90 @ref wxdatetimejdn() "wxDateTime(double jdn)"
92 @ref setjdn() "Set(double jdn)"
98 GetModifiedJulianDayNumber()
107 The functions in this section perform the basic calendar calculations, mostly
108 related to the week days. They allow to find the given week day in the
109 week with given number (either in the month or in the year) and so on.
110 All (non-const) functions in this section don't modify the time part of the
111 wxDateTime -- they only work with the date part of it.
112 SetToWeekDayInSameWeek()
114 GetWeekDayInSameWeek()
126 @ref wxDateTime::getweekday2 GetWeekDay
145 Constructors and various @c Set() methods are collected here. If you
146 construct a date object from separate values for day, month and year, you
147 should use IsValid() method to check that the
148 values were correct as constructors can not return an error code.
149 @ref wxdatetimedef() wxDateTime
151 @ref wxdatetimetimet() wxDateTime(time_t)
153 @ref wxdatetimetm() "wxDateTime(struct tm)"
155 @ref wxdatetimejdn() "wxDateTime(double jdn)"
157 @ref wxdatetimetime() "wxDateTime(h, m, s, ms)"
159 @ref wxdatetimedate() "wxDateTime(day, mon, year, h, m, s, ms)"
163 @ref settimet() Set(time_t)
165 @ref settm() "Set(struct tm)"
167 @ref setjdn() "Set(double jdn)"
169 @ref settime() "Set(h, m, s, ms)"
171 @ref setdate() "Set(day, mon, year, h, m, s, ms)"
173 @ref setfromdos() "SetFromDOS(unsigned long ddt)"
181 @ref setdate() SetDay
191 @ref operatoreqtimet() operator=(time_t)
193 @ref operatoreqtm() "operator=(struct tm)"
198 Converts the year in absolute notation (i.e. a number which can be negative,
199 positive or zero) to the year in BC/AD notation. For the positive years,
200 nothing is done, but the year 0 is year 1 BC and so for other years there is a
202 This function should be used like this:
204 static int ConvertYearToBC(int year
);
207 These functions carry out arithmetics() on the wxDateTime
208 objects. As explained in the overview, either wxTimeSpan or wxDateSpan may be
209 added to wxDateTime, hence all functions are overloaded to accept both
211 Also, both @c Add() and @c Subtract() have both const and non-const
212 version. The first one returns a new object which represents the
213 sum/difference of the original one with the argument while the second form
214 modifies the object to which it is applied. The operators -= and += are
215 defined to be equivalent to the second forms of these functions.
216 @ref addts() Add(wxTimeSpan)
218 @ref addds() Add(wxDateSpan)
220 @ref subtractts() Subtract(wxTimeSpan)
222 @ref subtractds() Subtract(wxDateSpan)
224 @ref subtractdt() Subtract(wxDateTime)
226 @ref addts() oparator+=(wxTimeSpan)
228 @ref addds() oparator+=(wxDateSpan)
230 @ref subtractts() oparator-=(wxTimeSpan)
232 @ref subtractds() oparator-=(wxDateSpan)
237 There are several function to allow date comparison. To supplement them, a few
238 global operators , etc taking wxDateTime are defined.
258 This function does the same as the standard ANSI C @c strftime(3) function.
259 Please see its description for the meaning of @a format parameter.
260 It also accepts a few wxWidgets-specific extensions: you can optionally specify
261 the width of the field to follow using @c printf(3)-like syntax and the
262 format specification @c %l can be used to get the number of milliseconds.
266 wxString
Format(const wxChar
* format
= wxDefaultDateTimeFormat
,
267 const TimeZone
& tz
= Local
) const;
270 Identical to calling Format() with @c "%x"
271 argument (which means 'preferred date representation for the current locale').
273 wxString
FormatDate() const;
276 Returns the combined date-time representation in the ISO 8601 format
277 (YYYY-MM-DDTHH:MM:SS). The @a sep parameter default value produces the
278 result exactly corresponding to the ISO standard, but it can also be useful to
279 use a space as seprator if a more human-readable combined date-time
280 representation is needed.
282 @see FormatISODate(), FormatISOTime(),
285 wxString
FormatISOCombined(char sep
= 'T') const;
288 This function returns the date representation in the ISO 8601 format
291 wxString
FormatISODate() const;
294 This function returns the time representation in the ISO 8601 format
297 wxString
FormatISOTime() const;
300 Identical to calling Format() with @c "%X"
301 argument (which means 'preferred time representation for the current locale').
303 wxString
FormatTime() const;
306 Transform the date from the given time zone to the local one. If @a noDST is
307 @true, no DST adjustments will be made.
308 Returns the date in the local time zone.
310 wxDateTime
FromTimezone(const TimeZone
& tz
,
311 bool noDST
= false) const;
314 Returns the translations of the strings @c AM and @c PM used for time
315 formatting for the current locale. Either of the pointers may be @NULL if
316 the corresponding value is not needed.
318 static void GetAmPmStrings(wxString
* am
, wxString
* pm
);
321 Returns the date and time in
325 unsigned long GetAsDOS() const;
328 Get the beginning of DST for the given country in the given year (current one
329 by default). This function suffers from limitations described in
330 @ref overview_tdatedst "DST overview".
334 static wxDateTime
GetBeginDST(int year
= Inv_Year
,
335 Country country
= Country_Default
);
338 Returns the century of this date.
340 int GetCentury(const TimeZone
& tz
= Local
) const;
343 Returns the current default country. The default country is used for DST
344 calculations, for example.
348 static Country
GetCountry();
351 Get the current month in given calendar (only Gregorian is currently supported).
353 static Month
GetCurrentMonth(Calendar cal
= Gregorian
);
356 Get the current year in given calendar (only Gregorian is currently supported).
358 static int GetCurrentYear(Calendar cal
= Gregorian
);
361 Returns the object having the same date component as this one but time of
368 wxDateTime
GetDateOnly() const;
371 Returns the day in the given timezone (local one by default).
373 wxDateTime_t
GetDay(const TimeZone
& tz
= Local
) const;
376 Returns the day of the year (in 1...366 range) in the given timezone
377 (local one by default).
379 wxDateTime_t
GetDayOfYear(const TimeZone
& tz
= Local
) const;
382 Returns the end of DST for the given country in the given year (current one by
387 static wxDateTime
GetEndDST(int year
= Inv_Year
,
388 Country country
= Country_Default
);
391 Returns the hour in the given timezone (local one by default).
393 wxDateTime_t
GetHour(const TimeZone
& tz
= Local
) const;
396 Synonym for GetJulianDayNumber().
398 double GetJDN() const;
401 Returns the @ref setjdn() JDN corresponding to this date. Beware
404 @see GetModifiedJulianDayNumber()
406 double GetJulianDayNumber() const;
409 Returns the copy of this object to which
410 SetToLastMonthDay() was applied.
412 wxDateTime
GetLastMonthDay(Month month
= Inv_Month
,
413 int year
= Inv_Year
) const;
416 Returns the copy of this object to which
417 SetToLastWeekDay() was applied.
419 wxDateTime
GetLastWeekDay(WeekDay weekday
,
420 Month month
= Inv_Month
,
421 int year
= Inv_Year
);
424 Synonym for GetModifiedJulianDayNumber().
426 double GetMJD() const;
429 Returns the milliseconds in the given timezone (local one by default).
431 wxDateTime_t
GetMillisecond(const TimeZone
& tz
= Local
) const;
434 Returns the minute in the given timezone (local one by default).
436 wxDateTime_t
GetMinute(const TimeZone
& tz
= Local
) const;
439 Returns the @e Modified Julian Day Number (MJD) which is, by definition,
440 equal to JDN - 2400000.5. The MJDs are simpler to work with as the integral
441 MJDs correspond to midnights of the dates in the Gregorian calendar and not th
442 noons like JDN. The MJD 0 is Nov 17, 1858.
444 double GetModifiedJulianDayNumber() const;
447 Returns the month in the given timezone (local one by default).
449 Month
GetMonth(const TimeZone
& tz
= Local
) const;
452 Gets the full (default) or abbreviated (specify @c Name_Abbr name of the
455 @see GetWeekDayName()
457 static wxString
GetMonthName(Month month
,
458 NameFlags flags
= Name_Full
);
461 Returns the copy of this object to which
462 SetToNextWeekDay() was applied.
464 wxDateTime
GetNextWeekDay(WeekDay weekday
) const;
468 Returns the number of days in the given year or in the given month of the
470 The only supported value for @a cal parameter is currently @c Gregorian.
472 static wxDateTime_t
GetNumberOfDays(int year
,
473 Calendar cal
= Gregorian
);
474 static wxDateTime_t
GetNumberOfDays(Month month
,
476 Calendar cal
= Gregorian
);
480 Returns the copy of this object to which
481 SetToPrevWeekDay() was applied.
483 wxDateTime
GetPrevWeekDay(WeekDay weekday
) const;
486 Return the @e Rata Die number of this date.
487 By definition, the Rata Die number is a date specified as the number of days
488 relative to a base date of December 31 of the year 0. Thus January 1 of the
489 year 1 is Rata Die day 1.
491 double GetRataDie() const;
494 Returns the seconds in the given timezone (local one by default).
496 wxDateTime_t
GetSecond(const TimeZone
& tz
= Local
) const;
499 Returns the number of seconds since Jan 1, 1970. An assert failure will occur
500 if the date is not in the range covered by @c time_t type.
502 time_t GetTicks() const;
505 Returns the current time.
507 static time_t GetTimeNow();
510 Returns broken down representation of the date and time.
512 Tm
GetTm(const TimeZone
& tz
= Local
) const;
515 Returns the current time broken down. Note that this function returns a
516 pointer to a static buffer that's reused by calls to this function and
517 certain C library functions (e.g. localtime). If there is any chance your
518 code might be used in a multi-threaded application, you really should use
519 the flavour of function GetTmNow()
522 static struct tm
* GetTmNow();
525 Returns the copy of this object to which
526 SetToWeekDay() was applied.
528 wxDateTime
GetWeekDay(WeekDay weekday
, int n
= 1,
529 Month month
= Inv_Month
,
530 int year
= Inv_Year
) const;
533 Returns the copy of this object to which
534 SetToWeekDayInSameWeek() was
537 wxDateTime
GetWeekDayInSameWeek(WeekDay weekday
,
538 WeekFlags flags
= Monday_First
) const;
541 Gets the full (default) or abbreviated (specify @c Name_Abbr name of the
546 static wxString
GetWeekDayName(WeekDay weekday
,
547 NameFlags flags
= Name_Full
);
550 Returns the ordinal number of the week in the month (in 1...5 range).
551 As GetWeekOfYear(), this function supports
552 both conventions for the week start. See the description of these
553 @ref overview_wxdatetime "week start" conventions.
555 wxDateTime_t
GetWeekOfMonth(WeekFlags flags
= Monday_First
,
556 const TimeZone
& tz
= Local
) const;
559 Returns the number of the week of the year this date is in. The first week of
560 the year is, according to international standards, the one containing Jan 4 or,
561 equivalently, the first week which has Thursday in this year. Both of these
562 definitions are the same as saying that the first week of the year must contain
563 more than half of its days in this year. Accordingly, the week number will
564 always be in 1...53 range (52 for non-leap years).
565 The function depends on the @ref overview_wxdatetime "week start" convention
566 specified by the @a flags argument but its results for
567 @c Sunday_First are not well-defined as the ISO definition quoted above
568 applies to the weeks starting on Monday only.
570 wxDateTime_t
GetWeekOfYear(WeekFlags flags
= Monday_First
,
571 const TimeZone
& tz
= Local
) const;
574 Returns the year in the given timezone (local one by default).
576 int GetYear(const TimeZone
& tz
= Local
) const;
579 Returns the copy of this object to which
580 SetToYearDay() was applied.
582 wxDateTime
GetYearDay(wxDateTime_t yday
) const;
585 Returns @true if IsStrictlyBetween()
586 is @true or if the date is equal to one of the limit values.
588 @see IsStrictlyBetween()
590 bool IsBetween(const wxDateTime
& t1
, const wxDateTime
& t2
) const;
593 Returns @true if the DST is applied for this date in the given country.
595 int IsDST(Country country
= Country_Default
) const;
598 Returns @true if DST was used n the given year (the current one by
599 default) in the given country.
601 static bool IsDSTApplicable(int year
= Inv_Year
,
602 Country country
= Country_Default
);
605 Returns @true if this date precedes the given one.
607 bool IsEarlierThan(const wxDateTime
& datetime
) const;
610 Returns @true if the two dates are strictly identical.
612 bool IsEqualTo(const wxDateTime
& datetime
) const;
615 Returns @true if the date is equal to another one up to the given time
616 interval, i.e. if the absolute difference between the two dates is less than
619 bool IsEqualUpTo(const wxDateTime
& dt
, const wxTimeSpan
& ts
) const;
622 Returns @true if the given date is later than the date of adoption of the
623 Gregorian calendar in the given country (and hence the Gregorian calendar
624 calculations make sense for it).
626 bool IsGregorianDate(GregorianAdoption country
= Gr_Standard
) const;
629 Returns @true if this date is later than the given one.
631 bool IsLaterThan(const wxDateTime
& datetime
) const;
634 Returns @true if the @a year is a leap one in the specified calendar.
635 This functions supports Gregorian and Julian calendars.
637 static bool IsLeapYear(int year
= Inv_Year
,
638 Calendar cal
= Gregorian
);
641 Returns @true if the date is the same without comparing the time parts.
643 bool IsSameDate(const wxDateTime
& dt
) const;
646 Returns @true if the time is the same (although dates may differ).
648 bool IsSameTime(const wxDateTime
& dt
) const;
651 Returns @true if this date lies strictly between the two others,
655 bool IsStrictlyBetween(const wxDateTime
& t1
,
656 const wxDateTime
& t2
) const;
659 Returns @true if the object represents a valid time moment.
661 bool IsValid() const;
664 This function returns @true if the specified (or default) country is one
665 of Western European ones. It is used internally by wxDateTime to determine the
666 DST convention and date and time formatting rules.
668 static bool IsWestEuropeanCountry(Country country
= Country_Default
);
671 Returns @true is this day is not a holiday in the given country.
673 bool IsWorkDay(Country country
= Country_Default
) const;
676 Same as FromTimezone() but modifies the object
679 wxDateTime
MakeFromTimezone(const TimeZone
& tz
,
683 Modifies the object in place to represent the date in another time zone. If
684 @a noDST is @true, no DST adjustments will be made.
686 wxDateTime
MakeTimezone(const TimeZone
& tz
,
690 This is the same as calling MakeTimezone() with
691 the argument @c GMT0.
693 wxDateTime
MakeUTC(bool noDST
= false);
696 Returns the object corresponding to the current time.
699 Note that this function is accurate up to second:
700 UNow() should be used for better precision
701 (but it is less efficient and might not be available on all platforms).
705 static wxDateTime
Now();
709 This function is like ParseDateTime(), but it
710 only allows the date to be specified. It is thus less flexible then
711 ParseDateTime(), but also has less chances to
712 misinterpret the user input.
713 Returns @NULL if the conversion failed, otherwise return the pointer to
714 the character which stopped the scan.
716 const char* ParseDate(const wxString
& date
,
717 wxString::const_iterator
* end
= NULL
);
718 const char* ParseDate(const char* date
);
719 const wchar_t* ParseDate(const wchar_t* date
);
724 Parses the string @a datetime containing the date and time in free format.
725 This function tries as hard as it can to interpret the given string as date
726 and time. Unlike wxDateTime::ParseRfc822Date, it
727 will accept anything that may be accepted and will only reject strings which
728 can not be parsed in any way at all.
729 Returns @NULL if the conversion failed, otherwise return the pointer to
730 the character which stopped the scan.
732 const char* ParseDateTime(const wxString
& datetime
,
733 wxString::const_iterator
* end
= NULL
);
734 const char* ParseDateTime(const char* datetime
);
735 const wchar_t* ParseDateTime(const wchar_t* datetime
);
740 This function parses the string @a date according to the given
741 @e format. The system @c strptime(3) function is used whenever available,
742 but even if it is not, this function is still implemented, although support
743 for locale-dependent format specifiers such as @c "%c", @c "%x" or @c "%X" may
744 not be perfect and GNU extensions such as @c "%z" and @c "%Z" are
745 not implemented. This function does handle the month and weekday
746 names in the current locale on all platforms, however.
747 Please see the description of the ANSI C function @c strftime(3) for the syntax
748 of the format string.
749 The @a dateDef parameter is used to fill in the fields which could not be
750 determined from the format string. For example, if the format is @c "%d" (the
751 ay of the month), the month and the year are taken from @e dateDef. If
752 it is not specified, Today() is used as the
754 Returns @NULL if the conversion failed, otherwise return the pointer to
755 the character which stopped the scan.
757 const char* ParseFormat(const wxString
& date
,
758 const wxString
& format
= wxDefaultDateTimeFormat
,
759 const wxDateTime
& dateDef
= wxDefaultDateTime
,
760 wxString::const_iterator
* end
= NULL
);
761 const char* ParseFormat(const char* date
,
762 const wxString
& format
= wxDefaultDateTimeFormat
,
763 const wxDateTime
& dateDef
= wxDefaultDateTime
);
764 const wchar_t* ParseFormat(const wchar_t* date
,
765 const wxString
& format
= wxDefaultDateTimeFormat
,
766 const wxDateTime
& dateDef
= wxDefaultDateTime
);
770 This function parses the string containing the date and time in ISO 8601
771 combined format (YYYY-MM-DDTHH:MM:SS). The separator between the date and time
772 parts must be equal to @a sep for the function to succeed.
773 Returns @true if the entire string was parsed successfully, @false
776 bool ParseISOCombined(const wxString
& date
, char sep
= 'T');
779 This function parses the date in ISO 8601 format (YYYY-MM-DD).
780 Returns @true if the entire string was parsed successfully, @false
783 bool ParseISODate(const wxString
& date
);
786 This function parses the time in ISO 8601 format (HH:MM:SS).
787 Returns @true if the entire string was parsed successfully, @false
790 bool ParseISOTime(const wxString
& date
);
794 Parses the string @a date looking for a date formatted according to the RFC
795 822 in it. The exact description of this format may, of course, be found in
796 the RFC (section 5), but, briefly, this is the format used in the headers of
797 Internet email messages and one of the most common strings expressing date in
798 this format may be something like @c "Sat, 18 Dec 1999 00:48:30 +0100".
799 Returns @NULL if the conversion failed, otherwise return the pointer to
800 the character immediately following the part of the string which could be
801 parsed. If the entire string contains only the date in RFC 822 format,
802 the returned pointer will be pointing to a @c NUL character.
803 This function is intentionally strict, it will return an error for any string
804 which is not RFC 822 compliant. If you need to parse date formatted in more
805 free ways, you should use ParseDateTime() or
808 const char* ParseRfc822Date(const wxString
& date
,
809 wxString::const_iterator
* end
= NULL
);
810 const char* ParseRfc822Date(const char* date
);
811 const wchar_t* ParseRfc822Date(const wchar_t* date
);
816 This functions is like ParseDateTime(), but
817 only allows the time to be specified in the input string.
818 Returns @NULL if the conversion failed, otherwise return the pointer to
819 the character which stopped the scan.
821 const char* ParseTime(const wxString
& time
,
822 wxString::const_iterator
* end
= NULL
);
823 const char* ParseTime(const char* time
);
824 const wchar_t* ParseTime(const wchar_t* time
);
828 These functions convert wxDateTime objects to and from text. The
829 conversions to text are mostly trivial: you can either do it using the default
830 date and time representations for the current locale (
832 wxDateTime::FormatTime), using the international standard
833 representation defined by ISO 8601 (
836 wxDateTime::FormatISOCombined) or by specifying any
837 format at all and using Format() directly.
838 The conversions from text are more interesting, as there are much more
839 possibilities to care about. The simplest cases can be taken care of with
840 ParseFormat() which can parse any date in the
841 given (rigid) format. wxDateTime::ParseRfc822Date is
842 another function for parsing dates in predefined format -- the one of RFC 822
843 which (still...) defines the format of email messages on the Internet. This
844 format can not be described with @c strptime(3)-like format strings used by
845 Format(), hence the need for a separate function.
846 But the most interesting functions are
849 ParseDateTime(). They try to parse the date
850 ans time (or only one of them) in 'free' format, i.e. allow them to be
851 specified in any of possible ways. These functions will usually be used to
852 parse the (interactive) user input which is not bound to be in any predefined
853 format. As an example, ParseDateTime() can
854 parse the strings such as @c "tomorrow", @c "March first" and even
856 Finally notice that each of the parsing functions is available in several
857 overloads: if the input string is a narrow (@c char *) string, then a
858 narrow pointer is returned. If the input string is a wide string, a wide char
859 pointer is returned. Finally, if the input parameter is a wxString, a narrow
860 char pointer is also returned for backwards compatibility but there is also an
861 additional argument of wxString::const_iterator type in which, if it is not
862 @NULL, an iterator pointing to the end of the scanned string part is returned.
877 wxDateTime::ParseRfc822Date
894 Reset time to midnight (00:00:00) without changing the date.
896 wxDateTime
ResetTime();
899 Sets the date and time from the parameters.
901 wxDateTime
Set(wxDateTime_t day
, Month month
= Inv_Month
,
903 wxDateTime_t hour
= 0,
904 wxDateTime_t minute
= 0,
905 wxDateTime_t second
= 0,
906 wxDateTime_t millisec
= 0);
909 Sets the country to use by default. This setting influences the DST
910 calculations, date formatting and other things.
911 The possible values for @a country parameter are enumerated in
912 @ref overview_wxdatetime "wxDateTime constants section".
916 static void SetCountry(Country country
);
919 Sets the day without changing other date components.
921 wxDateTime
SetDay(wxDateTime_t day
);
924 Sets the date from the date and time in
928 wxDateTime
Set(unsigned long ddt
);
931 Sets the hour without changing other date components.
933 wxDateTime
SetHour(wxDateTime_t hour
);
936 Sets the millisecond without changing other date components.
938 wxDateTime
SetMillisecond(wxDateTime_t millisecond
);
941 Sets the minute without changing other date components.
943 wxDateTime
SetMinute(wxDateTime_t minute
);
946 Sets the month without changing other date components.
948 wxDateTime
SetMonth(Month month
);
951 Sets the second without changing other date components.
953 wxDateTime
SetSecond(wxDateTime_t second
);
956 Sets the date and time of to the current values. Same as assigning the result
957 of Now() to this object.
959 wxDateTime
SetToCurrent();
962 Sets the date to the last day in the specified month (the current one by
964 Returns the reference to the modified object itself.
966 wxDateTime
SetToLastMonthDay(Month month
= Inv_Month
,
967 int year
= Inv_Year
);
970 The effect of calling this function is the same as of calling
971 @c SetToWeekDay(-1, weekday, month, year). The date will be set to the last
972 @a weekday in the given month and year (the current ones by default).
973 Always returns @true.
975 bool SetToLastWeekDay(WeekDay weekday
, Month month
= Inv_Month
,
976 int year
= Inv_Year
);
979 Sets the date so that it will be the first @a weekday following the current
981 Returns the reference to the modified object itself.
983 wxDateTime
SetToNextWeekDay(WeekDay weekday
);
986 Sets the date so that it will be the last @a weekday before the current
988 Returns the reference to the modified object itself.
990 wxDateTime
SetToPrevWeekDay(WeekDay weekday
);
993 Sets the date to the @e n-th @a weekday in the given month of the given
994 year (the current month and year are used by default). The parameter @e n
995 may be either positive (counting from the beginning of the month) or negative
996 (counting from the end of it).
997 For example, @c SetToWeekDay(2, wxDateTime::Wed) will set the date to the
998 second Wednesday in the current month and
999 @c SetToWeekDay(-1, wxDateTime::Sun) -- to the last Sunday in it.
1000 Returns @true if the date was modified successfully, @false
1001 otherwise meaning that the specified date doesn't exist.
1003 bool SetToWeekDay(WeekDay weekday
, int n
= 1,
1004 Month month
= Inv_Month
,
1005 int year
= Inv_Year
);
1008 Adjusts the date so that it will still lie in the same week as before, but its
1009 week day will be the given one.
1010 Returns the reference to the modified object itself.
1012 wxDateTime
SetToWeekDayInSameWeek(WeekDay weekday
,
1013 WeekFlags flags
= Monday_First
);
1016 Set the date to the given @a weekday in the week number @a numWeek of the
1017 given @a year . The number should be in range 1...53.
1018 Note that the returned date may be in a different year than the one passed to
1019 this function because both the week 1 and week 52 or 53 (for leap years)
1020 contain days from different years. See
1021 GetWeekOfYear() for the explanation of how the
1022 year weeks are counted.
1024 static wxDateTime
SetToWeekOfYear(int year
, wxDateTime_t numWeek
,
1025 WeekDay weekday
= Mon
);
1028 Sets the date to the day number @a yday in the same year (i.e., unlike the
1029 other functions, this one does not use the current year). The day number
1030 should be in the range 1...366 for the leap years and 1...365 for
1032 Returns the reference to the modified object itself.
1034 wxDateTime
SetToYearDay(wxDateTime_t yday
);
1037 Sets the year without changing other date components.
1039 wxDateTime
SetYear(int year
);
1042 For convenience, all static functions are collected here. These functions
1043 either set or return the static variables of wxDateSpan (the country), return
1044 the current moment, year, month or number of days in it, or do some general
1045 calendar-related actions.
1046 Please note that although several function accept an extra @e Calendar
1047 parameter, it is currently ignored as only the Gregorian calendar is
1048 supported. Future versions will support other calendars.
1054 IsWestEuropeanCountry()
1064 @ref getcenturystatic() GetCentury
1091 Subtracts another date from this one and returns the difference between them
1094 wxTimeSpan
Subtract(const wxDateTime
& dt
) const;
1097 Please see the @ref overview_tdatetimezones "time zone overview" for more
1098 information about time zones. Normally, these functions should be rarely used.
1120 Transform the date to the given time zone. If @a noDST is @true, no
1121 DST adjustments will be made.
1122 Returns the date in the new time zone.
1124 wxDateTime
ToTimezone(const TimeZone
& tz
, bool noDST
= false) const;
1127 This is the same as calling ToTimezone() with
1128 the argument @c GMT0.
1130 wxDateTime
ToUTC(bool noDST
= false) const;
1133 Returns the object corresponding to the midnight of the current day (i.e. the
1134 same as Now(), but the time part is set to 0).
1138 static wxDateTime
Today();
1141 Returns the object corresponding to the current time including the
1142 milliseconds if a function to get time with such precision is available on the
1143 current platform (supported under most Unices and Win32).
1147 static wxDateTime
UNow();
1150 Same as @ref settm() Set.
1152 wxDateTime
operator(const struct tm
& tm
);
1158 @class wxDateTimeWorkDays
1159 @wxheader{datetime.h}
1165 class wxDateTimeWorkDays
1175 @wxheader{datetime.h}
1177 This class is a "logical time span" and is useful for implementing program
1178 logic for such things as "add one month to the date" which, in general,
1179 doesn't mean to add 60*60*24*31 seconds to it, but to take the same date
1180 the next month (to understand that this is indeed different consider adding
1181 one month to Feb, 15 -- we want to get Mar, 15, of course).
1183 When adding a month to the date, all lesser components (days, hours, ...)
1184 won't be changed unless the resulting date would be invalid: for example,
1185 Jan 31 + 1 month will be Feb 28, not (non-existing) Feb 31.
1187 Because of this feature, adding and subtracting back again the same
1188 wxDateSpan will @b not, in general give back the original date: Feb 28 - 1
1189 month will be Jan 28, not Jan 31!
1191 wxDateSpan objects can be either positive or negative. They may be
1192 multiplied by scalars which multiply all deltas by the scalar: i.e.
1193 2*(1 month and 1 day) is 2 months and 2 days. They can
1194 be added together and with wxDateTime or
1195 wxTimeSpan, but the type of result is different for each
1198 Beware about weeks: if you specify both weeks and days, the total number of
1199 days added will be 7*weeks + days! See also GetTotalDays()
1202 Equality operators are defined for wxDateSpans. Two datespans are equal if
1203 and only if they both give the same target date when added to @b every
1204 source date. Thus wxDateSpan::Months(1) is not equal to wxDateSpan::Days(30),
1205 because they don't give the same date when added to 1 Feb. But
1206 wxDateSpan::Days(14) is equal to wxDateSpan::Weeks(2)
1208 Finally, notice that for adding hours, minutes and so on you don't need this
1209 class at all: wxTimeSpan will do the job because there
1210 are no subtleties associated with those (we don't support leap seconds).
1215 @see @ref overview_wxdatetimeoverview "Date classes overview", wxDateTime
1221 Constructs the date span object for the given number of years, months, weeks
1222 and days. Note that the weeks and days add together if both are given.
1224 wxDateSpan(int years
= 0, int months
= 0, int weeks
= 0,
1229 Returns the sum of two date spans. The first version returns a new object, the
1230 second and third ones modify this object in place.
1232 wxDateSpan
Add(const wxDateSpan
& other
);
1233 const wxDateSpan
& Add(const wxDateSpan
& other
);
1234 wxDateSpan
operator+=(const wxDateSpan
& other
);
1238 Returns a date span object corresponding to one day.
1242 static wxDateSpan
Day();
1245 Returns a date span object corresponding to the given number of days.
1249 static wxDateSpan
Days(int days
);
1252 Returns the number of days (only, that it not counting the weeks component!)
1257 int GetDays() const;
1260 Returns the number of the months (not counting the years) in this date span.
1262 int GetMonths() const;
1265 Returns the combined number of days in this date span, counting both weeks and
1266 days. It still doesn't take neither months nor years into the account.
1268 @see GetWeeks(), GetDays()
1270 int GetTotalDays() const;
1273 Returns the number of weeks in this date span.
1277 int GetWeeks() const;
1280 Returns the number of years in this date span.
1282 int GetYears() const;
1285 Returns a date span object corresponding to one month.
1289 static wxDateSpan
Month();
1292 Returns a date span object corresponding to the given number of months.
1296 static wxDateSpan
Months(int mon
);
1300 Returns the product of the date span by the specified @e factor. The
1301 product is computed by multiplying each of the components by the factor.
1302 The first version returns a new object, the second and third ones modify this
1305 wxDateSpan
Multiply(int factor
);
1306 const wxDateSpan
& Multiply(int factor
);
1307 wxDateSpan
operator*=(int factor
);
1312 Changes the sign of this date span.
1317 wxDateSpan
operator-();
1321 Returns the date span with the opposite sign.
1325 wxDateSpan
Negate() const;
1328 Sets the number of days (without modifying any other components) in this date
1331 wxDateSpan
SetDays(int n
);
1334 Sets the number of months (without modifying any other components) in this
1337 wxDateSpan
SetMonths(int n
);
1340 Sets the number of weeks (without modifying any other components) in this date
1343 wxDateSpan
SetWeeks(int n
);
1346 Sets the number of years (without modifying any other components) in this date
1349 wxDateSpan
SetYears(int n
);
1353 Returns the difference of two date spans. The first version returns a new
1354 object, the second and third ones modify this object in place.
1356 wxDateSpan
Subtract(const wxDateSpan
& other
);
1357 const wxDateSpan
& Subtract(const wxDateSpan
& other
);
1358 wxDateSpan
operator+=(const wxDateSpan
& other
);
1362 Returns a date span object corresponding to one week.
1366 static wxDateSpan
Week();
1369 Returns a date span object corresponding to the given number of weeks.
1373 static wxDateSpan
Weeks(int weeks
);
1376 Returns a date span object corresponding to one year.
1380 static wxDateSpan
Year();
1383 Returns a date span object corresponding to the given number of years.
1387 static wxDateSpan
Years(int years
);
1390 Returns @true if this date span is different from the other one.
1392 bool operator!=(wxDateSpan
& other
) const;
1395 Returns @true if this date span is equal to the other one. Two date spans
1396 are considered equal if and only if they have the same number of years and
1397 months and the same total number of days (counting both days and weeks).
1399 bool operator==(wxDateSpan
& other
) const;
1406 @wxheader{datetime.h}
1408 wxTimeSpan class represents a time interval.
1413 @see @ref overview_wxdatetimeoverview "Date classes overview", wxDateTime
1420 Constructs timespan from separate values for each component, with the date
1421 set to 0. Hours are not restricted to 0..24 range, neither are
1422 minutes, seconds or milliseconds.
1425 wxTimeSpan(long hours
, long min
, long sec
, long msec
);
1429 Returns the absolute value of the timespan: does not modify the
1432 wxTimeSpan
Abs() const;
1451 Returns the sum of two timespans.
1453 wxTimeSpan
Add(const wxTimeSpan
& diff
);
1454 const wxTimeSpan
& Add(const wxTimeSpan
& diff
);
1455 wxTimeSpan
operator+=(const wxTimeSpan
& diff
);
1459 @ref ctor() wxTimeSpan
1464 Returns the timespan for one day.
1466 static wxTimespan
Day();
1469 Returns the timespan for the given number of days.
1471 static wxTimespan
Days(long days
);
1474 Returns the string containing the formatted representation of the time span.
1475 The following format specifiers are allowed after %:
1483 number of @b Minutes
1487 number of @b Seconds
1491 number of mi@b lliseconds
1503 the percent character
1505 Note that, for example, the number of hours in the description above is not
1506 well defined: it can be either the total number of hours (for example, for a
1507 time span of 50 hours this would be 50) or just the hour part of the time
1508 span, which would be 2 in this case as 50 hours is equal to 2 days and
1510 wxTimeSpan resolves this ambiguity in the following way: if there had been,
1511 indeed, the @c %D format specified preceding the @c %H, then it is
1512 interpreted as 2. Otherwise, it is 50.
1513 The same applies to all other format specifiers: if they follow a specifier of
1514 larger unit, only the rest part is taken, otherwise the full value is used.
1516 wxString
Format(const wxChar
* format
= wxDefaultTimeSpanFormat
);
1524 Returns the difference in number of days.
1526 int GetDays() const;
1529 Returns the difference in number of hours.
1531 int GetHours() const;
1534 Returns the difference in number of milliseconds.
1536 wxLongLong
GetMilliseconds() const;
1539 Returns the difference in number of minutes.
1541 int GetMinutes() const;
1544 Returns the difference in number of seconds.
1546 wxLongLong
GetSeconds() const;
1549 Returns the internal representation of timespan.
1551 wxLongLong
GetValue() const;
1554 Returns the difference in number of weeks.
1556 int GetWeeks() const;
1559 Returns the timespan for one hour.
1561 static wxTimespan
Hour();
1564 Returns the timespan for the given number of hours.
1566 static wxTimespan
Hours(long hours
);
1569 Returns @true if two timespans are equal.
1571 bool IsEqualTo(const wxTimeSpan
& ts
) const;
1574 Compares two timespans: works with the absolute values, i.e. -2
1575 hours is longer than 1 hour. Also, it will return @false if
1576 the timespans are equal in absolute value.
1578 bool IsLongerThan(const wxTimeSpan
& ts
) const;
1581 Returns @true if the timespan is negative.
1583 bool IsNegative() const;
1586 Returns @true if the timespan is empty.
1588 bool IsNull() const;
1591 Returns @true if the timespan is positive.
1593 bool IsPositive() const;
1596 Compares two timespans: works with the absolute values, i.e. 1
1597 hour is shorter than -2 hours. Also, it will return @false if
1598 the timespans are equal in absolute value.
1600 bool IsShorterThan(const wxTimeSpan
& ts
) const;
1603 Returns the timespan for one millisecond.
1605 static wxTimespan
Millisecond();
1608 Returns the timespan for the given number of milliseconds.
1610 static wxTimespan
Milliseconds(long ms
);
1613 Returns the timespan for one minute.
1615 static wxTimespan
Minute();
1618 Returns the timespan for the given number of minutes.
1620 static wxTimespan
Minutes(long min
);
1624 Multiplies timespan by a scalar.
1626 wxTimeSpan
Multiply(int n
);
1627 const wxTimeSpan
& Multiply(int n
);
1628 wxTimeSpan
operator*=(int n
);
1633 Negate the value of the timespan.
1636 wxTimeSpan
operator-();
1640 Returns timespan with inverted sign.
1642 wxTimeSpan
Negate() const;
1660 Returns the timespan for one second.
1662 static wxTimespan
Second();
1665 Returns the timespan for the given number of seconds.
1667 static wxTimespan
Seconds(long sec
);
1698 Returns the difference of two timespans.
1700 wxTimeSpan
Subtract(const wxTimeSpan
& diff
);
1701 const wxTimeSpan
& Subtract(const wxTimeSpan
& diff
);
1702 wxTimeSpan
operator-=(const wxTimeSpan
& diff
);
1721 Returns the timespan for one week.
1723 static wxTimespan
Week();
1726 Returns the timespan for the given number of weeks.
1728 static wxTimespan
Weeks(long weeks
);
1734 @class wxDateTimeHolidayAuthority
1735 @wxheader{datetime.h}
1741 class wxDateTimeHolidayAuthority