From: Vadim Zeitlin Date: Sat, 15 Dec 2007 21:03:21 +0000 (+0000) Subject: don't misinterpret the time after the date as a weekday (patch 1836708) X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/804eeca5d59fc4d3822b719dee61a9d491e6bcfc?ds=inline don't misinterpret the time after the date as a weekday (patch 1836708) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@50732 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/docs/changes.txt b/docs/changes.txt index b58dda0e4e..c1412642d1 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -291,6 +291,10 @@ wxX11: 2.8.8 ----- +All: + +- Fixed bug with parsing some dates in wxDateTime (Bob Pesner) + All (GUI): - Added wxWindow::GetNextSibling() and GetPrevSibling() diff --git a/src/common/datetime.cpp b/src/common/datetime.cpp index d1ce06ab39..c80eddf67d 100644 --- a/src/common/datetime.cpp +++ b/src/common/datetime.cpp @@ -3963,8 +3963,8 @@ const wxChar *wxDateTime::ParseDate(const wxChar *date) } else // not a valid month name { - wday = GetWeekDayFromName(token, Name_Full | Name_Abbr); - if ( wday != Inv_WeekDay ) + WeekDay wday2 = GetWeekDayFromName(token, Name_Full | Name_Abbr); + if ( wday2 != Inv_WeekDay ) { // a week day if ( haveWDay ) @@ -3972,6 +3972,8 @@ const wxChar *wxDateTime::ParseDate(const wxChar *date) break; } + wday = wday2; + haveWDay = true; } else // not a valid weekday name diff --git a/tests/datetime/datetimetest.cpp b/tests/datetime/datetimetest.cpp index 8caa1e71c4..8c584dd659 100644 --- a/tests/datetime/datetimetest.cpp +++ b/tests/datetime/datetimetest.cpp @@ -189,6 +189,7 @@ private: CPPUNIT_TEST( TestTimeTicks ); CPPUNIT_TEST( TestParceRFC822 ); CPPUNIT_TEST( TestDateParse ); + CPPUNIT_TEST( TestDateTimeParse ); CPPUNIT_TEST( TestTimeArithmetics ); CPPUNIT_TEST( TestDSTBug ); CPPUNIT_TEST( TestDateOnly ); @@ -205,6 +206,7 @@ private: void TestTimeTicks(); void TestParceRFC822(); void TestDateParse(); + void TestDateTimeParse(); void TestTimeArithmetics(); void TestDSTBug(); void TestDateOnly(); @@ -799,7 +801,7 @@ void DateTimeTestCase::TestDateParse() // some invalid ones too { _T("29 Feb 2006") }, { _T("31/04/06") }, - { _T("bloordyblop") } + { _T("bloordyblop") }, }; // special cases @@ -823,6 +825,37 @@ void DateTimeTestCase::TestDateParse() } } +void DateTimeTestCase::TestDateTimeParse() +{ + static const struct ParseTestData + { + const wxChar *str; + Date date; // NB: this should be in UTC + bool good; + } parseTestDates[] = + { + { _T("Thu 22 Nov 2007 07:40:00 PM"), + { 22, wxDateTime::Nov, 2007, 19, 40, 0}, true }, + }; + + // special cases + wxDateTime dt; + for ( size_t n = 0; n < WXSIZEOF(parseTestDates); n++ ) + { + wxDateTime dt; + if ( dt.ParseDateTime(parseTestDates[n].str) ) + { + CPPUNIT_ASSERT( parseTestDates[n].good ); + + CPPUNIT_ASSERT_EQUAL( parseTestDates[n].date.DT(), dt ); + } + else // failed to parse + { + CPPUNIT_ASSERT( !parseTestDates[n].good ); + } + } +} + void DateTimeTestCase::TestTimeArithmetics() { static const wxDateSpan testArithmData[] =