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
This commit is contained in:
Vadim Zeitlin 2013-05-15 13:05:49 +00:00
parent b561290c3a
commit 2747a51b24
2 changed files with 22 additions and 0 deletions

View File

@ -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

View File

@ -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