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
23 #include "wx/msw/wince/time.h"
26 #include <limits.h> // for INT_MIN
28 #include "wx/longlong.h"
30 class WXDLLIMPEXP_BASE wxDateTime
;
31 class WXDLLIMPEXP_BASE wxTimeSpan
;
32 class WXDLLIMPEXP_BASE wxDateSpan
;
34 #include "wx/dynarray.h"
36 // not all c-runtimes are based on 1/1/1970 being (time_t) 0
37 // set this to the corresponding value in seconds 1/1/1970 has on your
40 #if defined(__WXMAC__) && !defined(__DARWIN__) && __MSL__ < 0x6000
41 #define WX_TIME_BASE_OFFSET ( 2082844800L + 126144000L )
43 #define WX_TIME_BASE_OFFSET 0
48 * + 1. Time zones with minutes (make TimeZone a class)
49 * ? 2. getdate() function like under Solaris
50 * + 3. text conversion for wxDateSpan
51 * + 4. pluggable modules for the workdays calculations
52 * 5. wxDateTimeHolidayAuthority for Easter and other christian feasts
55 /* Two wrapper functions for thread safety */
56 #ifdef HAVE_LOCALTIME_R
57 #define wxLocaltime_r localtime_r
59 WXDLLIMPEXP_BASE
struct tm
*wxLocaltime_r(const time_t*, struct tm
*);
60 #if wxUSE_THREADS && !defined(__WINDOWS__) && !defined(__WATCOMC__)
61 // On Windows, localtime _is_ threadsafe!
62 #warning using pseudo thread-safe wrapper for localtime to emulate localtime_r
67 #define wxGmtime_r gmtime_r
69 WXDLLIMPEXP_BASE
struct tm
*wxGmtime_r(const time_t*, struct tm
*);
70 #if wxUSE_THREADS && !defined(__WINDOWS__) && !defined(__WATCOMC__)
71 // On Windows, gmtime _is_ threadsafe!
72 #warning using pseudo thread-safe wrapper for gmtime to emulate gmtime_r
77 The three (main) classes declared in this header represent:
79 1. An absolute moment in the time (wxDateTime)
80 2. A difference between two moments in the time, positive or negative
82 3. A logical difference between two dates expressed in
83 years/months/weeks/days (wxDateSpan)
85 The following arithmetic operations are permitted (all others are not):
90 wxDateTime + wxTimeSpan = wxDateTime
91 wxDateTime + wxDateSpan = wxDateTime
92 wxTimeSpan + wxTimeSpan = wxTimeSpan
93 wxDateSpan + wxDateSpan = wxDateSpan
97 wxDateTime - wxDateTime = wxTimeSpan
98 wxDateTime - wxTimeSpan = wxDateTime
99 wxDateTime - wxDateSpan = wxDateTime
100 wxTimeSpan - wxTimeSpan = wxTimeSpan
101 wxDateSpan - wxDateSpan = wxDateSpan
105 wxTimeSpan * number = wxTimeSpan
106 number * wxTimeSpan = wxTimeSpan
107 wxDateSpan * number = wxDateSpan
108 number * wxDateSpan = wxDateSpan
112 -wxTimeSpan = wxTimeSpan
113 -wxDateSpan = wxDateSpan
115 For each binary operation OP (+, -, *) we have the following operatorOP=() as
116 a method and the method with a symbolic name OPER (Add, Subtract, Multiply)
117 as a synonym for it and another const method with the same name which returns
118 the changed copy of the object and operatorOP() as a global function which is
119 implemented in terms of the const version of OPEN. For the unary - we have
120 operator-() as a method, Neg() as synonym for it and Negate() which returns
121 the copy of the object with the changed sign.
124 // an invalid/default date time object which may be used as the default
125 // argument for arguments of type wxDateTime; it is also returned by all
126 // functions returning wxDateTime on failure (this is why it is also called
127 // wxInvalidDateTime)
128 class WXDLLIMPEXP_BASE wxDateTime
;
130 extern WXDLLIMPEXP_DATA_BASE(const wxChar
*) wxDefaultDateTimeFormat
;
131 extern WXDLLIMPEXP_DATA_BASE(const wxChar
*) wxDefaultTimeSpanFormat
;
132 extern WXDLLIMPEXP_DATA_BASE(const wxDateTime
) wxDefaultDateTime
;
134 #define wxInvalidDateTime wxDefaultDateTime
136 // ----------------------------------------------------------------------------
137 // wxDateTime represents an absolute moment in the time
138 // ----------------------------------------------------------------------------
140 class WXDLLIMPEXP_BASE wxDateTime
144 // ------------------------------------------------------------------------
146 // a small unsigned integer type for storing things like minutes,
147 // seconds &c. It should be at least short (i.e. not char) to contain
148 // the number of milliseconds - it may also be 'int' because there is
149 // no size penalty associated with it in our code, we don't store any
150 // data in this format
151 typedef unsigned short wxDateTime_t
;
154 // ------------------------------------------------------------------------
159 // the time in the current time zone
162 // zones from GMT (= Greenwhich Mean Time): they're guaranteed to be
163 // consequent numbers, so writing something like `GMT0 + offset' is
164 // safe if abs(offset) <= 12
166 // underscore stands for minus
167 GMT_12
, GMT_11
, GMT_10
, GMT_9
, GMT_8
, GMT_7
,
168 GMT_6
, GMT_5
, GMT_4
, GMT_3
, GMT_2
, GMT_1
,
170 GMT1
, GMT2
, GMT3
, GMT4
, GMT5
, GMT6
,
171 GMT7
, GMT8
, GMT9
, GMT10
, GMT11
, GMT12
, GMT13
,
172 // Note that GMT12 and GMT_12 are not the same: there is a difference
173 // of exactly one day between them
175 // some symbolic names for TZ
178 WET
= GMT0
, // Western Europe Time
179 WEST
= GMT1
, // Western Europe Summer Time
180 CET
= GMT1
, // Central Europe Time
181 CEST
= GMT2
, // Central Europe Summer Time
182 EET
= GMT2
, // Eastern Europe Time
183 EEST
= GMT3
, // Eastern Europe Summer Time
184 MSK
= GMT3
, // Moscow Time
185 MSD
= GMT4
, // Moscow Summer Time
188 AST
= GMT_4
, // Atlantic Standard Time
189 ADT
= GMT_3
, // Atlantic Daylight Time
190 EST
= GMT_5
, // Eastern Standard Time
191 EDT
= GMT_4
, // Eastern Daylight Saving Time
192 CST
= GMT_6
, // Central Standard Time
193 CDT
= GMT_5
, // Central Daylight Saving Time
194 MST
= GMT_7
, // Mountain Standard Time
195 MDT
= GMT_6
, // Mountain Daylight Saving Time
196 PST
= GMT_8
, // Pacific Standard Time
197 PDT
= GMT_7
, // Pacific Daylight Saving Time
198 HST
= GMT_10
, // Hawaiian Standard Time
199 AKST
= GMT_9
, // Alaska Standard Time
200 AKDT
= GMT_8
, // Alaska Daylight Saving Time
204 A_WST
= GMT8
, // Western Standard Time
205 A_CST
= GMT13
+ 1, // Central Standard Time (+9.5)
206 A_EST
= GMT10
, // Eastern Standard Time
207 A_ESST
= GMT11
, // Eastern Summer Time
210 NZST
= GMT12
, // Standard Time
211 NZDT
= GMT13
, // Daylight Saving Time
213 // TODO add more symbolic timezone names here
215 // Universal Coordinated Time = the new and politically correct name
220 // the calendar systems we know about: notice that it's valid (for
221 // this classes purpose anyhow) to work with any of these calendars
222 // even with the dates before the historical appearance of the
226 Gregorian
, // current calendar
227 Julian
// calendar in use since -45 until the 1582 (or later)
229 // TODO Hebrew, Chinese, Maya, ... (just kidding) (or then may be not?)
232 // these values only are used to identify the different dates of
233 // adoption of the Gregorian calendar (see IsGregorian())
235 // All data and comments taken verbatim from "The Calendar FAQ (v 2.0)"
236 // by Claus Tøndering, http://www.pip.dknet.dk/~c-t/calendar.html
237 // except for the comments "we take".
239 // Symbol "->" should be read as "was followed by" in the comments
241 enum GregorianAdoption
243 Gr_Unknown
, // no data for this country or it's too uncertain to use
244 Gr_Standard
, // on the day 0 of Gregorian calendar: 15 Oct 1582
246 Gr_Alaska
, // Oct 1867 when Alaska became part of the USA
247 Gr_Albania
, // Dec 1912
249 Gr_Austria
= Gr_Unknown
, // Different regions on different dates
250 Gr_Austria_Brixen
, // 5 Oct 1583 -> 16 Oct 1583
251 Gr_Austria_Salzburg
= Gr_Austria_Brixen
,
252 Gr_Austria_Tyrol
= Gr_Austria_Brixen
,
253 Gr_Austria_Carinthia
, // 14 Dec 1583 -> 25 Dec 1583
254 Gr_Austria_Styria
= Gr_Austria_Carinthia
,
256 Gr_Belgium
, // Then part of the Netherlands
258 Gr_Bulgaria
= Gr_Unknown
, // Unknown precisely (from 1915 to 1920)
259 Gr_Bulgaria_1
, // 18 Mar 1916 -> 1 Apr 1916
260 Gr_Bulgaria_2
, // 31 Mar 1916 -> 14 Apr 1916
261 Gr_Bulgaria_3
, // 3 Sep 1920 -> 17 Sep 1920
263 Gr_Canada
= Gr_Unknown
, // Different regions followed the changes in
264 // Great Britain or France
266 Gr_China
= Gr_Unknown
, // Different authorities say:
267 Gr_China_1
, // 18 Dec 1911 -> 1 Jan 1912
268 Gr_China_2
, // 18 Dec 1928 -> 1 Jan 1929
270 Gr_Czechoslovakia
, // (Bohemia and Moravia) 6 Jan 1584 -> 17 Jan 1584
271 Gr_Denmark
, // (including Norway) 18 Feb 1700 -> 1 Mar 1700
274 Gr_Finland
, // Then part of Sweden
276 Gr_France
, // 9 Dec 1582 -> 20 Dec 1582
277 Gr_France_Alsace
, // 4 Feb 1682 -> 16 Feb 1682
278 Gr_France_Lorraine
, // 16 Feb 1760 -> 28 Feb 1760
279 Gr_France_Strasbourg
, // February 1682
281 Gr_Germany
= Gr_Unknown
, // Different states on different dates:
282 Gr_Germany_Catholic
, // 1583-1585 (we take 1584)
283 Gr_Germany_Prussia
, // 22 Aug 1610 -> 2 Sep 1610
284 Gr_Germany_Protestant
, // 18 Feb 1700 -> 1 Mar 1700
286 Gr_GreatBritain
, // 2 Sep 1752 -> 14 Sep 1752 (use 'cal(1)')
288 Gr_Greece
, // 9 Mar 1924 -> 23 Mar 1924
289 Gr_Hungary
, // 21 Oct 1587 -> 1 Nov 1587
290 Gr_Ireland
= Gr_GreatBritain
,
291 Gr_Italy
= Gr_Standard
,
293 Gr_Japan
= Gr_Unknown
, // Different authorities say:
294 Gr_Japan_1
, // 19 Dec 1872 -> 1 Jan 1873
295 Gr_Japan_2
, // 19 Dec 1892 -> 1 Jan 1893
296 Gr_Japan_3
, // 18 Dec 1918 -> 1 Jan 1919
298 Gr_Latvia
, // 1915-1918 (we take 1915)
299 Gr_Lithuania
, // 1915
300 Gr_Luxemburg
, // 14 Dec 1582 -> 25 Dec 1582
301 Gr_Netherlands
= Gr_Belgium
, // (including Belgium) 1 Jan 1583
303 // this is too weird to take into account: the Gregorian calendar was
304 // introduced twice in Groningen, first time 28 Feb 1583 was followed
305 // by 11 Mar 1583, then it has gone back to Julian in the summer of
306 // 1584 and then 13 Dec 1700 -> 12 Jan 1701 - which is
307 // the date we take here
308 Gr_Netherlands_Groningen
, // 13 Dec 1700 -> 12 Jan 1701
309 Gr_Netherlands_Gelderland
, // 30 Jun 1700 -> 12 Jul 1700
310 Gr_Netherlands_Utrecht
, // (and Overijssel) 30 Nov 1700->12 Dec 1700
311 Gr_Netherlands_Friesland
, // (and Drenthe) 31 Dec 1700 -> 12 Jan 1701
313 Gr_Norway
= Gr_Denmark
, // Then part of Denmark
314 Gr_Poland
= Gr_Standard
,
315 Gr_Portugal
= Gr_Standard
,
316 Gr_Romania
, // 31 Mar 1919 -> 14 Apr 1919
317 Gr_Russia
, // 31 Jan 1918 -> 14 Feb 1918
318 Gr_Scotland
= Gr_GreatBritain
,
319 Gr_Spain
= Gr_Standard
,
321 // Sweden has a curious history. Sweden decided to make a gradual
322 // change from the Julian to the Gregorian calendar. By dropping every
323 // leap year from 1700 through 1740 the eleven superfluous days would
324 // be omitted and from 1 Mar 1740 they would be in sync with the
325 // Gregorian calendar. (But in the meantime they would be in sync with
328 // So 1700 (which should have been a leap year in the Julian calendar)
329 // was not a leap year in Sweden. However, by mistake 1704 and 1708
330 // became leap years. This left Sweden out of synchronisation with
331 // both the Julian and the Gregorian world, so they decided to go back
332 // to the Julian calendar. In order to do this, they inserted an extra
333 // day in 1712, making that year a double leap year! So in 1712,
334 // February had 30 days in Sweden.
336 // Later, in 1753, Sweden changed to the Gregorian calendar by
337 // dropping 11 days like everyone else.
338 Gr_Sweden
= Gr_Finland
, // 17 Feb 1753 -> 1 Mar 1753
340 Gr_Switzerland
= Gr_Unknown
,// Different cantons used different dates
341 Gr_Switzerland_Catholic
, // 1583, 1584 or 1597 (we take 1584)
342 Gr_Switzerland_Protestant
, // 31 Dec 1700 -> 12 Jan 1701
344 Gr_Turkey
, // 1 Jan 1927
345 Gr_USA
= Gr_GreatBritain
,
346 Gr_Wales
= Gr_GreatBritain
,
347 Gr_Yugoslavia
// 1919
350 // the country parameter is used so far for calculating the start and
351 // the end of DST period and for deciding whether the date is a work
354 // TODO move this to intl.h
356 // Required for WinCE
363 Country_Unknown
, // no special information for this country
364 Country_Default
, // set the default country with SetCountry() method
365 // or use the default country with any other
367 // TODO add more countries (for this we must know about DST and/or
368 // holidays for this country)
370 // Western European countries: we assume that they all follow the same
371 // DST rules (true or false?)
372 Country_WesternEurope_Start
,
373 Country_EEC
= Country_WesternEurope_Start
,
377 Country_WesternEurope_End
= UK
,
382 // symbolic names for the months
385 Jan
, Feb
, Mar
, Apr
, May
, Jun
, Jul
, Aug
, Sep
, Oct
, Nov
, Dec
, Inv_Month
388 // symbolic names for the weekdays
391 Sun
, Mon
, Tue
, Wed
, Thu
, Fri
, Sat
, Inv_WeekDay
394 // invalid value for the year
397 Inv_Year
= SHRT_MIN
// should hold in wxDateTime_t
400 // flags for GetWeekDayName and GetMonthName
403 Name_Full
= 0x01, // return full name
404 Name_Abbr
= 0x02 // return abbreviated name
407 // flags for GetWeekOfYear and GetWeekOfMonth
410 Default_First
, // Sunday_First for US, Monday_First for the rest
411 Monday_First
, // week starts with a Monday
412 Sunday_First
// week starts with a Sunday
416 // ------------------------------------------------------------------------
418 // a class representing a time zone: basicly, this is just an offset
419 // (in seconds) from GMT
420 class WXDLLIMPEXP_BASE TimeZone
424 TimeZone(wxDateTime_t offset
= 0) { m_offset
= offset
; }
426 long GetOffset() const { return m_offset
; }
429 // offset for this timezone from GMT in seconds
433 // standard struct tm is limited to the years from 1900 (because
434 // tm_year field is the offset from 1900), so we use our own struct
435 // instead to represent broken down time
437 // NB: this struct should always be kept normalized (i.e. mon should
438 // be < 12, 1 <= day <= 31 &c), so use AddMonths(), AddDays()
439 // instead of modifying the member fields directly!
440 struct WXDLLIMPEXP_BASE Tm
442 wxDateTime_t msec
, sec
, min
, hour
, mday
;
446 // default ctor inits the object to an invalid value
449 // ctor from struct tm and the timezone
450 Tm(const struct tm
& tm
, const TimeZone
& tz
);
452 // check that the given date/time is valid (in Gregorian calendar)
453 bool IsValid() const;
456 WeekDay
GetWeekDay() // not const because wday may be changed
458 if ( wday
== Inv_WeekDay
)
461 return (WeekDay
)wday
;
464 // add the given number of months to the date keeping it normalized
465 void AddMonths(int monDiff
);
467 // add the given number of months to the date keeping it normalized
468 void AddDays(int dayDiff
);
471 // compute the weekday from other fields
472 void ComputeWeekDay();
474 // the timezone we correspond to
477 // these values can't be accessed directly because they're not always
478 // computed and we calculate them on demand
479 wxDateTime_t wday
, yday
;
483 // ------------------------------------------------------------------------
485 // set the current country
486 static void SetCountry(Country country
);
487 // get the current country
488 static Country
GetCountry();
490 // return true if the country is a West European one (in practice,
491 // this means that the same DST rules as for EEC apply)
492 static bool IsWestEuropeanCountry(Country country
= Country_Default
);
494 // return the current year
495 static int GetCurrentYear(Calendar cal
= Gregorian
);
497 // convert the year as returned by wxDateTime::GetYear() to a year
498 // suitable for BC/AD notation. The difference is that BC year 1
499 // corresponds to the year 0 (while BC year 0 didn't exist) and AD
500 // year N is just year N.
501 static int ConvertYearToBC(int year
);
503 // return the current month
504 static Month
GetCurrentMonth(Calendar cal
= Gregorian
);
506 // returns true if the given year is a leap year in the given calendar
507 static bool IsLeapYear(int year
= Inv_Year
, Calendar cal
= Gregorian
);
509 // get the century (19 for 1999, 20 for 2000 and -5 for 492 BC)
510 static int GetCentury(int year
);
512 // returns the number of days in this year (356 or 355 for Gregorian
513 // calendar usually :-)
514 static wxDateTime_t
GetNumberOfDays(int year
, Calendar cal
= Gregorian
);
516 // get the number of the days in the given month (default value for
517 // the year means the current one)
518 static wxDateTime_t
GetNumberOfDays(Month month
,
520 Calendar cal
= Gregorian
);
522 // get the full (default) or abbreviated month name in the current
523 // locale, returns empty string on error
524 static wxString
GetMonthName(Month month
,
525 NameFlags flags
= Name_Full
);
527 // get the full (default) or abbreviated weekday name in the current
528 // locale, returns empty string on error
529 static wxString
GetWeekDayName(WeekDay weekday
,
530 NameFlags flags
= Name_Full
);
532 // get the AM and PM strings in the current locale (may be empty)
533 static void GetAmPmStrings(wxString
*am
, wxString
*pm
);
535 // return true if the given country uses DST for this year
536 static bool IsDSTApplicable(int year
= Inv_Year
,
537 Country country
= Country_Default
);
539 // get the beginning of DST for this year, will return invalid object
540 // if no DST applicable in this year. The default value of the
541 // parameter means to take the current year.
542 static wxDateTime
GetBeginDST(int year
= Inv_Year
,
543 Country country
= Country_Default
);
544 // get the end of DST for this year, will return invalid object
545 // if no DST applicable in this year. The default value of the
546 // parameter means to take the current year.
547 static wxDateTime
GetEndDST(int year
= Inv_Year
,
548 Country country
= Country_Default
);
550 // return the wxDateTime object for the current time
551 static inline wxDateTime
Now();
553 // return the wxDateTime object for the current time with millisecond
554 // precision (if available on this platform)
555 static wxDateTime
UNow();
557 // return the wxDateTime object for today midnight: i.e. as Now() but
558 // with time set to 0
559 static inline wxDateTime
Today();
561 // constructors: you should test whether the constructor succeeded with
562 // IsValid() function. The values Inv_Month and Inv_Year for the
563 // parameters mean take current month and/or year values.
564 // ------------------------------------------------------------------------
566 // default ctor does not initialize the object, use Set()!
567 wxDateTime() { m_time
= wxLongLong((long)ULONG_MAX
, ULONG_MAX
); }
569 // from time_t: seconds since the Epoch 00:00:00 UTC, Jan 1, 1970)
570 #if (!(defined(__VISAGECPP__) && __IBMCPP__ >= 400))
571 // VA C++ confuses this with wxDateTime(double jdn) thinking it is a duplicate declaration
572 inline wxDateTime(time_t timet
);
574 // from broken down time/date (only for standard Unix range)
575 inline wxDateTime(const struct tm
& tm
);
576 // from broken down time/date (any range)
577 inline wxDateTime(const Tm
& tm
);
579 // from JDN (beware of rounding errors)
580 inline wxDateTime(double jdn
);
582 // from separate values for each component, date set to today
583 inline wxDateTime(wxDateTime_t hour
,
584 wxDateTime_t minute
= 0,
585 wxDateTime_t second
= 0,
586 wxDateTime_t millisec
= 0);
587 // from separate values for each component with explicit date
588 inline wxDateTime(wxDateTime_t day
, // day of the month
590 int year
= Inv_Year
, // 1999, not 99 please!
591 wxDateTime_t hour
= 0,
592 wxDateTime_t minute
= 0,
593 wxDateTime_t second
= 0,
594 wxDateTime_t millisec
= 0);
596 // default copy ctor ok
600 // assignment operators and Set() functions: all non const methods return
601 // the reference to this object. IsValid() should be used to test whether
602 // the function succeeded.
603 // ------------------------------------------------------------------------
605 // set to the current time
606 inline wxDateTime
& SetToCurrent();
608 #if (!(defined(__VISAGECPP__) && __IBMCPP__ >= 400))
609 // VA C++ confuses this with wxDateTime(double jdn) thinking it is a duplicate declaration
610 // set to given time_t value
611 inline wxDateTime
& Set(time_t timet
);
614 // set to given broken down time/date
615 wxDateTime
& Set(const struct tm
& tm
);
617 // set to given broken down time/date
618 inline wxDateTime
& Set(const Tm
& tm
);
620 // set to given JDN (beware of rounding errors)
621 wxDateTime
& Set(double jdn
);
623 // set to given time, date = today
624 wxDateTime
& Set(wxDateTime_t hour
,
625 wxDateTime_t minute
= 0,
626 wxDateTime_t second
= 0,
627 wxDateTime_t millisec
= 0);
629 // from separate values for each component with explicit date
630 // (defaults for month and year are the current values)
631 wxDateTime
& Set(wxDateTime_t day
,
633 int year
= Inv_Year
, // 1999, not 99 please!
634 wxDateTime_t hour
= 0,
635 wxDateTime_t minute
= 0,
636 wxDateTime_t second
= 0,
637 wxDateTime_t millisec
= 0);
639 // resets time to 00:00:00, doesn't change the date
640 wxDateTime
& ResetTime();
642 #if wxABI_VERSION >= 20802
643 // get the date part of this object only, i.e. the object which has the
644 // same date as this one but time of 00:00:00
645 wxDateTime
GetDateOnly() const;
646 #endif // wxABI 2.8.1+
648 // the following functions don't change the values of the other
649 // fields, i.e. SetMinute() won't change either hour or seconds value
652 wxDateTime
& SetYear(int year
);
654 wxDateTime
& SetMonth(Month month
);
655 // set the day of the month
656 wxDateTime
& SetDay(wxDateTime_t day
);
658 wxDateTime
& SetHour(wxDateTime_t hour
);
660 wxDateTime
& SetMinute(wxDateTime_t minute
);
662 wxDateTime
& SetSecond(wxDateTime_t second
);
664 wxDateTime
& SetMillisecond(wxDateTime_t millisecond
);
666 // assignment operator from time_t
667 wxDateTime
& operator=(time_t timet
) { return Set(timet
); }
669 // assignment operator from broken down time/date
670 wxDateTime
& operator=(const struct tm
& tm
) { return Set(tm
); }
672 // assignment operator from broken down time/date
673 wxDateTime
& operator=(const Tm
& tm
) { return Set(tm
); }
675 // default assignment operator is ok
677 // calendar calculations (functions which set the date only leave the time
678 // unchanged, e.g. don't explictly zero it): SetXXX() functions modify the
679 // object itself, GetXXX() ones return a new object.
680 // ------------------------------------------------------------------------
682 // set to the given week day in the same week as this one
683 wxDateTime
& SetToWeekDayInSameWeek(WeekDay weekday
,
684 WeekFlags flags
= Monday_First
);
685 inline wxDateTime
GetWeekDayInSameWeek(WeekDay weekday
,
686 WeekFlags flags
= Monday_First
) const;
688 // set to the next week day following this one
689 wxDateTime
& SetToNextWeekDay(WeekDay weekday
);
690 inline wxDateTime
GetNextWeekDay(WeekDay weekday
) const;
692 // set to the previous week day before this one
693 wxDateTime
& SetToPrevWeekDay(WeekDay weekday
);
694 inline wxDateTime
GetPrevWeekDay(WeekDay weekday
) const;
696 // set to Nth occurence of given weekday in the given month of the
697 // given year (time is set to 0), return true on success and false on
698 // failure. n may be positive (1..5) or negative to count from the end
699 // of the month (see helper function SetToLastWeekDay())
700 bool SetToWeekDay(WeekDay weekday
,
702 Month month
= Inv_Month
,
703 int year
= Inv_Year
);
704 inline wxDateTime
GetWeekDay(WeekDay weekday
,
706 Month month
= Inv_Month
,
707 int year
= Inv_Year
) const;
709 // sets to the last weekday in the given month, year
710 inline bool SetToLastWeekDay(WeekDay weekday
,
711 Month month
= Inv_Month
,
712 int year
= Inv_Year
);
713 inline wxDateTime
GetLastWeekDay(WeekDay weekday
,
714 Month month
= Inv_Month
,
715 int year
= Inv_Year
);
717 #if WXWIN_COMPATIBILITY_2_6
718 // sets the date to the given day of the given week in the year,
719 // returns true on success and false if given date doesn't exist (e.g.
722 // these functions are badly defined as they're not the reverse of
723 // GetWeekOfYear(), use SetToTheWeekOfYear() instead
724 wxDEPRECATED( bool SetToTheWeek(wxDateTime_t numWeek
,
725 WeekDay weekday
= Mon
,
726 WeekFlags flags
= Monday_First
) );
727 wxDEPRECATED( wxDateTime
GetWeek(wxDateTime_t numWeek
,
728 WeekDay weekday
= Mon
,
729 WeekFlags flags
= Monday_First
) const );
730 #endif // WXWIN_COMPATIBILITY_2_6
732 // returns the date corresponding to the given week day of the given
733 // week (in ISO notation) of the specified year
734 static wxDateTime
SetToWeekOfYear(int year
,
735 wxDateTime_t numWeek
,
736 WeekDay weekday
= Mon
);
738 // sets the date to the last day of the given (or current) month or the
739 // given (or current) year
740 wxDateTime
& SetToLastMonthDay(Month month
= Inv_Month
,
741 int year
= Inv_Year
);
742 inline wxDateTime
GetLastMonthDay(Month month
= Inv_Month
,
743 int year
= Inv_Year
) const;
745 // sets to the given year day (1..365 or 366)
746 wxDateTime
& SetToYearDay(wxDateTime_t yday
);
747 inline wxDateTime
GetYearDay(wxDateTime_t yday
) const;
749 // The definitions below were taken verbatim from
751 // http://www.capecod.net/~pbaum/date/date0.htm
753 // (Peter Baum's home page)
755 // definition: The Julian Day Number, Julian Day, or JD of a
756 // particular instant of time is the number of days and fractions of a
757 // day since 12 hours Universal Time (Greenwich mean noon) on January
758 // 1 of the year -4712, where the year is given in the Julian
759 // proleptic calendar. The idea of using this reference date was
760 // originally proposed by Joseph Scalizer in 1582 to count years but
761 // it was modified by 19th century astronomers to count days. One
762 // could have equivalently defined the reference time to be noon of
763 // November 24, -4713 if were understood that Gregorian calendar rules
764 // were applied. Julian days are Julian Day Numbers and are not to be
765 // confused with Julian dates.
767 // definition: The Rata Die number is a date specified as the number
768 // of days relative to a base date of December 31 of the year 0. Thus
769 // January 1 of the year 1 is Rata Die day 1.
771 // get the Julian Day number (the fractional part specifies the time of
772 // the day, related to noon - beware of rounding errors!)
773 double GetJulianDayNumber() const;
774 double GetJDN() const { return GetJulianDayNumber(); }
776 // get the Modified Julian Day number: it is equal to JDN - 2400000.5
777 // and so integral MJDs correspond to the midnights (and not noons).
778 // MJD 0 is Nov 17, 1858
779 double GetModifiedJulianDayNumber() const { return GetJDN() - 2400000.5; }
780 double GetMJD() const { return GetModifiedJulianDayNumber(); }
782 // get the Rata Die number
783 double GetRataDie() const;
785 // TODO algorithms for calculating some important dates, such as
786 // religious holidays (Easter...) or moon/solar eclipses? Some
787 // algorithms can be found in the calendar FAQ
790 // Timezone stuff: a wxDateTime object constructed using given
791 // day/month/year/hour/min/sec values is interpreted as this moment in
792 // local time. Using the functions below, it may be converted to another
793 // time zone (e.g., the Unix epoch is wxDateTime(1, Jan, 1970).ToGMT()).
795 // These functions try to handle DST internally, but there is no magical
796 // way to know all rules for it in all countries in the world, so if the
797 // program can handle it itself (or doesn't want to handle it at all for
798 // whatever reason), the DST handling can be disabled with noDST.
799 // ------------------------------------------------------------------------
801 // transform to any given timezone
802 inline wxDateTime
ToTimezone(const TimeZone
& tz
, bool noDST
= false) const;
803 wxDateTime
& MakeTimezone(const TimeZone
& tz
, bool noDST
= false);
805 // interpret current value as being in another timezone and transform
807 inline wxDateTime
FromTimezone(const TimeZone
& tz
, bool noDST
= false) const;
808 wxDateTime
& MakeFromTimezone(const TimeZone
& tz
, bool noDST
= false);
810 // transform to/from GMT/UTC
811 wxDateTime
ToUTC(bool noDST
= false) const { return ToTimezone(UTC
, noDST
); }
812 wxDateTime
& MakeUTC(bool noDST
= false) { return MakeTimezone(UTC
, noDST
); }
814 wxDateTime
ToGMT(bool noDST
= false) const { return ToUTC(noDST
); }
815 wxDateTime
& MakeGMT(bool noDST
= false) { return MakeUTC(noDST
); }
817 wxDateTime
FromUTC(bool noDST
= false) const
818 { return FromTimezone(UTC
, noDST
); }
819 wxDateTime
& MakeFromUTC(bool noDST
= false)
820 { return MakeFromTimezone(UTC
, noDST
); }
822 // is daylight savings time in effect at this moment according to the
823 // rules of the specified country?
825 // Return value is > 0 if DST is in effect, 0 if it is not and -1 if
826 // the information is not available (this is compatible with ANSI C)
827 int IsDST(Country country
= Country_Default
) const;
830 // accessors: many of them take the timezone parameter which indicates the
831 // timezone for which to make the calculations and the default value means
832 // to do it for the current timezone of this machine (even if the function
833 // only operates with the date it's necessary because a date may wrap as
834 // result of timezone shift)
835 // ------------------------------------------------------------------------
837 // is the date valid?
838 inline bool IsValid() const { return m_time
!= wxInvalidDateTime
.m_time
; }
840 // get the broken down date/time representation in the given timezone
842 // If you wish to get several time components (day, month and year),
843 // consider getting the whole Tm strcuture first and retrieving the
844 // value from it - this is much more efficient
845 Tm
GetTm(const TimeZone
& tz
= Local
) const;
847 // get the number of seconds since the Unix epoch - returns (time_t)-1
848 // if the value is out of range
849 inline time_t GetTicks() const;
851 // get the century, same as GetCentury(GetYear())
852 int GetCentury(const TimeZone
& tz
= Local
) const
853 { return GetCentury(GetYear(tz
)); }
854 // get the year (returns Inv_Year if date is invalid)
855 int GetYear(const TimeZone
& tz
= Local
) const
856 { return GetTm(tz
).year
; }
857 // get the month (Inv_Month if date is invalid)
858 Month
GetMonth(const TimeZone
& tz
= Local
) const
859 { return (Month
)GetTm(tz
).mon
; }
860 // get the month day (in 1..31 range, 0 if date is invalid)
861 wxDateTime_t
GetDay(const TimeZone
& tz
= Local
) const
862 { return GetTm(tz
).mday
; }
863 // get the day of the week (Inv_WeekDay if date is invalid)
864 WeekDay
GetWeekDay(const TimeZone
& tz
= Local
) const
865 { return GetTm(tz
).GetWeekDay(); }
866 // get the hour of the day
867 wxDateTime_t
GetHour(const TimeZone
& tz
= Local
) const
868 { return GetTm(tz
).hour
; }
870 wxDateTime_t
GetMinute(const TimeZone
& tz
= Local
) const
871 { return GetTm(tz
).min
; }
873 wxDateTime_t
GetSecond(const TimeZone
& tz
= Local
) const
874 { return GetTm(tz
).sec
; }
876 wxDateTime_t
GetMillisecond(const TimeZone
& tz
= Local
) const
877 { return GetTm(tz
).msec
; }
879 // get the day since the year start (1..366, 0 if date is invalid)
880 wxDateTime_t
GetDayOfYear(const TimeZone
& tz
= Local
) const;
881 // get the week number since the year start (1..52 or 53, 0 if date is
883 wxDateTime_t
GetWeekOfYear(WeekFlags flags
= Monday_First
,
884 const TimeZone
& tz
= Local
) const;
885 // get the week number since the month start (1..5, 0 if date is
887 wxDateTime_t
GetWeekOfMonth(WeekFlags flags
= Monday_First
,
888 const TimeZone
& tz
= Local
) const;
890 // is this date a work day? This depends on a country, of course,
891 // because the holidays are different in different countries
892 bool IsWorkDay(Country country
= Country_Default
) const;
894 // is this date later than Gregorian calendar introduction for the
895 // given country (see enum GregorianAdoption)?
897 // NB: this function shouldn't be considered as absolute authority in
898 // the matter. Besides, for some countries the exact date of
899 // adoption of the Gregorian calendar is simply unknown.
900 bool IsGregorianDate(GregorianAdoption country
= Gr_Standard
) const;
902 // dos date and time format
903 // ------------------------------------------------------------------------
905 // set from the DOS packed format
906 wxDateTime
& SetFromDOS(unsigned long ddt
);
908 // pack the date in DOS format
909 unsigned long GetAsDOS() const;
911 // comparison (see also functions below for operator versions)
912 // ------------------------------------------------------------------------
914 // returns true if the two moments are strictly identical
915 inline bool IsEqualTo(const wxDateTime
& datetime
) const;
917 // returns true if the date is strictly earlier than the given one
918 inline bool IsEarlierThan(const wxDateTime
& datetime
) const;
920 // returns true if the date is strictly later than the given one
921 inline bool IsLaterThan(const wxDateTime
& datetime
) const;
923 // returns true if the date is strictly in the given range
924 inline bool IsStrictlyBetween(const wxDateTime
& t1
,
925 const wxDateTime
& t2
) const;
927 // returns true if the date is in the given range
928 inline bool IsBetween(const wxDateTime
& t1
, const wxDateTime
& t2
) const;
930 // do these two objects refer to the same date?
931 inline bool IsSameDate(const wxDateTime
& dt
) const;
933 // do these two objects have the same time?
934 inline bool IsSameTime(const wxDateTime
& dt
) const;
936 // are these two objects equal up to given timespan?
937 inline bool IsEqualUpTo(const wxDateTime
& dt
, const wxTimeSpan
& ts
) const;
939 inline bool operator<(const wxDateTime
& dt
) const
941 wxASSERT_MSG( IsValid() && dt
.IsValid(), _T("invalid wxDateTime") );
942 return GetValue() < dt
.GetValue();
945 inline bool operator<=(const wxDateTime
& dt
) const
947 wxASSERT_MSG( IsValid() && dt
.IsValid(), _T("invalid wxDateTime") );
948 return GetValue() <= dt
.GetValue();
951 inline bool operator>(const wxDateTime
& dt
) const
953 wxASSERT_MSG( IsValid() && dt
.IsValid(), _T("invalid wxDateTime") );
954 return GetValue() > dt
.GetValue();
957 inline bool operator>=(const wxDateTime
& dt
) const
959 wxASSERT_MSG( IsValid() && dt
.IsValid(), _T("invalid wxDateTime") );
960 return GetValue() >= dt
.GetValue();
963 inline bool operator==(const wxDateTime
& dt
) const
965 wxASSERT_MSG( IsValid() && dt
.IsValid(), _T("invalid wxDateTime") );
966 return GetValue() == dt
.GetValue();
969 inline bool operator!=(const wxDateTime
& dt
) const
971 wxASSERT_MSG( IsValid() && dt
.IsValid(), _T("invalid wxDateTime") );
972 return GetValue() != dt
.GetValue();
975 // arithmetics with dates (see also below for more operators)
976 // ------------------------------------------------------------------------
978 // return the sum of the date with a time span (positive or negative)
979 inline wxDateTime
Add(const wxTimeSpan
& diff
) const;
980 // add a time span (positive or negative)
981 inline wxDateTime
& Add(const wxTimeSpan
& diff
);
982 // add a time span (positive or negative)
983 inline wxDateTime
& operator+=(const wxTimeSpan
& diff
);
984 inline wxDateTime
operator+(const wxTimeSpan
& ts
) const
986 wxDateTime
dt(*this);
991 // return the difference of the date with a time span
992 inline wxDateTime
Subtract(const wxTimeSpan
& diff
) const;
993 // subtract a time span (positive or negative)
994 inline wxDateTime
& Subtract(const wxTimeSpan
& diff
);
995 // subtract a time span (positive or negative)
996 inline wxDateTime
& operator-=(const wxTimeSpan
& diff
);
997 inline wxDateTime
operator-(const wxTimeSpan
& ts
) const
999 wxDateTime
dt(*this);
1004 // return the sum of the date with a date span
1005 inline wxDateTime
Add(const wxDateSpan
& diff
) const;
1006 // add a date span (positive or negative)
1007 wxDateTime
& Add(const wxDateSpan
& diff
);
1008 // add a date span (positive or negative)
1009 inline wxDateTime
& operator+=(const wxDateSpan
& diff
);
1010 inline wxDateTime
operator+(const wxDateSpan
& ds
) const
1012 wxDateTime
dt(*this);
1017 // return the difference of the date with a date span
1018 inline wxDateTime
Subtract(const wxDateSpan
& diff
) const;
1019 // subtract a date span (positive or negative)
1020 inline wxDateTime
& Subtract(const wxDateSpan
& diff
);
1021 // subtract a date span (positive or negative)
1022 inline wxDateTime
& operator-=(const wxDateSpan
& diff
);
1023 inline wxDateTime
operator-(const wxDateSpan
& ds
) const
1025 wxDateTime
dt(*this);
1030 // return the difference between two dates
1031 inline wxTimeSpan
Subtract(const wxDateTime
& dt
) const;
1032 inline wxTimeSpan
operator-(const wxDateTime
& dt2
) const;
1034 // conversion to/from text: all conversions from text return the pointer to
1035 // the next character following the date specification (i.e. the one where
1036 // the scan had to stop) or NULL on failure.
1037 // ------------------------------------------------------------------------
1039 // parse a string in RFC 822 format (found e.g. in mail headers and
1040 // having the form "Wed, 10 Feb 1999 19:07:07 +0100")
1041 const wxChar
*ParseRfc822Date(const wxChar
* date
);
1042 // parse a date/time in the given format (see strptime(3)), fill in
1043 // the missing (in the string) fields with the values of dateDef (by
1044 // default, they will not change if they had valid values or will
1045 // default to Today() otherwise)
1046 const wxChar
*ParseFormat(const wxChar
*date
,
1047 const wxChar
*format
= wxDefaultDateTimeFormat
,
1048 const wxDateTime
& dateDef
= wxDefaultDateTime
);
1049 // parse a string containing the date/time in "free" format, this
1050 // function will try to make an educated guess at the string contents
1051 const wxChar
*ParseDateTime(const wxChar
*datetime
);
1052 // parse a string containing the date only in "free" format (less
1053 // flexible than ParseDateTime)
1054 const wxChar
*ParseDate(const wxChar
*date
);
1055 // parse a string containing the time only in "free" format
1056 const wxChar
*ParseTime(const wxChar
*time
);
1058 // this function accepts strftime()-like format string (default
1059 // argument corresponds to the preferred date and time representation
1060 // for the current locale) and returns the string containing the
1061 // resulting text representation
1062 wxString
Format(const wxChar
*format
= wxDefaultDateTimeFormat
,
1063 const TimeZone
& tz
= Local
) const;
1064 // preferred date representation for the current locale
1065 wxString
FormatDate() const { return Format(_T("%x")); }
1066 // preferred time representation for the current locale
1067 wxString
FormatTime() const { return Format(_T("%X")); }
1068 // returns the string representing the date in ISO 8601 format
1070 wxString
FormatISODate() const { return Format(_T("%Y-%m-%d")); }
1071 // returns the string representing the time in ISO 8601 format
1073 wxString
FormatISOTime() const { return Format(_T("%H:%M:%S")); }
1076 // ------------------------------------------------------------------------
1078 // construct from internal representation
1079 wxDateTime(const wxLongLong
& time
) { m_time
= time
; }
1081 // get the internal representation
1082 inline wxLongLong
GetValue() const;
1084 // a helper function to get the current time_t
1085 static time_t GetTimeNow() { return time((time_t *)NULL
); }
1087 // another one to get the current time broken down
1088 static struct tm
*GetTmNow()
1090 time_t t
= GetTimeNow();
1091 return localtime(&t
);
1094 // get current time using thread-safe function
1095 static struct tm
*GetTmNow(struct tm
*tmstruct
);
1098 // the current country - as it's the same for all program objects (unless
1099 // it runs on a _really_ big cluster system :-), this is a static member:
1100 // see SetCountry() and GetCountry()
1101 static Country ms_country
;
1103 // this constant is used to transform a time_t value to the internal
1104 // representation, as time_t is in seconds and we use milliseconds it's
1106 static const long TIME_T_FACTOR
;
1108 // returns true if we fall in range in which we can use standard ANSI C
1110 inline bool IsInStdRange() const;
1112 // the internal representation of the time is the amount of milliseconds
1113 // elapsed since the origin which is set by convention to the UNIX/C epoch
1114 // value: the midnight of January 1, 1970 (UTC)
1118 // ----------------------------------------------------------------------------
1119 // This class contains a difference between 2 wxDateTime values, so it makes
1120 // sense to add it to wxDateTime and it is the result of subtraction of 2
1121 // objects of that class. See also wxDateSpan.
1122 // ----------------------------------------------------------------------------
1124 class WXDLLIMPEXP_BASE wxTimeSpan
1128 // ------------------------------------------------------------------------
1130 // return the timespan for the given number of milliseconds
1131 static wxTimeSpan
Milliseconds(wxLongLong ms
) { return wxTimeSpan(0, 0, 0, ms
); }
1132 static wxTimeSpan
Millisecond() { return Milliseconds(1); }
1134 // return the timespan for the given number of seconds
1135 static wxTimeSpan
Seconds(wxLongLong sec
) { return wxTimeSpan(0, 0, sec
); }
1136 static wxTimeSpan
Second() { return Seconds(1); }
1138 // return the timespan for the given number of minutes
1139 static wxTimeSpan
Minutes(long min
) { return wxTimeSpan(0, min
, 0 ); }
1140 static wxTimeSpan
Minute() { return Minutes(1); }
1142 // return the timespan for the given number of hours
1143 static wxTimeSpan
Hours(long hours
) { return wxTimeSpan(hours
, 0, 0); }
1144 static wxTimeSpan
Hour() { return Hours(1); }
1146 // return the timespan for the given number of days
1147 static wxTimeSpan
Days(long days
) { return Hours(24 * days
); }
1148 static wxTimeSpan
Day() { return Days(1); }
1150 // return the timespan for the given number of weeks
1151 static wxTimeSpan
Weeks(long days
) { return Days(7 * days
); }
1152 static wxTimeSpan
Week() { return Weeks(1); }
1154 // default ctor constructs the 0 time span
1157 // from separate values for each component, date set to 0 (hours are
1158 // not restricted to 0..24 range, neither are minutes, seconds or
1160 inline wxTimeSpan(long hours
,
1162 wxLongLong seconds
= 0,
1163 wxLongLong milliseconds
= 0);
1165 // default copy ctor is ok
1169 // arithmetics with time spans (see also below for more operators)
1170 // ------------------------------------------------------------------------
1172 // return the sum of two timespans
1173 inline wxTimeSpan
Add(const wxTimeSpan
& diff
) const;
1174 // add two timespans together
1175 inline wxTimeSpan
& Add(const wxTimeSpan
& diff
);
1176 // add two timespans together
1177 wxTimeSpan
& operator+=(const wxTimeSpan
& diff
) { return Add(diff
); }
1178 inline wxTimeSpan
operator+(const wxTimeSpan
& ts
) const
1180 return wxTimeSpan(GetValue() + ts
.GetValue());
1183 // return the difference of two timespans
1184 inline wxTimeSpan
Subtract(const wxTimeSpan
& diff
) const;
1185 // subtract another timespan
1186 inline wxTimeSpan
& Subtract(const wxTimeSpan
& diff
);
1187 // subtract another timespan
1188 wxTimeSpan
& operator-=(const wxTimeSpan
& diff
) { return Subtract(diff
); }
1189 inline wxTimeSpan
operator-(const wxTimeSpan
& ts
)
1191 return wxTimeSpan(GetValue() - ts
.GetValue());
1194 // multiply timespan by a scalar
1195 inline wxTimeSpan
Multiply(int n
) const;
1196 // multiply timespan by a scalar
1197 inline wxTimeSpan
& Multiply(int n
);
1198 // multiply timespan by a scalar
1199 wxTimeSpan
& operator*=(int n
) { return Multiply(n
); }
1200 inline wxTimeSpan
operator*(int n
) const
1202 return wxTimeSpan(*this).Multiply(n
);
1205 // return this timespan with opposite sign
1206 wxTimeSpan
Negate() const { return wxTimeSpan(-GetValue()); }
1207 // negate the value of the timespan
1208 wxTimeSpan
& Neg() { m_diff
= -GetValue(); return *this; }
1209 // negate the value of the timespan
1210 wxTimeSpan
& operator-() { return Neg(); }
1212 // return the absolute value of the timespan: does _not_ modify the
1214 inline wxTimeSpan
Abs() const;
1216 // there is intentionally no division because we don't want to
1217 // introduce rounding errors in time calculations
1219 // comparaison (see also operator versions below)
1220 // ------------------------------------------------------------------------
1222 // is the timespan null?
1223 bool IsNull() const { return m_diff
== 0l; }
1224 // returns true if the timespan is null
1225 bool operator!() const { return !IsNull(); }
1227 // is the timespan positive?
1228 bool IsPositive() const { return m_diff
> 0l; }
1230 // is the timespan negative?
1231 bool IsNegative() const { return m_diff
< 0l; }
1233 // are two timespans equal?
1234 inline bool IsEqualTo(const wxTimeSpan
& ts
) const;
1235 // compare two timestamps: works with the absolute values, i.e. -2
1236 // hours is longer than 1 hour. Also, it will return false if the
1237 // timespans are equal in absolute value.
1238 inline bool IsLongerThan(const wxTimeSpan
& ts
) const;
1239 // compare two timestamps: works with the absolute values, i.e. 1
1240 // hour is shorter than -2 hours. Also, it will return false if the
1241 // timespans are equal in absolute value.
1242 bool IsShorterThan(const wxTimeSpan
& t
) const { return !IsLongerThan(t
); }
1244 inline bool operator<(const wxTimeSpan
&ts
) const
1246 return GetValue() < ts
.GetValue();
1249 inline bool operator<=(const wxTimeSpan
&ts
) const
1251 return GetValue() <= ts
.GetValue();
1254 inline bool operator>(const wxTimeSpan
&ts
) const
1256 return GetValue() > ts
.GetValue();
1259 inline bool operator>=(const wxTimeSpan
&ts
) const
1261 return GetValue() >= ts
.GetValue();
1264 inline bool operator==(const wxTimeSpan
&ts
) const
1266 return GetValue() == ts
.GetValue();
1269 inline bool operator!=(const wxTimeSpan
&ts
) const
1271 return GetValue() != ts
.GetValue();
1274 // breaking into days, hours, minutes and seconds
1275 // ------------------------------------------------------------------------
1277 // get the max number of weeks in this timespan
1278 inline int GetWeeks() const;
1279 // get the max number of days in this timespan
1280 inline int GetDays() const;
1281 // get the max number of hours in this timespan
1282 inline int GetHours() const;
1283 // get the max number of minutes in this timespan
1284 inline int GetMinutes() const;
1285 // get the max number of seconds in this timespan
1286 inline wxLongLong
GetSeconds() const;
1287 // get the number of milliseconds in this timespan
1288 wxLongLong
GetMilliseconds() const { return m_diff
; }
1290 // conversion to text
1291 // ------------------------------------------------------------------------
1293 // this function accepts strftime()-like format string (default
1294 // argument corresponds to the preferred date and time representation
1295 // for the current locale) and returns the string containing the
1296 // resulting text representation. Notice that only some of format
1297 // specifiers valid for wxDateTime are valid for wxTimeSpan: hours,
1298 // minutes and seconds make sense, but not "PM/AM" string for example.
1299 wxString
Format(const wxChar
*format
= wxDefaultTimeSpanFormat
) const;
1302 // ------------------------------------------------------------------------
1304 // construct from internal representation
1305 wxTimeSpan(const wxLongLong
& diff
) { m_diff
= diff
; }
1307 // get the internal representation
1308 wxLongLong
GetValue() const { return m_diff
; }
1311 // the (signed) time span in milliseconds
1315 // ----------------------------------------------------------------------------
1316 // This class is a "logical time span" and is useful for implementing program
1317 // logic for such things as "add one month to the date" which, in general,
1318 // doesn't mean to add 60*60*24*31 seconds to it, but to take the same date
1319 // the next month (to understand that this is indeed different consider adding
1320 // one month to Feb, 15 - we want to get Mar, 15, of course).
1322 // When adding a month to the date, all lesser components (days, hours, ...)
1323 // won't be changed unless the resulting date would be invalid: for example,
1324 // Jan 31 + 1 month will be Feb 28, not (non existing) Feb 31.
1326 // Because of this feature, adding and subtracting back again the same
1327 // wxDateSpan will *not*, in general give back the original date: Feb 28 - 1
1328 // month will be Jan 28, not Jan 31!
1330 // wxDateSpan can be either positive or negative. They may be
1331 // multiplied by scalars which multiply all deltas by the scalar: i.e. 2*(1
1332 // month and 1 day) is 2 months and 2 days. They can be added together and
1333 // with wxDateTime or wxTimeSpan, but the type of result is different for each
1336 // Beware about weeks: if you specify both weeks and days, the total number of
1337 // days added will be 7*weeks + days! See also GetTotalDays() function.
1339 // Equality operators are defined for wxDateSpans. Two datespans are equal if
1340 // they both give the same target date when added to *every* source date.
1341 // Thus wxDateSpan::Months(1) is not equal to wxDateSpan::Days(30), because
1342 // they not give the same date when added to 1 Feb. But wxDateSpan::Days(14) is
1343 // equal to wxDateSpan::Weeks(2)
1345 // Finally, notice that for adding hours, minutes &c you don't need this
1346 // class: wxTimeSpan will do the job because there are no subtleties
1347 // associated with those.
1348 // ----------------------------------------------------------------------------
1350 class WXDLLIMPEXP_BASE wxDateSpan
1354 // ------------------------------------------------------------------------
1356 // this many years/months/weeks/days
1357 wxDateSpan(int years
= 0, int months
= 0, int weeks
= 0, int days
= 0)
1365 // get an object for the given number of days
1366 static wxDateSpan
Days(int days
) { return wxDateSpan(0, 0, 0, days
); }
1367 static wxDateSpan
Day() { return Days(1); }
1369 // get an object for the given number of weeks
1370 static wxDateSpan
Weeks(int weeks
) { return wxDateSpan(0, 0, weeks
, 0); }
1371 static wxDateSpan
Week() { return Weeks(1); }
1373 // get an object for the given number of months
1374 static wxDateSpan
Months(int mon
) { return wxDateSpan(0, mon
, 0, 0); }
1375 static wxDateSpan
Month() { return Months(1); }
1377 // get an object for the given number of years
1378 static wxDateSpan
Years(int years
) { return wxDateSpan(years
, 0, 0, 0); }
1379 static wxDateSpan
Year() { return Years(1); }
1381 // default copy ctor is ok
1385 // accessors (all SetXXX() return the (modified) wxDateSpan object)
1386 // ------------------------------------------------------------------------
1388 // set number of years
1389 wxDateSpan
& SetYears(int n
) { m_years
= n
; return *this; }
1390 // set number of months
1391 wxDateSpan
& SetMonths(int n
) { m_months
= n
; return *this; }
1392 // set number of weeks
1393 wxDateSpan
& SetWeeks(int n
) { m_weeks
= n
; return *this; }
1394 // set number of days
1395 wxDateSpan
& SetDays(int n
) { m_days
= n
; return *this; }
1397 // get number of years
1398 int GetYears() const { return m_years
; }
1399 // get number of months
1400 int GetMonths() const { return m_months
; }
1401 // get number of weeks
1402 int GetWeeks() const { return m_weeks
; }
1403 // get number of days
1404 int GetDays() const { return m_days
; }
1405 // returns 7*GetWeeks() + GetDays()
1406 int GetTotalDays() const { return 7*m_weeks
+ m_days
; }
1408 // arithmetics with date spans (see also below for more operators)
1409 // ------------------------------------------------------------------------
1411 // return sum of two date spans
1412 inline wxDateSpan
Add(const wxDateSpan
& other
) const;
1413 // add another wxDateSpan to us
1414 inline wxDateSpan
& Add(const wxDateSpan
& other
);
1415 // add another wxDateSpan to us
1416 inline wxDateSpan
& operator+=(const wxDateSpan
& other
);
1417 inline wxDateSpan
operator+(const wxDateSpan
& ds
) const
1419 return wxDateSpan(GetYears() + ds
.GetYears(),
1420 GetMonths() + ds
.GetMonths(),
1421 GetWeeks() + ds
.GetWeeks(),
1422 GetDays() + ds
.GetDays());
1425 // return difference of two date spans
1426 inline wxDateSpan
Subtract(const wxDateSpan
& other
) const;
1427 // subtract another wxDateSpan from us
1428 inline wxDateSpan
& Subtract(const wxDateSpan
& other
);
1429 // subtract another wxDateSpan from us
1430 inline wxDateSpan
& operator-=(const wxDateSpan
& other
);
1431 inline wxDateSpan
operator-(const wxDateSpan
& ds
) const
1433 return wxDateSpan(GetYears() - ds
.GetYears(),
1434 GetMonths() - ds
.GetMonths(),
1435 GetWeeks() - ds
.GetWeeks(),
1436 GetDays() - ds
.GetDays());
1439 // return a copy of this time span with changed sign
1440 inline wxDateSpan
Negate() const;
1441 // inverse the sign of this timespan
1442 inline wxDateSpan
& Neg();
1443 // inverse the sign of this timespan
1444 wxDateSpan
& operator-() { return Neg(); }
1446 // return the date span proportional to this one with given factor
1447 inline wxDateSpan
Multiply(int factor
) const;
1448 // multiply all components by a (signed) number
1449 inline wxDateSpan
& Multiply(int factor
);
1450 // multiply all components by a (signed) number
1451 inline wxDateSpan
& operator*=(int factor
) { return Multiply(factor
); }
1452 inline wxDateSpan
operator*(int n
) const
1454 return wxDateSpan(*this).Multiply(n
);
1457 // ds1 == d2 if and only if for every wxDateTime t t + ds1 == t + ds2
1458 inline bool operator==(const wxDateSpan
& ds
) const
1460 return GetYears() == ds
.GetYears() &&
1461 GetMonths() == ds
.GetMonths() &&
1462 GetTotalDays() == ds
.GetTotalDays();
1465 inline bool operator!=(const wxDateSpan
& ds
) const
1467 return !(*this == ds
);
1477 // ----------------------------------------------------------------------------
1478 // wxDateTimeArray: array of dates.
1479 // ----------------------------------------------------------------------------
1481 WX_DECLARE_USER_EXPORTED_OBJARRAY(wxDateTime
, wxDateTimeArray
, WXDLLIMPEXP_BASE
);
1483 // ----------------------------------------------------------------------------
1484 // wxDateTimeHolidayAuthority: an object of this class will decide whether a
1485 // given date is a holiday and is used by all functions working with "work
1488 // NB: the base class is an ABC, derived classes must implement the pure
1489 // virtual methods to work with the holidays they correspond to.
1490 // ----------------------------------------------------------------------------
1492 class WXDLLIMPEXP_BASE wxDateTimeHolidayAuthority
;
1493 WX_DEFINE_USER_EXPORTED_ARRAY_PTR(wxDateTimeHolidayAuthority
*,
1494 wxHolidayAuthoritiesArray
,
1495 class WXDLLIMPEXP_BASE
);
1497 class wxDateTimeHolidaysModule
;
1498 class WXDLLIMPEXP_BASE wxDateTimeHolidayAuthority
1500 friend class wxDateTimeHolidaysModule
;
1502 // returns true if the given date is a holiday
1503 static bool IsHoliday(const wxDateTime
& dt
);
1505 // fills the provided array with all holidays in the given range, returns
1506 // the number of them
1507 static size_t GetHolidaysInRange(const wxDateTime
& dtStart
,
1508 const wxDateTime
& dtEnd
,
1509 wxDateTimeArray
& holidays
);
1511 // clear the list of holiday authorities
1512 static void ClearAllAuthorities();
1514 // add a new holiday authority (the pointer will be deleted by
1515 // wxDateTimeHolidayAuthority)
1516 static void AddAuthority(wxDateTimeHolidayAuthority
*auth
);
1518 // the base class must have a virtual dtor
1519 virtual ~wxDateTimeHolidayAuthority();
1522 // this function is called to determine whether a given day is a holiday
1523 virtual bool DoIsHoliday(const wxDateTime
& dt
) const = 0;
1525 // this function should fill the array with all holidays between the two
1526 // given dates - it is implemented in the base class, but in a very
1527 // inefficient way (it just iterates over all days and uses IsHoliday() for
1528 // each of them), so it must be overridden in the derived class where the
1529 // base class version may be explicitly used if needed
1531 // returns the number of holidays in the given range and fills holidays
1533 virtual size_t DoGetHolidaysInRange(const wxDateTime
& dtStart
,
1534 const wxDateTime
& dtEnd
,
1535 wxDateTimeArray
& holidays
) const = 0;
1538 // all holiday authorities
1539 static wxHolidayAuthoritiesArray ms_authorities
;
1542 // the holidays for this class are all Saturdays and Sundays
1543 class WXDLLIMPEXP_BASE wxDateTimeWorkDays
: public wxDateTimeHolidayAuthority
1546 virtual bool DoIsHoliday(const wxDateTime
& dt
) const;
1547 virtual size_t DoGetHolidaysInRange(const wxDateTime
& dtStart
,
1548 const wxDateTime
& dtEnd
,
1549 wxDateTimeArray
& holidays
) const;
1552 // ============================================================================
1553 // inline functions implementation
1554 // ============================================================================
1556 // ----------------------------------------------------------------------------
1558 // ----------------------------------------------------------------------------
1560 #define MILLISECONDS_PER_DAY 86400000l
1562 // some broken compilers (HP-UX CC) refuse to compile the "normal" version, but
1563 // using a temp variable always might prevent other compilers from optimising
1564 // it away - hence use of this ugly macro
1566 #define MODIFY_AND_RETURN(op) return wxDateTime(*this).op
1568 #define MODIFY_AND_RETURN(op) wxDateTime dt(*this); dt.op; return dt
1571 // ----------------------------------------------------------------------------
1572 // wxDateTime construction
1573 // ----------------------------------------------------------------------------
1575 inline bool wxDateTime::IsInStdRange() const
1577 return m_time
>= 0l && (m_time
/ TIME_T_FACTOR
) < LONG_MAX
;
1581 inline wxDateTime
wxDateTime::Now()
1584 return wxDateTime(*GetTmNow(&tmstruct
));
1588 inline wxDateTime
wxDateTime::Today()
1590 wxDateTime
dt(Now());
1596 #if (!(defined(__VISAGECPP__) && __IBMCPP__ >= 400))
1597 inline wxDateTime
& wxDateTime::Set(time_t timet
)
1599 // assign first to avoid long multiplication overflow!
1600 m_time
= timet
- WX_TIME_BASE_OFFSET
;
1601 m_time
*= TIME_T_FACTOR
;
1607 inline wxDateTime
& wxDateTime::SetToCurrent()
1613 #if (!(defined(__VISAGECPP__) && __IBMCPP__ >= 400))
1614 inline wxDateTime::wxDateTime(time_t timet
)
1620 inline wxDateTime::wxDateTime(const struct tm
& tm
)
1625 inline wxDateTime::wxDateTime(const Tm
& tm
)
1630 inline wxDateTime::wxDateTime(double jdn
)
1635 inline wxDateTime
& wxDateTime::Set(const Tm
& tm
)
1637 wxASSERT_MSG( tm
.IsValid(), _T("invalid broken down date/time") );
1639 return Set(tm
.mday
, (Month
)tm
.mon
, tm
.year
,
1640 tm
.hour
, tm
.min
, tm
.sec
, tm
.msec
);
1643 inline wxDateTime::wxDateTime(wxDateTime_t hour
,
1644 wxDateTime_t minute
,
1645 wxDateTime_t second
,
1646 wxDateTime_t millisec
)
1648 Set(hour
, minute
, second
, millisec
);
1651 inline wxDateTime::wxDateTime(wxDateTime_t day
,
1655 wxDateTime_t minute
,
1656 wxDateTime_t second
,
1657 wxDateTime_t millisec
)
1659 Set(day
, month
, year
, hour
, minute
, second
, millisec
);
1662 // ----------------------------------------------------------------------------
1663 // wxDateTime accessors
1664 // ----------------------------------------------------------------------------
1666 inline wxLongLong
wxDateTime::GetValue() const
1668 wxASSERT_MSG( IsValid(), _T("invalid wxDateTime"));
1673 inline time_t wxDateTime::GetTicks() const
1675 wxASSERT_MSG( IsValid(), _T("invalid wxDateTime"));
1676 if ( !IsInStdRange() )
1681 return (time_t)((m_time
/ (long)TIME_T_FACTOR
).GetLo())+WX_TIME_BASE_OFFSET
;
1684 inline bool wxDateTime::SetToLastWeekDay(WeekDay weekday
,
1688 return SetToWeekDay(weekday
, -1, month
, year
);
1692 wxDateTime::GetWeekDayInSameWeek(WeekDay weekday
,
1693 WeekFlags
WXUNUSED(flags
)) const
1695 MODIFY_AND_RETURN( SetToWeekDayInSameWeek(weekday
) );
1698 inline wxDateTime
wxDateTime::GetNextWeekDay(WeekDay weekday
) const
1700 MODIFY_AND_RETURN( SetToNextWeekDay(weekday
) );
1703 inline wxDateTime
wxDateTime::GetPrevWeekDay(WeekDay weekday
) const
1705 MODIFY_AND_RETURN( SetToPrevWeekDay(weekday
) );
1708 inline wxDateTime
wxDateTime::GetWeekDay(WeekDay weekday
,
1713 wxDateTime
dt(*this);
1715 return dt
.SetToWeekDay(weekday
, n
, month
, year
) ? dt
: wxInvalidDateTime
;
1718 inline wxDateTime
wxDateTime::GetLastWeekDay(WeekDay weekday
,
1722 wxDateTime
dt(*this);
1724 return dt
.SetToLastWeekDay(weekday
, month
, year
) ? dt
: wxInvalidDateTime
;
1727 inline wxDateTime
wxDateTime::GetLastMonthDay(Month month
, int year
) const
1729 MODIFY_AND_RETURN( SetToLastMonthDay(month
, year
) );
1732 inline wxDateTime
wxDateTime::GetYearDay(wxDateTime_t yday
) const
1734 MODIFY_AND_RETURN( SetToYearDay(yday
) );
1737 // ----------------------------------------------------------------------------
1738 // wxDateTime comparison
1739 // ----------------------------------------------------------------------------
1741 inline bool wxDateTime::IsEqualTo(const wxDateTime
& datetime
) const
1743 wxASSERT_MSG( IsValid() && datetime
.IsValid(), _T("invalid wxDateTime"));
1745 return m_time
== datetime
.m_time
;
1748 inline bool wxDateTime::IsEarlierThan(const wxDateTime
& datetime
) const
1750 wxASSERT_MSG( IsValid() && datetime
.IsValid(), _T("invalid wxDateTime"));
1752 return m_time
< datetime
.m_time
;
1755 inline bool wxDateTime::IsLaterThan(const wxDateTime
& datetime
) const
1757 wxASSERT_MSG( IsValid() && datetime
.IsValid(), _T("invalid wxDateTime"));
1759 return m_time
> datetime
.m_time
;
1762 inline bool wxDateTime::IsStrictlyBetween(const wxDateTime
& t1
,
1763 const wxDateTime
& t2
) const
1765 // no need for assert, will be checked by the functions we call
1766 return IsLaterThan(t1
) && IsEarlierThan(t2
);
1769 inline bool wxDateTime::IsBetween(const wxDateTime
& t1
,
1770 const wxDateTime
& t2
) const
1772 // no need for assert, will be checked by the functions we call
1773 return IsEqualTo(t1
) || IsEqualTo(t2
) || IsStrictlyBetween(t1
, t2
);
1776 inline bool wxDateTime::IsSameDate(const wxDateTime
& dt
) const
1781 return tm1
.year
== tm2
.year
&&
1782 tm1
.mon
== tm2
.mon
&&
1783 tm1
.mday
== tm2
.mday
;
1786 inline bool wxDateTime::IsSameTime(const wxDateTime
& dt
) const
1788 // notice that we can't do something like this:
1790 // m_time % MILLISECONDS_PER_DAY == dt.m_time % MILLISECONDS_PER_DAY
1792 // because we have also to deal with (possibly) different DST settings!
1796 return tm1
.hour
== tm2
.hour
&&
1797 tm1
.min
== tm2
.min
&&
1798 tm1
.sec
== tm2
.sec
&&
1799 tm1
.msec
== tm2
.msec
;
1802 inline bool wxDateTime::IsEqualUpTo(const wxDateTime
& dt
,
1803 const wxTimeSpan
& ts
) const
1805 return IsBetween(dt
.Subtract(ts
), dt
.Add(ts
));
1808 // ----------------------------------------------------------------------------
1809 // wxDateTime arithmetics
1810 // ----------------------------------------------------------------------------
1812 inline wxDateTime
wxDateTime::Add(const wxTimeSpan
& diff
) const
1814 wxASSERT_MSG( IsValid(), _T("invalid wxDateTime"));
1816 return wxDateTime(m_time
+ diff
.GetValue());
1819 inline wxDateTime
& wxDateTime::Add(const wxTimeSpan
& diff
)
1821 wxASSERT_MSG( IsValid(), _T("invalid wxDateTime"));
1823 m_time
+= diff
.GetValue();
1828 inline wxDateTime
& wxDateTime::operator+=(const wxTimeSpan
& diff
)
1833 inline wxDateTime
wxDateTime::Subtract(const wxTimeSpan
& diff
) const
1835 wxASSERT_MSG( IsValid(), _T("invalid wxDateTime"));
1837 return wxDateTime(m_time
- diff
.GetValue());
1840 inline wxDateTime
& wxDateTime::Subtract(const wxTimeSpan
& diff
)
1842 wxASSERT_MSG( IsValid(), _T("invalid wxDateTime"));
1844 m_time
-= diff
.GetValue();
1849 inline wxDateTime
& wxDateTime::operator-=(const wxTimeSpan
& diff
)
1851 return Subtract(diff
);
1854 inline wxTimeSpan
wxDateTime::Subtract(const wxDateTime
& datetime
) const
1856 wxASSERT_MSG( IsValid() && datetime
.IsValid(), _T("invalid wxDateTime"));
1858 return wxTimeSpan(GetValue() - datetime
.GetValue());
1861 inline wxTimeSpan
wxDateTime::operator-(const wxDateTime
& dt2
) const
1863 return this->Subtract(dt2
);
1866 inline wxDateTime
wxDateTime::Add(const wxDateSpan
& diff
) const
1868 return wxDateTime(*this).Add(diff
);
1871 inline wxDateTime
& wxDateTime::Subtract(const wxDateSpan
& diff
)
1873 return Add(diff
.Negate());
1876 inline wxDateTime
wxDateTime::Subtract(const wxDateSpan
& diff
) const
1878 return wxDateTime(*this).Subtract(diff
);
1881 inline wxDateTime
& wxDateTime::operator-=(const wxDateSpan
& diff
)
1883 return Subtract(diff
);
1886 inline wxDateTime
& wxDateTime::operator+=(const wxDateSpan
& diff
)
1891 // ----------------------------------------------------------------------------
1892 // wxDateTime and timezones
1893 // ----------------------------------------------------------------------------
1896 wxDateTime::ToTimezone(const wxDateTime::TimeZone
& tz
, bool noDST
) const
1898 MODIFY_AND_RETURN( MakeTimezone(tz
, noDST
) );
1902 wxDateTime::FromTimezone(const wxDateTime::TimeZone
& tz
, bool noDST
) const
1904 MODIFY_AND_RETURN( MakeFromTimezone(tz
, noDST
) );
1907 // ----------------------------------------------------------------------------
1908 // wxTimeSpan construction
1909 // ----------------------------------------------------------------------------
1911 inline wxTimeSpan::wxTimeSpan(long hours
,
1914 wxLongLong milliseconds
)
1916 // assign first to avoid precision loss
1923 m_diff
+= milliseconds
;
1926 // ----------------------------------------------------------------------------
1927 // wxTimeSpan accessors
1928 // ----------------------------------------------------------------------------
1930 inline wxLongLong
wxTimeSpan::GetSeconds() const
1932 return m_diff
/ 1000l;
1935 inline int wxTimeSpan::GetMinutes() const
1937 // explicit cast to int suppresses a warning with CodeWarrior and possibly
1938 // others (changing the return type to long from int is impossible in 2.8)
1939 return (int)((GetSeconds() / 60l).GetLo());
1942 inline int wxTimeSpan::GetHours() const
1944 return GetMinutes() / 60;
1947 inline int wxTimeSpan::GetDays() const
1949 return GetHours() / 24;
1952 inline int wxTimeSpan::GetWeeks() const
1954 return GetDays() / 7;
1957 // ----------------------------------------------------------------------------
1958 // wxTimeSpan arithmetics
1959 // ----------------------------------------------------------------------------
1961 inline wxTimeSpan
wxTimeSpan::Add(const wxTimeSpan
& diff
) const
1963 return wxTimeSpan(m_diff
+ diff
.GetValue());
1966 inline wxTimeSpan
& wxTimeSpan::Add(const wxTimeSpan
& diff
)
1968 m_diff
+= diff
.GetValue();
1973 inline wxTimeSpan
wxTimeSpan::Subtract(const wxTimeSpan
& diff
) const
1975 return wxTimeSpan(m_diff
- diff
.GetValue());
1978 inline wxTimeSpan
& wxTimeSpan::Subtract(const wxTimeSpan
& diff
)
1980 m_diff
-= diff
.GetValue();
1985 inline wxTimeSpan
& wxTimeSpan::Multiply(int n
)
1992 inline wxTimeSpan
wxTimeSpan::Multiply(int n
) const
1994 return wxTimeSpan(m_diff
* (long)n
);
1997 inline wxTimeSpan
wxTimeSpan::Abs() const
1999 return wxTimeSpan(GetValue().Abs());
2002 inline bool wxTimeSpan::IsEqualTo(const wxTimeSpan
& ts
) const
2004 return GetValue() == ts
.GetValue();
2007 inline bool wxTimeSpan::IsLongerThan(const wxTimeSpan
& ts
) const
2009 return GetValue().Abs() > ts
.GetValue().Abs();
2012 // ----------------------------------------------------------------------------
2014 // ----------------------------------------------------------------------------
2016 inline wxDateSpan
& wxDateSpan::operator+=(const wxDateSpan
& other
)
2018 m_years
+= other
.m_years
;
2019 m_months
+= other
.m_months
;
2020 m_weeks
+= other
.m_weeks
;
2021 m_days
+= other
.m_days
;
2026 inline wxDateSpan
& wxDateSpan::Add(const wxDateSpan
& other
)
2028 return *this += other
;
2031 inline wxDateSpan
wxDateSpan::Add(const wxDateSpan
& other
) const
2033 wxDateSpan
ds(*this);
2038 inline wxDateSpan
& wxDateSpan::Multiply(int factor
)
2048 inline wxDateSpan
wxDateSpan::Multiply(int factor
) const
2050 wxDateSpan
ds(*this);
2051 ds
.Multiply(factor
);
2055 inline wxDateSpan
wxDateSpan::Negate() const
2057 return wxDateSpan(-m_years
, -m_months
, -m_weeks
, -m_days
);
2060 inline wxDateSpan
& wxDateSpan::Neg()
2063 m_months
= -m_months
;
2070 inline wxDateSpan
& wxDateSpan::operator-=(const wxDateSpan
& other
)
2072 return *this += other
.Negate();
2075 inline wxDateSpan
& wxDateSpan::Subtract(const wxDateSpan
& other
)
2077 return *this -= other
;
2080 inline wxDateSpan
wxDateSpan::Subtract(const wxDateSpan
& other
) const
2082 wxDateSpan
ds(*this);
2087 #undef MILLISECONDS_PER_DAY
2089 #undef MODIFY_AND_RETURN
2091 // ============================================================================
2093 // ============================================================================
2095 // ----------------------------------------------------------------------------
2096 // wxTimeSpan operators
2097 // ----------------------------------------------------------------------------
2099 wxTimeSpan WXDLLIMPEXP_BASE
operator*(int n
, const wxTimeSpan
& ts
);
2101 // ----------------------------------------------------------------------------
2103 // ----------------------------------------------------------------------------
2105 wxDateSpan WXDLLIMPEXP_BASE
operator*(int n
, const wxDateSpan
& ds
);
2107 // ============================================================================
2108 // other helper functions
2109 // ============================================================================
2111 // ----------------------------------------------------------------------------
2112 // iteration helpers: can be used to write a for loop over enum variable like
2114 // for ( m = wxDateTime::Jan; m < wxDateTime::Inv_Month; wxNextMonth(m) )
2115 // ----------------------------------------------------------------------------
2117 WXDLLIMPEXP_BASE
void wxNextMonth(wxDateTime::Month
& m
);
2118 WXDLLIMPEXP_BASE
void wxPrevMonth(wxDateTime::Month
& m
);
2119 WXDLLIMPEXP_BASE
void wxNextWDay(wxDateTime::WeekDay
& wd
);
2120 WXDLLIMPEXP_BASE
void wxPrevWDay(wxDateTime::WeekDay
& wd
);
2122 #endif // wxUSE_DATETIME
2124 #endif // _WX_DATETIME_H