Fix DateTimeFormat problem where the 'z' format couldn't parse what it
generated. Timezone support is still quite weak.
Patch by: jat
Review by: ocarlsen
git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@8315 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/user/src/com/google/gwt/i18n/client/DateTimeFormat.java b/user/src/com/google/gwt/i18n/client/DateTimeFormat.java
index fa1032a..c77e680 100644
--- a/user/src/com/google/gwt/i18n/client/DateTimeFormat.java
+++ b/user/src/com/google/gwt/i18n/client/DateTimeFormat.java
@@ -480,6 +480,7 @@
private static final String WHITE_SPACE = " \t\r\n";
private static final String GMT = "GMT";
+ private static final String UTC = "UTC";
private static final int MINUTES_PER_HOUR = 60;
@@ -2224,6 +2225,11 @@
pos[0] = start + GMT.length();
return parseTimeZoneOffset(text, pos, cal);
}
+ // Likewise for UTC.
+ if (text.startsWith(UTC, start)) {
+ pos[0] = start + UTC.length();
+ return parseTimeZoneOffset(text, pos, cal);
+ }
// At this point, check for named time zones by looking through
// the locale data from the DateFormatZoneData strings.
diff --git a/user/test/com/google/gwt/i18n/client/DateTimeFormat_en_Test.java b/user/test/com/google/gwt/i18n/client/DateTimeFormat_en_Test.java
index 5694748..2299435 100644
--- a/user/test/com/google/gwt/i18n/client/DateTimeFormat_en_Test.java
+++ b/user/test/com/google/gwt/i18n/client/DateTimeFormat_en_Test.java
@@ -464,6 +464,10 @@
assertEquals("02/27/2006 05:10:10 Pacific Standard Time",
DateTimeFormat.getFormat("MM/dd/yyyy HH:mm:ss zzzz").format(date,
usPacific));
+
+ // test that we can reparse the formatted output
+ DateTimeFormat format = DateTimeFormat.getFormat("MMM d, yyyy h:mm:ss a z");
+ assertEquals(date, format.parse(format.format(date)));
}
public void test_timezoneZ() {