X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/fcd47970b8bef855b447a93fae1d05dcd5a79f11..1a9a6eed360bc9a263f2ea7c0d470953397de531:/include/wx/datetime.h diff --git a/include/wx/datetime.h b/include/wx/datetime.h index 5aac2b16d4..7da0c17a28 100644 --- a/include/wx/datetime.h +++ b/include/wx/datetime.h @@ -17,11 +17,11 @@ #if wxUSE_DATETIME -#ifndef __WXWINCE__ -#include -#else -#include "wx/msw/wince/time.h" -#endif +#ifdef __WXWINCE__ + #include "wx/msw/wince/time.h" +#elif !defined(__WXPALMOS5__) + #include +#endif // OS #include // for INT_MIN @@ -30,6 +30,9 @@ class WXDLLIMPEXP_FWD_BASE wxDateTime; class WXDLLIMPEXP_FWD_BASE wxTimeSpan; class WXDLLIMPEXP_FWD_BASE wxDateSpan; +#ifdef __WXMSW__ +struct _SYSTEMTIME; +#endif #include "wx/dynarray.h" @@ -598,6 +601,12 @@ public: wxDateTime_t minute = 0, wxDateTime_t second = 0, wxDateTime_t millisec = 0); +#ifdef __WXMSW__ + wxDateTime(const struct _SYSTEMTIME& st) + { + SetFromMSWSysTime(st); + } +#endif // default copy ctor ok @@ -912,6 +921,17 @@ public: // pack the date in DOS format unsigned long GetAsDOS() const; + // SYSTEMTIME format + // ------------------------------------------------------------------------ +#ifdef __WXMSW__ + + // convert SYSTEMTIME to wxDateTime + wxDateTime& SetFromMSWSysTime(const struct _SYSTEMTIME&); + + // convert wxDateTime to SYSTEMTIME + void GetAsMSWSysTime(struct _SYSTEMTIME*) const; +#endif // __WXMSW__ + // comparison (see also functions below for operator versions) // ------------------------------------------------------------------------ @@ -1068,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); } @@ -1109,17 +1146,34 @@ public: } const char *ParseFormat(const char *date, - const wxString& format = L"%c", + const wxString& format = "%c", const wxDateTime& dateDef = wxDefaultDateTime) { return ParseFormat(wxString(date), format, dateDef); } - const char *ParseFormat(const char *date, - const char *format = wxDefaultDateTimeFormat, - const wxDateTime& dateDef = wxDefaultDateTime) + + // parse a string containing date, time or both in ISO 8601 format + // + // notice that these functions are new in wx 3.0 and so we don't + // provide compatibility overloads for them + bool ParseISODate(const wxString& date) { - return ParseFormat(wxString(date), wxString(format), dateDef); + wxString::const_iterator end; + return ParseFormat(date, wxS("%Y-%m-%d"), &end) && end == date.end(); + } + + bool ParseISOTime(const wxString& time) + { + wxString::const_iterator end; + return ParseFormat(time, wxS("%H:%M:%S"), &end) && end == time.end(); + } + + bool ParseISOCombined(const wxString& datetime, char sep = 'T') + { + wxString::const_iterator end; + const wxString fmt = wxS("%Y-%m-%d") + wxString(sep) + wxS("%H:%M:%S"); + return ParseFormat(datetime, fmt, &end) && end == datetime.end(); } // parse a string containing the date/time in "free" format, this @@ -1191,15 +1245,20 @@ public: wxString Format(const wxString& format = wxDefaultDateTimeFormat, const TimeZone& tz = Local) const; // preferred date representation for the current locale - wxString FormatDate() const { return Format(_T("%x")); } + wxString FormatDate() const { return Format(wxS("%x")); } // preferred time representation for the current locale - wxString FormatTime() const { return Format(_T("%X")); } + wxString FormatTime() const { return Format(wxS("%X")); } // returns the string representing the date in ISO 8601 format // (YYYY-MM-DD) - wxString FormatISODate() const { return Format(_T("%Y-%m-%d")); } + wxString FormatISODate() const { return Format(wxS("%Y-%m-%d")); } // returns the string representing the time in ISO 8601 format // (HH:MM:SS) - wxString FormatISOTime() const { return Format(_T("%H:%M:%S")); } + wxString FormatISOTime() const { return Format(wxS("%H:%M:%S")); } + // return the combined date time representation in ISO 8601 format; the + // separator character should be 'T' according to the standard but it + // can also be useful to set it to ' ' + wxString FormatISOCombined(char sep = 'T') const + { return FormatISODate() + sep + FormatISOTime(); } // implementation // ------------------------------------------------------------------------ @@ -1385,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 { @@ -2155,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 // ----------------------------------------------------------------------------