1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: SWIG interface for wxDateTime and etc.
7 // Created: 25-Nov-1998
9 // Copyright: (c) 2003 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
16 //---------------------------------------------------------------------------
20 #include <wx/datetime.h>
22 DECLARE_DEF_STRING2(DateFormatStr, wxT("%c"));
23 DECLARE_DEF_STRING2(TimeSpanFormatStr, wxT("%H:%M:%S"));
27 //---------------------------------------------------------------------------
30 %typemap(in) wxDateTime::TimeZone& (bool temp=False) {
31 $1 = new wxDateTime::TimeZone((wxDateTime::TZ)PyInt_AsLong($input));
34 %typemap(python,freearg) wxDateTime::TimeZone& {
35 if (temp$argnum) delete $1;
40 #define LOCAL_TZ wxDateTime::Local
44 // Convert a wxLongLong to a Python Long by getting the hi/lo dwords, then
45 // shifting and oring them together
46 %typemap(python, out) wxLongLong {
47 PyObject *hi, *lo, *shifter, *shifted;
48 hi = PyLong_FromLong( $1.GetHi() );
49 lo = PyLong_FromLong( $1.GetLo() );
50 shifter = PyLong_FromLong(32);
51 shifted = PyNumber_Lshift(hi, shifter);
52 $result = PyNumber_Or(shifted, lo);
60 //---------------------------------------------------------------------------
62 //typedef unsigned short wxDateTime_t;
63 #define wxDateTime_t int
65 // wxDateTime represents an absolute moment in the time
71 // the time in the current time zone
74 // zones from GMT (= Greenwhich Mean Time): they're guaranteed to be
75 // consequent numbers, so writing something like `GMT0 + offset' is
76 // safe if abs(offset) <= 12
77 // underscore stands for minus
78 GMT_12, GMT_11, GMT_10, GMT_9, GMT_8, GMT_7,
79 GMT_6, GMT_5, GMT_4, GMT_3, GMT_2, GMT_1,
81 GMT1, GMT2, GMT3, GMT4, GMT5, GMT6,
82 GMT7, GMT8, GMT9, GMT10, GMT11, GMT12,
85 WET = GMT0, // Western Europe Time
86 WEST = GMT1, // Western Europe Summer Time
87 CET = GMT1, // Central Europe Time
88 CEST = GMT2, // Central Europe Summer Time
89 EET = GMT2, // Eastern Europe Time
90 EEST = GMT3, // Eastern Europe Summer Time
91 MSK = GMT3, // Moscow Time
92 MSD = GMT4, // Moscow Summer Time
95 AST = GMT_4, // Atlantic Standard Time
96 ADT = GMT_3, // Atlantic Daylight Time
97 EST = GMT_5, // Eastern Standard Time
98 EDT = GMT_4, // Eastern Daylight Saving Time
99 CST = GMT_6, // Central Standard Time
100 CDT = GMT_5, // Central Daylight Saving Time
101 MST = GMT_7, // Mountain Standard Time
102 MDT = GMT_6, // Mountain Daylight Saving Time
103 PST = GMT_8, // Pacific Standard Time
104 PDT = GMT_7, // Pacific Daylight Saving Time
105 HST = GMT_10, // Hawaiian Standard Time
106 AKST = GMT_9, // Alaska Standard Time
107 AKDT = GMT_8, // Alaska Daylight Saving Time
111 A_WST = GMT8, // Western Standard Time
112 A_CST = GMT12 + 1, // Central Standard Time (+9.5)
113 A_EST = GMT10, // Eastern Standard Time
114 A_ESST = GMT11, // Eastern Summer Time
116 // Universal Coordinated Time = the new and politically correct name
122 // the calendar systems we know about: notice that it's valid (for
123 // this classes purpose anyhow) to work with any of these calendars
124 // even with the dates before the historical appearance of the
128 Gregorian, // current calendar
129 Julian // calendar in use since -45 until the 1582 (or later)
132 // these values only are used to identify the different dates of
133 // adoption of the Gregorian calendar (see IsGregorian())
135 // All data and comments taken verbatim from "The Calendar FAQ (v 2.0)"
136 // by Claus Tøndering, http://www.pip.dknet.dk/~c-t/calendar.html
137 // except for the comments "we take".
139 // Symbol "->" should be read as "was followed by" in the comments
141 enum GregorianAdoption
143 Gr_Unknown, // no data for this country or it's too uncertain to use
144 Gr_Standard, // on the day 0 of Gregorian calendar: 15 Oct 1582
146 Gr_Alaska, // Oct 1867 when Alaska became part of the USA
147 Gr_Albania, // Dec 1912
149 Gr_Austria = Gr_Unknown, // Different regions on different dates
150 Gr_Austria_Brixen, // 5 Oct 1583 -> 16 Oct 1583
151 Gr_Austria_Salzburg = Gr_Austria_Brixen,
152 Gr_Austria_Tyrol = Gr_Austria_Brixen,
153 Gr_Austria_Carinthia, // 14 Dec 1583 -> 25 Dec 1583
154 Gr_Austria_Styria = Gr_Austria_Carinthia,
156 Gr_Belgium, // Then part of the Netherlands
158 Gr_Bulgaria = Gr_Unknown, // Unknown precisely (from 1915 to 1920)
159 Gr_Bulgaria_1, // 18 Mar 1916 -> 1 Apr 1916
160 Gr_Bulgaria_2, // 31 Mar 1916 -> 14 Apr 1916
161 Gr_Bulgaria_3, // 3 Sep 1920 -> 17 Sep 1920
163 Gr_Canada = Gr_Unknown, // Different regions followed the changes in
164 // Great Britain or France
166 Gr_China = Gr_Unknown, // Different authorities say:
167 Gr_China_1, // 18 Dec 1911 -> 1 Jan 1912
168 Gr_China_2, // 18 Dec 1928 -> 1 Jan 1929
170 Gr_Czechoslovakia, // (Bohemia and Moravia) 6 Jan 1584 -> 17 Jan 1584
171 Gr_Denmark, // (including Norway) 18 Feb 1700 -> 1 Mar 1700
174 Gr_Finland, // Then part of Sweden
176 Gr_France, // 9 Dec 1582 -> 20 Dec 1582
177 Gr_France_Alsace, // 4 Feb 1682 -> 16 Feb 1682
178 Gr_France_Lorraine, // 16 Feb 1760 -> 28 Feb 1760
179 Gr_France_Strasbourg, // February 1682
181 Gr_Germany = Gr_Unknown, // Different states on different dates:
182 Gr_Germany_Catholic, // 1583-1585 (we take 1584)
183 Gr_Germany_Prussia, // 22 Aug 1610 -> 2 Sep 1610
184 Gr_Germany_Protestant, // 18 Feb 1700 -> 1 Mar 1700
186 Gr_GreatBritain, // 2 Sep 1752 -> 14 Sep 1752 (use 'cal(1)')
188 Gr_Greece, // 9 Mar 1924 -> 23 Mar 1924
189 Gr_Hungary, // 21 Oct 1587 -> 1 Nov 1587
190 Gr_Ireland = Gr_GreatBritain,
191 Gr_Italy = Gr_Standard,
193 Gr_Japan = Gr_Unknown, // Different authorities say:
194 Gr_Japan_1, // 19 Dec 1872 -> 1 Jan 1873
195 Gr_Japan_2, // 19 Dec 1892 -> 1 Jan 1893
196 Gr_Japan_3, // 18 Dec 1918 -> 1 Jan 1919
198 Gr_Latvia, // 1915-1918 (we take 1915)
199 Gr_Lithuania, // 1915
200 Gr_Luxemburg, // 14 Dec 1582 -> 25 Dec 1582
201 Gr_Netherlands = Gr_Belgium, // (including Belgium) 1 Jan 1583
203 // this is too weird to take into account: the Gregorian calendar was
204 // introduced twice in Groningen, first time 28 Feb 1583 was followed
205 // by 11 Mar 1583, then it has gone back to Julian in the summer of
206 // 1584 and then 13 Dec 1700 -> 12 Jan 1701 - which is
207 // the date we take here
208 Gr_Netherlands_Groningen, // 13 Dec 1700 -> 12 Jan 1701
209 Gr_Netherlands_Gelderland, // 30 Jun 1700 -> 12 Jul 1700
210 Gr_Netherlands_Utrecht, // (and Overijssel) 30 Nov 1700->12 Dec 1700
211 Gr_Netherlands_Friesland, // (and Drenthe) 31 Dec 1700 -> 12 Jan 1701
213 Gr_Norway = Gr_Denmark, // Then part of Denmark
214 Gr_Poland = Gr_Standard,
215 Gr_Portugal = Gr_Standard,
216 Gr_Romania, // 31 Mar 1919 -> 14 Apr 1919
217 Gr_Russia, // 31 Jan 1918 -> 14 Feb 1918
218 Gr_Scotland = Gr_GreatBritain,
219 Gr_Spain = Gr_Standard,
221 // Sweden has a curious history. Sweden decided to make a gradual
222 // change from the Julian to the Gregorian calendar. By dropping every
223 // leap year from 1700 through 1740 the eleven superfluous days would
224 // be omitted and from 1 Mar 1740 they would be in sync with the
225 // Gregorian calendar. (But in the meantime they would be in sync with
228 // So 1700 (which should have been a leap year in the Julian calendar)
229 // was not a leap year in Sweden. However, by mistake 1704 and 1708
230 // became leap years. This left Sweden out of synchronisation with
231 // both the Julian and the Gregorian world, so they decided to go back
232 // to the Julian calendar. In order to do this, they inserted an extra
233 // day in 1712, making that year a double leap year! So in 1712,
234 // February had 30 days in Sweden.
236 // Later, in 1753, Sweden changed to the Gregorian calendar by
237 // dropping 11 days like everyone else.
238 Gr_Sweden = Gr_Finland, // 17 Feb 1753 -> 1 Mar 1753
240 Gr_Switzerland = Gr_Unknown,// Different cantons used different dates
241 Gr_Switzerland_Catholic, // 1583, 1584 or 1597 (we take 1584)
242 Gr_Switzerland_Protestant, // 31 Dec 1700 -> 12 Jan 1701
244 Gr_Turkey, // 1 Jan 1927
245 Gr_USA = Gr_GreatBritain,
246 Gr_Wales = Gr_GreatBritain,
247 Gr_Yugoslavia // 1919
252 // the country parameter is used so far for calculating the start and
253 // the end of DST period and for deciding whether the date is a work
257 Country_Unknown, // no special information for this country
258 Country_Default, // set the default country with SetCountry() method
259 // or use the default country with any other
261 // Western European countries: we assume that they all follow the same
262 // DST rules (True or False?)
263 Country_WesternEurope_Start,
264 Country_EEC = Country_WesternEurope_Start,
268 Country_WesternEurope_End = UK,
275 // symbolic names for the months
278 Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec, Inv_Month
281 // symbolic names for the weekdays
284 Sun, Mon, Tue, Wed, Thu, Fri, Sat, Inv_WeekDay
287 // invalid value for the year
290 Inv_Year = SHRT_MIN // should hold in wxDateTime_t
293 // flags for GetWeekDayName and GetMonthName
296 Name_Full = 0x01, // return full name
297 Name_Abbr = 0x02 // return abbreviated name
300 // flags for GetWeekOfYear and GetWeekOfMonth
303 Default_First, // Sunday_First for US, Monday_First for the rest
304 Monday_First, // week starts with a Monday
305 Sunday_First // week starts with a Sunday
309 //** Nested class TimeZone is handled by a typemap instead
311 //** Is nested class Tm needed?
315 // ------------------------------------------------------------------------
317 // set the current country
318 static void SetCountry(Country country);
320 // get the current country
321 static Country GetCountry();
323 // return True if the country is a West European one (in practice,
324 // this means that the same DST rules as for EEC apply)
325 static bool IsWestEuropeanCountry(Country country = Country_Default);
327 // return the current year
328 static int GetCurrentYear(Calendar cal = Gregorian);
330 // convert the year as returned by wxDateTime::GetYear() to a year
331 // suitable for BC/AD notation. The difference is that BC year 1
332 // corresponds to the year 0 (while BC year 0 didn't exist) and AD
333 // year N is just year N.
334 static int ConvertYearToBC(int year);
336 // return the current month
337 static Month GetCurrentMonth(Calendar cal = Gregorian);
339 // returns True if the given year is a leap year in the given calendar
340 static bool IsLeapYear(int year = Inv_Year, Calendar cal = Gregorian);
342 // get the century (19 for 1999, 20 for 2000 and -5 for 492 BC)
343 static int GetCentury(int year = Inv_Year);
345 // returns the number of days in this year (356 or 355 for Gregorian
346 // calendar usually :-)
347 %name(GetNumberOfDaysinYear)
348 static wxDateTime_t GetNumberOfDays(int year, Calendar cal = Gregorian);
350 // get the number of the days in the given month (default value for
351 // the year means the current one)
352 %name(GetNumberOfDaysInMonth)
353 static wxDateTime_t GetNumberOfDays(Month month,
355 Calendar cal = Gregorian);
357 // get the full (default) or abbreviated month name in the current
358 // locale, returns empty string on error
359 static wxString GetMonthName(Month month,
360 NameFlags flags = Name_Full);
362 // get the full (default) or abbreviated weekday name in the current
363 // locale, returns empty string on error
364 static wxString GetWeekDayName(WeekDay weekday,
365 NameFlags flags = Name_Full);
368 static void, GetAmPmStrings(wxString *OUTPUT, wxString *OUTPUT),
369 "GetAmPmStrings() -> (am, pm)",
370 "Get the AM and PM strings in the current locale (may be empty)");
372 // return True if the given country uses DST for this year
373 static bool IsDSTApplicable(int year = Inv_Year,
374 Country country = Country_Default);
376 // get the beginning of DST for this year, will return invalid object
377 // if no DST applicable in this year. The default value of the
378 // parameter means to take the current year.
379 static wxDateTime GetBeginDST(int year = Inv_Year,
380 Country country = Country_Default);
381 // get the end of DST for this year, will return invalid object
382 // if no DST applicable in this year. The default value of the
383 // parameter means to take the current year.
384 static wxDateTime GetEndDST(int year = Inv_Year,
385 Country country = Country_Default);
387 // return the wxDateTime object for the current time
388 static inline wxDateTime Now();
390 // return the wxDateTime object for the current time with millisecond
391 // precision (if available on this platform)
392 static wxDateTime UNow();
394 // return the wxDateTime object for today midnight: i.e. as Now() but
395 // with time set to 0
396 static inline wxDateTime Today();
400 // ------------------------------------------------------------------------
404 %name(DateTimeFromTimeT)wxDateTime(time_t timet);
405 %name(DateTimeFromJDN)wxDateTime(double jdn);
406 %name(DateTimeFromHMS)wxDateTime(wxDateTime_t hour,
407 wxDateTime_t minute = 0,
408 wxDateTime_t second = 0,
409 wxDateTime_t millisec = 0);
410 %name(DateTimeFromDMY)wxDateTime(wxDateTime_t day,
411 Month month = Inv_Month,
413 wxDateTime_t hour = 0,
414 wxDateTime_t minute = 0,
415 wxDateTime_t second = 0,
416 wxDateTime_t millisec = 0);
420 // ------------------------------------------------------------------------
423 wxDateTime& SetToCurrent();
425 // set to given time_t value
426 %name(SetTimeT)wxDateTime& Set(time_t timet);
428 // set to given JDN (beware of rounding errors)
429 %name(SetJDN)wxDateTime& Set(double jdn);
431 // set to given time, date = today
432 %name(SetHMS)wxDateTime& Set(wxDateTime_t hour,
433 wxDateTime_t minute = 0,
434 wxDateTime_t second = 0,
435 wxDateTime_t millisec = 0);
437 // from separate values for each component with explicit date
438 // (defaults for month and year are the current values)
439 wxDateTime& Set(wxDateTime_t day,
440 Month month = Inv_Month,
441 int year = Inv_Year, // 1999, not 99 please!
442 wxDateTime_t hour = 0,
443 wxDateTime_t minute = 0,
444 wxDateTime_t second = 0,
445 wxDateTime_t millisec = 0);
447 // resets time to 00:00:00, doesn't change the date
448 wxDateTime& ResetTime();
450 // the following functions don't change the values of the other
451 // fields, i.e. SetMinute() won't change either hour or seconds value
454 wxDateTime& SetYear(int year);
456 wxDateTime& SetMonth(Month month);
457 // set the day of the month
458 wxDateTime& SetDay(wxDateTime_t day);
460 wxDateTime& SetHour(wxDateTime_t hour);
462 wxDateTime& SetMinute(wxDateTime_t minute);
464 wxDateTime& SetSecond(wxDateTime_t second);
466 wxDateTime& SetMillisecond(wxDateTime_t millisecond);
469 // ------------------------------------------------------------------------
470 // calendar calculations
472 // set to the given week day in the same week as this one
473 wxDateTime& SetToWeekDayInSameWeek(WeekDay weekday, WeekFlags flags = Monday_First);
474 wxDateTime GetWeekDayInSameWeek(WeekDay weekday, WeekFlags flags = Monday_First);
476 // set to the next week day following this one
477 wxDateTime& SetToNextWeekDay(WeekDay weekday);
478 wxDateTime GetNextWeekDay(WeekDay weekday);
480 // set to the previous week day before this one
481 wxDateTime& SetToPrevWeekDay(WeekDay weekday);
482 wxDateTime GetPrevWeekDay(WeekDay weekday);
484 // set to Nth occurence of given weekday in the given month of the
485 // given year (time is set to 0), return True on success and False on
486 // failure. n may be positive (1..5) or negative to count from the end
487 // of the month (see helper function SetToLastWeekDay())
488 bool SetToWeekDay(WeekDay weekday,
490 Month month = Inv_Month,
491 int year = Inv_Year);
492 // wxDateTime GetWeekDay(WeekDay weekday,
494 // Month month = Inv_Month,
495 // int year = Inv_Year);
497 // sets to the last weekday in the given month, year
498 bool SetToLastWeekDay(WeekDay weekday,
499 Month month = Inv_Month,
500 int year = Inv_Year);
501 wxDateTime GetLastWeekDay(WeekDay weekday,
502 Month month = Inv_Month,
503 int year = Inv_Year);
505 // sets the date to the given day of the given week in the year,
506 // returns True on success and False if given date doesn't exist (e.g.
508 bool SetToTheWeek(wxDateTime_t numWeek, WeekDay weekday = Mon, WeekFlags flags = Monday_First);
509 wxDateTime GetWeek(wxDateTime_t numWeek, WeekDay weekday = Mon, WeekFlags flags = Monday_First);
511 // sets the date to the last day of the given (or current) month or the
512 // given (or current) year
513 wxDateTime& SetToLastMonthDay(Month month = Inv_Month,
514 int year = Inv_Year);
515 wxDateTime GetLastMonthDay(Month month = Inv_Month,
516 int year = Inv_Year);
518 // sets to the given year day (1..365 or 366)
519 wxDateTime& SetToYearDay(wxDateTime_t yday);
520 wxDateTime GetYearDay(wxDateTime_t yday);
522 // The definitions below were taken verbatim from
524 // http://www.capecod.net/~pbaum/date/date0.htm
526 // (Peter Baum's home page)
528 // definition: The Julian Day Number, Julian Day, or JD of a
529 // particular instant of time is the number of days and fractions of a
530 // day since 12 hours Universal Time (Greenwich mean noon) on January
531 // 1 of the year -4712, where the year is given in the Julian
532 // proleptic calendar. The idea of using this reference date was
533 // originally proposed by Joseph Scalizer in 1582 to count years but
534 // it was modified by 19th century astronomers to count days. One
535 // could have equivalently defined the reference time to be noon of
536 // November 24, -4713 if were understood that Gregorian calendar rules
537 // were applied. Julian days are Julian Day Numbers and are not to be
538 // confused with Julian dates.
540 // definition: The Rata Die number is a date specified as the number
541 // of days relative to a base date of December 31 of the year 0. Thus
542 // January 1 of the year 1 is Rata Die day 1.
544 // get the Julian Day number (the fractional part specifies the time of
545 // the day, related to noon - beware of rounding errors!)
546 double GetJulianDayNumber();
549 // get the Modified Julian Day number: it is equal to JDN - 2400000.5
550 // and so integral MJDs correspond to the midnights (and not noons).
551 // MJD 0 is Nov 17, 1858
552 double GetModifiedJulianDayNumber() const { return GetJDN() - 2400000.5; }
555 // get the Rata Die number
559 // ------------------------------------------------------------------------
562 // transform to any given timezone
563 wxDateTime ToTimezone(const wxDateTime::TimeZone& tz, bool noDST = False);
564 wxDateTime& MakeTimezone(const wxDateTime::TimeZone& tz, bool noDST = False);
566 // transform to GMT/UTC
567 wxDateTime ToGMT(bool noDST = False);
568 wxDateTime& MakeGMT(bool noDST = False);
570 // is daylight savings time in effect at this moment according to the
571 // rules of the specified country?
573 // Return value is > 0 if DST is in effect, 0 if it is not and -1 if
574 // the information is not available (this is compatible with ANSI C)
575 int IsDST(Country country = Country_Default);
579 // ------------------------------------------------------------------------
582 // is the date valid (True even for non initialized objects)?
583 inline bool IsValid() const;
585 // get the number of seconds since the Unix epoch - returns (time_t)-1
586 // if the value is out of range
587 inline time_t GetTicks() const;
589 // get the year (returns Inv_Year if date is invalid)
590 int GetYear(const wxDateTime::TimeZone& tz = LOCAL_TZ) const;
592 // get the month (Inv_Month if date is invalid)
593 Month GetMonth(const wxDateTime::TimeZone& tz = LOCAL_TZ) const;
595 // get the month day (in 1..31 range, 0 if date is invalid)
596 wxDateTime_t GetDay(const wxDateTime::TimeZone& tz = LOCAL_TZ) const;
598 // get the day of the week (Inv_WeekDay if date is invalid)
599 WeekDay GetWeekDay(const wxDateTime::TimeZone& tz = LOCAL_TZ) const;
601 // get the hour of the day
602 wxDateTime_t GetHour(const wxDateTime::TimeZone& tz = LOCAL_TZ) const;
605 wxDateTime_t GetMinute(const wxDateTime::TimeZone& tz = LOCAL_TZ) const;
608 wxDateTime_t GetSecond(const wxDateTime::TimeZone& tz = LOCAL_TZ) const;
611 wxDateTime_t GetMillisecond(const wxDateTime::TimeZone& tz = LOCAL_TZ) const;
614 // get the day since the year start (1..366, 0 if date is invalid)
615 wxDateTime_t GetDayOfYear(const wxDateTime::TimeZone& tz = LOCAL_TZ) const;
616 // get the week number since the year start (1..52 or 53, 0 if date is
618 wxDateTime_t GetWeekOfYear(WeekFlags flags = Monday_First,
619 const wxDateTime::TimeZone& tz = LOCAL_TZ) const;
620 // get the week number since the month start (1..5, 0 if date is
622 wxDateTime_t GetWeekOfMonth(WeekFlags flags = Monday_First,
623 const wxDateTime::TimeZone& tz = LOCAL_TZ) const;
625 // is this date a work day? This depends on a country, of course,
626 // because the holidays are different in different countries
627 bool IsWorkDay(Country country = Country_Default) const;
629 // is this date later than Gregorian calendar introduction for the
630 // given country (see enum GregorianAdoption)?
632 // NB: this function shouldn't be considered as absolute authority in
633 // the matter. Besides, for some countries the exact date of
634 // adoption of the Gregorian calendar is simply unknown.
635 // bool IsGregorianDate(GregorianAdoption country = Gr_Standard) const;
638 // ------------------------------------------------------------------------
639 // comparison (see also functions below for operator versions)
641 // returns True if the two moments are strictly identical
642 inline bool IsEqualTo(const wxDateTime& datetime) const;
644 // returns True if the date is strictly earlier than the given one
645 inline bool IsEarlierThan(const wxDateTime& datetime) const;
647 // returns True if the date is strictly later than the given one
648 inline bool IsLaterThan(const wxDateTime& datetime) const;
650 // returns True if the date is strictly in the given range
651 inline bool IsStrictlyBetween(const wxDateTime& t1,
652 const wxDateTime& t2) const;
654 // returns True if the date is in the given range
655 inline bool IsBetween(const wxDateTime& t1, const wxDateTime& t2) const;
657 // do these two objects refer to the same date?
658 inline bool IsSameDate(const wxDateTime& dt) const;
660 // do these two objects have the same time?
661 inline bool IsSameTime(const wxDateTime& dt) const;
663 // are these two objects equal up to given timespan?
664 inline bool IsEqualUpTo(const wxDateTime& dt, const wxTimeSpan& ts) const;
667 // ------------------------------------------------------------------------
668 // arithmetics with dates (see also below for more operators)
670 // add a time span (positive or negative)
671 %name(AddTS) wxDateTime& Add(const wxTimeSpan& diff);
672 // add a date span (positive or negative)
673 %name(AddDS) wxDateTime& Add(const wxDateSpan& diff);
675 // subtract a time span (positive or negative)
676 %name(SubtractTS) wxDateTime& Subtract(const wxTimeSpan& diff);
678 // subtract a date span (positive or negative)
679 %name(SubtractDS) wxDateTime& Subtract(const wxDateSpan& diff);
681 // return the difference between two dates
682 wxTimeSpan Subtract(const wxDateTime& dt) const;
685 %nokwargs operator+=;
686 // add a time span (positive or negative)
687 inline wxDateTime& operator+=(const wxTimeSpan& diff);
688 // add a date span (positive or negative)
689 inline wxDateTime& operator+=(const wxDateSpan& diff);
691 %nokwargs operator-=;
692 // subtract a time span (positive or negative)
693 inline wxDateTime& operator-=(const wxTimeSpan& diff);
694 // subtract a date span (positive or negative)
695 inline wxDateTime& operator-=(const wxDateSpan& diff);
707 wxDateTime __add__(const wxTimeSpan& other) { return *self + other; }
708 wxDateTime __add__(const wxDateSpan& other) { return *self + other; }
710 wxTimeSpan __sub__(const wxDateTime& other) { return *self - other; }
711 wxDateTime __sub__(const wxTimeSpan& other) { return *self - other; }
712 wxDateTime __sub__(const wxDateSpan& other) { return *self - other; }
714 bool __lt__(const wxDateTime& other) { return *self < other; }
715 bool __le__(const wxDateTime& other) { return *self <= other; }
716 bool __gt__(const wxDateTime& other) { return *self > other; }
717 bool __ge__(const wxDateTime& other) { return *self >= other; }
718 bool __eq__(const wxDateTime& other) { return *self == other; }
719 bool __ne__(const wxDateTime& other) { return *self != other; }
723 // ------------------------------------------------------------------------
724 // conversion from text: all conversions from text return -1 on failure,
725 // or the index in the string where the next character following the date
726 // specification (i.e. the one where the scan had to stop) is located.
730 // parse a string in RFC 822 format (found e.g. in mail headers and
731 // having the form "Wed, 10 Feb 1999 19:07:07 +0100")
732 int ParseRfc822Date(const wxString& date) {
734 const wxChar* _date = date;
735 rv = self->ParseRfc822Date(_date);
736 if (rv == NULL) return -1;
741 // parse a date/time in the given format (see strptime(3)), fill in
742 // the missing (in the string) fields with the values of dateDef (by
743 // default, they will not change if they had valid values or will
744 // default to Today() otherwise)
745 int ParseFormat(const wxString& date,
746 const wxString& format = wxPyDateFormatStr,
747 const wxDateTime& dateDef = wxDefaultDateTime) {
749 const wxChar* _date = date;
750 rv = self->ParseFormat(_date, format, dateDef);
751 if (rv == NULL) return -1;
755 // parse a string containing the date/time in "free" format, this
756 // function will try to make an educated guess at the string contents
757 int ParseDateTime(const wxString& datetime) {
759 const wxChar* _datetime = datetime;
760 rv = self->ParseDateTime(_datetime);
761 if (rv == NULL) return -1;
762 return rv - _datetime;
766 // parse a string containing the date only in "free" format (less
767 // flexible than ParseDateTime)
768 int ParseDate(const wxString& date) {
770 const wxChar* _date = date;
771 rv = self->ParseDate(_date);
772 if (rv == NULL) return -1;
776 // parse a string containing the time only in "free" format
777 int ParseTime(const wxString& time) {
779 const wxChar* _time = time;
780 rv = self->ParseTime(_time);
781 if (rv == NULL) return -1;
787 // this function accepts strftime()-like format string (default
788 // argument corresponds to the preferred date and time representation
789 // for the current locale) and returns the string containing the
790 // resulting text representation
791 wxString Format(const wxString& format = wxPyDateFormatStr,
792 const wxDateTime::TimeZone& tz = LOCAL_TZ) const;
794 // preferred date representation for the current locale
795 wxString FormatDate() const;
797 // preferred time representation for the current locale
798 wxString FormatTime() const;
800 // returns the string representing the date in ISO 8601 format
802 wxString FormatISODate() const;
804 // returns the string representing the time in ISO 8601 format
806 wxString FormatISOTime() const;
810 return '<wxDateTime: \"%s\" at %s>' % ( self.Format(), self.this)
816 //---------------------------------------------------------------------------
817 //---------------------------------------------------------------------------
820 // This class contains a difference between 2 wxDateTime values, so it makes
821 // sense to add it to wxDateTime and it is the result of subtraction of 2
822 // objects of that class. See also wxDateSpan.
827 // return the timespan for the given number of seconds
828 static wxTimeSpan Seconds(long sec);
829 static wxTimeSpan Second();
831 // return the timespan for the given number of minutes
832 static wxTimeSpan Minutes(long min);
833 static wxTimeSpan Minute();
835 // return the timespan for the given number of hours
836 static wxTimeSpan Hours(long hours);
837 static wxTimeSpan Hour();
839 // return the timespan for the given number of days
840 static wxTimeSpan Days(long days);
841 static wxTimeSpan Day();
843 // return the timespan for the given number of weeks
844 static wxTimeSpan Weeks(long days);
845 static wxTimeSpan Week();
847 // ------------------------------------------------------------------------
850 // from separate values for each component, date set to 0 (hours are
851 // not restricted to 0..24 range, neither are minutes, seconds or
853 wxTimeSpan(long hours = 0,
856 long milliseconds = 0);
860 // ------------------------------------------------------------------------
861 // arithmetics with time spans
863 // add two timespans together
864 inline wxTimeSpan& Add(const wxTimeSpan& diff);
866 // subtract another timespan
867 inline wxTimeSpan& Subtract(const wxTimeSpan& diff);
869 // multiply timespan by a scalar
870 inline wxTimeSpan& Multiply(int n);
872 // negate the value of the timespan
875 // return the absolute value of the timespan: does _not_ modify the
877 inline wxTimeSpan Abs() const;
880 wxTimeSpan& operator+=(const wxTimeSpan& diff);
881 wxTimeSpan& operator-=(const wxTimeSpan& diff);
882 wxTimeSpan& operator*=(int n);
883 wxTimeSpan& operator-();
886 wxTimeSpan __add__(const wxTimeSpan& other) { return *self + other; }
887 wxTimeSpan __sub__(const wxTimeSpan& other) { return *self - other; }
888 wxTimeSpan __mul__(int n) { return *self * n; }
889 wxTimeSpan __rmul__(int n) { return n * *self; }
890 bool __lt__(const wxTimeSpan& other) { return *self < other; }
891 bool __le__(const wxTimeSpan& other) { return *self <= other; }
892 bool __gt__(const wxTimeSpan& other) { return *self > other; }
893 bool __ge__(const wxTimeSpan& other) { return *self >= other; }
894 bool __eq__(const wxTimeSpan& other) { return *self == other; }
895 bool __ne__(const wxTimeSpan& other) { return *self != other; }
900 // ------------------------------------------------------------------------
902 // is the timespan null?
905 // is the timespan positive?
906 bool IsPositive() const;
908 // is the timespan negative?
909 bool IsNegative() const;
911 // are two timespans equal?
912 inline bool IsEqualTo(const wxTimeSpan& ts) const;
914 // compare two timestamps: works with the absolute values, i.e. -2
915 // hours is longer than 1 hour. Also, it will return False if the
916 // timespans are equal in absolute value.
917 inline bool IsLongerThan(const wxTimeSpan& ts) const;
919 // compare two timestamps: works with the absolute values, i.e. 1
920 // hour is shorter than -2 hours. Also, it will return False if the
921 // timespans are equal in absolute value.
922 bool IsShorterThan(const wxTimeSpan& t) const;
924 // ------------------------------------------------------------------------
925 // breaking into days, hours, minutes and seconds
927 // get the max number of weeks in this timespan
928 inline int GetWeeks() const;
929 // get the max number of days in this timespan
930 inline int GetDays() const;
931 // get the max number of hours in this timespan
932 inline int GetHours() const;
933 // get the max number of minutes in this timespan
934 inline int GetMinutes() const;
937 // get the max number of seconds in this timespan
938 inline wxLongLong GetSeconds() const;
939 // get the number of milliseconds in this timespan
940 wxLongLong GetMilliseconds() const;
942 // ------------------------------------------------------------------------
943 // conversion to text
945 // this function accepts strftime()-like format string (default
946 // argument corresponds to the preferred date and time representation
947 // for the current locale) and returns the string containing the
948 // resulting text representation. Notice that only some of format
949 // specifiers valid for wxDateTime are valid for wxTimeSpan: hours,
950 // minutes and seconds make sense, but not "PM/AM" string for example.
951 wxString Format(const wxString& format = wxPyTimeSpanFormatStr) const;
955 return '<wxTimeSpan: \"%s\" at %s>' % ( self.Format(), self.this)
962 //---------------------------------------------------------------------------
963 //---------------------------------------------------------------------------
965 // This class is a "logical time span" and is useful for implementing program
966 // logic for such things as "add one month to the date" which, in general,
967 // doesn't mean to add 60*60*24*31 seconds to it, but to take the same date
968 // the next month (to understand that this is indeed different consider adding
969 // one month to Feb, 15 - we want to get Mar, 15, of course).
971 // When adding a month to the date, all lesser components (days, hours, ...)
972 // won't be changed unless the resulting date would be invalid: for example,
973 // Jan 31 + 1 month will be Feb 28, not (non existing) Feb 31.
975 // Because of this feature, adding and subtracting back again the same
976 // wxDateSpan will *not*, in general give back the original date: Feb 28 - 1
977 // month will be Jan 28, not Jan 31!
979 // wxDateSpan can be either positive or negative. They may be
980 // multiplied by scalars which multiply all deltas by the scalar: i.e. 2*(1
981 // month and 1 day) is 2 months and 2 days. They can be added together and
982 // with wxDateTime or wxTimeSpan, but the type of result is different for each
985 // Beware about weeks: if you specify both weeks and days, the total number of
986 // days added will be 7*weeks + days! See also GetTotalDays() function.
988 // Equality operators are defined for wxDateSpans. Two datespans are equal if
989 // they both give the same target date when added to *every* source date.
990 // Thus wxDateSpan::Months(1) is not equal to wxDateSpan::Days(30), because
991 // they not give the same date when added to 1 Feb. But wxDateSpan::Days(14) is
992 // equal to wxDateSpan::Weeks(2)
994 // Finally, notice that for adding hours, minutes &c you don't need this
995 // class: wxTimeSpan will do the job because there are no subtleties
996 // associated with those.
1000 // this many years/months/weeks/days
1001 wxDateSpan(int years = 0, int months = 0, int weeks = 0, int days = 0)
1011 // get an object for the given number of days
1012 static wxDateSpan Days(int days);
1013 static wxDateSpan Day();
1015 // get an object for the given number of weeks
1016 static wxDateSpan Weeks(int weeks);
1017 static wxDateSpan Week();
1019 // get an object for the given number of months
1020 static wxDateSpan Months(int mon);
1021 static wxDateSpan Month();
1023 // get an object for the given number of years
1024 static wxDateSpan Years(int years);
1025 static wxDateSpan Year();
1028 // ------------------------------------------------------------------------
1030 // set number of years
1031 wxDateSpan& SetYears(int n);
1032 // set number of months
1033 wxDateSpan& SetMonths(int n);
1034 // set number of weeks
1035 wxDateSpan& SetWeeks(int n);
1036 // set number of days
1037 wxDateSpan& SetDays(int n);
1039 // get number of years
1040 int GetYears() const;
1041 // get number of months
1042 int GetMonths() const;
1043 // get number of weeks
1044 int GetWeeks() const;
1045 // get number of days
1046 int GetDays() const;
1047 // returns 7*GetWeeks() + GetDays()
1048 int GetTotalDays() const;
1051 // ------------------------------------------------------------------------
1053 // add another wxDateSpan to us
1054 inline wxDateSpan& Add(const wxDateSpan& other);
1056 // subtract another wxDateSpan from us
1057 inline wxDateSpan& Subtract(const wxDateSpan& other);
1059 // inverse the sign of this timespan
1060 inline wxDateSpan& Neg();
1062 // multiply all components by a (signed) number
1063 inline wxDateSpan& Multiply(int factor);
1065 inline wxDateSpan& operator+=(const wxDateSpan& other);
1066 inline wxDateSpan& operator-=(const wxDateSpan& other);
1067 wxDateSpan& operator-() { return Neg(); }
1068 inline wxDateSpan& operator*=(int factor) { return Multiply(factor); }
1071 wxDateSpan __add__(const wxDateSpan& other) { return *self + other; }
1072 wxDateSpan __sub__(const wxDateSpan& other) { return *self - other; }
1073 wxDateSpan __mul__(int n) { return *self * n; }
1074 wxDateSpan __rmul__(int n) { return n * *self; }
1075 // bool __lt__(const wxDateSpan& other) { return *self < other; }
1076 // bool __le__(const wxDateSpan& other) { return *self <= other; }
1077 // bool __gt__(const wxDateSpan& other) { return *self > other; }
1078 // bool __ge__(const wxDateSpan& other) { return *self >= other; }
1079 bool __eq__(const wxDateSpan& other) { return *self == other; }
1080 bool __ne__(const wxDateSpan& other) { return *self != other; }
1085 //---------------------------------------------------------------------------
1087 // TODO: wxDateTimeHolidayAuthority
1089 //---------------------------------------------------------------------------
1091 long wxGetLocalTime();
1092 long wxGetUTCTime();
1093 long wxGetCurrentTime();
1094 wxLongLong wxGetLocalTimeMillis();
1096 //---------------------------------------------------------------------------
1097 //---------------------------------------------------------------------------