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