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