X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/94d33c49d11788ae1939e9fffb0b28fe04693f47..303f572ea95a88622fd93b33008de75f756ff068:/wxPython/src/_datetime.i diff --git a/wxPython/src/_datetime.i b/wxPython/src/_datetime.i index c3eb550e3a..4bba1d2124 100644 --- a/wxPython/src/_datetime.i +++ b/wxPython/src/_datetime.i @@ -18,20 +18,20 @@ %{ #include +%} - DECLARE_DEF_STRING2(DateFormatStr, wxT("%c")); - DECLARE_DEF_STRING2(TimeSpanFormatStr, wxT("%H:%M:%S")); - -%} +MAKE_CONST_WXSTRING(DefaultDateTimeFormat); +MAKE_CONST_WXSTRING(DefaultTimeSpanFormat); //--------------------------------------------------------------------------- -%typemap(in) wxDateTime::TimeZone& { +%typemap(in) wxDateTime::TimeZone& (bool temp=false) { $1 = new wxDateTime::TimeZone((wxDateTime::TZ)PyInt_AsLong($input)); + temp = true; } %typemap(python,freearg) wxDateTime::TimeZone& { - if ($1) delete $1; + if (temp$argnum) delete $1; } @@ -58,11 +58,12 @@ //--------------------------------------------------------------------------- +//typedef unsigned short wxDateTime_t; +#define wxDateTime_t int // wxDateTime represents an absolute moment in the time class wxDateTime { public: - typedef unsigned short wxDateTime_t; enum TZ { @@ -257,7 +258,7 @@ public: // or use the default country with any other // Western European countries: we assume that they all follow the same - // DST rules (true or false?) + // DST rules (True or False?) Country_WesternEurope_Start, Country_EEC = Country_WesternEurope_Start, France, @@ -318,7 +319,7 @@ public: // get the current country static Country GetCountry(); - // return TRUE if the country is a West European one (in practice, + // return True if the country is a West European one (in practice, // this means that the same DST rules as for EEC apply) static bool IsWestEuropeanCountry(Country country = Country_Default); @@ -334,7 +335,7 @@ public: // return the current month static Month GetCurrentMonth(Calendar cal = Gregorian); - // returns TRUE if the given year is a leap year in the given calendar + // returns True if the given year is a leap year in the given calendar static bool IsLeapYear(int year = Inv_Year, Calendar cal = Gregorian); // get the century (19 for 1999, 20 for 2000 and -5 for 492 BC) @@ -342,15 +343,15 @@ public: // returns the number of days in this year (356 or 355 for Gregorian // calendar usually :-) - %name(GetNumberOfDaysinYear) - static wxDateTime_t GetNumberOfDays(int year, Calendar cal = Gregorian); + %Rename(GetNumberOfDaysinYear, + static wxDateTime_t, GetNumberOfDays(int year, Calendar cal = Gregorian)); // get the number of the days in the given month (default value for // the year means the current one) - %name(GetNumberOfDaysInMonth) - static wxDateTime_t GetNumberOfDays(Month month, + %Rename(GetNumberOfDaysInMonth, + static wxDateTime_t, GetNumberOfDays(Month month, int year = Inv_Year, - Calendar cal = Gregorian); + Calendar cal = Gregorian)); // get the full (default) or abbreviated month name in the current // locale, returns empty string on error @@ -362,10 +363,25 @@ public: static wxString GetWeekDayName(WeekDay weekday, NameFlags flags = Name_Full); - // get the AM and PM strings in the current locale (may be empty) - static void GetAmPmStrings(wxString *OUTPUT, wxString *OUTPUT); - - // return TRUE if the given country uses DST for this year + %extend { + DocAStr( + GetAmPmStrings, + "GetAmPmStrings() -> (am, pm)", + "Get the AM and PM strings in the current locale (may be empty)", ""); + static PyObject* GetAmPmStrings() { + wxString am; + wxString pm; + wxDateTime::GetAmPmStrings(&am, &pm); + wxPyBlock_t blocked = wxPyBeginBlockThreads(); + PyObject* tup = PyTuple_New(2); + PyTuple_SET_ITEM(tup, 0, wx2PyString(am)); + PyTuple_SET_ITEM(tup, 1, wx2PyString(pm)); + wxPyEndBlockThreads(blocked); + return tup; + } + } + + // return True if the given country uses DST for this year static bool IsDSTApplicable(int year = Inv_Year, Country country = Country_Default); @@ -397,19 +413,19 @@ public: // constructors wxDateTime(); - %name(DateTimeFromTimeT)wxDateTime(time_t timet); - %name(DateTimeFromJDN)wxDateTime(double jdn); - %name(DateTimeFromHMS)wxDateTime(wxDateTime_t hour, + %RenameCtor(DateTimeFromTimeT, wxDateTime(time_t timet)); + %RenameCtor(DateTimeFromJDN, wxDateTime(double jdn)); + %RenameCtor(DateTimeFromHMS, wxDateTime(wxDateTime_t hour, wxDateTime_t minute = 0, wxDateTime_t second = 0, - wxDateTime_t millisec = 0); - %name(DateTimeFromDMY)wxDateTime(wxDateTime_t day, + wxDateTime_t millisec = 0)); + %RenameCtor(DateTimeFromDMY, wxDateTime(wxDateTime_t day, Month month = Inv_Month, int year = Inv_Year, wxDateTime_t hour = 0, wxDateTime_t minute = 0, wxDateTime_t second = 0, - wxDateTime_t millisec = 0); + wxDateTime_t millisec = 0)); ~wxDateTime(); @@ -419,16 +435,16 @@ public: wxDateTime& SetToCurrent(); // set to given time_t value - %name(SetTimeT)wxDateTime& Set(time_t timet); + %Rename(SetTimeT, wxDateTime&, Set(time_t timet)); // set to given JDN (beware of rounding errors) - %name(SetJDN)wxDateTime& Set(double jdn); + %Rename(SetJDN, wxDateTime&, Set(double jdn)); // set to given time, date = today - %name(SetHMS)wxDateTime& Set(wxDateTime_t hour, + %Rename(SetHMS, wxDateTime&, Set(wxDateTime_t hour, wxDateTime_t minute = 0, wxDateTime_t second = 0, - wxDateTime_t millisec = 0); + wxDateTime_t millisec = 0)); // from separate values for each component with explicit date // (defaults for month and year are the current values) @@ -478,7 +494,7 @@ public: wxDateTime GetPrevWeekDay(WeekDay weekday); // set to Nth occurence of given weekday in the given month of the - // given year (time is set to 0), return TRUE on success and FALSE on + // given year (time is set to 0), return True on success and False on // failure. n may be positive (1..5) or negative to count from the end // of the month (see helper function SetToLastWeekDay()) bool SetToWeekDay(WeekDay weekday, @@ -499,11 +515,22 @@ public: int year = Inv_Year); // sets the date to the given day of the given week in the year, - // returns TRUE on success and FALSE if given date doesn't exist (e.g. + // returns True on success and False if given date doesn't exist (e.g. // numWeek is > 53) bool SetToTheWeek(wxDateTime_t numWeek, WeekDay weekday = Mon, WeekFlags flags = Monday_First); wxDateTime GetWeek(wxDateTime_t numWeek, WeekDay weekday = Mon, WeekFlags flags = Monday_First); + %pythoncode { + SetToTheWeek = wx._deprecated(SetToTheWeek, "SetToTheWeek is deprecated, use (static) SetToWeekOfYear instead") + GetWeek = wx._deprecated(GetWeek, "GetWeek is deprecated, use GetWeekOfYear instead") + } + + // returns the date corresponding to the given week day of the given + // week (in ISO notation) of the specified year + static wxDateTime SetToWeekOfYear(int year, + wxDateTime_t numWeek, + WeekDay weekday = Mon); + // sets the date to the last day of the given (or current) month or the // given (or current) year wxDateTime& SetToLastMonthDay(Month month = Inv_Month, @@ -556,12 +583,12 @@ public: // timezone stuff // transform to any given timezone - wxDateTime ToTimezone(const wxDateTime::TimeZone& tz, bool noDST = FALSE); - wxDateTime& MakeTimezone(const wxDateTime::TimeZone& tz, bool noDST = FALSE); + wxDateTime ToTimezone(const wxDateTime::TimeZone& tz, bool noDST = false); + wxDateTime& MakeTimezone(const wxDateTime::TimeZone& tz, bool noDST = false); // transform to GMT/UTC - wxDateTime ToGMT(bool noDST = FALSE); - wxDateTime& MakeGMT(bool noDST = FALSE); + wxDateTime ToGMT(bool noDST = false); + wxDateTime& MakeGMT(bool noDST = false); // is daylight savings time in effect at this moment according to the // rules of the specified country? @@ -575,9 +602,12 @@ public: // ------------------------------------------------------------------------ // accessors - // is the date valid (TRUE even for non initialized objects)? + // is the date valid (True even for non initialized objects)? inline bool IsValid() const; + %pythoncode { Ok = IsValid } + %pythoncode { def __nonzero__(self): return self.Ok() }; + // get the number of seconds since the Unix epoch - returns (time_t)-1 // if the value is out of range inline time_t GetTicks() const; @@ -634,20 +664,20 @@ public: // ------------------------------------------------------------------------ // comparison (see also functions below for operator versions) - // returns TRUE if the two moments are strictly identical + // returns True if the two moments are strictly identical inline bool IsEqualTo(const wxDateTime& datetime) const; - // returns TRUE if the date is strictly earlier than the given one + // returns True if the date is strictly earlier than the given one inline bool IsEarlierThan(const wxDateTime& datetime) const; - // returns TRUE if the date is strictly later than the given one + // returns True if the date is strictly later than the given one inline bool IsLaterThan(const wxDateTime& datetime) const; - // returns TRUE if the date is strictly in the given range + // returns True if the date is strictly in the given range inline bool IsStrictlyBetween(const wxDateTime& t1, const wxDateTime& t2) const; - // returns TRUE if the date is in the given range + // returns True if the date is in the given range inline bool IsBetween(const wxDateTime& t1, const wxDateTime& t2) const; // do these two objects refer to the same date? @@ -664,15 +694,15 @@ public: // arithmetics with dates (see also below for more operators) // add a time span (positive or negative) - %name(AddTS) wxDateTime& Add(const wxTimeSpan& diff); + %Rename(AddTS, wxDateTime&, Add(const wxTimeSpan& diff)); // add a date span (positive or negative) - %name(AddDS) wxDateTime& Add(const wxDateSpan& diff); + %Rename(AddDS, wxDateTime&, Add(const wxDateSpan& diff)); // subtract a time span (positive or negative) - %name(SubtractTS) wxDateTime& Subtract(const wxTimeSpan& diff); + %Rename(SubtractTS, wxDateTime&, Subtract(const wxTimeSpan& diff)); // subtract a date span (positive or negative) - %name(SubtractDS) wxDateTime& Subtract(const wxDateSpan& diff); + %Rename(SubtractDS, wxDateTime&, Subtract(const wxDateSpan& diff)); // return the difference between two dates wxTimeSpan Subtract(const wxDateTime& dt) const; @@ -691,14 +721,15 @@ public: inline wxDateTime& operator-=(const wxDateSpan& diff); +// inline bool operator<(const wxDateTime& dt) const; +// inline bool operator<=(const wxDateTime& dt) const; +// inline bool operator>(const wxDateTime& dt) const; +// inline bool operator>=(const wxDateTime& dt) const; +// inline bool operator==(const wxDateTime& dt) const; +// inline bool operator!=(const wxDateTime& dt) const; + %nokwargs __add__; %nokwargs __sub__; - %nokwargs __lt__; - %nokwargs __le__; - %nokwargs __gt__; - %nokwargs __ge__; - %nokwargs __eq__; - %nokwargs __ne__; %extend { wxDateTime __add__(const wxTimeSpan& other) { return *self + other; } wxDateTime __add__(const wxDateSpan& other) { return *self + other; } @@ -707,14 +738,39 @@ public: wxDateTime __sub__(const wxTimeSpan& other) { return *self - other; } wxDateTime __sub__(const wxDateSpan& other) { return *self - other; } - bool __lt__(const wxDateTime& other) { return *self < other; } - bool __le__(const wxDateTime& other) { return *self <= other; } - bool __gt__(const wxDateTime& other) { return *self > other; } - bool __ge__(const wxDateTime& other) { return *self >= other; } - bool __eq__(const wxDateTime& other) { return *self == other; } - bool __ne__(const wxDateTime& other) { return *self != other; } + // These fall back to just comparing pointers if other is NULL, or if + // either operand is invalid. This allows Python comparrisons to None + // to not assert and to return a sane value for the compare. + bool __lt__(const wxDateTime* other) { + if (!other || !self->IsValid() || !other->IsValid()) return self < other; + return (*self < *other); + } + bool __le__(const wxDateTime* other) { + if (!other || !self->IsValid() || !other->IsValid()) return self <= other; + return (*self <= *other); + } + bool __gt__(const wxDateTime* other) { + if (!other || !self->IsValid() || !other->IsValid()) return self > other; + return (*self > *other); + } + bool __ge__(const wxDateTime* other) { + if (!other || !self->IsValid() || !other->IsValid()) return self >= other; + return (*self >= *other); + } + + bool __eq__(const wxDateTime* other) { + if (!other || !self->IsValid() || !other->IsValid()) return self == other; + return (*self == *other); + } + bool __ne__(const wxDateTime* other) { + if (!other || !self->IsValid() || !other->IsValid()) return self != other; + return (*self != *other); + } } + + + // ------------------------------------------------------------------------ // conversion from text: all conversions from text return -1 on failure, @@ -739,7 +795,7 @@ public: // default, they will not change if they had valid values or will // default to Today() otherwise) int ParseFormat(const wxString& date, - const wxString& format = wxPyDateFormatStr, + const wxString& format = wxPyDefaultDateTimeFormat, const wxDateTime& dateDef = wxDefaultDateTime) { const wxChar* rv; const wxChar* _date = date; @@ -784,7 +840,7 @@ public: // argument corresponds to the preferred date and time representation // for the current locale) and returns the string containing the // resulting text representation - wxString Format(const wxString& format = wxPyDateFormatStr, + wxString Format(const wxString& format = wxPyDefaultDateTimeFormat, const wxDateTime::TimeZone& tz = LOCAL_TZ) const; // preferred date representation for the current locale @@ -803,9 +859,15 @@ public: %pythoncode { def __repr__(self): - return '' % ( self.Format(), self.this) + if self.IsValid(): + return '' % ( self.Format(), self.this) + else: + return '' % self.this def __str__(self): - return self.Format() + if self.IsValid(): + return self.Format() + else: + return "INVALID DateTime" } }; @@ -883,12 +945,13 @@ public: wxTimeSpan __sub__(const wxTimeSpan& other) { return *self - other; } wxTimeSpan __mul__(int n) { return *self * n; } wxTimeSpan __rmul__(int n) { return n * *self; } - bool __lt__(const wxTimeSpan& other) { return *self < other; } - bool __le__(const wxTimeSpan& other) { return *self <= other; } - bool __gt__(const wxTimeSpan& other) { return *self > other; } - bool __ge__(const wxTimeSpan& other) { return *self >= other; } - bool __eq__(const wxTimeSpan& other) { return *self == other; } - bool __ne__(const wxTimeSpan& other) { return *self != other; } + + bool __lt__(const wxTimeSpan* other) { return other ? (*self < *other) : false; } + bool __le__(const wxTimeSpan* other) { return other ? (*self <= *other) : false; } + bool __gt__(const wxTimeSpan* other) { return other ? (*self > *other) : true; } + bool __ge__(const wxTimeSpan* other) { return other ? (*self >= *other) : true; } + bool __eq__(const wxTimeSpan* other) { return other ? (*self == *other) : false; } + bool __ne__(const wxTimeSpan* other) { return other ? (*self != *other) : true; } } @@ -908,12 +971,12 @@ public: inline bool IsEqualTo(const wxTimeSpan& ts) const; // compare two timestamps: works with the absolute values, i.e. -2 - // hours is longer than 1 hour. Also, it will return FALSE if the + // hours is longer than 1 hour. Also, it will return False if the // timespans are equal in absolute value. inline bool IsLongerThan(const wxTimeSpan& ts) const; // compare two timestamps: works with the absolute values, i.e. 1 - // hour is shorter than -2 hours. Also, it will return FALSE if the + // hour is shorter than -2 hours. Also, it will return False if the // timespans are equal in absolute value. bool IsShorterThan(const wxTimeSpan& t) const; @@ -944,11 +1007,11 @@ public: // resulting text representation. Notice that only some of format // specifiers valid for wxDateTime are valid for wxTimeSpan: hours, // minutes and seconds make sense, but not "PM/AM" string for example. - wxString Format(const wxString& format = wxPyTimeSpanFormatStr) const; + wxString Format(const wxString& format = wxPyDefaultTimeSpanFormat) const; %pythoncode { def __repr__(self): - return '' % ( self.Format(), self.this) + return '' % ( self.Format(), self.this) def __str__(self): return self.Format() } @@ -1068,12 +1131,14 @@ public: wxDateSpan __sub__(const wxDateSpan& other) { return *self - other; } wxDateSpan __mul__(int n) { return *self * n; } wxDateSpan __rmul__(int n) { return n * *self; } -// bool __lt__(const wxDateSpan& other) { return *self < other; } -// bool __le__(const wxDateSpan& other) { return *self <= other; } -// bool __gt__(const wxDateSpan& other) { return *self > other; } -// bool __ge__(const wxDateSpan& other) { return *self >= other; } - bool __eq__(const wxDateSpan& other) { return *self == other; } - bool __ne__(const wxDateSpan& other) { return *self != other; } + +// bool __lt__(const wxDateSpan* other) { return other ? (*self < *other) : false; } +// bool __le__(const wxDateSpan* other) { return other ? (*self <= *other) : false; } +// bool __gt__(const wxDateSpan* other) { return other ? (*self > *other) : true; } +// bool __ge__(const wxDateSpan* other) { return other ? (*self >= *other) : true; } + + bool __eq__(const wxDateSpan* other) { return other ? (*self == *other) : false; } + bool __ne__(const wxDateSpan* other) { return other ? (*self != *other) : true; } } }; @@ -1089,5 +1154,9 @@ long wxGetUTCTime(); long wxGetCurrentTime(); wxLongLong wxGetLocalTimeMillis(); +%immutable; +const wxDateTime wxDefaultDateTime; +%mutable; + //--------------------------------------------------------------------------- //---------------------------------------------------------------------------