From eca0692c77cce1e8195094feb627cbe753eb30ab Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 21 Mar 2006 16:20:43 +0000 Subject: [PATCH] fixed several bugs in ParseDate() (invalid dates could result in assert failure while some valid dates such as 29 Feb 2004 were not recognized) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@38255 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/changes.txt | 1 + src/common/datetime.cpp | 15 +++++++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index 4f9a0716b9..0be81e0c1c 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -49,6 +49,7 @@ All: - Albanian translation added (Besnik Bleta) - Assert messages now show the function in which assert failed - wxApp::OnAssertFailure() should now be used instead the old wxApp::OnAssert() +- Fixed several bugs in wxDateTime::ParseDate() All (GUI): diff --git a/src/common/datetime.cpp b/src/common/datetime.cpp index ef51bf684b..31d6a2ad18 100644 --- a/src/common/datetime.cpp +++ b/src/common/datetime.cpp @@ -3817,9 +3817,11 @@ const wxChar *wxDateTime::ParseDate(const wxChar *date) } else // may be either day or year { + // use a leap year if we don't have the year yet to allow + // dates like 2/29/1976 which would be rejected otherwise wxDateTime_t max_days = (wxDateTime_t)( haveMon - ? GetNumOfDaysInMonth(haveYear ? year : Inv_Year, mon) + ? GetNumOfDaysInMonth(haveYear ? year : 1976, mon) : 31 ); @@ -3972,7 +3974,7 @@ const wxChar *wxDateTime::ParseDate(const wxChar *date) { wxLogDebug(_T("ParseDate: no day, no weekday hence no date.")); - return (wxChar *)NULL; + return NULL; } if ( haveWDay && (haveMon || haveYear || haveDay) && @@ -3981,7 +3983,7 @@ const wxChar *wxDateTime::ParseDate(const wxChar *date) // without adjectives (which we don't support here) the week day only // makes sense completely separately or with the full date // specification (what would "Wed 1999" mean?) - return (wxChar *)NULL; + return NULL; } if ( !haveWDay && haveYear && !(haveDay && haveMon) ) @@ -4011,7 +4013,7 @@ const wxChar *wxDateTime::ParseDate(const wxChar *date) // if we give the year, month and day must be given too wxLogDebug(_T("ParseDate: day and month should be specified if year is.")); - return (wxChar *)NULL; + return NULL; } } @@ -4027,6 +4029,11 @@ const wxChar *wxDateTime::ParseDate(const wxChar *date) if ( haveDay ) { + // normally we check the day above but the check is optimistic in case + // we find the day before its month/year so we have to redo it now + if ( day > GetNumOfDaysInMonth(year, mon) ) + return NULL; + Set(day, mon, year); if ( haveWDay ) -- 2.47.2