]> git.saurik.com Git - wxWidgets.git/blame_incremental - interface/datetime.h
Commented out appearance sections in docs temporarily until screenshots are added.
[wxWidgets.git] / interface / datetime.h
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: datetime.h
3// Purpose: interface of wxDateTime
4// Author: wxWidgets team
5// RCS-ID: $Id$
6// Licence: wxWindows license
7/////////////////////////////////////////////////////////////////////////////
8
9/**
10 @class wxDateTime
11 @wxheader{datetime.h}
12
13 wxDateTime class represents an absolute moment in the time.
14
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
17 milliseconds.
18
19
20 @section datetime_constants Constants
21
22 Global constant wxDefaultDateTime and synonym for it wxInvalidDateTime are
23 defined. This constant will be different from any valid wxDateTime object.
24
25 All the following constants are defined inside wxDateTime class (i.e., to
26 refer to them you should prepend their names with "wxDateTime::").
27
28 Time zone symbolic names:
29
30 @code
31 enum TZ
32 {
33 // the time in the current time zone
34 Local,
35
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
39
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,
43 GMT0,
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
48
49 // some symbolic names for TZ
50
51 // Europe
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
60
61 // US and Canada
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
75
76 // Australia
77
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
82
83 // New Zealand
84 NZST = GMT12, // Standard Time
85 NZDT = GMT13, // Daylight Saving Time
86
87 // Universal Coordinated Time = the new and politically correct name
88 // for GMT
89 UTC = GMT0
90 };
91 @endcode
92
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.
95
96 Likewise, Sun, Mon, Tue, Wed, Thu, Fri, Sat, and Inv_WeekDay are the values
97 in @c wxDateTime::WeekDay enum.
98
99 Finally, Inv_Year is defined to be an invalid value for year parameter.
100
101 GetMonthName() and GetWeekDayName() functions use the following flags:
102
103 @code
104 enum NameFlags
105 {
106 Name_Full = 0x01, // return full name
107 Name_Abbr = 0x02 // return abbreviated name
108 };
109 @endcode
110
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:
114
115 @code
116 enum Calendar
117 {
118 Gregorian, // calendar currently in use in Western countries
119 Julian // calendar in use since -45 until the 1582 (or later)
120 };
121 @endcode
122
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:
126
127 @code
128 enum Country
129 {
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
133
134 Country_WesternEurope_Start,
135 Country_EEC = Country_WesternEurope_Start,
136 France,
137 Germany,
138 UK,
139 Country_WesternEurope_End = UK,
140
141 Russia,
142
143 USA
144 };
145 @endcode
146
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
151 GetWeekOfMonth()).
152
153 The desired behvaiour may be specified by giving one of the following
154 constants as argument to these functions:
155
156 @code
157 enum WeekFlags
158 {
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
162 };
163 @endcode
164
165
166 @section datetime_static Static Functions
167
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.
171
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.
175
176 @beginWxPythonOnly
177 These methods are standalone functions named
178 "wxDateTime_<StaticMethodName>" in wxPython.
179 @endWxPythonOnly
180
181
182 @section datetime_formatting Date Formatting and Parsing
183
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()
190 directly.
191
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
199 separate function.
200
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
207 even "next Sunday".
208
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
216 part is returned.
217
218
219 @library{wxbase}
220 @category{data}
221
222 @stdobjects
223 - ::wxDefaultDateTime
224
225 @see @ref overview_datetime, wxTimeSpan, wxDateSpan, wxCalendarCtrl
226*/
227class wxDateTime
228{
229public:
230 /**
231 @name Constructors, Assignment Operators and Setters
232
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.
237 */
238 //@{
239
240 /**
241 Default constructor. Use one of the Set() functions to initialize the
242 object later.
243 */
244 wxDateTime();
245 /**
246 Same as Set().
247
248 @beginWxPythonOnly
249 This constructor is named "wxDateTimeFromTimeT" in wxPython.
250 @endWxPythonOnly
251 */
252 wxDateTime& wxDateTime(time_t timet);
253 /**
254 Same as Set().
255
256 @beginWxPythonOnly Unsupported. @endWxPythonOnly
257 */
258 wxDateTime& wxDateTime(const struct tm& tm);
259 /**
260 Same as Set().
261
262 @beginWxPythonOnly
263 This constructor is named "wxDateTimeFromJDN" in wxPython.
264 @endWxPythonOnly
265 */
266 wxDateTime& wxDateTime(double jdn);
267 /**
268 Same as Set().
269
270 @beginWxPythonOnly
271 This constructor is named "wxDateTimeFromHMS" in wxPython.
272 @endWxPythonOnly
273 */
274 wxDateTime& wxDateTime(wxDateTime_t hour, wxDateTime_t minute = 0,
275 wxDateTime_t second = 0, wxDateTime_t millisec = 0);
276 /**
277 Same as Set().
278
279 @beginWxPythonOnly
280 This constructor is named "wxDateTimeFromDMY" in wxPython.
281 @endWxPythonOnly
282 */
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);
287
288 /**
289 Reset time to midnight (00:00:00) without changing the date.
290 */
291 wxDateTime& ResetTime();
292
293 /**
294 Constructs the object from @a timet value holding the number of seconds
295 since Jan 1, 1970.
296
297 @beginWxPythonOnly
298 This method is named "SetTimeT" in wxPython.
299 @endWxPythonOnly
300 */
301 wxDateTime& Set(time_t timet);
302 /**
303 Sets the date and time from the broken down representation in the
304 standard @a tm structure.
305
306 @beginWxPythonOnly Unsupported. @endWxPythonOnly
307 */
308 wxDateTime& Set(const struct tm& tm);
309 /**
310 Sets the date from the so-called Julian Day Number.
311
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.
316
317 @beginWxPythonOnly
318 This method is named "SetJDN" in wxPython.
319 @endWxPythonOnly
320 */
321 wxDateTime& Set(double jdn);
322 /**
323 Sets the date to be equal to Today() and the time from supplied
324 parameters.
325
326 @beginWxPythonOnly
327 This method is named "SetHMS" in wxPython.
328 @endWxPythonOnly
329 */
330 wxDateTime& Set(wxDateTime_t hour, wxDateTime_t minute = 0,
331 wxDateTime_t second = 0, wxDateTime_t millisec = 0);
332 /**
333 Sets the date and time from the parameters.
334 */
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);
339
340 /**
341 Sets the day without changing other date components.
342 */
343 wxDateTime& SetDay(short unsigned int);
344
345 /**
346 Sets the date from the date and time in DOS format.
347 */
348 wxDateTime& SetFromDOS(unsigned long ddt);
349
350 /**
351 Sets the hour without changing other date components.
352 */
353 wxDateTime& SetHour(short unsigned int);
354
355 /**
356 Sets the millisecond without changing other date components.
357 */
358 wxDateTime& SetMillisecond(short unsigned int);
359
360 /**
361 Sets the minute without changing other date components.
362 */
363 wxDateTime& SetMinute(short unsigned int);
364
365 /**
366 Sets the month without changing other date components.
367 */
368 wxDateTime& SetMonth(Month month);
369
370 /**
371 Sets the second without changing other date components.
372 */
373 wxDateTime& SetSecond(short unsigned int);
374
375 /**
376 Sets the date and time of to the current values. Same as assigning the
377 result of Now() to this object.
378 */
379 wxDateTime& SetToCurrent();
380
381 /**
382 Sets the year without changing other date components.
383 */
384 wxDateTime& SetYear(int year);
385
386 /**
387 Same as Set().
388 */
389 wxDateTime& operator=(time_t timet);
390 /**
391 Same as Set().
392 */
393 wxDateTime& operator=(const struct tm& tm);
394
395 //@}
396
397
398
399 /**
400 @name Accessors
401
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.
405 */
406 //@{
407
408 /**
409 Returns the date and time in DOS format.
410 */
411 long unsigned int GetAsDOS() const;
412
413 /**
414 Returns the century of this date.
415 */
416 int GetCentury(const TimeZone& tz = Local) const;
417
418 /**
419 Returns the object having the same date component as this one but time
420 of 00:00:00.
421
422 @since 2.8.2
423
424 @see ResetTime()
425 */
426 wxDateTime GetDateOnly() const;
427
428 /**
429 Returns the day in the given timezone (local one by default).
430 */
431 short unsigned int GetDay(const TimeZone& tz = Local) const;
432
433 /**
434 Returns the day of the year (in 1-366 range) in the given timezone
435 (local one by default).
436 */
437 short unsigned int GetDayOfYear(const TimeZone& tz = Local) const;
438
439 /**
440 Returns the hour in the given timezone (local one by default).
441 */
442 short unsigned int GetHour(const TimeZone& tz = Local) const;
443
444 /**
445 Returns the milliseconds in the given timezone (local one by default).
446 */
447 short unsigned int GetMillisecond(const TimeZone& tz = Local) const;
448
449 /**
450 Returns the minute in the given timezone (local one by default).
451 */
452 short unsigned int GetMinute(const TimeZone& tz = Local) const;
453
454 /**
455 Returns the month in the given timezone (local one by default).
456 */
457 Month GetMonth(const TimeZone& tz = Local) const;
458
459 /**
460 Returns the seconds in the given timezone (local one by default).
461 */
462 short unsigned int GetSecond(const TimeZone& tz = Local) const;
463
464 /**
465 Returns the number of seconds since Jan 1, 1970. An assert failure will
466 occur if the date is not in the range covered by @c time_t type.
467 */
468 time_t GetTicks() const;
469
470 /**
471 Returns broken down representation of the date and time.
472 */
473 Tm GetTm(const TimeZone& tz = Local) const;
474
475 /**
476 Returns the week day in the given timezone (local one by default).
477 */
478 WeekDay GetWeekDay(const TimeZone& tz = Local) const;
479
480 /**
481 Returns the ordinal number of the week in the month (in 1-5 range).
482
483 As GetWeekOfYear(), this function supports both conventions for the
484 week start. See the description of these @c WeekFlags in the
485 @ref datetime_constants section.
486 */
487 wxDateTime_t GetWeekOfMonth(WeekFlags flags = Monday_First,
488 const TimeZone& tz = Local) const;
489
490 /**
491 Returns the number of the week of the year this date is in. The first
492 week of the year is, according to international standards, the one
493 containing Jan 4 or, equivalently, the first week which has Thursday in
494 this year. Both of these definitions are the same as saying that the
495 first week of the year must contain more than half of its days in this
496 year. Accordingly, the week number will always be in 1-53 range (52 for
497 non-leap years).
498
499 The function depends on the @ref datetime_constants "week start"
500 convention specified by the @a flags argument but its results for
501 @c Sunday_First are not well-defined as the ISO definition quoted above
502 applies to the weeks starting on Monday only.
503 */
504 wxDateTime_t GetWeekOfYear(WeekFlags flags = Monday_First,
505 const TimeZone& tz = Local) const;
506
507 /**
508 Returns the year in the given timezone (local one by default).
509 */
510 int GetYear(const TimeZone& tz = Local) const;
511
512 /**
513 Returns @true if the given date is later than the date of adoption of
514 the Gregorian calendar in the given country (and hence the Gregorian
515 calendar calculations make sense for it).
516 */
517 bool IsGregorianDate(GregorianAdoption country = Gr_Standard) const;
518
519 /**
520 Returns @true if the object represents a valid time moment.
521 */
522 bool IsValid() const;
523
524 /**
525 Returns @true is this day is not a holiday in the given country.
526 */
527 bool IsWorkDay(Country country = Country_Default) const;
528
529 //@}
530
531
532
533 /**
534 @name Date Comparison
535
536 There are several functions to allow date comparison. To supplement
537 them, a few global operators, etc taking wxDateTime are defined.
538 */
539 //@{
540
541 /**
542 Returns @true if this date precedes the given one.
543 */
544 bool IsEarlierThan(const wxDateTime& datetime) const;
545
546 /**
547 Returns @true if the two dates are strictly identical.
548 */
549 bool IsEqualTo(const wxDateTime& datetime) const;
550
551 /**
552 Returns @true if the date is equal to another one up to the given time
553 interval, i.e. if the absolute difference between the two dates is less
554 than this interval.
555 */
556 bool IsEqualUpTo(const wxDateTime& dt, const wxTimeSpan& ts) const;
557
558 /**
559 Returns @true if this date is later than the given one.
560 */
561 bool IsLaterThan(const wxDateTime& datetime) const;
562
563 /**
564 Returns @true if the date is the same without comparing the time parts.
565 */
566 bool IsSameDate(const wxDateTime& dt) const;
567
568 /**
569 Returns @true if the time is the same (although dates may differ).
570 */
571 bool IsSameTime(const wxDateTime& dt) const;
572
573 /**
574 Returns @true if this date lies strictly between the two given dates.
575
576 @see IsBetween()
577 */
578 bool IsStrictlyBetween(const wxDateTime& t1,
579 const wxDateTime& t2) const;
580
581 /**
582 Returns @true if IsStrictlyBetween() is @true or if the date is equal
583 to one of the limit values.
584
585 @see IsStrictlyBetween()
586 */
587 bool IsBetween(const wxDateTime& t1, const wxDateTime& t2) const;
588
589 //@}
590
591
592
593 /**
594 @name Date Arithmetics
595
596 These functions carry out
597 @ref overview_datetime_arithmetics "arithmetics" on the wxDateTime
598 objects. As explained in the overview, either wxTimeSpan or wxDateSpan
599 may be added to wxDateTime, hence all functions are overloaded to
600 accept both arguments.
601
602 Also, both Add() and Subtract() have both const and non-const version.
603 The first one returns a new object which represents the sum/difference
604 of the original one with the argument while the second form modifies
605 the object to which it is applied. The operators "-=" and "+=" are
606 defined to be equivalent to the second forms of these functions.
607 */
608 //@{
609
610 /**
611 Adds the given date span to this object.
612
613 @beginWxPythonOnly
614 This method is named "AddDS" in wxPython.
615 @endWxPythonOnly
616 */
617 wxDateTime Add(const wxDateSpan& diff) const;
618 /**
619 Adds the given date span to this object.
620
621 @beginWxPythonOnly
622 This method is named "AddDS" in wxPython.
623 @endWxPythonOnly
624 */
625 wxDateTime Add(const wxDateSpan& diff);
626 /**
627 Adds the given time span to this object.
628
629 @beginWxPythonOnly
630 This method is named "AddTS" in wxPython.
631 @endWxPythonOnly
632 */
633 wxDateTime Add(const wxTimeSpan& diff) const;
634 /**
635 Adds the given time span to this object.
636
637 @beginWxPythonOnly
638 This method is named "AddTS" in wxPython.
639 @endWxPythonOnly
640 */
641 wxDateTime& Add(const wxTimeSpan& diff);
642
643 /**
644 Subtracts the given time span from this object.
645
646 @beginWxPythonOnly
647 This method is named "SubtractTS" in wxPython.
648 @endWxPythonOnly
649 */
650 wxDateTime Subtract(const wxTimeSpan& diff) const;
651 /**
652 Subtracts the given time span from this object.
653
654 @beginWxPythonOnly
655 This method is named "SubtractTS" in wxPython.
656 @endWxPythonOnly
657 */
658 wxDateTime& Subtract(const wxTimeSpan& diff);
659 /**
660 Subtracts the given date span from this object.
661
662 @beginWxPythonOnly
663 This method is named "SubtractDS" in wxPython.
664 @endWxPythonOnly
665 */
666 wxDateTime Subtract(const wxDateSpan& diff) const;
667 /**
668 Subtracts the given date span from this object.
669
670 @beginWxPythonOnly
671 This method is named "SubtractDS" in wxPython.
672 @endWxPythonOnly
673 */
674 wxDateTime& Subtract(const wxDateSpan& diff);
675 /**
676 Subtracts another date from this one and returns the difference between
677 them as a wxTimeSpan.
678 */
679 wxTimeSpan Subtract(const wxDateTime& dt) const;
680
681 /**
682 Adds the given date span to this object.
683 */
684 wxDateTime operator+=(const wxDateSpan& diff);
685 /**
686 Subtracts the given date span from this object.
687 */
688 wxDateTime& operator-=(const wxDateSpan& diff);
689 /**
690 Adds the given time span to this object.
691 */
692 wxDateTime& operator+=(const wxTimeSpan& diff);
693 /**
694 Subtracts the given time span from this object.
695 */
696 wxDateTime& operator-=(const wxTimeSpan& diff);
697
698 //@}
699
700
701
702 /**
703 @name Date Formatting and Parsing
704
705 See @ref datetime_formatting
706 */
707 //@{
708
709 /**
710 This function does the same as the standard ANSI C @c strftime(3)
711 function. Please see its description for the meaning of @a format
712 parameter.
713
714 It also accepts a few wxWidgets-specific extensions: you can optionally
715 specify the width of the field to follow using @c printf(3)-like syntax
716 and the format specification @c "%l" can be used to get the number of
717 milliseconds.
718
719 @see ParseFormat()
720 */
721 wxString Format(const wxChar* format = wxDefaultDateTimeFormat,
722 const TimeZone& tz = Local) const;
723
724 /**
725 Identical to calling Format() with @c "%x" argument (which means
726 "preferred date representation for the current locale").
727 */
728 wxString FormatDate() const;
729
730 /**
731 Returns the combined date-time representation in the ISO 8601 format
732 @c "YYYY-MM-DDTHH:MM:SS". The @a sep parameter default value produces
733 the result exactly corresponding to the ISO standard, but it can also
734 be useful to use a space as seprator if a more human-readable combined
735 date-time representation is needed.
736
737 @see FormatISODate(), FormatISOTime(), ParseISOCombined()
738 */
739 wxString FormatISOCombined(char sep = 'T') const;
740
741 /**
742 This function returns the date representation in the ISO 8601 format
743 @c "YYYY-MM-DD".
744 */
745 wxString FormatISODate() const;
746
747 /**
748 This function returns the time representation in the ISO 8601 format
749 @c "HH:MM:SS".
750 */
751 wxString FormatISOTime() const;
752
753 /**
754 Identical to calling Format() with @c "%X" argument (which means
755 "preferred time representation for the current locale").
756 */
757 wxString FormatTime() const;
758
759 /**
760 This function is like ParseDateTime(), but it only allows the date to
761 be specified. It is thus less flexible then ParseDateTime(), but also
762 has less chances to misinterpret the user input.
763
764 @returns @NULL if the conversion failed, otherwise return the pointer
765 to the character which stopped the scan.
766 */
767 const char* ParseDate(const wxString& date,
768 wxString::const_iterator* end = NULL);
769 /**
770 This function is like ParseDateTime(), but it only allows the date to
771 be specified. It is thus less flexible then ParseDateTime(), but also
772 has less chances to misinterpret the user input.
773
774 @returns @NULL if the conversion failed, otherwise return the pointer
775 to the character which stopped the scan.
776 */
777 const char* ParseDate(const char* date);
778 /**
779 This function is like ParseDateTime(), but it only allows the date to
780 be specified. It is thus less flexible then ParseDateTime(), but also
781 has less chances to misinterpret the user input.
782
783 @returns @NULL if the conversion failed, otherwise return the pointer
784 to the character which stopped the scan.
785 */
786 const wchar_t* ParseDate(const wchar_t* date);
787
788 /**
789 Parses the string @a datetime containing the date and time in free
790 format. This function tries as hard as it can to interpret the given
791 string as date and time. Unlike ParseRfc822Date(), it will accept
792 anything that may be accepted and will only reject strings which can
793 not be parsed in any way at all.
794
795 @returns @NULL if the conversion failed, otherwise return the pointer
796 to the character which stopped the scan.
797 */
798 const char* ParseDateTime(const wxString& datetime,
799 wxString::const_iterator* end = NULL);
800 /**
801 Parses the string @a datetime containing the date and time in free
802 format. This function tries as hard as it can to interpret the given
803 string as date and time. Unlike ParseRfc822Date(), it will accept
804 anything that may be accepted and will only reject strings which can
805 not be parsed in any way at all.
806
807 @returns @NULL if the conversion failed, otherwise return the pointer
808 to the character which stopped the scan.
809 */
810 const char* ParseDateTime(const char* datetime);
811 /**
812 Parses the string @a datetime containing the date and time in free
813 format. This function tries as hard as it can to interpret the given
814 string as date and time. Unlike ParseRfc822Date(), it will accept
815 anything that may be accepted and will only reject strings which can
816 not be parsed in any way at all.
817
818 @returns @NULL if the conversion failed, otherwise return the pointer
819 to the character which stopped the scan.
820 */
821 const wchar_t* ParseDateTime(const wchar_t* datetime);
822
823 /**
824 This function parses the string @a date according to the given
825 @e format. The system @c strptime(3) function is used whenever
826 available, but even if it is not, this function is still implemented,
827 although support for locale-dependent format specifiers such as
828 @c "%c", @c "%x" or @c "%X" may not be perfect and GNU extensions such
829 as @c "%z" and @c "%Z" are not implemented. This function does handle
830 the month and weekday names in the current locale on all platforms,
831 however.
832
833 Please see the description of the ANSI C function @c strftime(3) for
834 the syntax of the format string.
835
836 The @a dateDef parameter is used to fill in the fields which could not
837 be determined from the format string. For example, if the format is
838 @c "%d" (the day of the month), the month and the year are taken from
839 @a dateDef. If it is not specified, Today() is used as the default
840 date.
841
842 @returns @NULL if the conversion failed, otherwise return the pointer
843 to the character which stopped the scan.
844 */
845 const char* ParseFormat(const wxString& date,
846 const wxString& format = wxDefaultDateTimeFormat,
847 const wxDateTime& dateDef = wxDefaultDateTime,
848 wxString::const_iterator* end = NULL);
849 /**
850 This function parses the string @a date according to the given
851 @e format. The system @c strptime(3) function is used whenever
852 available, but even if it is not, this function is still implemented,
853 although support for locale-dependent format specifiers such as
854 @c "%c", @c "%x" or @c "%X" may not be perfect and GNU extensions such
855 as @c "%z" and @c "%Z" are not implemented. This function does handle
856 the month and weekday names in the current locale on all platforms,
857 however.
858
859 Please see the description of the ANSI C function @c strftime(3) for
860 the syntax of the format string.
861
862 The @a dateDef parameter is used to fill in the fields which could not
863 be determined from the format string. For example, if the format is
864 @c "%d" (the day of the month), the month and the year are taken from
865 @a dateDef. If it is not specified, Today() is used as the default
866 date.
867
868 @returns @NULL if the conversion failed, otherwise return the pointer
869 to the character which stopped the scan.
870 */
871 const char* ParseFormat(const char* date,
872 const wxString& format = wxDefaultDateTimeFormat,
873 const wxDateTime& dateDef = wxDefaultDateTime);
874 /**
875 This function parses the string @a date according to the given
876 @e format. The system @c strptime(3) function is used whenever
877 available, but even if it is not, this function is still implemented,
878 although support for locale-dependent format specifiers such as
879 @c "%c", @c "%x" or @c "%X" may not be perfect and GNU extensions such
880 as @c "%z" and @c "%Z" are not implemented. This function does handle
881 the month and weekday names in the current locale on all platforms,
882 however.
883
884 Please see the description of the ANSI C function @c strftime(3) for
885 the syntax of the format string.
886
887 The @a dateDef parameter is used to fill in the fields which could not
888 be determined from the format string. For example, if the format is
889 @c "%d" (the day of the month), the month and the year are taken from
890 @a dateDef. If it is not specified, Today() is used as the default
891 date.
892
893 @returns @NULL if the conversion failed, otherwise return the pointer
894 to the character which stopped the scan.
895 */
896 const wchar_t* ParseFormat(const wchar_t* date,
897 const wxString& format = wxDefaultDateTimeFormat,
898 const wxDateTime& dateDef = wxDefaultDateTime);
899
900 /**
901 This function parses the string containing the date and time in ISO
902 8601 combined format @c "YYYY-MM-DDTHH:MM:SS". The separator between
903 the date and time parts must be equal to @a sep for the function to
904 succeed.
905
906 @returns @true if the entire string was parsed successfully, @false
907 otherwise.
908 */
909 bool ParseISOCombined(const wxString& date, char sep = 'T');
910
911 /**
912 This function parses the date in ISO 8601 format @c "YYYY-MM-DD".
913
914 @returns @true if the entire string was parsed successfully, @false
915 otherwise.
916 */
917 bool ParseISODate(const wxString& date);
918
919 /**
920 This function parses the time in ISO 8601 format @c "HH:MM:SS".
921
922 @returns @true if the entire string was parsed successfully, @false
923 otherwise.
924 */
925 bool ParseISOTime(const wxString& date);
926
927 /**
928 Parses the string @a date looking for a date formatted according to the
929 RFC 822 in it. The exact description of this format may, of course, be
930 found in the RFC (section 5), but, briefly, this is the format used in
931 the headers of Internet email messages and one of the most common
932 strings expressing date in this format may be something like
933 @c "Sat, 18 Dec 1999 00:48:30 +0100".
934
935 Returns @NULL if the conversion failed, otherwise return the pointer to
936 the character immediately following the part of the string which could
937 be parsed. If the entire string contains only the date in RFC 822
938 format, the returned pointer will be pointing to a @c NUL character.
939
940 This function is intentionally strict, it will return an error for any
941 string which is not RFC 822 compliant. If you need to parse date
942 formatted in more free ways, you should use ParseDateTime() or
943 ParseDate() instead.
944 */
945 const char* ParseRfc822Date(const wxString& date,
946 wxString::const_iterator* end = NULL);
947 /**
948 Parses the string @a date looking for a date formatted according to the
949 RFC 822 in it. The exact description of this format may, of course, be
950 found in the RFC (section 5), but, briefly, this is the format used in
951 the headers of Internet email messages and one of the most common
952 strings expressing date in this format may be something like
953 @c "Sat, 18 Dec 1999 00:48:30 +0100".
954
955 Returns @NULL if the conversion failed, otherwise return the pointer to
956 the character immediately following the part of the string which could
957 be parsed. If the entire string contains only the date in RFC 822
958 format, the returned pointer will be pointing to a @c NUL character.
959
960 This function is intentionally strict, it will return an error for any
961 string which is not RFC 822 compliant. If you need to parse date
962 formatted in more free ways, you should use ParseDateTime() or
963 ParseDate() instead.
964 */
965 const char* ParseRfc822Date(const char* date);
966 /**
967 Parses the string @a date looking for a date formatted according to the
968 RFC 822 in it. The exact description of this format may, of course, be
969 found in the RFC (section 5), but, briefly, this is the format used in
970 the headers of Internet email messages and one of the most common
971 strings expressing date in this format may be something like
972 @c "Sat, 18 Dec 1999 00:48:30 +0100".
973
974 Returns @NULL if the conversion failed, otherwise return the pointer to
975 the character immediately following the part of the string which could
976 be parsed. If the entire string contains only the date in RFC 822
977 format, the returned pointer will be pointing to a @c NUL character.
978
979 This function is intentionally strict, it will return an error for any
980 string which is not RFC 822 compliant. If you need to parse date
981 formatted in more free ways, you should use ParseDateTime() or
982 ParseDate() instead.
983 */
984 const wchar_t* ParseRfc822Date(const wchar_t* date);
985
986 /**
987 This functions is like ParseDateTime(), but only allows the time to be
988 specified in the input string.
989
990 @returns @NULL if the conversion failed, otherwise return the pointer
991 to the character which stopped the scan.
992 */
993 const char* ParseTime(const wxString& time,
994 wxString::const_iterator* end = NULL);
995 /**
996 This functions is like ParseDateTime(), but only allows the time to be
997 specified in the input string.
998
999 @returns @NULL if the conversion failed, otherwise return the pointer
1000 to the character which stopped the scan.
1001 */
1002 const char* ParseTime(const char* time);
1003 /**
1004 This functions is like ParseDateTime(), but only allows the time to be
1005 specified in the input string.
1006
1007 @returns @NULL if the conversion failed, otherwise return the pointer
1008 to the character which stopped the scan.
1009 */
1010 const wchar_t* ParseTime(const wchar_t* time);
1011
1012 //@}
1013
1014
1015
1016 /**
1017 @name Calendar Calculations
1018
1019 The functions in this section perform the basic calendar calculations,
1020 mostly related to the week days. They allow to find the given week day
1021 in the week with given number (either in the month or in the year) and
1022 so on.
1023
1024 None of the functions in this section modify the time part of the
1025 wxDateTime, they only work with the date part of it.
1026 */
1027 //@{
1028
1029 /**
1030 Returns the copy of this object to which SetToLastMonthDay() was
1031 applied.
1032 */
1033 wxDateTime GetLastMonthDay(Month month = Inv_Month,
1034 int year = Inv_Year) const;
1035
1036 /**
1037 Returns the copy of this object to which SetToLastWeekDay() was
1038 applied.
1039 */
1040 wxDateTime GetLastWeekDay(WeekDay weekday, Month month = Inv_Month,
1041 int year = Inv_Year);
1042
1043 /**
1044 Returns the copy of this object to which SetToNextWeekDay() was
1045 applied.
1046 */
1047 wxDateTime GetNextWeekDay(WeekDay weekday) const;
1048
1049 /**
1050 Returns the copy of this object to which SetToPrevWeekDay() was
1051 applied.
1052 */
1053 wxDateTime GetPrevWeekDay(WeekDay weekday) const;
1054
1055 /**
1056 Returns the copy of this object to which SetToWeekDay() was applied.
1057 */
1058 wxDateTime GetWeekDay(WeekDay weekday, int n = 1, Month month = Inv_Month,
1059 int year = Inv_Year) const;
1060
1061 /**
1062 Returns the copy of this object to which SetToWeekDayInSameWeek() was
1063 applied.
1064 */
1065 wxDateTime GetWeekDayInSameWeek(WeekDay weekday,
1066 WeekFlags flags = Monday_First) const;
1067
1068 /**
1069 Returns the copy of this object to which SetToYearDay() was applied.
1070 */
1071 wxDateTime GetYearDay(wxDateTime_t yday) const;
1072
1073 /**
1074 Sets the date to the last day in the specified month (the current one
1075 by default).
1076
1077 @returns The reference to the modified object itself.
1078 */
1079 wxDateTime SetToLastMonthDay(Month month = Inv_Month,
1080 int year = Inv_Year);
1081
1082 /**
1083 The effect of calling this function is the same as of calling
1084 @c SetToWeekDay(-1, weekday, month, year). The date will be set to the
1085 last @a weekday in the given month and year (the current ones by
1086 default). Always returns @true.
1087 */
1088 bool SetToLastWeekDay(WeekDay weekday, Month month = Inv_Month,
1089 int year = Inv_Year);
1090
1091 /**
1092 Sets the date so that it will be the first @a weekday following the
1093 current date.
1094
1095 @returns The reference to the modified object itself.
1096 */
1097 wxDateTime& SetToNextWeekDay(WeekDay weekday);
1098
1099 /**
1100 Sets the date so that it will be the last @a weekday before the current
1101 date.
1102
1103 @returns The reference to the modified object itself.
1104 */
1105 wxDateTime& SetToPrevWeekDay(WeekDay weekday);
1106
1107 /**
1108 Sets the date to the @e n-th @a weekday in the given month of the given
1109 year (the current month and year are used by default). The parameter
1110 @a n may be either positive (counting from the beginning of the month)
1111 or negative (counting from the end of it).
1112
1113 For example, SetToWeekDay(2, wxDateTime::Wed) will set the date to the
1114 second Wednesday in the current month and
1115 SetToWeekDay(-1, wxDateTime::Sun) will set the date to the last Sunday
1116 in the current month.
1117
1118 @returns @true if the date was modified successfully, @false otherwise
1119 meaning that the specified date doesn't exist.
1120 */
1121 bool SetToWeekDay(WeekDay weekday, int n = 1,
1122 Month month = Inv_Month, int year = Inv_Year);
1123
1124 /**
1125 Adjusts the date so that it will still lie in the same week as before,
1126 but its week day will be the given one.
1127
1128 @returns The reference to the modified object itself.
1129 */
1130 wxDateTime SetToWeekDayInSameWeek(WeekDay weekday,
1131 WeekFlags flags = Monday_First);
1132
1133 /**
1134 Sets the date to the day number @a yday in the same year (i.e., unlike
1135 the other functions, this one does not use the current year). The day
1136 number should be in the range 1-366 for the leap years and 1-365 for
1137 the other ones.
1138
1139 @returns The reference to the modified object itself.
1140 */
1141 wxDateTime& SetToYearDay(wxDateTime_t yday);
1142
1143 //@}
1144
1145
1146
1147 /**
1148 @name Astronomical/Historical Functions
1149
1150 Some degree of support for the date units used in astronomy and/or
1151 history is provided. You can construct a wxDateTime object from a
1152 JDN and you may also get its JDN, MJD or Rata Die number from it.
1153
1154 Related functions in other groups: wxDateTime(double), Set(double)
1155 */
1156 //@{
1157
1158 /**
1159 Synonym for GetJulianDayNumber().
1160 */
1161 double GetJDN() const;
1162
1163 /**
1164 Returns the JDN corresponding to this date. Beware of rounding errors!
1165
1166 @see GetModifiedJulianDayNumber()
1167 */
1168 double GetJulianDayNumber() const;
1169
1170 /**
1171 Synonym for GetModifiedJulianDayNumber().
1172 */
1173 double GetMJD() const;
1174
1175 /**
1176 Returns the @e "Modified Julian Day Number" (MJD) which is, by
1177 definition, is equal to JDN - 2400000.5. The MJDs are simpler to work
1178 with as the integral MJDs correspond to midnights of the dates in the
1179 Gregorian calendar and not the noons like JDN. The MJD 0 represents
1180 Nov 17, 1858.
1181 */
1182 double GetModifiedJulianDayNumber() const;
1183
1184 /**
1185 Return the @e Rata Die number of this date.
1186
1187 By definition, the Rata Die number is a date specified as the number of
1188 days relative to a base date of December 31 of the year 0. Thus January
1189 1 of the year 1 is Rata Die day 1.
1190 */
1191 double GetRataDie() const;
1192
1193 //@}
1194
1195
1196
1197 /**
1198 @name Time Zone and DST Support
1199
1200 Please see the @ref overview_datetime_timezones "time zone overview"
1201 for more information about time zones. Normally, these functions should
1202 be rarely used.
1203
1204 Related functions in other groups: GetBeginDST(), GetEndDST()
1205 */
1206 //@{
1207
1208 /**
1209 Transform the date from the given time zone to the local one. If
1210 @a noDST is @true, no DST adjustments will be made.
1211
1212 @returns The date in the local time zone.
1213 */
1214 wxDateTime FromTimezone(const TimeZone& tz, bool noDST = false) const;
1215
1216 /**
1217 Returns @true if the DST is applied for this date in the given country.
1218
1219 @see GetBeginDST(), GetEndDST()
1220 */
1221 int IsDST(Country country = Country_Default) const;
1222
1223 /**
1224 Same as FromTimezone() but modifies the object in place.
1225 */
1226 wxDateTime MakeFromTimezone(const TimeZone& tz, bool noDST = false);
1227
1228 /**
1229 Modifies the object in place to represent the date in another time
1230 zone. If @a noDST is @true, no DST adjustments will be made.
1231 */
1232 wxDateTime MakeTimezone(const TimeZone& tz, bool noDST = false);
1233
1234 /**
1235 This is the same as calling MakeTimezone() with the argument @c GMT0.
1236 */
1237 wxDateTime& MakeUTC(bool noDST = false);
1238
1239 /**
1240 Transform the date to the given time zone. If @a noDST is @true, no DST
1241 adjustments will be made.
1242
1243 @returns The date in the new time zone.
1244 */
1245 wxDateTime ToTimezone(const TimeZone& tz, bool noDST = false) const;
1246
1247 /**
1248 This is the same as calling ToTimezone() with the argument @c GMT0.
1249 */
1250 wxDateTime ToUTC(bool noDST = false) const;
1251
1252 //@}
1253
1254
1255
1256
1257
1258 /**
1259 Converts the year in absolute notation (i.e. a number which can be
1260 negative, positive or zero) to the year in BC/AD notation. For the
1261 positive years, nothing is done, but the year 0 is year 1 BC and so for
1262 other years there is a difference of 1.
1263
1264 This function should be used like this:
1265
1266 @code
1267 wxDateTime dt(...);
1268 int y = dt.GetYear();
1269 printf("The year is %d%s", wxDateTime::ConvertYearToBC(y), y > 0 ? "AD" : "BC");
1270 @endcode
1271 */
1272 static int ConvertYearToBC(int year);
1273
1274 /**
1275 Returns the translations of the strings @c AM and @c PM used for time
1276 formatting for the current locale. Either of the pointers may be @NULL
1277 if the corresponding value is not needed.
1278 */
1279 static void GetAmPmStrings(wxString* am, wxString* pm);
1280
1281 /**
1282 Get the beginning of DST for the given country in the given year
1283 (current one by default). This function suffers from limitations
1284 described in the @ref overview_datetime_dst "DST overview".
1285
1286 @see GetEndDST()
1287 */
1288 static wxDateTime GetBeginDST(int year = Inv_Year,
1289 Country country = Country_Default);
1290
1291 /**
1292 Returns the end of DST for the given country in the given year (current
1293 one by default).
1294
1295 @see GetBeginDST()
1296 */
1297 static wxDateTime GetEndDST(int year = Inv_Year,
1298 Country country = Country_Default);
1299
1300 /**
1301 Get the current century, i.e. first two digits of the year, in given
1302 calendar (only Gregorian is currently supported).
1303 */
1304 static int GetCentury(int year);
1305
1306 /**
1307 Returns the current default country. The default country is used for
1308 DST calculations, for example.
1309
1310 @see SetCountry()
1311 */
1312 static Country GetCountry();
1313
1314 /**
1315 Get the current month in given calendar (only Gregorian is currently
1316 supported).
1317 */
1318 static Month GetCurrentMonth(Calendar cal = Gregorian);
1319
1320 /**
1321 Get the current year in given calendar (only Gregorian is currently
1322 supported).
1323 */
1324 static int GetCurrentYear(Calendar cal = Gregorian);
1325
1326 /**
1327 Gets the full (default) or abbreviated (specify @c Name_Abbr name of
1328 the given month.
1329
1330 @see GetWeekDayName()
1331 */
1332 static wxString GetMonthName(Month month, NameFlags flags = Name_Full);
1333
1334 /**
1335 Returns the number of days in the given year. The only supported value
1336 for @a cal currently is @c Gregorian.
1337
1338 @beginWxPythonOnly
1339 This method is named "GetNumberOfDaysInYear" in wxPython.
1340 @endWxPythonOnly
1341 */
1342 static wxDateTime_t GetNumberOfDays(int year, Calendar cal = Gregorian);
1343
1344 /**
1345 Returns the number of days in the given month of the given year. The
1346 only supported value for @a cal currently is @c Gregorian.
1347
1348 @beginWxPythonOnly
1349 This method is named "GetNumberOfDaysInMonth" in wxPython.
1350 @endWxPythonOnly
1351 */
1352 static wxDateTime_t GetNumberOfDays(Month month, int year = Inv_Year,
1353 Calendar cal = Gregorian);
1354
1355 /**
1356 Returns the current time.
1357 */
1358 static time_t GetTimeNow();
1359
1360 /**
1361 Returns the current time broken down using the buffer whose adress is
1362 passed to the function with @a tm to store the result.
1363 */
1364 static struct tm* GetTmNow(struct tm *tm);
1365
1366 /**
1367 Returns the current time broken down. Note that this function returns a
1368 pointer to a static buffer that's reused by calls to this function and
1369 certain C library functions (e.g. localtime). If there is any chance
1370 your code might be used in a multi-threaded application, you really
1371 should use GetTmNow(struct tm *) instead.
1372 */
1373 static struct tm* GetTmNow();
1374
1375 /**
1376 Gets the full (default) or abbreviated (specify @c Name_Abbr) name of
1377 the given week day.
1378
1379 @see GetMonthName()
1380 */
1381 static wxString GetWeekDayName(WeekDay weekday,
1382 NameFlags flags = Name_Full);
1383
1384 /**
1385 Returns @true if DST was used n the given year (the current one by
1386 default) in the given country.
1387 */
1388 static bool IsDSTApplicable(int year = Inv_Year,
1389 Country country = Country_Default);
1390
1391 /**
1392 Returns @true if the @a year is a leap one in the specified calendar.
1393 This functions supports Gregorian and Julian calendars.
1394 */
1395 static bool IsLeapYear(int year = Inv_Year, Calendar cal = Gregorian);
1396
1397 /**
1398 This function returns @true if the specified (or default) country is
1399 one of Western European ones. It is used internally by wxDateTime to
1400 determine the DST convention and date and time formatting rules.
1401 */
1402 static bool IsWestEuropeanCountry(Country country = Country_Default);
1403
1404 /**
1405 Returns the object corresponding to the current time.
1406
1407 Example:
1408
1409 @code
1410 wxDateTime now = wxDateTime::Now();
1411 printf("Current time in Paris:\t%s\n", now.Format("%c", wxDateTime::CET).c_str());
1412 @endcode
1413
1414 @note This function is accurate up to seconds. UNow() should be used
1415 for better precision, but it is less efficient and might not be
1416 available on all platforms.
1417
1418 @see Today()
1419 */
1420 static wxDateTime Now();
1421
1422 /**
1423 Sets the country to use by default. This setting influences the DST
1424 calculations, date formatting and other things.
1425
1426 The possible values for @a country parameter are enumerated in the
1427 @ref datetime_constants section.
1428
1429 @see GetCountry()
1430 */
1431 static void SetCountry(Country country);
1432
1433 /**
1434 Set the date to the given @a weekday in the week number @a numWeek of
1435 the given @a year . The number should be in range 1-53.
1436
1437 Note that the returned date may be in a different year than the one
1438 passed to this function because both the week 1 and week 52 or 53 (for
1439 leap years) contain days from different years. See GetWeekOfYear() for
1440 the explanation of how the year weeks are counted.
1441 */
1442 static wxDateTime SetToWeekOfYear(int year, wxDateTime_t numWeek,
1443 WeekDay weekday = Mon);
1444
1445 /**
1446 Returns the object corresponding to the midnight of the current day
1447 (i.e. the same as Now(), but the time part is set to 0).
1448
1449 @see Now()
1450 */
1451 static wxDateTime Today();
1452
1453 /**
1454 Returns the object corresponding to the current time including the
1455 milliseconds if a function to get time with such precision is available
1456 on the current platform (supported under most Unices and Win32).
1457
1458 @see Now()
1459 */
1460 static wxDateTime UNow();
1461};
1462
1463/**
1464 Global instance of an empty wxDateTime object.
1465
1466 @todo Would it be better to rename this wxNullDateTime so it's consistent
1467 with the rest of the "empty/invalid/null" global objects?
1468*/
1469const wxDateTime wxDefaultDateTime;
1470
1471
1472
1473/**
1474 @class wxDateTimeWorkDays
1475 @wxheader{datetime.h}
1476
1477 @todo Write wxDateTimeWorkDays documentation.
1478
1479 @library{wxbase}
1480 @category{data}
1481*/
1482class wxDateTimeWorkDays
1483{
1484public:
1485
1486};
1487
1488
1489
1490/**
1491 @class wxDateSpan
1492 @wxheader{datetime.h}
1493
1494 This class is a "logical time span" and is useful for implementing program
1495 logic for such things as "add one month to the date" which, in general,
1496 doesn't mean to add 60*60*24*31 seconds to it, but to take the same date
1497 the next month (to understand that this is indeed different consider adding
1498 one month to Feb, 15 -- we want to get Mar, 15, of course).
1499
1500 When adding a month to the date, all lesser components (days, hours, ...)
1501 won't be changed unless the resulting date would be invalid: for example,
1502 Jan 31 + 1 month will be Feb 28, not (non-existing) Feb 31.
1503
1504 Because of this feature, adding and subtracting back again the same
1505 wxDateSpan will @b not, in general, give back the original date: Feb 28 - 1
1506 month will be Jan 28, not Jan 31!
1507
1508 wxDateSpan objects can be either positive or negative. They may be
1509 multiplied by scalars which multiply all deltas by the scalar: i.e.
1510 2*(1 month and 1 day) is 2 months and 2 days. They can be added together
1511 with wxDateTime or wxTimeSpan, but the type of result is different for each
1512 case.
1513
1514 @warning If you specify both weeks and days, the total number of days added
1515 will be 7*weeks + days! See also GetTotalDays().
1516
1517 Equality operators are defined for wxDateSpans. Two wxDateSpans are equal
1518 if and only if they both give the same target date when added to @b every
1519 source date. Thus wxDateSpan::Months(1) is not equal to
1520 wxDateSpan::Days(30), because they don't give the same date when added to
1521 Feb 1st. But wxDateSpan::Days(14) is equal to wxDateSpan::Weeks(2).
1522
1523 Finally, notice that for adding hours, minutes and so on you don't need
1524 this class at all: wxTimeSpan will do the job because there are no
1525 subtleties associated with those (we don't support leap seconds).
1526
1527 @library{wxbase}
1528 @category{data}
1529
1530 @see @ref overview_datetime, wxDateTime
1531*/
1532class wxDateSpan
1533{
1534public:
1535 /**
1536 Constructs the date span object for the given number of years, months,
1537 weeks and days. Note that the weeks and days add together if both are
1538 given.
1539 */
1540 wxDateSpan(int years = 0, int months = 0, int weeks = 0, int days = 0);
1541
1542 /**
1543 Returns the sum of two date spans.
1544
1545 @returns A new wxDateSpan object with the result.
1546 */
1547 wxDateSpan Add(const wxDateSpan& other) const;
1548 /**
1549 Adds the given wxDateSpan to this wxDateSpan and returns a reference
1550 to itself.
1551 */
1552 wxDateSpan& Add(const wxDateSpan& other);
1553
1554 /**
1555 Returns a date span object corresponding to one day.
1556
1557 @see Days()
1558 */
1559 static wxDateSpan Day();
1560
1561 /**
1562 Returns a date span object corresponding to the given number of days.
1563
1564 @see Day()
1565 */
1566 static wxDateSpan Days(int days);
1567
1568 /**
1569 Returns the number of days (not counting the weeks component) in this
1570 date span.
1571
1572 @see GetTotalDays()
1573 */
1574 int GetDays() const;
1575
1576 /**
1577 Returns the number of the months (not counting the years) in this date
1578 span.
1579 */
1580 int GetMonths() const;
1581
1582 /**
1583 Returns the combined number of days in this date span, counting both
1584 weeks and days. This doesn't take months or years into account.
1585
1586 @see GetWeeks(), GetDays()
1587 */
1588 int GetTotalDays() const;
1589
1590 /**
1591 Returns the number of weeks in this date span.
1592
1593 @see GetTotalDays()
1594 */
1595 int GetWeeks() const;
1596
1597 /**
1598 Returns the number of years in this date span.
1599 */
1600 int GetYears() const;
1601
1602 /**
1603 Returns a date span object corresponding to one month.
1604
1605 @see Months()
1606 */
1607 static wxDateSpan Month();
1608
1609 /**
1610 Returns a date span object corresponding to the given number of months.
1611
1612 @see Month()
1613 */
1614 static wxDateSpan Months(int mon);
1615
1616 /**
1617 Returns the product of the date span by the specified @a factor. The
1618 product is computed by multiplying each of the components by the
1619 @a factor.
1620
1621 @returns A new wxDateSpan object with the result.
1622 */
1623 wxDateSpan Multiply(int factor) const;
1624 /**
1625 Multiplies this date span by the specified @a factor. The product is
1626 computed by multiplying each of the components by the @a factor.
1627
1628 @returns A reference to this wxDateSpan object modified in place.
1629 */
1630 wxDateSpan& Multiply(int factor);
1631
1632 /**
1633 Changes the sign of this date span.
1634
1635 @see Negate()
1636 */
1637 wxDateSpan& Neg();
1638
1639 /**
1640 Returns a date span with the opposite sign.
1641
1642 @see Neg()
1643 */
1644 wxDateSpan Negate() const;
1645
1646 /**
1647 Sets the number of days (without modifying any other components) in
1648 this date span.
1649 */
1650 wxDateSpan& SetDays(int n);
1651
1652 /**
1653 Sets the number of months (without modifying any other components) in
1654 this date span.
1655 */
1656 wxDateSpan& SetMonths(int n);
1657
1658 /**
1659 Sets the number of weeks (without modifying any other components) in
1660 this date span.
1661 */
1662 wxDateSpan& SetWeeks(int n);
1663
1664 /**
1665 Sets the number of years (without modifying any other components) in
1666 this date span.
1667 */
1668 wxDateSpan& SetYears(int n);
1669
1670 /**
1671 Returns the difference of two date spans.
1672
1673 @returns A new wxDateSpan object with the result.
1674 */
1675 wxDateSpan Subtract(const wxDateSpan& other) const;
1676 /**
1677 Subtracts the given wxDateSpan to this wxDateSpan and returns a
1678 reference to itself.
1679 */
1680 wxDateSpan& Subtract(const wxDateSpan& other);
1681
1682 /**
1683 Returns a date span object corresponding to one week.
1684
1685 @see Weeks()
1686 */
1687 static wxDateSpan Week();
1688
1689 /**
1690 Returns a date span object corresponding to the given number of weeks.
1691
1692 @see Week()
1693 */
1694 static wxDateSpan Weeks(int weeks);
1695
1696 /**
1697 Returns a date span object corresponding to one year.
1698
1699 @see Years()
1700 */
1701 static wxDateSpan Year();
1702
1703 /**
1704 Returns a date span object corresponding to the given number of years.
1705
1706 @see Year()
1707 */
1708 static wxDateSpan Years(int years);
1709
1710 /**
1711 Adds the given wxDateSpan to this wxDateSpan and returns the result.
1712 */
1713 wxDateSpan& operator+=(const wxDateSpan& other);
1714
1715 /**
1716 Subtracts the given wxDateSpan to this wxDateSpan and returns the
1717 result.
1718 */
1719 wxDateSpan& operator-=(const wxDateSpan& other);
1720
1721 /**
1722 Changes the sign of this date span.
1723
1724 @see Negate()
1725 */
1726 wxDateSpan& operator-();
1727
1728 /**
1729 Multiplies this date span by the specified @a factor. The product is
1730 computed by multiplying each of the components by the @a factor.
1731
1732 @returns A reference to this wxDateSpan object modified in place.
1733 */
1734 wxDateSpan& operator*=(int factor);
1735
1736 /**
1737 Returns @true if this date span is different from the other one.
1738 */
1739 bool operator!=(const wxDateSpan&) const;
1740
1741 /**
1742 Returns @true if this date span is equal to the other one. Two date
1743 spans are considered equal if and only if they have the same number of
1744 years and months and the same total number of days (counting both days
1745 and weeks).
1746 */
1747 bool operator==(const wxDateSpan&) const;
1748};
1749
1750
1751
1752/**
1753 @class wxTimeSpan
1754 @wxheader{datetime.h}
1755
1756 wxTimeSpan class represents a time interval.
1757
1758 @library{wxbase}
1759 @category{data}
1760
1761 @see @ref overview_datetime, wxDateTime
1762*/
1763class wxTimeSpan
1764{
1765public:
1766 /**
1767 Default constructor, constructs a zero timespan.
1768 */
1769 wxTimeSpan();
1770 /**
1771 Constructs timespan from separate values for each component, with the
1772 date set to 0. Hours are not restricted to 0-24 range, neither are
1773 minutes, seconds or milliseconds.
1774 */
1775 wxTimeSpan(long hours, long min, long sec, long msec);
1776
1777 /**
1778 Returns the absolute value of the timespan: does not modify the object.
1779 */
1780 wxTimeSpan Abs() const;
1781
1782 /**
1783 Returns the sum of two time spans.
1784
1785 @returns A new wxDateSpan object with the result.
1786 */
1787 wxTimeSpan Add(const wxTimeSpan& diff) const;
1788 /**
1789 Adds the given wxTimeSpan to this wxTimeSpan and returns a reference
1790 to itself.
1791 */
1792 wxTimeSpan& Add(const wxTimeSpan& diff);
1793
1794 /**
1795 Returns the timespan for one day.
1796 */
1797 static wxTimespan Day();
1798
1799 /**
1800 Returns the timespan for the given number of days.
1801 */
1802 static wxTimespan Days(long days);
1803
1804 /**
1805 Returns the string containing the formatted representation of the time
1806 span. The following format specifiers are allowed after %:
1807
1808 - @c H - Number of Hours
1809 - @c M - Number of Minutes
1810 - @c S - Number of Seconds
1811 - @c l - Number of Milliseconds
1812 - @c D - Number of Days
1813 - @c E - Number of Weeks
1814 - @c % - The percent character
1815
1816 Note that, for example, the number of hours in the description above is
1817 not well defined: it can be either the total number of hours (for
1818 example, for a time span of 50 hours this would be 50) or just the hour
1819 part of the time span, which would be 2 in this case as 50 hours is
1820 equal to 2 days and 2 hours.
1821
1822 wxTimeSpan resolves this ambiguity in the following way: if there had
1823 been, indeed, the @c %D format specified preceding the @c %H, then it
1824 is interpreted as 2. Otherwise, it is 50.
1825
1826 The same applies to all other format specifiers: if they follow a
1827 specifier of larger unit, only the rest part is taken, otherwise the
1828 full value is used.
1829 */
1830 wxString Format(const wxString& = wxDefaultTimeSpanFormat) const;
1831
1832 /**
1833 Returns the difference in number of days.
1834 */
1835 int GetDays() const;
1836
1837 /**
1838 Returns the difference in number of hours.
1839 */
1840 int GetHours() const;
1841
1842 /**
1843 Returns the difference in number of milliseconds.
1844 */
1845 wxLongLong GetMilliseconds() const;
1846
1847 /**
1848 Returns the difference in number of minutes.
1849 */
1850 int GetMinutes() const;
1851
1852 /**
1853 Returns the difference in number of seconds.
1854 */
1855 wxLongLong GetSeconds() const;
1856
1857 /**
1858 Returns the internal representation of timespan.
1859 */
1860 wxLongLong GetValue() const;
1861
1862 /**
1863 Returns the difference in number of weeks.
1864 */
1865 int GetWeeks() const;
1866
1867 /**
1868 Returns the timespan for one hour.
1869 */
1870 static wxTimespan Hour();
1871
1872 /**
1873 Returns the timespan for the given number of hours.
1874 */
1875 static wxTimespan Hours(long hours);
1876
1877 /**
1878 Returns @true if two timespans are equal.
1879 */
1880 bool IsEqualTo(const wxTimeSpan& ts) const;
1881
1882 /**
1883 Compares two timespans: works with the absolute values, i.e. -2 hours
1884 is longer than 1 hour. Also, it will return @false if the timespans are
1885 equal in absolute value.
1886 */
1887 bool IsLongerThan(const wxTimeSpan& ts) const;
1888
1889 /**
1890 Returns @true if the timespan is negative.
1891 */
1892 bool IsNegative() const;
1893
1894 /**
1895 Returns @true if the timespan is empty.
1896 */
1897 bool IsNull() const;
1898
1899 /**
1900 Returns @true if the timespan is positive.
1901 */
1902 bool IsPositive() const;
1903
1904 /**
1905 Compares two timespans: works with the absolute values, i.e. 1 hour is
1906 shorter than -2 hours. Also, it will return @false if the timespans are
1907 equal in absolute value.
1908 */
1909 bool IsShorterThan(const wxTimeSpan& ts) const;
1910
1911 /**
1912 Returns the timespan for one millisecond.
1913 */
1914 static wxTimespan Millisecond();
1915
1916 /**
1917 Returns the timespan for the given number of milliseconds.
1918 */
1919 static wxTimespan Milliseconds(long ms);
1920
1921 /**
1922 Returns the timespan for one minute.
1923 */
1924 static wxTimespan Minute();
1925
1926 /**
1927 Returns the timespan for the given number of minutes.
1928 */
1929 static wxTimespan Minutes(long min);
1930
1931 /**
1932 Returns the product of this time span by @a n.
1933
1934 @returns A new wxTimeSpan object with the result.
1935 */
1936 wxTimeSpan Multiply(int n) const;
1937 /**
1938 Multiplies this time span by @a n.
1939
1940 @returns A reference to this wxTimeSpan object modified in place.
1941 */
1942 wxTimeSpan& Multiply(int n);
1943
1944 /**
1945 Negate the value of the timespan.
1946
1947 @see Negate()
1948 */
1949 wxTimeSpan& Neg();
1950
1951 /**
1952 Returns timespan with inverted sign.
1953
1954 @see Neg()
1955 */
1956 wxTimeSpan Negate() const;
1957
1958 /**
1959 Returns the timespan for one second.
1960 */
1961 static wxTimespan Second();
1962
1963 /**
1964 Returns the timespan for the given number of seconds.
1965 */
1966 static wxTimespan Seconds(long sec);
1967
1968 /**
1969 Returns the difference of two time spans.
1970
1971 @returns A new wxDateSpan object with the result.
1972 */
1973 wxTimeSpan Subtract(const wxTimeSpan& diff) const;
1974 /**
1975 Subtracts the given wxTimeSpan to this wxTimeSpan and returns a
1976 reference to itself.
1977 */
1978 wxTimeSpan& Subtract(const wxTimeSpan& diff);
1979
1980 /**
1981 Returns the timespan for one week.
1982 */
1983 static wxTimespan Week();
1984
1985 /**
1986 Returns the timespan for the given number of weeks.
1987 */
1988 static wxTimespan Weeks(long weeks);
1989
1990 /**
1991 Adds the given wxTimeSpan to this wxTimeSpan and returns the result.
1992 */
1993 wxTimeSpan& operator+=(const wxTimeSpan& diff);
1994
1995 /**
1996 Multiplies this time span by @a n.
1997
1998 @returns A reference to this wxTimeSpan object modified in place.
1999 */
2000 wxTimeSpan& operator*=(int n);
2001
2002 /**
2003 Negate the value of the timespan.
2004
2005 @see Negate()
2006 */
2007 wxTimeSpan& operator-();
2008
2009 /**
2010 Subtracts the given wxTimeSpan to this wxTimeSpan and returns the
2011 result.
2012 */
2013 wxTimeSpan& operator-=(const wxTimeSpan& diff);
2014};
2015
2016
2017
2018/**
2019 @class wxDateTimeHolidayAuthority
2020 @wxheader{datetime.h}
2021
2022 @todo Write wxDateTimeHolidayAuthority documentation.
2023
2024 @library{wxbase}
2025 @category{misc}
2026*/
2027class wxDateTimeHolidayAuthority
2028{
2029public:
2030
2031};
2032