From: Vadim Zeitlin Date: Sun, 14 Sep 2003 23:13:18 +0000 (+0000) Subject: implemented wxDateTime::ParseDateTime() (patch 779794) X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/de07d2004fd7813c01959102465a5107fce7f4c7 implemented wxDateTime::ParseDateTime() (patch 779794) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@23591 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/docs/changes.txt b/docs/changes.txt index fc4256c960..837f6e31a3 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -43,6 +43,10 @@ OTHER CHANGES 2.5.1 ----- +Base: + +- wxDateTime::ParseDateTime() implemented (Linus McCabe) + wxMSW: - fixed wxTE_*WRAP styles handling diff --git a/src/common/datetime.cpp b/src/common/datetime.cpp index c671694698..ce2814825e 100644 --- a/src/common/datetime.cpp +++ b/src/common/datetime.cpp @@ -3217,11 +3217,48 @@ const wxChar *wxDateTime::ParseDateTime(const wxChar *date) { wxCHECK_MSG( date, (wxChar *)NULL, _T("NULL pointer in wxDateTime::Parse") ); - // there is a public domain version of getdate.y, but it only works for - // English... - wxFAIL_MSG(_T("TODO")); + // Set to current day and hour, so strings like '14:00' becomes today at + // 14, not some other random date + wxDateTime dtDate = wxDateTime::Today(); + wxDateTime dtTime = wxDateTime::Today(); - return (wxChar *)NULL; + const wxChar* pchTime; + + // Try to parse the beginning of the string as a date + const wxChar* pchDate = dtDate.ParseDate(date); + + // 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 + while ( wxIsspace(*pchDate) ) + pchDate++; + + pchTime = dtTime.ParseTime(pchDate); + } + else // no date in the beginning + { + // check and see if we have a time followed by a date + pchTime = dtTime.ParseTime(date); + if ( pchTime ) + { + while ( wxIsspace(*pchTime) ) + pchTime++; + + pchDate = dtDate.ParseDate(pchTime); + } + } + + // 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(), + dtTime.GetHour(), dtTime.GetMinute(), dtTime.GetSecond(), + dtTime.GetMillisecond()); + + // Return endpoint of scan + return pchDate > pchTime ? pchDate : pchTime; } const wxChar *wxDateTime::ParseDate(const wxChar *date)