make wxDateTime::ParseXXX() functions char*-friendly

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@51059 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2008-01-07 00:17:45 +00:00
parent b7c746d017
commit 71ebd60b06
5 changed files with 382 additions and 235 deletions

View File

@@ -355,6 +355,14 @@ format. As an example, \helpref{ParseDateTime}{wxdatetimeparsedatetime} can
parse the strings such as {\tt "tomorrow"}, {\tt "March first"} and even parse the strings such as {\tt "tomorrow"}, {\tt "March first"} and even
{\tt "next Sunday"}. {\tt "next Sunday"}.
Finally notice that each of the parsing functions is available in several
overloads: if the input string is a narrow (\texttt{char *}) string, then a
narrow pointer is returned. If the input string is a wide string, a wide char
pointer is returned. Finally, if the input parameter is a wxString, a narrow
char pointer is also returned for backwards compatibility but there is also an
additional argument of wxString::const\_iterator type in which, if it is not
\NULL, an iterator pointing to the end of the scanned string part is returned.
\helpref{ParseRfc822Date}{wxdatetimeparserfc822date}\\ \helpref{ParseRfc822Date}{wxdatetimeparserfc822date}\\
\helpref{ParseFormat}{wxdatetimeparseformat}\\ \helpref{ParseFormat}{wxdatetimeparseformat}\\
\helpref{ParseDateTime}{wxdatetimeparsedatetime}\\ \helpref{ParseDateTime}{wxdatetimeparsedatetime}\\
@@ -1169,9 +1177,13 @@ as wxTimeSpan.
\membersection{wxDateTime::ParseRfc822Date}\label{wxdatetimeparserfc822date} \membersection{wxDateTime::ParseRfc822Date}\label{wxdatetimeparserfc822date}
\func{const wxChar *}{ParseRfc822Date}{\param{const wxChar* }{date}} \func{const char *}{ParseRfc822Date}{\param{const wxString\& }{date}, \param{wxString::const\_iterator *}{end = \NULL}}
Parses the string {\it date} looking for a date formatted according to the RFC \func{const char *}{ParseRfc822Date}{\param{const char* }{date}}
\func{const wchar\_t *}{ParseRfc822Date}{\param{const wchar\_t* }{date}}
Parses the string \arg{date} looking for a date formatted according to the RFC
822 in it. The exact description of this format may, of course, be found in 822 in it. The exact description of this format may, of course, be found in
the RFC (section $5$), but, briefly, this is the format used in the headers of the RFC (section $5$), but, briefly, this is the format used in the headers of
Internet email messages and one of the most common strings expressing date in Internet email messages and one of the most common strings expressing date in
@@ -1190,7 +1202,11 @@ free ways, you should use \helpref{ParseDateTime}{wxdatetimeparsedatetime} or
\membersection{wxDateTime::ParseFormat}\label{wxdatetimeparseformat} \membersection{wxDateTime::ParseFormat}\label{wxdatetimeparseformat}
\func{const wxChar *}{ParseFormat}{\param{const wxChar *}{date}, \param{const wxChar *}{format = wxDefaultDateTimeFormat}, \param{const wxDateTime\& }{dateDef = wxDefaultDateTime}} \func{const char *}{ParseFormat}{\param{const wxString\& }{date}, \param{const wxString\& }{format = wxDefaultDateTimeFormat}, \param{const wxDateTime\& }{dateDef = wxDefaultDateTime}, \param{wxString::const\_iterator *}{end = \NULL}}
\func{const char *}{ParseFormat}{\param{const char *}{date}, \param{const wxString\& }{format = wxDefaultDateTimeFormat}, \param{const wxDateTime\& }{dateDef = wxDefaultDateTime}}
\func{const wchar\_t *}{ParseFormat}{\param{const wchar\_t *}{date}, \param{const wxString\& }{format = wxDefaultDateTimeFormat}, \param{const wxDateTime\& }{dateDef = wxDefaultDateTime}}
This function parses the string {\it date} according to the given This function parses the string {\it date} according to the given
{\it format}. The system {\tt strptime(3)} function is used whenever available, {\it format}. The system {\tt strptime(3)} function is used whenever available,
@@ -1215,7 +1231,11 @@ the character which stopped the scan.
\membersection{wxDateTime::ParseDateTime}\label{wxdatetimeparsedatetime} \membersection{wxDateTime::ParseDateTime}\label{wxdatetimeparsedatetime}
\func{const wxChar *}{ParseDateTime}{\param{const wxChar *}{datetime}} \func{const char *}{ParseDateTime}{\param{const wxString\& }{datetime}, \param{wxString::const\_iterator *}{end = \NULL}}
\func{const char *}{ParseDateTime}{\param{const char *}{datetime}}
\func{const wchar\_t *}{ParseDateTime}{\param{const wchar\_t *}{datetime}}
Parses the string {\it datetime} containing the date and time in free format. Parses the string {\it datetime} containing the date and time in free format.
This function tries as hard as it can to interpret the given string as date This function tries as hard as it can to interpret the given string as date
@@ -1229,7 +1249,11 @@ the character which stopped the scan.
\membersection{wxDateTime::ParseDate}\label{wxdatetimeparsedate} \membersection{wxDateTime::ParseDate}\label{wxdatetimeparsedate}
\func{const wxChar *}{ParseDate}{\param{const wxChar *}{date}} \func{const char *}{ParseDate}{\param{const wxString\& }{date}, \param{wxString::const\_iterator *}{end = \NULL}}
\func{const char *}{ParseDate}{\param{const char *}{date}}
\func{const wchar\_t *}{ParseDate}{\param{const wchar\_t *}{date}}
This function is like \helpref{ParseDateTime}{wxdatetimeparsedatetime}, but it This function is like \helpref{ParseDateTime}{wxdatetimeparsedatetime}, but it
only allows the date to be specified. It is thus less flexible then only allows the date to be specified. It is thus less flexible then
@@ -1242,7 +1266,11 @@ the character which stopped the scan.
\membersection{wxDateTime::ParseTime}\label{wxdatetimeparsetime} \membersection{wxDateTime::ParseTime}\label{wxdatetimeparsetime}
\func{const wxChar *}{ParseTime}{\param{const wxChar *}{time}} \func{const char *}{ParseTime}{\param{const wxString\& }{time}, \param{wxString::const\_iterator *}{end = \NULL}}
\func{const char *}{ParseTime}{\param{const char *}{time}}
\func{const wchar\_t *}{ParseTime}{\param{const wchar\_t *}{time}}
This functions is like \helpref{ParseDateTime}{wxdatetimeparsedatetime}, but This functions is like \helpref{ParseDateTime}{wxdatetimeparsedatetime}, but
only allows the time to be specified in the input string. only allows the time to be specified in the input string.

View File

@@ -124,8 +124,8 @@ WXDLLIMPEXP_BASE struct tm *wxGmtime_r(const time_t*, struct tm*);
// wxInvalidDateTime) // wxInvalidDateTime)
class WXDLLIMPEXP_FWD_BASE wxDateTime; class WXDLLIMPEXP_FWD_BASE wxDateTime;
extern WXDLLIMPEXP_DATA_BASE(const wxChar*) wxDefaultDateTimeFormat; extern WXDLLIMPEXP_DATA_BASE(const char *) wxDefaultDateTimeFormat;
extern WXDLLIMPEXP_DATA_BASE(const wxChar*) wxDefaultTimeSpanFormat; extern WXDLLIMPEXP_DATA_BASE(const char *) wxDefaultTimeSpanFormat;
extern WXDLLIMPEXP_DATA_BASE(const wxDateTime) wxDefaultDateTime; extern WXDLLIMPEXP_DATA_BASE(const wxDateTime) wxDefaultDateTime;
#define wxInvalidDateTime wxDefaultDateTime #define wxInvalidDateTime wxDefaultDateTime
@@ -1037,36 +1037,145 @@ public:
// conversion to/from text: all conversions from text return the pointer to // conversion to/from text: all conversions from text return the pointer to
// the next character following the date specification (i.e. the one where // the next character following the date specification (i.e. the one where
// the scan had to stop) or NULL on failure; for the versions returning // the scan had to stop) or NULL on failure; for the versions taking
// iterators, end iterator is returned instead of NULL // wxString or wxCStrData, we don't know if the user code needs char* or
// wchar_t* pointer and so we return char* one for compatibility with the
// existing ANSI code and also return iterator in another output parameter
// (it will be equal to end if the entire string was parsed)
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
// parse a string in RFC 822 format (found e.g. in mail headers and // parse a string in RFC 822 format (found e.g. in mail headers and
// having the form "Wed, 10 Feb 1999 19:07:07 +0100") // having the form "Wed, 10 Feb 1999 19:07:07 +0100")
wxString::const_iterator ParseRfc822Date(const wxString& date); const char *ParseRfc822Date(const wxString& date,
wxString::const_iterator *end = NULL);
const char *ParseRfc822Date(const wxCStrData& date,
wxString::const_iterator *end = NULL)
{
return ParseRfc822Date(date.AsString(), end);
}
const wchar_t *ParseRfc822Date(const wchar_t* date) const wchar_t *ParseRfc822Date(const wchar_t* date)
{ {
return ReturnEndAsWidePtr(&wxDateTime::ParseRfc822Date, date);
} }
const char *ParseRfc822Date(const char* date) const char *ParseRfc822Date(const char* date)
{ {
return ParseRfc822Date(wxString(date));
} }
// parse a date/time in the given format (see strptime(3)), fill in // parse a date/time in the given format (see strptime(3)), fill in
// the missing (in the string) fields with the values of dateDef (by // 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, they will not change if they had valid values or will
// default to Today() otherwise) // default to Today() otherwise)
const wxChar *ParseFormat(const wxChar *date, const char *ParseFormat(const wxString& date,
const wxString& format = wxDefaultDateTimeFormat, const wxString& format = wxDefaultDateTimeFormat,
const wxDateTime& dateDef = wxDefaultDateTime); 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)
{
return ParseFormat(date, format, wxDefaultDateTime, end);
}
const char *ParseFormat(const wxCStrData& date,
const wxString& format = wxDefaultDateTimeFormat,
const wxDateTime& dateDef = wxDefaultDateTime,
wxString::const_iterator *end = NULL)
{
return ParseFormat(date.AsString(), format, dateDef, end);
}
const wchar_t *ParseFormat(const wchar_t *date,
const wxString& format = wxDefaultDateTimeFormat,
const wxDateTime& dateDef = wxDefaultDateTime)
{
const wxString datestr(date);
wxString::const_iterator end;
if ( !ParseFormat(datestr, format, dateDef, &end) )
return NULL;
return date + (end - datestr.begin());
}
const char *ParseFormat(const char *date,
const wxString& format = wxDefaultDateTimeFormat,
const wxDateTime& dateDef = wxDefaultDateTime)
{
return ParseFormat(wxString(date), format, dateDef);
}
// parse a string containing the date/time in "free" format, this // parse a string containing the date/time in "free" format, this
// function will try to make an educated guess at the string contents // function will try to make an educated guess at the string contents
const wxChar *ParseDateTime(const wxChar *datetime); const char *ParseDateTime(const wxString& datetime,
wxString::const_iterator *end = NULL);
const char *ParseDateTime(const wxCStrData& datetime,
wxString::const_iterator *end = NULL)
{
return ParseDateTime(datetime.AsString(), end);
}
const wchar_t *ParseDateTime(const wchar_t *datetime)
{
return ReturnEndAsWidePtr(&wxDateTime::ParseDateTime, datetime);
}
const char *ParseDateTime(const char *datetime)
{
return ParseDateTime(wxString(datetime));
}
// parse a string containing the date only in "free" format (less // parse a string containing the date only in "free" format (less
// flexible than ParseDateTime) // flexible than ParseDateTime)
const wxChar *ParseDate(const wxChar *date); const char *ParseDate(const wxString& date,
wxString::const_iterator *end = NULL);
const char *ParseDate(const wxCStrData& date,
wxString::const_iterator *end = NULL)
{
return ParseDate(date.AsString(), end);
}
const wchar_t *ParseDate(const wchar_t *date)
{
return ReturnEndAsWidePtr(&wxDateTime::ParseDate, date);
}
const char *ParseDate(const char *date)
{
return ParseDate(wxString(date));
}
// parse a string containing the time only in "free" format // parse a string containing the time only in "free" format
const wxChar *ParseTime(const wxChar *time); const char *ParseTime(const wxString& time,
wxString::const_iterator *end = NULL);
const char *ParseTime(const wxCStrData& time,
wxString::const_iterator *end = NULL)
{
return ParseTime(time.AsString(), end);
}
const wchar_t *ParseTime(const wchar_t *time)
{
return ReturnEndAsWidePtr(&wxDateTime::ParseTime, time);
}
const char *ParseTime(const char *time)
{
return ParseTime(wxString(time));
}
// this function accepts strftime()-like format string (default // this function accepts strftime()-like format string (default
// argument corresponds to the preferred date and time representation // argument corresponds to the preferred date and time representation
@@ -1108,6 +1217,23 @@ public:
static struct tm *GetTmNow(struct tm *tmstruct); static struct tm *GetTmNow(struct tm *tmstruct);
private: private:
// helper function for defining backward-compatible wrappers for code
// using wchar_t* pointer instead of wxString iterators
typedef
const char *(wxDateTime::*StringMethod)(const wxString& s,
wxString::const_iterator *end);
const wchar_t *ReturnEndAsWidePtr(StringMethod func, const wchar_t *p)
{
const wxString s(p);
wxString::const_iterator end;
if ( !(this->*func)(s, &end) )
return NULL;
return p + (end - s.begin());
}
// the current country - as it's the same for all program objects (unless // the current country - as it's the same for all program objects (unless
// it runs on a _really_ big cluster system :-), this is a static member: // it runs on a _really_ big cluster system :-), this is a static member:
// see SetCountry() and GetCountry() // see SetCountry() and GetCountry()

View File

@@ -806,8 +806,7 @@ int wxCmdLineParser::Parse(bool showUsage)
case wxCMD_LINE_VAL_DATE: case wxCMD_LINE_VAL_DATE:
{ {
wxDateTime dt; wxDateTime dt;
// FIXME-UTF8: ParseDate API will need changes const char *res = dt.ParseDate(value);
const wxChar *res = dt.ParseDate(value.c_str());
if ( !res || *res ) if ( !res || *res )
{ {
errorMsg << wxString::Format(_("Option '%s': '%s' cannot be converted to a date."), errorMsg << wxString::Format(_("Option '%s': '%s' cannot be converted to a date."),

View File

@@ -368,8 +368,8 @@ static const wxDateTime::wxDateTime_t gs_cumulatedDays[2][MONTHS_IN_YEAR] =
// global data // global data
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
const wxChar * wxDefaultDateTimeFormat = wxT("%c"); const char *wxDefaultDateTimeFormat = "%c";
const wxChar * wxDefaultTimeSpanFormat = wxT("%H:%M:%S"); const char *wxDefaultTimeSpanFormat = "%H:%M:%S";
// in the fine tradition of ANSI C we use our equivalent of (time_t)-1 to // in the fine tradition of ANSI C we use our equivalent of (time_t)-1 to
// indicate an invalid wxDateTime object // indicate an invalid wxDateTime object
@@ -511,13 +511,13 @@ static wxString CallStrftime(const wxString& format, const tm* tm)
#endif #endif
// Unicode-friendly strptime() wrapper // Unicode-friendly strptime() wrapper
static const wxChar * static const wxStringCharType *
CallStrptime(const wxChar *input, const char *fmt, tm *tm) CallStrptime(const wxStringCharType *input, const char *fmt, tm *tm)
{ {
// the problem here is that strptime() returns pointer into the string we // the problem here is that strptime() returns pointer into the string we
// passed to it while we're really interested in the pointer into the // passed to it while we're really interested in the pointer into the
// original, Unicode, string so we try to transform the pointer back // original, Unicode, string so we try to transform the pointer back
#if wxUSE_UNICODE #if wxUSE_UNICODE_WCHAR
wxCharBuffer inputMB(wxConvertWX2MB(input)); wxCharBuffer inputMB(wxConvertWX2MB(input));
#else // ASCII #else // ASCII
const char * const inputMB = input; const char * const inputMB = input;
@@ -527,7 +527,7 @@ CallStrptime(const wxChar *input, const char *fmt, tm *tm)
if ( !result ) if ( !result )
return NULL; return NULL;
#if wxUSE_UNICODE #if wxUSE_UNICODE_WCHAR
// FIXME: this is wrong in presence of surrogates &c // FIXME: this is wrong in presence of surrogates &c
return input + (result - inputMB.data()); return input + (result - inputMB.data());
#else // ASCII #else // ASCII
@@ -643,7 +643,9 @@ struct tm *wxDateTime::GetTmNow(struct tm *tmstruct)
} }
// scans all digits (but no more than len) and returns the resulting number // scans all digits (but no more than len) and returns the resulting number
static bool GetNumericToken(size_t len, const wxChar*& p, unsigned long *number) static bool GetNumericToken(size_t len,
const wxStringCharType*& p,
unsigned long *number)
{ {
size_t n = 1; size_t n = 1;
wxString s; wxString s;
@@ -659,7 +661,7 @@ static bool GetNumericToken(size_t len, const wxChar*& p, unsigned long *number)
} }
// scans all alphabetic characters and returns the resulting string // scans all alphabetic characters and returns the resulting string
static wxString GetAlphaToken(const wxChar*& p) static wxString GetAlphaToken(const wxStringCharType*& p)
{ {
wxString s; wxString s;
while ( wxIsalpha(*p) ) while ( wxIsalpha(*p) )
@@ -2689,12 +2691,12 @@ wxString wxDateTime::Format(const wxString& format, const TimeZone& tz) const
// RFC822 time specs. // RFC822 time specs.
// //
// TODO a great candidate for using reg exps // TODO a great candidate for using reg exps
const wxChar *wxDateTime::ParseRfc822Date(const wxChar* date) const char *
wxDateTime::ParseRfc822Date(const wxString& date, wxString::const_iterator *end)
{ {
wxCHECK_MSG( date, (wxChar *)NULL, _T("NULL pointer in wxDateTime::Parse") ); // TODO: rewrite using iterators instead of wxChar pointers
const wxStringCharType *p = date.wx_str();
const wxChar *p = date; const wxStringCharType *comma = wxStrchr(p, wxS(','));
const wxChar *comma = wxStrchr(p, _T(','));
if ( comma ) if ( comma )
{ {
// the part before comma is the weekday // the part before comma is the weekday
@@ -2707,7 +2709,7 @@ const wxChar *wxDateTime::ParseRfc822Date(const wxChar* date)
{ {
wxLogDebug(_T("no space after weekday in RFC822 time spec")); wxLogDebug(_T("no space after weekday in RFC822 time spec"));
return (wxChar *)NULL; return NULL;
} }
p++; // skip space p++; // skip space
@@ -2718,7 +2720,7 @@ const wxChar *wxDateTime::ParseRfc822Date(const wxChar* date)
{ {
wxLogDebug(_T("day number expected in RFC822 time spec, none found")); wxLogDebug(_T("day number expected in RFC822 time spec, none found"));
return (wxChar *)NULL; return NULL;
} }
wxDateTime_t day = (wxDateTime_t)(*p++ - _T('0')); wxDateTime_t day = (wxDateTime_t)(*p++ - _T('0'));
@@ -2730,7 +2732,7 @@ const wxChar *wxDateTime::ParseRfc822Date(const wxChar* date)
if ( *p++ != _T(' ') ) if ( *p++ != _T(' ') )
{ {
return (wxChar *)NULL; return NULL;
} }
// the following 3 letters specify the month // the following 3 letters specify the month
@@ -2764,21 +2766,21 @@ const wxChar *wxDateTime::ParseRfc822Date(const wxChar* date)
{ {
wxLogDebug(_T("Invalid RFC 822 month name '%s'"), monName.c_str()); wxLogDebug(_T("Invalid RFC 822 month name '%s'"), monName.c_str());
return (wxChar *)NULL; return NULL;
} }
p += 3; p += 3;
if ( *p++ != _T(' ') ) if ( *p++ != _T(' ') )
{ {
return (wxChar *)NULL; return NULL;
} }
// next is the year // next is the year
if ( !wxIsdigit(*p) ) if ( !wxIsdigit(*p) )
{ {
// no year? // no year?
return (wxChar *)NULL; return NULL;
} }
int year = *p++ - _T('0'); int year = *p++ - _T('0');
@@ -2786,7 +2788,7 @@ const wxChar *wxDateTime::ParseRfc822Date(const wxChar* date)
if ( !wxIsdigit(*p) ) if ( !wxIsdigit(*p) )
{ {
// should have at least 2 digits in the year // should have at least 2 digits in the year
return (wxChar *)NULL; return NULL;
} }
year *= 10; year *= 10;
@@ -2801,7 +2803,7 @@ const wxChar *wxDateTime::ParseRfc822Date(const wxChar* date)
if ( !wxIsdigit(*p) ) if ( !wxIsdigit(*p) )
{ {
// no 3 digit years please // no 3 digit years please
return (wxChar *)NULL; return NULL;
} }
year *= 10; year *= 10;
@@ -2810,20 +2812,20 @@ const wxChar *wxDateTime::ParseRfc822Date(const wxChar* date)
if ( *p++ != _T(' ') ) if ( *p++ != _T(' ') )
{ {
return (wxChar *)NULL; return NULL;
} }
// time is in the format hh:mm:ss and seconds are optional // time is in the format hh:mm:ss and seconds are optional
if ( !wxIsdigit(*p) ) if ( !wxIsdigit(*p) )
{ {
return (wxChar *)NULL; return NULL;
} }
wxDateTime_t hour = (wxDateTime_t)(*p++ - _T('0')); wxDateTime_t hour = (wxDateTime_t)(*p++ - _T('0'));
if ( !wxIsdigit(*p) ) if ( !wxIsdigit(*p) )
{ {
return (wxChar *)NULL; return NULL;
} }
hour *= 10; hour *= 10;
@@ -2831,19 +2833,19 @@ const wxChar *wxDateTime::ParseRfc822Date(const wxChar* date)
if ( *p++ != _T(':') ) if ( *p++ != _T(':') )
{ {
return (wxChar *)NULL; return NULL;
} }
if ( !wxIsdigit(*p) ) if ( !wxIsdigit(*p) )
{ {
return (wxChar *)NULL; return NULL;
} }
wxDateTime_t min = (wxDateTime_t)(*p++ - _T('0')); wxDateTime_t min = (wxDateTime_t)(*p++ - _T('0'));
if ( !wxIsdigit(*p) ) if ( !wxIsdigit(*p) )
{ {
return (wxChar *)NULL; return NULL;
} }
min *= 10; min *= 10;
@@ -2854,14 +2856,14 @@ const wxChar *wxDateTime::ParseRfc822Date(const wxChar* date)
{ {
if ( !wxIsdigit(*p) ) if ( !wxIsdigit(*p) )
{ {
return (wxChar *)NULL; return NULL;
} }
sec = (wxDateTime_t)(*p++ - _T('0')); sec = (wxDateTime_t)(*p++ - _T('0'));
if ( !wxIsdigit(*p) ) if ( !wxIsdigit(*p) )
{ {
return (wxChar *)NULL; return NULL;
} }
sec *= 10; sec *= 10;
@@ -2870,7 +2872,7 @@ const wxChar *wxDateTime::ParseRfc822Date(const wxChar* date)
if ( *p++ != _T(' ') ) if ( *p++ != _T(' ') )
{ {
return (wxChar *)NULL; return NULL;
} }
// and now the interesting part: the timezone // and now the interesting part: the timezone
@@ -2882,7 +2884,7 @@ const wxChar *wxDateTime::ParseRfc822Date(const wxChar* date)
if ( !wxIsdigit(*p) || !wxIsdigit(*(p + 1)) ) if ( !wxIsdigit(*p) || !wxIsdigit(*(p + 1)) )
{ {
return (wxChar *)NULL; return NULL;
} }
// hours // hours
@@ -2892,7 +2894,7 @@ const wxChar *wxDateTime::ParseRfc822Date(const wxChar* date)
if ( !wxIsdigit(*p) || !wxIsdigit(*(p + 1)) ) if ( !wxIsdigit(*p) || !wxIsdigit(*(p + 1)) )
{ {
return (wxChar *)NULL; return NULL;
} }
// minutes // minutes
@@ -2924,7 +2926,7 @@ const wxChar *wxDateTime::ParseRfc822Date(const wxChar* date)
{ {
wxLogDebug(_T("Invalid militaty timezone '%c'"), *p); wxLogDebug(_T("Invalid militaty timezone '%c'"), *p);
return (wxChar *)NULL; return NULL;
} }
offset = offsets[*p++ - _T('A')]; offset = offsets[*p++ - _T('A')];
@@ -2959,7 +2961,7 @@ const wxChar *wxDateTime::ParseRfc822Date(const wxChar* date)
{ {
wxLogDebug(_T("Unknown RFC 822 timezone '%s'"), p); wxLogDebug(_T("Unknown RFC 822 timezone '%s'"), p);
return (wxChar *)NULL; return NULL;
} }
p += tz.length(); p += tz.length();
@@ -2973,7 +2975,11 @@ const wxChar *wxDateTime::ParseRfc822Date(const wxChar* date)
Set(day, mon, year, hour, min, sec); Set(day, mon, year, hour, min, sec);
MakeFromTimezone(TimeZone::Make(offset*SEC_PER_MIN)); MakeFromTimezone(TimeZone::Make(offset*SEC_PER_MIN));
return p; const size_t endpos = p - date.wx_str();
if ( end )
*end = date.begin() + endpos;
return date.c_str() + endpos;
} }
#ifdef __WINDOWS__ #ifdef __WINDOWS__
@@ -3136,12 +3142,13 @@ static wxString GetLocaleDateFormat()
#endif // __WINDOWS__ #endif // __WINDOWS__
const wxChar *wxDateTime::ParseFormat(const wxChar *date, const char *
const wxString& format, wxDateTime::ParseFormat(const wxString& date,
const wxDateTime& dateDef) const wxString& format,
const wxDateTime& dateDef,
wxString::const_iterator *end)
{ {
wxCHECK_MSG( date && !format.empty(), (wxChar *)NULL, wxCHECK_MSG( !format.empty(), NULL, "format can't be empty" );
_T("NULL pointer in wxDateTime::ParseFormat()") );
wxString str; wxString str;
unsigned long num; unsigned long num;
@@ -3169,7 +3176,7 @@ const wxChar *wxDateTime::ParseFormat(const wxChar *date,
wxDateTime::Month mon = Inv_Month; wxDateTime::Month mon = Inv_Month;
int year = 0; int year = 0;
const wxChar *input = date; const wxStringCharType *input = date.wx_str();
for ( wxString::const_iterator fmt = format.begin(); fmt != format.end(); ++fmt ) for ( wxString::const_iterator fmt = format.begin(); fmt != format.end(); ++fmt )
{ {
if ( *fmt != _T('%') ) if ( *fmt != _T('%') )
@@ -3190,7 +3197,7 @@ const wxChar *wxDateTime::ParseFormat(const wxChar *date,
if ( *input++ != *fmt ) if ( *input++ != *fmt )
{ {
// no match // no match
return (wxChar *)NULL; return NULL;
} }
} }
@@ -3243,7 +3250,7 @@ const wxChar *wxDateTime::ParseFormat(const wxChar *date,
if ( wday == Inv_WeekDay ) if ( wday == Inv_WeekDay )
{ {
// no match // no match
return (wxChar *)NULL; return NULL;
} }
} }
haveWDay = true; haveWDay = true;
@@ -3257,7 +3264,7 @@ const wxChar *wxDateTime::ParseFormat(const wxChar *date,
if ( mon == Inv_Month ) if ( mon == Inv_Month )
{ {
// no match // no match
return (wxChar *)NULL; return NULL;
} }
} }
haveMon = true; haveMon = true;
@@ -3267,25 +3274,16 @@ const wxChar *wxDateTime::ParseFormat(const wxChar *date,
{ {
wxDateTime dt; wxDateTime dt;
// this is the format which corresponds to ctime() output const wxString inc(input);
// and strptime("%c") should parse it, so try it first
static const wxChar *fmtCtime = _T("%a %b %d %H:%M:%S %Y");
const wxChar *result = dt.ParseFormat(input, fmtCtime); // try the format which corresponds to ctime() output first
if ( !result ) wxString::const_iterator endc;
{ if ( !dt.ParseFormat(inc, wxS("%a %b %d %H:%M:%S %Y"), &endc) &&
result = dt.ParseFormat(input, _T("%x %X")); !dt.ParseFormat(inc, wxS("%x %X"), &endc) &&
} !dt.ParseFormat(inc, wxS("%X %x"), &endc) )
if ( !result )
{
result = dt.ParseFormat(input, _T("%X %x"));
}
if ( !result )
{ {
// we've tried everything and still no match // we've tried everything and still no match
return (wxChar *)NULL; return NULL;
} }
Tm tm = dt.GetTm(); Tm tm = dt.GetTm();
@@ -3301,7 +3299,7 @@ const wxChar *wxDateTime::ParseFormat(const wxChar *date,
mon = tm.mon; mon = tm.mon;
mday = tm.mday; mday = tm.mday;
input = result; input += endc - inc.begin();
} }
break; break;
@@ -3310,7 +3308,7 @@ const wxChar *wxDateTime::ParseFormat(const wxChar *date,
(num > 31) || (num < 1) ) (num > 31) || (num < 1) )
{ {
// no match // no match
return (wxChar *)NULL; return NULL;
} }
// we can't check whether the day range is correct yet, will // we can't check whether the day range is correct yet, will
@@ -3323,7 +3321,7 @@ const wxChar *wxDateTime::ParseFormat(const wxChar *date,
if ( !GetNumericToken(width, input, &num) || (num > 23) ) if ( !GetNumericToken(width, input, &num) || (num > 23) )
{ {
// no match // no match
return (wxChar *)NULL; return NULL;
} }
haveHour = true; haveHour = true;
@@ -3334,7 +3332,7 @@ const wxChar *wxDateTime::ParseFormat(const wxChar *date,
if ( !GetNumericToken(width, input, &num) || !num || (num > 12) ) if ( !GetNumericToken(width, input, &num) || !num || (num > 12) )
{ {
// no match // no match
return (wxChar *)NULL; return NULL;
} }
haveHour = true; haveHour = true;
@@ -3346,7 +3344,7 @@ const wxChar *wxDateTime::ParseFormat(const wxChar *date,
if ( !GetNumericToken(width, input, &num) || !num || (num > 366) ) if ( !GetNumericToken(width, input, &num) || !num || (num > 366) )
{ {
// no match // no match
return (wxChar *)NULL; return NULL;
} }
haveYDay = true; haveYDay = true;
@@ -3357,7 +3355,7 @@ const wxChar *wxDateTime::ParseFormat(const wxChar *date,
if ( !GetNumericToken(width, input, &num) || !num || (num > 12) ) if ( !GetNumericToken(width, input, &num) || !num || (num > 12) )
{ {
// no match // no match
return (wxChar *)NULL; return NULL;
} }
haveMon = true; haveMon = true;
@@ -3368,7 +3366,7 @@ const wxChar *wxDateTime::ParseFormat(const wxChar *date,
if ( !GetNumericToken(width, input, &num) || (num > 59) ) if ( !GetNumericToken(width, input, &num) || (num > 59) )
{ {
// no match // no match
return (wxChar *)NULL; return NULL;
} }
haveMin = true; haveMin = true;
@@ -3381,7 +3379,7 @@ const wxChar *wxDateTime::ParseFormat(const wxChar *date,
GetAmPmStrings(&am, &pm); GetAmPmStrings(&am, &pm);
if (am.empty() && pm.empty()) if (am.empty() && pm.empty())
return (wxChar *)NULL; // no am/pm strings defined return NULL; // no am/pm strings defined
if ( token.CmpNoCase(pm) == 0 ) if ( token.CmpNoCase(pm) == 0 )
{ {
isPM = true; isPM = true;
@@ -3389,7 +3387,7 @@ const wxChar *wxDateTime::ParseFormat(const wxChar *date,
else if ( token.CmpNoCase(am) != 0 ) else if ( token.CmpNoCase(am) != 0 )
{ {
// no match // no match
return (wxChar *)NULL; return NULL;
} }
} }
break; break;
@@ -3401,7 +3399,7 @@ const wxChar *wxDateTime::ParseFormat(const wxChar *date,
if ( !input ) if ( !input )
{ {
// no match // no match
return (wxChar *)NULL; return NULL;
} }
haveHour = haveMin = haveSec = true; haveHour = haveMin = haveSec = true;
@@ -3420,7 +3418,7 @@ const wxChar *wxDateTime::ParseFormat(const wxChar *date,
if ( !input ) if ( !input )
{ {
// no match // no match
return (wxChar *)NULL; return NULL;
} }
haveHour = haveMin = true; haveHour = haveMin = true;
@@ -3435,7 +3433,7 @@ const wxChar *wxDateTime::ParseFormat(const wxChar *date,
if ( !GetNumericToken(width, input, &num) || (num > 61) ) if ( !GetNumericToken(width, input, &num) || (num > 61) )
{ {
// no match // no match
return (wxChar *)NULL; return NULL;
} }
haveSec = true; haveSec = true;
@@ -3449,7 +3447,7 @@ const wxChar *wxDateTime::ParseFormat(const wxChar *date,
if ( !input ) if ( !input )
{ {
// no match // no match
return (wxChar *)NULL; return NULL;
} }
haveHour = haveMin = haveSec = true; haveHour = haveMin = haveSec = true;
@@ -3465,7 +3463,7 @@ const wxChar *wxDateTime::ParseFormat(const wxChar *date,
if ( !GetNumericToken(width, input, &num) || (wday > 6) ) if ( !GetNumericToken(width, input, &num) || (wday > 6) )
{ {
// no match // no match
return (wxChar *)NULL; return NULL;
} }
haveWDay = true; haveWDay = true;
@@ -3480,7 +3478,8 @@ const wxChar *wxDateTime::ParseFormat(const wxChar *date,
{ {
struct tm tm; struct tm tm;
const wxChar *result = CallStrptime(input, "%x", &tm); const wxStringCharType *
result = CallStrptime(input, "%x", &tm);
if ( result ) if ( result )
{ {
input = result; input = result;
@@ -3506,7 +3505,7 @@ const wxChar *wxDateTime::ParseFormat(const wxChar *date,
// Windows for the right way of formatting the date: // Windows for the right way of formatting the date:
fmtDate = GetLocaleDateFormat(); fmtDate = GetLocaleDateFormat();
if ( fmtDate.empty() ) if ( fmtDate.empty() )
#endif #endif // __WINDOWS__
{ {
if ( IsWestEuropeanCountry(GetCountry()) || if ( IsWestEuropeanCountry(GetCountry()) ||
GetCountry() == Russia ) GetCountry() == Russia )
@@ -3521,29 +3520,29 @@ const wxChar *wxDateTime::ParseFormat(const wxChar *date,
} }
} }
const wxChar *result = dt.ParseFormat(input, fmtDate); const wxString indate(input);
wxString::const_iterator endDate;
if ( !result && !fmtDateAlt.empty() ) if ( !dt.ParseFormat(indate, fmtDate, &endDate) )
{ {
// ok, be nice and try another one // try another one if we have it
result = dt.ParseFormat(input, fmtDateAlt); if ( fmtDateAlt.empty() ||
} !dt.ParseFormat(indate, fmtDateAlt, &endDate) )
{
if ( !result ) return NULL;
{ }
// bad luck
return (wxChar *)NULL;
} }
Tm tm = dt.GetTm(); Tm tm = dt.GetTm();
haveDay = haveMon = haveYear = true; haveDay =
haveMon =
haveYear = true;
year = tm.year; year = tm.year;
mon = tm.mon; mon = tm.mon;
mday = tm.mday; mday = tm.mday;
input = result; input += endDate - indate.begin();
} }
break; break;
@@ -3556,7 +3555,7 @@ const wxChar *wxDateTime::ParseFormat(const wxChar *date,
input = CallStrptime(input, "%X", &tm); input = CallStrptime(input, "%X", &tm);
if ( !input ) if ( !input )
{ {
return (wxChar *)NULL; return NULL;
} }
haveHour = haveMin = haveSec = true; haveHour = haveMin = haveSec = true;
@@ -3584,7 +3583,7 @@ const wxChar *wxDateTime::ParseFormat(const wxChar *date,
if ( !result ) if ( !result )
{ {
// no match // no match
return (wxChar *)NULL; return NULL;
} }
haveHour = haveMin = haveSec = true; haveHour = haveMin = haveSec = true;
@@ -3603,7 +3602,7 @@ const wxChar *wxDateTime::ParseFormat(const wxChar *date,
if ( !GetNumericToken(width, input, &num) || (num > 99) ) if ( !GetNumericToken(width, input, &num) || (num > 99) )
{ {
// no match // no match
return (wxChar *)NULL; return NULL;
} }
haveYear = true; haveYear = true;
@@ -3617,7 +3616,7 @@ const wxChar *wxDateTime::ParseFormat(const wxChar *date,
if ( !GetNumericToken(width, input, &num) ) if ( !GetNumericToken(width, input, &num) )
{ {
// no match // no match
return (wxChar *)NULL; return NULL;
} }
haveYear = true; haveYear = true;
@@ -3632,7 +3631,7 @@ const wxChar *wxDateTime::ParseFormat(const wxChar *date,
if ( *input++ != _T('%') ) if ( *input++ != _T('%') )
{ {
// no match // no match
return (wxChar *)NULL; return NULL;
} }
break; break;
@@ -3642,7 +3641,7 @@ const wxChar *wxDateTime::ParseFormat(const wxChar *date,
// fall through // fall through
default: // not a known format spec default: // not a known format spec
return (wxChar *)NULL; return NULL;
} }
} }
@@ -3681,7 +3680,7 @@ const wxChar *wxDateTime::ParseFormat(const wxChar *date,
{ {
wxLogDebug(_T("bad month day in wxDateTime::ParseFormat")); wxLogDebug(_T("bad month day in wxDateTime::ParseFormat"));
return (wxChar *)NULL; return NULL;
} }
tm.mon = mon; tm.mon = mon;
@@ -3693,7 +3692,7 @@ const wxChar *wxDateTime::ParseFormat(const wxChar *date,
{ {
wxLogDebug(_T("bad year day in wxDateTime::ParseFormat")); wxLogDebug(_T("bad year day in wxDateTime::ParseFormat"));
return (wxChar *)NULL; return NULL;
} }
Tm tm2 = wxDateTime(1, Jan, tm.year).SetToYearDay(yday).GetTm(); Tm tm2 = wxDateTime(1, Jan, tm.year).SetToYearDay(yday).GetTm();
@@ -3736,66 +3735,75 @@ const wxChar *wxDateTime::ParseFormat(const wxChar *date,
return NULL; return NULL;
} }
return input; const size_t endpos = input - date.wx_str();
if ( end )
*end = date.begin() + endpos;
return date.c_str() + endpos;
} }
const wxChar *wxDateTime::ParseDateTime(const wxChar *date) const char *
wxDateTime::ParseDateTime(const wxString& date, wxString::const_iterator *end)
{ {
wxCHECK_MSG( date, (wxChar *)NULL, _T("NULL pointer in wxDateTime::Parse") );
// Set to current day and hour, so strings like '14:00' becomes today at // Set to current day and hour, so strings like '14:00' becomes today at
// 14, not some other random date // 14, not some other random date
wxDateTime dtDate = wxDateTime::Today(); wxDateTime dtDate = wxDateTime::Today();
wxDateTime dtTime = wxDateTime::Today(); wxDateTime dtTime = wxDateTime::Today();
const wxChar* pchTime; wxString::const_iterator
endTime,
endDate,
endBoth;
// Try to parse the beginning of the string as a date // If we got a date in the beginning, see if there is a time specified
const wxChar* pchDate = dtDate.ParseDate(date); // after the date
if ( dtDate.ParseDate(date, &endDate) )
// We got a date in the beginning, see if there is a time specified after the date
if ( pchDate )
{ {
// Skip spaces, as the ParseTime() function fails on spaces // Skip spaces, as the ParseTime() function fails on spaces
while ( wxIsspace(*pchDate) ) while ( endDate != date.end() && wxIsspace(*endDate) )
pchDate++; ++endDate;
pchTime = dtTime.ParseTime(pchDate); const wxString timestr(endDate, date.end());
if ( !dtTime.ParseTime(timestr, &endTime) )
return NULL;
endBoth = endDate + (endTime - timestr.begin());
} }
else // no date in the beginning else // no date in the beginning
{ {
// check and see if we have a time followed by a date // check if we have a time followed by a date
pchTime = dtTime.ParseTime(date); if ( !dtTime.ParseTime(date, &endTime) )
if ( pchTime ) return NULL;
{
while ( wxIsspace(*pchTime) )
pchTime++;
pchDate = dtDate.ParseDate(pchTime); while ( endTime != date.end() && wxIsspace(*endTime) )
} ++endTime;
const wxString datestr(endTime, date.end());
if ( !dtDate.ParseDate(datestr, &endDate) )
return NULL;
endBoth = endTime + (endDate - datestr.begin());
} }
// If we have a date specified, set our own data to the same date
if ( !pchDate || !pchTime )
return NULL;
Set(dtDate.GetDay(), dtDate.GetMonth(), dtDate.GetYear(), Set(dtDate.GetDay(), dtDate.GetMonth(), dtDate.GetYear(),
dtTime.GetHour(), dtTime.GetMinute(), dtTime.GetSecond(), dtTime.GetHour(), dtTime.GetMinute(), dtTime.GetSecond(),
dtTime.GetMillisecond()); dtTime.GetMillisecond());
// Return endpoint of scan // Return endpoint of scan
return pchDate > pchTime ? pchDate : pchTime; if ( end )
*end = endBoth;
return date.c_str() + (endBoth - date.begin());
} }
const wxChar *wxDateTime::ParseDate(const wxChar *date) const char *
wxDateTime::ParseDate(const wxString& date, wxString::const_iterator *end)
{ {
// this is a simplified version of ParseDateTime() which understands only // this is a simplified version of ParseDateTime() which understands only
// "today" (for wxDate compatibility) and digits only otherwise (and not // "today" (for wxDate compatibility) and digits only otherwise (and not
// all esoteric constructions ParseDateTime() knows about) // all esoteric constructions ParseDateTime() knows about)
wxCHECK_MSG( date, (wxChar *)NULL, _T("NULL pointer in wxDateTime::Parse") ); const wxStringCharType *p = date.wx_str();
const wxChar *p = date;
while ( wxIsspace(*p) ) while ( wxIsspace(*p) )
p++; p++;
@@ -3830,7 +3838,11 @@ const wxChar *wxDateTime::ParseDate(const wxChar *date)
*this += wxDateSpan::Days(dayDiffFromToday); *this += wxDateSpan::Days(dayDiffFromToday);
} }
return p; const size_t endpos = p - date.wx_str();
if ( end )
*end = date.begin() + endpos;
return date.c_str() + endpos;
} }
} }
} }
@@ -3854,7 +3866,7 @@ const wxChar *wxDateTime::ParseDate(const wxChar *date)
// tokenize the string // tokenize the string
size_t nPosCur = 0; size_t nPosCur = 0;
static const wxChar *dateDelimiters = _T(".,/-\t\r\n "); static const wxStringCharType *dateDelimiters = wxS(".,/-\t\r\n ");
wxStringTokenizer tok(p, dateDelimiters); wxStringTokenizer tok(p, dateDelimiters);
while ( tok.HasMoreTokens() ) while ( tok.HasMoreTokens() )
{ {
@@ -4115,7 +4127,7 @@ const wxChar *wxDateTime::ParseDate(const wxChar *date)
// inconsistency detected // inconsistency detected
wxLogDebug(_T("ParseDate: inconsistent day/weekday.")); wxLogDebug(_T("ParseDate: inconsistent day/weekday."));
return (wxChar *)NULL; return NULL;
} }
} }
} }
@@ -4135,13 +4147,16 @@ const wxChar *wxDateTime::ParseDate(const wxChar *date)
p--; p--;
} }
return p; const size_t endpos = p - date.wx_str();
if ( end )
*end = date.begin() + endpos;
return date.c_str() + endpos;
} }
const wxChar *wxDateTime::ParseTime(const wxChar *time) const char *
wxDateTime::ParseTime(const wxString& time, wxString::const_iterator *end)
{ {
wxCHECK_MSG( time, (wxChar *)NULL, _T("NULL pointer in wxDateTime::Parse") );
// first try some extra things // first try some extra things
static const struct static const struct
{ {
@@ -4163,56 +4178,35 @@ const wxChar *wxDateTime::ParseTime(const wxChar *time)
// casts required by DigitalMars // casts required by DigitalMars
Set(stdTimes[n].hour, wxDateTime_t(0), wxDateTime_t(0)); Set(stdTimes[n].hour, wxDateTime_t(0), wxDateTime_t(0));
return time + len; if ( end )
*end = time.begin() + len;
return time.c_str() + len;
} }
} }
// try all time formats we may think about in the order from longest to // try all time formats we may think about in the order from longest to
// shortest // shortest
static const char *timeFormats[] =
// 12hour with AM/PM?
const wxChar *result = ParseFormat(time, _T("%I:%M:%S %p"));
if ( !result )
{ {
// normally, it's the same, but why not try it? "%I:%M:%S %p", // 12hour with AM/PM
result = ParseFormat(time, _T("%H:%M:%S")); "%H:%M:%S", // could be the same or 24 hour one so try it too
"%I:%M %p", // 12hour with AM/PM but without seconds
"%H:%M:%S", // and a possibly 24 hour version without seconds
"%X", // possibly something from above or maybe something
// completely different -- try it last
// TODO: parse timezones
};
for ( size_t nFmt = 0; nFmt < WXSIZEOF(timeFormats); nFmt++ )
{
const char *result = ParseFormat(time, timeFormats[nFmt], end);
if ( result )
return result;
} }
if ( !result ) return NULL;
{
// 12hour with AM/PM but without seconds?
result = ParseFormat(time, _T("%I:%M %p"));
}
if ( !result )
{
// without seconds?
result = ParseFormat(time, _T("%H:%M"));
}
if ( !result )
{
// just the hour and AM/PM?
result = ParseFormat(time, _T("%I %p"));
}
if ( !result )
{
// just the hour?
result = ParseFormat(time, _T("%H"));
}
if ( !result )
{
// parse the standard format: normally it is one of the formats above
// but it may be set to something completely different by the user
result = ParseFormat(time, _T("%X"));
}
// TODO: parse timezones
return result;
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------

View File

@@ -602,15 +602,15 @@ void DateTimeTestCase::TestTimeFormat()
static const struct static const struct
{ {
CompareKind compareKind; CompareKind compareKind;
const wxChar *format; const char *format;
} formatTestFormats[] = } formatTestFormats[] =
{ {
{ CompareYear, _T("---> %c") }, // %c could use 2 digit years { CompareYear, "---> %c" }, // %c could use 2 digit years
{ CompareDate, _T("Date is %A, %d of %B, in year %Y") }, { CompareDate, "Date is %A, %d of %B, in year %Y" },
{ CompareYear, _T("Date is %x, time is %X") }, // %x could use 2 digits { CompareYear, "Date is %x, time is %X" }, // %x could use 2 digits
{ CompareTime, _T("Time is %H:%M:%S or %I:%M:%S %p") }, { CompareTime, "Time is %H:%M:%S or %I:%M:%S %p" },
{ CompareNone, _T("The day of year: %j, the week of year: %W") }, { CompareNone, "The day of year: %j, the week of year: %W" },
{ CompareDate, _T("ISO date without separators: %Y%m%d") }, { CompareDate, "ISO date without separators: %Y%m%d" },
}; };
static const Date formatTestDates[] = static const Date formatTestDates[] =
@@ -633,7 +633,7 @@ void DateTimeTestCase::TestTimeFormat()
wxDateTime dt = formatTestDates[d].DT(); wxDateTime dt = formatTestDates[d].DT();
for ( size_t n = 0; n < WXSIZEOF(formatTestFormats); n++ ) for ( size_t n = 0; n < WXSIZEOF(formatTestFormats); n++ )
{ {
const wxChar *fmt = formatTestFormats[n].format; const char *fmt = formatTestFormats[n].format;
wxString s = dt.Format(fmt); wxString s = dt.Format(fmt);
// what can we recover? // what can we recover?
@@ -641,7 +641,7 @@ void DateTimeTestCase::TestTimeFormat()
// convert back // convert back
wxDateTime dt2; wxDateTime dt2;
const wxChar *result = dt2.ParseFormat(s.c_str(), fmt); const char *result = dt2.ParseFormat(s, fmt);
if ( !result ) if ( !result )
{ {
// converion failed - should it have? // converion failed - should it have?
@@ -690,22 +690,22 @@ void DateTimeTestCase::TestTimeSpanFormat()
static const struct TimeSpanFormatTestData static const struct TimeSpanFormatTestData
{ {
long h, min, sec, msec; long h, min, sec, msec;
const wxChar *fmt; const char *fmt;
const wxChar *result; const char *result;
} testSpans[] = } testSpans[] =
{ {
{ 12, 34, 56, 789, _T("%H:%M:%S.%l"), _T("12:34:56.789") }, { 12, 34, 56, 789, "%H:%M:%S.%l", "12:34:56.789" },
{ 1, 2, 3, 0, _T("%H:%M:%S"), _T("01:02:03") }, { 1, 2, 3, 0, "%H:%M:%S", "01:02:03" },
{ 1, 2, 3, 0, _T("%S"), _T("3723") }, { 1, 2, 3, 0, "%S", "3723" },
{ -1, -2, -3, 0, _T("%S"), _T("-3723") }, { -1, -2, -3, 0, "%S", "-3723" },
{ -1, -2, -3, 0, _T("%H:%M:%S"), _T("-01:02:03") }, { -1, -2, -3, 0, "%H:%M:%S", "-01:02:03" },
{ 26, 0, 0, 0, _T("%H"), _T("26") }, { 26, 0, 0, 0, "%H", "26" },
{ 26, 0, 0, 0, _T("%D, %H"), _T("1, 02") }, { 26, 0, 0, 0, "%D, %H", "1, 02" },
{ -26, 0, 0, 0, _T("%H"), _T("-26") }, { -26, 0, 0, 0, "%H", "-26" },
{ -26, 0, 0, 0, _T("%D, %H"), _T("-1, 02") }, { -26, 0, 0, 0, "%D, %H", "-1, 02" },
{ 219, 0, 0, 0, _T("%H"), _T("219") }, { 219, 0, 0, 0, "%H", "219" },
{ 219, 0, 0, 0, _T("%D, %H"), _T("9, 03") }, { 219, 0, 0, 0, "%D, %H", "9, 03" },
{ 219, 0, 0, 0, _T("%E, %D, %H"), _T("1, 2, 03") }, { 219, 0, 0, 0, "%E, %D, %H", "1, 2, 03" },
}; };
for ( size_t n = 0; n < WXSIZEOF(testSpans); n++ ) for ( size_t n = 0; n < WXSIZEOF(testSpans); n++ )
@@ -743,29 +743,29 @@ void DateTimeTestCase::TestParceRFC822()
{ {
static const struct ParseTestData static const struct ParseTestData
{ {
const wxChar *rfc822; const char *rfc822;
Date date; // NB: this should be in UTC Date date; // NB: this should be in UTC
bool good; bool good;
} parseTestDates[] = } parseTestDates[] =
{ {
{ {
_T("Sat, 18 Dec 1999 00:46:40 +0100"), "Sat, 18 Dec 1999 00:46:40 +0100",
{ 17, wxDateTime::Dec, 1999, 23, 46, 40 }, { 17, wxDateTime::Dec, 1999, 23, 46, 40 },
true true
}, },
{ {
_T("Wed, 1 Dec 1999 05:17:20 +0300"), "Wed, 1 Dec 1999 05:17:20 +0300",
{ 1, wxDateTime::Dec, 1999, 2, 17, 20 }, { 1, wxDateTime::Dec, 1999, 2, 17, 20 },
true true
}, },
{ {
_T("Sun, 28 Aug 2005 03:31:30 +0200"), "Sun, 28 Aug 2005 03:31:30 +0200",
{ 28, wxDateTime::Aug, 2005, 1, 31, 30 }, { 28, wxDateTime::Aug, 2005, 1, 31, 30 },
true true
}, },
{ {
_T("Sat, 18 Dec 1999 10:48:30 -0500"), "Sat, 18 Dec 1999 10:48:30 -0500",
{ 18, wxDateTime::Dec, 1999, 15, 48, 30 }, { 18, wxDateTime::Dec, 1999, 15, 48, 30 },
true true
}, },
@@ -773,7 +773,7 @@ void DateTimeTestCase::TestParceRFC822()
for ( unsigned n = 0; n < WXSIZEOF(parseTestDates); n++ ) for ( unsigned n = 0; n < WXSIZEOF(parseTestDates); n++ )
{ {
const wxChar * const datestr = parseTestDates[n].rfc822; const char * const datestr = parseTestDates[n].rfc822;
wxDateTime dt; wxDateTime dt;
if ( dt.ParseRfc822Date(datestr) ) if ( dt.ParseRfc822Date(datestr) )
@@ -801,21 +801,21 @@ void DateTimeTestCase::TestDateParse()
{ {
static const struct ParseTestData static const struct ParseTestData
{ {
const wxChar *str; const char *str;
Date date; // NB: this should be in UTC Date date; // NB: this should be in UTC
bool good; bool good;
} parseTestDates[] = } parseTestDates[] =
{ {
{ _T("21 Mar 2006"), { 21, wxDateTime::Mar, 2006 }, true }, { "21 Mar 2006", { 21, wxDateTime::Mar, 2006 }, true },
{ _T("29 Feb 1976"), { 29, wxDateTime::Feb, 1976 }, true }, { "29 Feb 1976", { 29, wxDateTime::Feb, 1976 }, true },
{ _T("Feb 29 1976"), { 29, wxDateTime::Feb, 1976 }, true }, { "Feb 29 1976", { 29, wxDateTime::Feb, 1976 }, true },
{ _T("31/03/06"), { 31, wxDateTime::Mar, 6 }, true }, { "31/03/06", { 31, wxDateTime::Mar, 6 }, true },
{ _T("31/03/2006"), { 31, wxDateTime::Mar, 2006 }, true }, { "31/03/2006", { 31, wxDateTime::Mar, 2006 }, true },
// some invalid ones too // some invalid ones too
{ _T("29 Feb 2006") }, { "29 Feb 2006" },
{ _T("31/04/06") }, { "31/04/06" },
{ _T("bloordyblop") }, { "bloordyblop" },
}; };
// special cases // special cases
@@ -843,12 +843,12 @@ void DateTimeTestCase::TestDateTimeParse()
{ {
static const struct ParseTestData static const struct ParseTestData
{ {
const wxChar *str; const char *str;
Date date; // NB: this should be in UTC Date date; // NB: this should be in UTC
bool good; bool good;
} parseTestDates[] = } parseTestDates[] =
{ {
{ _T("Thu 22 Nov 2007 07:40:00 PM"), { "Thu 22 Nov 2007 07:40:00 PM",
{ 22, wxDateTime::Nov, 2007, 19, 40, 0}, true }, { 22, wxDateTime::Nov, 2007, 19, 40, 0}, true },
}; };