]> git.saurik.com Git - wxWidgets.git/blob - interface/wx/datetime.h
f0751079373fb244f24755fc9add289b48a20720
[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.
531 */
532 wxDateTime_t GetWeekOfMonth(WeekFlags flags = Monday_First,
533 const TimeZone& tz = Local) const;
534
535 /**
536 Returns the number of the week of the year this date is in. The first
537 week of the year is, according to international standards, the one
538 containing Jan 4 or, equivalently, the first week which has Thursday in
539 this year. Both of these definitions are the same as saying that the
540 first week of the year must contain more than half of its days in this
541 year. Accordingly, the week number will always be in 1-53 range (52 for
542 non-leap years).
543
544 The function depends on the week start convention specified by the @a flags
545 argument but its results for @c Sunday_First are not well-defined as the
546 ISO definition quoted above applies to the weeks starting on Monday only.
547 */
548 wxDateTime_t GetWeekOfYear(WeekFlags flags = Monday_First,
549 const TimeZone& tz = Local) const;
550
551 /**
552 Returns the year in the given timezone (local one by default).
553 */
554 int GetYear(const TimeZone& tz = Local) const;
555
556 /**
557 Returns @true if the given date is later than the date of adoption of
558 the Gregorian calendar in the given country (and hence the Gregorian
559 calendar calculations make sense for it).
560 */
561 bool IsGregorianDate(GregorianAdoption country = Gr_Standard) const;
562
563 /**
564 Returns @true if the object represents a valid time moment.
565 */
566 bool IsValid() const;
567
568 /**
569 Returns @true is this day is not a holiday in the given country.
570 */
571 bool IsWorkDay(Country country = Country_Default) const;
572
573 //@}
574
575
576
577 /**
578 @name Date Comparison
579
580 There are several functions to allow date comparison. To supplement
581 them, a few global operators, etc taking wxDateTime are defined.
582 */
583 //@{
584
585 /**
586 Returns @true if this date precedes the given one.
587 */
588 bool IsEarlierThan(const wxDateTime& datetime) const;
589
590 /**
591 Returns @true if the two dates are strictly identical.
592 */
593 bool IsEqualTo(const wxDateTime& datetime) const;
594
595 /**
596 Returns @true if the date is equal to another one up to the given time
597 interval, i.e. if the absolute difference between the two dates is less
598 than this interval.
599 */
600 bool IsEqualUpTo(const wxDateTime& dt, const wxTimeSpan& ts) const;
601
602 /**
603 Returns @true if this date is later than the given one.
604 */
605 bool IsLaterThan(const wxDateTime& datetime) const;
606
607 /**
608 Returns @true if the date is the same without comparing the time parts.
609 */
610 bool IsSameDate(const wxDateTime& dt) const;
611
612 /**
613 Returns @true if the time is the same (although dates may differ).
614 */
615 bool IsSameTime(const wxDateTime& dt) const;
616
617 /**
618 Returns @true if this date lies strictly between the two given dates.
619
620 @see IsBetween()
621 */
622 bool IsStrictlyBetween(const wxDateTime& t1,
623 const wxDateTime& t2) const;
624
625 /**
626 Returns @true if IsStrictlyBetween() is @true or if the date is equal
627 to one of the limit values.
628
629 @see IsStrictlyBetween()
630 */
631 bool IsBetween(const wxDateTime& t1, const wxDateTime& t2) const;
632
633 //@}
634
635
636
637 /**
638 @name Date Arithmetics
639
640 These functions carry out
641 @ref overview_datetime_arithmetics "arithmetics" on the wxDateTime
642 objects. As explained in the overview, either wxTimeSpan or wxDateSpan
643 may be added to wxDateTime, hence all functions are overloaded to
644 accept both arguments.
645
646 Also, both Add() and Subtract() have both const and non-const version.
647 The first one returns a new object which represents the sum/difference
648 of the original one with the argument while the second form modifies
649 the object to which it is applied. The operators "-=" and "+=" are
650 defined to be equivalent to the second forms of these functions.
651 */
652 //@{
653
654 /**
655 Adds the given date span to this object.
656
657 @beginWxPythonOnly
658 This method is named "AddDS" in wxPython.
659 @endWxPythonOnly
660 */
661 wxDateTime Add(const wxDateSpan& diff) const;
662 /**
663 Adds the given date span to this object.
664
665 @beginWxPythonOnly
666 This method is named "AddDS" in wxPython.
667 @endWxPythonOnly
668 */
669 wxDateTime Add(const wxDateSpan& diff);
670 /**
671 Adds the given time span to this object.
672
673 @beginWxPythonOnly
674 This method is named "AddTS" in wxPython.
675 @endWxPythonOnly
676 */
677 wxDateTime Add(const wxTimeSpan& diff) const;
678 /**
679 Adds the given time span to this object.
680
681 @beginWxPythonOnly
682 This method is named "AddTS" in wxPython.
683 @endWxPythonOnly
684 */
685 wxDateTime& Add(const wxTimeSpan& diff);
686
687 /**
688 Subtracts the given time span from this object.
689
690 @beginWxPythonOnly
691 This method is named "SubtractTS" in wxPython.
692 @endWxPythonOnly
693 */
694 wxDateTime Subtract(const wxTimeSpan& diff) const;
695 /**
696 Subtracts the given time span from this object.
697
698 @beginWxPythonOnly
699 This method is named "SubtractTS" in wxPython.
700 @endWxPythonOnly
701 */
702 wxDateTime& Subtract(const wxTimeSpan& diff);
703 /**
704 Subtracts the given date span from this object.
705
706 @beginWxPythonOnly
707 This method is named "SubtractDS" in wxPython.
708 @endWxPythonOnly
709 */
710 wxDateTime Subtract(const wxDateSpan& diff) const;
711 /**
712 Subtracts the given date span from this object.
713
714 @beginWxPythonOnly
715 This method is named "SubtractDS" in wxPython.
716 @endWxPythonOnly
717 */
718 wxDateTime& Subtract(const wxDateSpan& diff);
719 /**
720 Subtracts another date from this one and returns the difference between
721 them as a wxTimeSpan.
722 */
723 wxTimeSpan Subtract(const wxDateTime& dt) const;
724
725 /**
726 Adds the given date span to this object.
727 */
728 wxDateTime operator+=(const wxDateSpan& diff);
729 /**
730 Subtracts the given date span from this object.
731 */
732 wxDateTime& operator-=(const wxDateSpan& diff);
733 /**
734 Adds the given time span to this object.
735 */
736 wxDateTime& operator+=(const wxTimeSpan& diff);
737 /**
738 Subtracts the given time span from this object.
739 */
740 wxDateTime& operator-=(const wxTimeSpan& diff);
741
742 //@}
743
744
745
746 /**
747 @name Date Formatting and Parsing
748
749 See @ref datetime_formatting
750 */
751 //@{
752
753 /**
754 This function does the same as the standard ANSI C @c strftime(3)
755 function (http://www.cplusplus.com/reference/clibrary/ctime/strftime.html).
756 Please see its description for the meaning of @a format parameter.
757
758 It also accepts a few wxWidgets-specific extensions: you can optionally
759 specify the width of the field to follow using @c printf(3)-like syntax
760 and the format specification @c "%l" can be used to get the number of
761 milliseconds.
762
763 @see ParseFormat()
764 */
765 wxString Format(const wxString& format = wxDefaultDateTimeFormat,
766 const TimeZone& tz = Local) const;
767
768 /**
769 Identical to calling Format() with @c "%x" argument (which means
770 "preferred date representation for the current locale").
771 */
772 wxString FormatDate() const;
773
774 /**
775 Returns the combined date-time representation in the ISO 8601 format
776 @c "YYYY-MM-DDTHH:MM:SS". The @a sep parameter default value produces
777 the result exactly corresponding to the ISO standard, but it can also
778 be useful to use a space as seprator if a more human-readable combined
779 date-time representation is needed.
780
781 @see FormatISODate(), FormatISOTime(), ParseISOCombined()
782 */
783 wxString FormatISOCombined(char sep = 'T') const;
784
785 /**
786 This function returns the date representation in the ISO 8601 format
787 @c "YYYY-MM-DD".
788 */
789 wxString FormatISODate() const;
790
791 /**
792 This function returns the time representation in the ISO 8601 format
793 @c "HH:MM:SS".
794 */
795 wxString FormatISOTime() const;
796
797 /**
798 Identical to calling Format() with @c "%X" argument (which means
799 "preferred time representation for the current locale").
800 */
801 wxString FormatTime() const;
802
803 /**
804 This function is like ParseDateTime(), but it only allows the date to
805 be specified.
806
807 It is thus less flexible then ParseDateTime(), but also has less
808 chances to misinterpret the user input.
809
810 See ParseFormat() for the description of function parameters and return
811 value.
812
813 @see Format()
814 */
815 const char* ParseDate(const wxString& date,
816 wxString::const_iterator* end = NULL);
817
818 /**
819 Parses the string @a datetime containing the date and time in free
820 format.
821
822 This function tries as hard as it can to interpret the given string as
823 date and time. Unlike ParseRfc822Date(), it will accept anything that
824 may be accepted and will only reject strings which can not be parsed in
825 any way at all.
826
827 See ParseFormat() for the description of function parameters and return
828 value.
829 */
830 const char* ParseDateTime(const wxString& datetime,
831 wxString::const_iterator* end = NULL);
832
833 /**
834 This function parses the string @a date according to the given
835 @e format. The system @c strptime(3) function is used whenever
836 available, but even if it is not, this function is still implemented,
837 although support for locale-dependent format specifiers such as
838 @c "%c", @c "%x" or @c "%X" may not be perfect and GNU extensions such
839 as @c "%z" and @c "%Z" are not implemented. This function does handle
840 the month and weekday names in the current locale on all platforms,
841 however.
842
843 Please see the description of the ANSI C function @c strftime(3) for
844 the syntax of the format string.
845
846 The @a dateDef parameter is used to fill in the fields which could not
847 be determined from the format string. For example, if the format is
848 @c "%d" (the day of the month), the month and the year are taken from
849 @a dateDef. If it is not specified, Today() is used as the default
850 date.
851
852 Notice that the return value of this method is not actually a pointer
853 but rather an object of a special proxy class which is convertible to
854 either @c char* or @c wchar_t* pointer. This is needed for
855 compatibility with the existing code but the new code should use @a end
856 parameter instead and just test whether the return value is @NULL or
857 not, e.g.:
858 @code
859 wxDateTime dt;
860 wxString str = "...";
861 wxString::const_iterator end;
862 if ( !dt.ParseFormat(str, "%Y-%m-%d", &end) )
863 ... parsing failed ...
864 else if ( end == str.end() )
865 ... entire string parsed ...
866 else
867 ... wxString(end, str.end()) left over ...
868 @endcode
869
870 @param date
871 The string to be parsed.
872 @param format
873 strptime()-like format string.
874 @param dateDef
875 Used to fill in the date components not specified in the @a date
876 string.
877 @param end
878 If non-@NULL, will be filled with the iterator pointing to the
879 location where the parsing stopped. If the entire string was
880 consumed, it is set to @c date.end().
881 @return
882 Pointer-like object indicating the location where the scan stopped
883 if parsing was successful or @NULL-like otherwise.
884
885 @see Format()
886 */
887 const char* ParseFormat(const wxString& date,
888 const wxString& format = wxDefaultDateTimeFormat,
889 const wxDateTime& dateDef = wxDefaultDateTime,
890 wxString::const_iterator* end = NULL);
891
892 /**
893 @overload
894 */
895 const char* ParseFormat(const wxString& date,
896 const wxString& format = wxDefaultDateTimeFormat,
897 wxString::const_iterator* end = NULL);
898
899 /**
900 This function parses the string containing the date and time in ISO
901 8601 combined format @c "YYYY-MM-DDTHH:MM:SS". The separator between
902 the date and time parts must be equal to @a sep for the function to
903 succeed.
904
905 @return @true if the entire string was parsed successfully, @false
906 otherwise.
907 */
908 bool ParseISOCombined(const wxString& date, char sep = 'T');
909
910 /**
911 This function parses the date in ISO 8601 format @c "YYYY-MM-DD".
912
913 @return @true if the entire string was parsed successfully, @false
914 otherwise.
915 */
916 bool ParseISODate(const wxString& date);
917
918 /**
919 This function parses the time in ISO 8601 format @c "HH:MM:SS".
920
921 @return @true if the entire string was parsed successfully, @false
922 otherwise.
923 */
924 bool ParseISOTime(const wxString& date);
925
926 /**
927 Parses the string @a date looking for a date formatted according to the
928 RFC 822 in it. The exact description of this format may, of course, be
929 found in the RFC (section 5), but, briefly, this is the format used in
930 the headers of Internet email messages and one of the most common
931 strings expressing date in this format may be something like
932 @c "Sat, 18 Dec 1999 00:48:30 +0100".
933
934 Returns @NULL if the conversion failed, otherwise return the pointer to
935 the character immediately following the part of the string which could
936 be parsed. If the entire string contains only the date in RFC 822
937 format, the returned pointer will be pointing to a @c NUL character.
938
939 This function is intentionally strict, it will return an error for any
940 string which is not RFC 822 compliant. If you need to parse date
941 formatted in more free ways, you should use ParseDateTime() or
942 ParseDate() instead.
943
944 See ParseFormat() for the description of function parameters and return
945 value.
946 */
947 const char* ParseRfc822Date(const wxString& date,
948 wxString::const_iterator* end = NULL);
949
950 /**
951 This functions is like ParseDateTime(), but only allows the time to be
952 specified in the input string.
953
954 See ParseFormat() for the description of function parameters and return
955 value.
956 */
957 const char* ParseTime(const wxString& time,
958 wxString::const_iterator* end = NULL);
959
960 //@}
961
962
963
964 /**
965 @name Calendar Calculations
966
967 The functions in this section perform the basic calendar calculations,
968 mostly related to the week days. They allow to find the given week day
969 in the week with given number (either in the month or in the year) and
970 so on.
971
972 None of the functions in this section modify the time part of the
973 wxDateTime, they only work with the date part of it.
974 */
975 //@{
976
977 /**
978 Returns the copy of this object to which SetToLastMonthDay() was
979 applied.
980 */
981 wxDateTime GetLastMonthDay(Month month = Inv_Month,
982 int year = Inv_Year) const;
983
984 /**
985 Returns the copy of this object to which SetToLastWeekDay() was
986 applied.
987 */
988 wxDateTime GetLastWeekDay(WeekDay weekday, Month month = Inv_Month,
989 int year = Inv_Year);
990
991 /**
992 Returns the copy of this object to which SetToNextWeekDay() was
993 applied.
994 */
995 wxDateTime GetNextWeekDay(WeekDay weekday) const;
996
997 /**
998 Returns the copy of this object to which SetToPrevWeekDay() was
999 applied.
1000 */
1001 wxDateTime GetPrevWeekDay(WeekDay weekday) const;
1002
1003 /**
1004 Returns the copy of this object to which SetToWeekDay() was applied.
1005 */
1006 wxDateTime GetWeekDay(WeekDay weekday, int n = 1, Month month = Inv_Month,
1007 int year = Inv_Year) const;
1008
1009 /**
1010 Returns the copy of this object to which SetToWeekDayInSameWeek() was
1011 applied.
1012 */
1013 wxDateTime GetWeekDayInSameWeek(WeekDay weekday,
1014 WeekFlags flags = Monday_First) const;
1015
1016 /**
1017 Returns the copy of this object to which SetToYearDay() was applied.
1018 */
1019 wxDateTime GetYearDay(wxDateTime_t yday) const;
1020
1021 /**
1022 Sets the date to the last day in the specified month (the current one
1023 by default).
1024
1025 @return The reference to the modified object itself.
1026 */
1027 wxDateTime& SetToLastMonthDay(Month month = Inv_Month, int year = Inv_Year);
1028
1029 /**
1030 The effect of calling this function is the same as of calling
1031 @c SetToWeekDay(-1, weekday, month, year). The date will be set to the
1032 last @a weekday in the given month and year (the current ones by
1033 default). Always returns @true.
1034 */
1035 bool SetToLastWeekDay(WeekDay weekday, Month month = Inv_Month,
1036 int year = Inv_Year);
1037
1038 /**
1039 Sets the date so that it will be the first @a weekday following the
1040 current date.
1041
1042 @return The reference to the modified object itself.
1043 */
1044 wxDateTime& SetToNextWeekDay(WeekDay weekday);
1045
1046 /**
1047 Sets the date so that it will be the last @a weekday before the current
1048 date.
1049
1050 @return The reference to the modified object itself.
1051 */
1052 wxDateTime& SetToPrevWeekDay(WeekDay weekday);
1053
1054 /**
1055 Sets the date to the @e n-th @a weekday in the given month of the given
1056 year (the current month and year are used by default). The parameter
1057 @a n may be either positive (counting from the beginning of the month)
1058 or negative (counting from the end of it).
1059
1060 For example, SetToWeekDay(2, wxDateTime::Wed) will set the date to the
1061 second Wednesday in the current month and
1062 SetToWeekDay(-1, wxDateTime::Sun) will set the date to the last Sunday
1063 in the current month.
1064
1065 @return @true if the date was modified successfully, @false otherwise
1066 meaning that the specified date doesn't exist.
1067 */
1068 bool SetToWeekDay(WeekDay weekday, int n = 1,
1069 Month month = Inv_Month, int year = Inv_Year);
1070
1071 /**
1072 Adjusts the date so that it will still lie in the same week as before,
1073 but its week day will be the given one.
1074
1075 @return The reference to the modified object itself.
1076 */
1077 wxDateTime& SetToWeekDayInSameWeek(WeekDay weekday,
1078 WeekFlags flags = Monday_First);
1079
1080 /**
1081 Sets the date to the day number @a yday in the same year (i.e., unlike
1082 the other functions, this one does not use the current year). The day
1083 number should be in the range 1-366 for the leap years and 1-365 for
1084 the other ones.
1085
1086 @return The reference to the modified object itself.
1087 */
1088 wxDateTime& SetToYearDay(wxDateTime_t yday);
1089
1090 //@}
1091
1092
1093
1094 /**
1095 @name Astronomical/Historical Functions
1096
1097 Some degree of support for the date units used in astronomy and/or
1098 history is provided. You can construct a wxDateTime object from a
1099 JDN and you may also get its JDN, MJD or Rata Die number from it.
1100
1101 Related functions in other groups: wxDateTime(double), Set(double)
1102 */
1103 //@{
1104
1105 /**
1106 Synonym for GetJulianDayNumber().
1107 */
1108 double GetJDN() const;
1109
1110 /**
1111 Returns the JDN corresponding to this date. Beware of rounding errors!
1112
1113 @see GetModifiedJulianDayNumber()
1114 */
1115 double GetJulianDayNumber() const;
1116
1117 /**
1118 Synonym for GetModifiedJulianDayNumber().
1119 */
1120 double GetMJD() const;
1121
1122 /**
1123 Returns the @e "Modified Julian Day Number" (MJD) which is, by
1124 definition, is equal to JDN - 2400000.5.
1125 The MJDs are simpler to work with as the integral MJDs correspond to
1126 midnights of the dates in the Gregorian calendar and not the noons like
1127 JDN. The MJD 0 represents Nov 17, 1858.
1128 */
1129 double GetModifiedJulianDayNumber() const;
1130
1131 /**
1132 Return the @e Rata Die number of this date.
1133
1134 By definition, the Rata Die number is a date specified as the number of
1135 days relative to a base date of December 31 of the year 0. Thus January
1136 1 of the year 1 is Rata Die day 1.
1137 */
1138 double GetRataDie() const;
1139
1140 //@}
1141
1142
1143
1144 /**
1145 @name Time Zone and DST Support
1146
1147 Please see the @ref overview_datetime_timezones "time zone overview"
1148 for more information about time zones. Normally, these functions should
1149 be rarely used.
1150
1151 Related functions in other groups: GetBeginDST(), GetEndDST()
1152 */
1153 //@{
1154
1155 /**
1156 Transform the date from the given time zone to the local one. If
1157 @a noDST is @true, no DST adjustments will be made.
1158
1159 @return The date in the local time zone.
1160 */
1161 wxDateTime FromTimezone(const TimeZone& tz, bool noDST = false) const;
1162
1163 /**
1164 Returns @true if the DST is applied for this date in the given country.
1165
1166 @see GetBeginDST(), GetEndDST()
1167 */
1168 int IsDST(Country country = Country_Default) const;
1169
1170 /**
1171 Same as FromTimezone() but modifies the object in place.
1172 */
1173 wxDateTime& MakeFromTimezone(const TimeZone& tz, bool noDST = false);
1174
1175 /**
1176 Modifies the object in place to represent the date in another time
1177 zone. If @a noDST is @true, no DST adjustments will be made.
1178 */
1179 wxDateTime& MakeTimezone(const TimeZone& tz, bool noDST = false);
1180
1181 /**
1182 This is the same as calling MakeTimezone() with the argument @c GMT0.
1183 */
1184 wxDateTime& MakeUTC(bool noDST = false);
1185
1186 /**
1187 Transform the date to the given time zone. If @a noDST is @true, no DST
1188 adjustments will be made.
1189
1190 @return The date in the new time zone.
1191 */
1192 wxDateTime ToTimezone(const TimeZone& tz, bool noDST = false) const;
1193
1194 /**
1195 This is the same as calling ToTimezone() with the argument @c GMT0.
1196 */
1197 wxDateTime ToUTC(bool noDST = false) const;
1198
1199 //@}
1200
1201
1202
1203
1204
1205 /**
1206 Converts the year in absolute notation (i.e. a number which can be
1207 negative, positive or zero) to the year in BC/AD notation. For the
1208 positive years, nothing is done, but the year 0 is year 1 BC and so for
1209 other years there is a difference of 1.
1210
1211 This function should be used like this:
1212
1213 @code
1214 wxDateTime dt(...);
1215 int y = dt.GetYear();
1216 printf("The year is %d%s", wxDateTime::ConvertYearToBC(y), y > 0 ? "AD" : "BC");
1217 @endcode
1218 */
1219 static int ConvertYearToBC(int year);
1220
1221 /**
1222 Returns the translations of the strings @c AM and @c PM used for time
1223 formatting for the current locale. Either of the pointers may be @NULL
1224 if the corresponding value is not needed.
1225 */
1226 static void GetAmPmStrings(wxString* am, wxString* pm);
1227
1228 /**
1229 Get the beginning of DST for the given country in the given year
1230 (current one by default). This function suffers from limitations
1231 described in the @ref overview_datetime_dst "DST overview".
1232
1233 @see GetEndDST()
1234 */
1235 static wxDateTime GetBeginDST(int year = Inv_Year,
1236 Country country = Country_Default);
1237
1238 /**
1239 Returns the end of DST for the given country in the given year (current
1240 one by default).
1241
1242 @see GetBeginDST()
1243 */
1244 static wxDateTime GetEndDST(int year = Inv_Year,
1245 Country country = Country_Default);
1246
1247 /**
1248 Get the current century, i.e. first two digits of the year, in given
1249 calendar (only Gregorian is currently supported).
1250 */
1251 static int GetCentury(int year);
1252
1253 /**
1254 Returns the current default country. The default country is used for
1255 DST calculations, for example.
1256
1257 @see SetCountry()
1258 */
1259 static Country GetCountry();
1260
1261 /**
1262 Get the current month in given calendar (only Gregorian is currently
1263 supported).
1264 */
1265 static Month GetCurrentMonth(Calendar cal = Gregorian);
1266
1267 /**
1268 Get the current year in given calendar (only Gregorian is currently
1269 supported).
1270 */
1271 static int GetCurrentYear(Calendar cal = Gregorian);
1272
1273 /**
1274 Return the standard English name of the given month.
1275
1276 This function always returns "January" or "Jan" for January, use
1277 GetMonthName() to retrieve the name of the month in the users current
1278 locale.
1279
1280 @param month
1281 One of wxDateTime::Jan, ..., wxDateTime::Dec values.
1282 @param flags
1283 Either Name_Full (default) or Name_Abbr.
1284
1285 @see GetEnglishWeekDayName()
1286
1287 @since 2.9.0
1288 */
1289 static wxString GetEnglishMonthName(Month month,
1290 NameFlags flags = Name_Full);
1291
1292 /**
1293 Return the standard English name of the given week day.
1294
1295 This function always returns "Monday" or "Mon" for Monday, use
1296 GetWeekDayName() to retrieve the name of the month in the users current
1297 locale.
1298
1299 @param weekday
1300 One of wxDateTime::Sun, ..., wxDateTime::Sat values.
1301 @param flags
1302 Either Name_Full (default) or Name_Abbr.
1303
1304 @see GetEnglishMonthName()
1305
1306 @since 2.9.0
1307 */
1308 static wxString GetEnglishWeekDayName(WeekDay weekday,
1309 NameFlags flags = Name_Full);
1310
1311 /**
1312 Gets the full (default) or abbreviated name of the given month.
1313
1314 This function returns the name in the current locale, use
1315 GetEnglishMonthName() to get the untranslated name if necessary.
1316
1317 @param month
1318 One of wxDateTime::Jan, ..., wxDateTime::Dec values.
1319 @param flags
1320 Either Name_Full (default) or Name_Abbr.
1321
1322 @see GetWeekDayName()
1323 */
1324 static wxString GetMonthName(Month month, NameFlags flags = Name_Full);
1325
1326 /**
1327 Returns the number of days in the given year. The only supported value
1328 for @a cal currently is @c Gregorian.
1329
1330 @beginWxPythonOnly
1331 This method is named "GetNumberOfDaysInYear" in wxPython.
1332 @endWxPythonOnly
1333 */
1334 static wxDateTime_t GetNumberOfDays(int year, Calendar cal = Gregorian);
1335
1336 /**
1337 Returns the number of days in the given month of the given year. The
1338 only supported value for @a cal currently is @c Gregorian.
1339
1340 @beginWxPythonOnly
1341 This method is named "GetNumberOfDaysInMonth" in wxPython.
1342 @endWxPythonOnly
1343 */
1344 static wxDateTime_t GetNumberOfDays(Month month, int year = Inv_Year,
1345 Calendar cal = Gregorian);
1346
1347 /**
1348 Returns the current time.
1349 */
1350 static time_t GetTimeNow();
1351
1352 /**
1353 Returns the current time broken down using the buffer whose adress is
1354 passed to the function with @a tm to store the result.
1355 */
1356 static tm* GetTmNow(struct tm *tm);
1357
1358 /**
1359 Returns the current time broken down. Note that this function returns a
1360 pointer to a static buffer that's reused by calls to this function and
1361 certain C library functions (e.g. localtime). If there is any chance
1362 your code might be used in a multi-threaded application, you really
1363 should use GetTmNow(struct tm *) instead.
1364 */
1365 static tm* GetTmNow();
1366
1367 /**
1368 Gets the full (default) or abbreviated name of the given week day.
1369
1370 This function returns the name in the current locale, use
1371 GetEnglishWeekDayName() to get the untranslated name if necessary.
1372
1373 @param weekday
1374 One of wxDateTime::Sun, ..., wxDateTime::Sat values.
1375 @param flags
1376 Either Name_Full (default) or Name_Abbr.
1377
1378 @see GetMonthName()
1379 */
1380 static wxString GetWeekDayName(WeekDay weekday,
1381 NameFlags flags = Name_Full);
1382
1383 /**
1384 Returns @true if DST was used in the given year (the current one by
1385 default) in the given country.
1386 */
1387 static bool IsDSTApplicable(int year = Inv_Year,
1388 Country country = Country_Default);
1389
1390 /**
1391 Returns @true if the @a year is a leap one in the specified calendar.
1392 This functions supports Gregorian and Julian calendars.
1393 */
1394 static bool IsLeapYear(int year = Inv_Year, Calendar cal = Gregorian);
1395
1396 /**
1397 This function returns @true if the specified (or default) country is
1398 one of Western European ones. It is used internally by wxDateTime to
1399 determine the DST convention and date and time formatting rules.
1400 */
1401 static bool IsWestEuropeanCountry(Country country = Country_Default);
1402
1403 /**
1404 Returns the object corresponding to the current time.
1405
1406 Example:
1407
1408 @code
1409 wxDateTime now = wxDateTime::Now();
1410 printf("Current time in Paris:\t%s\n", now.Format("%c", wxDateTime::CET).c_str());
1411 @endcode
1412
1413 @note This function is accurate up to seconds. UNow() should be used
1414 for better precision, but it is less efficient and might not be
1415 available on all platforms.
1416
1417 @see Today()
1418 */
1419 static wxDateTime Now();
1420
1421 /**
1422 Sets the country to use by default. This setting influences the DST
1423 calculations, date formatting and other things.
1424
1425 @see GetCountry()
1426 */
1427 static void SetCountry(Country country);
1428
1429 /**
1430 Set the date to the given @a weekday in the week number @a numWeek of
1431 the given @a year . The number should be in range 1-53.
1432
1433 Note that the returned date may be in a different year than the one
1434 passed to this function because both the week 1 and week 52 or 53 (for
1435 leap years) contain days from different years. See GetWeekOfYear() for
1436 the explanation of how the year weeks are counted.
1437 */
1438 static wxDateTime SetToWeekOfYear(int year, wxDateTime_t numWeek,
1439 WeekDay weekday = Mon);
1440
1441 /**
1442 Returns the object corresponding to the midnight of the current day
1443 (i.e. the same as Now(), but the time part is set to 0).
1444
1445 @see Now()
1446 */
1447 static wxDateTime Today();
1448
1449 /**
1450 Returns the object corresponding to the current time including the
1451 milliseconds if a function to get time with such precision is available
1452 on the current platform (supported under most Unices and Win32).
1453
1454 @see Now()
1455 */
1456 static wxDateTime UNow();
1457 };
1458
1459 /**
1460 Global instance of an empty wxDateTime object.
1461
1462 @todo Would it be better to rename this wxNullDateTime so it's consistent
1463 with the rest of the "empty/invalid/null" global objects?
1464 */
1465 const wxDateTime wxDefaultDateTime;
1466
1467
1468
1469 /**
1470 @class wxDateTimeWorkDays
1471
1472 @todo Write wxDateTimeWorkDays documentation.
1473
1474 @library{wxbase}
1475 @category{data}
1476 */
1477 class wxDateTimeWorkDays
1478 {
1479 public:
1480
1481 };
1482
1483
1484
1485 /**
1486 @class wxDateSpan
1487
1488 This class is a "logical time span" and is useful for implementing program
1489 logic for such things as "add one month to the date" which, in general,
1490 doesn't mean to add 60*60*24*31 seconds to it, but to take the same date
1491 the next month (to understand that this is indeed different consider adding
1492 one month to Feb, 15 -- we want to get Mar, 15, of course).
1493
1494 When adding a month to the date, all lesser components (days, hours, ...)
1495 won't be changed unless the resulting date would be invalid: for example,
1496 Jan 31 + 1 month will be Feb 28, not (non-existing) Feb 31.
1497
1498 Because of this feature, adding and subtracting back again the same
1499 wxDateSpan will @b not, in general, give back the original date: Feb 28 - 1
1500 month will be Jan 28, not Jan 31!
1501
1502 wxDateSpan objects can be either positive or negative. They may be
1503 multiplied by scalars which multiply all deltas by the scalar: i.e.
1504 2*(1 month and 1 day) is 2 months and 2 days. They can be added together
1505 with wxDateTime or wxTimeSpan, but the type of result is different for each
1506 case.
1507
1508 @warning If you specify both weeks and days, the total number of days added
1509 will be 7*weeks + days! See also GetTotalDays().
1510
1511 Equality operators are defined for wxDateSpans. Two wxDateSpans are equal
1512 if and only if they both give the same target date when added to @b every
1513 source date. Thus wxDateSpan::Months(1) is not equal to
1514 wxDateSpan::Days(30), because they don't give the same date when added to
1515 Feb 1st. But wxDateSpan::Days(14) is equal to wxDateSpan::Weeks(2).
1516
1517 Finally, notice that for adding hours, minutes and so on you don't need
1518 this class at all: wxTimeSpan will do the job because there are no
1519 subtleties associated with those (we don't support leap seconds).
1520
1521 @library{wxbase}
1522 @category{data}
1523
1524 @see @ref overview_datetime, wxDateTime
1525 */
1526 class wxDateSpan
1527 {
1528 public:
1529 /**
1530 Constructs the date span object for the given number of years, months,
1531 weeks and days. Note that the weeks and days add together if both are
1532 given.
1533 */
1534 wxDateSpan(int years = 0, int months = 0, int weeks = 0, int days = 0);
1535
1536 /**
1537 Returns the sum of two date spans.
1538
1539 @return A new wxDateSpan object with the result.
1540 */
1541 wxDateSpan Add(const wxDateSpan& other) const;
1542 /**
1543 Adds the given wxDateSpan to this wxDateSpan and returns a reference
1544 to itself.
1545 */
1546 wxDateSpan& Add(const wxDateSpan& other);
1547
1548 /**
1549 Returns a date span object corresponding to one day.
1550
1551 @see Days()
1552 */
1553 static wxDateSpan Day();
1554
1555 /**
1556 Returns a date span object corresponding to the given number of days.
1557
1558 @see Day()
1559 */
1560 static wxDateSpan Days(int days);
1561
1562 /**
1563 Returns the number of days (not counting the weeks component) in this
1564 date span.
1565
1566 @see GetTotalDays()
1567 */
1568 int GetDays() const;
1569
1570 /**
1571 Returns the number of the months (not counting the years) in this date
1572 span.
1573 */
1574 int GetMonths() const;
1575
1576 /**
1577 Returns the combined number of days in this date span, counting both
1578 weeks and days. This doesn't take months or years into account.
1579
1580 @see GetWeeks(), GetDays()
1581 */
1582 int GetTotalDays() const;
1583
1584 /**
1585 Returns the number of weeks in this date span.
1586
1587 @see GetTotalDays()
1588 */
1589 int GetWeeks() const;
1590
1591 /**
1592 Returns the number of years in this date span.
1593 */
1594 int GetYears() const;
1595
1596 /**
1597 Returns a date span object corresponding to one month.
1598
1599 @see Months()
1600 */
1601 static wxDateSpan Month();
1602
1603 /**
1604 Returns a date span object corresponding to the given number of months.
1605
1606 @see Month()
1607 */
1608 static wxDateSpan Months(int mon);
1609
1610 /**
1611 Returns the product of the date span by the specified @a factor. The
1612 product is computed by multiplying each of the components by the
1613 @a factor.
1614
1615 @return A new wxDateSpan object with the result.
1616 */
1617 wxDateSpan Multiply(int factor) const;
1618 /**
1619 Multiplies this date span by the specified @a factor. The product is
1620 computed by multiplying each of the components by the @a factor.
1621
1622 @return A reference to this wxDateSpan object modified in place.
1623 */
1624 wxDateSpan& Multiply(int factor);
1625
1626 /**
1627 Changes the sign of this date span.
1628
1629 @see Negate()
1630 */
1631 wxDateSpan& Neg();
1632
1633 /**
1634 Returns a date span with the opposite sign.
1635
1636 @see Neg()
1637 */
1638 wxDateSpan Negate() const;
1639
1640 /**
1641 Sets the number of days (without modifying any other components) in
1642 this date span.
1643 */
1644 wxDateSpan& SetDays(int n);
1645
1646 /**
1647 Sets the number of months (without modifying any other components) in
1648 this date span.
1649 */
1650 wxDateSpan& SetMonths(int n);
1651
1652 /**
1653 Sets the number of weeks (without modifying any other components) in
1654 this date span.
1655 */
1656 wxDateSpan& SetWeeks(int n);
1657
1658 /**
1659 Sets the number of years (without modifying any other components) in
1660 this date span.
1661 */
1662 wxDateSpan& SetYears(int n);
1663
1664 /**
1665 Returns the difference of two date spans.
1666
1667 @return A new wxDateSpan object with the result.
1668 */
1669 wxDateSpan Subtract(const wxDateSpan& other) const;
1670 /**
1671 Subtracts the given wxDateSpan to this wxDateSpan and returns a
1672 reference to itself.
1673 */
1674 wxDateSpan& Subtract(const wxDateSpan& other);
1675
1676 /**
1677 Returns a date span object corresponding to one week.
1678
1679 @see Weeks()
1680 */
1681 static wxDateSpan Week();
1682
1683 /**
1684 Returns a date span object corresponding to the given number of weeks.
1685
1686 @see Week()
1687 */
1688 static wxDateSpan Weeks(int weeks);
1689
1690 /**
1691 Returns a date span object corresponding to one year.
1692
1693 @see Years()
1694 */
1695 static wxDateSpan Year();
1696
1697 /**
1698 Returns a date span object corresponding to the given number of years.
1699
1700 @see Year()
1701 */
1702 static wxDateSpan Years(int years);
1703
1704 /**
1705 Adds the given wxDateSpan to this wxDateSpan and returns the result.
1706 */
1707 wxDateSpan& operator+=(const wxDateSpan& other);
1708
1709 /**
1710 Subtracts the given wxDateSpan to this wxDateSpan and returns the
1711 result.
1712 */
1713 wxDateSpan& operator-=(const wxDateSpan& other);
1714
1715 /**
1716 Changes the sign of this date span.
1717
1718 @see Negate()
1719 */
1720 wxDateSpan& operator-();
1721
1722 /**
1723 Multiplies this date span by the specified @a factor. The product is
1724 computed by multiplying each of the components by the @a factor.
1725
1726 @return A reference to this wxDateSpan object modified in place.
1727 */
1728 wxDateSpan& operator*=(int factor);
1729
1730 /**
1731 Returns @true if this date span is different from the other one.
1732 */
1733 bool operator!=(const wxDateSpan&) const;
1734
1735 /**
1736 Returns @true if this date span is equal to the other one. Two date
1737 spans are considered equal if and only if they have the same number of
1738 years and months and the same total number of days (counting both days
1739 and weeks).
1740 */
1741 bool operator==(const wxDateSpan&) const;
1742 };
1743
1744
1745
1746 /**
1747 @class wxTimeSpan
1748
1749 wxTimeSpan class represents a time interval.
1750
1751 @library{wxbase}
1752 @category{data}
1753
1754 @see @ref overview_datetime, wxDateTime
1755 */
1756 class wxTimeSpan
1757 {
1758 public:
1759 /**
1760 Default constructor, constructs a zero timespan.
1761 */
1762 wxTimeSpan();
1763 /**
1764 Constructs timespan from separate values for each component, with the
1765 date set to 0. Hours are not restricted to 0-24 range, neither are
1766 minutes, seconds or milliseconds.
1767 */
1768 wxTimeSpan(long hours, long min = 0, wxLongLong sec = 0, wxLongLong msec = 0);
1769
1770 /**
1771 Returns the absolute value of the timespan: does not modify the object.
1772 */
1773 wxTimeSpan Abs() const;
1774
1775 /**
1776 Returns the sum of two time spans.
1777
1778 @return A new wxDateSpan object with the result.
1779 */
1780 wxTimeSpan Add(const wxTimeSpan& diff) const;
1781 /**
1782 Adds the given wxTimeSpan to this wxTimeSpan and returns a reference
1783 to itself.
1784 */
1785 wxTimeSpan& Add(const wxTimeSpan& diff);
1786
1787 /**
1788 Returns the timespan for one day.
1789 */
1790 static wxTimeSpan Day();
1791
1792 /**
1793 Returns the timespan for the given number of days.
1794 */
1795 static wxTimeSpan Days(long days);
1796
1797 /**
1798 Returns the string containing the formatted representation of the time
1799 span. The following format specifiers are allowed after %:
1800
1801 - @c H - Number of Hours
1802 - @c M - Number of Minutes
1803 - @c S - Number of Seconds
1804 - @c l - Number of Milliseconds
1805 - @c D - Number of Days
1806 - @c E - Number of Weeks
1807 - @c % - The percent character
1808
1809 Note that, for example, the number of hours in the description above is
1810 not well defined: it can be either the total number of hours (for
1811 example, for a time span of 50 hours this would be 50) or just the hour
1812 part of the time span, which would be 2 in this case as 50 hours is
1813 equal to 2 days and 2 hours.
1814
1815 wxTimeSpan resolves this ambiguity in the following way: if there had
1816 been, indeed, the @c %D format specified preceding the @c %H, then it
1817 is interpreted as 2. Otherwise, it is 50.
1818
1819 The same applies to all other format specifiers: if they follow a
1820 specifier of larger unit, only the rest part is taken, otherwise the
1821 full value is used.
1822 */
1823 wxString Format(const wxString& = wxDefaultTimeSpanFormat) const;
1824
1825 /**
1826 Returns the difference in number of days.
1827 */
1828 int GetDays() const;
1829
1830 /**
1831 Returns the difference in number of hours.
1832 */
1833 int GetHours() const;
1834
1835 /**
1836 Returns the difference in number of milliseconds.
1837 */
1838 wxLongLong GetMilliseconds() const;
1839
1840 /**
1841 Returns the difference in number of minutes.
1842 */
1843 int GetMinutes() const;
1844
1845 /**
1846 Returns the difference in number of seconds.
1847 */
1848 wxLongLong GetSeconds() const;
1849
1850 /**
1851 Returns the internal representation of timespan.
1852 */
1853 wxLongLong GetValue() const;
1854
1855 /**
1856 Returns the difference in number of weeks.
1857 */
1858 int GetWeeks() const;
1859
1860 /**
1861 Returns the timespan for one hour.
1862 */
1863 static wxTimeSpan Hour();
1864
1865 /**
1866 Returns the timespan for the given number of hours.
1867 */
1868 static wxTimeSpan Hours(long hours);
1869
1870 /**
1871 Returns @true if two timespans are equal.
1872 */
1873 bool IsEqualTo(const wxTimeSpan& ts) const;
1874
1875 /**
1876 Compares two timespans: works with the absolute values, i.e. -2 hours
1877 is longer than 1 hour. Also, it will return @false if the timespans are
1878 equal in absolute value.
1879 */
1880 bool IsLongerThan(const wxTimeSpan& ts) const;
1881
1882 /**
1883 Returns @true if the timespan is negative.
1884 */
1885 bool IsNegative() const;
1886
1887 /**
1888 Returns @true if the timespan is empty.
1889 */
1890 bool IsNull() const;
1891
1892 /**
1893 Returns @true if the timespan is positive.
1894 */
1895 bool IsPositive() const;
1896
1897 /**
1898 Compares two timespans: works with the absolute values, i.e. 1 hour is
1899 shorter than -2 hours. Also, it will return @false if the timespans are
1900 equal in absolute value.
1901 */
1902 bool IsShorterThan(const wxTimeSpan& ts) const;
1903
1904 /**
1905 Returns the timespan for one millisecond.
1906 */
1907 static wxTimeSpan Millisecond();
1908
1909 /**
1910 Returns the timespan for the given number of milliseconds.
1911 */
1912 static wxTimeSpan Milliseconds(wxLongLong ms);
1913
1914 /**
1915 Returns the timespan for one minute.
1916 */
1917 static wxTimeSpan Minute();
1918
1919 /**
1920 Returns the timespan for the given number of minutes.
1921 */
1922 static wxTimeSpan Minutes(long min);
1923
1924 /**
1925 Returns the product of this time span by @a n.
1926
1927 @return A new wxTimeSpan object with the result.
1928 */
1929 wxTimeSpan Multiply(int n) const;
1930 /**
1931 Multiplies this time span by @a n.
1932
1933 @return A reference to this wxTimeSpan object modified in place.
1934 */
1935 wxTimeSpan& Multiply(int n);
1936
1937 /**
1938 Negate the value of the timespan.
1939
1940 @see Negate()
1941 */
1942 wxTimeSpan& Neg();
1943
1944 /**
1945 Returns timespan with inverted sign.
1946
1947 @see Neg()
1948 */
1949 wxTimeSpan Negate() const;
1950
1951 /**
1952 Returns the timespan for one second.
1953 */
1954 static wxTimeSpan Second();
1955
1956 /**
1957 Returns the timespan for the given number of seconds.
1958 */
1959 static wxTimeSpan Seconds(wxLongLong sec);
1960
1961 /**
1962 Returns the difference of two time spans.
1963
1964 @return A new wxDateSpan object with the result.
1965 */
1966 wxTimeSpan Subtract(const wxTimeSpan& diff) const;
1967 /**
1968 Subtracts the given wxTimeSpan to this wxTimeSpan and returns a
1969 reference to itself.
1970 */
1971 wxTimeSpan& Subtract(const wxTimeSpan& diff);
1972
1973 /**
1974 Returns the timespan for one week.
1975 */
1976 static wxTimeSpan Week();
1977
1978 /**
1979 Returns the timespan for the given number of weeks.
1980 */
1981 static wxTimeSpan Weeks(long weeks);
1982
1983 /**
1984 Adds the given wxTimeSpan to this wxTimeSpan and returns the result.
1985 */
1986 wxTimeSpan& operator+=(const wxTimeSpan& diff);
1987
1988 /**
1989 Multiplies this time span by @a n.
1990
1991 @return A reference to this wxTimeSpan object modified in place.
1992 */
1993 wxTimeSpan& operator*=(int n);
1994
1995 /**
1996 Negate the value of the timespan.
1997
1998 @see Negate()
1999 */
2000 wxTimeSpan& operator-();
2001
2002 /**
2003 Subtracts the given wxTimeSpan to this wxTimeSpan and returns the
2004 result.
2005 */
2006 wxTimeSpan& operator-=(const wxTimeSpan& diff);
2007 };
2008
2009
2010
2011 /**
2012 @class wxDateTimeHolidayAuthority
2013
2014 @todo Write wxDateTimeHolidayAuthority documentation.
2015
2016 @library{wxbase}
2017 @category{data}
2018 */
2019 class wxDateTimeHolidayAuthority
2020 {
2021 public:
2022
2023 };
2024