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