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