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