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 licence
11 /////////////////////////////////////////////////////////////////////////////
13 #ifndef _WX_DATETIME_H
14 #define _WX_DATETIME_H
16 #if defined(__GNUG__) && !defined(__APPLE__)
17 #pragma interface "datetime.h"
25 #include <limits.h> // for INT_MIN
27 #include "wx/longlong.h"
29 class WXDLLIMPEXP_BASE wxDateTime
;
30 class WXDLLIMPEXP_BASE wxTimeSpan
;
31 class WXDLLIMPEXP_BASE wxDateSpan
;
33 #include "wx/dynarray.h"
35 // not all c-runtimes are based on 1/1/1970 being (time_t) 0
36 // set this to the corresponding value in seconds 1/1/1970 has on your
39 #if defined(__WXMAC__) && !defined(__DARWIN__) && __MSL__ < 0x6000
40 #define WX_TIME_BASE_OFFSET ( 2082844800L + 126144000L )
42 #define WX_TIME_BASE_OFFSET 0
47 * + 1. Time zones with minutes (make TimeZone a class)
48 * ? 2. getdate() function like under Solaris
49 * + 3. text conversion for wxDateSpan
50 * + 4. pluggable modules for the workdays calculations
51 * 5. wxDateTimeHolidayAuthority for Easter and other christian feasts
55 The three (main) classes declared in this header represent:
57 1. An absolute moment in the time (wxDateTime)
58 2. A difference between two moments in the time, positive or negative
60 3. A logical difference between two dates expressed in
61 years/months/weeks/days (wxDateSpan)
63 The following arithmetic operations are permitted (all others are not):
68 wxDateTime + wxTimeSpan = wxDateTime
69 wxDateTime + wxDateSpan = wxDateTime
70 wxTimeSpan + wxTimeSpan = wxTimeSpan
71 wxDateSpan + wxDateSpan = wxDateSpan
75 wxDateTime - wxDateTime = wxTimeSpan
76 wxDateTime - wxTimeSpan = wxDateTime
77 wxDateTime - wxDateSpan = wxDateTime
78 wxTimeSpan - wxTimeSpan = wxTimeSpan
79 wxDateSpan - wxDateSpan = wxDateSpan
83 wxTimeSpan * number = wxTimeSpan
84 number * wxTimeSpan = wxTimeSpan
85 wxDateSpan * number = wxDateSpan
86 number * wxDateSpan = wxDateSpan
90 -wxTimeSpan = wxTimeSpan
91 -wxDateSpan = wxDateSpan
93 For each binary operation OP (+, -, *) we have the following operatorOP=() as
94 a method and the method with a symbolic name OPER (Add, Subtract, Multiply)
95 as a synonym for it and another const method with the same name which returns
96 the changed copy of the object and operatorOP() as a global function which is
97 implemented in terms of the const version of OPEN. For the unary - we have
98 operator-() as a method, Neg() as synonym for it and Negate() which returns
99 the copy of the object with the changed sign.
102 // an invalid/default date time object which may be used as the default
103 // argument for arguments of type wxDateTime; it is also returned by all
104 // functions returning wxDateTime on failure (this is why it is also called
105 // wxInvalidDateTime)
106 class WXDLLIMPEXP_BASE wxDateTime
;
108 extern WXDLLIMPEXP_DATA_BASE(const wxDateTime
) wxDefaultDateTime
;
109 #define wxInvalidDateTime wxDefaultDateTime
111 // ----------------------------------------------------------------------------
112 // wxDateTime represents an absolute moment in the time
113 // ----------------------------------------------------------------------------
115 class WXDLLIMPEXP_BASE wxDateTime
119 // ------------------------------------------------------------------------
121 // a small unsigned integer type for storing things like minutes,
122 // seconds &c. It should be at least short (i.e. not char) to contain
123 // the number of milliseconds - it may also be 'int' because there is
124 // no size penalty associated with it in our code, we don't store any
125 // data in this format
126 typedef unsigned short wxDateTime_t
;
129 // ------------------------------------------------------------------------
134 // the time in the current time zone
137 // zones from GMT (= Greenwhich Mean Time): they're guaranteed to be
138 // consequent numbers, so writing something like `GMT0 + offset' is
139 // safe if abs(offset) <= 12
141 // underscore stands for minus
142 GMT_12
, GMT_11
, GMT_10
, GMT_9
, GMT_8
, GMT_7
,
143 GMT_6
, GMT_5
, GMT_4
, GMT_3
, GMT_2
, GMT_1
,
145 GMT1
, GMT2
, GMT3
, GMT4
, GMT5
, GMT6
,
146 GMT7
, GMT8
, GMT9
, GMT10
, GMT11
, GMT12
,
147 // Note that GMT12 and GMT_12 are not the same: there is a difference
148 // of exactly one day between them
150 // some symbolic names for TZ
153 WET
= GMT0
, // Western Europe Time
154 WEST
= GMT1
, // Western Europe Summer Time
155 CET
= GMT1
, // Central Europe Time
156 CEST
= GMT2
, // Central Europe Summer Time
157 EET
= GMT2
, // Eastern Europe Time
158 EEST
= GMT3
, // Eastern Europe Summer Time
159 MSK
= GMT3
, // Moscow Time
160 MSD
= GMT4
, // Moscow Summer Time
163 AST
= GMT_4
, // Atlantic Standard Time
164 ADT
= GMT_3
, // Atlantic Daylight Time
165 EST
= GMT_5
, // Eastern Standard Time
166 EDT
= GMT_4
, // Eastern Daylight Saving Time
167 CST
= GMT_6
, // Central Standard Time
168 CDT
= GMT_5
, // Central Daylight Saving Time
169 MST
= GMT_7
, // Mountain Standard Time
170 MDT
= GMT_6
, // Mountain Daylight Saving Time
171 PST
= GMT_8
, // Pacific Standard Time
172 PDT
= GMT_7
, // Pacific Daylight Saving Time
173 HST
= GMT_10
, // Hawaiian Standard Time
174 AKST
= GMT_9
, // Alaska Standard Time
175 AKDT
= GMT_8
, // Alaska Daylight Saving Time
179 A_WST
= GMT8
, // Western Standard Time
180 A_CST
= GMT12
+ 1, // Central Standard Time (+9.5)
181 A_EST
= GMT10
, // Eastern Standard Time
182 A_ESST
= GMT11
, // Eastern Summer Time
184 // TODO add more symbolic timezone names here
186 // Universal Coordinated Time = the new and politically correct name
191 // the calendar systems we know about: notice that it's valid (for
192 // this classes purpose anyhow) to work with any of these calendars
193 // even with the dates before the historical appearance of the
197 Gregorian
, // current calendar
198 Julian
// calendar in use since -45 until the 1582 (or later)
200 // TODO Hebrew, Chinese, Maya, ... (just kidding) (or then may be not?)
203 // these values only are used to identify the different dates of
204 // adoption of the Gregorian calendar (see IsGregorian())
206 // All data and comments taken verbatim from "The Calendar FAQ (v 2.0)"
207 // by Claus Tøndering, http://www.pip.dknet.dk/~c-t/calendar.html
208 // except for the comments "we take".
210 // Symbol "->" should be read as "was followed by" in the comments
212 enum GregorianAdoption
214 Gr_Unknown
, // no data for this country or it's too uncertain to use
215 Gr_Standard
, // on the day 0 of Gregorian calendar: 15 Oct 1582
217 Gr_Alaska
, // Oct 1867 when Alaska became part of the USA
218 Gr_Albania
, // Dec 1912
220 Gr_Austria
= Gr_Unknown
, // Different regions on different dates
221 Gr_Austria_Brixen
, // 5 Oct 1583 -> 16 Oct 1583
222 Gr_Austria_Salzburg
= Gr_Austria_Brixen
,
223 Gr_Austria_Tyrol
= Gr_Austria_Brixen
,
224 Gr_Austria_Carinthia
, // 14 Dec 1583 -> 25 Dec 1583
225 Gr_Austria_Styria
= Gr_Austria_Carinthia
,
227 Gr_Belgium
, // Then part of the Netherlands
229 Gr_Bulgaria
= Gr_Unknown
, // Unknown precisely (from 1915 to 1920)
230 Gr_Bulgaria_1
, // 18 Mar 1916 -> 1 Apr 1916
231 Gr_Bulgaria_2
, // 31 Mar 1916 -> 14 Apr 1916
232 Gr_Bulgaria_3
, // 3 Sep 1920 -> 17 Sep 1920
234 Gr_Canada
= Gr_Unknown
, // Different regions followed the changes in
235 // Great Britain or France
237 Gr_China
= Gr_Unknown
, // Different authorities say:
238 Gr_China_1
, // 18 Dec 1911 -> 1 Jan 1912
239 Gr_China_2
, // 18 Dec 1928 -> 1 Jan 1929
241 Gr_Czechoslovakia
, // (Bohemia and Moravia) 6 Jan 1584 -> 17 Jan 1584
242 Gr_Denmark
, // (including Norway) 18 Feb 1700 -> 1 Mar 1700
245 Gr_Finland
, // Then part of Sweden
247 Gr_France
, // 9 Dec 1582 -> 20 Dec 1582
248 Gr_France_Alsace
, // 4 Feb 1682 -> 16 Feb 1682
249 Gr_France_Lorraine
, // 16 Feb 1760 -> 28 Feb 1760
250 Gr_France_Strasbourg
, // February 1682
252 Gr_Germany
= Gr_Unknown
, // Different states on different dates:
253 Gr_Germany_Catholic
, // 1583-1585 (we take 1584)
254 Gr_Germany_Prussia
, // 22 Aug 1610 -> 2 Sep 1610
255 Gr_Germany_Protestant
, // 18 Feb 1700 -> 1 Mar 1700
257 Gr_GreatBritain
, // 2 Sep 1752 -> 14 Sep 1752 (use 'cal(1)')
259 Gr_Greece
, // 9 Mar 1924 -> 23 Mar 1924
260 Gr_Hungary
, // 21 Oct 1587 -> 1 Nov 1587
261 Gr_Ireland
= Gr_GreatBritain
,
262 Gr_Italy
= Gr_Standard
,
264 Gr_Japan
= Gr_Unknown
, // Different authorities say:
265 Gr_Japan_1
, // 19 Dec 1872 -> 1 Jan 1873
266 Gr_Japan_2
, // 19 Dec 1892 -> 1 Jan 1893
267 Gr_Japan_3
, // 18 Dec 1918 -> 1 Jan 1919
269 Gr_Latvia
, // 1915-1918 (we take 1915)
270 Gr_Lithuania
, // 1915
271 Gr_Luxemburg
, // 14 Dec 1582 -> 25 Dec 1582
272 Gr_Netherlands
= Gr_Belgium
, // (including Belgium) 1 Jan 1583
274 // this is too weird to take into account: the Gregorian calendar was
275 // introduced twice in Groningen, first time 28 Feb 1583 was followed
276 // by 11 Mar 1583, then it has gone back to Julian in the summer of
277 // 1584 and then 13 Dec 1700 -> 12 Jan 1701 - which is
278 // the date we take here
279 Gr_Netherlands_Groningen
, // 13 Dec 1700 -> 12 Jan 1701
280 Gr_Netherlands_Gelderland
, // 30 Jun 1700 -> 12 Jul 1700
281 Gr_Netherlands_Utrecht
, // (and Overijssel) 30 Nov 1700->12 Dec 1700
282 Gr_Netherlands_Friesland
, // (and Drenthe) 31 Dec 1700 -> 12 Jan 1701
284 Gr_Norway
= Gr_Denmark
, // Then part of Denmark
285 Gr_Poland
= Gr_Standard
,
286 Gr_Portugal
= Gr_Standard
,
287 Gr_Romania
, // 31 Mar 1919 -> 14 Apr 1919
288 Gr_Russia
, // 31 Jan 1918 -> 14 Feb 1918
289 Gr_Scotland
= Gr_GreatBritain
,
290 Gr_Spain
= Gr_Standard
,
292 // Sweden has a curious history. Sweden decided to make a gradual
293 // change from the Julian to the Gregorian calendar. By dropping every
294 // leap year from 1700 through 1740 the eleven superfluous days would
295 // be omitted and from 1 Mar 1740 they would be in sync with the
296 // Gregorian calendar. (But in the meantime they would be in sync with
299 // So 1700 (which should have been a leap year in the Julian calendar)
300 // was not a leap year in Sweden. However, by mistake 1704 and 1708
301 // became leap years. This left Sweden out of synchronisation with
302 // both the Julian and the Gregorian world, so they decided to go back
303 // to the Julian calendar. In order to do this, they inserted an extra
304 // day in 1712, making that year a double leap year! So in 1712,
305 // February had 30 days in Sweden.
307 // Later, in 1753, Sweden changed to the Gregorian calendar by
308 // dropping 11 days like everyone else.
309 Gr_Sweden
= Gr_Finland
, // 17 Feb 1753 -> 1 Mar 1753
311 Gr_Switzerland
= Gr_Unknown
,// Different cantons used different dates
312 Gr_Switzerland_Catholic
, // 1583, 1584 or 1597 (we take 1584)
313 Gr_Switzerland_Protestant
, // 31 Dec 1700 -> 12 Jan 1701
315 Gr_Turkey
, // 1 Jan 1927
316 Gr_USA
= Gr_GreatBritain
,
317 Gr_Wales
= Gr_GreatBritain
,
318 Gr_Yugoslavia
// 1919
321 // the country parameter is used so far for calculating the start and
322 // the end of DST period and for deciding whether the date is a work
325 // TODO move this to intl.h
328 Country_Unknown
, // no special information for this country
329 Country_Default
, // set the default country with SetCountry() method
330 // or use the default country with any other
332 // TODO add more countries (for this we must know about DST and/or
333 // holidays for this country)
335 // Western European countries: we assume that they all follow the same
336 // DST rules (true or false?)
337 Country_WesternEurope_Start
,
338 Country_EEC
= Country_WesternEurope_Start
,
342 Country_WesternEurope_End
= UK
,
349 // symbolic names for the months
352 Jan
, Feb
, Mar
, Apr
, May
, Jun
, Jul
, Aug
, Sep
, Oct
, Nov
, Dec
, Inv_Month
355 // symbolic names for the weekdays
358 Sun
, Mon
, Tue
, Wed
, Thu
, Fri
, Sat
, Inv_WeekDay
361 // invalid value for the year
364 Inv_Year
= SHRT_MIN
// should hold in wxDateTime_t
367 // flags for GetWeekDayName and GetMonthName
370 Name_Full
= 0x01, // return full name
371 Name_Abbr
= 0x02 // return abbreviated name
374 // flags for GetWeekOfYear and GetWeekOfMonth
377 Default_First
, // Sunday_First for US, Monday_First for the rest
378 Monday_First
, // week starts with a Monday
379 Sunday_First
// week starts with a Sunday
383 // ------------------------------------------------------------------------
385 // a class representing a time zone: basicly, this is just an offset
386 // (in seconds) from GMT
387 class WXDLLIMPEXP_BASE TimeZone
391 TimeZone(wxDateTime_t offset
= 0) { m_offset
= offset
; }
393 long GetOffset() const { return m_offset
; }
396 // offset for this timezone from GMT in seconds
400 // standard struct tm is limited to the years from 1900 (because
401 // tm_year field is the offset from 1900), so we use our own struct
402 // instead to represent broken down time
404 // NB: this struct should always be kept normalized (i.e. mon should
405 // be < 12, 1 <= day <= 31 &c), so use AddMonths(), AddDays()
406 // instead of modifying the member fields directly!
407 struct WXDLLIMPEXP_BASE Tm
409 wxDateTime_t msec
, sec
, min
, hour
, mday
;
413 // default ctor inits the object to an invalid value
416 // ctor from struct tm and the timezone
417 Tm(const struct tm
& tm
, const TimeZone
& tz
);
419 // check that the given date/time is valid (in Gregorian calendar)
420 bool IsValid() const;
423 WeekDay
GetWeekDay() // not const because wday may be changed
425 if ( wday
== Inv_WeekDay
)
428 return (WeekDay
)wday
;
431 // add the given number of months to the date keeping it normalized
432 void AddMonths(int monDiff
);
434 // add the given number of months to the date keeping it normalized
435 void AddDays(int dayDiff
);
438 // compute the weekday from other fields
439 void ComputeWeekDay();
441 // the timezone we correspond to
444 // these values can't be accessed directly because they're not always
445 // computed and we calculate them on demand
446 wxDateTime_t wday
, yday
;
450 // ------------------------------------------------------------------------
452 // set the current country
453 static void SetCountry(Country country
);
454 // get the current country
455 static Country
GetCountry();
457 // return TRUE if the country is a West European one (in practice,
458 // this means that the same DST rules as for EEC apply)
459 static bool IsWestEuropeanCountry(Country country
= Country_Default
);
461 // return the current year
462 static int GetCurrentYear(Calendar cal
= Gregorian
);
464 // convert the year as returned by wxDateTime::GetYear() to a year
465 // suitable for BC/AD notation. The difference is that BC year 1
466 // corresponds to the year 0 (while BC year 0 didn't exist) and AD
467 // year N is just year N.
468 static int ConvertYearToBC(int year
);
470 // return the current month
471 static Month
GetCurrentMonth(Calendar cal
= Gregorian
);
473 // returns TRUE if the given year is a leap year in the given calendar
474 static bool IsLeapYear(int year
= Inv_Year
, Calendar cal
= Gregorian
);
476 // get the century (19 for 1999, 20 for 2000 and -5 for 492 BC)
477 static int GetCentury(int year
= Inv_Year
);
479 // returns the number of days in this year (356 or 355 for Gregorian
480 // calendar usually :-)
481 static wxDateTime_t
GetNumberOfDays(int year
, Calendar cal
= Gregorian
);
483 // get the number of the days in the given month (default value for
484 // the year means the current one)
485 static wxDateTime_t
GetNumberOfDays(Month month
,
487 Calendar cal
= Gregorian
);
489 // get the full (default) or abbreviated month name in the current
490 // locale, returns empty string on error
491 static wxString
GetMonthName(Month month
,
492 NameFlags flags
= Name_Full
);
494 // get the full (default) or abbreviated weekday name in the current
495 // locale, returns empty string on error
496 static wxString
GetWeekDayName(WeekDay weekday
,
497 NameFlags flags
= Name_Full
);
499 // get the AM and PM strings in the current locale (may be empty)
500 static void GetAmPmStrings(wxString
*am
, wxString
*pm
);
502 // return TRUE if the given country uses DST for this year
503 static bool IsDSTApplicable(int year
= Inv_Year
,
504 Country country
= Country_Default
);
506 // get the beginning of DST for this year, will return invalid object
507 // if no DST applicable in this year. The default value of the
508 // parameter means to take the current year.
509 static wxDateTime
GetBeginDST(int year
= Inv_Year
,
510 Country country
= Country_Default
);
511 // get the end of DST for this year, will return invalid object
512 // if no DST applicable in this year. The default value of the
513 // parameter means to take the current year.
514 static wxDateTime
GetEndDST(int year
= Inv_Year
,
515 Country country
= Country_Default
);
517 // return the wxDateTime object for the current time
518 static inline wxDateTime
Now();
520 // return the wxDateTime object for the current time with millisecond
521 // precision (if available on this platform)
522 static wxDateTime
UNow();
524 // return the wxDateTime object for today midnight: i.e. as Now() but
525 // with time set to 0
526 static inline wxDateTime
Today();
528 // constructors: you should test whether the constructor succeeded with
529 // IsValid() function. The values Inv_Month and Inv_Year for the
530 // parameters mean take current month and/or year values.
531 // ------------------------------------------------------------------------
533 // default ctor does not initialize the object, use Set()!
534 wxDateTime() { m_time
= wxLongLong((long)ULONG_MAX
, ULONG_MAX
); }
536 // from time_t: seconds since the Epoch 00:00:00 UTC, Jan 1, 1970)
537 #if (!(defined(__VISAGECPP__) && __IBMCPP__ >= 400))
538 // VA C++ confuses this with wxDateTime(double jdn) thinking it is a duplicate declaration
539 inline wxDateTime(time_t timet
);
541 // from broken down time/date (only for standard Unix range)
542 inline wxDateTime(const struct tm
& tm
);
543 // from broken down time/date (any range)
544 inline wxDateTime(const Tm
& tm
);
546 // from JDN (beware of rounding errors)
547 inline wxDateTime(double jdn
);
549 // from separate values for each component, date set to today
550 inline wxDateTime(wxDateTime_t hour
,
551 wxDateTime_t minute
= 0,
552 wxDateTime_t second
= 0,
553 wxDateTime_t millisec
= 0);
554 // from separate values for each component with explicit date
555 inline wxDateTime(wxDateTime_t day
, // day of the month
557 int year
= Inv_Year
, // 1999, not 99 please!
558 wxDateTime_t hour
= 0,
559 wxDateTime_t minute
= 0,
560 wxDateTime_t second
= 0,
561 wxDateTime_t millisec
= 0);
563 // default copy ctor ok
567 // assignment operators and Set() functions: all non const methods return
568 // the reference to this object. IsValid() should be used to test whether
569 // the function succeeded.
570 // ------------------------------------------------------------------------
572 // set to the current time
573 inline wxDateTime
& SetToCurrent();
575 #if (!(defined(__VISAGECPP__) && __IBMCPP__ >= 400))
576 // VA C++ confuses this with wxDateTime(double jdn) thinking it is a duplicate declaration
577 // set to given time_t value
578 inline wxDateTime
& Set(time_t timet
);
581 // set to given broken down time/date
582 wxDateTime
& Set(const struct tm
& tm
);
584 // set to given broken down time/date
585 inline wxDateTime
& Set(const Tm
& tm
);
587 // set to given JDN (beware of rounding errors)
588 wxDateTime
& Set(double jdn
);
590 // set to given time, date = today
591 wxDateTime
& Set(wxDateTime_t hour
,
592 wxDateTime_t minute
= 0,
593 wxDateTime_t second
= 0,
594 wxDateTime_t millisec
= 0);
596 // from separate values for each component with explicit date
597 // (defaults for month and year are the current values)
598 wxDateTime
& Set(wxDateTime_t day
,
600 int year
= Inv_Year
, // 1999, not 99 please!
601 wxDateTime_t hour
= 0,
602 wxDateTime_t minute
= 0,
603 wxDateTime_t second
= 0,
604 wxDateTime_t millisec
= 0);
606 // resets time to 00:00:00, doesn't change the date
607 wxDateTime
& ResetTime();
609 // the following functions don't change the values of the other
610 // fields, i.e. SetMinute() won't change either hour or seconds value
613 wxDateTime
& SetYear(int year
);
615 wxDateTime
& SetMonth(Month month
);
616 // set the day of the month
617 wxDateTime
& SetDay(wxDateTime_t day
);
619 wxDateTime
& SetHour(wxDateTime_t hour
);
621 wxDateTime
& SetMinute(wxDateTime_t minute
);
623 wxDateTime
& SetSecond(wxDateTime_t second
);
625 wxDateTime
& SetMillisecond(wxDateTime_t millisecond
);
627 // assignment operator from time_t
628 wxDateTime
& operator=(time_t timet
) { return Set(timet
); }
630 // assignment operator from broken down time/date
631 wxDateTime
& operator=(const struct tm
& tm
) { return Set(tm
); }
633 // assignment operator from broken down time/date
634 wxDateTime
& operator=(const Tm
& tm
) { return Set(tm
); }
636 // default assignment operator is ok
638 // calendar calculations (functions which set the date only leave the time
639 // unchanged, e.g. don't explictly zero it): SetXXX() functions modify the
640 // object itself, GetXXX() ones return a new object.
641 // ------------------------------------------------------------------------
643 // set to the given week day in the same week as this one
644 wxDateTime
& SetToWeekDayInSameWeek(WeekDay weekday
,
645 WeekFlags flags
= Monday_First
);
646 inline wxDateTime
GetWeekDayInSameWeek(WeekDay weekday
,
647 WeekFlags flags
= Monday_First
) const;
649 // set to the next week day following this one
650 wxDateTime
& SetToNextWeekDay(WeekDay weekday
);
651 inline wxDateTime
GetNextWeekDay(WeekDay weekday
) const;
653 // set to the previous week day before this one
654 wxDateTime
& SetToPrevWeekDay(WeekDay weekday
);
655 inline wxDateTime
GetPrevWeekDay(WeekDay weekday
) const;
657 // set to Nth occurence of given weekday in the given month of the
658 // given year (time is set to 0), return TRUE on success and FALSE on
659 // failure. n may be positive (1..5) or negative to count from the end
660 // of the month (see helper function SetToLastWeekDay())
661 bool SetToWeekDay(WeekDay weekday
,
663 Month month
= Inv_Month
,
664 int year
= Inv_Year
);
665 inline wxDateTime
GetWeekDay(WeekDay weekday
,
667 Month month
= Inv_Month
,
668 int year
= Inv_Year
) const;
670 // sets to the last weekday in the given month, year
671 inline bool SetToLastWeekDay(WeekDay weekday
,
672 Month month
= Inv_Month
,
673 int year
= Inv_Year
);
674 inline wxDateTime
GetLastWeekDay(WeekDay weekday
,
675 Month month
= Inv_Month
,
676 int year
= Inv_Year
);
678 // sets the date to the given day of the given week in the year,
679 // returns TRUE on success and FALSE if given date doesn't exist (e.g.
681 bool SetToTheWeek(wxDateTime_t numWeek
,
682 WeekDay weekday
= Mon
,
683 WeekFlags flags
= Monday_First
);
684 inline wxDateTime
GetWeek(wxDateTime_t numWeek
,
685 WeekDay weekday
= Mon
,
686 WeekFlags flags
= Monday_First
) const;
688 // sets the date to the last day of the given (or current) month or the
689 // given (or current) year
690 wxDateTime
& SetToLastMonthDay(Month month
= Inv_Month
,
691 int year
= Inv_Year
);
692 inline wxDateTime
GetLastMonthDay(Month month
= Inv_Month
,
693 int year
= Inv_Year
) const;
695 // sets to the given year day (1..365 or 366)
696 wxDateTime
& SetToYearDay(wxDateTime_t yday
);
697 inline wxDateTime
GetYearDay(wxDateTime_t yday
) const;
699 // The definitions below were taken verbatim from
701 // http://www.capecod.net/~pbaum/date/date0.htm
703 // (Peter Baum's home page)
705 // definition: The Julian Day Number, Julian Day, or JD of a
706 // particular instant of time is the number of days and fractions of a
707 // day since 12 hours Universal Time (Greenwich mean noon) on January
708 // 1 of the year -4712, where the year is given in the Julian
709 // proleptic calendar. The idea of using this reference date was
710 // originally proposed by Joseph Scalizer in 1582 to count years but
711 // it was modified by 19th century astronomers to count days. One
712 // could have equivalently defined the reference time to be noon of
713 // November 24, -4713 if were understood that Gregorian calendar rules
714 // were applied. Julian days are Julian Day Numbers and are not to be
715 // confused with Julian dates.
717 // definition: The Rata Die number is a date specified as the number
718 // of days relative to a base date of December 31 of the year 0. Thus
719 // January 1 of the year 1 is Rata Die day 1.
721 // get the Julian Day number (the fractional part specifies the time of
722 // the day, related to noon - beware of rounding errors!)
723 double GetJulianDayNumber() const;
724 double GetJDN() const { return GetJulianDayNumber(); }
726 // get the Modified Julian Day number: it is equal to JDN - 2400000.5
727 // and so integral MJDs correspond to the midnights (and not noons).
728 // MJD 0 is Nov 17, 1858
729 double GetModifiedJulianDayNumber() const { return GetJDN() - 2400000.5; }
730 double GetMJD() const { return GetModifiedJulianDayNumber(); }
732 // get the Rata Die number
733 double GetRataDie() const;
735 // TODO algorithms for calculating some important dates, such as
736 // religious holidays (Easter...) or moon/solar eclipses? Some
737 // algorithms can be found in the calendar FAQ
739 // timezone stuff: a wxDateTime object constructed using given
740 // day/month/year/hour/min/sec values correspond to this moment in local
741 // time. Using the functions below, it may be converted to another time
742 // zone (for example, the Unix epoch is wxDateTime(1, Jan, 1970).ToGMT())
744 // these functions try to handle DST internally, but there is no magical
745 // way to know all rules for it in all countries in the world, so if the
746 // program can handle it itself (or doesn't want to handle it at all for
747 // whatever reason), the DST handling can be disabled with noDST.
749 // Converting to the local time zone doesn't do anything.
750 // ------------------------------------------------------------------------
752 // transform to any given timezone
753 inline wxDateTime
ToTimezone(const TimeZone
& tz
, bool noDST
= FALSE
) const;
754 wxDateTime
& MakeTimezone(const TimeZone
& tz
, bool noDST
= FALSE
);
756 // transform to GMT/UTC
757 wxDateTime
ToGMT(bool noDST
= FALSE
) const { return ToTimezone(GMT0
, noDST
); }
758 wxDateTime
& MakeGMT(bool noDST
= FALSE
) { return MakeTimezone(GMT0
, noDST
); }
760 // is daylight savings time in effect at this moment according to the
761 // rules of the specified country?
763 // Return value is > 0 if DST is in effect, 0 if it is not and -1 if
764 // the information is not available (this is compatible with ANSI C)
765 int IsDST(Country country
= Country_Default
) const;
767 // accessors: many of them take the timezone parameter which indicates the
768 // timezone for which to make the calculations and the default value means
769 // to do it for the current timezone of this machine (even if the function
770 // only operates with the date it's necessary because a date may wrap as
771 // result of timezone shift)
772 // ------------------------------------------------------------------------
774 // is the date valid?
775 inline bool IsValid() const { return m_time
!= wxInvalidDateTime
.m_time
; }
777 // get the broken down date/time representation in the given timezone
779 // If you wish to get several time components (day, month and year),
780 // consider getting the whole Tm strcuture first and retrieving the
781 // value from it - this is much more efficient
782 Tm
GetTm(const TimeZone
& tz
= Local
) const;
784 // get the number of seconds since the Unix epoch - returns (time_t)-1
785 // if the value is out of range
786 inline time_t GetTicks() const;
788 // get the year (returns Inv_Year if date is invalid)
789 int GetYear(const TimeZone
& tz
= Local
) const
790 { return GetTm(tz
).year
; }
791 // get the month (Inv_Month if date is invalid)
792 Month
GetMonth(const TimeZone
& tz
= Local
) const
793 { return (Month
)GetTm(tz
).mon
; }
794 // get the month day (in 1..31 range, 0 if date is invalid)
795 wxDateTime_t
GetDay(const TimeZone
& tz
= Local
) const
796 { return GetTm(tz
).mday
; }
797 // get the day of the week (Inv_WeekDay if date is invalid)
798 WeekDay
GetWeekDay(const TimeZone
& tz
= Local
) const
799 { return GetTm(tz
).GetWeekDay(); }
800 // get the hour of the day
801 wxDateTime_t
GetHour(const TimeZone
& tz
= Local
) const
802 { return GetTm(tz
).hour
; }
804 wxDateTime_t
GetMinute(const TimeZone
& tz
= Local
) const
805 { return GetTm(tz
).min
; }
807 wxDateTime_t
GetSecond(const TimeZone
& tz
= Local
) const
808 { return GetTm(tz
).sec
; }
810 wxDateTime_t
GetMillisecond(const TimeZone
& tz
= Local
) const
811 { return GetTm(tz
).msec
; }
813 // get the day since the year start (1..366, 0 if date is invalid)
814 wxDateTime_t
GetDayOfYear(const TimeZone
& tz
= Local
) const;
815 // get the week number since the year start (1..52 or 53, 0 if date is
817 wxDateTime_t
GetWeekOfYear(WeekFlags flags
= Monday_First
,
818 const TimeZone
& tz
= Local
) const;
819 // get the week number since the month start (1..5, 0 if date is
821 wxDateTime_t
GetWeekOfMonth(WeekFlags flags
= Monday_First
,
822 const TimeZone
& tz
= Local
) const;
824 // is this date a work day? This depends on a country, of course,
825 // because the holidays are different in different countries
826 bool IsWorkDay(Country country
= Country_Default
) const;
828 // is this date later than Gregorian calendar introduction for the
829 // given country (see enum GregorianAdoption)?
831 // NB: this function shouldn't be considered as absolute authority in
832 // the matter. Besides, for some countries the exact date of
833 // adoption of the Gregorian calendar is simply unknown.
834 bool IsGregorianDate(GregorianAdoption country
= Gr_Standard
) const;
836 // dos date and time format
837 // ------------------------------------------------------------------------
839 // set from the DOS packed format
840 wxDateTime
& SetFromDOS(unsigned long ddt
);
842 // pack the date in DOS format
843 unsigned long GetAsDOS() const;
845 // comparison (see also functions below for operator versions)
846 // ------------------------------------------------------------------------
848 // returns TRUE if the two moments are strictly identical
849 inline bool IsEqualTo(const wxDateTime
& datetime
) const;
851 // returns TRUE if the date is strictly earlier than the given one
852 inline bool IsEarlierThan(const wxDateTime
& datetime
) const;
854 // returns TRUE if the date is strictly later than the given one
855 inline bool IsLaterThan(const wxDateTime
& datetime
) const;
857 // returns TRUE if the date is strictly in the given range
858 inline bool IsStrictlyBetween(const wxDateTime
& t1
,
859 const wxDateTime
& t2
) const;
861 // returns TRUE if the date is in the given range
862 inline bool IsBetween(const wxDateTime
& t1
, const wxDateTime
& t2
) const;
864 // do these two objects refer to the same date?
865 inline bool IsSameDate(const wxDateTime
& dt
) const;
867 // do these two objects have the same time?
868 inline bool IsSameTime(const wxDateTime
& dt
) const;
870 // are these two objects equal up to given timespan?
871 inline bool IsEqualUpTo(const wxDateTime
& dt
, const wxTimeSpan
& ts
) const;
873 // arithmetics with dates (see also below for more operators)
874 // ------------------------------------------------------------------------
876 // return the sum of the date with a time span (positive or negative)
877 inline wxDateTime
Add(const wxTimeSpan
& diff
) const;
878 // add a time span (positive or negative)
879 inline wxDateTime
& Add(const wxTimeSpan
& diff
);
880 // add a time span (positive or negative)
881 inline wxDateTime
& operator+=(const wxTimeSpan
& diff
);
883 // return the difference of the date with a time span
884 inline wxDateTime
Subtract(const wxTimeSpan
& diff
) const;
885 // subtract a time span (positive or negative)
886 inline wxDateTime
& Subtract(const wxTimeSpan
& diff
);
887 // subtract a time span (positive or negative)
888 inline wxDateTime
& operator-=(const wxTimeSpan
& diff
);
890 // return the sum of the date with a date span
891 inline wxDateTime
Add(const wxDateSpan
& diff
) const;
892 // add a date span (positive or negative)
893 wxDateTime
& Add(const wxDateSpan
& diff
);
894 // add a date span (positive or negative)
895 inline wxDateTime
& operator+=(const wxDateSpan
& diff
);
897 // return the difference of the date with a date span
898 inline wxDateTime
Subtract(const wxDateSpan
& diff
) const;
899 // subtract a date span (positive or negative)
900 inline wxDateTime
& Subtract(const wxDateSpan
& diff
);
901 // subtract a date span (positive or negative)
902 inline wxDateTime
& operator-=(const wxDateSpan
& diff
);
904 // return the difference between two dates
905 inline wxTimeSpan
Subtract(const wxDateTime
& dt
) const;
907 // conversion to/from text: all conversions from text return the pointer to
908 // the next character following the date specification (i.e. the one where
909 // the scan had to stop) or NULL on failure.
910 // ------------------------------------------------------------------------
912 // parse a string in RFC 822 format (found e.g. in mail headers and
913 // having the form "Wed, 10 Feb 1999 19:07:07 +0100")
914 const wxChar
*ParseRfc822Date(const wxChar
* date
);
915 // parse a date/time in the given format (see strptime(3)), fill in
916 // the missing (in the string) fields with the values of dateDef (by
917 // default, they will not change if they had valid values or will
918 // default to Today() otherwise)
919 const wxChar
*ParseFormat(const wxChar
*date
,
920 const wxChar
*format
= _T("%c"),
921 const wxDateTime
& dateDef
= wxDefaultDateTime
);
922 // parse a string containing the date/time in "free" format, this
923 // function will try to make an educated guess at the string contents
924 const wxChar
*ParseDateTime(const wxChar
*datetime
);
925 // parse a string containing the date only in "free" format (less
926 // flexible than ParseDateTime)
927 const wxChar
*ParseDate(const wxChar
*date
);
928 // parse a string containing the time only in "free" format
929 const wxChar
*ParseTime(const wxChar
*time
);
931 // this function accepts strftime()-like format string (default
932 // argument corresponds to the preferred date and time representation
933 // for the current locale) and returns the string containing the
934 // resulting text representation
935 wxString
Format(const wxChar
*format
= _T("%c"),
936 const TimeZone
& tz
= Local
) const;
937 // preferred date representation for the current locale
938 wxString
FormatDate() const { return Format(_T("%x")); }
939 // preferred time representation for the current locale
940 wxString
FormatTime() const { return Format(_T("%X")); }
941 // returns the string representing the date in ISO 8601 format
943 wxString
FormatISODate() const { return Format(_T("%Y-%m-%d")); }
944 // returns the string representing the time in ISO 8601 format
946 wxString
FormatISOTime() const { return Format(_T("%H:%M:%S")); }
949 // ------------------------------------------------------------------------
951 // construct from internal representation
952 wxDateTime(const wxLongLong
& time
) { m_time
= time
; }
954 // get the internal representation
955 inline wxLongLong
GetValue() const;
957 // a helper function to get the current time_t
958 static time_t GetTimeNow() { return time((time_t *)NULL
); }
960 // another one to get the current time broken down
961 static struct tm
*GetTmNow()
963 time_t t
= GetTimeNow();
964 return localtime(&t
);
968 // the current country - as it's the same for all program objects (unless
969 // it runs on a _really_ big cluster system :-), this is a static member:
970 // see SetCountry() and GetCountry()
971 static Country ms_country
;
973 // this constant is used to transform a time_t value to the internal
974 // representation, as time_t is in seconds and we use milliseconds it's
976 static const long TIME_T_FACTOR
;
978 // returns TRUE if we fall in range in which we can use standard ANSI C
980 inline bool IsInStdRange() const;
982 // the internal representation of the time is the amount of milliseconds
983 // elapsed since the origin which is set by convention to the UNIX/C epoch
984 // value: the midnight of January 1, 1970 (UTC)
988 // ----------------------------------------------------------------------------
989 // This class contains a difference between 2 wxDateTime values, so it makes
990 // sense to add it to wxDateTime and it is the result of subtraction of 2
991 // objects of that class. See also wxDateSpan.
992 // ----------------------------------------------------------------------------
994 class WXDLLIMPEXP_BASE wxTimeSpan
998 // ------------------------------------------------------------------------
1000 // return the timespan for the given number of seconds
1001 static wxTimeSpan
Seconds(long sec
) { return wxTimeSpan(0, 0, sec
); }
1002 static wxTimeSpan
Second() { return Seconds(1); }
1004 // return the timespan for the given number of minutes
1005 static wxTimeSpan
Minutes(long min
) { return wxTimeSpan(0, min
, 0 ); }
1006 static wxTimeSpan
Minute() { return Minutes(1); }
1008 // return the timespan for the given number of hours
1009 static wxTimeSpan
Hours(long hours
) { return wxTimeSpan(hours
, 0, 0); }
1010 static wxTimeSpan
Hour() { return Hours(1); }
1012 // return the timespan for the given number of days
1013 static wxTimeSpan
Days(long days
) { return Hours(24 * days
); }
1014 static wxTimeSpan
Day() { return Days(1); }
1016 // return the timespan for the given number of weeks
1017 static wxTimeSpan
Weeks(long days
) { return Days(7 * days
); }
1018 static wxTimeSpan
Week() { return Weeks(1); }
1020 // default ctor constructs the 0 time span
1023 // from separate values for each component, date set to 0 (hours are
1024 // not restricted to 0..24 range, neither are minutes, seconds or
1026 inline wxTimeSpan(long hours
,
1029 long milliseconds
= 0);
1031 // default copy ctor is ok
1035 // arithmetics with time spans (see also below for more operators)
1036 // ------------------------------------------------------------------------
1038 // return the sum of two timespans
1039 inline wxTimeSpan
Add(const wxTimeSpan
& diff
) const;
1040 // add two timespans together
1041 inline wxTimeSpan
& Add(const wxTimeSpan
& diff
);
1042 // add two timespans together
1043 wxTimeSpan
& operator+=(const wxTimeSpan
& diff
) { return Add(diff
); }
1045 // return the difference of two timespans
1046 inline wxTimeSpan
Subtract(const wxTimeSpan
& diff
) const;
1047 // subtract another timespan
1048 inline wxTimeSpan
& Subtract(const wxTimeSpan
& diff
);
1049 // subtract another timespan
1050 wxTimeSpan
& operator-=(const wxTimeSpan
& diff
) { return Subtract(diff
); }
1052 // multiply timespan by a scalar
1053 inline wxTimeSpan
Multiply(int n
) const;
1054 // multiply timespan by a scalar
1055 inline wxTimeSpan
& Multiply(int n
);
1056 // multiply timespan by a scalar
1057 wxTimeSpan
& operator*=(int n
) { return Multiply(n
); }
1059 // return this timespan with inversed sign
1060 wxTimeSpan
Negate() const { return wxTimeSpan(-GetValue()); }
1061 // negate the value of the timespan
1062 wxTimeSpan
& Neg() { m_diff
= -GetValue(); return *this; }
1063 // negate the value of the timespan
1064 wxTimeSpan
& operator-() { return Neg(); }
1066 // return the absolute value of the timespan: does _not_ modify the
1068 inline wxTimeSpan
Abs() const;
1070 // there is intentionally no division because we don't want to
1071 // introduce rounding errors in time calculations
1073 // comparaison (see also operator versions below)
1074 // ------------------------------------------------------------------------
1076 // is the timespan null?
1077 bool IsNull() const { return m_diff
== 0l; }
1078 // returns true if the timespan is null
1079 bool operator!() const { return !IsNull(); }
1081 // is the timespan positive?
1082 bool IsPositive() const { return m_diff
> 0l; }
1084 // is the timespan negative?
1085 bool IsNegative() const { return m_diff
< 0l; }
1087 // are two timespans equal?
1088 inline bool IsEqualTo(const wxTimeSpan
& ts
) const;
1089 // compare two timestamps: works with the absolute values, i.e. -2
1090 // hours is longer than 1 hour. Also, it will return FALSE if the
1091 // timespans are equal in absolute value.
1092 inline bool IsLongerThan(const wxTimeSpan
& ts
) const;
1093 // compare two timestamps: works with the absolute values, i.e. 1
1094 // hour is shorter than -2 hours. Also, it will return FALSE if the
1095 // timespans are equal in absolute value.
1096 bool IsShorterThan(const wxTimeSpan
& t
) const { return !IsLongerThan(t
); }
1098 // breaking into days, hours, minutes and seconds
1099 // ------------------------------------------------------------------------
1101 // get the max number of weeks in this timespan
1102 inline int GetWeeks() const;
1103 // get the max number of days in this timespan
1104 inline int GetDays() const;
1105 // get the max number of hours in this timespan
1106 inline int GetHours() const;
1107 // get the max number of minutes in this timespan
1108 inline int GetMinutes() const;
1109 // get the max number of seconds in this timespan
1110 inline wxLongLong
GetSeconds() const;
1111 // get the number of milliseconds in this timespan
1112 wxLongLong
GetMilliseconds() const { return m_diff
; }
1114 // conversion to text
1115 // ------------------------------------------------------------------------
1117 // this function accepts strftime()-like format string (default
1118 // argument corresponds to the preferred date and time representation
1119 // for the current locale) and returns the string containing the
1120 // resulting text representation. Notice that only some of format
1121 // specifiers valid for wxDateTime are valid for wxTimeSpan: hours,
1122 // minutes and seconds make sense, but not "PM/AM" string for example.
1123 wxString
Format(const wxChar
*format
= _T("%H:%M:%S")) const;
1126 // ------------------------------------------------------------------------
1128 // construct from internal representation
1129 wxTimeSpan(const wxLongLong
& diff
) { m_diff
= diff
; }
1131 // get the internal representation
1132 wxLongLong
GetValue() const { return m_diff
; }
1135 // the (signed) time span in milliseconds
1139 // ----------------------------------------------------------------------------
1140 // This class is a "logical time span" and is useful for implementing program
1141 // logic for such things as "add one month to the date" which, in general,
1142 // doesn't mean to add 60*60*24*31 seconds to it, but to take the same date
1143 // the next month (to understand that this is indeed different consider adding
1144 // one month to Feb, 15 - we want to get Mar, 15, of course).
1146 // When adding a month to the date, all lesser components (days, hours, ...)
1147 // won't be changed unless the resulting date would be invalid: for example,
1148 // Jan 31 + 1 month will be Feb 28, not (non existing) Feb 31.
1150 // Because of this feature, adding and subtracting back again the same
1151 // wxDateSpan will *not*, in general give back the original date: Feb 28 - 1
1152 // month will be Jan 28, not Jan 31!
1154 // wxDateSpan can be either positive or negative. They may be
1155 // multiplied by scalars which multiply all deltas by the scalar: i.e. 2*(1
1156 // month and 1 day) is 2 months and 2 days. They can be added together and
1157 // with wxDateTime or wxTimeSpan, but the type of result is different for each
1160 // Beware about weeks: if you specify both weeks and days, the total number of
1161 // days added will be 7*weeks + days! See also GetTotalDays() function.
1163 // Equality operators are defined for wxDateSpans. Two datespans are equal if
1164 // they both give the same target date when added to *every* source date.
1165 // Thus wxDateSpan::Months(1) is not equal to wxDateSpan::Days(30), because
1166 // they not give the same date when added to 1 Feb. But wxDateSpan::Days(14) is
1167 // equal to wxDateSpan::Weeks(2)
1169 // Finally, notice that for adding hours, minutes &c you don't need this
1170 // class: wxTimeSpan will do the job because there are no subtleties
1171 // associated with those.
1172 // ----------------------------------------------------------------------------
1174 class WXDLLIMPEXP_BASE wxDateSpan
1178 // ------------------------------------------------------------------------
1180 // this many years/months/weeks/days
1181 wxDateSpan(int years
= 0, int months
= 0, int weeks
= 0, int days
= 0)
1189 // get an object for the given number of days
1190 static wxDateSpan
Days(int days
) { return wxDateSpan(0, 0, 0, days
); }
1191 static wxDateSpan
Day() { return Days(1); }
1193 // get an object for the given number of weeks
1194 static wxDateSpan
Weeks(int weeks
) { return wxDateSpan(0, 0, weeks
, 0); }
1195 static wxDateSpan
Week() { return Weeks(1); }
1197 // get an object for the given number of months
1198 static wxDateSpan
Months(int mon
) { return wxDateSpan(0, mon
, 0, 0); }
1199 static wxDateSpan
Month() { return Months(1); }
1201 // get an object for the given number of years
1202 static wxDateSpan
Years(int years
) { return wxDateSpan(years
, 0, 0, 0); }
1203 static wxDateSpan
Year() { return Years(1); }
1205 // default copy ctor is ok
1209 // accessors (all SetXXX() return the (modified) wxDateSpan object)
1210 // ------------------------------------------------------------------------
1212 // set number of years
1213 wxDateSpan
& SetYears(int n
) { m_years
= n
; return *this; }
1214 // set number of months
1215 wxDateSpan
& SetMonths(int n
) { m_months
= n
; return *this; }
1216 // set number of weeks
1217 wxDateSpan
& SetWeeks(int n
) { m_weeks
= n
; return *this; }
1218 // set number of days
1219 wxDateSpan
& SetDays(int n
) { m_days
= n
; return *this; }
1221 // get number of years
1222 int GetYears() const { return m_years
; }
1223 // get number of months
1224 int GetMonths() const { return m_months
; }
1225 // get number of weeks
1226 int GetWeeks() const { return m_weeks
; }
1227 // get number of days
1228 int GetDays() const { return m_days
; }
1229 // returns 7*GetWeeks() + GetDays()
1230 int GetTotalDays() const { return 7*m_weeks
+ m_days
; }
1232 // arithmetics with date spans (see also below for more operators)
1233 // ------------------------------------------------------------------------
1235 // return sum of two date spans
1236 inline wxDateSpan
Add(const wxDateSpan
& other
) const;
1237 // add another wxDateSpan to us
1238 inline wxDateSpan
& Add(const wxDateSpan
& other
);
1239 // add another wxDateSpan to us
1240 inline wxDateSpan
& operator+=(const wxDateSpan
& other
);
1242 // return difference of two date spans
1243 inline wxDateSpan
Subtract(const wxDateSpan
& other
) const;
1244 // subtract another wxDateSpan from us
1245 inline wxDateSpan
& Subtract(const wxDateSpan
& other
);
1246 // subtract another wxDateSpan from us
1247 inline wxDateSpan
& operator-=(const wxDateSpan
& other
);
1249 // return a copy of this time span with changed sign
1250 inline wxDateSpan
Negate() const;
1251 // inverse the sign of this timespan
1252 inline wxDateSpan
& Neg();
1253 // inverse the sign of this timespan
1254 wxDateSpan
& operator-() { return Neg(); }
1256 // return the date span proportional to this one with given factor
1257 inline wxDateSpan
Multiply(int factor
) const;
1258 // multiply all components by a (signed) number
1259 inline wxDateSpan
& Multiply(int factor
);
1260 // multiply all components by a (signed) number
1261 inline wxDateSpan
& operator*=(int factor
) { return Multiply(factor
); }
1270 // ----------------------------------------------------------------------------
1271 // wxDateTimeArray: array of dates.
1272 // ----------------------------------------------------------------------------
1274 WX_DECLARE_USER_EXPORTED_OBJARRAY(wxDateTime
, wxDateTimeArray
, WXDLLIMPEXP_BASE
);
1276 // ----------------------------------------------------------------------------
1277 // wxDateTimeHolidayAuthority: an object of this class will decide whether a
1278 // given date is a holiday and is used by all functions working with "work
1281 // NB: the base class is an ABC, derived classes must implement the pure
1282 // virtual methods to work with the holidays they correspond to.
1283 // ----------------------------------------------------------------------------
1285 class WXDLLIMPEXP_BASE wxDateTimeHolidayAuthority
;
1286 WX_DEFINE_USER_EXPORTED_ARRAY(wxDateTimeHolidayAuthority
*,
1287 wxHolidayAuthoritiesArray
,
1288 class WXDLLIMPEXP_BASE
);
1290 class wxDateTimeHolidaysModule
;
1291 class WXDLLIMPEXP_BASE wxDateTimeHolidayAuthority
1293 friend class wxDateTimeHolidaysModule
;
1295 // returns TRUE if the given date is a holiday
1296 static bool IsHoliday(const wxDateTime
& dt
);
1298 // fills the provided array with all holidays in the given range, returns
1299 // the number of them
1300 static size_t GetHolidaysInRange(const wxDateTime
& dtStart
,
1301 const wxDateTime
& dtEnd
,
1302 wxDateTimeArray
& holidays
);
1304 // clear the list of holiday authorities
1305 static void ClearAllAuthorities();
1307 // add a new holiday authority (the pointer will be deleted by
1308 // wxDateTimeHolidayAuthority)
1309 static void AddAuthority(wxDateTimeHolidayAuthority
*auth
);
1311 // the base class must have a virtual dtor
1312 virtual ~wxDateTimeHolidayAuthority();
1315 // this function is called to determine whether a given day is a holiday
1316 virtual bool DoIsHoliday(const wxDateTime
& dt
) const = 0;
1318 // this function should fill the array with all holidays between the two
1319 // given dates - it is implemented in the base class, but in a very
1320 // inefficient way (it just iterates over all days and uses IsHoliday() for
1321 // each of them), so it must be overridden in the derived class where the
1322 // base class version may be explicitly used if needed
1324 // returns the number of holidays in the given range and fills holidays
1326 virtual size_t DoGetHolidaysInRange(const wxDateTime
& dtStart
,
1327 const wxDateTime
& dtEnd
,
1328 wxDateTimeArray
& holidays
) const = 0;
1331 // all holiday authorities
1332 static wxHolidayAuthoritiesArray ms_authorities
;
1335 // the holidays for this class are all Saturdays and Sundays
1336 class WXDLLIMPEXP_BASE wxDateTimeWorkDays
: public wxDateTimeHolidayAuthority
1339 virtual bool DoIsHoliday(const wxDateTime
& dt
) const;
1340 virtual size_t DoGetHolidaysInRange(const wxDateTime
& dtStart
,
1341 const wxDateTime
& dtEnd
,
1342 wxDateTimeArray
& holidays
) const;
1345 // ============================================================================
1346 // inline functions implementation
1347 // ============================================================================
1349 // ----------------------------------------------------------------------------
1351 // ----------------------------------------------------------------------------
1353 #define MILLISECONDS_PER_DAY 86400000l
1355 // some broken compilers (HP-UX CC) refuse to compile the "normal" version, but
1356 // using a temp variable always might prevent other compilers from optimising
1357 // it away - hence use of this ugly macro
1359 #define MODIFY_AND_RETURN(op) return wxDateTime(*this).op
1361 #define MODIFY_AND_RETURN(op) wxDateTime dt(*this); dt.op; return dt
1364 // ----------------------------------------------------------------------------
1365 // wxDateTime construction
1366 // ----------------------------------------------------------------------------
1368 inline bool wxDateTime::IsInStdRange() const
1370 return m_time
>= 0l && (m_time
/ TIME_T_FACTOR
) < LONG_MAX
;
1374 inline wxDateTime
wxDateTime::Now()
1376 return wxDateTime(*GetTmNow());
1380 inline wxDateTime
wxDateTime::Today()
1382 struct tm
*time
= GetTmNow();
1387 return wxDateTime(*time
);
1390 #if (!(defined(__VISAGECPP__) && __IBMCPP__ >= 400))
1391 inline wxDateTime
& wxDateTime::Set(time_t timet
)
1393 // assign first to avoid long multiplication overflow!
1394 m_time
= timet
- WX_TIME_BASE_OFFSET
;
1395 m_time
*= TIME_T_FACTOR
;
1401 inline wxDateTime
& wxDateTime::SetToCurrent()
1407 #if (!(defined(__VISAGECPP__) && __IBMCPP__ >= 400))
1408 inline wxDateTime::wxDateTime(time_t timet
)
1414 inline wxDateTime::wxDateTime(const struct tm
& tm
)
1419 inline wxDateTime::wxDateTime(const Tm
& tm
)
1424 inline wxDateTime::wxDateTime(double jdn
)
1429 inline wxDateTime
& wxDateTime::Set(const Tm
& tm
)
1431 wxASSERT_MSG( tm
.IsValid(), _T("invalid broken down date/time") );
1433 return Set(tm
.mday
, (Month
)tm
.mon
, tm
.year
, tm
.hour
, tm
.min
, tm
.sec
);
1436 inline wxDateTime::wxDateTime(wxDateTime_t hour
,
1437 wxDateTime_t minute
,
1438 wxDateTime_t second
,
1439 wxDateTime_t millisec
)
1441 Set(hour
, minute
, second
, millisec
);
1444 inline wxDateTime::wxDateTime(wxDateTime_t day
,
1448 wxDateTime_t minute
,
1449 wxDateTime_t second
,
1450 wxDateTime_t millisec
)
1452 Set(day
, month
, year
, hour
, minute
, second
, millisec
);
1455 // ----------------------------------------------------------------------------
1456 // wxDateTime accessors
1457 // ----------------------------------------------------------------------------
1459 inline wxLongLong
wxDateTime::GetValue() const
1461 wxASSERT_MSG( IsValid(), _T("invalid wxDateTime"));
1466 inline time_t wxDateTime::GetTicks() const
1468 wxASSERT_MSG( IsValid(), _T("invalid wxDateTime"));
1469 if ( !IsInStdRange() )
1474 return (time_t)((m_time
/ (long)TIME_T_FACTOR
).GetLo())+WX_TIME_BASE_OFFSET
;
1477 inline bool wxDateTime::SetToLastWeekDay(WeekDay weekday
,
1481 return SetToWeekDay(weekday
, -1, month
, year
);
1484 inline wxDateTime
wxDateTime::GetWeekDayInSameWeek(WeekDay weekday
,
1485 WeekFlags flags
) const
1487 MODIFY_AND_RETURN( SetToWeekDayInSameWeek(weekday
) );
1490 inline wxDateTime
wxDateTime::GetNextWeekDay(WeekDay weekday
) const
1492 MODIFY_AND_RETURN( SetToNextWeekDay(weekday
) );
1495 inline wxDateTime
wxDateTime::GetPrevWeekDay(WeekDay weekday
) const
1497 MODIFY_AND_RETURN( SetToPrevWeekDay(weekday
) );
1500 inline wxDateTime
wxDateTime::GetWeekDay(WeekDay weekday
,
1505 wxDateTime
dt(*this);
1507 return dt
.SetToWeekDay(weekday
, n
, month
, year
) ? dt
: wxInvalidDateTime
;
1510 inline wxDateTime
wxDateTime::GetLastWeekDay(WeekDay weekday
,
1514 wxDateTime
dt(*this);
1516 return dt
.SetToLastWeekDay(weekday
, month
, year
) ? dt
: wxInvalidDateTime
;
1519 inline wxDateTime
wxDateTime::GetWeek(wxDateTime_t numWeek
,
1521 WeekFlags flags
) const
1523 wxDateTime
dt(*this);
1525 return dt
.SetToTheWeek(numWeek
, weekday
, flags
) ? dt
: wxInvalidDateTime
;
1528 inline wxDateTime
wxDateTime::GetLastMonthDay(Month month
, int year
) const
1530 MODIFY_AND_RETURN( SetToLastMonthDay(month
, year
) );
1533 inline wxDateTime
wxDateTime::GetYearDay(wxDateTime_t yday
) const
1535 MODIFY_AND_RETURN( SetToYearDay(yday
) );
1538 // ----------------------------------------------------------------------------
1539 // wxDateTime comparison
1540 // ----------------------------------------------------------------------------
1542 inline bool wxDateTime::IsEqualTo(const wxDateTime
& datetime
) const
1544 wxASSERT_MSG( IsValid() && datetime
.IsValid(), _T("invalid wxDateTime"));
1546 return m_time
== datetime
.m_time
;
1549 inline bool wxDateTime::IsEarlierThan(const wxDateTime
& datetime
) const
1551 wxASSERT_MSG( IsValid() && datetime
.IsValid(), _T("invalid wxDateTime"));
1553 return m_time
< datetime
.m_time
;
1556 inline bool wxDateTime::IsLaterThan(const wxDateTime
& datetime
) const
1558 wxASSERT_MSG( IsValid() && datetime
.IsValid(), _T("invalid wxDateTime"));
1560 return m_time
> datetime
.m_time
;
1563 inline bool wxDateTime::IsStrictlyBetween(const wxDateTime
& t1
,
1564 const wxDateTime
& t2
) const
1566 // no need for assert, will be checked by the functions we call
1567 return IsLaterThan(t1
) && IsEarlierThan(t2
);
1570 inline bool wxDateTime::IsBetween(const wxDateTime
& t1
,
1571 const wxDateTime
& t2
) const
1573 // no need for assert, will be checked by the functions we call
1574 return IsEqualTo(t1
) || IsEqualTo(t2
) || IsStrictlyBetween(t1
, t2
);
1577 inline bool wxDateTime::IsSameDate(const wxDateTime
& dt
) const
1582 return tm1
.year
== tm2
.year
&&
1583 tm1
.mon
== tm2
.mon
&&
1584 tm1
.mday
== tm2
.mday
;
1587 inline bool wxDateTime::IsSameTime(const wxDateTime
& dt
) const
1589 // notice that we can't do something like this:
1591 // m_time % MILLISECONDS_PER_DAY == dt.m_time % MILLISECONDS_PER_DAY
1593 // because we have also to deal with (possibly) different DST settings!
1597 return tm1
.hour
== tm2
.hour
&&
1598 tm1
.min
== tm2
.min
&&
1599 tm1
.sec
== tm2
.sec
&&
1600 tm1
.msec
== tm2
.msec
;
1603 inline bool wxDateTime::IsEqualUpTo(const wxDateTime
& dt
,
1604 const wxTimeSpan
& ts
) const
1606 return IsBetween(dt
.Subtract(ts
), dt
.Add(ts
));
1609 // ----------------------------------------------------------------------------
1610 // wxDateTime arithmetics
1611 // ----------------------------------------------------------------------------
1613 inline wxDateTime
wxDateTime::Add(const wxTimeSpan
& diff
) const
1615 wxASSERT_MSG( IsValid(), _T("invalid wxDateTime"));
1617 return wxDateTime(m_time
+ diff
.GetValue());
1620 inline wxDateTime
& wxDateTime::Add(const wxTimeSpan
& diff
)
1622 wxASSERT_MSG( IsValid(), _T("invalid wxDateTime"));
1624 m_time
+= diff
.GetValue();
1629 inline wxDateTime
& wxDateTime::operator+=(const wxTimeSpan
& diff
)
1634 inline wxDateTime
wxDateTime::Subtract(const wxTimeSpan
& diff
) const
1636 wxASSERT_MSG( IsValid(), _T("invalid wxDateTime"));
1638 return wxDateTime(m_time
- diff
.GetValue());
1641 inline wxDateTime
& wxDateTime::Subtract(const wxTimeSpan
& diff
)
1643 wxASSERT_MSG( IsValid(), _T("invalid wxDateTime"));
1645 m_time
-= diff
.GetValue();
1650 inline wxDateTime
& wxDateTime::operator-=(const wxTimeSpan
& diff
)
1652 return Subtract(diff
);
1655 inline wxTimeSpan
wxDateTime::Subtract(const wxDateTime
& datetime
) const
1657 wxASSERT_MSG( IsValid() && datetime
.IsValid(), _T("invalid wxDateTime"));
1659 return wxTimeSpan(GetValue() - datetime
.GetValue());
1662 inline wxDateTime
wxDateTime::Add(const wxDateSpan
& diff
) const
1664 return wxDateTime(*this).Add(diff
);
1667 inline wxDateTime
& wxDateTime::Subtract(const wxDateSpan
& diff
)
1669 return Add(diff
.Negate());
1672 inline wxDateTime
wxDateTime::Subtract(const wxDateSpan
& diff
) const
1674 return wxDateTime(*this).Subtract(diff
);
1677 inline wxDateTime
& wxDateTime::operator-=(const wxDateSpan
& diff
)
1679 return Subtract(diff
);
1682 inline wxDateTime
& wxDateTime::operator+=(const wxDateSpan
& diff
)
1687 // ----------------------------------------------------------------------------
1688 // wxDateTime and timezones
1689 // ----------------------------------------------------------------------------
1691 inline wxDateTime
wxDateTime::ToTimezone(const wxDateTime::TimeZone
& tz
,
1694 MODIFY_AND_RETURN( MakeTimezone(tz
, noDST
) );
1697 // ----------------------------------------------------------------------------
1698 // wxTimeSpan construction
1699 // ----------------------------------------------------------------------------
1701 inline wxTimeSpan::wxTimeSpan(long hours
,
1706 // assign first to avoid precision loss
1713 m_diff
+= milliseconds
;
1716 // ----------------------------------------------------------------------------
1717 // wxTimeSpan accessors
1718 // ----------------------------------------------------------------------------
1720 inline wxLongLong
wxTimeSpan::GetSeconds() const
1722 return m_diff
/ 1000l;
1725 inline int wxTimeSpan::GetMinutes() const
1727 return (GetSeconds() / 60l).GetLo();
1730 inline int wxTimeSpan::GetHours() const
1732 return GetMinutes() / 60;
1735 inline int wxTimeSpan::GetDays() const
1737 return GetHours() / 24;
1740 inline int wxTimeSpan::GetWeeks() const
1742 return GetDays() / 7;
1745 // ----------------------------------------------------------------------------
1746 // wxTimeSpan arithmetics
1747 // ----------------------------------------------------------------------------
1749 inline wxTimeSpan
wxTimeSpan::Add(const wxTimeSpan
& diff
) const
1751 return wxTimeSpan(m_diff
+ diff
.GetValue());
1754 inline wxTimeSpan
& wxTimeSpan::Add(const wxTimeSpan
& diff
)
1756 m_diff
+= diff
.GetValue();
1761 inline wxTimeSpan
wxTimeSpan::Subtract(const wxTimeSpan
& diff
) const
1763 return wxTimeSpan(m_diff
- diff
.GetValue());
1766 inline wxTimeSpan
& wxTimeSpan::Subtract(const wxTimeSpan
& diff
)
1768 m_diff
-= diff
.GetValue();
1773 inline wxTimeSpan
& wxTimeSpan::Multiply(int n
)
1780 inline wxTimeSpan
wxTimeSpan::Multiply(int n
) const
1782 return wxTimeSpan(m_diff
* (long)n
);
1785 inline wxTimeSpan
wxTimeSpan::Abs() const
1787 return wxTimeSpan(GetValue().Abs());
1790 inline bool wxTimeSpan::IsEqualTo(const wxTimeSpan
& ts
) const
1792 return GetValue() == ts
.GetValue();
1795 inline bool wxTimeSpan::IsLongerThan(const wxTimeSpan
& ts
) const
1797 return GetValue().Abs() > ts
.GetValue().Abs();
1800 // ----------------------------------------------------------------------------
1802 // ----------------------------------------------------------------------------
1804 inline wxDateSpan
& wxDateSpan::operator+=(const wxDateSpan
& other
)
1806 m_years
+= other
.m_years
;
1807 m_months
+= other
.m_months
;
1808 m_weeks
+= other
.m_weeks
;
1809 m_days
+= other
.m_days
;
1814 inline wxDateSpan
& wxDateSpan::Add(const wxDateSpan
& other
)
1816 return *this += other
;
1819 inline wxDateSpan
wxDateSpan::Add(const wxDateSpan
& other
) const
1821 wxDateSpan
ds(*this);
1826 inline wxDateSpan
& wxDateSpan::Multiply(int factor
)
1836 inline wxDateSpan
wxDateSpan::Multiply(int factor
) const
1838 wxDateSpan
ds(*this);
1839 ds
.Multiply(factor
);
1843 inline wxDateSpan
wxDateSpan::Negate() const
1845 return wxDateSpan(-m_years
, -m_months
, -m_weeks
, -m_days
);
1848 inline wxDateSpan
& wxDateSpan::Neg()
1851 m_months
= -m_months
;
1858 inline wxDateSpan
& wxDateSpan::operator-=(const wxDateSpan
& other
)
1860 return *this += other
.Negate();
1863 inline wxDateSpan
& wxDateSpan::Subtract(const wxDateSpan
& other
)
1865 return *this -= other
;
1868 inline wxDateSpan
wxDateSpan::Subtract(const wxDateSpan
& other
) const
1870 wxDateSpan
ds(*this);
1875 #undef MILLISECONDS_PER_DAY
1877 #undef MODIFY_AND_RETURN
1879 // ============================================================================
1881 // ============================================================================
1883 // ----------------------------------------------------------------------------
1884 // wxDateTime operators
1885 // ----------------------------------------------------------------------------
1890 // no need to check for validity - the member functions we call will do it
1892 inline wxDateTime WXDLLIMPEXP_BASE
operator+(const wxDateTime
& dt
,
1893 const wxTimeSpan
& ts
)
1898 inline wxDateTime WXDLLIMPEXP_BASE
operator-(const wxDateTime
& dt
,
1899 const wxTimeSpan
& ts
)
1901 return dt
.Subtract(ts
);
1904 inline wxDateTime WXDLLIMPEXP_BASE
operator+(const wxDateTime
& dt
,
1905 const wxDateSpan
& ds
)
1910 inline wxDateTime WXDLLIMPEXP_BASE
operator-(const wxDateTime
& dt
,
1911 const wxDateSpan
& ds
)
1913 return dt
.Subtract(ds
);
1916 inline wxTimeSpan WXDLLIMPEXP_BASE
operator-(const wxDateTime
& dt1
,
1917 const wxDateTime
& dt2
)
1919 return dt1
.Subtract(dt2
);
1925 inline bool WXDLLIMPEXP_BASE
operator<(const wxDateTime
& t1
, const wxDateTime
& t2
)
1927 wxASSERT_MSG( t1
.IsValid() && t2
.IsValid(), _T("invalid wxDateTime") );
1929 return t1
.GetValue() < t2
.GetValue();
1932 inline bool WXDLLIMPEXP_BASE
operator<=(const wxDateTime
& t1
, const wxDateTime
& t2
)
1934 wxASSERT_MSG( t1
.IsValid() && t2
.IsValid(), _T("invalid wxDateTime") );
1936 return t1
.GetValue() <= t2
.GetValue();
1939 inline bool WXDLLIMPEXP_BASE
operator>(const wxDateTime
& t1
, const wxDateTime
& t2
)
1941 wxASSERT_MSG( t1
.IsValid() && t2
.IsValid(), _T("invalid wxDateTime") );
1943 return t1
.GetValue() > t2
.GetValue();
1946 inline bool WXDLLIMPEXP_BASE
operator>=(const wxDateTime
& t1
, const wxDateTime
& t2
)
1948 wxASSERT_MSG( t1
.IsValid() && t2
.IsValid(), _T("invalid wxDateTime") );
1950 return t1
.GetValue() >= t2
.GetValue();
1953 inline bool WXDLLIMPEXP_BASE
operator==(const wxDateTime
& t1
, const wxDateTime
& t2
)
1955 wxASSERT_MSG( t1
.IsValid() && t2
.IsValid(), _T("invalid wxDateTime") );
1957 return t1
.GetValue() == t2
.GetValue();
1960 inline bool WXDLLIMPEXP_BASE
operator!=(const wxDateTime
& t1
, const wxDateTime
& t2
)
1962 wxASSERT_MSG( t1
.IsValid() && t2
.IsValid(), _T("invalid wxDateTime") );
1964 return t1
.GetValue() != t2
.GetValue();
1967 // ----------------------------------------------------------------------------
1968 // wxTimeSpan operators
1969 // ----------------------------------------------------------------------------
1974 inline wxTimeSpan WXDLLIMPEXP_BASE
operator+(const wxTimeSpan
& ts1
,
1975 const wxTimeSpan
& ts2
)
1977 return wxTimeSpan(ts1
.GetValue() + ts2
.GetValue());
1980 inline wxTimeSpan WXDLLIMPEXP_BASE
operator-(const wxTimeSpan
& ts1
,
1981 const wxTimeSpan
& ts2
)
1983 return wxTimeSpan(ts1
.GetValue() - ts2
.GetValue());
1986 inline wxTimeSpan WXDLLIMPEXP_BASE
operator*(const wxTimeSpan
& ts
, int n
)
1988 return wxTimeSpan(ts
).Multiply(n
);
1991 inline wxTimeSpan WXDLLIMPEXP_BASE
operator*(int n
, const wxTimeSpan
& ts
)
1993 return wxTimeSpan(ts
).Multiply(n
);
1999 inline bool WXDLLIMPEXP_BASE
operator<(const wxTimeSpan
&t1
, const wxTimeSpan
&t2
)
2001 return t1
.GetValue() < t2
.GetValue();
2004 inline bool WXDLLIMPEXP_BASE
operator<=(const wxTimeSpan
&t1
, const wxTimeSpan
&t2
)
2006 return t1
.GetValue() <= t2
.GetValue();
2009 inline bool WXDLLIMPEXP_BASE
operator>(const wxTimeSpan
&t1
, const wxTimeSpan
&t2
)
2011 return t1
.GetValue() > t2
.GetValue();
2014 inline bool WXDLLIMPEXP_BASE
operator>=(const wxTimeSpan
&t1
, const wxTimeSpan
&t2
)
2016 return t1
.GetValue() >= t2
.GetValue();
2019 inline bool WXDLLIMPEXP_BASE
operator==(const wxTimeSpan
&t1
, const wxTimeSpan
&t2
)
2021 return t1
.GetValue() == t2
.GetValue();
2024 inline bool WXDLLIMPEXP_BASE
operator!=(const wxTimeSpan
&t1
, const wxTimeSpan
&t2
)
2026 return t1
.GetValue() != t2
.GetValue();
2029 // ----------------------------------------------------------------------------
2031 // ----------------------------------------------------------------------------
2036 // ds1 == d2 if and only if for every wxDateTime t t + ds1 == t + ds2
2037 inline WXDLLIMPEXP_BASE
bool operator==(const wxDateSpan
& ds1
,
2038 const wxDateSpan
& ds2
)
2040 return ds1
.GetYears() == ds2
.GetYears() &&
2041 ds1
.GetMonths() == ds2
.GetMonths() &&
2042 ds1
.GetTotalDays() == ds2
.GetTotalDays();
2045 inline WXDLLIMPEXP_BASE
bool operator!=(const wxDateSpan
& ds1
,
2046 const wxDateSpan
& ds2
)
2048 return !(ds1
== ds2
);
2054 inline WXDLLIMPEXP_BASE wxDateSpan
operator+(const wxDateSpan
& ds1
,
2055 const wxDateSpan
& ds2
)
2057 return wxDateSpan(ds1
.GetYears() + ds2
.GetYears(),
2058 ds1
.GetMonths() + ds2
.GetMonths(),
2059 ds1
.GetWeeks() + ds2
.GetWeeks(),
2060 ds1
.GetDays() + ds2
.GetDays());
2063 inline WXDLLIMPEXP_BASE wxDateSpan
operator-(const wxDateSpan
& ds1
,
2064 const wxDateSpan
& ds2
)
2066 return wxDateSpan(ds1
.GetYears() - ds2
.GetYears(),
2067 ds1
.GetMonths() - ds2
.GetMonths(),
2068 ds1
.GetWeeks() - ds2
.GetWeeks(),
2069 ds1
.GetDays() - ds2
.GetDays());
2072 inline WXDLLIMPEXP_BASE wxDateSpan
operator*(const wxDateSpan
& ds
, int n
)
2074 return wxDateSpan(ds
).Multiply(n
);
2077 inline WXDLLIMPEXP_BASE wxDateSpan
operator*(int n
, const wxDateSpan
& ds
)
2079 return wxDateSpan(ds
).Multiply(n
);
2082 // ============================================================================
2083 // other helper functions
2084 // ============================================================================
2086 // ----------------------------------------------------------------------------
2087 // iteration helpers: can be used to write a for loop over enum variable like
2089 // for ( m = wxDateTime::Jan; m < wxDateTime::Inv_Month; wxNextMonth(m) )
2090 // ----------------------------------------------------------------------------
2092 inline WXDLLIMPEXP_BASE
void wxNextMonth(wxDateTime::Month
& m
)
2094 wxASSERT_MSG( m
< wxDateTime::Inv_Month
, _T("invalid month") );
2096 // no wrapping or the for loop above would never end!
2097 m
= (wxDateTime::Month
)(m
+ 1);
2100 inline WXDLLIMPEXP_BASE
void wxPrevMonth(wxDateTime::Month
& m
)
2102 wxASSERT_MSG( m
< wxDateTime::Inv_Month
, _T("invalid month") );
2104 m
= m
== wxDateTime::Jan
? wxDateTime::Inv_Month
2105 : (wxDateTime::Month
)(m
- 1);
2108 inline WXDLLIMPEXP_BASE
void wxNextWDay(wxDateTime::WeekDay
& wd
)
2110 wxASSERT_MSG( wd
< wxDateTime::Inv_WeekDay
, _T("invalid week day") );
2112 // no wrapping or the for loop above would never end!
2113 wd
= (wxDateTime::WeekDay
)(wd
+ 1);
2116 inline WXDLLIMPEXP_BASE
void wxPrevWDay(wxDateTime::WeekDay
& wd
)
2118 wxASSERT_MSG( wd
< wxDateTime::Inv_WeekDay
, _T("invalid week day") );
2120 wd
= wd
== wxDateTime::Sun
? wxDateTime::Inv_WeekDay
2121 : (wxDateTime::WeekDay
)(wd
- 1);
2124 #endif // wxUSE_DATETIME
2126 #endif // _WX_DATETIME_H