]> git.saurik.com Git - wxWidgets.git/commitdiff
fix ParseFormat("%d") to set the date it finds (#10002)
authorVadim Zeitlin <vadim@wxwidgets.org>
Fri, 26 Sep 2008 15:27:08 +0000 (15:27 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Fri, 26 Sep 2008 15:27:08 +0000 (15:27 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@55900 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/common/datetime.cpp
tests/datetime/datetimetest.cpp

index 8bd4933a187b83f9ecbb48717bdfa58ebd455e54..0a58ed3f860c84df61e6ef47184469674839d06c 100644 (file)
@@ -3667,6 +3667,11 @@ wxDateTime::ParseFormat(const wxString& date,
     Tm tm = tmDef;
 
     // set the date
     Tm tm = tmDef;
 
     // set the date
+    if ( haveMon )
+    {
+        tm.mon = mon;
+    }
+
     if ( haveYear )
     {
         tm.year = year;
     if ( haveYear )
     {
         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
     //      day and month/day were found, we just ignore the year day and we
     //      also always ignore the week day
     // 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
     //      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"));
 
             return NULL;
         }
 
         {
             wxLogDebug(_T("bad month day in wxDateTime::ParseFormat"));
 
             return NULL;
         }
 
-        tm.mon = mon;
         tm.mday = mday;
     }
     else if ( haveYDay )
         tm.mday = mday;
     }
     else if ( haveYDay )
index 48611e4480043297a2bf9c6c34122264ed63e380..b9a3b9caf3a4389a25b3b78032682c3bf7d59c72 100644 (file)
@@ -645,7 +645,7 @@ void DateTimeTestCase::TestTimeFormat()
             const char *result = dt2.ParseFormat(s, fmt);
             if ( !result )
             {
             const char *result = dt2.ParseFormat(s, fmt);
             if ( !result )
             {
-                // converion failed - should it have?
+                // conversion failed - should it have?
                 CPPUNIT_ASSERT( kind == CompareNone );
             }
             else // conversion succeeded
                 CPPUNIT_ASSERT( kind == CompareNone );
             }
             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
     // ambiguity because of char*<->wxCStrData<->wxString conversions)
     // test compilation of some calls which should compile (and not result in
     // ambiguity because of char*<->wxCStrData<->wxString conversions)
-    wxDateTime dt;
     wxString s("foo");
     CPPUNIT_ASSERT( !dt.ParseFormat("foo") );
     CPPUNIT_ASSERT( !dt.ParseFormat(wxT("foo")) );
     wxString s("foo");
     CPPUNIT_ASSERT( !dt.ParseFormat("foo") );
     CPPUNIT_ASSERT( !dt.ParseFormat(wxT("foo")) );