]> git.saurik.com Git - wxWidgets.git/commitdiff
ParseDate() understands tomorrow and yesterday as well as today
authorVadim Zeitlin <vadim@wxwidgets.org>
Wed, 5 Jan 2000 16:59:31 +0000 (16:59 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Wed, 5 Jan 2000 16:59:31 +0000 (16:59 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@5261 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/common/datetime.cpp

index e933221766669dae48e32f7c6572d19948c1dfed..e9b1e7c677f93ea9c4b10c00e79f86a49b8b58ee 100644 (file)
@@ -2963,16 +2963,36 @@ const wxChar *wxDateTime::ParseDate(const wxChar *date)
     while ( wxIsspace(*p) )
         p++;
 
-    wxString today = _T("today");
-    size_t len = today.length();
-    if ( wxString(p, len).CmpNoCase(today) == 0 )
+    // some special cases
+    static struct
     {
-        // nothing can follow this, so stop here
-        p += len;
+        const wxChar *str;
+        int dayDiffFromToday;
+    } literalDates[] =
+    {
+        { wxTRANSLATE("today"),             0 },
+        { wxTRANSLATE("yesterday"),        -1 },
+        { wxTRANSLATE("tomorrow"),          1 },
+    };
 
-        *this = Today();
+    for ( size_t n = 0; n < WXSIZEOF(literalDates); n++ )
+    {
+        wxString date = wxGetTranslation(literalDates[n].str);
+        size_t len = date.length();
+        if ( wxString(p, len).CmpNoCase(date) == 0 )
+        {
+            // nothing can follow this, so stop here
+            p += len;
 
-        return p;
+            int dayDiffFromToday = literalDates[n].dayDiffFromToday;
+            *this = Today();
+            if ( dayDiffFromToday )
+            {
+                *this += wxDateSpan::Days(dayDiffFromToday);
+            }
+
+            return p;
+        }
     }
 
     // what do we have?