1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: SWIG definitions of various utility classes
7 // Created: 25-Nov-1998
9 // Copyright: (c) 1998 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
18 #include <wx/config.h>
19 #include <wx/fileconf.h>
20 #include <wx/datetime.h>
23 //---------------------------------------------------------------------------
25 // Put some wx default wxChar* values into wxStrings.
26 DECLARE_DEF_STRING2(DateFormatStr, wxT("%c"));
27 static const wxString wxPyEmptyString(wxT(""));
30 //---------------------------------------------------------------------------
33 %include my_typemaps.i
35 // Import some definitions of other classes, etc.
38 %pragma(python) code = "import wx"
41 //---------------------------------------------------------------------------
44 static PyObject* __EnumerationHelper(bool flag, wxString& str, long index) {
45 PyObject* ret = PyTuple_New(3);
47 PyTuple_SET_ITEM(ret, 0, PyInt_FromLong(flag));
49 PyTuple_SET_ITEM(ret, 1, PyUnicode_FromWideChar(str.c_str(), str.Len()));
51 PyTuple_SET_ITEM(ret, 1, PyString_FromStringAndSize(str.c_str(), str.Len()));
53 PyTuple_SET_ITEM(ret, 2, PyInt_FromLong(index));
59 //---------------------------------------------------------------------------
63 wxCONFIG_USE_LOCAL_FILE,
64 wxCONFIG_USE_GLOBAL_FILE,
65 wxCONFIG_USE_RELATIVE_PATH,
66 wxCONFIG_USE_NO_ESCAPE_CHARACTERS
69 //---------------------------------------------------------------------------
73 // wxConfigBase(const wxString& appName = wxPyEmptyString, **** An ABC
74 // const wxString& vendorName = wxPyEmptyString,
75 // const wxString& localFilename = wxPyEmptyString,
76 // const wxString& globalFilename = wxPyEmptyString,
85 Type_Integer, // use Read(long *)
86 Type_Float // use Read(double *)
90 // sets the config object, returns the previous pointer
91 static wxConfigBase *Set(wxConfigBase *pConfig);
92 // get the config object, creates it on demand unless DontCreateOnDemand
94 static wxConfigBase *Get(bool createOnDemand = TRUE);
95 // create a new config object: this function will create the "best"
96 // implementation of wxConfig available for the current platform, see
97 // comments near definition wxUSE_CONFIG_NATIVE for details. It returns
98 // the created object and also sets it as ms_pConfig.
99 static wxConfigBase *Create();
100 // should Get() try to create a new log object if the current one is NULL?
101 static void DontCreateOnDemand();
105 bool DeleteAll(); // This is supposed to have been fixed...
106 bool DeleteEntry(const wxString& key, bool bDeleteGroupIfEmpty = TRUE);
107 bool DeleteGroup(const wxString& key);
108 bool Exists(wxString& strName);
109 bool Flush(bool bCurrentOnly = FALSE);
110 wxString GetAppName();
113 // Each of these enumeration methods return a 3-tuple consisting of
114 // the continue flag, the value string, and the index for the next call.
116 PyObject* GetFirstGroup() {
121 cont = self->GetFirstGroup(value, index);
122 return __EnumerationHelper(cont, value, index);
125 PyObject* GetFirstEntry() {
130 cont = self->GetFirstEntry(value, index);
131 return __EnumerationHelper(cont, value, index);
134 PyObject* GetNextGroup(long index) {
138 cont = self->GetNextGroup(value, index);
139 return __EnumerationHelper(cont, value, index);
142 PyObject* GetNextEntry(long index) {
146 cont = self->GetNextEntry(value, index);
147 return __EnumerationHelper(cont, value, index);
152 int GetNumberOfEntries(bool bRecursive = FALSE);
153 int GetNumberOfGroups(bool bRecursive = FALSE);
155 wxString GetVendorName();
156 bool HasEntry(wxString& strName);
157 bool HasGroup(const wxString& strName);
158 bool IsExpandingEnvVars();
159 bool IsRecordingDefaults();
161 wxString Read(const wxString& key, const wxString& defaultVal = wxPyEmptyString);
164 long ReadInt(const wxString& key, long defaultVal = 0) {
166 self->Read(key, &rv, defaultVal);
169 double ReadFloat(const wxString& key, double defaultVal = 0.0) {
171 self->Read(key, &rv, defaultVal);
174 bool ReadBool(const wxString& key, bool defaultVal = FALSE) {
176 self->Read(key, &rv, defaultVal);
181 void SetExpandEnvVars (bool bDoIt = TRUE);
182 void SetPath(const wxString& strPath);
183 void SetRecordDefaults(bool bDoIt = TRUE);
184 void SetAppName(const wxString& appName);
185 void SetVendorName(const wxString& vendorName);
187 void SetStyle(long style);
190 bool Write(const wxString& key, const wxString& value);
191 %name(WriteInt)bool Write(const wxString& key, long value);
192 %name(WriteFloat)bool Write(const wxString& key, double value);
193 %name(WriteBool)bool Write(const wxString& key, bool value);
195 EntryType GetEntryType(const wxString& name);
196 bool RenameEntry(const wxString& oldName,
197 const wxString& newName);
198 bool RenameGroup(const wxString& oldName,
199 const wxString& newName);
200 wxString ExpandEnvVars(const wxString& str);
206 //---------------------------------------------------------------------------
208 // This will be a wxRegConfig on Win32 and wxFileConfig otherwise.
209 class wxConfig : public wxConfigBase {
211 wxConfig(const wxString& appName = wxPyEmptyString,
212 const wxString& vendorName = wxPyEmptyString,
213 const wxString& localFilename = wxPyEmptyString,
214 const wxString& globalFilename = wxPyEmptyString,
220 // Sometimes it's nice to explicitly have a wxFileConfig too.
221 class wxFileConfig : public wxConfigBase {
223 wxFileConfig(const wxString& appName = wxPyEmptyString,
224 const wxString& vendorName = wxPyEmptyString,
225 const wxString& localFilename = wxPyEmptyString,
226 const wxString& globalFilename = wxPyEmptyString,
232 //---------------------------------------------------------------------------
233 //---------------------------------------------------------------------------
240 %typemap(python,in) wxDateTime::TimeZone& {
241 $target = new wxDateTime::TimeZone((wxDateTime::TZ)PyInt_AsLong($source));
243 %typemap(python,freearg) wxDateTime::TimeZone& {
244 if ($source) delete $source;
248 #define LOCAL *(new wxDateTime::TimeZone(wxDateTime::Local))
252 %typemap(python, out) wxLongLong {
253 PyObject *hi, *lo, *shifter, *shifted;
254 hi = PyLong_FromLong($source->GetHi());
255 lo = PyLong_FromLong($source->GetLo());
256 shifter = PyLong_FromLong(32);
257 shifted = PyNumber_Lshift(hi, shifter);
258 $target = PyNumber_Or(shifted, lo);
270 typedef unsigned short wxDateTime_t;
276 GMT_12, GMT_11, GMT_10, GMT_9, GMT_8, GMT_7,
277 GMT_6, GMT_5, GMT_4, GMT_3, GMT_2, GMT_1,
279 GMT1, GMT2, GMT3, GMT4, GMT5, GMT6,
280 GMT7, GMT8, GMT9, GMT10, GMT11, GMT12,
283 WET = GMT0, // Western Europe Time
284 WEST = GMT1, // Western Europe Summer Time
285 CET = GMT1, // Central Europe Time
286 CEST = GMT2, // Central Europe Summer Time
287 EET = GMT2, // Eastern Europe Time
288 EEST = GMT3, // Eastern Europe Summer Time
289 MSK = GMT3, // Moscow Time
290 MSD = GMT4, // Moscow Summer Time
293 AST = GMT_4, // Atlantic Standard Time
294 ADT = GMT_3, // Atlantic Daylight Time
295 EST = GMT_5, // Eastern Standard Time
296 EDT = GMT_4, // Eastern Daylight Saving Time
297 CST = GMT_6, // Central Standard Time
298 CDT = GMT_5, // Central Daylight Saving Time
299 MST = GMT_7, // Mountain Standard Time
300 MDT = GMT_6, // Mountain Daylight Saving Time
301 PST = GMT_8, // Pacific Standard Time
302 PDT = GMT_7, // Pacific Daylight Saving Time
303 HST = GMT_10, // Hawaiian Standard Time
304 AKST = GMT_9, // Alaska Standard Time
305 AKDT = GMT_8, // Alaska Daylight Saving Time
309 A_WST = GMT8, // Western Standard Time
310 A_CST = GMT12 + 1, // Central Standard Time (+9.5)
311 A_EST = GMT10, // Eastern Standard Time
312 A_ESST = GMT11, // Eastern Summer Time
314 // Universal Coordinated Time = the new and politically correct name
321 Gregorian, // current calendar
322 Julian // calendar in use since -45 until the 1582 (or later)
327 Country_Unknown, // no special information for this country
328 Country_Default, // set the default country with SetCountry() method
329 // or use the default country with any other
331 // Western European countries: we assume that they all follow the same
332 // DST rules (true or false?)
333 Country_WesternEurope_Start,
334 Country_EEC = Country_WesternEurope_Start,
338 Country_WesternEurope_End = UK,
345 // symbolic names for the months
348 Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec, Inv_Month
351 // symbolic names for the weekdays
354 Sun, Mon, Tue, Wed, Thu, Fri, Sat, Inv_WeekDay
357 // invalid value for the year
360 Inv_Year = SHRT_MIN // should hold in wxDateTime_t
363 // flags for GetWeekDayName and GetMonthName
366 Name_Full = 0x01, // return full name
367 Name_Abbr = 0x02 // return abbreviated name
370 // flags for GetWeekOfYear and GetWeekOfMonth
373 Default_First, // Sunday_First for US, Monday_First for the rest
374 Monday_First, // week starts with a Monday
375 Sunday_First // week starts with a Sunday
380 // ------------------------------------------------------------------------
382 // set the current country
383 static void SetCountry(Country country);
384 // get the current country
385 static Country GetCountry();
387 // return TRUE if the country is a West European one (in practice,
388 // this means that the same DST rules as for EEC apply)
389 static bool IsWestEuropeanCountry(Country country = Country_Default);
391 // return the current year
392 static int GetCurrentYear(Calendar cal = Gregorian);
394 // convert the year as returned by wxDateTime::GetYear() to a year
395 // suitable for BC/AD notation. The difference is that BC year 1
396 // corresponds to the year 0 (while BC year 0 didn't exist) and AD
397 // year N is just year N.
398 static int ConvertYearToBC(int year);
400 // return the current month
401 static Month GetCurrentMonth(Calendar cal = Gregorian);
403 // returns TRUE if the given year is a leap year in the given calendar
404 static bool IsLeapYear(int year = Inv_Year, Calendar cal = Gregorian);
406 // get the century (19 for 1999, 20 for 2000 and -5 for 492 BC)
407 static int GetCentury(int year = Inv_Year);
409 // returns the number of days in this year (356 or 355 for Gregorian
410 // calendar usually :-)
411 %name(GetNumberOfDaysinYear)
412 static wxDateTime_t GetNumberOfDays(int year, Calendar cal = Gregorian);
414 // get the number of the days in the given month (default value for
415 // the year means the current one)
416 %name(GetNumberOfDaysInMonth)
417 static wxDateTime_t GetNumberOfDays(Month month,
419 Calendar cal = Gregorian);
421 // get the full (default) or abbreviated month name in the current
422 // locale, returns empty string on error
423 static wxString GetMonthName(Month month,
424 NameFlags flags = Name_Full);
426 // get the full (default) or abbreviated weekday name in the current
427 // locale, returns empty string on error
428 static wxString GetWeekDayName(WeekDay weekday,
429 NameFlags flags = Name_Full);
431 // get the AM and PM strings in the current locale (may be empty)
432 static void GetAmPmStrings(wxString *OUTPUT, wxString *OUTPUT);
434 // return TRUE if the given country uses DST for this year
435 static bool IsDSTApplicable(int year = Inv_Year,
436 Country country = Country_Default);
438 // get the beginning of DST for this year, will return invalid object
439 // if no DST applicable in this year. The default value of the
440 // parameter means to take the current year.
441 static wxDateTime GetBeginDST(int year = Inv_Year,
442 Country country = Country_Default);
443 // get the end of DST for this year, will return invalid object
444 // if no DST applicable in this year. The default value of the
445 // parameter means to take the current year.
446 static wxDateTime GetEndDST(int year = Inv_Year,
447 Country country = Country_Default);
449 // return the wxDateTime object for the current time
450 static inline wxDateTime Now();
452 // return the wxDateTime object for the current time with millisecond
453 // precision (if available on this platform)
454 static wxDateTime UNow();
456 // return the wxDateTime object for today midnight: i.e. as Now() but
457 // with time set to 0
458 static inline wxDateTime Today();
462 // ------------------------------------------------------------------------
466 %name(wxDateTimeFromTimeT)wxDateTime(time_t timet);
467 %name(wxDateTimeFromJDN)wxDateTime(double jdn);
468 %name(wxDateTimeFromHMS)wxDateTime(wxDateTime_t hour,
469 wxDateTime_t minute = 0,
470 wxDateTime_t second = 0,
471 wxDateTime_t millisec = 0);
472 %name(wxDateTimeFromDMY)wxDateTime(wxDateTime_t day,
473 Month month = Inv_Month,
475 wxDateTime_t hour = 0,
476 wxDateTime_t minute = 0,
477 wxDateTime_t second = 0,
478 wxDateTime_t millisec = 0);
482 // ------------------------------------------------------------------------
485 wxDateTime& SetToCurrent();
487 // set to given time_t value
488 %name(SetTimeT)wxDateTime& Set(time_t timet);
490 // set to given JDN (beware of rounding errors)
491 %name(SetJDN)wxDateTime& Set(double jdn);
493 // set to given time, date = today
494 %name(SetHMS)wxDateTime& Set(wxDateTime_t hour,
495 wxDateTime_t minute = 0,
496 wxDateTime_t second = 0,
497 wxDateTime_t millisec = 0);
499 // from separate values for each component with explicit date
500 // (defaults for month and year are the current values)
501 wxDateTime& Set(wxDateTime_t day,
502 Month month = Inv_Month,
503 int year = Inv_Year, // 1999, not 99 please!
504 wxDateTime_t hour = 0,
505 wxDateTime_t minute = 0,
506 wxDateTime_t second = 0,
507 wxDateTime_t millisec = 0);
509 // resets time to 00:00:00, doesn't change the date
510 wxDateTime& ResetTime();
512 // the following functions don't change the values of the other
513 // fields, i.e. SetMinute() won't change either hour or seconds value
516 wxDateTime& SetYear(int year);
518 wxDateTime& SetMonth(Month month);
519 // set the day of the month
520 wxDateTime& SetDay(wxDateTime_t day);
522 wxDateTime& SetHour(wxDateTime_t hour);
524 wxDateTime& SetMinute(wxDateTime_t minute);
526 wxDateTime& SetSecond(wxDateTime_t second);
528 wxDateTime& SetMillisecond(wxDateTime_t millisecond);
531 // ------------------------------------------------------------------------
532 // calendar calculations
534 // set to the given week day in the same week as this one
535 wxDateTime& SetToWeekDayInSameWeek(WeekDay weekday, WeekFlags flags = Monday_First);
536 wxDateTime GetWeekDayInSameWeek(WeekDay weekday, WeekFlags flags = Monday_First);
538 // set to the next week day following this one
539 wxDateTime& SetToNextWeekDay(WeekDay weekday);
540 wxDateTime GetNextWeekDay(WeekDay weekday);
542 // set to the previous week day before this one
543 wxDateTime& SetToPrevWeekDay(WeekDay weekday);
544 wxDateTime GetPrevWeekDay(WeekDay weekday);
546 // set to Nth occurence of given weekday in the given month of the
547 // given year (time is set to 0), return TRUE on success and FALSE on
548 // failure. n may be positive (1..5) or negative to count from the end
549 // of the month (see helper function SetToLastWeekDay())
550 bool SetToWeekDay(WeekDay weekday,
552 Month month = Inv_Month,
553 int year = Inv_Year);
554 // wxDateTime GetWeekDay(WeekDay weekday,
556 // Month month = Inv_Month,
557 // int year = Inv_Year);
559 // sets to the last weekday in the given month, year
560 bool SetToLastWeekDay(WeekDay weekday,
561 Month month = Inv_Month,
562 int year = Inv_Year);
563 wxDateTime GetLastWeekDay(WeekDay weekday,
564 Month month = Inv_Month,
565 int year = Inv_Year);
567 // sets the date to the given day of the given week in the year,
568 // returns TRUE on success and FALSE if given date doesn't exist (e.g.
570 bool SetToTheWeek(wxDateTime_t numWeek, WeekDay weekday = Mon, WeekFlags flags = Monday_First);
571 wxDateTime GetWeek(wxDateTime_t numWeek, WeekDay weekday = Mon, WeekFlags flags = Monday_First);
573 // sets the date to the last day of the given (or current) month or the
574 // given (or current) year
575 wxDateTime& SetToLastMonthDay(Month month = Inv_Month,
576 int year = Inv_Year);
577 wxDateTime GetLastMonthDay(Month month = Inv_Month,
578 int year = Inv_Year);
580 // sets to the given year day (1..365 or 366)
581 wxDateTime& SetToYearDay(wxDateTime_t yday);
582 wxDateTime GetYearDay(wxDateTime_t yday);
584 // The definitions below were taken verbatim from
586 // http://www.capecod.net/~pbaum/date/date0.htm
588 // (Peter Baum's home page)
590 // definition: The Julian Day Number, Julian Day, or JD of a
591 // particular instant of time is the number of days and fractions of a
592 // day since 12 hours Universal Time (Greenwich mean noon) on January
593 // 1 of the year -4712, where the year is given in the Julian
594 // proleptic calendar. The idea of using this reference date was
595 // originally proposed by Joseph Scalizer in 1582 to count years but
596 // it was modified by 19th century astronomers to count days. One
597 // could have equivalently defined the reference time to be noon of
598 // November 24, -4713 if were understood that Gregorian calendar rules
599 // were applied. Julian days are Julian Day Numbers and are not to be
600 // confused with Julian dates.
602 // definition: The Rata Die number is a date specified as the number
603 // of days relative to a base date of December 31 of the year 0. Thus
604 // January 1 of the year 1 is Rata Die day 1.
606 // get the Julian Day number (the fractional part specifies the time of
607 // the day, related to noon - beware of rounding errors!)
608 double GetJulianDayNumber();
611 // get the Modified Julian Day number: it is equal to JDN - 2400000.5
612 // and so integral MJDs correspond to the midnights (and not noons).
613 // MJD 0 is Nov 17, 1858
614 double GetModifiedJulianDayNumber() const { return GetJDN() - 2400000.5; }
617 // get the Rata Die number
621 // ------------------------------------------------------------------------
624 // transform to any given timezone
625 wxDateTime ToTimezone(const wxDateTime::TimeZone& tz, bool noDST = FALSE);
626 wxDateTime& MakeTimezone(const wxDateTime::TimeZone& tz, bool noDST = FALSE);
628 // transform to GMT/UTC
629 wxDateTime ToGMT(bool noDST = FALSE);
630 wxDateTime& MakeGMT(bool noDST = FALSE);
632 // is daylight savings time in effect at this moment according to the
633 // rules of the specified country?
635 // Return value is > 0 if DST is in effect, 0 if it is not and -1 if
636 // the information is not available (this is compatible with ANSI C)
637 int IsDST(Country country = Country_Default);
641 // ------------------------------------------------------------------------
644 // is the date valid (TRUE even for non initialized objects)?
645 inline bool IsValid() const;
647 // get the number of seconds since the Unix epoch - returns (time_t)-1
648 // if the value is out of range
649 inline time_t GetTicks() const;
651 // get the year (returns Inv_Year if date is invalid)
652 int GetYear(const wxDateTime::TimeZone& tz = LOCAL) const;
654 // get the month (Inv_Month if date is invalid)
655 Month GetMonth(const wxDateTime::TimeZone& tz = LOCAL) const;
657 // get the month day (in 1..31 range, 0 if date is invalid)
658 wxDateTime_t GetDay(const wxDateTime::TimeZone& tz = LOCAL) const;
660 // get the day of the week (Inv_WeekDay if date is invalid)
661 WeekDay GetWeekDay(const wxDateTime::TimeZone& tz = LOCAL) const;
663 // get the hour of the day
664 wxDateTime_t GetHour(const wxDateTime::TimeZone& tz = LOCAL) const;
667 wxDateTime_t GetMinute(const wxDateTime::TimeZone& tz = LOCAL) const;
670 wxDateTime_t GetSecond(const wxDateTime::TimeZone& tz = LOCAL) const;
673 wxDateTime_t GetMillisecond(const wxDateTime::TimeZone& tz = LOCAL) const;
676 // get the day since the year start (1..366, 0 if date is invalid)
677 wxDateTime_t GetDayOfYear(const wxDateTime::TimeZone& tz = LOCAL) const;
678 // get the week number since the year start (1..52 or 53, 0 if date is
680 wxDateTime_t GetWeekOfYear(WeekFlags flags = Monday_First,
681 const wxDateTime::TimeZone& tz = LOCAL) const;
682 // get the week number since the month start (1..5, 0 if date is
684 wxDateTime_t GetWeekOfMonth(WeekFlags flags = Monday_First,
685 const wxDateTime::TimeZone& tz = LOCAL) const;
687 // is this date a work day? This depends on a country, of course,
688 // because the holidays are different in different countries
689 bool IsWorkDay(Country country = Country_Default) const;
691 // is this date later than Gregorian calendar introduction for the
692 // given country (see enum GregorianAdoption)?
694 // NB: this function shouldn't be considered as absolute authority in
695 // the matter. Besides, for some countries the exact date of
696 // adoption of the Gregorian calendar is simply unknown.
697 //bool IsGregorianDate(GregorianAdoption country = Gr_Standard) const;
700 // ------------------------------------------------------------------------
701 // comparison (see also functions below for operator versions)
703 // returns TRUE if the two moments are strictly identical
704 inline bool IsEqualTo(const wxDateTime& datetime) const;
706 // returns TRUE if the date is strictly earlier than the given one
707 inline bool IsEarlierThan(const wxDateTime& datetime) const;
709 // returns TRUE if the date is strictly later than the given one
710 inline bool IsLaterThan(const wxDateTime& datetime) const;
712 // returns TRUE if the date is strictly in the given range
713 inline bool IsStrictlyBetween(const wxDateTime& t1,
714 const wxDateTime& t2) const;
716 // returns TRUE if the date is in the given range
717 inline bool IsBetween(const wxDateTime& t1, const wxDateTime& t2) const;
719 // do these two objects refer to the same date?
720 inline bool IsSameDate(const wxDateTime& dt) const;
722 // do these two objects have the same time?
723 inline bool IsSameTime(const wxDateTime& dt) const;
725 // are these two objects equal up to given timespan?
726 inline bool IsEqualUpTo(const wxDateTime& dt, const wxTimeSpan& ts) const;
729 // ------------------------------------------------------------------------
730 // arithmetics with dates (see also below for more operators)
732 // add a time span (positive or negative)
733 %name(AddTS) wxDateTime& Add(const wxTimeSpan& diff);
734 // add a date span (positive or negative)
735 %name(AddDS) wxDateTime& Add(const wxDateSpan& diff);
737 // subtract a time span (positive or negative)
738 %name(SubtractTS) wxDateTime& Subtract(const wxTimeSpan& diff);
740 // subtract a date span (positive or negative)
741 %name(SubtractDS) wxDateTime& Subtract(const wxDateSpan& diff);
743 // return the difference between two dates
744 wxTimeSpan Subtract(const wxDateTime& dt) const;
748 wxDateTime __add__TS(const wxTimeSpan& other) { return *self + other; }
749 wxDateTime __add__DS(const wxDateSpan& other) { return *self + other; }
751 wxTimeSpan __sub__DT(const wxDateTime& other) { return *self - other; }
752 wxDateTime __sub__TS(const wxTimeSpan& other) { return *self - other; }
753 wxDateTime __sub__DS(const wxDateSpan& other) { return *self - other; }
755 int __cmp__(const wxDateTime* other) {
756 if (! other) return -1;
757 if (*self < *other) return -1;
758 if (*self == *other) return 0;
763 %pragma(python) addtoclass = "
764 def __add__(self, other):
765 if isinstance(other, wxTimeSpanPtr):
766 return self.__add__TS(other)
767 if isinstance(other, wxDateSpanPtr):
768 return self.__add__DS(other)
769 raise TypeError, 'Invalid r.h.s. type for __add__'
770 def __sub__(self, other):
771 if isinstance(other, wxDateTimePtr):
772 return self.__sub__DT(other)
773 if isinstance(other, wxTimeSpanPtr):
774 return self.__sub__TS(other)
775 if isinstance(other, wxDateSpanPtr):
776 return self.__sub__DS(other)
777 raise TypeError, 'Invalid r.h.s. type for __sub__'
780 // ------------------------------------------------------------------------
781 // conversion from text: all conversions from text return -1 on failure,
782 // or the index in the string where the next character following the date
783 // specification (i.e. the one where the scan had to stop) is located.
787 // parse a string in RFC 822 format (found e.g. in mail headers and
788 // having the form "Wed, 10 Feb 1999 19:07:07 +0100")
789 int ParseRfc822Date(const wxString& date) {
791 const wxChar* _date = date;
792 rv = self->ParseRfc822Date(_date);
793 if (rv == NULL) return -1;
798 // parse a date/time in the given format (see strptime(3)), fill in
799 // the missing (in the string) fields with the values of dateDef (by
800 // default, they will not change if they had valid values or will
801 // default to Today() otherwise)
802 int ParseFormat(const wxString& date,
803 const wxString& format = wxPyDateFormatStr,
804 const wxDateTime& dateDef = wxDefaultDateTime) {
806 const wxChar* _date = date;
807 rv = self->ParseFormat(_date, format, dateDef);
808 if (rv == NULL) return -1;
812 // parse a string containing the date/time in "free" format, this
813 // function will try to make an educated guess at the string contents
814 int ParseDateTime(const wxString& datetime) {
816 const wxChar* _datetime = datetime;
817 rv = self->ParseDateTime(_datetime);
818 if (rv == NULL) return -1;
819 return rv - _datetime;
823 // parse a string containing the date only in "free" format (less
824 // flexible than ParseDateTime)
825 int ParseDate(const wxString& date) {
827 const wxChar* _date = date;
828 rv = self->ParseDate(_date);
829 if (rv == NULL) return -1;
833 // parse a string containing the time only in "free" format
834 int ParseTime(const wxString& time) {
836 const wxChar* _time = time;
837 rv = self->ParseTime(_time);
838 if (rv == NULL) return -1;
844 // this function accepts strftime()-like format string (default
845 // argument corresponds to the preferred date and time representation
846 // for the current locale) and returns the string containing the
847 // resulting text representation
848 wxString Format(const wxString& format = wxPyDateFormatStr,
849 const wxDateTime::TimeZone& tz = LOCAL) const;
851 // preferred date representation for the current locale
852 wxString FormatDate() const;
854 // preferred time representation for the current locale
855 wxString FormatTime() const;
857 // returns the string representing the date in ISO 8601 format
859 wxString FormatISODate() const;
861 // returns the string representing the time in ISO 8601 format
863 wxString FormatISOTime() const;
865 %pragma(python) addtoclass = "
867 return '<wxDateTime: \"%s\" at %s>' % ( self.Format(), self.this)
874 //---------------------------------------------------------------------------
875 //---------------------------------------------------------------------------
881 // return the timespan for the given number of seconds
882 static wxTimeSpan Seconds(long sec);
883 static wxTimeSpan Second();
885 // return the timespan for the given number of minutes
886 static wxTimeSpan Minutes(long min);
887 static wxTimeSpan Minute();
889 // return the timespan for the given number of hours
890 static wxTimeSpan Hours(long hours);
891 static wxTimeSpan Hour();
893 // return the timespan for the given number of days
894 static wxTimeSpan Days(long days);
895 static wxTimeSpan Day();
897 // return the timespan for the given number of weeks
898 static wxTimeSpan Weeks(long days);
899 static wxTimeSpan Week();
901 // ------------------------------------------------------------------------
904 // from separate values for each component, date set to 0 (hours are
905 // not restricted to 0..24 range, neither are minutes, seconds or
907 wxTimeSpan(long hours = 0,
910 long milliseconds = 0);
914 // ------------------------------------------------------------------------
915 // arithmetics with time spans
917 // add two timespans together
918 inline wxTimeSpan& Add(const wxTimeSpan& diff);
920 // subtract another timespan
921 inline wxTimeSpan& Subtract(const wxTimeSpan& diff);
923 // multiply timespan by a scalar
924 inline wxTimeSpan& Multiply(int n);
926 // negate the value of the timespan
929 // return the absolute value of the timespan: does _not_ modify the
931 inline wxTimeSpan Abs() const;
934 wxTimeSpan __add__(const wxTimeSpan& other) { return *self + other; }
935 wxTimeSpan __sub__(const wxTimeSpan& other) { return *self - other; }
936 wxTimeSpan __mul__(int n) { return *self * n; }
937 wxTimeSpan __rmul__(int n) { return n * *self; }
938 wxTimeSpan __neg__() { return self->Negate(); }
939 int __cmp__(const wxTimeSpan* other) {
940 if (! other) return -1;
941 if (*self < *other) return -1;
942 if (*self == *other) return 0;
947 // comparaison (see also operator versions below)
948 // ------------------------------------------------------------------------
950 // is the timespan null?
953 // is the timespan positive?
954 bool IsPositive() const;
956 // is the timespan negative?
957 bool IsNegative() const;
959 // are two timespans equal?
960 inline bool IsEqualTo(const wxTimeSpan& ts) const;
962 // compare two timestamps: works with the absolute values, i.e. -2
963 // hours is longer than 1 hour. Also, it will return FALSE if the
964 // timespans are equal in absolute value.
965 inline bool IsLongerThan(const wxTimeSpan& ts) const;
967 // compare two timestamps: works with the absolute values, i.e. 1
968 // hour is shorter than -2 hours. Also, it will return FALSE if the
969 // timespans are equal in absolute value.
970 bool IsShorterThan(const wxTimeSpan& t) const;
972 // ------------------------------------------------------------------------
973 // breaking into days, hours, minutes and seconds
975 // get the max number of weeks in this timespan
976 inline int GetWeeks() const;
977 // get the max number of days in this timespan
978 inline int GetDays() const;
979 // get the max number of hours in this timespan
980 inline int GetHours() const;
981 // get the max number of minutes in this timespan
982 inline int GetMinutes() const;
985 // get the max number of seconds in this timespan
986 inline wxLongLong GetSeconds() const;
987 // get the number of milliseconds in this timespan
988 wxLongLong GetMilliseconds() const;
990 // ------------------------------------------------------------------------
991 // conversion to text
993 // this function accepts strftime()-like format string (default
994 // argument corresponds to the preferred date and time representation
995 // for the current locale) and returns the string containing the
996 // resulting text representation. Notice that only some of format
997 // specifiers valid for wxDateTime are valid for wxTimeSpan: hours,
998 // minutes and seconds make sense, but not "PM/AM" string for example.
999 wxString Format(const wxString& format = wxPyDateFormatStr) const;
1001 // // preferred date representation for the current locale
1002 // wxString FormatDate() const;
1004 // // preferred time representation for the current locale
1005 // wxString FormatTime() const;
1007 // %pragma(python) addtoclass = "
1008 // def __repr__(self):
1009 // return '<wxTimeSpan: \"%s\" at %s>' % ( self.Format(), self.this)
1010 // def __str__(self):
1011 // return self.Format()
1016 //---------------------------------------------------------------------------
1017 //---------------------------------------------------------------------------
1022 // this many years/months/weeks/days
1023 wxDateSpan(int years = 0, int months = 0, int weeks = 0, int days = 0)
1033 // get an object for the given number of days
1034 static wxDateSpan Days(int days);
1035 static wxDateSpan Day();
1037 // get an object for the given number of weeks
1038 static wxDateSpan Weeks(int weeks);
1039 static wxDateSpan Week();
1041 // get an object for the given number of months
1042 static wxDateSpan Months(int mon);
1043 static wxDateSpan Month();
1045 // get an object for the given number of years
1046 static wxDateSpan Years(int years);
1047 static wxDateSpan Year();
1050 // ------------------------------------------------------------------------
1052 // set number of years
1053 wxDateSpan& SetYears(int n);
1054 // set number of months
1055 wxDateSpan& SetMonths(int n);
1056 // set number of weeks
1057 wxDateSpan& SetWeeks(int n);
1058 // set number of days
1059 wxDateSpan& SetDays(int n);
1061 // get number of years
1062 int GetYears() const;
1063 // get number of months
1064 int GetMonths() const;
1065 // get number of weeks
1066 int GetWeeks() const;
1067 // get number of days
1068 int GetDays() const;
1069 // returns 7*GetWeeks() + GetDays()
1070 int GetTotalDays() const;
1073 // ------------------------------------------------------------------------
1075 // add another wxDateSpan to us
1076 inline wxDateSpan& Add(const wxDateSpan& other);
1078 // subtract another wxDateSpan from us
1079 inline wxDateSpan& Subtract(const wxDateSpan& other);
1081 // inverse the sign of this timespan
1082 inline wxDateSpan& Neg();
1084 // multiply all components by a (signed) number
1085 inline wxDateSpan& Multiply(int factor);
1088 wxDateSpan __add__(const wxDateSpan& other) { return *self + other; }
1089 wxDateSpan __sub__(const wxDateSpan& other) { return *self - other; }
1090 wxDateSpan __mul__(int n) { return *self * n; }
1091 wxDateSpan __rmul__(int n) { return n * *self; }
1092 wxDateSpan __neg__() { return self->Negate(); }
1097 //---------------------------------------------------------------------------
1099 long wxGetLocalTime();
1100 long wxGetUTCTime();
1101 long wxGetCurrentTime();
1102 wxLongLong wxGetLocalTimeMillis();
1104 //---------------------------------------------------------------------------
1105 //---------------------------------------------------------------------------
1110 //---------------------------------------------------------------------------