Fixes Issue #1271 DateTimeFormat.parse() defaults to 0 hours, minutes, and seconds, but it defaults to the current number of milliseconds. The original patch I submitted (r1281) cleared out the hours, minutes, and seconds, but date does not provide a method for clearing milliseconds. Found by: jgw Fixed by: jlabanca Review by: knorton git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@1536 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 45b6015..6ae7f16 100644 --- a/user/src/com/google/gwt/i18n/client/DateTimeFormat.java +++ b/user/src/com/google/gwt/i18n/client/DateTimeFormat.java
@@ -591,10 +591,9 @@ * into a number */ public Date parse(String text) { - Date date = new Date(); - date.setHours(0); - date.setMinutes(0); - date.setSeconds(0); + Date curDate = new Date(); + Date date = new Date(curDate.getYear(), curDate.getMonth(), + curDate.getDate()); int charsConsumed = parse(text, 0, date); if (charsConsumed == 0 || charsConsumed < text.length()) { throw new IllegalArgumentException(text);
diff --git a/user/test/com/google/gwt/i18n/client/DateTimeParse_en_Test.java b/user/test/com/google/gwt/i18n/client/DateTimeParse_en_Test.java index 047cacd..7343e4a 100644 --- a/user/test/com/google/gwt/i18n/client/DateTimeParse_en_Test.java +++ b/user/test/com/google/gwt/i18n/client/DateTimeParse_en_Test.java
@@ -435,10 +435,12 @@ public void testPartialParsing() { // Only specify a date DateTimeFormat fmt = DateTimeFormat.getFormat("MM-dd-yyyy"); - Date dateOnly = fmt.parse("05-06-1987"); + Date dateActual = new Date(87, 10, 22); + Date dateOnly = fmt.parse("11-22-1987"); assertEquals(dateOnly.getHours(), 0); assertEquals(dateOnly.getMinutes(), 0); assertEquals(dateOnly.getSeconds(), 0); + assertEquals(dateOnly.getTime(), dateActual.getTime()); // Only specify a time, should use current date fmt = DateTimeFormat.getFormat("hha");