Reviewers: rchandia,
Description:
Fix zero-padding of 4-digit year patterns.
Issue: 4569
Patch by: jat
Review by: rchandia
Please review this at http://gwt-code-reviews.appspot.com/433801/show
Affected files:
M user/src/com/google/gwt/i18n/client/DateTimeFormat.java
M user/test/com/google/gwt/i18n/client/DateTimeFormat_en_Test.java
Index: user/src/com/google/gwt/i18n/client/DateTimeFormat.java
===================================================================
--- user/src/com/google/gwt/i18n/client/DateTimeFormat.java (revision 8015)
+++ user/src/com/google/gwt/i18n/client/DateTimeFormat.java (working copy)
@@ -1194,7 +1194,9 @@
if (value < 0) {
value = -value;
}
- if (count == 2) {
+ if (count == 4) {
+ zeroPaddingNumber(buf, value, 4);
+ } else if (count == 2) {
zeroPaddingNumber(buf, value % 100, 2);
} else {
// count != 2
Index: user/test/com/google/gwt/i18n/client/DateTimeFormat_en_Test.java
===================================================================
--- user/test/com/google/gwt/i18n/client/DateTimeFormat_en_Test.java
(revision 8015)
+++ user/test/com/google/gwt/i18n/client/DateTimeFormat_en_Test.java
(working copy)
@@ -506,4 +506,10 @@
assertEquals("06", DateTimeFormat.getFormat("SS").format(date, utc));
assertEquals("1", DateTimeFormat.getFormat("S").format(date, utc));
}
+
+ public void testZeroPadYear() {
+ DateTimeFormat fmt = DateTimeFormat.getFormat("dd.MM.yyyy");
+ String str = fmt.format(new Date(1 - 1900, 0, 1)); // 1 Jan 0001
+ assertEquals("01.01.0001", str);
+ }
}
--
http://groups.google.com/group/Google-Web-Toolkit-Contributors