X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/154014d68152d7dcca9ee08c593a3d89fc8fe488..e2cb366f612460ba70fb12560c112fef2d8389dd:/include/wx/datetime.h diff --git a/include/wx/datetime.h b/include/wx/datetime.h index 3fddea3f9a..6e4341618a 100644 --- a/include/wx/datetime.h +++ b/include/wx/datetime.h @@ -706,7 +706,7 @@ public: wxDateTime& SetToPrevWeekDay(WeekDay weekday); inline wxDateTime GetPrevWeekDay(WeekDay weekday) const; - // set to Nth occurence of given weekday in the given month of the + // set to Nth occurrence of given weekday in the given month of the // 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()) @@ -1088,22 +1088,39 @@ public: // the missing (in the string) fields with the values of dateDef (by // default, they will not change if they had valid values or will // default to Today() otherwise) + + // notice that we unfortunately need all those overloads because we use + // the type of the date string to select the return value of the + // function: it's wchar_t if a wide string is passed for compatibility + // with the code doing "const wxChar *p = dt.ParseFormat(_T("..."))", + // but char* in all other cases for compatibility with ANSI build which + // allowed code like "const char *p = dt.ParseFormat("...")" + // + // so we need wchar_t overload and now passing s.c_str() as first + // argument is ambiguous because it's convertible to both wxString and + // wchar_t* and now it's passing char* which becomes ambiguous as it is + // convertible to both wxString and wxCStrData hence we need char* + // overload too + // + // and to make our life more miserable we also pay for having the + // optional dateDef parameter: as it's almost never used, we want to + // allow people to omit it when specifying the end iterator output + // parameter but we still have to allow specifying dateDef too, so we + // need another overload for this + // + // FIXME: all this mess could be avoided by using some class similar to + // wxFormatString, i.e. remembering string [pointer] of any type + // and convertible to either char* or wchar_t* as wxCStrData and + // having only 1 (or 2, because of the last paragraph above) + // overload taking it, see #9560 const char *ParseFormat(const wxString& date, const wxString& format = wxDefaultDateTimeFormat, const wxDateTime& dateDef = wxDefaultDateTime, wxString::const_iterator *end = NULL); const char *ParseFormat(const wxString& date, - const char *format = wxDefaultDateTimeFormat, - const wxDateTime& dateDef = wxDefaultDateTime, - wxString::const_iterator *end = NULL) - { - return ParseFormat(date, wxString(format), dateDef, end); - } - - const char *ParseFormat(const wxString& date, - const wxString& format = wxDefaultDateTimeFormat, - wxString::const_iterator *end = NULL) + const wxString& format, + wxString::const_iterator *end) { return ParseFormat(date, format, wxDefaultDateTime, end); } @@ -1135,12 +1152,6 @@ public: return ParseFormat(wxString(date), format, dateDef); } - const char *ParseFormat(const char *date, - const char *format = wxDefaultDateTimeFormat, - const wxDateTime& dateDef = wxDefaultDateTime) - { - return ParseFormat(wxString(date), wxString(format), dateDef); - } // parse a string containing date, time or both in ISO 8601 format // @@ -1259,7 +1270,7 @@ public: inline wxLongLong GetValue() const; // a helper function to get the current time_t - static time_t GetTimeNow() { return time((time_t *)NULL); } + static time_t GetTimeNow() { return time(NULL); } // another one to get the current time broken down static struct tm *GetTmNow() @@ -1433,7 +1444,7 @@ public: // compare two timestamps: works with the absolute values, i.e. 1 // 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 { return !IsLongerThan(t); } + bool IsShorterThan(const wxTimeSpan& t) const; inline bool operator<(const wxTimeSpan &ts) const { @@ -2203,6 +2214,11 @@ inline bool wxTimeSpan::IsLongerThan(const wxTimeSpan& ts) const return GetValue().Abs() > ts.GetValue().Abs(); } +inline bool wxTimeSpan::IsShorterThan(const wxTimeSpan& ts) const +{ + return GetValue().Abs() < ts.GetValue().Abs(); +} + // ---------------------------------------------------------------------------- // wxDateSpan // ----------------------------------------------------------------------------