Author: [email protected]
Date: Fri Apr 17 14:54:39 2009
New Revision: 5257

Modified:
    trunk/user/src/com/google/gwt/i18n/client/DateTimeFormat.java
    trunk/user/test/com/google/gwt/i18n/client/DateTimeParse_en_Test.java

Log:
Fixes a bug where DateTimeFormat would accept 0 as a valid month or day.  
Also
adds a test to demonstrate the fix.

patch by: shanjianli
review by: ajr


Modified: trunk/user/src/com/google/gwt/i18n/client/DateTimeFormat.java
==============================================================================
--- trunk/user/src/com/google/gwt/i18n/client/DateTimeFormat.java       
(original)
+++ trunk/user/src/com/google/gwt/i18n/client/DateTimeFormat.java       Fri Apr 
 
17 14:54:39 2009
@@ -1705,6 +1705,9 @@
        case 'y': // 'y' - YEAR
          return subParseYear(text, pos, start, value, part, cal);
        case 'd': // 'd' - DATE
+        if (value <= 0) {
+          return false;
+        }
          cal.setDayOfMonth(value);
          return true;
        case 'S': // 'S' - FRACTIONAL_SECOND
@@ -1823,10 +1826,11 @@
        }
        cal.setMonth(value);
        return true;
-    } else {
+    } else if (value > 0) {
        cal.setMonth(value - 1);
        return true;
      }
+    return false;
    }

    /**

Modified:  
trunk/user/test/com/google/gwt/i18n/client/DateTimeParse_en_Test.java
==============================================================================
--- trunk/user/test/com/google/gwt/i18n/client/DateTimeParse_en_Test.java       
 
(original)
+++ trunk/user/test/com/google/gwt/i18n/client/DateTimeParse_en_Test.java       
 
Fri Apr 17 14:54:39 2009
@@ -638,4 +638,25 @@
      assertTrue(date.getDate() == 02);
    }

+  public void testInvalidDayAndMonth() {
+    DateTimeFormat fmt = DateTimeFormat.getFormat("MM/dd/yyyy");
+    try {
+      fmt.parseStrict("00/22/1999");
+      fail("Should have thrown an exception on failure to parse");
+    } catch (IllegalArgumentException e) {
+      // Success
+    }
+    try {
+      fmt.parseStrict("01/00/1999");
+      fail("Should have thrown an exception on failure to parse");
+    } catch (IllegalArgumentException e) {
+      // Success
+    }
+    try {
+      fmt.parseStrict("01/22/1999");
+      // success
+    } catch (IllegalArgumentException e) {
+      fail("Should succeed to parse");
+    }
+  }
  }

--~--~---------~--~----~------------~-------~--~----~
http://groups.google.com/group/Google-Web-Toolkit-Contributors
-~----------~----~----~----~------~----~------~--~---

Reply via email to