]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/_datetime.i
Patches from KevinO that work around issues where the widget isn't
[wxWidgets.git] / wxPython / src / _datetime.i
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: _datetime.i
3 // Purpose: SWIG interface for wxDateTime and etc.
4 //
5 // Author: Robin Dunn
6 //
7 // Created: 25-Nov-1998
8 // RCS-ID: $Id$
9 // Copyright: (c) 2003 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
12
13 // Not a %module
14
15
16 //---------------------------------------------------------------------------
17 %newgroup
18
19 %{
20 #include <wx/datetime.h>
21
22 %}
23 MAKE_CONST_WXSTRING2(DateFormatStr, wxT("%c"));
24 MAKE_CONST_WXSTRING2(TimeSpanFormatStr, wxT("%H:%M:%S"));
25
26 //---------------------------------------------------------------------------
27
28
29 %typemap(in) wxDateTime::TimeZone& (bool temp=False) {
30 $1 = new wxDateTime::TimeZone((wxDateTime::TZ)PyInt_AsLong($input));
31 temp = True;
32 }
33 %typemap(python,freearg) wxDateTime::TimeZone& {
34 if (temp$argnum) delete $1;
35 }
36
37
38 %{
39 #define LOCAL_TZ wxDateTime::Local
40 %}
41
42
43 // Convert a wxLongLong to a Python Long by getting the hi/lo dwords, then
44 // shifting and oring them together
45 %typemap(python, out) wxLongLong {
46 PyObject *hi, *lo, *shifter, *shifted;
47 hi = PyLong_FromLong( $1.GetHi() );
48 lo = PyLong_FromLong( $1.GetLo() );
49 shifter = PyLong_FromLong(32);
50 shifted = PyNumber_Lshift(hi, shifter);
51 $result = PyNumber_Or(shifted, lo);
52 Py_DECREF(hi);
53 Py_DECREF(lo);
54 Py_DECREF(shifter);
55 Py_DECREF(shifted);
56 }
57
58
59 //---------------------------------------------------------------------------
60
61 //typedef unsigned short wxDateTime_t;
62 #define wxDateTime_t int
63
64 // wxDateTime represents an absolute moment in the time
65 class wxDateTime {
66 public:
67
68 enum TZ
69 {
70 // the time in the current time zone
71 Local,
72
73 // zones from GMT (= Greenwhich Mean Time): they're guaranteed to be
74 // consequent numbers, so writing something like `GMT0 + offset' is
75 // safe if abs(offset) <= 12
76 // underscore stands for minus
77 GMT_12, GMT_11, GMT_10, GMT_9, GMT_8, GMT_7,
78 GMT_6, GMT_5, GMT_4, GMT_3, GMT_2, GMT_1,
79 GMT0,
80 GMT1, GMT2, GMT3, GMT4, GMT5, GMT6,
81 GMT7, GMT8, GMT9, GMT10, GMT11, GMT12,
82
83 // Europe
84 WET = GMT0, // Western Europe Time
85 WEST = GMT1, // Western Europe Summer Time
86 CET = GMT1, // Central Europe Time
87 CEST = GMT2, // Central Europe Summer Time
88 EET = GMT2, // Eastern Europe Time
89 EEST = GMT3, // Eastern Europe Summer Time
90 MSK = GMT3, // Moscow Time
91 MSD = GMT4, // Moscow Summer Time
92
93 // US and Canada
94 AST = GMT_4, // Atlantic Standard Time
95 ADT = GMT_3, // Atlantic Daylight Time
96 EST = GMT_5, // Eastern Standard Time
97 EDT = GMT_4, // Eastern Daylight Saving Time
98 CST = GMT_6, // Central Standard Time
99 CDT = GMT_5, // Central Daylight Saving Time
100 MST = GMT_7, // Mountain Standard Time
101 MDT = GMT_6, // Mountain Daylight Saving Time
102 PST = GMT_8, // Pacific Standard Time
103 PDT = GMT_7, // Pacific Daylight Saving Time
104 HST = GMT_10, // Hawaiian Standard Time
105 AKST = GMT_9, // Alaska Standard Time
106 AKDT = GMT_8, // Alaska Daylight Saving Time
107
108 // Australia
109
110 A_WST = GMT8, // Western Standard Time
111 A_CST = GMT12 + 1, // Central Standard Time (+9.5)
112 A_EST = GMT10, // Eastern Standard Time
113 A_ESST = GMT11, // Eastern Summer Time
114
115 // Universal Coordinated Time = the new and politically correct name
116 // for GMT
117 UTC = GMT0
118 };
119
120
121 // the calendar systems we know about: notice that it's valid (for
122 // this classes purpose anyhow) to work with any of these calendars
123 // even with the dates before the historical appearance of the
124 // calendar
125 enum Calendar
126 {
127 Gregorian, // current calendar
128 Julian // calendar in use since -45 until the 1582 (or later)
129 };
130
131 // these values only are used to identify the different dates of
132 // adoption of the Gregorian calendar (see IsGregorian())
133 //
134 // All data and comments taken verbatim from "The Calendar FAQ (v 2.0)"
135 // by Claus Tøndering, http://www.pip.dknet.dk/~c-t/calendar.html
136 // except for the comments "we take".
137 //
138 // Symbol "->" should be read as "was followed by" in the comments
139 // which follow.
140 enum GregorianAdoption
141 {
142 Gr_Unknown, // no data for this country or it's too uncertain to use
143 Gr_Standard, // on the day 0 of Gregorian calendar: 15 Oct 1582
144
145 Gr_Alaska, // Oct 1867 when Alaska became part of the USA
146 Gr_Albania, // Dec 1912
147
148 Gr_Austria = Gr_Unknown, // Different regions on different dates
149 Gr_Austria_Brixen, // 5 Oct 1583 -> 16 Oct 1583
150 Gr_Austria_Salzburg = Gr_Austria_Brixen,
151 Gr_Austria_Tyrol = Gr_Austria_Brixen,
152 Gr_Austria_Carinthia, // 14 Dec 1583 -> 25 Dec 1583
153 Gr_Austria_Styria = Gr_Austria_Carinthia,
154
155 Gr_Belgium, // Then part of the Netherlands
156
157 Gr_Bulgaria = Gr_Unknown, // Unknown precisely (from 1915 to 1920)
158 Gr_Bulgaria_1, // 18 Mar 1916 -> 1 Apr 1916
159 Gr_Bulgaria_2, // 31 Mar 1916 -> 14 Apr 1916
160 Gr_Bulgaria_3, // 3 Sep 1920 -> 17 Sep 1920
161
162 Gr_Canada = Gr_Unknown, // Different regions followed the changes in
163 // Great Britain or France
164
165 Gr_China = Gr_Unknown, // Different authorities say:
166 Gr_China_1, // 18 Dec 1911 -> 1 Jan 1912
167 Gr_China_2, // 18 Dec 1928 -> 1 Jan 1929
168
169 Gr_Czechoslovakia, // (Bohemia and Moravia) 6 Jan 1584 -> 17 Jan 1584
170 Gr_Denmark, // (including Norway) 18 Feb 1700 -> 1 Mar 1700
171 Gr_Egypt, // 1875
172 Gr_Estonia, // 1918
173 Gr_Finland, // Then part of Sweden
174
175 Gr_France, // 9 Dec 1582 -> 20 Dec 1582
176 Gr_France_Alsace, // 4 Feb 1682 -> 16 Feb 1682
177 Gr_France_Lorraine, // 16 Feb 1760 -> 28 Feb 1760
178 Gr_France_Strasbourg, // February 1682
179
180 Gr_Germany = Gr_Unknown, // Different states on different dates:
181 Gr_Germany_Catholic, // 1583-1585 (we take 1584)
182 Gr_Germany_Prussia, // 22 Aug 1610 -> 2 Sep 1610
183 Gr_Germany_Protestant, // 18 Feb 1700 -> 1 Mar 1700
184
185 Gr_GreatBritain, // 2 Sep 1752 -> 14 Sep 1752 (use 'cal(1)')
186
187 Gr_Greece, // 9 Mar 1924 -> 23 Mar 1924
188 Gr_Hungary, // 21 Oct 1587 -> 1 Nov 1587
189 Gr_Ireland = Gr_GreatBritain,
190 Gr_Italy = Gr_Standard,
191
192 Gr_Japan = Gr_Unknown, // Different authorities say:
193 Gr_Japan_1, // 19 Dec 1872 -> 1 Jan 1873
194 Gr_Japan_2, // 19 Dec 1892 -> 1 Jan 1893
195 Gr_Japan_3, // 18 Dec 1918 -> 1 Jan 1919
196
197 Gr_Latvia, // 1915-1918 (we take 1915)
198 Gr_Lithuania, // 1915
199 Gr_Luxemburg, // 14 Dec 1582 -> 25 Dec 1582
200 Gr_Netherlands = Gr_Belgium, // (including Belgium) 1 Jan 1583
201
202 // this is too weird to take into account: the Gregorian calendar was
203 // introduced twice in Groningen, first time 28 Feb 1583 was followed
204 // by 11 Mar 1583, then it has gone back to Julian in the summer of
205 // 1584 and then 13 Dec 1700 -> 12 Jan 1701 - which is
206 // the date we take here
207 Gr_Netherlands_Groningen, // 13 Dec 1700 -> 12 Jan 1701
208 Gr_Netherlands_Gelderland, // 30 Jun 1700 -> 12 Jul 1700
209 Gr_Netherlands_Utrecht, // (and Overijssel) 30 Nov 1700->12 Dec 1700
210 Gr_Netherlands_Friesland, // (and Drenthe) 31 Dec 1700 -> 12 Jan 1701
211
212 Gr_Norway = Gr_Denmark, // Then part of Denmark
213 Gr_Poland = Gr_Standard,
214 Gr_Portugal = Gr_Standard,
215 Gr_Romania, // 31 Mar 1919 -> 14 Apr 1919
216 Gr_Russia, // 31 Jan 1918 -> 14 Feb 1918
217 Gr_Scotland = Gr_GreatBritain,
218 Gr_Spain = Gr_Standard,
219
220 // Sweden has a curious history. Sweden decided to make a gradual
221 // change from the Julian to the Gregorian calendar. By dropping every
222 // leap year from 1700 through 1740 the eleven superfluous days would
223 // be omitted and from 1 Mar 1740 they would be in sync with the
224 // Gregorian calendar. (But in the meantime they would be in sync with
225 // nobody!)
226 //
227 // So 1700 (which should have been a leap year in the Julian calendar)
228 // was not a leap year in Sweden. However, by mistake 1704 and 1708
229 // became leap years. This left Sweden out of synchronisation with
230 // both the Julian and the Gregorian world, so they decided to go back
231 // to the Julian calendar. In order to do this, they inserted an extra
232 // day in 1712, making that year a double leap year! So in 1712,
233 // February had 30 days in Sweden.
234 //
235 // Later, in 1753, Sweden changed to the Gregorian calendar by
236 // dropping 11 days like everyone else.
237 Gr_Sweden = Gr_Finland, // 17 Feb 1753 -> 1 Mar 1753
238
239 Gr_Switzerland = Gr_Unknown,// Different cantons used different dates
240 Gr_Switzerland_Catholic, // 1583, 1584 or 1597 (we take 1584)
241 Gr_Switzerland_Protestant, // 31 Dec 1700 -> 12 Jan 1701
242
243 Gr_Turkey, // 1 Jan 1927
244 Gr_USA = Gr_GreatBritain,
245 Gr_Wales = Gr_GreatBritain,
246 Gr_Yugoslavia // 1919
247 };
248
249
250
251 // the country parameter is used so far for calculating the start and
252 // the end of DST period and for deciding whether the date is a work
253 // day or not
254 enum Country
255 {
256 Country_Unknown, // no special information for this country
257 Country_Default, // set the default country with SetCountry() method
258 // or use the default country with any other
259
260 // Western European countries: we assume that they all follow the same
261 // DST rules (True or False?)
262 Country_WesternEurope_Start,
263 Country_EEC = Country_WesternEurope_Start,
264 France,
265 Germany,
266 UK,
267 Country_WesternEurope_End = UK,
268
269 Russia,
270
271 USA
272 };
273
274 // symbolic names for the months
275 enum Month
276 {
277 Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec, Inv_Month
278 };
279
280 // symbolic names for the weekdays
281 enum WeekDay
282 {
283 Sun, Mon, Tue, Wed, Thu, Fri, Sat, Inv_WeekDay
284 };
285
286 // invalid value for the year
287 enum Year
288 {
289 Inv_Year = SHRT_MIN // should hold in wxDateTime_t
290 };
291
292 // flags for GetWeekDayName and GetMonthName
293 enum NameFlags
294 {
295 Name_Full = 0x01, // return full name
296 Name_Abbr = 0x02 // return abbreviated name
297 };
298
299 // flags for GetWeekOfYear and GetWeekOfMonth
300 enum WeekFlags
301 {
302 Default_First, // Sunday_First for US, Monday_First for the rest
303 Monday_First, // week starts with a Monday
304 Sunday_First // week starts with a Sunday
305 };
306
307
308 //** Nested class TimeZone is handled by a typemap instead
309
310 //** Is nested class Tm needed?
311
312
313 // static methods
314 // ------------------------------------------------------------------------
315
316 // set the current country
317 static void SetCountry(Country country);
318
319 // get the current country
320 static Country GetCountry();
321
322 // return True if the country is a West European one (in practice,
323 // this means that the same DST rules as for EEC apply)
324 static bool IsWestEuropeanCountry(Country country = Country_Default);
325
326 // return the current year
327 static int GetCurrentYear(Calendar cal = Gregorian);
328
329 // convert the year as returned by wxDateTime::GetYear() to a year
330 // suitable for BC/AD notation. The difference is that BC year 1
331 // corresponds to the year 0 (while BC year 0 didn't exist) and AD
332 // year N is just year N.
333 static int ConvertYearToBC(int year);
334
335 // return the current month
336 static Month GetCurrentMonth(Calendar cal = Gregorian);
337
338 // returns True if the given year is a leap year in the given calendar
339 static bool IsLeapYear(int year = Inv_Year, Calendar cal = Gregorian);
340
341 // get the century (19 for 1999, 20 for 2000 and -5 for 492 BC)
342 static int GetCentury(int year = Inv_Year);
343
344 // returns the number of days in this year (356 or 355 for Gregorian
345 // calendar usually :-)
346 %name(GetNumberOfDaysinYear)
347 static wxDateTime_t GetNumberOfDays(int year, Calendar cal = Gregorian);
348
349 // get the number of the days in the given month (default value for
350 // the year means the current one)
351 %name(GetNumberOfDaysInMonth)
352 static wxDateTime_t GetNumberOfDays(Month month,
353 int year = Inv_Year,
354 Calendar cal = Gregorian);
355
356 // get the full (default) or abbreviated month name in the current
357 // locale, returns empty string on error
358 static wxString GetMonthName(Month month,
359 NameFlags flags = Name_Full);
360
361 // get the full (default) or abbreviated weekday name in the current
362 // locale, returns empty string on error
363 static wxString GetWeekDayName(WeekDay weekday,
364 NameFlags flags = Name_Full);
365
366 DocDeclAStr(
367 static void, GetAmPmStrings(wxString *OUTPUT, wxString *OUTPUT),
368 "GetAmPmStrings() -> (am, pm)",
369 "Get the AM and PM strings in the current locale (may be empty)");
370
371 // return True if the given country uses DST for this year
372 static bool IsDSTApplicable(int year = Inv_Year,
373 Country country = Country_Default);
374
375 // get the beginning of DST for this year, will return invalid object
376 // if no DST applicable in this year. The default value of the
377 // parameter means to take the current year.
378 static wxDateTime GetBeginDST(int year = Inv_Year,
379 Country country = Country_Default);
380 // get the end of DST for this year, will return invalid object
381 // if no DST applicable in this year. The default value of the
382 // parameter means to take the current year.
383 static wxDateTime GetEndDST(int year = Inv_Year,
384 Country country = Country_Default);
385
386 // return the wxDateTime object for the current time
387 static inline wxDateTime Now();
388
389 // return the wxDateTime object for the current time with millisecond
390 // precision (if available on this platform)
391 static wxDateTime UNow();
392
393 // return the wxDateTime object for today midnight: i.e. as Now() but
394 // with time set to 0
395 static inline wxDateTime Today();
396
397
398
399 // ------------------------------------------------------------------------
400 // constructors
401
402 wxDateTime();
403 %name(DateTimeFromTimeT)wxDateTime(time_t timet);
404 %name(DateTimeFromJDN)wxDateTime(double jdn);
405 %name(DateTimeFromHMS)wxDateTime(wxDateTime_t hour,
406 wxDateTime_t minute = 0,
407 wxDateTime_t second = 0,
408 wxDateTime_t millisec = 0);
409 %name(DateTimeFromDMY)wxDateTime(wxDateTime_t day,
410 Month month = Inv_Month,
411 int year = Inv_Year,
412 wxDateTime_t hour = 0,
413 wxDateTime_t minute = 0,
414 wxDateTime_t second = 0,
415 wxDateTime_t millisec = 0);
416
417 ~wxDateTime();
418
419 // ------------------------------------------------------------------------
420 // Set methods
421
422 wxDateTime& SetToCurrent();
423
424 // set to given time_t value
425 %name(SetTimeT)wxDateTime& Set(time_t timet);
426
427 // set to given JDN (beware of rounding errors)
428 %name(SetJDN)wxDateTime& Set(double jdn);
429
430 // set to given time, date = today
431 %name(SetHMS)wxDateTime& Set(wxDateTime_t hour,
432 wxDateTime_t minute = 0,
433 wxDateTime_t second = 0,
434 wxDateTime_t millisec = 0);
435
436 // from separate values for each component with explicit date
437 // (defaults for month and year are the current values)
438 wxDateTime& Set(wxDateTime_t day,
439 Month month = Inv_Month,
440 int year = Inv_Year, // 1999, not 99 please!
441 wxDateTime_t hour = 0,
442 wxDateTime_t minute = 0,
443 wxDateTime_t second = 0,
444 wxDateTime_t millisec = 0);
445
446 // resets time to 00:00:00, doesn't change the date
447 wxDateTime& ResetTime();
448
449 // the following functions don't change the values of the other
450 // fields, i.e. SetMinute() won't change either hour or seconds value
451
452 // set the year
453 wxDateTime& SetYear(int year);
454 // set the month
455 wxDateTime& SetMonth(Month month);
456 // set the day of the month
457 wxDateTime& SetDay(wxDateTime_t day);
458 // set hour
459 wxDateTime& SetHour(wxDateTime_t hour);
460 // set minute
461 wxDateTime& SetMinute(wxDateTime_t minute);
462 // set second
463 wxDateTime& SetSecond(wxDateTime_t second);
464 // set millisecond
465 wxDateTime& SetMillisecond(wxDateTime_t millisecond);
466
467
468 // ------------------------------------------------------------------------
469 // calendar calculations
470
471 // set to the given week day in the same week as this one
472 wxDateTime& SetToWeekDayInSameWeek(WeekDay weekday, WeekFlags flags = Monday_First);
473 wxDateTime GetWeekDayInSameWeek(WeekDay weekday, WeekFlags flags = Monday_First);
474
475 // set to the next week day following this one
476 wxDateTime& SetToNextWeekDay(WeekDay weekday);
477 wxDateTime GetNextWeekDay(WeekDay weekday);
478
479 // set to the previous week day before this one
480 wxDateTime& SetToPrevWeekDay(WeekDay weekday);
481 wxDateTime GetPrevWeekDay(WeekDay weekday);
482
483 // set to Nth occurence of given weekday in the given month of the
484 // given year (time is set to 0), return True on success and False on
485 // failure. n may be positive (1..5) or negative to count from the end
486 // of the month (see helper function SetToLastWeekDay())
487 bool SetToWeekDay(WeekDay weekday,
488 int n = 1,
489 Month month = Inv_Month,
490 int year = Inv_Year);
491 // wxDateTime GetWeekDay(WeekDay weekday,
492 // int n = 1,
493 // Month month = Inv_Month,
494 // int year = Inv_Year);
495
496 // sets to the last weekday in the given month, year
497 bool SetToLastWeekDay(WeekDay weekday,
498 Month month = Inv_Month,
499 int year = Inv_Year);
500 wxDateTime GetLastWeekDay(WeekDay weekday,
501 Month month = Inv_Month,
502 int year = Inv_Year);
503
504 // sets the date to the given day of the given week in the year,
505 // returns True on success and False if given date doesn't exist (e.g.
506 // numWeek is > 53)
507 bool SetToTheWeek(wxDateTime_t numWeek, WeekDay weekday = Mon, WeekFlags flags = Monday_First);
508 wxDateTime GetWeek(wxDateTime_t numWeek, WeekDay weekday = Mon, WeekFlags flags = Monday_First);
509
510 // sets the date to the last day of the given (or current) month or the
511 // given (or current) year
512 wxDateTime& SetToLastMonthDay(Month month = Inv_Month,
513 int year = Inv_Year);
514 wxDateTime GetLastMonthDay(Month month = Inv_Month,
515 int year = Inv_Year);
516
517 // sets to the given year day (1..365 or 366)
518 wxDateTime& SetToYearDay(wxDateTime_t yday);
519 wxDateTime GetYearDay(wxDateTime_t yday);
520
521 // The definitions below were taken verbatim from
522 //
523 // http://www.capecod.net/~pbaum/date/date0.htm
524 //
525 // (Peter Baum's home page)
526 //
527 // definition: The Julian Day Number, Julian Day, or JD of a
528 // particular instant of time is the number of days and fractions of a
529 // day since 12 hours Universal Time (Greenwich mean noon) on January
530 // 1 of the year -4712, where the year is given in the Julian
531 // proleptic calendar. The idea of using this reference date was
532 // originally proposed by Joseph Scalizer in 1582 to count years but
533 // it was modified by 19th century astronomers to count days. One
534 // could have equivalently defined the reference time to be noon of
535 // November 24, -4713 if were understood that Gregorian calendar rules
536 // were applied. Julian days are Julian Day Numbers and are not to be
537 // confused with Julian dates.
538 //
539 // definition: The Rata Die number is a date specified as the number
540 // of days relative to a base date of December 31 of the year 0. Thus
541 // January 1 of the year 1 is Rata Die day 1.
542
543 // get the Julian Day number (the fractional part specifies the time of
544 // the day, related to noon - beware of rounding errors!)
545 double GetJulianDayNumber();
546 double GetJDN();
547
548 // get the Modified Julian Day number: it is equal to JDN - 2400000.5
549 // and so integral MJDs correspond to the midnights (and not noons).
550 // MJD 0 is Nov 17, 1858
551 double GetModifiedJulianDayNumber() const { return GetJDN() - 2400000.5; }
552 double GetMJD();
553
554 // get the Rata Die number
555 double GetRataDie();
556
557
558 // ------------------------------------------------------------------------
559 // timezone stuff
560
561 // transform to any given timezone
562 wxDateTime ToTimezone(const wxDateTime::TimeZone& tz, bool noDST = False);
563 wxDateTime& MakeTimezone(const wxDateTime::TimeZone& tz, bool noDST = False);
564
565 // transform to GMT/UTC
566 wxDateTime ToGMT(bool noDST = False);
567 wxDateTime& MakeGMT(bool noDST = False);
568
569 // is daylight savings time in effect at this moment according to the
570 // rules of the specified country?
571 //
572 // Return value is > 0 if DST is in effect, 0 if it is not and -1 if
573 // the information is not available (this is compatible with ANSI C)
574 int IsDST(Country country = Country_Default);
575
576
577
578 // ------------------------------------------------------------------------
579 // accessors
580
581 // is the date valid (True even for non initialized objects)?
582 inline bool IsValid() const;
583 %pythoncode { Ok = IsValid }
584 %pythoncode { def __nonzero__(self): return self.Ok() };
585
586
587 // get the number of seconds since the Unix epoch - returns (time_t)-1
588 // if the value is out of range
589 inline time_t GetTicks() const;
590
591 // get the year (returns Inv_Year if date is invalid)
592 int GetYear(const wxDateTime::TimeZone& tz = LOCAL_TZ) const;
593
594 // get the month (Inv_Month if date is invalid)
595 Month GetMonth(const wxDateTime::TimeZone& tz = LOCAL_TZ) const;
596
597 // get the month day (in 1..31 range, 0 if date is invalid)
598 wxDateTime_t GetDay(const wxDateTime::TimeZone& tz = LOCAL_TZ) const;
599
600 // get the day of the week (Inv_WeekDay if date is invalid)
601 WeekDay GetWeekDay(const wxDateTime::TimeZone& tz = LOCAL_TZ) const;
602
603 // get the hour of the day
604 wxDateTime_t GetHour(const wxDateTime::TimeZone& tz = LOCAL_TZ) const;
605
606 // get the minute
607 wxDateTime_t GetMinute(const wxDateTime::TimeZone& tz = LOCAL_TZ) const;
608
609 // get the second
610 wxDateTime_t GetSecond(const wxDateTime::TimeZone& tz = LOCAL_TZ) const;
611
612 // get milliseconds
613 wxDateTime_t GetMillisecond(const wxDateTime::TimeZone& tz = LOCAL_TZ) const;
614
615
616 // get the day since the year start (1..366, 0 if date is invalid)
617 wxDateTime_t GetDayOfYear(const wxDateTime::TimeZone& tz = LOCAL_TZ) const;
618 // get the week number since the year start (1..52 or 53, 0 if date is
619 // invalid)
620 wxDateTime_t GetWeekOfYear(WeekFlags flags = Monday_First,
621 const wxDateTime::TimeZone& tz = LOCAL_TZ) const;
622 // get the week number since the month start (1..5, 0 if date is
623 // invalid)
624 wxDateTime_t GetWeekOfMonth(WeekFlags flags = Monday_First,
625 const wxDateTime::TimeZone& tz = LOCAL_TZ) const;
626
627 // is this date a work day? This depends on a country, of course,
628 // because the holidays are different in different countries
629 bool IsWorkDay(Country country = Country_Default) const;
630
631 // is this date later than Gregorian calendar introduction for the
632 // given country (see enum GregorianAdoption)?
633 //
634 // NB: this function shouldn't be considered as absolute authority in
635 // the matter. Besides, for some countries the exact date of
636 // adoption of the Gregorian calendar is simply unknown.
637 // bool IsGregorianDate(GregorianAdoption country = Gr_Standard) const;
638
639
640 // ------------------------------------------------------------------------
641 // comparison (see also functions below for operator versions)
642
643 // returns True if the two moments are strictly identical
644 inline bool IsEqualTo(const wxDateTime& datetime) const;
645
646 // returns True if the date is strictly earlier than the given one
647 inline bool IsEarlierThan(const wxDateTime& datetime) const;
648
649 // returns True if the date is strictly later than the given one
650 inline bool IsLaterThan(const wxDateTime& datetime) const;
651
652 // returns True if the date is strictly in the given range
653 inline bool IsStrictlyBetween(const wxDateTime& t1,
654 const wxDateTime& t2) const;
655
656 // returns True if the date is in the given range
657 inline bool IsBetween(const wxDateTime& t1, const wxDateTime& t2) const;
658
659 // do these two objects refer to the same date?
660 inline bool IsSameDate(const wxDateTime& dt) const;
661
662 // do these two objects have the same time?
663 inline bool IsSameTime(const wxDateTime& dt) const;
664
665 // are these two objects equal up to given timespan?
666 inline bool IsEqualUpTo(const wxDateTime& dt, const wxTimeSpan& ts) const;
667
668
669 // ------------------------------------------------------------------------
670 // arithmetics with dates (see also below for more operators)
671
672 // add a time span (positive or negative)
673 %name(AddTS) wxDateTime& Add(const wxTimeSpan& diff);
674 // add a date span (positive or negative)
675 %name(AddDS) wxDateTime& Add(const wxDateSpan& diff);
676
677 // subtract a time span (positive or negative)
678 %name(SubtractTS) wxDateTime& Subtract(const wxTimeSpan& diff);
679
680 // subtract a date span (positive or negative)
681 %name(SubtractDS) wxDateTime& Subtract(const wxDateSpan& diff);
682
683 // return the difference between two dates
684 wxTimeSpan Subtract(const wxDateTime& dt) const;
685
686
687 %nokwargs operator+=;
688 // add a time span (positive or negative)
689 inline wxDateTime& operator+=(const wxTimeSpan& diff);
690 // add a date span (positive or negative)
691 inline wxDateTime& operator+=(const wxDateSpan& diff);
692
693 %nokwargs operator-=;
694 // subtract a time span (positive or negative)
695 inline wxDateTime& operator-=(const wxTimeSpan& diff);
696 // subtract a date span (positive or negative)
697 inline wxDateTime& operator-=(const wxDateSpan& diff);
698
699
700 %nokwargs __add__;
701 %nokwargs __sub__;
702 %nokwargs __lt__;
703 %nokwargs __le__;
704 %nokwargs __gt__;
705 %nokwargs __ge__;
706 %nokwargs __eq__;
707 %nokwargs __ne__;
708 %extend {
709 wxDateTime __add__(const wxTimeSpan& other) { return *self + other; }
710 wxDateTime __add__(const wxDateSpan& other) { return *self + other; }
711
712 wxTimeSpan __sub__(const wxDateTime& other) { return *self - other; }
713 wxDateTime __sub__(const wxTimeSpan& other) { return *self - other; }
714 wxDateTime __sub__(const wxDateSpan& other) { return *self - other; }
715
716 // bool __lt__(const wxDateTime* other) { return other ? (*self < *other) : False; }
717 // bool __le__(const wxDateTime* other) { return other ? (*self <= *other) : False; }
718 // bool __gt__(const wxDateTime* other) { return other ? (*self > *other) : True; }
719 // bool __ge__(const wxDateTime* other) { return other ? (*self >= *other) : True; }
720
721
722 // These fall back to just comparing pointers if other is NULL, or if
723 // either operand is invalid.
724 bool __lt__(const wxDateTime* other) {
725 if (!other || !self->IsValid() || !other->IsValid()) return self < other;
726 return (*self < *other);
727 }
728 bool __le__(const wxDateTime* other) {
729 if (!other || !self->IsValid() || !other->IsValid()) return self <= other;
730 return (*self <= *other);
731 }
732 bool __gt__(const wxDateTime* other) {
733 if (!other || !self->IsValid() || !other->IsValid()) return self > other;
734 return (*self > *other);
735 }
736 bool __ge__(const wxDateTime* other) {
737 if (!other || !self->IsValid() || !other->IsValid()) return self >= other;
738 return (*self >= *other);
739 }
740
741 bool __eq__(const wxDateTime* other) {
742 if (!other || !self->IsValid() || !other->IsValid()) return self == other;
743 return (*self == *other);
744 }
745 bool __ne__(const wxDateTime* other) {
746 if (!other || !self->IsValid() || !other->IsValid()) return self != other;
747 return (*self != *other);
748 }
749 }
750
751
752 // ------------------------------------------------------------------------
753 // conversion from text: all conversions from text return -1 on failure,
754 // or the index in the string where the next character following the date
755 // specification (i.e. the one where the scan had to stop) is located.
756
757 %extend {
758
759 // parse a string in RFC 822 format (found e.g. in mail headers and
760 // having the form "Wed, 10 Feb 1999 19:07:07 +0100")
761 int ParseRfc822Date(const wxString& date) {
762 const wxChar* rv;
763 const wxChar* _date = date;
764 rv = self->ParseRfc822Date(_date);
765 if (rv == NULL) return -1;
766 return rv - _date;
767 }
768
769
770 // parse a date/time in the given format (see strptime(3)), fill in
771 // the missing (in the string) fields with the values of dateDef (by
772 // default, they will not change if they had valid values or will
773 // default to Today() otherwise)
774 int ParseFormat(const wxString& date,
775 const wxString& format = wxPyDateFormatStr,
776 const wxDateTime& dateDef = wxDefaultDateTime) {
777 const wxChar* rv;
778 const wxChar* _date = date;
779 rv = self->ParseFormat(_date, format, dateDef);
780 if (rv == NULL) return -1;
781 return rv - _date;
782 }
783
784 // parse a string containing the date/time in "free" format, this
785 // function will try to make an educated guess at the string contents
786 int ParseDateTime(const wxString& datetime) {
787 const wxChar* rv;
788 const wxChar* _datetime = datetime;
789 rv = self->ParseDateTime(_datetime);
790 if (rv == NULL) return -1;
791 return rv - _datetime;
792 }
793
794
795 // parse a string containing the date only in "free" format (less
796 // flexible than ParseDateTime)
797 int ParseDate(const wxString& date) {
798 const wxChar* rv;
799 const wxChar* _date = date;
800 rv = self->ParseDate(_date);
801 if (rv == NULL) return -1;
802 return rv - _date;
803 }
804
805 // parse a string containing the time only in "free" format
806 int ParseTime(const wxString& time) {
807 const wxChar* rv;
808 const wxChar* _time = time;
809 rv = self->ParseTime(_time);
810 if (rv == NULL) return -1;
811 return rv - _time;
812 }
813 }
814
815
816 // this function accepts strftime()-like format string (default
817 // argument corresponds to the preferred date and time representation
818 // for the current locale) and returns the string containing the
819 // resulting text representation
820 wxString Format(const wxString& format = wxPyDateFormatStr,
821 const wxDateTime::TimeZone& tz = LOCAL_TZ) const;
822
823 // preferred date representation for the current locale
824 wxString FormatDate() const;
825
826 // preferred time representation for the current locale
827 wxString FormatTime() const;
828
829 // returns the string representing the date in ISO 8601 format
830 // (YYYY-MM-DD)
831 wxString FormatISODate() const;
832
833 // returns the string representing the time in ISO 8601 format
834 // (HH:MM:SS)
835 wxString FormatISOTime() const;
836
837 %pythoncode {
838 def __repr__(self):
839 if self.IsValid():
840 return '<wx.DateTime: \"%s\" at %s>' % ( self.Format(), self.this)
841 else:
842 return '<wx.DateTime: \"INVALID\" at %s>' % self.this
843 def __str__(self):
844 if self.IsValid():
845 return self.Format()
846 else:
847 return "INVALID DateTime"
848 }
849 };
850
851 //---------------------------------------------------------------------------
852 //---------------------------------------------------------------------------
853
854
855 // This class contains a difference between 2 wxDateTime values, so it makes
856 // sense to add it to wxDateTime and it is the result of subtraction of 2
857 // objects of that class. See also wxDateSpan.
858 class wxTimeSpan
859 {
860 public:
861
862 // return the timespan for the given number of seconds
863 static wxTimeSpan Seconds(long sec);
864 static wxTimeSpan Second();
865
866 // return the timespan for the given number of minutes
867 static wxTimeSpan Minutes(long min);
868 static wxTimeSpan Minute();
869
870 // return the timespan for the given number of hours
871 static wxTimeSpan Hours(long hours);
872 static wxTimeSpan Hour();
873
874 // return the timespan for the given number of days
875 static wxTimeSpan Days(long days);
876 static wxTimeSpan Day();
877
878 // return the timespan for the given number of weeks
879 static wxTimeSpan Weeks(long days);
880 static wxTimeSpan Week();
881
882 // ------------------------------------------------------------------------
883 // constructors
884
885 // from separate values for each component, date set to 0 (hours are
886 // not restricted to 0..24 range, neither are minutes, seconds or
887 // milliseconds)
888 wxTimeSpan(long hours = 0,
889 long minutes = 0,
890 long seconds = 0,
891 long milliseconds = 0);
892
893 ~wxTimeSpan();
894
895 // ------------------------------------------------------------------------
896 // arithmetics with time spans
897
898 // add two timespans together
899 inline wxTimeSpan& Add(const wxTimeSpan& diff);
900
901 // subtract another timespan
902 inline wxTimeSpan& Subtract(const wxTimeSpan& diff);
903
904 // multiply timespan by a scalar
905 inline wxTimeSpan& Multiply(int n);
906
907 // negate the value of the timespan
908 wxTimeSpan& Neg();
909
910 // return the absolute value of the timespan: does _not_ modify the
911 // object
912 inline wxTimeSpan Abs() const;
913
914
915 wxTimeSpan& operator+=(const wxTimeSpan& diff);
916 wxTimeSpan& operator-=(const wxTimeSpan& diff);
917 wxTimeSpan& operator*=(int n);
918 wxTimeSpan& operator-();
919
920 %extend {
921 wxTimeSpan __add__(const wxTimeSpan& other) { return *self + other; }
922 wxTimeSpan __sub__(const wxTimeSpan& other) { return *self - other; }
923 wxTimeSpan __mul__(int n) { return *self * n; }
924 wxTimeSpan __rmul__(int n) { return n * *self; }
925
926 bool __lt__(const wxTimeSpan* other) { return other ? (*self < *other) : False; }
927 bool __le__(const wxTimeSpan* other) { return other ? (*self <= *other) : False; }
928 bool __gt__(const wxTimeSpan* other) { return other ? (*self > *other) : True; }
929 bool __ge__(const wxTimeSpan* other) { return other ? (*self >= *other) : True; }
930 bool __eq__(const wxTimeSpan* other) { return other ? (*self == *other) : False; }
931 bool __ne__(const wxTimeSpan* other) { return other ? (*self != *other) : True; }
932 }
933
934
935
936 // ------------------------------------------------------------------------
937
938 // is the timespan null?
939 bool IsNull() const;
940
941 // is the timespan positive?
942 bool IsPositive() const;
943
944 // is the timespan negative?
945 bool IsNegative() const;
946
947 // are two timespans equal?
948 inline bool IsEqualTo(const wxTimeSpan& ts) const;
949
950 // compare two timestamps: works with the absolute values, i.e. -2
951 // hours is longer than 1 hour. Also, it will return False if the
952 // timespans are equal in absolute value.
953 inline bool IsLongerThan(const wxTimeSpan& ts) const;
954
955 // compare two timestamps: works with the absolute values, i.e. 1
956 // hour is shorter than -2 hours. Also, it will return False if the
957 // timespans are equal in absolute value.
958 bool IsShorterThan(const wxTimeSpan& t) const;
959
960 // ------------------------------------------------------------------------
961 // breaking into days, hours, minutes and seconds
962
963 // get the max number of weeks in this timespan
964 inline int GetWeeks() const;
965 // get the max number of days in this timespan
966 inline int GetDays() const;
967 // get the max number of hours in this timespan
968 inline int GetHours() const;
969 // get the max number of minutes in this timespan
970 inline int GetMinutes() const;
971
972
973 // get the max number of seconds in this timespan
974 inline wxLongLong GetSeconds() const;
975 // get the number of milliseconds in this timespan
976 wxLongLong GetMilliseconds() const;
977
978 // ------------------------------------------------------------------------
979 // conversion to text
980
981 // this function accepts strftime()-like format string (default
982 // argument corresponds to the preferred date and time representation
983 // for the current locale) and returns the string containing the
984 // resulting text representation. Notice that only some of format
985 // specifiers valid for wxDateTime are valid for wxTimeSpan: hours,
986 // minutes and seconds make sense, but not "PM/AM" string for example.
987 wxString Format(const wxString& format = wxPyTimeSpanFormatStr) const;
988
989 %pythoncode {
990 def __repr__(self):
991 return '<wx.TimeSpan: \"%s\" at %s>' % ( self.Format(), self.this)
992 def __str__(self):
993 return self.Format()
994 }
995 };
996
997
998 //---------------------------------------------------------------------------
999 //---------------------------------------------------------------------------
1000
1001 // This class is a "logical time span" and is useful for implementing program
1002 // logic for such things as "add one month to the date" which, in general,
1003 // doesn't mean to add 60*60*24*31 seconds to it, but to take the same date
1004 // the next month (to understand that this is indeed different consider adding
1005 // one month to Feb, 15 - we want to get Mar, 15, of course).
1006 //
1007 // When adding a month to the date, all lesser components (days, hours, ...)
1008 // won't be changed unless the resulting date would be invalid: for example,
1009 // Jan 31 + 1 month will be Feb 28, not (non existing) Feb 31.
1010 //
1011 // Because of this feature, adding and subtracting back again the same
1012 // wxDateSpan will *not*, in general give back the original date: Feb 28 - 1
1013 // month will be Jan 28, not Jan 31!
1014 //
1015 // wxDateSpan can be either positive or negative. They may be
1016 // multiplied by scalars which multiply all deltas by the scalar: i.e. 2*(1
1017 // month and 1 day) is 2 months and 2 days. They can be added together and
1018 // with wxDateTime or wxTimeSpan, but the type of result is different for each
1019 // case.
1020 //
1021 // Beware about weeks: if you specify both weeks and days, the total number of
1022 // days added will be 7*weeks + days! See also GetTotalDays() function.
1023 //
1024 // Equality operators are defined for wxDateSpans. Two datespans are equal if
1025 // they both give the same target date when added to *every* source date.
1026 // Thus wxDateSpan::Months(1) is not equal to wxDateSpan::Days(30), because
1027 // they not give the same date when added to 1 Feb. But wxDateSpan::Days(14) is
1028 // equal to wxDateSpan::Weeks(2)
1029 //
1030 // Finally, notice that for adding hours, minutes &c you don't need this
1031 // class: wxTimeSpan will do the job because there are no subtleties
1032 // associated with those.
1033 class wxDateSpan
1034 {
1035 public:
1036 // this many years/months/weeks/days
1037 wxDateSpan(int years = 0, int months = 0, int weeks = 0, int days = 0)
1038 {
1039 m_years = years;
1040 m_months = months;
1041 m_weeks = weeks;
1042 m_days = days;
1043 }
1044
1045 ~wxDateSpan();
1046
1047 // get an object for the given number of days
1048 static wxDateSpan Days(int days);
1049 static wxDateSpan Day();
1050
1051 // get an object for the given number of weeks
1052 static wxDateSpan Weeks(int weeks);
1053 static wxDateSpan Week();
1054
1055 // get an object for the given number of months
1056 static wxDateSpan Months(int mon);
1057 static wxDateSpan Month();
1058
1059 // get an object for the given number of years
1060 static wxDateSpan Years(int years);
1061 static wxDateSpan Year();
1062
1063
1064 // ------------------------------------------------------------------------
1065
1066 // set number of years
1067 wxDateSpan& SetYears(int n);
1068 // set number of months
1069 wxDateSpan& SetMonths(int n);
1070 // set number of weeks
1071 wxDateSpan& SetWeeks(int n);
1072 // set number of days
1073 wxDateSpan& SetDays(int n);
1074
1075 // get number of years
1076 int GetYears() const;
1077 // get number of months
1078 int GetMonths() const;
1079 // get number of weeks
1080 int GetWeeks() const;
1081 // get number of days
1082 int GetDays() const;
1083 // returns 7*GetWeeks() + GetDays()
1084 int GetTotalDays() const;
1085
1086
1087 // ------------------------------------------------------------------------
1088
1089 // add another wxDateSpan to us
1090 inline wxDateSpan& Add(const wxDateSpan& other);
1091
1092 // subtract another wxDateSpan from us
1093 inline wxDateSpan& Subtract(const wxDateSpan& other);
1094
1095 // inverse the sign of this timespan
1096 inline wxDateSpan& Neg();
1097
1098 // multiply all components by a (signed) number
1099 inline wxDateSpan& Multiply(int factor);
1100
1101 inline wxDateSpan& operator+=(const wxDateSpan& other);
1102 inline wxDateSpan& operator-=(const wxDateSpan& other);
1103 wxDateSpan& operator-() { return Neg(); }
1104 inline wxDateSpan& operator*=(int factor) { return Multiply(factor); }
1105
1106 %extend {
1107 wxDateSpan __add__(const wxDateSpan& other) { return *self + other; }
1108 wxDateSpan __sub__(const wxDateSpan& other) { return *self - other; }
1109 wxDateSpan __mul__(int n) { return *self * n; }
1110 wxDateSpan __rmul__(int n) { return n * *self; }
1111
1112 // bool __lt__(const wxDateSpan* other) { return other ? (*self < *other) : False; }
1113 // bool __le__(const wxDateSpan* other) { return other ? (*self <= *other) : False; }
1114 // bool __gt__(const wxDateSpan* other) { return other ? (*self > *other) : True; }
1115 // bool __ge__(const wxDateSpan* other) { return other ? (*self >= *other) : True; }
1116
1117 bool __eq__(const wxDateSpan* other) { return other ? (*self == *other) : False; }
1118 bool __ne__(const wxDateSpan* other) { return other ? (*self != *other) : True; }
1119 }
1120 };
1121
1122
1123 //---------------------------------------------------------------------------
1124
1125 // TODO: wxDateTimeHolidayAuthority
1126
1127 //---------------------------------------------------------------------------
1128
1129 long wxGetLocalTime();
1130 long wxGetUTCTime();
1131 long wxGetCurrentTime();
1132 wxLongLong wxGetLocalTimeMillis();
1133
1134 %immutable;
1135 const wxDateTime wxDefaultDateTime;
1136 %mutable;
1137
1138 //---------------------------------------------------------------------------
1139 //---------------------------------------------------------------------------