1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: declarations of time/date related classes (wxDateTime,
5 // Author: Vadim Zeitlin
9 // Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
13 #ifndef _WX_DATETIME_H
14 #define _WX_DATETIME_H
17 #pragma interface "datetime.h"
21 #include <limits.h> // for INT_MIN
23 #include "wx/longlong.h"
25 class WXDLLEXPORT wxDateTime
;
26 class WXDLLEXPORT wxTimeSpan
;
27 class WXDLLEXPORT wxDateSpan
;
29 // don't use inline functions in debug builds - we don't care about
30 // performances and this only leads to increased rebuild time (because every
31 // time an inline method is changed, all files including the header must be
38 * TODO Well, everything :-)
40 * + 1. Time zones with minutes (make TimeZone a class)
41 * 2. getdate() function like under Solaris
42 * + 3. text conversion for wxDateSpan
43 * 4. pluggable modules for the workdays calculations
47 The three (main) classes declared in this header represent:
49 1. An absolute moment in the time (wxDateTime)
50 2. A difference between two moments in the time, positive or negative
52 3. A logical difference between two dates expressed in
53 years/months/weeks/days (wxDateSpan)
55 The following arithmetic operations are permitted (all others are not):
60 wxDateTime + wxTimeSpan = wxDateTime
61 wxDateTime + wxDateSpan = wxDateTime
62 wxTimeSpan + wxTimeSpan = wxTimeSpan
63 wxDateSpan + wxDateSpan = wxDateSpan
67 wxDateTime - wxDateTime = wxTimeSpan
68 wxDateTime - wxTimeSpan = wxDateTime
69 wxDateTime - wxDateSpan = wxDateTime
70 wxTimeSpan - wxTimeSpan = wxTimeSpan
71 wxDateSpan - wxDateSpan = wxDateSpan
75 wxTimeSpan * number = wxTimeSpan
76 number * wxTimeSpan = wxTimeSpan
77 wxDateSpan * number = wxDateSpan
78 number * wxDateSpan = wxDateSpan
82 -wxTimeSpan = wxTimeSpan
83 -wxDateSpan = wxDateSpan
85 For each binary operation OP (+, -, *) we have the following operatorOP=() as
86 a method and the method with a symbolic name OPER (Add, Substract, Multiply)
87 as a synonym for it and another const method with the same name which returns
88 the changed copy of the object and operatorOP() as a global function which is
89 implemented in terms of the const version of OPEN. For the unary - we have
90 operator-() as a method, Neg() as synonym for it and Negate() which returns
91 the copy of the object with the changed sign.
94 // an invalid/default date time object which may be used as the default
95 // argument for arguments of type wxDateTime; it is also returned by all
96 // functions returning wxDateTime on failure (this is why it is also called
98 class WXDLLEXPORT wxDateTime
;
100 WXDLLEXPORT_DATA(extern wxDateTime
&) wxDefaultDateTime
;
101 #define wxInvalidDateTime wxDefaultDateTime
103 // ----------------------------------------------------------------------------
104 // wxDateTime represents an absolute moment in the time
105 // ----------------------------------------------------------------------------
107 class WXDLLEXPORT wxDateTime
111 // ------------------------------------------------------------------------
113 // a small unsigned integer type for storing things like minutes,
114 // seconds &c. It should be at least short (i.e. not char) to contain
115 // the number of milliseconds - it may also be 'int' because there is
116 // no size penalty associated with it in our code, we don't store any
117 // data in this format
118 typedef unsigned short wxDateTime_t
;
121 // ------------------------------------------------------------------------
126 // the time in the current time zone
129 // zones from GMT (= Greenwhich Mean Time): they're guaranteed to be
130 // consequent numbers, so writing something like `GMT0 + offset' is
131 // safe if abs(offset) <= 12
133 // underscore stands for minus
134 GMT_12
, GMT_11
, GMT_10
, GMT_9
, GMT_8
, GMT_7
,
135 GMT_6
, GMT_5
, GMT_4
, GMT_3
, GMT_2
, GMT_1
,
137 GMT1
, GMT2
, GMT3
, GMT4
, GMT5
, GMT6
,
138 GMT7
, GMT8
, GMT9
, GMT10
, GMT11
, GMT12
,
139 // Note that GMT12 and GMT_12 are not the same: there is a difference
140 // of exactly one day between them
142 // some symbolic names for TZ
145 WET
= GMT0
, // Western Europe Time
146 WEST
= GMT1
, // Western Europe Summer Time
147 CET
= GMT1
, // Central Europe Time
148 CEST
= GMT2
, // Central Europe Summer Time
149 EET
= GMT2
, // Eastern Europe Time
150 EEST
= GMT3
, // Eastern Europe Summer Time
151 MSK
= GMT3
, // Moscow Time
152 MSD
= GMT4
, // Moscow Summer Time
155 AST
= GMT_4
, // Atlantic Standard Time
156 ADT
= GMT_3
, // Atlantic Daylight Time
157 EST
= GMT_5
, // Eastern Standard Time
158 EDT
= GMT_4
, // Eastern Daylight Saving Time
159 CST
= GMT_6
, // Central Standard Time
160 CDT
= GMT_5
, // Central Daylight Saving Time
161 MST
= GMT_7
, // Mountain Standard Time
162 MDT
= GMT_6
, // Mountain Daylight Saving Time
163 PST
= GMT_8
, // Pacific Standard Time
164 PDT
= GMT_7
, // Pacific Daylight Saving Time
165 HST
= GMT_10
, // Hawaiian Standard Time
166 AKST
= GMT_9
, // Alaska Standard Time
167 AKDT
= GMT_8
, // Alaska Daylight Saving Time
171 A_WST
= GMT8
, // Western Standard Time
172 A_CST
= GMT12
+ 1, // Central Standard Time (+9.5)
173 A_EST
= GMT10
, // Eastern Standard Time
174 A_ESST
= GMT11
, // Eastern Summer Time
176 // TODO add more symbolic timezone names here
178 // Universal Coordinated Time = the new and politically correct name
183 // the calendar systems we know about: notice that it's valid (for
184 // this classes purpose anyhow) to work with any of these calendars
185 // even with the dates before the historical appearance of the
189 Gregorian
, // current calendar
190 Julian
// calendar in use since -45 until the 1582 (or later)
192 // TODO Hebrew, Chinese, Maya, ... (just kidding) (or then may be not?)
195 // these values only are used to identify the different dates of
196 // adoption of the Gregorian calendar (see IsGregorian())
198 // All data and comments taken verbatim from "The Calendar FAQ (v 2.0)"
199 // by Claus Tøndering, http://www.pip.dknet.dk/~c-t/calendar.html
200 // except for the comments "we take".
202 // Symbol "->" should be read as "was followed by" in the comments
204 enum GregorianAdoption
206 Gr_Unknown
, // no data for this country or it's too uncertain to use
207 Gr_Standard
, // on the day 0 of Gregorian calendar: 15 Oct 1582
209 Gr_Alaska
, // Oct 1867 when Alaska became part of the USA
210 Gr_Albania
, // Dec 1912
212 Gr_Austria
= Gr_Unknown
, // Different regions on different dates
213 Gr_Austria_Brixen
, // 5 Oct 1583 -> 16 Oct 1583
214 Gr_Austria_Salzburg
= Gr_Austria_Brixen
,
215 Gr_Austria_Tyrol
= Gr_Austria_Brixen
,
216 Gr_Austria_Carinthia
, // 14 Dec 1583 -> 25 Dec 1583
217 Gr_Austria_Styria
= Gr_Austria_Carinthia
,
219 Gr_Belgium
, // Then part of the Netherlands
221 Gr_Bulgaria
= Gr_Unknown
, // Unknown precisely (from 1915 to 1920)
222 Gr_Bulgaria_1
, // 18 Mar 1916 -> 1 Apr 1916
223 Gr_Bulgaria_2
, // 31 Mar 1916 -> 14 Apr 1916
224 Gr_Bulgaria_3
, // 3 Sep 1920 -> 17 Sep 1920
226 Gr_Canada
= Gr_Unknown
, // Different regions followed the changes in
227 // Great Britain or France
229 Gr_China
= Gr_Unknown
, // Different authorities say:
230 Gr_China_1
, // 18 Dec 1911 -> 1 Jan 1912
231 Gr_China_2
, // 18 Dec 1928 -> 1 Jan 1929
233 Gr_Czechoslovakia
, // (Bohemia and Moravia) 6 Jan 1584 -> 17 Jan 1584
234 Gr_Denmark
, // (including Norway) 18 Feb 1700 -> 1 Mar 1700
237 Gr_Finland
, // Then part of Sweden
239 Gr_France
, // 9 Dec 1582 -> 20 Dec 1582
240 Gr_France_Alsace
, // 4 Feb 1682 -> 16 Feb 1682
241 Gr_France_Lorraine
, // 16 Feb 1760 -> 28 Feb 1760
242 Gr_France_Strasbourg
, // February 1682
244 Gr_Germany
= Gr_Unknown
, // Different states on different dates:
245 Gr_Germany_Catholic
, // 1583-1585 (we take 1584)
246 Gr_Germany_Prussia
, // 22 Aug 1610 -> 2 Sep 1610
247 Gr_Germany_Protestant
, // 18 Feb 1700 -> 1 Mar 1700
249 Gr_GreatBritain
, // 2 Sep 1752 -> 14 Sep 1752 (use 'cal(1)')
251 Gr_Greece
, // 9 Mar 1924 -> 23 Mar 1924
252 Gr_Hungary
, // 21 Oct 1587 -> 1 Nov 1587
253 Gr_Ireland
= Gr_GreatBritain
,
254 Gr_Italy
= Gr_Standard
,
256 Gr_Japan
= Gr_Unknown
, // Different authorities say:
257 Gr_Japan_1
, // 19 Dec 1872 -> 1 Jan 1873
258 Gr_Japan_2
, // 19 Dec 1892 -> 1 Jan 1893
259 Gr_Japan_3
, // 18 Dec 1918 -> 1 Jan 1919
261 Gr_Latvia
, // 1915-1918 (we take 1915)
262 Gr_Lithuania
, // 1915
263 Gr_Luxemburg
, // 14 Dec 1582 -> 25 Dec 1582
264 Gr_Netherlands
= Gr_Belgium
, // (including Belgium) 1 Jan 1583
266 // this is too weird to take into account: the Gregorian calendar was
267 // introduced twice in Groningen, first time 28 Feb 1583 was followed
268 // by 11 Mar 1583, then it has gone back to Julian in the summer of
269 // 1584 and then 13 Dec 1700 -> 12 Jan 1701 - which is
270 // the date we take here
271 Gr_Netherlands_Groningen
, // 13 Dec 1700 -> 12 Jan 1701
272 Gr_Netherlands_Gelderland
, // 30 Jun 1700 -> 12 Jul 1700
273 Gr_Netherlands_Utrecht
, // (and Overijssel) 30 Nov 1700->12 Dec 1700
274 Gr_Netherlands_Friesland
, // (and Drenthe) 31 Dec 1700 -> 12 Jan 1701
276 Gr_Norway
= Gr_Denmark
, // Then part of Denmark
277 Gr_Poland
= Gr_Standard
,
278 Gr_Portugal
= Gr_Standard
,
279 Gr_Romania
, // 31 Mar 1919 -> 14 Apr 1919
280 Gr_Russia
, // 31 Jan 1918 -> 14 Feb 1918
281 Gr_Scotland
= Gr_GreatBritain
,
282 Gr_Spain
= Gr_Standard
,
284 // Sweden has a curious history. Sweden decided to make a gradual
285 // change from the Julian to the Gregorian calendar. By dropping every
286 // leap year from 1700 through 1740 the eleven superfluous days would
287 // be omitted and from 1 Mar 1740 they would be in sync with the
288 // Gregorian calendar. (But in the meantime they would be in sync with
291 // So 1700 (which should have been a leap year in the Julian calendar)
292 // was not a leap year in Sweden. However, by mistake 1704 and 1708
293 // became leap years. This left Sweden out of synchronisation with
294 // both the Julian and the Gregorian world, so they decided to go back
295 // to the Julian calendar. In order to do this, they inserted an extra
296 // day in 1712, making that year a double leap year! So in 1712,
297 // February had 30 days in Sweden.
299 // Later, in 1753, Sweden changed to the Gregorian calendar by
300 // dropping 11 days like everyone else.
301 Gr_Sweden
= Gr_Finland
, // 17 Feb 1753 -> 1 Mar 1753
303 Gr_Switzerland
= Gr_Unknown
,// Different cantons used different dates
304 Gr_Switzerland_Catholic
, // 1583, 1584 or 1597 (we take 1584)
305 Gr_Switzerland_Protestant
, // 31 Dec 1700 -> 12 Jan 1701
307 Gr_Turkey
, // 1 Jan 1927
308 Gr_USA
= Gr_GreatBritain
,
309 Gr_Wales
= Gr_GreatBritain
,
310 Gr_Yugoslavia
// 1919
313 // the country parameter is used so far for calculating the start and
314 // the end of DST period and for deciding whether the date is a work
317 // TODO move this to intl.h
320 Country_Unknown
, // no special information for this country
321 Country_Default
, // set the default country with SetCountry() method
322 // or use the default country with any other
324 // TODO add more countries (for this we must know about DST and/or
325 // holidays for this country)
327 // Western European countries: we assume that they all follow the same
328 // DST rules (true or false?)
329 Country_WesternEurope_Start
,
330 Country_EEC
= Country_WesternEurope_Start
,
334 Country_WesternEurope_End
= UK
,
341 // symbolic names for the months
344 Jan
, Feb
, Mar
, Apr
, May
, Jun
, Jul
, Aug
, Sep
, Oct
, Nov
, Dec
, Inv_Month
347 // symbolic names for the weekdays
350 Sun
, Mon
, Tue
, Wed
, Thu
, Fri
, Sat
, Inv_WeekDay
353 // invalid value for the year
356 Inv_Year
= SHRT_MIN
// should hold in wxDateTime_t
359 // flags for GetWeekDayName and GetMonthName
362 Name_Full
= 0x01, // return full name
363 Name_Abbr
= 0x02 // return abbreviated name
367 // ------------------------------------------------------------------------
369 // a class representing a time zone: basicly, this is just an offset
370 // (in seconds) from GMT
375 TimeZone(wxDateTime_t offset
= 0) { m_offset
= offset
; }
377 long GetOffset() const { return m_offset
; }
380 // offset for this timezone from GMT in seconds
384 // standard struct tm is limited to the years from 1900 (because
385 // tm_year field is the offset from 1900), so we use our own struct
386 // instead to represent broken down time
388 // NB: this struct should always be kept normalized (i.e. mon should
389 // be < 12, 1 <= day <= 31 &c), so use AddMonths(), AddDays()
390 // instead of modifying the member fields directly!
393 wxDateTime_t msec
, sec
, min
, hour
, mday
;
397 // default ctor inits the object to an invalid value
400 // ctor from struct tm and the timezone
401 Tm(const struct tm
& tm
, const TimeZone
& tz
);
403 // check that the given date/time is valid (in Gregorian calendar)
404 bool IsValid() const;
407 WeekDay
GetWeekDay() // not const because wday may be changed
409 if ( wday
== Inv_WeekDay
)
412 return (WeekDay
)wday
;
415 // add the given number of months to the date keeping it normalized
416 void AddMonths(int monDiff
);
418 // add the given number of months to the date keeping it normalized
419 void AddDays(int dayDiff
);
422 // compute the weekday from other fields
423 void ComputeWeekDay();
425 // the timezone we correspond to
428 // these values can't be accessed directly because they're not always
429 // computed and we calculate them on demand
430 wxDateTime_t wday
, yday
;
434 // ------------------------------------------------------------------------
436 // set the current country
437 static void SetCountry(Country country
);
438 // get the current country
439 static Country
GetCountry();
441 // return TRUE if the country is a West European one (in practice,
442 // this means that the same DST rules as for EEC apply)
443 static bool IsWestEuropeanCountry(Country country
= Country_Default
);
445 // return the current year
446 static int GetCurrentYear(Calendar cal
= Gregorian
);
448 // convert the year as returned by wxDateTime::GetYear() to a year
449 // suitable for BC/AD notation. The difference is that BC year 1
450 // corresponds to the year 0 (while BC year 0 didn't exist) and AD
451 // year N is just year N.
452 static int ConvertYearToBC(int year
);
454 // return the current month
455 static Month
GetCurrentMonth(Calendar cal
= Gregorian
);
457 // returns TRUE if the given year is a leap year in the given calendar
458 static bool IsLeapYear(int year
= Inv_Year
, Calendar cal
= Gregorian
);
460 // get the century (19 for 1999, 20 for 2000 and -5 for 492 BC)
461 static int GetCentury(int year
= Inv_Year
);
463 // returns the number of days in this year (356 or 355 for Gregorian
464 // calendar usually :-)
465 static wxDateTime_t
GetNumberOfDays(int year
, Calendar cal
= Gregorian
);
467 // get the number of the days in the given month (default value for
468 // the year means the current one)
469 static wxDateTime_t
GetNumberOfDays(Month month
,
471 Calendar cal
= Gregorian
);
473 // get the full (default) or abbreviated month name in the current
474 // locale, returns empty string on error
475 static wxString
GetMonthName(Month month
,
476 NameFlags flags
= Name_Full
);
478 // get the full (default) or abbreviated weekday name in the current
479 // locale, returns empty string on error
480 static wxString
GetWeekDayName(WeekDay weekday
,
481 NameFlags flags
= Name_Full
);
483 // get the AM and PM strings in the current locale (may be empty)
484 static void GetAmPmStrings(wxString
*am
, wxString
*pm
);
486 // return TRUE if the given country uses DST for this year
487 static bool IsDSTApplicable(int year
= Inv_Year
,
488 Country country
= Country_Default
);
490 // get the beginning of DST for this year, will return invalid object
491 // if no DST applicable in this year. The default value of the
492 // parameter means to take the current year.
493 static wxDateTime
GetBeginDST(int year
= Inv_Year
,
494 Country country
= Country_Default
);
495 // get the end of DST for this year, will return invalid object
496 // if no DST applicable in this year. The default value of the
497 // parameter means to take the current year.
498 static wxDateTime
GetEndDST(int year
= Inv_Year
,
499 Country country
= Country_Default
);
501 // return the wxDateTime object for the current time
502 static inline wxDateTime
Now();
504 // return the wxDateTime object for today midnight: i.e. as Now() but
505 // with time set to 0
506 static inline wxDateTime
Today();
508 // constructors: you should test whether the constructor succeeded with
509 // IsValid() function. The values Inv_Month and Inv_Year for the
510 // parameters mean take current month and/or year values.
511 // ------------------------------------------------------------------------
513 // default ctor does not initialize the object, use Set()!
516 // from time_t: seconds since the Epoch 00:00:00 UTC, Jan 1, 1970)
517 inline wxDateTime(time_t timet
);
518 // from broken down time/date (only for standard Unix range)
519 inline wxDateTime(const struct tm
& tm
);
520 // from broken down time/date (any range)
521 inline wxDateTime(const Tm
& tm
);
523 // from JDN (beware of rounding errors)
524 inline wxDateTime(double jdn
);
526 // from separate values for each component, date set to today
527 inline wxDateTime(wxDateTime_t hour
,
528 wxDateTime_t minute
= 0,
529 wxDateTime_t second
= 0,
530 wxDateTime_t millisec
= 0);
531 // from separate values for each component with explicit date
532 inline wxDateTime(wxDateTime_t day
, // day of the month
533 Month month
= Inv_Month
,
534 int year
= Inv_Year
, // 1999, not 99 please!
535 wxDateTime_t hour
= 0,
536 wxDateTime_t minute
= 0,
537 wxDateTime_t second
= 0,
538 wxDateTime_t millisec
= 0);
540 // default copy ctor ok
544 // assignment operators and Set() functions: all non const methods return
545 // the reference to this object. IsValid() should be used to test whether
546 // the function succeeded.
547 // ------------------------------------------------------------------------
549 // set to the current time
550 inline wxDateTime
& SetToCurrent();
552 // set to given time_t value
553 inline wxDateTime
& Set(time_t timet
);
555 // set to given broken down time/date
556 wxDateTime
& Set(const struct tm
& tm
);
558 // set to given broken down time/date
559 inline wxDateTime
& Set(const Tm
& tm
);
561 // set to given JDN (beware of rounding errors)
562 wxDateTime
& Set(double jdn
);
564 // set to given time, date = today
565 wxDateTime
& Set(wxDateTime_t hour
,
566 wxDateTime_t minute
= 0,
567 wxDateTime_t second
= 0,
568 wxDateTime_t millisec
= 0);
570 // from separate values for each component with explicit date
571 // (defaults for month and year are the current values)
572 wxDateTime
& Set(wxDateTime_t day
,
573 Month month
= Inv_Month
,
574 int year
= Inv_Year
, // 1999, not 99 please!
575 wxDateTime_t hour
= 0,
576 wxDateTime_t minute
= 0,
577 wxDateTime_t second
= 0,
578 wxDateTime_t millisec
= 0);
580 // resets time to 00:00:00, doesn't change the date
581 wxDateTime
& ResetTime();
583 // the following functions don't change the values of the other
584 // fields, i.e. SetMinute() won't change either hour or seconds value
587 wxDateTime
& SetYear(int year
);
589 wxDateTime
& SetMonth(Month month
);
590 // set the day of the month
591 wxDateTime
& SetDay(wxDateTime_t day
);
593 wxDateTime
& SetHour(wxDateTime_t hour
);
595 wxDateTime
& SetMinute(wxDateTime_t minute
);
597 wxDateTime
& SetSecond(wxDateTime_t second
);
599 wxDateTime
& SetMillisecond(wxDateTime_t millisecond
);
601 // assignment operator from time_t
602 wxDateTime
& operator=(time_t timet
) { return Set(timet
); }
604 // assignment operator from broken down time/date
605 wxDateTime
& operator=(const struct tm
& tm
) { return Set(tm
); }
607 // assignment operator from broken down time/date
608 wxDateTime
& operator=(const Tm
& tm
) { return Set(tm
); }
610 // default assignment operator is ok
612 // calendar calculations (functions which set the date only leave the time
613 // unchanged, e.g. don't explictly zero it)
614 // ------------------------------------------------------------------------
616 // set to the given week day in the same week as this one
617 wxDateTime
& SetToWeekDayInSameWeek(WeekDay weekday
);
619 // set to the next week day following this one
620 wxDateTime
& SetToNextWeekDay(WeekDay weekday
);
622 // set to the previous week day before this one
623 wxDateTime
& SetToPrevWeekDay(WeekDay weekday
);
625 // set to Nth occurence of given weekday in the given month of the
626 // given year (time is set to 0), return TRUE on success and FALSE on
627 // failure. n may be positive (1..5) or negative to count from the end
628 // of the month (see helper function SetToLastWeekDay())
629 bool SetToWeekDay(WeekDay weekday
,
631 Month month
= Inv_Month
,
632 int year
= Inv_Year
);
634 // sets to the last weekday in the given month, year
635 inline bool SetToLastWeekDay(WeekDay weekday
,
636 Month month
= Inv_Month
,
637 int year
= Inv_Year
);
639 // sets the date to the given day of the given week in the year,
640 // returns TRUE on success and FALSE if given date doesn't exist (e.g.
642 bool SetToTheWeek(wxDateTime_t numWeek
, WeekDay weekday
= Mon
);
644 // sets the date to the last day of the given (or current) month or the
645 // given (or current) year
646 wxDateTime
& SetToLastMonthDay(Month month
= Inv_Month
,
647 int year
= Inv_Year
);
649 // sets to the given year day (1..365 or 366)
650 wxDateTime
& SetToYearDay(wxDateTime_t yday
);
652 // The definitions below were taken verbatim from
654 // http://www.capecod.net/~pbaum/date/date0.htm
656 // (Peter Baum's home page)
658 // definition: The Julian Day Number, Julian Day, or JD of a
659 // particular instant of time is the number of days and fractions of a
660 // day since 12 hours Universal Time (Greenwich mean noon) on January
661 // 1 of the year -4712, where the year is given in the Julian
662 // proleptic calendar. The idea of using this reference date was
663 // originally proposed by Joseph Scalizer in 1582 to count years but
664 // it was modified by 19th century astronomers to count days. One
665 // could have equivalently defined the reference time to be noon of
666 // November 24, -4713 if were understood that Gregorian calendar rules
667 // were applied. Julian days are Julian Day Numbers and are not to be
668 // confused with Julian dates.
670 // definition: The Rata Die number is a date specified as the number
671 // of days relative to a base date of December 31 of the year 0. Thus
672 // January 1 of the year 1 is Rata Die day 1.
674 // get the Julian Day number (the fractional part specifies the time of
675 // the day, related to noon - beware of rounding errors!)
676 double GetJulianDayNumber() const;
677 double GetJDN() const { return GetJulianDayNumber(); }
679 // get the Modified Julian Day number: it is equal to JDN - 2400000.5
680 // and so integral MJDs correspond to the midnights (and not noons).
681 // MJD 0 is Nov 17, 1858
682 double GetModifiedJulianDayNumber() const { return GetJDN() - 2400000.5; }
683 double GetMJD() const { return GetModifiedJulianDayNumber(); }
685 // get the Rata Die number
686 double GetRataDie() const;
688 // TODO algorithms for calculating some important dates, such as
689 // religious holidays (Easter...) or moon/solar eclipses? Some
690 // algorithms can be found in the calendar FAQ
692 // timezone stuff: a wxDateTime object constructed using given
693 // day/month/year/hour/min/sec values correspond to this moment in local
694 // time. Using the functions below, it may be converted to another time
695 // zone (for example, the Unix epoch is wxDateTime(1, Jan, 1970).ToGMT())
697 // these functions try to handle DST internally, but there is no magical
698 // way to know all rules for it in all countries in the world, so if the
699 // program can handle it itself (or doesn't want to handle it at all for
700 // whatever reason), the DST handling can be disabled with noDST.
702 // Converting to the local time zone doesn't do anything.
703 // ------------------------------------------------------------------------
705 // transform to any given timezone
706 inline wxDateTime
ToTimezone(const TimeZone
& tz
, bool noDST
= FALSE
) const;
707 wxDateTime
& MakeTimezone(const TimeZone
& tz
, bool noDST
= FALSE
);
709 // transform to GMT/UTC
710 wxDateTime
ToGMT(bool noDST
= FALSE
) const { return ToTimezone(GMT0
, noDST
); }
711 wxDateTime
& MakeGMT(bool noDST
= FALSE
) { return MakeTimezone(GMT0
, noDST
); }
713 // is daylight savings time in effect at this moment according to the
714 // rules of the specified country?
716 // Return value is > 0 if DST is in effect, 0 if it is not and -1 if
717 // the information is not available (this is compatible with ANSI C)
718 int IsDST(Country country
= Country_Default
) const;
720 // accessors: many of them take the timezone parameter which indicates the
721 // timezone for which to make the calculations and the default value means
722 // to do it for the current timezone of this machine (even if the function
723 // only operates with the date it's necessary because a date may wrap as
724 // result of timezone shift)
725 // ------------------------------------------------------------------------
727 // is the date valid (TRUE even for non initialized objects)?
728 inline bool IsValid() const { return this != &wxInvalidDateTime
; }
730 // get the broken down date/time representation in the given timezone
732 // If you wish to get several time components (day, month and year),
733 // consider getting the whole Tm strcuture first and retrieving the
734 // value from it - this is much more efficient
735 Tm
GetTm(const TimeZone
& tz
= Local
) const;
737 // get the number of seconds since the Unix epoch - returns (time_t)-1
738 // if the value is out of range
739 inline time_t GetTicks() const;
741 // get the year (returns Inv_Year if date is invalid)
742 int GetYear(const TimeZone
& tz
= Local
) const
743 { return GetTm(tz
).year
; }
744 // get the month (Inv_Month if date is invalid)
745 Month
GetMonth(const TimeZone
& tz
= Local
) const
746 { return (Month
)GetTm(tz
).mon
; }
747 // get the month day (in 1..31 range, 0 if date is invalid)
748 wxDateTime_t
GetDay(const TimeZone
& tz
= Local
) const
749 { return GetTm(tz
).mday
; }
750 // get the day of the week (Inv_WeekDay if date is invalid)
751 WeekDay
GetWeekDay(const TimeZone
& tz
= Local
) const
752 { return GetTm(tz
).GetWeekDay(); }
753 // get the hour of the day
754 wxDateTime_t
GetHour(const TimeZone
& tz
= Local
) const
755 { return GetTm(tz
).hour
; }
757 wxDateTime_t
GetMinute(const TimeZone
& tz
= Local
) const
758 { return GetTm(tz
).min
; }
760 wxDateTime_t
GetSecond(const TimeZone
& tz
= Local
) const
761 { return GetTm(tz
).sec
; }
763 wxDateTime_t
GetMillisecond(const TimeZone
& tz
= Local
) const
764 { return GetTm(tz
).msec
; }
766 // get the day since the year start (1..366, 0 if date is invalid)
767 wxDateTime_t
GetDayOfYear(const TimeZone
& tz
= Local
) const;
768 // get the week number since the year start (1..52 or 53, 0 if date is
770 wxDateTime_t
GetWeekOfYear(const TimeZone
& tz
= Local
) const;
771 // get the week number since the month start (1..5, 0 if date is
773 wxDateTime_t
GetWeekOfMonth(const TimeZone
& tz
= Local
) const;
775 // is this date a work day? This depends on a country, of course,
776 // because the holidays are different in different countries
777 bool IsWorkDay(Country country
= Country_Default
,
778 const TimeZone
& tz
= Local
) const;
780 // is this date later than Gregorian calendar introduction for the
781 // given country (see enum GregorianAdoption)?
783 // NB: this function shouldn't be considered as absolute authoiruty in
784 // the matter. Besides, for some countries the exact date of
785 // adoption of the Gregorian calendar is simply unknown.
786 bool IsGregorianDate(GregorianAdoption country
= Gr_Standard
) const;
788 // comparison (see also functions below for operator versions)
789 // ------------------------------------------------------------------------
791 // returns TRUE if the two moments are strictly identical
792 inline bool IsEqualTo(const wxDateTime
& datetime
) const;
794 // returns TRUE if the date is strictly earlier than the given one
795 inline bool IsEarlierThan(const wxDateTime
& datetime
) const;
797 // returns TRUE if the date is strictly later than the given one
798 inline bool IsLaterThan(const wxDateTime
& datetime
) const;
800 // returns TRUE if the date is strictly in the given range
801 inline bool IsStrictlyBetween(const wxDateTime
& t1
,
802 const wxDateTime
& t2
) const;
804 // returns TRUE if the date is in the given range
805 inline bool IsBetween(const wxDateTime
& t1
, const wxDateTime
& t2
) const;
807 // do these two objects refer to the same date?
808 inline bool IsSameDate(const wxDateTime
& dt
) const;
810 // do these two objects have the same time?
811 inline bool IsSameTime(const wxDateTime
& dt
) const;
813 // are these two objects equal up to given timespan?
814 inline bool IsEqualUpTo(const wxDateTime
& dt
, const wxTimeSpan
& ts
) const;
816 // arithmetics with dates (see also below for more operators)
817 // ------------------------------------------------------------------------
819 // return the sum of the date with a time span (positive or negative)
820 inline wxDateTime
Add(const wxTimeSpan
& diff
) const;
821 // add a time span (positive or negative)
822 inline wxDateTime
& Add(const wxTimeSpan
& diff
);
823 // add a time span (positive or negative)
824 inline wxDateTime
& operator+=(const wxTimeSpan
& diff
);
826 // return the difference of the date with a time span
827 inline wxDateTime
Substract(const wxTimeSpan
& diff
) const;
828 // substract a time span (positive or negative)
829 inline wxDateTime
& Substract(const wxTimeSpan
& diff
);
830 // substract a time span (positive or negative)
831 inline wxDateTime
& operator-=(const wxTimeSpan
& diff
);
833 // return the sum of the date with a date span
834 inline wxDateTime
Add(const wxDateSpan
& diff
) const;
835 // add a date span (positive or negative)
836 wxDateTime
& Add(const wxDateSpan
& diff
);
837 // add a date span (positive or negative)
838 inline wxDateTime
& operator+=(const wxDateSpan
& diff
);
840 // return the difference of the date with a date span
841 inline wxDateTime
Substract(const wxDateSpan
& diff
) const;
842 // substract a date span (positive or negative)
843 inline wxDateTime
& Substract(const wxDateSpan
& diff
);
844 // substract a date span (positive or negative)
845 inline wxDateTime
& operator-=(const wxDateSpan
& diff
);
847 // return the difference between two dates
848 inline wxTimeSpan
Substract(const wxDateTime
& dt
) const;
850 // conversion to/from text: all conversions from text return the pointer to
851 // the next character following the date specification (i.e. the one where
852 // the scan had to stop) or NULL on failure.
853 // ------------------------------------------------------------------------
855 // parse a string in RFC 822 format (found e.g. in mail headers and
856 // having the form "Wed, 10 Feb 1999 19:07:07 +0100")
857 const wxChar
*ParseRfc822Date(const wxChar
* date
);
858 // parse a date/time in the given format (see strptime(3)), fill in
859 // the missing (in the string) fields with the values of dateDef (by
860 // default, they will not change if they had valid values or will
861 // default to Today() otherwise)
862 const wxChar
*ParseFormat(const wxChar
*date
,
863 const wxChar
*format
= _T("%c"),
864 const wxDateTime
& dateDef
= wxDefaultDateTime
);
865 // parse a string containing the date/time in "free" format, this
866 // function will try to make an educated guess at the string contents
867 const wxChar
*ParseDateTime(const wxChar
*datetime
);
868 // parse a string containing the date only in "free" format (less
869 // flexible than ParseDateTime)
870 const wxChar
*ParseDate(const wxChar
*date
);
871 // parse a string containing the time only in "free" format
872 const wxChar
*ParseTime(const wxChar
*time
);
874 // this function accepts strftime()-like format string (default
875 // argument corresponds to the preferred date and time representation
876 // for the current locale) and returns the string containing the
877 // resulting text representation
878 wxString
Format(const wxChar
*format
= _T("%c"),
879 const TimeZone
& tz
= Local
) const;
880 // preferred date representation for the current locale
881 wxString
FormatDate() const { return Format(_T("%x")); }
882 // preferred time representation for the current locale
883 wxString
FormatTime() const { return Format(_T("%X")); }
886 // ------------------------------------------------------------------------
888 // construct from internal representation
889 wxDateTime(const wxLongLong
& time
) { m_time
= time
; }
891 // get the internal representation
892 inline wxLongLong
GetValue() const;
894 // a helper function to get the current time_t
895 static time_t GetTimeNow() { return time((time_t *)NULL
); }
897 // another one to get the current time broken down
898 static struct tm
*GetTmNow()
900 time_t t
= GetTimeNow();
901 return localtime(&t
);
905 // the current country - as it's the same for all program objects (unless
906 // it runs on a _really_ big cluster system :-), this is a static member:
907 // see SetCountry() and GetCountry()
908 static Country ms_country
;
910 // this constant is used to transform a time_t value to the internal
911 // representation, as time_t is in seconds and we use milliseconds it's
913 static const long TIME_T_FACTOR
;
915 // returns TRUE if we fall in range in which we can use standard ANSI C
917 inline bool IsInStdRange() const;
919 // the internal representation of the time is the amount of milliseconds
920 // elapsed since the origin which is set by convention to the UNIX/C epoch
921 // value: the midnight of January 1, 1970 (UTC)
925 // ----------------------------------------------------------------------------
926 // This class contains a difference between 2 wxDateTime values, so it makes
927 // sense to add it to wxDateTime and it is the result of substraction of 2
928 // objects of that class. See also wxDateSpan.
929 // ----------------------------------------------------------------------------
931 class WXDLLEXPORT wxTimeSpan
935 // ------------------------------------------------------------------------
937 // return the timespan for the given number of seconds
938 static wxTimeSpan
Seconds(int sec
) { return wxTimeSpan(0, 0, sec
); }
939 static wxTimeSpan
Second() { return Seconds(1); }
941 // return the timespan for the given number of minutes
942 static wxTimeSpan
Minutes(int min
) { return wxTimeSpan(0, min
, 0 ); }
943 static wxTimeSpan
Minute() { return Minutes(1); }
945 // return the timespan for the given number of hours
946 static wxTimeSpan
Hours(int hours
) { return wxTimeSpan(hours
, 0, 0); }
947 static wxTimeSpan
Hour() { return Hours(1); }
949 // return the timespan for the given number of days
950 static wxTimeSpan
Days(int days
) { return Hours(24 * days
); }
951 static wxTimeSpan
Day() { return Days(1); }
953 // return the timespan for the given number of weeks
954 static wxTimeSpan
Weeks(int days
) { return Days(7 * days
); }
955 static wxTimeSpan
Week() { return Weeks(1); }
957 // default ctor constructs the 0 time span
960 // from separate values for each component, date set to 0 (hours are
961 // not restricted to 0..24 range, neither are minutes, seconds or
963 inline wxTimeSpan(int hours
,
966 int milliseconds
= 0);
968 // default copy ctor is ok
972 // arithmetics with time spans (see also below for more operators)
973 // ------------------------------------------------------------------------
975 // return the sum of two timespans
976 inline wxTimeSpan
Add(const wxTimeSpan
& diff
) const;
977 // add two timespans together
978 inline wxTimeSpan
& Add(const wxTimeSpan
& diff
);
979 // add two timespans together
980 wxTimeSpan
& operator+=(const wxTimeSpan
& diff
) { return Add(diff
); }
982 // return the difference of two timespans
983 inline wxTimeSpan
Substract(const wxTimeSpan
& diff
) const;
984 // substract another timespan
985 inline wxTimeSpan
& Substract(const wxTimeSpan
& diff
);
986 // substract another timespan
987 wxTimeSpan
& operator-=(const wxTimeSpan
& diff
) { return Substract(diff
); }
989 // multiply timespan by a scalar
990 inline wxTimeSpan
Multiply(int n
) const;
991 // multiply timespan by a scalar
992 inline wxTimeSpan
& Multiply(int n
);
993 // multiply timespan by a scalar
994 wxTimeSpan
& operator*=(int n
) { return Multiply(n
); }
996 // return this timespan with inversed sign
997 wxTimeSpan
Negate() const { return wxTimeSpan(-GetValue()); }
998 // negate the value of the timespan
999 wxTimeSpan
& Neg() { m_diff
= -GetValue(); return *this; }
1000 // negate the value of the timespan
1001 wxTimeSpan
& operator-() { return Neg(); }
1003 // return the absolute value of the timespan: does _not_ modify the
1005 inline wxTimeSpan
Abs() const;
1007 // there is intentionally no division because we don't want to
1008 // introduce rounding errors in time calculations
1010 // comparaison (see also operator versions below)
1011 // ------------------------------------------------------------------------
1013 // is the timespan null?
1014 bool IsNull() const { return m_diff
== 0l; }
1015 // returns true if the timespan is null
1016 bool operator!() const { return !IsNull(); }
1018 // is the timespan positive?
1019 bool IsPositive() const { return m_diff
> 0l; }
1021 // is the timespan negative?
1022 bool IsNegative() const { return m_diff
< 0l; }
1024 // are two timespans equal?
1025 inline bool IsEqualTo(const wxTimeSpan
& ts
) const;
1026 // compare two timestamps: works with the absolute values, i.e. -2
1027 // hours is longer than 1 hour. Also, it will return FALSE if the
1028 // timespans are equal in absolute value.
1029 inline bool IsLongerThan(const wxTimeSpan
& ts
) const;
1030 // compare two timestamps: works with the absolute values, i.e. 1
1031 // hour is shorter than -2 hours. Also, it will return FALSE if the
1032 // timespans are equal in absolute value.
1033 bool IsShorterThan(const wxTimeSpan
& t
) const { return !IsLongerThan(t
); }
1035 // breaking into days, hours, minutes and seconds
1036 // ------------------------------------------------------------------------
1038 // get the max number of weeks in this timespan
1039 inline int GetWeeks() const;
1040 // get the max number of days in this timespan
1041 inline int GetDays() const;
1042 // get the max number of hours in this timespan
1043 inline int GetHours() const;
1044 // get the max number of minutes in this timespan
1045 inline int GetMinutes() const;
1046 // get the max number of seconds in this timespan
1047 inline wxLongLong
GetSeconds() const;
1048 // get the number of milliseconds in this timespan
1049 wxLongLong
GetMilliseconds() const { return m_diff
; }
1051 // conversion to text
1052 // ------------------------------------------------------------------------
1054 // this function accepts strftime()-like format string (default
1055 // argument corresponds to the preferred date and time representation
1056 // for the current locale) and returns the string containing the
1057 // resulting text representation. Notice that only some of format
1058 // specifiers valid for wxDateTime are valid for wxTimeSpan: hours,
1059 // minutes and seconds make sense, but not "PM/AM" string for example.
1060 wxString
Format(const wxChar
*format
= _T("%c")) const;
1061 // preferred date representation for the current locale
1062 wxString
FormatDate() const { return Format(_T("%x")); }
1063 // preferred time representation for the current locale
1064 wxString
FormatTime() const { return Format(_T("%X")); }
1067 // ------------------------------------------------------------------------
1069 // construct from internal representation
1070 wxTimeSpan(const wxLongLong
& diff
) { m_diff
= diff
; }
1072 // get the internal representation
1073 wxLongLong
GetValue() const { return m_diff
; }
1076 // the (signed) time span in milliseconds
1080 // ----------------------------------------------------------------------------
1081 // This class is a "logical time span" and is useful for implementing program
1082 // logic for such things as "add one month to the date" which, in general,
1083 // doesn't mean to add 60*60*24*31 seconds to it, but to take the same date
1084 // the next month (to understand that this is indeed different consider adding
1085 // one month to Feb, 15 - we want to get Mar, 15, of course).
1087 // When adding a month to the date, all lesser components (days, hours, ...)
1088 // won't be changed.
1090 // wxDateSpan can be either positive or negative. They may be
1091 // multiplied by scalars which multiply all deltas by the scalar: i.e. 2*(1
1092 // month and 1 day) is 2 months and 2 days. They can be added together and
1093 // with wxDateTime or wxTimeSpan, but the type of result is different for each
1096 // Beware about weeks: if you specify both weeks and days, the total number of
1097 // days added will be 7*weeks + days! See also GetTotalDays() function.
1099 // Finally, notice that for adding hours, minutes &c you don't need this
1100 // class: wxTimeSpan will do the job because there are no subtleties
1101 // associated with those.
1102 // ----------------------------------------------------------------------------
1104 class WXDLLEXPORT wxDateSpan
1108 // ------------------------------------------------------------------------
1110 // this many years/months/weeks/days
1111 wxDateSpan(int years
= 0, int months
= 0, int weeks
= 0, int days
= 0)
1119 // get an object for the given number of days
1120 static wxDateSpan
Days(int days
) { return wxDateSpan(0, 0, 0, days
); }
1121 static wxDateSpan
Day() { return Days(1); }
1123 // get an object for the given number of weeks
1124 static wxDateSpan
Weeks(int weeks
) { return wxDateSpan(0, 0, weeks
, 0); }
1125 static wxDateSpan
Week() { return Weeks(1); }
1127 // get an object for the given number of months
1128 static wxDateSpan
Months(int mon
) { return wxDateSpan(0, mon
, 0, 0); }
1129 static wxDateSpan
Month() { return Months(1); }
1131 // get an object for the given number of years
1132 static wxDateSpan
Years(int years
) { return wxDateSpan(years
, 0, 0, 0); }
1133 static wxDateSpan
Year() { return Years(1); }
1135 // default copy ctor is ok
1139 // accessors (all SetXXX() return the (modified) wxDateSpan object)
1140 // ------------------------------------------------------------------------
1142 // set number of years
1143 wxDateSpan
& SetYears(int n
) { m_years
= n
; return *this; }
1144 // set number of months
1145 wxDateSpan
& SetMonths(int n
) { m_months
= n
; return *this; }
1146 // set number of weeks
1147 wxDateSpan
& SetWeeks(int n
) { m_weeks
= n
; return *this; }
1148 // set number of days
1149 wxDateSpan
& SetDays(int n
) { m_days
= n
; return *this; }
1151 // get number of years
1152 int GetYears() const { return m_years
; }
1153 // get number of months
1154 int GetMonths() const { return m_months
; }
1155 // get number of weeks
1156 int GetWeeks() const { return m_weeks
; }
1157 // get number of days
1158 int GetDays() const { return m_days
; }
1159 // returns 7*GetWeeks() + GetDays()
1160 int GetTotalDays() const { return 7*m_weeks
+ m_days
; }
1162 // arithmetics with date spans (see also below for more operators)
1163 // ------------------------------------------------------------------------
1165 // return sum of two date spans
1166 inline wxDateSpan
Add(const wxDateSpan
& other
) const;
1167 // add another wxDateSpan to us
1168 inline wxDateSpan
& Add(const wxDateSpan
& other
);
1169 // add another wxDateSpan to us
1170 inline wxDateSpan
& operator+=(const wxDateSpan
& other
);
1172 // return difference of two date spans
1173 inline wxDateSpan
Substract(const wxDateSpan
& other
) const;
1174 // substract another wxDateSpan from us
1175 inline wxDateSpan
& Substract(const wxDateSpan
& other
);
1176 // substract another wxDateSpan from us
1177 inline wxDateSpan
& operator-=(const wxDateSpan
& other
);
1179 // return a copy of this time span with changed sign
1180 inline wxDateSpan
Negate() const;
1181 // inverse the sign of this timespan
1182 inline wxDateSpan
& Neg();
1183 // inverse the sign of this timespan
1184 wxDateSpan
& operator-() { return Neg(); }
1186 // return the date span proportional to this one with given factor
1187 inline wxDateSpan
Multiply(int factor
) const;
1188 // multiply all components by a (signed) number
1189 inline wxDateSpan
& Multiply(int factor
);
1190 // multiply all components by a (signed) number
1191 inline wxDateSpan
& operator*=(int factor
) { return Multiply(factor
); }
1200 WXDLLEXPORT_DATA(extern wxDateSpan
) wxYear
;
1201 WXDLLEXPORT_DATA(extern wxDateSpan
) wxMonth
;
1202 WXDLLEXPORT_DATA(extern wxDateSpan
) wxWeek
;
1203 WXDLLEXPORT_DATA(extern wxDateSpan
) wxDay
;
1205 // ============================================================================
1206 // inline functions implementation
1207 // ============================================================================
1209 // don't include inline functions definitions when we're included from anything
1210 // else than datetime.cpp in debug builds: this minimizes rebuilds if we change
1211 // some inline function and the performance doesn't matter in the debug builds.
1213 #if !defined(__WXDEBUG__) || defined(wxDEFINE_TIME_CONSTANTS)
1214 #define INCLUDED_FROM_WX_DATETIME_H
1215 #include "wx/datetime.inl"
1216 #undef INCLUDED_FROM_WX_DATETIME_H
1219 // if we defined it to be empty above, restore it now
1222 // ============================================================================
1224 // ============================================================================
1226 // ----------------------------------------------------------------------------
1227 // wxDateTime operators
1228 // ----------------------------------------------------------------------------
1233 // no need to check for validity - the member functions we call will do it
1235 inline wxDateTime WXDLLEXPORT
operator+(const wxDateTime
& dt
,
1236 const wxTimeSpan
& ts
)
1241 inline wxDateTime WXDLLEXPORT
operator-(const wxDateTime
& dt
,
1242 const wxTimeSpan
& ts
)
1244 return dt
.Substract(ts
);
1247 inline wxDateTime WXDLLEXPORT
operator+(const wxDateTime
& dt
,
1248 const wxDateSpan
& ds
)
1253 inline wxDateTime WXDLLEXPORT
operator-(const wxDateTime
& dt
,
1254 const wxDateSpan
& ds
)
1256 return dt
.Substract(ds
);
1259 inline wxTimeSpan WXDLLEXPORT
operator-(const wxDateTime
& dt1
,
1260 const wxDateTime
& dt2
)
1262 return dt1
.Substract(dt2
);
1268 inline bool WXDLLEXPORT
operator<(const wxDateTime
& t1
, const wxDateTime
& t2
)
1270 wxASSERT_MSG( t1
.IsValid() && t2
.IsValid(), _T("invalid wxDateTime") );
1272 return t1
.GetValue() < t2
.GetValue();
1275 inline bool WXDLLEXPORT
operator<=(const wxDateTime
& t1
, const wxDateTime
& t2
)
1277 wxASSERT_MSG( t1
.IsValid() && t2
.IsValid(), _T("invalid wxDateTime") );
1279 return t1
.GetValue() <= t2
.GetValue();
1282 inline bool WXDLLEXPORT
operator>(const wxDateTime
& t1
, const wxDateTime
& t2
)
1284 wxASSERT_MSG( t1
.IsValid() && t2
.IsValid(), _T("invalid wxDateTime") );
1286 return t1
.GetValue() > t2
.GetValue();
1289 inline bool WXDLLEXPORT
operator>=(const wxDateTime
& t1
, const wxDateTime
& t2
)
1291 wxASSERT_MSG( t1
.IsValid() && t2
.IsValid(), _T("invalid wxDateTime") );
1293 return t1
.GetValue() >= t2
.GetValue();
1296 inline bool WXDLLEXPORT
operator==(const wxDateTime
& t1
, const wxDateTime
& t2
)
1298 wxASSERT_MSG( t1
.IsValid() && t2
.IsValid(), _T("invalid wxDateTime") );
1300 return t1
.GetValue() == t2
.GetValue();
1303 inline bool WXDLLEXPORT
operator!=(const wxDateTime
& t1
, const wxDateTime
& t2
)
1305 wxASSERT_MSG( t1
.IsValid() && t2
.IsValid(), _T("invalid wxDateTime") );
1307 return t1
.GetValue() != t2
.GetValue();
1310 // ----------------------------------------------------------------------------
1311 // wxTimeSpan operators
1312 // ----------------------------------------------------------------------------
1317 inline wxTimeSpan WXDLLEXPORT
operator+(const wxTimeSpan
& ts1
,
1318 const wxTimeSpan
& ts2
)
1320 return wxTimeSpan(ts1
.GetValue() + ts2
.GetValue());
1323 inline wxTimeSpan WXDLLEXPORT
operator-(const wxTimeSpan
& ts1
,
1324 const wxTimeSpan
& ts2
)
1326 return wxTimeSpan(ts1
.GetValue() - ts2
.GetValue());
1329 inline wxTimeSpan WXDLLEXPORT
operator*(const wxTimeSpan
& ts
, int n
)
1331 return wxTimeSpan(ts
).Multiply(n
);
1334 inline wxTimeSpan WXDLLEXPORT
operator*(int n
, const wxTimeSpan
& ts
)
1336 return wxTimeSpan(ts
).Multiply(n
);
1342 inline bool WXDLLEXPORT
operator<(const wxTimeSpan
&t1
, const wxTimeSpan
&t2
)
1344 return t1
.GetValue() < t2
.GetValue();
1347 inline bool WXDLLEXPORT
operator<=(const wxTimeSpan
&t1
, const wxTimeSpan
&t2
)
1349 return t1
.GetValue() <= t2
.GetValue();
1352 inline bool WXDLLEXPORT
operator>(const wxTimeSpan
&t1
, const wxTimeSpan
&t2
)
1354 return t1
.GetValue() > t2
.GetValue();
1357 inline bool WXDLLEXPORT
operator>=(const wxTimeSpan
&t1
, const wxTimeSpan
&t2
)
1359 return t1
.GetValue() >= t2
.GetValue();
1362 inline bool WXDLLEXPORT
operator==(const wxTimeSpan
&t1
, const wxTimeSpan
&t2
)
1364 return t1
.GetValue() == t2
.GetValue();
1367 inline bool WXDLLEXPORT
operator!=(const wxTimeSpan
&t1
, const wxTimeSpan
&t2
)
1369 return t1
.GetValue() != t2
.GetValue();
1372 // ----------------------------------------------------------------------------
1374 // ----------------------------------------------------------------------------
1379 inline WXDLLEXPORT wxDateSpan
operator+(const wxDateSpan
& ds1
,
1380 const wxDateSpan
& ds2
)
1382 return wxDateSpan(ds1
.GetYears() + ds2
.GetYears(),
1383 ds1
.GetMonths() + ds2
.GetMonths(),
1384 ds1
.GetWeeks() + ds2
.GetWeeks(),
1385 ds1
.GetDays() + ds2
.GetDays());
1388 inline WXDLLEXPORT wxDateSpan
operator-(const wxDateSpan
& ds1
,
1389 const wxDateSpan
& ds2
)
1391 return wxDateSpan(ds1
.GetYears() - ds2
.GetYears(),
1392 ds1
.GetMonths() - ds2
.GetMonths(),
1393 ds1
.GetWeeks() - ds2
.GetWeeks(),
1394 ds1
.GetDays() - ds2
.GetDays());
1397 inline WXDLLEXPORT wxDateSpan
operator*(const wxDateSpan
& ds
, int n
)
1399 return wxDateSpan(ds
).Multiply(n
);
1402 inline WXDLLEXPORT wxDateSpan
operator*(int n
, const wxDateSpan
& ds
)
1404 return wxDateSpan(ds
).Multiply(n
);
1407 // ============================================================================
1408 // other helper functions
1409 // ============================================================================
1411 // ----------------------------------------------------------------------------
1412 // iteration helpers: can be used to write a for loop over enum variable like
1414 // for ( m = wxDateTime::Jan; m < wxDateTime::Inv_Month; wxNextMonth(m) )
1415 // ----------------------------------------------------------------------------
1417 inline WXDLLEXPORT
void wxNextMonth(wxDateTime
::Month
& m
)
1419 wxASSERT_MSG( m
< wxDateTime
::Inv_Month
, _T("invalid month") );
1421 // no wrapping or the for loop above would never end!
1422 m
= (wxDateTime
::Month
)(m
+ 1);
1425 inline WXDLLEXPORT
void wxPrevMonth(wxDateTime
::Month
& m
)
1427 wxASSERT_MSG( m
< wxDateTime
::Inv_Month
, _T("invalid month") );
1429 m
= m
== wxDateTime
::Jan ? wxDateTime
::Inv_Month
1430 : (wxDateTime
::Month
)(m
- 1);
1433 inline WXDLLEXPORT
void wxNextWDay(wxDateTime
::WeekDay
& wd
)
1435 wxASSERT_MSG( wd
< wxDateTime
::Inv_WeekDay
, _T("invalid week day") );
1437 // no wrapping or the for loop above would never end!
1438 wd
= (wxDateTime
::WeekDay
)(wd
+ 1);
1441 inline WXDLLEXPORT
void wxPrevWDay(wxDateTime
::WeekDay
& wd
)
1443 wxASSERT_MSG( wd
< wxDateTime
::Inv_WeekDay
, _T("invalid week day") );
1445 wd
= wd
== wxDateTime
::Sun ? wxDateTime
::Inv_WeekDay
1446 : (wxDateTime
::WeekDay
)(wd
- 1);
1449 #endif // _WX_DATETIME_H