fix ParseFormat("%d") to set the date it finds (#10002)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@55900 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2008-09-26 15:27:08 +00:00
parent 06936905a4
commit b5f85206a9
2 changed files with 15 additions and 5 deletions

View File

@@ -3667,6 +3667,11 @@ wxDateTime::ParseFormat(const wxString& date,
Tm tm = tmDef; Tm tm = tmDef;
// set the date // set the date
if ( haveMon )
{
tm.mon = mon;
}
if ( haveYear ) if ( haveYear )
{ {
tm.year = year; tm.year = year;
@@ -3675,16 +3680,15 @@ wxDateTime::ParseFormat(const wxString& date,
// TODO we don't check here that the values are consistent, if both year // TODO we don't check here that the values are consistent, if both year
// day and month/day were found, we just ignore the year day and we // day and month/day were found, we just ignore the year day and we
// also always ignore the week day // also always ignore the week day
if ( haveMon && haveDay ) if ( haveDay )
{ {
if ( mday > GetNumOfDaysInMonth(tm.year, mon) ) if ( mday > GetNumOfDaysInMonth(tm.year, tm.mon) )
{ {
wxLogDebug(_T("bad month day in wxDateTime::ParseFormat")); wxLogDebug(_T("bad month day in wxDateTime::ParseFormat"));
return NULL; return NULL;
} }
tm.mon = mon;
tm.mday = mday; tm.mday = mday;
} }
else if ( haveYDay ) else if ( haveYDay )

View File

@@ -645,7 +645,7 @@ void DateTimeTestCase::TestTimeFormat()
const char *result = dt2.ParseFormat(s, fmt); const char *result = dt2.ParseFormat(s, fmt);
if ( !result ) if ( !result )
{ {
// converion failed - should it have? // conversion failed - should it have?
CPPUNIT_ASSERT( kind == CompareNone ); CPPUNIT_ASSERT( kind == CompareNone );
} }
else // conversion succeeded else // conversion succeeded
@@ -685,9 +685,15 @@ void DateTimeTestCase::TestTimeFormat()
} }
} }
wxDateTime dt;
// test partially specified dates too
wxDateTime dtDef(26, wxDateTime::Sep, 2008);
CPPUNIT_ASSERT( dt.ParseFormat("17", "%d") );
CPPUNIT_ASSERT_EQUAL( 17, dt.GetDay() );
// test compilation of some calls which should compile (and not result in // test compilation of some calls which should compile (and not result in
// ambiguity because of char*<->wxCStrData<->wxString conversions) // ambiguity because of char*<->wxCStrData<->wxString conversions)
wxDateTime dt;
wxString s("foo"); wxString s("foo");
CPPUNIT_ASSERT( !dt.ParseFormat("foo") ); CPPUNIT_ASSERT( !dt.ParseFormat("foo") );
CPPUNIT_ASSERT( !dt.ParseFormat(wxT("foo")) ); CPPUNIT_ASSERT( !dt.ParseFormat(wxT("foo")) );