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