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 // ----------------------------------------------------------------------------
95 // wxDateTime represents an absolute moment in the time
96 // ----------------------------------------------------------------------------
98 class WXDLLEXPORT wxDateTime
101 // invalid wxDateTime object - returned by all functions which return
102 // "wxDateTime &" on failure.
103 // This variable has to be declared at the start of the class,
104 // or some compilers (e.g. Watcom C++) won't like it being used further down.
105 static wxDateTime ms_InvDateTime
;
109 // ------------------------------------------------------------------------
111 // a small unsigned integer type for storing things like minutes,
112 // seconds &c. It should be at least short (i.e. not char) to contain
113 // the number of milliseconds - it may also be 'int' because there is
114 // no size penalty associated with it in our code, we don't store any
115 // data in this format
116 typedef unsigned short wxDateTime_t
;
119 // ------------------------------------------------------------------------
124 // the time in the current time zone
127 // zones from GMT (= Greenwhich Mean Time): they're guaranteed to be
128 // consequent numbers, so writing something like `GMT0 + offset' is
129 // safe if abs(offset) <= 12
131 // underscore stands for minus
132 GMT_12
, GMT_11
, GMT_10
, GMT_9
, GMT_8
, GMT_7
,
133 GMT_6
, GMT_5
, GMT_4
, GMT_3
, GMT_2
, GMT_1
,
135 GMT1
, GMT2
, GMT3
, GMT4
, GMT5
, GMT6
,
136 GMT7
, GMT8
, GMT9
, GMT10
, GMT11
, GMT12
,
137 // Note that GMT12 and GMT_12 are not the same: there is a difference
138 // of exactly one day between them
140 // some symbolic names for TZ
143 WET
= GMT0
, // Western Europe Time
144 WEST
= GMT1
, // Western Europe Summer Time
145 CET
= GMT1
, // Central Europe Time
146 CEST
= GMT2
, // Central Europe Summer Time
147 EET
= GMT2
, // Eastern Europe Time
148 EEST
= GMT3
, // Eastern Europe Summer Time
149 MSK
= GMT3
, // Moscow Time
150 MSD
= GMT4
, // Moscow Summer Time
153 AST
= GMT_4
, // Atlantic Standard Time
154 ADT
= GMT_3
, // Atlantic Daylight Time
155 EST
= GMT_5
, // Eastern Standard Time
156 EDT
= GMT_4
, // Eastern Daylight Saving Time
157 CST
= GMT_6
, // Central Standard Time
158 CDT
= GMT_5
, // Central Daylight Saving Time
159 MST
= GMT_7
, // Mountain Standard Time
160 MDT
= GMT_6
, // Mountain Daylight Saving Time
161 PST
= GMT_8
, // Pacific Standard Time
162 PDT
= GMT_7
, // Pacific Daylight Saving Time
163 HST
= GMT_10
, // Hawaiian Standard Time
164 AKST
= GMT_9
, // Alaska Standard Time
165 AKDT
= GMT_8
, // Alaska Daylight Saving Time
169 A_WST
= GMT8
, // Western Standard Time
170 A_CST
= GMT12
+ 1, // Central Standard Time (+9.5)
171 A_EST
= GMT10
, // Eastern Standard Time
172 A_ESST
= GMT11
, // Eastern Summer Time
174 // TODO add more symbolic timezone names here
176 // Universal Coordinated Time = the new and politically correct name
181 // the calendar systems we know about: notice that it's valid (for
182 // this classes purpose anyhow) to work with any of these calendars
183 // even with the dates before the historical appearance of the
187 Gregorian
, // current calendar
188 Julian
// calendar in use since -45 until the 1582 (or later)
190 // TODO Hebrew, Chinese, Maya, ... (just kidding) (or then may be not?)
193 // these values only are used to identify the different dates of
194 // adoption of the Gregorian calendar (see IsGregorian())
196 // All data and comments taken verbatim from "The Calendar FAQ (v 2.0)"
197 // by Claus Tøndering, http://www.pip.dknet.dk/~c-t/calendar.html
198 // except for the comments "we take".
200 // Symbol "->" should be read as "was followed by" in the comments
202 enum GregorianAdoption
204 Gr_Unknown
, // no data for this country or it's too uncertain to use
205 Gr_Standard
, // on the day 0 of Gregorian calendar: 15 Oct 1582
207 Gr_Alaska
, // Oct 1867 when Alaska became part of the USA
208 Gr_Albania
, // Dec 1912
210 Gr_Austria
= Gr_Unknown
, // Different regions on different dates
211 Gr_Austria_Brixen
, // 5 Oct 1583 -> 16 Oct 1583
212 Gr_Austria_Salzburg
= Gr_Austria_Brixen
,
213 Gr_Austria_Tyrol
= Gr_Austria_Brixen
,
214 Gr_Austria_Carinthia
, // 14 Dec 1583 -> 25 Dec 1583
215 Gr_Austria_Styria
= Gr_Austria_Carinthia
,
217 Gr_Belgium
, // Then part of the Netherlands
219 Gr_Bulgaria
= Gr_Unknown
, // Unknown precisely (from 1915 to 1920)
220 Gr_Bulgaria_1
, // 18 Mar 1916 -> 1 Apr 1916
221 Gr_Bulgaria_2
, // 31 Mar 1916 -> 14 Apr 1916
222 Gr_Bulgaria_3
, // 3 Sep 1920 -> 17 Sep 1920
224 Gr_Canada
= Gr_Unknown
, // Different regions followed the changes in
225 // Great Britain or France
227 Gr_China
= Gr_Unknown
, // Different authorities say:
228 Gr_China_1
, // 18 Dec 1911 -> 1 Jan 1912
229 Gr_China_2
, // 18 Dec 1928 -> 1 Jan 1929
231 Gr_Czechoslovakia
, // (Bohemia and Moravia) 6 Jan 1584 -> 17 Jan 1584
232 Gr_Denmark
, // (including Norway) 18 Feb 1700 -> 1 Mar 1700
235 Gr_Finland
, // Then part of Sweden
237 Gr_France
, // 9 Dec 1582 -> 20 Dec 1582
238 Gr_France_Alsace
, // 4 Feb 1682 -> 16 Feb 1682
239 Gr_France_Lorraine
, // 16 Feb 1760 -> 28 Feb 1760
240 Gr_France_Strasbourg
, // February 1682
242 Gr_Germany
= Gr_Unknown
, // Different states on different dates:
243 Gr_Germany_Catholic
, // 1583-1585 (we take 1584)
244 Gr_Germany_Prussia
, // 22 Aug 1610 -> 2 Sep 1610
245 Gr_Germany_Protestant
, // 18 Feb 1700 -> 1 Mar 1700
247 Gr_GreatBritain
, // 2 Sep 1752 -> 14 Sep 1752 (use 'cal(1)')
249 Gr_Greece
, // 9 Mar 1924 -> 23 Mar 1924
250 Gr_Hungary
, // 21 Oct 1587 -> 1 Nov 1587
251 Gr_Ireland
= Gr_GreatBritain
,
252 Gr_Italy
= Gr_Standard
,
254 Gr_Japan
= Gr_Unknown
, // Different authorities say:
255 Gr_Japan_1
, // 19 Dec 1872 -> 1 Jan 1873
256 Gr_Japan_2
, // 19 Dec 1892 -> 1 Jan 1893
257 Gr_Japan_3
, // 18 Dec 1918 -> 1 Jan 1919
259 Gr_Latvia
, // 1915-1918 (we take 1915)
260 Gr_Lithuania
, // 1915
261 Gr_Luxemburg
, // 14 Dec 1582 -> 25 Dec 1582
262 Gr_Netherlands
= Gr_Belgium
, // (including Belgium) 1 Jan 1583
264 // this is too weird to take into account: the Gregorian calendar was
265 // introduced twice in Groningen, first time 28 Feb 1583 was followed
266 // by 11 Mar 1583, then it has gone back to Julian in the summer of
267 // 1584 and then 13 Dec 1700 -> 12 Jan 1701 - which is
268 // the date we take here
269 Gr_Netherlands_Groningen
, // 13 Dec 1700 -> 12 Jan 1701
270 Gr_Netherlands_Gelderland
, // 30 Jun 1700 -> 12 Jul 1700
271 Gr_Netherlands_Utrecht
, // (and Overijssel) 30 Nov 1700->12 Dec 1700
272 Gr_Netherlands_Friesland
, // (and Drenthe) 31 Dec 1700 -> 12 Jan 1701
274 Gr_Norway
= Gr_Denmark
, // Then part of Denmark
275 Gr_Poland
= Gr_Standard
,
276 Gr_Portugal
= Gr_Standard
,
277 Gr_Romania
, // 31 Mar 1919 -> 14 Apr 1919
278 Gr_Russia
, // 31 Jan 1918 -> 14 Feb 1918
279 Gr_Scotland
= Gr_GreatBritain
,
280 Gr_Spain
= Gr_Standard
,
282 // Sweden has a curious history. Sweden decided to make a gradual
283 // change from the Julian to the Gregorian calendar. By dropping every
284 // leap year from 1700 through 1740 the eleven superfluous days would
285 // be omitted and from 1 Mar 1740 they would be in sync with the
286 // Gregorian calendar. (But in the meantime they would be in sync with
289 // So 1700 (which should have been a leap year in the Julian calendar)
290 // was not a leap year in Sweden. However, by mistake 1704 and 1708
291 // became leap years. This left Sweden out of synchronisation with
292 // both the Julian and the Gregorian world, so they decided to go back
293 // to the Julian calendar. In order to do this, they inserted an extra
294 // day in 1712, making that year a double leap year! So in 1712,
295 // February had 30 days in Sweden.
297 // Later, in 1753, Sweden changed to the Gregorian calendar by
298 // dropping 11 days like everyone else.
299 Gr_Sweden
= Gr_Finland
, // 17 Feb 1753 -> 1 Mar 1753
301 Gr_Switzerland
= Gr_Unknown
,// Different cantons used different dates
302 Gr_Switzerland_Catholic
, // 1583, 1584 or 1597 (we take 1584)
303 Gr_Switzerland_Protestant
, // 31 Dec 1700 -> 12 Jan 1701
305 Gr_Turkey
, // 1 Jan 1927
306 Gr_USA
= Gr_GreatBritain
,
307 Gr_Wales
= Gr_GreatBritain
,
308 Gr_Yugoslavia
// 1919
311 // the country parameter is used so far for calculating the start and
312 // the end of DST period and for deciding whether the date is a work
315 // TODO move this to intl.h
318 Country_Unknown
, // no special information for this country
319 Country_Default
, // set the default country with SetCountry() method
320 // or use the default country with any other
322 // TODO add more countries (for this we must know about DST and/or
323 // holidays for this country)
325 // Western European countries: we assume that they all follow the same
326 // DST rules (true or false?)
327 Country_WesternEurope_Start
,
328 Country_EEC
= Country_WesternEurope_Start
,
332 Country_WesternEurope_End
= UK
,
339 // symbolic names for the months
342 Jan
, Feb
, Mar
, Apr
, May
, Jun
, Jul
, Aug
, Sep
, Oct
, Nov
, Dec
, Inv_Month
345 // symbolic names for the weekdays
348 Sun
, Mon
, Tue
, Wed
, Thu
, Fri
, Sat
, Inv_WeekDay
351 // invalid value for the year
354 Inv_Year
= SHRT_MIN
// should hold in wxDateTime_t
357 // flags for GetWeekDayName and GetMonthName
360 Name_Full
= 0x01, // return full name
361 Name_Abbr
= 0x02 // return abbreviated name
365 // ------------------------------------------------------------------------
367 // a class representing a time zone: basicly, this is just an offset
368 // (in seconds) from GMT
373 TimeZone(wxDateTime_t offset
= 0) { m_offset
= offset
; }
375 long GetOffset() const { return m_offset
; }
378 // offset for this timezone from GMT in seconds
382 // standard struct tm is limited to the years from 1900 (because
383 // tm_year field is the offset from 1900), so we use our own struct
384 // instead to represent broken down time
386 // NB: this struct should always be kept normalized (i.e. mon should
387 // be < 12, 1 <= day <= 31 &c), so use AddMonths(), AddDays()
388 // instead of modifying the member fields directly!
391 wxDateTime_t msec
, sec
, min
, hour
, mday
;
395 // default ctor inits the object to an invalid value
398 // ctor from struct tm and the timezone
399 Tm(const struct tm
& tm
, const TimeZone
& tz
);
401 // check that the given date/time is valid (in Gregorian calendar)
402 bool IsValid() const;
405 WeekDay
GetWeekDay() // not const because wday may be changed
407 if ( wday
== Inv_WeekDay
)
410 return (WeekDay
)wday
;
413 // add the given number of months to the date keeping it normalized
414 void AddMonths(int monDiff
);
416 // add the given number of months to the date keeping it normalized
417 void AddDays(int dayDiff
);
420 // compute the weekday from other fields
421 void ComputeWeekDay();
423 // the timezone we correspond to
426 // these values can't be accessed directly because they're not always
427 // computed and we calculate them on demand
428 wxDateTime_t wday
, yday
;
432 // ------------------------------------------------------------------------
434 // set the current country
435 static void SetCountry(Country country
);
436 // get the current country
437 static Country
GetCountry();
439 // return TRUE if the country is a West European one (in practice,
440 // this means that the same DST rules as for EEC apply)
441 static bool IsWestEuropeanCountry(Country country
= Country_Default
);
443 // return the current year
444 static int GetCurrentYear(Calendar cal
= Gregorian
);
446 // convert the year as returned by wxDateTime::GetYear() to a year
447 // suitable for BC/AD notation. The difference is that BC year 1
448 // corresponds to the year 0 (while BC year 0 didn't exist) and AD
449 // year N is just year N.
450 static int ConvertYearToBC(int year
);
452 // return the current month
453 static Month
GetCurrentMonth(Calendar cal
= Gregorian
);
455 // returns TRUE if the given year is a leap year in the given calendar
456 static bool IsLeapYear(int year
= Inv_Year
, Calendar cal
= Gregorian
);
458 // get the century (19 for 1999, 20 for 2000 and -5 for 492 BC)
459 static int GetCentury(int year
= Inv_Year
);
461 // returns the number of days in this year (356 or 355 for Gregorian
462 // calendar usually :-)
463 static wxDateTime_t
GetNumberOfDays(int year
, Calendar cal
= Gregorian
);
465 // get the number of the days in the given month (default value for
466 // the year means the current one)
467 static wxDateTime_t
GetNumberOfDays(Month month
,
469 Calendar cal
= Gregorian
);
471 // get the full (default) or abbreviated month name in the current
472 // locale, returns empty string on error
473 static wxString
GetMonthName(Month month
,
474 NameFlags flags
= Name_Full
);
476 // get the full (default) or abbreviated weekday name in the current
477 // locale, returns empty string on error
478 static wxString
GetWeekDayName(WeekDay weekday
,
479 NameFlags flags
= Name_Full
);
481 // get the AM and PM strings in the current locale (may be empty)
482 static void GetAmPmStrings(wxString
*am
, wxString
*pm
);
484 // return TRUE if the given country uses DST for this year
485 static bool IsDSTApplicable(int year
= Inv_Year
,
486 Country country
= Country_Default
);
488 // get the beginning of DST for this year, will return invalid object
489 // if no DST applicable in this year. The default value of the
490 // parameter means to take the current year.
491 static wxDateTime
GetBeginDST(int year
= Inv_Year
,
492 Country country
= Country_Default
);
493 // get the end of DST for this year, will return invalid object
494 // if no DST applicable in this year. The default value of the
495 // parameter means to take the current year.
496 static wxDateTime
GetEndDST(int year
= Inv_Year
,
497 Country country
= Country_Default
);
499 // return the wxDateTime object for the current time
500 static inline wxDateTime
Now();
502 // return the wxDateTime object for today midnight: i.e. as Now() but
503 // with time set to 0
504 static inline wxDateTime
Today();
506 // constructors: you should test whether the constructor succeeded with
507 // IsValid() function. The values Inv_Month and Inv_Year for the
508 // parameters mean take current month and/or year values.
509 // ------------------------------------------------------------------------
511 // default ctor does not initialize the object, use Set()!
514 // from time_t: seconds since the Epoch 00:00:00 UTC, Jan 1, 1970)
515 inline wxDateTime(time_t timet
);
516 // from broken down time/date (only for standard Unix range)
517 inline wxDateTime(const struct tm
& tm
);
518 // from broken down time/date (any range)
519 inline wxDateTime(const Tm
& tm
);
521 // from JDN (beware of rounding errors)
522 inline wxDateTime(double jdn
);
524 // from separate values for each component, date set to today
525 inline wxDateTime(wxDateTime_t hour
,
526 wxDateTime_t minute
= 0,
527 wxDateTime_t second
= 0,
528 wxDateTime_t millisec
= 0);
529 // from separate values for each component with explicit date
530 inline wxDateTime(wxDateTime_t day
, // day of the month
531 Month month
= Inv_Month
,
532 int year
= Inv_Year
, // 1999, not 99 please!
533 wxDateTime_t hour
= 0,
534 wxDateTime_t minute
= 0,
535 wxDateTime_t second
= 0,
536 wxDateTime_t millisec
= 0);
538 // default copy ctor ok
542 // assignment operators and Set() functions: all non const methods return
543 // the reference to this object. IsValid() should be used to test whether
544 // the function succeeded.
545 // ------------------------------------------------------------------------
547 // set to the current time
548 inline wxDateTime
& SetToCurrent();
550 // set to given time_t value
551 inline wxDateTime
& Set(time_t timet
);
553 // set to given broken down time/date
554 wxDateTime
& Set(const struct tm
& tm
);
556 // set to given broken down time/date
557 inline wxDateTime
& Set(const Tm
& tm
);
559 // set to given JDN (beware of rounding errors)
560 wxDateTime
& Set(double jdn
);
562 // set to given time, date = today
563 wxDateTime
& Set(wxDateTime_t hour
,
564 wxDateTime_t minute
= 0,
565 wxDateTime_t second
= 0,
566 wxDateTime_t millisec
= 0);
568 // from separate values for each component with explicit date
569 // (defaults for month and year are the current values)
570 wxDateTime
& Set(wxDateTime_t day
,
571 Month month
= Inv_Month
,
572 int year
= Inv_Year
, // 1999, not 99 please!
573 wxDateTime_t hour
= 0,
574 wxDateTime_t minute
= 0,
575 wxDateTime_t second
= 0,
576 wxDateTime_t millisec
= 0);
578 // resets time to 00:00:00, doesn't change the date
579 wxDateTime
& ResetTime();
581 // the following functions don't change the values of the other
582 // fields, i.e. SetMinute() won't change either hour or seconds value
585 wxDateTime
& SetYear(int year
);
587 wxDateTime
& SetMonth(Month month
);
588 // set the day of the month
589 wxDateTime
& SetDay(wxDateTime_t day
);
591 wxDateTime
& SetHour(wxDateTime_t hour
);
593 wxDateTime
& SetMinute(wxDateTime_t minute
);
595 wxDateTime
& SetSecond(wxDateTime_t second
);
597 wxDateTime
& SetMillisecond(wxDateTime_t millisecond
);
599 // assignment operator from time_t
600 wxDateTime
& operator=(time_t timet
) { return Set(timet
); }
602 // assignment operator from broken down time/date
603 wxDateTime
& operator=(const struct tm
& tm
) { return Set(tm
); }
605 // assignment operator from broken down time/date
606 wxDateTime
& operator=(const Tm
& tm
) { return Set(tm
); }
608 // default assignment operator is ok
610 // calendar calculations (functions which set the date only leave the time
611 // unchanged, e.g. don't explictly zero it)
612 // ------------------------------------------------------------------------
614 // set to the given week day in the same week as this one
615 wxDateTime
& SetToWeekDayInSameWeek(WeekDay weekday
);
617 // set to the next week day following this one
618 wxDateTime
& SetToNextWeekDay(WeekDay weekday
);
620 // set to the previous week day following this one
621 wxDateTime
& SetToPrevWeekDay(WeekDay weekday
);
623 // set to Nth occurence of given weekday in the given month of the
624 // given year (time is set to 0), return TRUE on success and FALSE on
625 // failure. n may be positive (1..5) or negative to count from the end
626 // of the month (see helper function SetToLastWeekDay())
627 bool SetToWeekDay(WeekDay weekday
,
629 Month month
= Inv_Month
,
630 int year
= Inv_Year
);
632 // sets to the last weekday in the given month, year
633 inline bool SetToLastWeekDay(WeekDay weekday
,
634 Month month
= Inv_Month
,
635 int year
= Inv_Year
);
637 // sets the date to the given day of the given week in the year,
638 // returns TRUE on success and FALSE if given date doesn't exist (e.g.
640 bool SetToTheWeek(wxDateTime_t numWeek
, WeekDay weekday
= Mon
);
642 // sets the date to the last day of the given (or current) month or the
643 // given (or current) year
644 wxDateTime
& SetToLastMonthDay(Month month
= Inv_Month
,
645 int year
= Inv_Year
);
647 // sets to the given year day (1..365 or 366)
648 wxDateTime
& SetToYearDay(wxDateTime_t yday
);
650 // The definitions below were taken verbatim from
652 // http://www.capecod.net/~pbaum/date/date0.htm
654 // (Peter Baum's home page)
656 // definition: The Julian Day Number, Julian Day, or JD of a
657 // particular instant of time is the number of days and fractions of a
658 // day since 12 hours Universal Time (Greenwich mean noon) on January
659 // 1 of the year -4712, where the year is given in the Julian
660 // proleptic calendar. The idea of using this reference date was
661 // originally proposed by Joseph Scalizer in 1582 to count years but
662 // it was modified by 19th century astronomers to count days. One
663 // could have equivalently defined the reference time to be noon of
664 // November 24, -4713 if were understood that Gregorian calendar rules
665 // were applied. Julian days are Julian Day Numbers and are not to be
666 // confused with Julian dates.
668 // definition: The Rata Die number is a date specified as the number
669 // of days relative to a base date of December 31 of the year 0. Thus
670 // January 1 of the year 1 is Rata Die day 1.
672 // get the Julian Day number (the fractional part specifies the time of
673 // the day, related to noon - beware of rounding errors!)
674 double GetJulianDayNumber() const;
675 double GetJDN() const { return GetJulianDayNumber(); }
677 // get the Modified Julian Day number: it is equal to JDN - 2400000.5
678 // and so integral MJDs correspond to the midnights (and not noons).
679 // MJD 0 is Nov 17, 1858
680 double GetModifiedJulianDayNumber() const { return GetJDN() - 2400000.5; }
681 double GetMJD() const { return GetModifiedJulianDayNumber(); }
683 // get the Rata Die number
684 double GetRataDie() const;
686 // TODO algorithms for calculating some important dates, such as
687 // religious holidays (Easter...) or moon/solar eclipses? Some
688 // algorithms can be found in the calendar FAQ
690 // timezone stuff: a wxDateTime object constructed using given
691 // day/month/year/hour/min/sec values correspond to this moment in local
692 // time. Using the functions below, it may be converted to another time
693 // zone (for example, the Unix epoch is wxDateTime(1, Jan, 1970).ToGMT())
695 // these functions try to handle DST internally, but there is no magical
696 // way to know all rules for it in all countries in the world, so if the
697 // program can handle it itself (or doesn't want to handle it at all for
698 // whatever reason), the DST handling can be disabled with noDST.
700 // Converting to the local time zone doesn't do anything.
701 // ------------------------------------------------------------------------
703 // transform to any given timezone
704 inline wxDateTime
ToTimezone(const TimeZone
& tz
, bool noDST
= FALSE
) const;
705 wxDateTime
& MakeTimezone(const TimeZone
& tz
, bool noDST
= FALSE
);
707 // transform to GMT/UTC
708 wxDateTime
ToGMT(bool noDST
= FALSE
) const { return ToTimezone(GMT0
, noDST
); }
709 wxDateTime
& MakeGMT(bool noDST
= FALSE
) { return MakeTimezone(GMT0
, noDST
); }
711 // is daylight savings time in effect at this moment according to the
712 // rules of the specified country?
714 // Return value is > 0 if DST is in effect, 0 if it is not and -1 if
715 // the information is not available (this is compatible with ANSI C)
716 int IsDST(Country country
= Country_Default
) const;
718 // accessors: many of them take the timezone parameter which indicates the
719 // timezone for which to make the calculations and the default value means
720 // to do it for the current timezone of this machine (even if the function
721 // only operates with the date it's necessary because a date may wrap as
722 // result of timezone shift)
723 // ------------------------------------------------------------------------
725 // is the date valid (FALSE for uninitialized objects as well as after
726 // the functions which failed to convert the date to supported range)
727 inline bool IsValid() const { return this != &ms_InvDateTime
; }
729 // get the broken down date/time representation in the given timezone
731 // If you wish to get several time components (day, month and year),
732 // consider getting the whole Tm strcuture first and retrieving the
733 // value from it - this is much more efficient
734 Tm
GetTm(const TimeZone
& tz
= Local
) const;
736 // get the number of seconds since the Unix epoch - returns (time_t)-1
737 // if the value is out of range
738 inline time_t GetTicks() const;
740 // get the year (returns Inv_Year if date is invalid)
741 int GetYear(const TimeZone
& tz
= Local
) const
742 { return GetTm(tz
).year
; }
743 // get the month (Inv_Month if date is invalid)
744 Month
GetMonth(const TimeZone
& tz
= Local
) const
745 { return (Month
)GetTm(tz
).mon
; }
746 // get the month day (in 1..31 range, 0 if date is invalid)
747 wxDateTime_t
GetDay(const TimeZone
& tz
= Local
) const
748 { return GetTm(tz
).mday
; }
749 // get the day of the week (Inv_WeekDay if date is invalid)
750 WeekDay
GetWeekDay(const TimeZone
& tz
= Local
) const
751 { return GetTm(tz
).GetWeekDay(); }
752 // get the hour of the day
753 wxDateTime_t
GetHour(const TimeZone
& tz
= Local
) const
754 { return GetTm(tz
).hour
; }
756 wxDateTime_t
GetMinute(const TimeZone
& tz
= Local
) const
757 { return GetTm(tz
).min
; }
759 wxDateTime_t
GetSecond(const TimeZone
& tz
= Local
) const
760 { return GetTm(tz
).sec
; }
762 wxDateTime_t
GetMillisecond(const TimeZone
& tz
= Local
) const
763 { return GetTm(tz
).msec
; }
765 // get the day since the year start (1..366, 0 if date is invalid)
766 wxDateTime_t
GetDayOfYear(const TimeZone
& tz
= Local
) const;
767 // get the week number since the year start (1..52 or 53, 0 if date is
769 wxDateTime_t
GetWeekOfYear(const TimeZone
& tz
= Local
) const;
770 // get the week number since the month start (1..5, 0 if date is
772 wxDateTime_t
GetWeekOfMonth(const TimeZone
& tz
= Local
) const;
774 // is this date a work day? This depends on a country, of course,
775 // because the holidays are different in different countries
776 bool IsWorkDay(Country country
= Country_Default
,
777 const TimeZone
& tz
= Local
) const;
779 // is this date later than Gregorian calendar introduction for the
780 // given country (see enum GregorianAdoption)?
782 // NB: this function shouldn't be considered as absolute authoiruty in
783 // the matter. Besides, for some countries the exact date of
784 // adoption of the Gregorian calendar is simply unknown.
785 bool IsGregorianDate(GregorianAdoption country
= Gr_Standard
) const;
787 // comparison (see also functions below for operator versions)
788 // ------------------------------------------------------------------------
790 // returns TRUE if the two moments are strictly identical
791 inline bool IsEqualTo(const wxDateTime
& datetime
) const;
793 // returns TRUE if the date is strictly earlier than the given one
794 inline bool IsEarlierThan(const wxDateTime
& datetime
) const;
796 // returns TRUE if the date is strictly later than the given one
797 inline bool IsLaterThan(const wxDateTime
& datetime
) const;
799 // returns TRUE if the date is strictly in the given range
800 inline bool IsStrictlyBetween(const wxDateTime
& t1
,
801 const wxDateTime
& t2
) const;
803 // returns TRUE if the date is in the given range
804 inline bool IsBetween(const wxDateTime
& t1
, const wxDateTime
& t2
) const;
806 // do these two objects refer to the same date?
807 inline bool IsSameDate(const wxDateTime
& dt
) const;
809 // do these two objects have the same time?
810 inline bool IsSameTime(const wxDateTime
& dt
) const;
812 // are these two objects equal up to given timespan?
813 inline bool IsEqualUpTo(const wxDateTime
& dt
, const wxTimeSpan
& ts
) const;
815 // arithmetics with dates (see also below for more operators)
816 // ------------------------------------------------------------------------
818 // return the sum of the date with a time span (positive or negative)
819 inline wxDateTime
Add(const wxTimeSpan
& diff
) const;
820 // add a time span (positive or negative)
821 inline wxDateTime
& Add(const wxTimeSpan
& diff
);
822 // add a time span (positive or negative)
823 inline wxDateTime
& operator+=(const wxTimeSpan
& diff
);
825 // return the difference of the date with a time span
826 inline wxDateTime
Substract(const wxTimeSpan
& diff
) const;
827 // substract a time span (positive or negative)
828 inline wxDateTime
& Substract(const wxTimeSpan
& diff
);
829 // substract a time span (positive or negative)
830 inline wxDateTime
& operator-=(const wxTimeSpan
& diff
);
832 // return the sum of the date with a date span
833 inline wxDateTime
Add(const wxDateSpan
& diff
) const;
834 // add a date span (positive or negative)
835 wxDateTime
& Add(const wxDateSpan
& diff
);
836 // add a date span (positive or negative)
837 inline wxDateTime
& operator+=(const wxDateSpan
& diff
);
839 // return the difference of the date with a date span
840 inline wxDateTime
Substract(const wxDateSpan
& diff
) const;
841 // substract a date span (positive or negative)
842 inline wxDateTime
& Substract(const wxDateSpan
& diff
);
843 // substract a date span (positive or negative)
844 inline wxDateTime
& operator-=(const wxDateSpan
& diff
);
846 // return the difference between two dates
847 inline wxTimeSpan
Substract(const wxDateTime
& dt
) const;
849 // conversion to/from text: all conversions from text return the pointer to
850 // the next character following the date specification (i.e. the one where
851 // the scan had to stop) or NULL on failure.
852 // ------------------------------------------------------------------------
854 // parse a string in RFC 822 format (found e.g. in mail headers and
855 // having the form "Wed, 10 Feb 1999 19:07:07 +0100")
856 const wxChar
*ParseRfc822Date(const wxChar
* date
);
857 // parse a date/time in the given format (see strptime(3)), fill in
858 // the missing (in the string) fields with the values of dateDef (by
859 // default, they will not change if they had valid values or will
860 // default to Today() otherwise)
861 const wxChar
*ParseFormat(const wxChar
*date
,
862 const wxChar
*format
= _T("%c"),
863 const wxDateTime
& dateDef
= wxDateTime::ms_InvDateTime
);
864 // parse a string containing the date/time in "free" format, this
865 // function will try to make an educated guess at the string contents
866 const wxChar
*ParseDateTime(const wxChar
*datetime
);
867 // parse a string containing the date only in "free" format (less
868 // flexible than ParseDateTime)
869 const wxChar
*ParseDate(const wxChar
*date
);
870 // parse a string containing the time only in "free" format
871 const wxChar
*ParseTime(const wxChar
*time
);
873 // this function accepts strftime()-like format string (default
874 // argument corresponds to the preferred date and time representation
875 // for the current locale) and returns the string containing the
876 // resulting text representation
877 wxString
Format(const wxChar
*format
= _T("%c"),
878 const TimeZone
& tz
= Local
) const;
879 // preferred date representation for the current locale
880 wxString
FormatDate() const { return Format(_T("%x")); }
881 // preferred time representation for the current locale
882 wxString
FormatTime() const { return Format(_T("%X")); }
885 // ------------------------------------------------------------------------
887 // construct from internal representation
888 wxDateTime(const wxLongLong
& time
) { m_time
= time
; }
890 // get the internal representation
891 inline wxLongLong
GetValue() const;
893 // a helper function to get the current time_t
894 static time_t GetTimeNow() { return time((time_t *)NULL
); }
896 // another one to get the current time broken down
897 static struct tm
*GetTmNow()
899 time_t t
= GetTimeNow();
900 return localtime(&t
);
904 // the current country - as it's the same for all program objects (unless
905 // it runs on a _really_ big cluster system :-), this is a static member:
906 // see SetCountry() and GetCountry()
907 static Country ms_country
;
909 // this constant is used to transform a time_t value to the internal
910 // representation, as time_t is in seconds and we use milliseconds it's
912 static const long TIME_T_FACTOR
;
914 // returns TRUE if we fall in range in which we can use standard ANSI C
916 inline bool IsInStdRange() const;
918 // the internal representation of the time is the amount of milliseconds
919 // elapsed since the origin which is set by convention to the UNIX/C epoch
920 // value: the midnight of January 1, 1970 (UTC)
924 // ----------------------------------------------------------------------------
925 // This class contains a difference between 2 wxDateTime values, so it makes
926 // sense to add it to wxDateTime and it is the result of substraction of 2
927 // objects of that class. See also wxDateSpan.
928 // ----------------------------------------------------------------------------
930 class WXDLLEXPORT wxTimeSpan
934 // ------------------------------------------------------------------------
936 // return the timespan for the given number of seconds
937 static wxTimeSpan
Seconds(int sec
) { return wxTimeSpan(0, 0, sec
); }
938 static wxTimeSpan
Second() { return Seconds(1); }
940 // return the timespan for the given number of minutes
941 static wxTimeSpan
Minutes(int min
) { return wxTimeSpan(0, min
, 0 ); }
942 static wxTimeSpan
Minute() { return Minutes(1); }
944 // return the timespan for the given number of hours
945 static wxTimeSpan
Hours(int hours
) { return wxTimeSpan(hours
, 0, 0); }
946 static wxTimeSpan
Hour() { return Hours(1); }
948 // return the timespan for the given number of days
949 static wxTimeSpan
Days(int days
) { return Hours(24 * days
); }
950 static wxTimeSpan
Day() { return Days(1); }
952 // return the timespan for the given number of weeks
953 static wxTimeSpan
Weeks(int days
) { return Days(7 * days
); }
954 static wxTimeSpan
Week() { return Weeks(1); }
956 // default ctor constructs the 0 time span
959 // from separate values for each component, date set to 0 (hours are
960 // not restricted to 0..24 range, neither are minutes, seconds or
962 inline wxTimeSpan(int hours
,
965 int milliseconds
= 0);
967 // default copy ctor is ok
971 // arithmetics with time spans (see also below for more operators)
972 // ------------------------------------------------------------------------
974 // return the sum of two timespans
975 inline wxTimeSpan
Add(const wxTimeSpan
& diff
) const;
976 // add two timespans together
977 inline wxTimeSpan
& Add(const wxTimeSpan
& diff
);
978 // add two timespans together
979 wxTimeSpan
& operator+=(const wxTimeSpan
& diff
) { return Add(diff
); }
981 // return the difference of two timespans
982 inline wxTimeSpan
Substract(const wxTimeSpan
& diff
) const;
983 // substract another timespan
984 inline wxTimeSpan
& Substract(const wxTimeSpan
& diff
);
985 // substract another timespan
986 wxTimeSpan
& operator-=(const wxTimeSpan
& diff
) { return Substract(diff
); }
988 // multiply timespan by a scalar
989 inline wxTimeSpan
Multiply(int n
) const;
990 // multiply timespan by a scalar
991 inline wxTimeSpan
& Multiply(int n
);
992 // multiply timespan by a scalar
993 wxTimeSpan
& operator*=(int n
) { return Multiply(n
); }
995 // return this timespan with inversed sign
996 wxTimeSpan
Negate() const { return wxTimeSpan(-GetValue()); }
997 // negate the value of the timespan
998 wxTimeSpan
& Neg() { m_diff
= -GetValue(); return *this; }
999 // negate the value of the timespan
1000 wxTimeSpan
& operator-() { return Neg(); }
1002 // return the absolute value of the timespan: does _not_ modify the
1004 inline wxTimeSpan
Abs() const;
1006 // there is intentionally no division because we don't want to
1007 // introduce rounding errors in time calculations
1009 // comparaison (see also operator versions below)
1010 // ------------------------------------------------------------------------
1012 // is the timespan null?
1013 bool IsNull() const { return m_diff
== 0l; }
1014 // returns true if the timespan is null
1015 bool operator!() const { return !IsNull(); }
1017 // is the timespan positive?
1018 bool IsPositive() const { return m_diff
> 0l; }
1020 // is the timespan negative?
1021 bool IsNegative() const { return m_diff
< 0l; }
1023 // are two timespans equal?
1024 inline bool IsEqualTo(const wxTimeSpan
& ts
) const;
1025 // compare two timestamps: works with the absolute values, i.e. -2
1026 // hours is longer than 1 hour. Also, it will return FALSE if the
1027 // timespans are equal in absolute value.
1028 inline bool IsLongerThan(const wxTimeSpan
& ts
) const;
1029 // compare two timestamps: works with the absolute values, i.e. 1
1030 // hour is shorter than -2 hours. Also, it will return FALSE if the
1031 // timespans are equal in absolute value.
1032 bool IsShorterThan(const wxTimeSpan
& t
) const { return !IsLongerThan(t
); }
1034 // breaking into days, hours, minutes and seconds
1035 // ------------------------------------------------------------------------
1037 // get the max number of weeks in this timespan
1038 inline int GetWeeks() const;
1039 // get the max number of days in this timespan
1040 inline int GetDays() const;
1041 // get the max number of hours in this timespan
1042 inline int GetHours() const;
1043 // get the max number of minutes in this timespan
1044 inline int GetMinutes() const;
1045 // get the max number of seconds in this timespan
1046 inline wxLongLong
GetSeconds() const;
1047 // get the number of milliseconds in this timespan
1048 wxLongLong
GetMilliseconds() const { return m_diff
; }
1050 // conversion to text
1051 // ------------------------------------------------------------------------
1053 // this function accepts strftime()-like format string (default
1054 // argument corresponds to the preferred date and time representation
1055 // for the current locale) and returns the string containing the
1056 // resulting text representation. Notice that only some of format
1057 // specifiers valid for wxDateTime are valid for wxTimeSpan: hours,
1058 // minutes and seconds make sense, but not "PM/AM" string for example.
1059 wxString
Format(const wxChar
*format
= _T("%c")) const;
1060 // preferred date representation for the current locale
1061 wxString
FormatDate() const { return Format(_T("%x")); }
1062 // preferred time representation for the current locale
1063 wxString
FormatTime() const { return Format(_T("%X")); }
1066 // ------------------------------------------------------------------------
1068 // construct from internal representation
1069 wxTimeSpan(const wxLongLong
& diff
) { m_diff
= diff
; }
1071 // get the internal representation
1072 wxLongLong
GetValue() const { return m_diff
; }
1075 // the (signed) time span in milliseconds
1079 // ----------------------------------------------------------------------------
1080 // This class is a "logical time span" and is useful for implementing program
1081 // logic for such things as "add one month to the date" which, in general,
1082 // doesn't mean to add 60*60*24*31 seconds to it, but to take the same date
1083 // the next month (to understand that this is indeed different consider adding
1084 // one month to Feb, 15 - we want to get Mar, 15, of course).
1086 // When adding a month to the date, all lesser components (days, hours, ...)
1087 // won't be changed.
1089 // wxDateSpan can be either positive or negative. They may be
1090 // multiplied by scalars which multiply all deltas by the scalar: i.e. 2*(1
1091 // month and 1 day) is 2 months and 2 days. They can be added together and
1092 // with wxDateTime or wxTimeSpan, but the type of result is different for each
1095 // Beware about weeks: if you specify both weeks and days, the total number of
1096 // days added will be 7*weeks + days! See also GetTotalDays() function.
1098 // Finally, notice that for adding hours, minutes &c you don't need this
1099 // class: wxTimeSpan will do the job because there are no subtleties
1100 // associated with those.
1101 // ----------------------------------------------------------------------------
1103 class WXDLLEXPORT wxDateSpan
1107 // ------------------------------------------------------------------------
1109 // this many years/months/weeks/days
1110 wxDateSpan(int years
= 0, int months
= 0, int weeks
= 0, int days
= 0)
1118 // get an object for the given number of days
1119 static wxDateSpan
Days(int days
) { return wxDateSpan(0, 0, 0, days
); }
1120 static wxDateSpan
Day() { return Days(1); }
1122 // get an object for the given number of weeks
1123 static wxDateSpan
Weeks(int weeks
) { return wxDateSpan(0, 0, weeks
, 0); }
1124 static wxDateSpan
Week() { return Weeks(1); }
1126 // get an object for the given number of months
1127 static wxDateSpan
Months(int mon
) { return wxDateSpan(0, mon
, 0, 0); }
1128 static wxDateSpan
Month() { return Months(1); }
1130 // get an object for the given number of years
1131 static wxDateSpan
Years(int years
) { return wxDateSpan(years
, 0, 0, 0); }
1132 static wxDateSpan
Year() { return Years(1); }
1134 // default copy ctor is ok
1138 // accessors (all SetXXX() return the (modified) wxDateSpan object)
1139 // ------------------------------------------------------------------------
1141 // set number of years
1142 wxDateSpan
& SetYears(int n
) { m_years
= n
; return *this; }
1143 // set number of months
1144 wxDateSpan
& SetMonths(int n
) { m_months
= n
; return *this; }
1145 // set number of weeks
1146 wxDateSpan
& SetWeeks(int n
) { m_weeks
= n
; return *this; }
1147 // set number of days
1148 wxDateSpan
& SetDays(int n
) { m_days
= n
; return *this; }
1150 // get number of years
1151 int GetYears() const { return m_years
; }
1152 // get number of months
1153 int GetMonths() const { return m_months
; }
1154 // get number of weeks
1155 int GetWeeks() const { return m_weeks
; }
1156 // get number of days
1157 int GetDays() const { return m_days
; }
1158 // returns 7*GetWeeks() + GetDays()
1159 int GetTotalDays() const { return 7*m_weeks
+ m_days
; }
1161 // arithmetics with date spans (see also below for more operators)
1162 // ------------------------------------------------------------------------
1164 // return sum of two date spans
1165 inline wxDateSpan
Add(const wxDateSpan
& other
) const;
1166 // add another wxDateSpan to us
1167 inline wxDateSpan
& Add(const wxDateSpan
& other
);
1168 // add another wxDateSpan to us
1169 inline wxDateSpan
& operator+=(const wxDateSpan
& other
);
1171 // return difference of two date spans
1172 inline wxDateSpan
Substract(const wxDateSpan
& other
) const;
1173 // substract another wxDateSpan from us
1174 inline wxDateSpan
& Substract(const wxDateSpan
& other
);
1175 // substract another wxDateSpan from us
1176 inline wxDateSpan
& operator-=(const wxDateSpan
& other
);
1178 // return a copy of this time span with changed sign
1179 inline wxDateSpan
Negate() const;
1180 // inverse the sign of this timespan
1181 inline wxDateSpan
& Neg();
1182 // inverse the sign of this timespan
1183 wxDateSpan
& operator-() { return Neg(); }
1185 // return the date span proportional to this one with given factor
1186 inline wxDateSpan
Multiply(int factor
) const;
1187 // multiply all components by a (signed) number
1188 inline wxDateSpan
& Multiply(int factor
);
1189 // multiply all components by a (signed) number
1190 inline wxDateSpan
& operator*=(int factor
) { return Multiply(factor
); }
1199 WXDLLEXPORT_DATA(extern wxDateSpan
) wxYear
;
1200 WXDLLEXPORT_DATA(extern wxDateSpan
) wxMonth
;
1201 WXDLLEXPORT_DATA(extern wxDateSpan
) wxWeek
;
1202 WXDLLEXPORT_DATA(extern wxDateSpan
) wxDay
;
1204 // ============================================================================
1205 // inline functions implementation
1206 // ============================================================================
1208 // don't include inline functions definitions when we're included from anything
1209 // else than datetime.cpp in debug builds: this minimizes rebuilds if we change
1210 // some inline function and the performance doesn't matter in the debug builds.
1212 #if !defined(__WXDEBUG__) || defined(wxDEFINE_TIME_CONSTANTS)
1213 #define INCLUDED_FROM_WX_DATETIME_H
1214 #include "wx/datetime.inl"
1215 #undef INCLUDED_FROM_WX_DATETIME_H
1218 // if we defined it to be empty above, restore it now
1221 // ============================================================================
1223 // ============================================================================
1225 // ----------------------------------------------------------------------------
1226 // wxDateTime operators
1227 // ----------------------------------------------------------------------------
1232 // no need to check for validity - the member functions we call will do it
1234 inline wxDateTime WXDLLEXPORT
operator+(const wxDateTime
& dt
,
1235 const wxTimeSpan
& ts
)
1240 inline wxDateTime WXDLLEXPORT
operator-(const wxDateTime
& dt
,
1241 const wxTimeSpan
& ts
)
1243 return dt
.Substract(ts
);
1246 inline wxDateTime WXDLLEXPORT
operator+(const wxDateTime
& dt
,
1247 const wxDateSpan
& ds
)
1252 inline wxDateTime WXDLLEXPORT
operator-(const wxDateTime
& dt
,
1253 const wxDateSpan
& ds
)
1255 return dt
.Substract(ds
);
1258 inline wxTimeSpan WXDLLEXPORT
operator-(const wxDateTime
& dt1
,
1259 const wxDateTime
& dt2
)
1261 return dt1
.Substract(dt2
);
1267 inline bool WXDLLEXPORT
operator<(const wxDateTime
& t1
, const wxDateTime
& t2
)
1269 wxASSERT_MSG( t1
.IsValid() && t2
.IsValid(), _T("invalid wxDateTime") );
1271 return t1
.GetValue() < t2
.GetValue();
1274 inline bool WXDLLEXPORT
operator<=(const wxDateTime
& t1
, const wxDateTime
& t2
)
1276 wxASSERT_MSG( t1
.IsValid() && t2
.IsValid(), _T("invalid wxDateTime") );
1278 return t1
.GetValue() <= t2
.GetValue();
1281 inline bool WXDLLEXPORT
operator>(const wxDateTime
& t1
, const wxDateTime
& t2
)
1283 wxASSERT_MSG( t1
.IsValid() && t2
.IsValid(), _T("invalid wxDateTime") );
1285 return t1
.GetValue() > t2
.GetValue();
1288 inline bool WXDLLEXPORT
operator>=(const wxDateTime
& t1
, const wxDateTime
& t2
)
1290 wxASSERT_MSG( t1
.IsValid() && t2
.IsValid(), _T("invalid wxDateTime") );
1292 return t1
.GetValue() >= t2
.GetValue();
1295 inline bool WXDLLEXPORT
operator==(const wxDateTime
& t1
, const wxDateTime
& t2
)
1297 wxASSERT_MSG( t1
.IsValid() && t2
.IsValid(), _T("invalid wxDateTime") );
1299 return t1
.GetValue() == t2
.GetValue();
1302 inline bool WXDLLEXPORT
operator!=(const wxDateTime
& t1
, const wxDateTime
& t2
)
1304 wxASSERT_MSG( t1
.IsValid() && t2
.IsValid(), _T("invalid wxDateTime") );
1306 return t1
.GetValue() != t2
.GetValue();
1309 // ----------------------------------------------------------------------------
1310 // wxTimeSpan operators
1311 // ----------------------------------------------------------------------------
1316 inline wxTimeSpan WXDLLEXPORT
operator+(const wxTimeSpan
& ts1
,
1317 const wxTimeSpan
& ts2
)
1319 return wxTimeSpan(ts1
.GetValue() + ts2
.GetValue());
1322 inline wxTimeSpan WXDLLEXPORT
operator-(const wxTimeSpan
& ts1
,
1323 const wxTimeSpan
& ts2
)
1325 return wxTimeSpan(ts1
.GetValue() - ts2
.GetValue());
1328 inline wxTimeSpan WXDLLEXPORT
operator*(const wxTimeSpan
& ts
, int n
)
1330 return wxTimeSpan(ts
).Multiply(n
);
1333 inline wxTimeSpan WXDLLEXPORT
operator*(int n
, const wxTimeSpan
& ts
)
1335 return wxTimeSpan(ts
).Multiply(n
);
1341 inline bool WXDLLEXPORT
operator<(const wxTimeSpan
&t1
, const wxTimeSpan
&t2
)
1343 return t1
.GetValue() < t2
.GetValue();
1346 inline bool WXDLLEXPORT
operator<=(const wxTimeSpan
&t1
, const wxTimeSpan
&t2
)
1348 return t1
.GetValue() <= t2
.GetValue();
1351 inline bool WXDLLEXPORT
operator>(const wxTimeSpan
&t1
, const wxTimeSpan
&t2
)
1353 return t1
.GetValue() > t2
.GetValue();
1356 inline bool WXDLLEXPORT
operator>=(const wxTimeSpan
&t1
, const wxTimeSpan
&t2
)
1358 return t1
.GetValue() >= t2
.GetValue();
1361 inline bool WXDLLEXPORT
operator==(const wxTimeSpan
&t1
, const wxTimeSpan
&t2
)
1363 return t1
.GetValue() == t2
.GetValue();
1366 inline bool WXDLLEXPORT
operator!=(const wxTimeSpan
&t1
, const wxTimeSpan
&t2
)
1368 return t1
.GetValue() != t2
.GetValue();
1371 // ----------------------------------------------------------------------------
1373 // ----------------------------------------------------------------------------
1378 inline WXDLLEXPORT wxDateSpan
operator+(const wxDateSpan
& ds1
,
1379 const wxDateSpan
& ds2
)
1381 return wxDateSpan(ds1
.GetYears() + ds2
.GetYears(),
1382 ds1
.GetMonths() + ds2
.GetMonths(),
1383 ds1
.GetWeeks() + ds2
.GetWeeks(),
1384 ds1
.GetDays() + ds2
.GetDays());
1387 inline WXDLLEXPORT wxDateSpan
operator-(const wxDateSpan
& ds1
,
1388 const wxDateSpan
& ds2
)
1390 return wxDateSpan(ds1
.GetYears() - ds2
.GetYears(),
1391 ds1
.GetMonths() - ds2
.GetMonths(),
1392 ds1
.GetWeeks() - ds2
.GetWeeks(),
1393 ds1
.GetDays() - ds2
.GetDays());
1396 inline WXDLLEXPORT wxDateSpan
operator*(const wxDateSpan
& ds
, int n
)
1398 return wxDateSpan(ds
).Multiply(n
);
1401 inline WXDLLEXPORT wxDateSpan
operator*(int n
, const wxDateSpan
& ds
)
1403 return wxDateSpan(ds
).Multiply(n
);
1406 // ============================================================================
1407 // other helper functions
1408 // ============================================================================
1410 // ----------------------------------------------------------------------------
1411 // iteration helpers: can be used to write a for loop over enum variable like
1413 // for ( m = wxDateTime::Jan; m < wxDateTime::Inv_Month; wxNextMonth(m) )
1414 // ----------------------------------------------------------------------------
1416 inline WXDLLEXPORT
void wxNextMonth(wxDateTime::Month
& m
)
1418 wxASSERT_MSG( m
< wxDateTime::Inv_Month
, _T("invalid month") );
1420 // no wrapping or the for loop above would never end!
1421 m
= (wxDateTime::Month
)(m
+ 1);
1424 inline WXDLLEXPORT
void wxPrevMonth(wxDateTime::Month
& m
)
1426 wxASSERT_MSG( m
< wxDateTime::Inv_Month
, _T("invalid month") );
1428 m
= m
== wxDateTime::Jan
? wxDateTime::Inv_Month
1429 : (wxDateTime::Month
)(m
- 1);
1432 inline WXDLLEXPORT
void wxNextWDay(wxDateTime::WeekDay
& wd
)
1434 wxASSERT_MSG( wd
< wxDateTime::Inv_WeekDay
, _T("invalid week day") );
1436 // no wrapping or the for loop above would never end!
1437 wd
= (wxDateTime::WeekDay
)(wd
+ 1);
1440 inline WXDLLEXPORT
void wxPrevWDay(wxDateTime::WeekDay
& wd
)
1442 wxASSERT_MSG( wd
< wxDateTime::Inv_WeekDay
, _T("invalid week day") );
1444 wd
= wd
== wxDateTime::Sun
? wxDateTime::Inv_WeekDay
1445 : (wxDateTime::WeekDay
)(wd
- 1);
1448 #endif // _WX_DATETIME_H