1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: declarations of time/date related classes (wxDateTime,
5 // Author: Vadim Zeitlin
8 // Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_DATETIME_H
13 #define _WX_DATETIME_H
20 #include "wx/msw/wince/time.h"
25 #include <limits.h> // for INT_MIN
27 #include "wx/longlong.h"
28 #include "wx/anystr.h"
30 class WXDLLIMPEXP_FWD_BASE wxDateTime
;
31 class WXDLLIMPEXP_FWD_BASE wxTimeSpan
;
32 class WXDLLIMPEXP_FWD_BASE wxDateSpan
;
37 #include "wx/dynarray.h"
39 // not all c-runtimes are based on 1/1/1970 being (time_t) 0
40 // set this to the corresponding value in seconds 1/1/1970 has on your
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
56 The three (main) classes declared in this header represent:
58 1. An absolute moment in the time (wxDateTime)
59 2. A difference between two moments in the time, positive or negative
61 3. A logical difference between two dates expressed in
62 years/months/weeks/days (wxDateSpan)
64 The following arithmetic operations are permitted (all others are not):
69 wxDateTime + wxTimeSpan = wxDateTime
70 wxDateTime + wxDateSpan = wxDateTime
71 wxTimeSpan + wxTimeSpan = wxTimeSpan
72 wxDateSpan + wxDateSpan = wxDateSpan
76 wxDateTime - wxDateTime = wxTimeSpan
77 wxDateTime - wxTimeSpan = wxDateTime
78 wxDateTime - wxDateSpan = wxDateTime
79 wxTimeSpan - wxTimeSpan = wxTimeSpan
80 wxDateSpan - wxDateSpan = wxDateSpan
84 wxTimeSpan * number = wxTimeSpan
85 number * wxTimeSpan = wxTimeSpan
86 wxDateSpan * number = wxDateSpan
87 number * wxDateSpan = wxDateSpan
91 -wxTimeSpan = wxTimeSpan
92 -wxDateSpan = wxDateSpan
94 For each binary operation OP (+, -, *) we have the following operatorOP=() as
95 a method and the method with a symbolic name OPER (Add, Subtract, Multiply)
96 as a synonym for it and another const method with the same name which returns
97 the changed copy of the object and operatorOP() as a global function which is
98 implemented in terms of the const version of OPEN. For the unary - we have
99 operator-() as a method, Neg() as synonym for it and Negate() which returns
100 the copy of the object with the changed sign.
103 // an invalid/default date time object which may be used as the default
104 // argument for arguments of type wxDateTime; it is also returned by all
105 // functions returning wxDateTime on failure (this is why it is also called
106 // wxInvalidDateTime)
107 class WXDLLIMPEXP_FWD_BASE wxDateTime
;
109 extern WXDLLIMPEXP_DATA_BASE(const char) wxDefaultDateTimeFormat
[];
110 extern WXDLLIMPEXP_DATA_BASE(const char) wxDefaultTimeSpanFormat
[];
111 extern WXDLLIMPEXP_DATA_BASE(const wxDateTime
) wxDefaultDateTime
;
113 #define wxInvalidDateTime wxDefaultDateTime
116 // ----------------------------------------------------------------------------
117 // conditional compilation
118 // ----------------------------------------------------------------------------
120 // if configure detected strftime(), we have it too
122 #define wxHAS_STRFTIME
123 // suppose everyone else has strftime except Win CE unless VC8 is used
124 #elif !defined(__WXWINCE__) || defined(__VISUALC8__)
125 #define wxHAS_STRFTIME
128 // ----------------------------------------------------------------------------
129 // wxDateTime represents an absolute moment in the time
130 // ----------------------------------------------------------------------------
132 class WXDLLIMPEXP_BASE wxDateTime
136 // ------------------------------------------------------------------------
138 // a small unsigned integer type for storing things like minutes,
139 // seconds &c. It should be at least short (i.e. not char) to contain
140 // the number of milliseconds - it may also be 'int' because there is
141 // no size penalty associated with it in our code, we don't store any
142 // data in this format
143 typedef unsigned short wxDateTime_t
;
146 // ------------------------------------------------------------------------
151 // the time in the current time zone
154 // zones from GMT (= Greenwich Mean Time): they're guaranteed to be
155 // consequent numbers, so writing something like `GMT0 + offset' is
156 // safe if abs(offset) <= 12
158 // underscore stands for minus
159 GMT_12
, GMT_11
, GMT_10
, GMT_9
, GMT_8
, GMT_7
,
160 GMT_6
, GMT_5
, GMT_4
, GMT_3
, GMT_2
, GMT_1
,
162 GMT1
, GMT2
, GMT3
, GMT4
, GMT5
, GMT6
,
163 GMT7
, GMT8
, GMT9
, GMT10
, GMT11
, GMT12
, GMT13
,
164 // Note that GMT12 and GMT_12 are not the same: there is a difference
165 // of exactly one day between them
167 // some symbolic names for TZ
170 WET
= GMT0
, // Western Europe Time
171 WEST
= GMT1
, // Western Europe Summer Time
172 CET
= GMT1
, // Central Europe Time
173 CEST
= GMT2
, // Central Europe Summer Time
174 EET
= GMT2
, // Eastern Europe Time
175 EEST
= GMT3
, // Eastern Europe Summer Time
176 MSK
= GMT3
, // Moscow Time
177 MSD
= GMT4
, // Moscow Summer Time
180 AST
= GMT_4
, // Atlantic Standard Time
181 ADT
= GMT_3
, // Atlantic Daylight Time
182 EST
= GMT_5
, // Eastern Standard Time
183 EDT
= GMT_4
, // Eastern Daylight Saving Time
184 CST
= GMT_6
, // Central Standard Time
185 CDT
= GMT_5
, // Central Daylight Saving Time
186 MST
= GMT_7
, // Mountain Standard Time
187 MDT
= GMT_6
, // Mountain Daylight Saving Time
188 PST
= GMT_8
, // Pacific Standard Time
189 PDT
= GMT_7
, // Pacific Daylight Saving Time
190 HST
= GMT_10
, // Hawaiian Standard Time
191 AKST
= GMT_9
, // Alaska Standard Time
192 AKDT
= GMT_8
, // Alaska Daylight Saving Time
196 A_WST
= GMT8
, // Western Standard Time
197 A_CST
= GMT13
+ 1, // Central Standard Time (+9.5)
198 A_EST
= GMT10
, // Eastern Standard Time
199 A_ESST
= GMT11
, // Eastern Summer Time
202 NZST
= GMT12
, // Standard Time
203 NZDT
= GMT13
, // Daylight Saving Time
205 // TODO add more symbolic timezone names here
207 // Universal Coordinated Time = the new and politically correct name
212 // the calendar systems we know about: notice that it's valid (for
213 // this classes purpose anyhow) to work with any of these calendars
214 // even with the dates before the historical appearance of the
218 Gregorian
, // current calendar
219 Julian
// calendar in use since -45 until the 1582 (or later)
221 // TODO Hebrew, Chinese, Maya, ... (just kidding) (or then may be not?)
224 // the country parameter is used so far for calculating the start and
225 // the end of DST period and for deciding whether the date is a work
228 // TODO move this to intl.h
230 // Required for WinCE
237 Country_Unknown
, // no special information for this country
238 Country_Default
, // set the default country with SetCountry() method
239 // or use the default country with any other
241 // TODO add more countries (for this we must know about DST and/or
242 // holidays for this country)
244 // Western European countries: we assume that they all follow the same
245 // DST rules (true or false?)
246 Country_WesternEurope_Start
,
247 Country_EEC
= Country_WesternEurope_Start
,
251 Country_WesternEurope_End
= UK
,
256 // symbolic names for the months
259 Jan
, Feb
, Mar
, Apr
, May
, Jun
, Jul
, Aug
, Sep
, Oct
, Nov
, Dec
, Inv_Month
262 // symbolic names for the weekdays
265 Sun
, Mon
, Tue
, Wed
, Thu
, Fri
, Sat
, Inv_WeekDay
268 // invalid value for the year
271 Inv_Year
= SHRT_MIN
// should hold in wxDateTime_t
274 // flags for GetWeekDayName and GetMonthName
277 Name_Full
= 0x01, // return full name
278 Name_Abbr
= 0x02 // return abbreviated name
281 // flags for GetWeekOfYear and GetWeekOfMonth
284 Default_First
, // Sunday_First for US, Monday_First for the rest
285 Monday_First
, // week starts with a Monday
286 Sunday_First
// week starts with a Sunday
290 // ------------------------------------------------------------------------
292 // a class representing a time zone: basically, this is just an offset
293 // (in seconds) from GMT
294 class WXDLLIMPEXP_BASE TimeZone
299 // create time zone object with the given offset
300 TimeZone(long offset
= 0) { m_offset
= offset
; }
302 static TimeZone
Make(long offset
)
305 tz
.m_offset
= offset
;
309 long GetOffset() const { return m_offset
; }
312 // offset for this timezone from GMT in seconds
316 // standard struct tm is limited to the years from 1900 (because
317 // tm_year field is the offset from 1900), so we use our own struct
318 // instead to represent broken down time
320 // NB: this struct should always be kept normalized (i.e. mon should
321 // be < 12, 1 <= day <= 31 &c), so use AddMonths(), AddDays()
322 // instead of modifying the member fields directly!
323 struct WXDLLIMPEXP_BASE Tm
325 wxDateTime_t msec
, sec
, min
, hour
,
326 mday
, // Day of the month in 1..31 range.
327 yday
; // Day of the year in 0..365 range.
331 // default ctor inits the object to an invalid value
334 // ctor from struct tm and the timezone
335 Tm(const struct tm
& tm
, const TimeZone
& tz
);
337 // check that the given date/time is valid (in Gregorian calendar)
338 bool IsValid() const;
341 WeekDay
GetWeekDay() // not const because wday may be changed
343 if ( wday
== Inv_WeekDay
)
346 return (WeekDay
)wday
;
349 // add the given number of months to the date keeping it normalized
350 void AddMonths(int monDiff
);
352 // add the given number of months to the date keeping it normalized
353 void AddDays(int dayDiff
);
356 // compute the weekday from other fields
357 void ComputeWeekDay();
359 // the timezone we correspond to
362 // This value can only be accessed via GetWeekDay() and not directly
363 // because it's not always computed when creating this object and may
364 // need to be calculated on demand.
369 // ------------------------------------------------------------------------
371 // set the current country
372 static void SetCountry(Country country
);
373 // get the current country
374 static Country
GetCountry();
376 // return true if the country is a West European one (in practice,
377 // this means that the same DST rules as for EEC apply)
378 static bool IsWestEuropeanCountry(Country country
= Country_Default
);
380 // return the current year
381 static int GetCurrentYear(Calendar cal
= Gregorian
);
383 // convert the year as returned by wxDateTime::GetYear() to a year
384 // suitable for BC/AD notation. The difference is that BC year 1
385 // corresponds to the year 0 (while BC year 0 didn't exist) and AD
386 // year N is just year N.
387 static int ConvertYearToBC(int year
);
389 // return the current month
390 static Month
GetCurrentMonth(Calendar cal
= Gregorian
);
392 // returns true if the given year is a leap year in the given calendar
393 static bool IsLeapYear(int year
= Inv_Year
, Calendar cal
= Gregorian
);
395 // get the century (19 for 1999, 20 for 2000 and -5 for 492 BC)
396 static int GetCentury(int year
);
398 // returns the number of days in this year (356 or 355 for Gregorian
399 // calendar usually :-)
400 static wxDateTime_t
GetNumberOfDays(int year
, Calendar cal
= Gregorian
);
402 // get the number of the days in the given month (default value for
403 // the year means the current one)
404 static wxDateTime_t
GetNumberOfDays(Month month
,
406 Calendar cal
= Gregorian
);
409 // get the full (default) or abbreviated month name in the current
410 // locale, returns empty string on error
411 static wxString
GetMonthName(Month month
,
412 NameFlags flags
= Name_Full
);
414 // get the standard English full (default) or abbreviated month name
415 static wxString
GetEnglishMonthName(Month month
,
416 NameFlags flags
= Name_Full
);
418 // get the full (default) or abbreviated weekday name in the current
419 // locale, returns empty string on error
420 static wxString
GetWeekDayName(WeekDay weekday
,
421 NameFlags flags
= Name_Full
);
423 // get the standard English full (default) or abbreviated weekday name
424 static wxString
GetEnglishWeekDayName(WeekDay weekday
,
425 NameFlags flags
= Name_Full
);
427 // get the AM and PM strings in the current locale (may be empty)
428 static void GetAmPmStrings(wxString
*am
, wxString
*pm
);
430 // return true if the given country uses DST for this year
431 static bool IsDSTApplicable(int year
= Inv_Year
,
432 Country country
= Country_Default
);
434 // get the beginning of DST for this year, will return invalid object
435 // if no DST applicable in this year. The default value of the
436 // parameter means to take the current year.
437 static wxDateTime
GetBeginDST(int year
= Inv_Year
,
438 Country country
= Country_Default
);
439 // get the end of DST for this year, will return invalid object
440 // if no DST applicable in this year. The default value of the
441 // parameter means to take the current year.
442 static wxDateTime
GetEndDST(int year
= Inv_Year
,
443 Country country
= Country_Default
);
445 // return the wxDateTime object for the current time
446 static inline wxDateTime
Now();
448 // return the wxDateTime object for the current time with millisecond
449 // precision (if available on this platform)
450 static wxDateTime
UNow();
452 // return the wxDateTime object for today midnight: i.e. as Now() but
453 // with time set to 0
454 static inline wxDateTime
Today();
456 // constructors: you should test whether the constructor succeeded with
457 // IsValid() function. The values Inv_Month and Inv_Year for the
458 // parameters mean take current month and/or year values.
459 // ------------------------------------------------------------------------
461 // default ctor does not initialize the object, use Set()!
462 wxDateTime() { m_time
= wxLongLong(wxINT32_MIN
, 0); }
464 // from time_t: seconds since the Epoch 00:00:00 UTC, Jan 1, 1970)
465 #if (!(defined(__VISAGECPP__) && __IBMCPP__ >= 400))
466 // VA C++ confuses this with wxDateTime(double jdn) thinking it is a duplicate declaration
467 inline wxDateTime(time_t timet
);
469 // from broken down time/date (only for standard Unix range)
470 inline wxDateTime(const struct tm
& tm
);
471 // from broken down time/date (any range)
472 inline wxDateTime(const Tm
& tm
);
474 // from JDN (beware of rounding errors)
475 inline wxDateTime(double jdn
);
477 // from separate values for each component, date set to today
478 inline wxDateTime(wxDateTime_t hour
,
479 wxDateTime_t minute
= 0,
480 wxDateTime_t second
= 0,
481 wxDateTime_t millisec
= 0);
482 // from separate values for each component with explicit date
483 inline wxDateTime(wxDateTime_t day
, // day of the month
485 int year
= Inv_Year
, // 1999, not 99 please!
486 wxDateTime_t hour
= 0,
487 wxDateTime_t minute
= 0,
488 wxDateTime_t second
= 0,
489 wxDateTime_t millisec
= 0);
491 wxDateTime(const struct _SYSTEMTIME
& st
)
493 SetFromMSWSysTime(st
);
497 // default copy ctor ok
501 // assignment operators and Set() functions: all non const methods return
502 // the reference to this object. IsValid() should be used to test whether
503 // the function succeeded.
504 // ------------------------------------------------------------------------
506 // set to the current time
507 inline wxDateTime
& SetToCurrent();
509 #if (!(defined(__VISAGECPP__) && __IBMCPP__ >= 400))
510 // VA C++ confuses this with wxDateTime(double jdn) thinking it is a duplicate declaration
511 // set to given time_t value
512 inline wxDateTime
& Set(time_t timet
);
515 // set to given broken down time/date
516 wxDateTime
& Set(const struct tm
& tm
);
518 // set to given broken down time/date
519 inline wxDateTime
& Set(const Tm
& tm
);
521 // set to given JDN (beware of rounding errors)
522 wxDateTime
& Set(double jdn
);
524 // set to given time, date = today
525 wxDateTime
& Set(wxDateTime_t hour
,
526 wxDateTime_t minute
= 0,
527 wxDateTime_t second
= 0,
528 wxDateTime_t millisec
= 0);
530 // from separate values for each component with explicit date
531 // (defaults for month and year are the current values)
532 wxDateTime
& Set(wxDateTime_t day
,
534 int year
= Inv_Year
, // 1999, not 99 please!
535 wxDateTime_t hour
= 0,
536 wxDateTime_t minute
= 0,
537 wxDateTime_t second
= 0,
538 wxDateTime_t millisec
= 0);
540 // resets time to 00:00:00, doesn't change the date
541 wxDateTime
& ResetTime();
543 // get the date part of this object only, i.e. the object which has the
544 // same date as this one but time of 00:00:00
545 wxDateTime
GetDateOnly() const;
547 // the following functions don't change the values of the other
548 // fields, i.e. SetMinute() won't change either hour or seconds value
551 wxDateTime
& SetYear(int year
);
553 wxDateTime
& SetMonth(Month month
);
554 // set the day of the month
555 wxDateTime
& SetDay(wxDateTime_t day
);
557 wxDateTime
& SetHour(wxDateTime_t hour
);
559 wxDateTime
& SetMinute(wxDateTime_t minute
);
561 wxDateTime
& SetSecond(wxDateTime_t second
);
563 wxDateTime
& SetMillisecond(wxDateTime_t millisecond
);
565 // assignment operator from time_t
566 wxDateTime
& operator=(time_t timet
) { return Set(timet
); }
568 // assignment operator from broken down time/date
569 wxDateTime
& operator=(const struct tm
& tm
) { return Set(tm
); }
571 // assignment operator from broken down time/date
572 wxDateTime
& operator=(const Tm
& tm
) { return Set(tm
); }
574 // default assignment operator is ok
576 // calendar calculations (functions which set the date only leave the time
577 // unchanged, e.g. don't explicitly zero it): SetXXX() functions modify the
578 // object itself, GetXXX() ones return a new object.
579 // ------------------------------------------------------------------------
581 // set to the given week day in the same week as this one
582 wxDateTime
& SetToWeekDayInSameWeek(WeekDay weekday
,
583 WeekFlags flags
= Monday_First
);
584 inline wxDateTime
GetWeekDayInSameWeek(WeekDay weekday
,
585 WeekFlags flags
= Monday_First
) const;
587 // set to the next week day following this one
588 wxDateTime
& SetToNextWeekDay(WeekDay weekday
);
589 inline wxDateTime
GetNextWeekDay(WeekDay weekday
) const;
591 // set to the previous week day before this one
592 wxDateTime
& SetToPrevWeekDay(WeekDay weekday
);
593 inline wxDateTime
GetPrevWeekDay(WeekDay weekday
) const;
595 // set to Nth occurrence of given weekday in the given month of the
596 // given year (time is set to 0), return true on success and false on
597 // failure. n may be positive (1..5) or negative to count from the end
598 // of the month (see helper function SetToLastWeekDay())
599 bool SetToWeekDay(WeekDay weekday
,
601 Month month
= Inv_Month
,
602 int year
= Inv_Year
);
603 inline wxDateTime
GetWeekDay(WeekDay weekday
,
605 Month month
= Inv_Month
,
606 int year
= Inv_Year
) const;
608 // sets to the last weekday in the given month, year
609 inline bool SetToLastWeekDay(WeekDay weekday
,
610 Month month
= Inv_Month
,
611 int year
= Inv_Year
);
612 inline wxDateTime
GetLastWeekDay(WeekDay weekday
,
613 Month month
= Inv_Month
,
614 int year
= Inv_Year
);
616 #if WXWIN_COMPATIBILITY_2_6
617 // sets the date to the given day of the given week in the year,
618 // returns true on success and false if given date doesn't exist (e.g.
621 // these functions are badly defined as they're not the reverse of
622 // GetWeekOfYear(), use SetToTheWeekOfYear() instead
623 wxDEPRECATED( bool SetToTheWeek(wxDateTime_t numWeek
,
624 WeekDay weekday
= Mon
,
625 WeekFlags flags
= Monday_First
) );
626 wxDEPRECATED( wxDateTime
GetWeek(wxDateTime_t numWeek
,
627 WeekDay weekday
= Mon
,
628 WeekFlags flags
= Monday_First
) const );
629 #endif // WXWIN_COMPATIBILITY_2_6
631 // returns the date corresponding to the given week day of the given
632 // week (in ISO notation) of the specified year
633 static wxDateTime
SetToWeekOfYear(int year
,
634 wxDateTime_t numWeek
,
635 WeekDay weekday
= Mon
);
637 // sets the date to the last day of the given (or current) month or the
638 // given (or current) year
639 wxDateTime
& SetToLastMonthDay(Month month
= Inv_Month
,
640 int year
= Inv_Year
);
641 inline wxDateTime
GetLastMonthDay(Month month
= Inv_Month
,
642 int year
= Inv_Year
) const;
644 // sets to the given year day (1..365 or 366)
645 wxDateTime
& SetToYearDay(wxDateTime_t yday
);
646 inline wxDateTime
GetYearDay(wxDateTime_t yday
) const;
648 // The definitions below were taken verbatim from
650 // http://www.capecod.net/~pbaum/date/date0.htm
652 // (Peter Baum's home page)
654 // definition: The Julian Day Number, Julian Day, or JD of a
655 // particular instant of time is the number of days and fractions of a
656 // day since 12 hours Universal Time (Greenwich mean noon) on January
657 // 1 of the year -4712, where the year is given in the Julian
658 // proleptic calendar. The idea of using this reference date was
659 // originally proposed by Joseph Scalizer in 1582 to count years but
660 // it was modified by 19th century astronomers to count days. One
661 // could have equivalently defined the reference time to be noon of
662 // November 24, -4713 if were understood that Gregorian calendar rules
663 // were applied. Julian days are Julian Day Numbers and are not to be
664 // confused with Julian dates.
666 // definition: The Rata Die number is a date specified as the number
667 // of days relative to a base date of December 31 of the year 0. Thus
668 // January 1 of the year 1 is Rata Die day 1.
670 // get the Julian Day number (the fractional part specifies the time of
671 // the day, related to noon - beware of rounding errors!)
672 double GetJulianDayNumber() const;
673 double GetJDN() const { return GetJulianDayNumber(); }
675 // get the Modified Julian Day number: it is equal to JDN - 2400000.5
676 // and so integral MJDs correspond to the midnights (and not noons).
677 // MJD 0 is Nov 17, 1858
678 double GetModifiedJulianDayNumber() const { return GetJDN() - 2400000.5; }
679 double GetMJD() const { return GetModifiedJulianDayNumber(); }
681 // get the Rata Die number
682 double GetRataDie() const;
684 // TODO algorithms for calculating some important dates, such as
685 // religious holidays (Easter...) or moon/solar eclipses? Some
686 // algorithms can be found in the calendar FAQ
689 // Timezone stuff: a wxDateTime object constructed using given
690 // day/month/year/hour/min/sec values is interpreted as this moment in
691 // local time. Using the functions below, it may be converted to another
692 // time zone (e.g., the Unix epoch is wxDateTime(1, Jan, 1970).ToGMT()).
694 // These functions try to handle DST internally, but there is no magical
695 // way to know all rules for it in all countries in the world, so if the
696 // program can handle it itself (or doesn't want to handle it at all for
697 // whatever reason), the DST handling can be disabled with noDST.
698 // ------------------------------------------------------------------------
700 // transform to any given timezone
701 inline wxDateTime
ToTimezone(const TimeZone
& tz
, bool noDST
= false) const;
702 wxDateTime
& MakeTimezone(const TimeZone
& tz
, bool noDST
= false);
704 // interpret current value as being in another timezone and transform
706 inline wxDateTime
FromTimezone(const TimeZone
& tz
, bool noDST
= false) const;
707 wxDateTime
& MakeFromTimezone(const TimeZone
& tz
, bool noDST
= false);
709 // transform to/from GMT/UTC
710 wxDateTime
ToUTC(bool noDST
= false) const { return ToTimezone(UTC
, noDST
); }
711 wxDateTime
& MakeUTC(bool noDST
= false) { return MakeTimezone(UTC
, noDST
); }
713 wxDateTime
ToGMT(bool noDST
= false) const { return ToUTC(noDST
); }
714 wxDateTime
& MakeGMT(bool noDST
= false) { return MakeUTC(noDST
); }
716 wxDateTime
FromUTC(bool noDST
= false) const
717 { return FromTimezone(UTC
, noDST
); }
718 wxDateTime
& MakeFromUTC(bool noDST
= false)
719 { return MakeFromTimezone(UTC
, noDST
); }
721 // is daylight savings time in effect at this moment according to the
722 // rules of the specified country?
724 // Return value is > 0 if DST is in effect, 0 if it is not and -1 if
725 // the information is not available (this is compatible with ANSI C)
726 int IsDST(Country country
= Country_Default
) const;
729 // accessors: many of them take the timezone parameter which indicates the
730 // timezone for which to make the calculations and the default value means
731 // to do it for the current timezone of this machine (even if the function
732 // only operates with the date it's necessary because a date may wrap as
733 // result of timezone shift)
734 // ------------------------------------------------------------------------
736 // is the date valid?
737 inline bool IsValid() const { return m_time
!= wxInvalidDateTime
.m_time
; }
739 // get the broken down date/time representation in the given timezone
741 // If you wish to get several time components (day, month and year),
742 // consider getting the whole Tm strcuture first and retrieving the
743 // value from it - this is much more efficient
744 Tm
GetTm(const TimeZone
& tz
= Local
) const;
746 // get the number of seconds since the Unix epoch - returns (time_t)-1
747 // if the value is out of range
748 inline time_t GetTicks() const;
750 // get the century, same as GetCentury(GetYear())
751 int GetCentury(const TimeZone
& tz
= Local
) const
752 { return GetCentury(GetYear(tz
)); }
753 // get the year (returns Inv_Year if date is invalid)
754 int GetYear(const TimeZone
& tz
= Local
) const
755 { return GetTm(tz
).year
; }
756 // get the month (Inv_Month if date is invalid)
757 Month
GetMonth(const TimeZone
& tz
= Local
) const
758 { return (Month
)GetTm(tz
).mon
; }
759 // get the month day (in 1..31 range, 0 if date is invalid)
760 wxDateTime_t
GetDay(const TimeZone
& tz
= Local
) const
761 { return GetTm(tz
).mday
; }
762 // get the day of the week (Inv_WeekDay if date is invalid)
763 WeekDay
GetWeekDay(const TimeZone
& tz
= Local
) const
764 { return GetTm(tz
).GetWeekDay(); }
765 // get the hour of the day
766 wxDateTime_t
GetHour(const TimeZone
& tz
= Local
) const
767 { return GetTm(tz
).hour
; }
769 wxDateTime_t
GetMinute(const TimeZone
& tz
= Local
) const
770 { return GetTm(tz
).min
; }
772 wxDateTime_t
GetSecond(const TimeZone
& tz
= Local
) const
773 { return GetTm(tz
).sec
; }
775 wxDateTime_t
GetMillisecond(const TimeZone
& tz
= Local
) const
776 { return GetTm(tz
).msec
; }
778 // get the day since the year start (1..366, 0 if date is invalid)
779 wxDateTime_t
GetDayOfYear(const TimeZone
& tz
= Local
) const;
780 // get the week number since the year start (1..52 or 53, 0 if date is
782 wxDateTime_t
GetWeekOfYear(WeekFlags flags
= Monday_First
,
783 const TimeZone
& tz
= Local
) const;
784 // get the week number since the month start (1..5, 0 if date is
786 wxDateTime_t
GetWeekOfMonth(WeekFlags flags
= Monday_First
,
787 const TimeZone
& tz
= Local
) const;
789 // is this date a work day? This depends on a country, of course,
790 // because the holidays are different in different countries
791 bool IsWorkDay(Country country
= Country_Default
) const;
793 // dos date and time format
794 // ------------------------------------------------------------------------
796 // set from the DOS packed format
797 wxDateTime
& SetFromDOS(unsigned long ddt
);
799 // pack the date in DOS format
800 unsigned long GetAsDOS() const;
803 // ------------------------------------------------------------------------
805 // convert SYSTEMTIME to wxDateTime
806 wxDateTime
& SetFromMSWSysTime(const struct _SYSTEMTIME
& st
);
808 // convert wxDateTime to SYSTEMTIME
809 void GetAsMSWSysTime(struct _SYSTEMTIME
* st
) const;
811 // same as above but only take date part into account, time is always zero
812 wxDateTime
& SetFromMSWSysDate(const struct _SYSTEMTIME
& st
);
813 void GetAsMSWSysDate(struct _SYSTEMTIME
* st
) const;
814 #endif // __WINDOWS__
816 // comparison (see also functions below for operator versions)
817 // ------------------------------------------------------------------------
819 // returns true if the two moments are strictly identical
820 inline bool IsEqualTo(const wxDateTime
& datetime
) const;
822 // returns true if the date is strictly earlier than the given one
823 inline bool IsEarlierThan(const wxDateTime
& datetime
) const;
825 // returns true if the date is strictly later than the given one
826 inline bool IsLaterThan(const wxDateTime
& datetime
) const;
828 // returns true if the date is strictly in the given range
829 inline bool IsStrictlyBetween(const wxDateTime
& t1
,
830 const wxDateTime
& t2
) const;
832 // returns true if the date is in the given range
833 inline bool IsBetween(const wxDateTime
& t1
, const wxDateTime
& t2
) const;
835 // do these two objects refer to the same date?
836 inline bool IsSameDate(const wxDateTime
& dt
) const;
838 // do these two objects have the same time?
839 inline bool IsSameTime(const wxDateTime
& dt
) const;
841 // are these two objects equal up to given timespan?
842 inline bool IsEqualUpTo(const wxDateTime
& dt
, const wxTimeSpan
& ts
) const;
844 inline bool operator<(const wxDateTime
& dt
) const
846 wxASSERT_MSG( IsValid() && dt
.IsValid(), wxT("invalid wxDateTime") );
847 return GetValue() < dt
.GetValue();
850 inline bool operator<=(const wxDateTime
& dt
) const
852 wxASSERT_MSG( IsValid() && dt
.IsValid(), wxT("invalid wxDateTime") );
853 return GetValue() <= dt
.GetValue();
856 inline bool operator>(const wxDateTime
& dt
) const
858 wxASSERT_MSG( IsValid() && dt
.IsValid(), wxT("invalid wxDateTime") );
859 return GetValue() > dt
.GetValue();
862 inline bool operator>=(const wxDateTime
& dt
) const
864 wxASSERT_MSG( IsValid() && dt
.IsValid(), wxT("invalid wxDateTime") );
865 return GetValue() >= dt
.GetValue();
868 inline bool operator==(const wxDateTime
& dt
) const
870 wxASSERT_MSG( IsValid() && dt
.IsValid(), wxT("invalid wxDateTime") );
871 return GetValue() == dt
.GetValue();
874 inline bool operator!=(const wxDateTime
& dt
) const
876 wxASSERT_MSG( IsValid() && dt
.IsValid(), wxT("invalid wxDateTime") );
877 return GetValue() != dt
.GetValue();
880 // arithmetics with dates (see also below for more operators)
881 // ------------------------------------------------------------------------
883 // return the sum of the date with a time span (positive or negative)
884 inline wxDateTime
Add(const wxTimeSpan
& diff
) const;
885 // add a time span (positive or negative)
886 inline wxDateTime
& Add(const wxTimeSpan
& diff
);
887 // add a time span (positive or negative)
888 inline wxDateTime
& operator+=(const wxTimeSpan
& diff
);
889 inline wxDateTime
operator+(const wxTimeSpan
& ts
) const
891 wxDateTime
dt(*this);
896 // return the difference of the date with a time span
897 inline wxDateTime
Subtract(const wxTimeSpan
& diff
) const;
898 // subtract a time span (positive or negative)
899 inline wxDateTime
& Subtract(const wxTimeSpan
& diff
);
900 // subtract a time span (positive or negative)
901 inline wxDateTime
& operator-=(const wxTimeSpan
& diff
);
902 inline wxDateTime
operator-(const wxTimeSpan
& ts
) const
904 wxDateTime
dt(*this);
909 // return the sum of the date with a date span
910 inline wxDateTime
Add(const wxDateSpan
& diff
) const;
911 // add a date span (positive or negative)
912 wxDateTime
& Add(const wxDateSpan
& diff
);
913 // add a date span (positive or negative)
914 inline wxDateTime
& operator+=(const wxDateSpan
& diff
);
915 inline wxDateTime
operator+(const wxDateSpan
& ds
) const
917 wxDateTime
dt(*this);
922 // return the difference of the date with a date span
923 inline wxDateTime
Subtract(const wxDateSpan
& diff
) const;
924 // subtract a date span (positive or negative)
925 inline wxDateTime
& Subtract(const wxDateSpan
& diff
);
926 // subtract a date span (positive or negative)
927 inline wxDateTime
& operator-=(const wxDateSpan
& diff
);
928 inline wxDateTime
operator-(const wxDateSpan
& ds
) const
930 wxDateTime
dt(*this);
935 // return the difference between two dates
936 inline wxTimeSpan
Subtract(const wxDateTime
& dt
) const;
937 inline wxTimeSpan
operator-(const wxDateTime
& dt2
) const;
939 wxDateSpan
DiffAsDateSpan(const wxDateTime
& dt
) const;
941 // conversion to/from text
942 // ------------------------------------------------------------------------
944 // all conversions functions return true to indicate whether parsing
945 // succeeded or failed and fill in the provided end iterator, which must
946 // not be NULL, with the location of the character where the parsing
947 // stopped (this will be end() of the passed string if everything was
950 // parse a string in RFC 822 format (found e.g. in mail headers and
951 // having the form "Wed, 10 Feb 1999 19:07:07 +0100")
952 bool ParseRfc822Date(const wxString
& date
,
953 wxString::const_iterator
*end
);
955 // parse a date/time in the given format (see strptime(3)), fill in
956 // the missing (in the string) fields with the values of dateDef (by
957 // default, they will not change if they had valid values or will
958 // default to Today() otherwise)
959 bool ParseFormat(const wxString
& date
,
960 const wxString
& format
,
961 const wxDateTime
& dateDef
,
962 wxString::const_iterator
*end
);
964 bool ParseFormat(const wxString
& date
,
965 const wxString
& format
,
966 wxString::const_iterator
*end
)
968 return ParseFormat(date
, format
, wxDefaultDateTime
, end
);
971 bool ParseFormat(const wxString
& date
,
972 wxString::const_iterator
*end
)
974 return ParseFormat(date
, wxDefaultDateTimeFormat
, wxDefaultDateTime
, end
);
977 // parse a string containing date, time or both in ISO 8601 format
979 // notice that these functions are new in wx 3.0 and so we don't
980 // provide compatibility overloads for them
981 bool ParseISODate(const wxString
& date
)
983 wxString::const_iterator end
;
984 return ParseFormat(date
, wxS("%Y-%m-%d"), &end
) && end
== date
.end();
987 bool ParseISOTime(const wxString
& time
)
989 wxString::const_iterator end
;
990 return ParseFormat(time
, wxS("%H:%M:%S"), &end
) && end
== time
.end();
993 bool ParseISOCombined(const wxString
& datetime
, char sep
= 'T')
995 wxString::const_iterator end
;
996 const wxString fmt
= wxS("%Y-%m-%d") + wxString(sep
) + wxS("%H:%M:%S");
997 return ParseFormat(datetime
, fmt
, &end
) && end
== datetime
.end();
1000 // parse a string containing the date/time in "free" format, this
1001 // function will try to make an educated guess at the string contents
1002 bool ParseDateTime(const wxString
& datetime
,
1003 wxString::const_iterator
*end
);
1005 // parse a string containing the date only in "free" format (less
1006 // flexible than ParseDateTime)
1007 bool ParseDate(const wxString
& date
,
1008 wxString::const_iterator
*end
);
1010 // parse a string containing the time only in "free" format
1011 bool ParseTime(const wxString
& time
,
1012 wxString::const_iterator
*end
);
1015 // this function accepts strftime()-like format string (default
1016 // argument corresponds to the preferred date and time representation
1017 // for the current locale) and returns the string containing the
1018 // resulting text representation
1019 wxString
Format(const wxString
& format
= wxDefaultDateTimeFormat
,
1020 const TimeZone
& tz
= Local
) const;
1021 // preferred date representation for the current locale
1022 wxString
FormatDate() const { return Format(wxS("%x")); }
1023 // preferred time representation for the current locale
1024 wxString
FormatTime() const { return Format(wxS("%X")); }
1025 // returns the string representing the date in ISO 8601 format
1027 wxString
FormatISODate() const { return Format(wxS("%Y-%m-%d")); }
1028 // returns the string representing the time in ISO 8601 format
1030 wxString
FormatISOTime() const { return Format(wxS("%H:%M:%S")); }
1031 // return the combined date time representation in ISO 8601 format; the
1032 // separator character should be 'T' according to the standard but it
1033 // can also be useful to set it to ' '
1034 wxString
FormatISOCombined(char sep
= 'T') const
1035 { return FormatISODate() + sep
+ FormatISOTime(); }
1038 // backwards compatible versions of the parsing functions: they return an
1039 // object representing the next character following the date specification
1040 // (i.e. the one where the scan had to stop) or a special NULL-like object
1043 // they're not deprecated because a lot of existing code uses them and
1044 // there is no particular harm in keeping them but you should still prefer
1045 // the versions above in the new code
1046 wxAnyStrPtr
ParseRfc822Date(const wxString
& date
)
1048 wxString::const_iterator end
;
1049 return ParseRfc822Date(date
, &end
) ? wxAnyStrPtr(date
, end
)
1053 wxAnyStrPtr
ParseFormat(const wxString
& date
,
1054 const wxString
& format
= wxDefaultDateTimeFormat
,
1055 const wxDateTime
& dateDef
= wxDefaultDateTime
)
1057 wxString::const_iterator end
;
1058 return ParseFormat(date
, format
, dateDef
, &end
) ? wxAnyStrPtr(date
, end
)
1062 wxAnyStrPtr
ParseDateTime(const wxString
& datetime
)
1064 wxString::const_iterator end
;
1065 return ParseDateTime(datetime
, &end
) ? wxAnyStrPtr(datetime
, end
)
1069 wxAnyStrPtr
ParseDate(const wxString
& date
)
1071 wxString::const_iterator end
;
1072 return ParseDate(date
, &end
) ? wxAnyStrPtr(date
, end
)
1076 wxAnyStrPtr
ParseTime(const wxString
& time
)
1078 wxString::const_iterator end
;
1079 return ParseTime(time
, &end
) ? wxAnyStrPtr(time
, end
)
1083 // In addition to wxAnyStrPtr versions above we also must provide the
1084 // overloads for C strings as we must return a pointer into the original
1085 // string and not inside a temporary wxString which would have been created
1086 // if the overloads above were used.
1088 // And then we also have to provide the overloads for wxCStrData, as usual.
1089 // Unfortunately those ones can't return anything as we don't have any
1090 // sufficiently long-lived wxAnyStrPtr to return from them: any temporary
1091 // strings it would point to would be destroyed when this function returns
1092 // making it impossible to dereference the return value. So we just don't
1093 // return anything from here which at least allows to keep compatibility
1094 // with the code not testing the return value. Other uses of this method
1095 // need to be converted to use one of the new bool-returning overloads
1097 void ParseRfc822Date(const wxCStrData
& date
)
1098 { ParseRfc822Date(wxString(date
)); }
1099 const char* ParseRfc822Date(const char* date
);
1100 const wchar_t* ParseRfc822Date(const wchar_t* date
);
1102 void ParseFormat(const wxCStrData
& date
,
1103 const wxString
& format
= wxDefaultDateTimeFormat
,
1104 const wxDateTime
& dateDef
= wxDefaultDateTime
)
1105 { ParseFormat(wxString(date
), format
, dateDef
); }
1106 const char* ParseFormat(const char* date
,
1107 const wxString
& format
= wxDefaultDateTimeFormat
,
1108 const wxDateTime
& dateDef
= wxDefaultDateTime
);
1109 const wchar_t* ParseFormat(const wchar_t* date
,
1110 const wxString
& format
= wxDefaultDateTimeFormat
,
1111 const wxDateTime
& dateDef
= wxDefaultDateTime
);
1113 void ParseDateTime(const wxCStrData
& datetime
)
1114 { ParseDateTime(wxString(datetime
)); }
1115 const char* ParseDateTime(const char* datetime
);
1116 const wchar_t* ParseDateTime(const wchar_t* datetime
);
1118 void ParseDate(const wxCStrData
& date
)
1119 { ParseDate(wxString(date
)); }
1120 const char* ParseDate(const char* date
);
1121 const wchar_t* ParseDate(const wchar_t* date
);
1123 void ParseTime(const wxCStrData
& time
)
1124 { ParseTime(wxString(time
)); }
1125 const char* ParseTime(const char* time
);
1126 const wchar_t* ParseTime(const wchar_t* time
);
1130 // ------------------------------------------------------------------------
1132 // construct from internal representation
1133 wxDateTime(const wxLongLong
& time
) { m_time
= time
; }
1135 // get the internal representation
1136 inline wxLongLong
GetValue() const;
1138 // a helper function to get the current time_t
1139 static time_t GetTimeNow() { return time(NULL
); }
1141 // another one to get the current time broken down
1142 static struct tm
*GetTmNow()
1144 static struct tm l_CurrentTime
;
1145 return GetTmNow(&l_CurrentTime
);
1148 // get current time using thread-safe function
1149 static struct tm
*GetTmNow(struct tm
*tmstruct
);
1152 // the current country - as it's the same for all program objects (unless
1153 // it runs on a _really_ big cluster system :-), this is a static member:
1154 // see SetCountry() and GetCountry()
1155 static Country ms_country
;
1157 // this constant is used to transform a time_t value to the internal
1158 // representation, as time_t is in seconds and we use milliseconds it's
1160 static const long TIME_T_FACTOR
;
1162 // returns true if we fall in range in which we can use standard ANSI C
1164 inline bool IsInStdRange() const;
1166 // the internal representation of the time is the amount of milliseconds
1167 // elapsed since the origin which is set by convention to the UNIX/C epoch
1168 // value: the midnight of January 1, 1970 (UTC)
1172 // ----------------------------------------------------------------------------
1173 // This class contains a difference between 2 wxDateTime values, so it makes
1174 // sense to add it to wxDateTime and it is the result of subtraction of 2
1175 // objects of that class. See also wxDateSpan.
1176 // ----------------------------------------------------------------------------
1178 class WXDLLIMPEXP_BASE wxTimeSpan
1182 // ------------------------------------------------------------------------
1184 // return the timespan for the given number of milliseconds
1185 static wxTimeSpan
Milliseconds(wxLongLong ms
) { return wxTimeSpan(0, 0, 0, ms
); }
1186 static wxTimeSpan
Millisecond() { return Milliseconds(1); }
1188 // return the timespan for the given number of seconds
1189 static wxTimeSpan
Seconds(wxLongLong sec
) { return wxTimeSpan(0, 0, sec
); }
1190 static wxTimeSpan
Second() { return Seconds(1); }
1192 // return the timespan for the given number of minutes
1193 static wxTimeSpan
Minutes(long min
) { return wxTimeSpan(0, min
, 0 ); }
1194 static wxTimeSpan
Minute() { return Minutes(1); }
1196 // return the timespan for the given number of hours
1197 static wxTimeSpan
Hours(long hours
) { return wxTimeSpan(hours
, 0, 0); }
1198 static wxTimeSpan
Hour() { return Hours(1); }
1200 // return the timespan for the given number of days
1201 static wxTimeSpan
Days(long days
) { return Hours(24 * days
); }
1202 static wxTimeSpan
Day() { return Days(1); }
1204 // return the timespan for the given number of weeks
1205 static wxTimeSpan
Weeks(long days
) { return Days(7 * days
); }
1206 static wxTimeSpan
Week() { return Weeks(1); }
1208 // default ctor constructs the 0 time span
1211 // from separate values for each component, date set to 0 (hours are
1212 // not restricted to 0..24 range, neither are minutes, seconds or
1214 inline wxTimeSpan(long hours
,
1216 wxLongLong seconds
= 0,
1217 wxLongLong milliseconds
= 0);
1219 // default copy ctor is ok
1223 // arithmetics with time spans (see also below for more operators)
1224 // ------------------------------------------------------------------------
1226 // return the sum of two timespans
1227 inline wxTimeSpan
Add(const wxTimeSpan
& diff
) const;
1228 // add two timespans together
1229 inline wxTimeSpan
& Add(const wxTimeSpan
& diff
);
1230 // add two timespans together
1231 wxTimeSpan
& operator+=(const wxTimeSpan
& diff
) { return Add(diff
); }
1232 inline wxTimeSpan
operator+(const wxTimeSpan
& ts
) const
1234 return wxTimeSpan(GetValue() + ts
.GetValue());
1237 // return the difference of two timespans
1238 inline wxTimeSpan
Subtract(const wxTimeSpan
& diff
) const;
1239 // subtract another timespan
1240 inline wxTimeSpan
& Subtract(const wxTimeSpan
& diff
);
1241 // subtract another timespan
1242 wxTimeSpan
& operator-=(const wxTimeSpan
& diff
) { return Subtract(diff
); }
1243 inline wxTimeSpan
operator-(const wxTimeSpan
& ts
)
1245 return wxTimeSpan(GetValue() - ts
.GetValue());
1248 // multiply timespan by a scalar
1249 inline wxTimeSpan
Multiply(int n
) const;
1250 // multiply timespan by a scalar
1251 inline wxTimeSpan
& Multiply(int n
);
1252 // multiply timespan by a scalar
1253 wxTimeSpan
& operator*=(int n
) { return Multiply(n
); }
1254 inline wxTimeSpan
operator*(int n
) const
1256 return wxTimeSpan(*this).Multiply(n
);
1259 // return this timespan with opposite sign
1260 wxTimeSpan
Negate() const { return wxTimeSpan(-GetValue()); }
1261 // negate the value of the timespan
1262 wxTimeSpan
& Neg() { m_diff
= -GetValue(); return *this; }
1263 // negate the value of the timespan
1264 wxTimeSpan
& operator-() { return Neg(); }
1266 // return the absolute value of the timespan: does _not_ modify the
1268 inline wxTimeSpan
Abs() const;
1270 // there is intentionally no division because we don't want to
1271 // introduce rounding errors in time calculations
1273 // comparaison (see also operator versions below)
1274 // ------------------------------------------------------------------------
1276 // is the timespan null?
1277 bool IsNull() const { return m_diff
== 0l; }
1278 // returns true if the timespan is null
1279 bool operator!() const { return !IsNull(); }
1281 // is the timespan positive?
1282 bool IsPositive() const { return m_diff
> 0l; }
1284 // is the timespan negative?
1285 bool IsNegative() const { return m_diff
< 0l; }
1287 // are two timespans equal?
1288 inline bool IsEqualTo(const wxTimeSpan
& ts
) const;
1289 // compare two timestamps: works with the absolute values, i.e. -2
1290 // hours is longer than 1 hour. Also, it will return false if the
1291 // timespans are equal in absolute value.
1292 inline bool IsLongerThan(const wxTimeSpan
& ts
) const;
1293 // compare two timestamps: works with the absolute values, i.e. 1
1294 // hour is shorter than -2 hours. Also, it will return false if the
1295 // timespans are equal in absolute value.
1296 bool IsShorterThan(const wxTimeSpan
& t
) const;
1298 inline bool operator<(const wxTimeSpan
&ts
) const
1300 return GetValue() < ts
.GetValue();
1303 inline bool operator<=(const wxTimeSpan
&ts
) const
1305 return GetValue() <= ts
.GetValue();
1308 inline bool operator>(const wxTimeSpan
&ts
) const
1310 return GetValue() > ts
.GetValue();
1313 inline bool operator>=(const wxTimeSpan
&ts
) const
1315 return GetValue() >= ts
.GetValue();
1318 inline bool operator==(const wxTimeSpan
&ts
) const
1320 return GetValue() == ts
.GetValue();
1323 inline bool operator!=(const wxTimeSpan
&ts
) const
1325 return GetValue() != ts
.GetValue();
1328 // breaking into days, hours, minutes and seconds
1329 // ------------------------------------------------------------------------
1331 // get the max number of weeks in this timespan
1332 inline int GetWeeks() const;
1333 // get the max number of days in this timespan
1334 inline int GetDays() const;
1335 // get the max number of hours in this timespan
1336 inline int GetHours() const;
1337 // get the max number of minutes in this timespan
1338 inline int GetMinutes() const;
1339 // get the max number of seconds in this timespan
1340 inline wxLongLong
GetSeconds() const;
1341 // get the number of milliseconds in this timespan
1342 wxLongLong
GetMilliseconds() const { return m_diff
; }
1344 // conversion to text
1345 // ------------------------------------------------------------------------
1347 // this function accepts strftime()-like format string (default
1348 // argument corresponds to the preferred date and time representation
1349 // for the current locale) and returns the string containing the
1350 // resulting text representation. Notice that only some of format
1351 // specifiers valid for wxDateTime are valid for wxTimeSpan: hours,
1352 // minutes and seconds make sense, but not "PM/AM" string for example.
1353 wxString
Format(const wxString
& format
= wxDefaultTimeSpanFormat
) const;
1356 // ------------------------------------------------------------------------
1358 // construct from internal representation
1359 wxTimeSpan(const wxLongLong
& diff
) { m_diff
= diff
; }
1361 // get the internal representation
1362 wxLongLong
GetValue() const { return m_diff
; }
1365 // the (signed) time span in milliseconds
1369 // ----------------------------------------------------------------------------
1370 // This class is a "logical time span" and is useful for implementing program
1371 // logic for such things as "add one month to the date" which, in general,
1372 // doesn't mean to add 60*60*24*31 seconds to it, but to take the same date
1373 // the next month (to understand that this is indeed different consider adding
1374 // one month to Feb, 15 - we want to get Mar, 15, of course).
1376 // When adding a month to the date, all lesser components (days, hours, ...)
1377 // won't be changed unless the resulting date would be invalid: for example,
1378 // Jan 31 + 1 month will be Feb 28, not (non existing) Feb 31.
1380 // Because of this feature, adding and subtracting back again the same
1381 // wxDateSpan will *not*, in general give back the original date: Feb 28 - 1
1382 // month will be Jan 28, not Jan 31!
1384 // wxDateSpan can be either positive or negative. They may be
1385 // multiplied by scalars which multiply all deltas by the scalar: i.e. 2*(1
1386 // month and 1 day) is 2 months and 2 days. They can be added together and
1387 // with wxDateTime or wxTimeSpan, but the type of result is different for each
1390 // Beware about weeks: if you specify both weeks and days, the total number of
1391 // days added will be 7*weeks + days! See also GetTotalDays() function.
1393 // Equality operators are defined for wxDateSpans. Two datespans are equal if
1394 // they both give the same target date when added to *every* source date.
1395 // Thus wxDateSpan::Months(1) is not equal to wxDateSpan::Days(30), because
1396 // they not give the same date when added to 1 Feb. But wxDateSpan::Days(14) is
1397 // equal to wxDateSpan::Weeks(2)
1399 // Finally, notice that for adding hours, minutes &c you don't need this
1400 // class: wxTimeSpan will do the job because there are no subtleties
1401 // associated with those.
1402 // ----------------------------------------------------------------------------
1404 class WXDLLIMPEXP_BASE wxDateSpan
1408 // ------------------------------------------------------------------------
1410 // this many years/months/weeks/days
1411 wxDateSpan(int years
= 0, int months
= 0, int weeks
= 0, int days
= 0)
1419 // get an object for the given number of days
1420 static wxDateSpan
Days(int days
) { return wxDateSpan(0, 0, 0, days
); }
1421 static wxDateSpan
Day() { return Days(1); }
1423 // get an object for the given number of weeks
1424 static wxDateSpan
Weeks(int weeks
) { return wxDateSpan(0, 0, weeks
, 0); }
1425 static wxDateSpan
Week() { return Weeks(1); }
1427 // get an object for the given number of months
1428 static wxDateSpan
Months(int mon
) { return wxDateSpan(0, mon
, 0, 0); }
1429 static wxDateSpan
Month() { return Months(1); }
1431 // get an object for the given number of years
1432 static wxDateSpan
Years(int years
) { return wxDateSpan(years
, 0, 0, 0); }
1433 static wxDateSpan
Year() { return Years(1); }
1435 // default copy ctor is ok
1439 // accessors (all SetXXX() return the (modified) wxDateSpan object)
1440 // ------------------------------------------------------------------------
1442 // set number of years
1443 wxDateSpan
& SetYears(int n
) { m_years
= n
; return *this; }
1444 // set number of months
1445 wxDateSpan
& SetMonths(int n
) { m_months
= n
; return *this; }
1446 // set number of weeks
1447 wxDateSpan
& SetWeeks(int n
) { m_weeks
= n
; return *this; }
1448 // set number of days
1449 wxDateSpan
& SetDays(int n
) { m_days
= n
; return *this; }
1451 // get number of years
1452 int GetYears() const { return m_years
; }
1453 // get number of months
1454 int GetMonths() const { return m_months
; }
1455 // returns 12*GetYears() + GetMonths()
1456 int GetTotalMonths() const { return 12*m_years
+ m_months
; }
1457 // get number of weeks
1458 int GetWeeks() const { return m_weeks
; }
1459 // get number of days
1460 int GetDays() const { return m_days
; }
1461 // returns 7*GetWeeks() + GetDays()
1462 int GetTotalDays() const { return 7*m_weeks
+ m_days
; }
1464 // arithmetics with date spans (see also below for more operators)
1465 // ------------------------------------------------------------------------
1467 // return sum of two date spans
1468 inline wxDateSpan
Add(const wxDateSpan
& other
) const;
1469 // add another wxDateSpan to us
1470 inline wxDateSpan
& Add(const wxDateSpan
& other
);
1471 // add another wxDateSpan to us
1472 inline wxDateSpan
& operator+=(const wxDateSpan
& other
);
1473 inline wxDateSpan
operator+(const wxDateSpan
& ds
) const
1475 return wxDateSpan(GetYears() + ds
.GetYears(),
1476 GetMonths() + ds
.GetMonths(),
1477 GetWeeks() + ds
.GetWeeks(),
1478 GetDays() + ds
.GetDays());
1481 // return difference of two date spans
1482 inline wxDateSpan
Subtract(const wxDateSpan
& other
) const;
1483 // subtract another wxDateSpan from us
1484 inline wxDateSpan
& Subtract(const wxDateSpan
& other
);
1485 // subtract another wxDateSpan from us
1486 inline wxDateSpan
& operator-=(const wxDateSpan
& other
);
1487 inline wxDateSpan
operator-(const wxDateSpan
& ds
) const
1489 return wxDateSpan(GetYears() - ds
.GetYears(),
1490 GetMonths() - ds
.GetMonths(),
1491 GetWeeks() - ds
.GetWeeks(),
1492 GetDays() - ds
.GetDays());
1495 // return a copy of this time span with changed sign
1496 inline wxDateSpan
Negate() const;
1497 // inverse the sign of this timespan
1498 inline wxDateSpan
& Neg();
1499 // inverse the sign of this timespan
1500 wxDateSpan
& operator-() { return Neg(); }
1502 // return the date span proportional to this one with given factor
1503 inline wxDateSpan
Multiply(int factor
) const;
1504 // multiply all components by a (signed) number
1505 inline wxDateSpan
& Multiply(int factor
);
1506 // multiply all components by a (signed) number
1507 inline wxDateSpan
& operator*=(int factor
) { return Multiply(factor
); }
1508 inline wxDateSpan
operator*(int n
) const
1510 return wxDateSpan(*this).Multiply(n
);
1513 // ds1 == d2 if and only if for every wxDateTime t t + ds1 == t + ds2
1514 inline bool operator==(const wxDateSpan
& ds
) const
1516 return GetYears() == ds
.GetYears() &&
1517 GetMonths() == ds
.GetMonths() &&
1518 GetTotalDays() == ds
.GetTotalDays();
1521 inline bool operator!=(const wxDateSpan
& ds
) const
1523 return !(*this == ds
);
1533 // ----------------------------------------------------------------------------
1534 // wxDateTimeArray: array of dates.
1535 // ----------------------------------------------------------------------------
1537 WX_DECLARE_USER_EXPORTED_OBJARRAY(wxDateTime
, wxDateTimeArray
, WXDLLIMPEXP_BASE
);
1539 // ----------------------------------------------------------------------------
1540 // wxDateTimeHolidayAuthority: an object of this class will decide whether a
1541 // given date is a holiday and is used by all functions working with "work
1544 // NB: the base class is an ABC, derived classes must implement the pure
1545 // virtual methods to work with the holidays they correspond to.
1546 // ----------------------------------------------------------------------------
1548 class WXDLLIMPEXP_FWD_BASE wxDateTimeHolidayAuthority
;
1549 WX_DEFINE_USER_EXPORTED_ARRAY_PTR(wxDateTimeHolidayAuthority
*,
1550 wxHolidayAuthoritiesArray
,
1551 class WXDLLIMPEXP_BASE
);
1553 class wxDateTimeHolidaysModule
;
1554 class WXDLLIMPEXP_BASE wxDateTimeHolidayAuthority
1556 friend class wxDateTimeHolidaysModule
;
1558 // returns true if the given date is a holiday
1559 static bool IsHoliday(const wxDateTime
& dt
);
1561 // fills the provided array with all holidays in the given range, returns
1562 // the number of them
1563 static size_t GetHolidaysInRange(const wxDateTime
& dtStart
,
1564 const wxDateTime
& dtEnd
,
1565 wxDateTimeArray
& holidays
);
1567 // clear the list of holiday authorities
1568 static void ClearAllAuthorities();
1570 // add a new holiday authority (the pointer will be deleted by
1571 // wxDateTimeHolidayAuthority)
1572 static void AddAuthority(wxDateTimeHolidayAuthority
*auth
);
1574 // the base class must have a virtual dtor
1575 virtual ~wxDateTimeHolidayAuthority();
1578 // this function is called to determine whether a given day is a holiday
1579 virtual bool DoIsHoliday(const wxDateTime
& dt
) const = 0;
1581 // this function should fill the array with all holidays between the two
1582 // given dates - it is implemented in the base class, but in a very
1583 // inefficient way (it just iterates over all days and uses IsHoliday() for
1584 // each of them), so it must be overridden in the derived class where the
1585 // base class version may be explicitly used if needed
1587 // returns the number of holidays in the given range and fills holidays
1589 virtual size_t DoGetHolidaysInRange(const wxDateTime
& dtStart
,
1590 const wxDateTime
& dtEnd
,
1591 wxDateTimeArray
& holidays
) const = 0;
1594 // all holiday authorities
1595 static wxHolidayAuthoritiesArray ms_authorities
;
1598 // the holidays for this class are all Saturdays and Sundays
1599 class WXDLLIMPEXP_BASE wxDateTimeWorkDays
: public wxDateTimeHolidayAuthority
1602 virtual bool DoIsHoliday(const wxDateTime
& dt
) const;
1603 virtual size_t DoGetHolidaysInRange(const wxDateTime
& dtStart
,
1604 const wxDateTime
& dtEnd
,
1605 wxDateTimeArray
& holidays
) const;
1608 // ============================================================================
1609 // inline functions implementation
1610 // ============================================================================
1612 // ----------------------------------------------------------------------------
1614 // ----------------------------------------------------------------------------
1616 #define MILLISECONDS_PER_DAY 86400000l
1618 // some broken compilers (HP-UX CC) refuse to compile the "normal" version, but
1619 // using a temp variable always might prevent other compilers from optimising
1620 // it away - hence use of this ugly macro
1622 #define MODIFY_AND_RETURN(op) return wxDateTime(*this).op
1624 #define MODIFY_AND_RETURN(op) wxDateTime dt(*this); dt.op; return dt
1627 // ----------------------------------------------------------------------------
1628 // wxDateTime construction
1629 // ----------------------------------------------------------------------------
1631 inline bool wxDateTime::IsInStdRange() const
1633 // currently we don't know what is the real type of time_t so prefer to err
1634 // on the safe side and limit it to 32 bit values which is safe everywhere
1635 return m_time
>= 0l && (m_time
/ TIME_T_FACTOR
) < wxINT32_MAX
;
1639 inline wxDateTime
wxDateTime::Now()
1642 return wxDateTime(*GetTmNow(&tmstruct
));
1646 inline wxDateTime
wxDateTime::Today()
1648 wxDateTime
dt(Now());
1654 #if (!(defined(__VISAGECPP__) && __IBMCPP__ >= 400))
1655 inline wxDateTime
& wxDateTime::Set(time_t timet
)
1657 if ( timet
== (time_t)-1 )
1659 m_time
= wxInvalidDateTime
.m_time
;
1663 // assign first to avoid long multiplication overflow!
1664 m_time
= timet
- WX_TIME_BASE_OFFSET
;
1665 m_time
*= TIME_T_FACTOR
;
1672 inline wxDateTime
& wxDateTime::SetToCurrent()
1678 #if (!(defined(__VISAGECPP__) && __IBMCPP__ >= 400))
1679 inline wxDateTime::wxDateTime(time_t timet
)
1685 inline wxDateTime::wxDateTime(const struct tm
& tm
)
1690 inline wxDateTime::wxDateTime(const Tm
& tm
)
1695 inline wxDateTime::wxDateTime(double jdn
)
1700 inline wxDateTime
& wxDateTime::Set(const Tm
& tm
)
1702 wxASSERT_MSG( tm
.IsValid(), wxT("invalid broken down date/time") );
1704 return Set(tm
.mday
, (Month
)tm
.mon
, tm
.year
,
1705 tm
.hour
, tm
.min
, tm
.sec
, tm
.msec
);
1708 inline wxDateTime::wxDateTime(wxDateTime_t hour
,
1709 wxDateTime_t minute
,
1710 wxDateTime_t second
,
1711 wxDateTime_t millisec
)
1713 Set(hour
, minute
, second
, millisec
);
1716 inline wxDateTime::wxDateTime(wxDateTime_t day
,
1720 wxDateTime_t minute
,
1721 wxDateTime_t second
,
1722 wxDateTime_t millisec
)
1724 Set(day
, month
, year
, hour
, minute
, second
, millisec
);
1727 // ----------------------------------------------------------------------------
1728 // wxDateTime accessors
1729 // ----------------------------------------------------------------------------
1731 inline wxLongLong
wxDateTime::GetValue() const
1733 wxASSERT_MSG( IsValid(), wxT("invalid wxDateTime"));
1738 inline time_t wxDateTime::GetTicks() const
1740 wxASSERT_MSG( IsValid(), wxT("invalid wxDateTime"));
1741 if ( !IsInStdRange() )
1746 return (time_t)((m_time
/ (long)TIME_T_FACTOR
).ToLong()) + WX_TIME_BASE_OFFSET
;
1749 inline bool wxDateTime::SetToLastWeekDay(WeekDay weekday
,
1753 return SetToWeekDay(weekday
, -1, month
, year
);
1757 wxDateTime::GetWeekDayInSameWeek(WeekDay weekday
,
1758 WeekFlags
WXUNUSED(flags
)) const
1760 MODIFY_AND_RETURN( SetToWeekDayInSameWeek(weekday
) );
1763 inline wxDateTime
wxDateTime::GetNextWeekDay(WeekDay weekday
) const
1765 MODIFY_AND_RETURN( SetToNextWeekDay(weekday
) );
1768 inline wxDateTime
wxDateTime::GetPrevWeekDay(WeekDay weekday
) const
1770 MODIFY_AND_RETURN( SetToPrevWeekDay(weekday
) );
1773 inline wxDateTime
wxDateTime::GetWeekDay(WeekDay weekday
,
1778 wxDateTime
dt(*this);
1780 return dt
.SetToWeekDay(weekday
, n
, month
, year
) ? dt
: wxInvalidDateTime
;
1783 inline wxDateTime
wxDateTime::GetLastWeekDay(WeekDay weekday
,
1787 wxDateTime
dt(*this);
1789 return dt
.SetToLastWeekDay(weekday
, month
, year
) ? dt
: wxInvalidDateTime
;
1792 inline wxDateTime
wxDateTime::GetLastMonthDay(Month month
, int year
) const
1794 MODIFY_AND_RETURN( SetToLastMonthDay(month
, year
) );
1797 inline wxDateTime
wxDateTime::GetYearDay(wxDateTime_t yday
) const
1799 MODIFY_AND_RETURN( SetToYearDay(yday
) );
1802 // ----------------------------------------------------------------------------
1803 // wxDateTime comparison
1804 // ----------------------------------------------------------------------------
1806 inline bool wxDateTime::IsEqualTo(const wxDateTime
& datetime
) const
1808 wxASSERT_MSG( IsValid() && datetime
.IsValid(), wxT("invalid wxDateTime"));
1810 return m_time
== datetime
.m_time
;
1813 inline bool wxDateTime::IsEarlierThan(const wxDateTime
& datetime
) const
1815 wxASSERT_MSG( IsValid() && datetime
.IsValid(), wxT("invalid wxDateTime"));
1817 return m_time
< datetime
.m_time
;
1820 inline bool wxDateTime::IsLaterThan(const wxDateTime
& datetime
) const
1822 wxASSERT_MSG( IsValid() && datetime
.IsValid(), wxT("invalid wxDateTime"));
1824 return m_time
> datetime
.m_time
;
1827 inline bool wxDateTime::IsStrictlyBetween(const wxDateTime
& t1
,
1828 const wxDateTime
& t2
) const
1830 // no need for assert, will be checked by the functions we call
1831 return IsLaterThan(t1
) && IsEarlierThan(t2
);
1834 inline bool wxDateTime::IsBetween(const wxDateTime
& t1
,
1835 const wxDateTime
& t2
) const
1837 // no need for assert, will be checked by the functions we call
1838 return IsEqualTo(t1
) || IsEqualTo(t2
) || IsStrictlyBetween(t1
, t2
);
1841 inline bool wxDateTime::IsSameDate(const wxDateTime
& dt
) const
1846 return tm1
.year
== tm2
.year
&&
1847 tm1
.mon
== tm2
.mon
&&
1848 tm1
.mday
== tm2
.mday
;
1851 inline bool wxDateTime::IsSameTime(const wxDateTime
& dt
) const
1853 // notice that we can't do something like this:
1855 // m_time % MILLISECONDS_PER_DAY == dt.m_time % MILLISECONDS_PER_DAY
1857 // because we have also to deal with (possibly) different DST settings!
1861 return tm1
.hour
== tm2
.hour
&&
1862 tm1
.min
== tm2
.min
&&
1863 tm1
.sec
== tm2
.sec
&&
1864 tm1
.msec
== tm2
.msec
;
1867 inline bool wxDateTime::IsEqualUpTo(const wxDateTime
& dt
,
1868 const wxTimeSpan
& ts
) const
1870 return IsBetween(dt
.Subtract(ts
), dt
.Add(ts
));
1873 // ----------------------------------------------------------------------------
1874 // wxDateTime arithmetics
1875 // ----------------------------------------------------------------------------
1877 inline wxDateTime
wxDateTime::Add(const wxTimeSpan
& diff
) const
1879 wxASSERT_MSG( IsValid(), wxT("invalid wxDateTime"));
1881 return wxDateTime(m_time
+ diff
.GetValue());
1884 inline wxDateTime
& wxDateTime::Add(const wxTimeSpan
& diff
)
1886 wxASSERT_MSG( IsValid(), wxT("invalid wxDateTime"));
1888 m_time
+= diff
.GetValue();
1893 inline wxDateTime
& wxDateTime::operator+=(const wxTimeSpan
& diff
)
1898 inline wxDateTime
wxDateTime::Subtract(const wxTimeSpan
& diff
) const
1900 wxASSERT_MSG( IsValid(), wxT("invalid wxDateTime"));
1902 return wxDateTime(m_time
- diff
.GetValue());
1905 inline wxDateTime
& wxDateTime::Subtract(const wxTimeSpan
& diff
)
1907 wxASSERT_MSG( IsValid(), wxT("invalid wxDateTime"));
1909 m_time
-= diff
.GetValue();
1914 inline wxDateTime
& wxDateTime::operator-=(const wxTimeSpan
& diff
)
1916 return Subtract(diff
);
1919 inline wxTimeSpan
wxDateTime::Subtract(const wxDateTime
& datetime
) const
1921 wxASSERT_MSG( IsValid() && datetime
.IsValid(), wxT("invalid wxDateTime"));
1923 return wxTimeSpan(GetValue() - datetime
.GetValue());
1926 inline wxTimeSpan
wxDateTime::operator-(const wxDateTime
& dt2
) const
1928 return this->Subtract(dt2
);
1931 inline wxDateTime
wxDateTime::Add(const wxDateSpan
& diff
) const
1933 return wxDateTime(*this).Add(diff
);
1936 inline wxDateTime
& wxDateTime::Subtract(const wxDateSpan
& diff
)
1938 return Add(diff
.Negate());
1941 inline wxDateTime
wxDateTime::Subtract(const wxDateSpan
& diff
) const
1943 return wxDateTime(*this).Subtract(diff
);
1946 inline wxDateTime
& wxDateTime::operator-=(const wxDateSpan
& diff
)
1948 return Subtract(diff
);
1951 inline wxDateTime
& wxDateTime::operator+=(const wxDateSpan
& diff
)
1956 // ----------------------------------------------------------------------------
1957 // wxDateTime and timezones
1958 // ----------------------------------------------------------------------------
1961 wxDateTime::ToTimezone(const wxDateTime::TimeZone
& tz
, bool noDST
) const
1963 MODIFY_AND_RETURN( MakeTimezone(tz
, noDST
) );
1967 wxDateTime::FromTimezone(const wxDateTime::TimeZone
& tz
, bool noDST
) const
1969 MODIFY_AND_RETURN( MakeFromTimezone(tz
, noDST
) );
1972 // ----------------------------------------------------------------------------
1973 // wxTimeSpan construction
1974 // ----------------------------------------------------------------------------
1976 inline wxTimeSpan::wxTimeSpan(long hours
,
1979 wxLongLong milliseconds
)
1981 // assign first to avoid precision loss
1988 m_diff
+= milliseconds
;
1991 // ----------------------------------------------------------------------------
1992 // wxTimeSpan accessors
1993 // ----------------------------------------------------------------------------
1995 inline wxLongLong
wxTimeSpan::GetSeconds() const
1997 return m_diff
/ 1000l;
2000 inline int wxTimeSpan::GetMinutes() const
2002 // For compatibility, this method (and the other accessors) return int,
2003 // even though GetLo() actually returns unsigned long with greater range.
2004 return static_cast<int>((GetSeconds() / 60l).GetLo());
2007 inline int wxTimeSpan::GetHours() const
2009 return GetMinutes() / 60;
2012 inline int wxTimeSpan::GetDays() const
2014 return GetHours() / 24;
2017 inline int wxTimeSpan::GetWeeks() const
2019 return GetDays() / 7;
2022 // ----------------------------------------------------------------------------
2023 // wxTimeSpan arithmetics
2024 // ----------------------------------------------------------------------------
2026 inline wxTimeSpan
wxTimeSpan::Add(const wxTimeSpan
& diff
) const
2028 return wxTimeSpan(m_diff
+ diff
.GetValue());
2031 inline wxTimeSpan
& wxTimeSpan::Add(const wxTimeSpan
& diff
)
2033 m_diff
+= diff
.GetValue();
2038 inline wxTimeSpan
wxTimeSpan::Subtract(const wxTimeSpan
& diff
) const
2040 return wxTimeSpan(m_diff
- diff
.GetValue());
2043 inline wxTimeSpan
& wxTimeSpan::Subtract(const wxTimeSpan
& diff
)
2045 m_diff
-= diff
.GetValue();
2050 inline wxTimeSpan
& wxTimeSpan::Multiply(int n
)
2057 inline wxTimeSpan
wxTimeSpan::Multiply(int n
) const
2059 return wxTimeSpan(m_diff
* (long)n
);
2062 inline wxTimeSpan
wxTimeSpan::Abs() const
2064 return wxTimeSpan(GetValue().Abs());
2067 inline bool wxTimeSpan::IsEqualTo(const wxTimeSpan
& ts
) const
2069 return GetValue() == ts
.GetValue();
2072 inline bool wxTimeSpan::IsLongerThan(const wxTimeSpan
& ts
) const
2074 return GetValue().Abs() > ts
.GetValue().Abs();
2077 inline bool wxTimeSpan::IsShorterThan(const wxTimeSpan
& ts
) const
2079 return GetValue().Abs() < ts
.GetValue().Abs();
2082 // ----------------------------------------------------------------------------
2084 // ----------------------------------------------------------------------------
2086 inline wxDateSpan
& wxDateSpan::operator+=(const wxDateSpan
& other
)
2088 m_years
+= other
.m_years
;
2089 m_months
+= other
.m_months
;
2090 m_weeks
+= other
.m_weeks
;
2091 m_days
+= other
.m_days
;
2096 inline wxDateSpan
& wxDateSpan::Add(const wxDateSpan
& other
)
2098 return *this += other
;
2101 inline wxDateSpan
wxDateSpan::Add(const wxDateSpan
& other
) const
2103 wxDateSpan
ds(*this);
2108 inline wxDateSpan
& wxDateSpan::Multiply(int factor
)
2118 inline wxDateSpan
wxDateSpan::Multiply(int factor
) const
2120 wxDateSpan
ds(*this);
2121 ds
.Multiply(factor
);
2125 inline wxDateSpan
wxDateSpan::Negate() const
2127 return wxDateSpan(-m_years
, -m_months
, -m_weeks
, -m_days
);
2130 inline wxDateSpan
& wxDateSpan::Neg()
2133 m_months
= -m_months
;
2140 inline wxDateSpan
& wxDateSpan::operator-=(const wxDateSpan
& other
)
2142 return *this += other
.Negate();
2145 inline wxDateSpan
& wxDateSpan::Subtract(const wxDateSpan
& other
)
2147 return *this -= other
;
2150 inline wxDateSpan
wxDateSpan::Subtract(const wxDateSpan
& other
) const
2152 wxDateSpan
ds(*this);
2157 #undef MILLISECONDS_PER_DAY
2159 #undef MODIFY_AND_RETURN
2161 // ============================================================================
2163 // ============================================================================
2165 // ----------------------------------------------------------------------------
2166 // wxTimeSpan operators
2167 // ----------------------------------------------------------------------------
2169 wxTimeSpan WXDLLIMPEXP_BASE
operator*(int n
, const wxTimeSpan
& ts
);
2171 // ----------------------------------------------------------------------------
2173 // ----------------------------------------------------------------------------
2175 wxDateSpan WXDLLIMPEXP_BASE
operator*(int n
, const wxDateSpan
& ds
);
2177 // ============================================================================
2178 // other helper functions
2179 // ============================================================================
2181 // ----------------------------------------------------------------------------
2182 // iteration helpers: can be used to write a for loop over enum variable like
2184 // for ( m = wxDateTime::Jan; m < wxDateTime::Inv_Month; wxNextMonth(m) )
2185 // ----------------------------------------------------------------------------
2187 WXDLLIMPEXP_BASE
void wxNextMonth(wxDateTime::Month
& m
);
2188 WXDLLIMPEXP_BASE
void wxPrevMonth(wxDateTime::Month
& m
);
2189 WXDLLIMPEXP_BASE
void wxNextWDay(wxDateTime::WeekDay
& wd
);
2190 WXDLLIMPEXP_BASE
void wxPrevWDay(wxDateTime::WeekDay
& wd
);
2192 #endif // wxUSE_DATETIME
2194 #endif // _WX_DATETIME_H