From 2747a51b243ef5d44cec5b4e3757d56af56352a2 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 15 May 2013 13:05:49 +0000 Subject: [PATCH 1/1] Restore ability to parse hours only with wxDateTime::ParseTime(). This was accidentally removed in r51059, but worked in 2.8 and so should continue to work. Also add a unit test to ensure that this doesn't get broken again in the future. Closes #15204. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@73988 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/common/datetimefmt.cpp | 2 ++ tests/datetime/datetimetest.cpp | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/common/datetimefmt.cpp b/src/common/datetimefmt.cpp index fda6c0ad52..0868f626aa 100644 --- a/src/common/datetimefmt.cpp +++ b/src/common/datetimefmt.cpp @@ -2105,6 +2105,8 @@ wxDateTime::ParseTime(const wxString& time, wxString::const_iterator *end) "%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", // and a possibly 24 hour version without seconds + "%I %p", // just hour with AM/AM + "%H", // just hour in 24 hour version "%X", // possibly something from above or maybe something // completely different -- try it last diff --git a/tests/datetime/datetimetest.cpp b/tests/datetime/datetimetest.cpp index 39ef9387a0..67f9269c2a 100644 --- a/tests/datetime/datetimetest.cpp +++ b/tests/datetime/datetimetest.cpp @@ -222,6 +222,7 @@ private: CPPUNIT_TEST( TestTimeWDays ); CPPUNIT_TEST( TestTimeDST ); CPPUNIT_TEST( TestTimeFormat ); + CPPUNIT_TEST( TestTimeParse ); CPPUNIT_TEST( TestTimeSpanFormat ); CPPUNIT_TEST( TestTimeTicks ); CPPUNIT_TEST( TestParceRFC822 ); @@ -240,6 +241,7 @@ private: void TestTimeWDays(); void TestTimeDST(); void TestTimeFormat(); + void TestTimeParse(); void TestTimeSpanFormat(); void TestTimeTicks(); void TestParceRFC822(); @@ -863,6 +865,24 @@ void DateTimeTestCase::TestTimeFormat() dt.ParseFormat(s.c_str(), spec); } +// Test parsing time in free format. +void DateTimeTestCase::TestTimeParse() +{ + wxDateTime dt; + + // Parsing standard formats should work. + CPPUNIT_ASSERT( dt.ParseTime("12:34:56") ); + CPPUNIT_ASSERT_EQUAL( "12:34:56", dt.FormatISOTime() ); + + // Parsing just hours should work too. + dt.ResetTime(); + CPPUNIT_ASSERT( dt.ParseTime("17") ); + CPPUNIT_ASSERT_EQUAL( "17:00:00", dt.FormatISOTime() ); + + // Parsing gibberish shouldn't work. + CPPUNIT_ASSERT( !dt.ParseTime("bloordyblop") ); +} + void DateTimeTestCase::TestTimeSpanFormat() { static const struct TimeSpanFormatTestData -- 2.45.2