Revision: 7213
Author: [email protected]
Date: Mon Nov 30 20:45:32 2009
Log: Merge trunk r7212 into this branch
Fix standalone month/day-of-week handling.
svn merge --ignore-ancestry -c7212 \
https://google-web-toolkit.googlecode.com/svn/trunk/ .
http://code.google.com/p/google-web-toolkit/source/detail?r=7213
Added:
/releases/2.0/user/test/com/google/gwt/i18n/I18NTest_fil.gwt.xml
/releases/2.0/user/test/com/google/gwt/i18n/I18NTest_pl.gwt.xml
/releases/2.0/user/test/com/google/gwt/i18n/client/DateTimeFormat_fil_Test.java
/releases/2.0/user/test/com/google/gwt/i18n/client/DateTimeFormat_pl_Test.java
Modified:
/releases/2.0/branch-info.txt
/releases/2.0/user/src/com/google/gwt/i18n/client/DateTimeFormat.java
/releases/2.0/user/test/com/google/gwt/i18n/I18NSuite.java
/releases/2.0/user/test/com/google/gwt/i18n/client/DateTimeFormat_en_Test.java
/releases/2.0/user/test/com/google/gwt/i18n/client/DateTimeParse_en_Test.java
=======================================
--- /dev/null
+++ /releases/2.0/user/test/com/google/gwt/i18n/I18NTest_fil.gwt.xml Mon
Nov 30 20:45:32 2009
@@ -0,0 +1,23 @@
+<!--
-->
+<!-- Copyright 2009 Google
Inc. -->
+<!-- Licensed under the Apache License, Version 2.0 (the "License");
you -->
+<!-- may not use this file except in compliance with the License. You
may -->
+<!-- may obtain a copy of the License
at -->
+<!--
-->
+<!--
http://www.apache.org/licenses/LICENSE-2.0 -->
+<!--
-->
+<!-- Unless required by applicable law or agreed to in writing,
software -->
+<!-- distributed under the License is distributed on an "AS IS"
BASIS, -->
+<!-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
or -->
+<!-- implied. License for the specific language governing permissions
and -->
+<!-- limitations under the
License. -->
+
+<module>
+ <!-- Inherit the JUnit support -->
+ <inherits name='com.google.gwt.junit.JUnit'/>
+ <inherits name='com.google.gwt.i18n.I18N'/>
+ <!-- Include client-side source for the test cases -->
+ <source path="client"/>
+ <extend-property name="locale" values="fil"/>
+ <set-property name="locale" value = "fil"/>
+</module>
=======================================
--- /dev/null
+++ /releases/2.0/user/test/com/google/gwt/i18n/I18NTest_pl.gwt.xml Mon Nov
30 20:45:32 2009
@@ -0,0 +1,23 @@
+<!--
-->
+<!-- Copyright 2009 Google
Inc. -->
+<!-- Licensed under the Apache License, Version 2.0 (the "License");
you -->
+<!-- may not use this file except in compliance with the License. You
may -->
+<!-- may obtain a copy of the License
at -->
+<!--
-->
+<!--
http://www.apache.org/licenses/LICENSE-2.0 -->
+<!--
-->
+<!-- Unless required by applicable law or agreed to in writing,
software -->
+<!-- distributed under the License is distributed on an "AS IS"
BASIS, -->
+<!-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
or -->
+<!-- implied. License for the specific language governing permissions
and -->
+<!-- limitations under the
License. -->
+
+<module>
+ <!-- Inherit the JUnit support -->
+ <inherits name='com.google.gwt.junit.JUnit'/>
+ <inherits name='com.google.gwt.i18n.I18N'/>
+ <!-- Include client-side source for the test cases -->
+ <source path="client"/>
+ <extend-property name="locale" values="pl"/>
+ <set-property name="locale" value = "pl"/>
+</module>
=======================================
--- /dev/null
+++
/releases/2.0/user/test/com/google/gwt/i18n/client/DateTimeFormat_fil_Test.java
Mon Nov 30 20:45:32 2009
@@ -0,0 +1,63 @@
+/*
+ * Copyright 2009 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may
not
+ * use this file except in compliance with the License. You may obtain a
copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
under
+ * the License.
+ */
+package com.google.gwt.i18n.client;
+
+import com.google.gwt.junit.client.GWTTestCase;
+
+import java.util.Date;
+
+/**
+ * Tests unique functionality in {...@link DateTimeFormat} for the Filipino
+ * language.
+ */
+...@suppresswarnings("deprecation")
+public class DateTimeFormat_fil_Test extends GWTTestCase {
+
+ @Override
+ public String getModuleName() {
+ return "com.google.gwt.i18n.I18NTest_fil";
+ }
+
+ public void test_ccc() {
+ Date date = new Date(2006 - 1900, 6, 26, 13, 10, 10);
+ assertEquals("Miy", DateTimeFormat.getFormat("ccc").format(date));
+ }
+
+ public void test_cccc() {
+ Date date = new Date(2006 - 1900, 6, 26, 13, 10, 10);
+ assertEquals("Miyerkules",
DateTimeFormat.getFormat("cccc").format(date));
+ }
+
+ public void test_ccccc() {
+ Date date = new Date(2006 - 1900, 6, 26, 13, 10, 10);
+ assertEquals("M", DateTimeFormat.getFormat("ccccc").format(date));
+ }
+
+ public void test_EEE() {
+ Date date = new Date(2006 - 1900, 6, 26, 13, 10, 10);
+ assertEquals("Mye", DateTimeFormat.getFormat("EEE").format(date));
+ }
+
+ public void test_EEEE() {
+ Date date = new Date(2006 - 1900, 6, 26, 13, 10, 10);
+ assertEquals("Miyerkules",
DateTimeFormat.getFormat("EEEE").format(date));
+ }
+
+ public void test_EEEEE() {
+ Date date = new Date(2006 - 1900, 6, 26, 13, 10, 10);
+ assertEquals("M", DateTimeFormat.getFormat("EEEEE").format(date));
+ }
+}
=======================================
--- /dev/null
+++
/releases/2.0/user/test/com/google/gwt/i18n/client/DateTimeFormat_pl_Test.java
Mon Nov 30 20:45:32 2009
@@ -0,0 +1,73 @@
+/*
+ * Copyright 2009 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may
not
+ * use this file except in compliance with the License. You may obtain a
copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
under
+ * the License.
+ */
+package com.google.gwt.i18n.client;
+
+import com.google.gwt.junit.client.GWTTestCase;
+
+import java.util.Date;
+
+/**
+ * Tests unique functionality in {...@link DateTimeFormat} for the Polish
+ * language.
+ */
+...@suppresswarnings("deprecation")
+public class DateTimeFormat_pl_Test extends GWTTestCase {
+
+ @Override
+ public String getModuleName() {
+ return "com.google.gwt.i18n.I18NTest_pl";
+ }
+
+ public void test_LL() {
+ Date date = new Date(2006 - 1900, 6, 27, 13, 10, 10);
+ assertEquals("07", DateTimeFormat.getFormat("LL").format(date));
+ }
+
+ public void test_LLL() {
+ Date date = new Date(2006 - 1900, 6, 27, 13, 10, 10);
+ assertEquals("lip", DateTimeFormat.getFormat("LLL").format(date));
+ }
+
+ public void test_LLLL() {
+ Date date = new Date(2006 - 1900, 6, 27, 13, 10, 10);
+ assertEquals("lipiec", DateTimeFormat.getFormat("LLLL").format(date));
+ }
+
+ public void test_LLLLL() {
+ Date date = new Date(2006 - 1900, 6, 27, 13, 10, 10);
+ assertEquals("l", DateTimeFormat.getFormat("LLLLL").format(date));
+ }
+
+ public void test_MM() {
+ Date date = new Date(2006 - 1900, 6, 27, 13, 10, 10);
+ assertEquals("07", DateTimeFormat.getFormat("MM").format(date));
+ }
+
+ public void test_MMM() {
+ Date date = new Date(2006 - 1900, 6, 27, 13, 10, 10);
+ assertEquals("lip", DateTimeFormat.getFormat("MMM").format(date));
+ }
+
+ public void test_MMMM() {
+ Date date = new Date(2006 - 1900, 6, 27, 13, 10, 10);
+ assertEquals("lipca", DateTimeFormat.getFormat("MMMM").format(date));
+ }
+
+ public void test_MMMMM() {
+ Date date = new Date(2006 - 1900, 6, 27, 13, 10, 10);
+ assertEquals("l", DateTimeFormat.getFormat("MMMMM").format(date));
+ }
+}
=======================================
--- /releases/2.0/branch-info.txt Mon Nov 30 13:49:19 2009
+++ /releases/2.0/branch-info.txt Mon Nov 30 20:45:32 2009
@@ -1111,3 +1111,8 @@
Don't validate servlet tags with -noserver.
svn merge --ignore-ancestry -c7201
https://google-web-toolkit.googlecode.com/svn/trunk .
svn merge --ignore-ancestry -c7202
https://google-web-toolkit.googlecode.com/svn/trunk .
+
+tr...@7212 was merged into this branch
+ Fix standalone month/day-of-week handling.
+ svn merge --ignore-ancestry -c7212 \
+ https://google-web-toolkit.googlecode.com/svn/trunk/ .
=======================================
--- /releases/2.0/user/src/com/google/gwt/i18n/client/DateTimeFormat.java
Fri Nov 20 11:47:11 2009
+++ /releases/2.0/user/src/com/google/gwt/i18n/client/DateTimeFormat.java
Mon Nov 30 20:45:32 2009
@@ -49,6 +49,13 @@
* <td><code>1996</code></td>
* </tr>
*
+ * <tr>
+ * <td><code>L</code></td>
+ * <td>standalone month in year</td>
+ * <td>Text or Number</td>
+ * <td><code>July (or) 07</code></td>
+ * </tr>
+ *
* <tr>
* <td><code>M</code></td>
* <td>month in year</td>
@@ -185,7 +192,9 @@
* <dd>3 or more, use text, otherwise use number. (e.g. <code>"M"</code>
* produces <code>"1"</code>, <code>"MM"</code> produces <code>"01"</code>,
* <code>"MMM"</code> produces <code>"Jan"</code>, and <code>"MMMM"</code>
- * produces <code>"January"</code>.</dd>
+ * produces <code>"January"</code>. Some pattern letters also treat a
count
+ * of 5 specially, meaning a single-letter abbreviation: <code>L</code>,
+ * <code>M</code>, <code>E</code>, and <code>c</code>.</dd>
* </dl>
*
* <p>
@@ -407,9 +416,10 @@
private static DateTimeFormat cachedShortDateTimeFormat;
private static final int NUM_MILLISECONDS_IN_DAY = 24 * 60 * 60000;
- private static final String PATTERN_CHARS = "GyMdkHmsSEDahKzZv";
-
- private static final String NUMERIC_FORMAT_CHARS = "MydhHmsSDkK";
+ private static final String PATTERN_CHARS = "GyMLdkHmsSEcDahKzZv";
+
+ // Note: M & L must be the first two characters
+ private static final String NUMERIC_FORMAT_CHARS = "MLydhHmsSDkK";
private static final String WHITE_SPACE = " \t\r\n";
@@ -918,8 +928,6 @@
* Formats AM/PM field according to pattern specified.
*
* @param buf where formatted string will be appended to
- * @param count number of time pattern char repeats; this controls how a
field
- * should be formatted
* @param date hold the date object to be formatted
*/
private void formatAmPm(StringBuffer buf, Date date) {
@@ -953,7 +961,9 @@
*/
private void formatDayOfWeek(StringBuffer buf, int count, Date date) {
int value = date.getDay();
- if (count >= 4) {
+ if (count == 5) {
+ buf.append(dateTimeConstants.narrowWeekdays()[value]);
+ } else if (count == 4) {
buf.append(dateTimeConstants.weekdays()[value]);
} else {
buf.append(dateTimeConstants.shortWeekdays()[value]);
@@ -1039,7 +1049,7 @@
buf.append(dateTimeConstants.narrowMonths()[value]);
break;
case 4:
- buf.append(dateTimeConstants.standaloneMonths()[value]);
+ buf.append(dateTimeConstants.months()[value]);
break;
case 3:
buf.append(dateTimeConstants.shortMonths()[value]);
@@ -1236,7 +1246,8 @@
return false;
}
int i = NUMERIC_FORMAT_CHARS.indexOf(part.text.charAt(0));
- return (i > 0 || (i == 0 && part.count < 3));
+ // M & L (index 0 and 1) are only numeric if there are less than 3
chars
+ return (i > 1 || (i >= 0 && part.count < 3));
}
/**
@@ -1697,50 +1708,54 @@
}
switch (ch) {
- case 'G': // 'G' - ERA
+ case 'G': // era
value = matchString(text, start, dateTimeConstants.eras(), pos);
cal.setEra(value);
return true;
- case 'M': // 'M' - MONTH
+ case 'M': // month
return subParseMonth(text, pos, cal, value, start);
- case 'E':
+ case 'L': // standalone month
+ return subParseStandaloneMonth(text, pos, cal, value, start);
+ case 'E': // day of week
return subParseDayOfWeek(text, pos, start, cal);
- case 'a': // 'a' - AM_PM
+ case 'c': // standalone day of week
+ return subParseStandaloneDay(text, pos, start, cal);
+ case 'a': // AM/PM
value = matchString(text, start, dateTimeConstants.ampms(), pos);
cal.setAmpm(value);
return true;
- case 'y': // 'y' - YEAR
+ case 'y': // year
return subParseYear(text, pos, start, value, part, cal);
- case 'd': // 'd' - DATE
+ case 'd': // day of month
if (value <= 0) {
return false;
}
cal.setDayOfMonth(value);
return true;
- case 'S': // 'S' - FRACTIONAL_SECOND
+ case 'S': // fractional seconds
return subParseFractionalSeconds(value, start, pos[0], cal);
- case 'h': // 'h' - HOUR (1..12)
+ case 'h': // hour (1..12)
if (value == 12) {
value = 0;
}
// fall through
- case 'K': // 'K' - HOUR (0..11)
- case 'H': // 'H' - HOUR_OF_DAY (0..23)
+ case 'K': // hour (0..11)
+ case 'H': // hour (0..23)
cal.setHours(value);
return true;
- case 'k': // 'k' - HOUR_OF_DAY (1..24)
+ case 'k': // hour (1..24)
cal.setHours(value);
return true;
- case 'm': // 'm' - MINUTE
+ case 'm': // minute
cal.setMinutes(value);
return true;
- case 's': // 's' - SECOND
+ case 's': // second
cal.setSeconds(value);
return true;
- case 'z': // 'z' - ZONE_OFFSET
- case 'Z': // 'Z' - TIMEZONE_RFC
- case 'v': // 'v' - TIMEZONE_GENERIC
+ case 'z': // time zone offset
+ case 'Z': // time zone RFC
+ case 'v': // time zone generic
return subParseTimeZoneInGMT(text, start, pos, cal);
default:
return false;
@@ -1807,7 +1822,7 @@
}
/**
- * Method subParseMonth parses Month field.
+ * Parses Month field.
*
* @param text the time text to be parsed
* @param pos Parse position
@@ -1839,6 +1854,72 @@
}
return false;
}
+
+ /**
+ * Parses standalone day of the week field.
+ *
+ * @param text the time text to be parsed
+ * @param pos Parse position
+ * @param start from where parse start
+ * @param cal DateRecord object that holds parsed value
+ *
+ * @return <code>true</code> if parsing successful, otherwise
+ * <code>false</code>
+ */
+ private boolean subParseStandaloneDay(String text, int[] pos, int start,
+ DateRecord cal) {
+ int value;
+ // 'c' - DAY_OF_WEEK
+ // Want to be able to parse both short and long forms.
+ // Try count == 4 (cccc) first:
+ value = matchString(text, start,
dateTimeConstants.standaloneWeekdays(),
+ pos);
+ if (value < 0) {
+ value = matchString(text, start,
+ dateTimeConstants.standaloneShortWeekdays(), pos);
+ }
+ if (value < 0) {
+ return false;
+ }
+ cal.setDayOfWeek(value);
+ return true;
+ }
+
+ /**
+ * Parses a standalone month field.
+ *
+ * @param text the time text to be parsed
+ * @param pos Parse position
+ * @param cal DateRecord object that will hold parsed value
+ * @param value numeric value if this field is expressed using numberic
+ * pattern
+ * @param start from where parse start
+ *
+ * @return <code>true</code> if parsing successful
+ */
+ private boolean subParseStandaloneMonth(String text, int[] pos,
+ DateRecord cal, int value, int start) {
+ // When month is symbols, i.e., LLL or LLLL, value will be -1.
+ if (value < 0) {
+ // Want to be able to parse both short and long forms.
+ // Try count == 4 first:
+ value = matchString(text, start,
+ dateTimeConstants.standaloneMonths(), pos);
+ if (value < 0) { // count == 4 failed, now try count == 3.
+ value = matchString(text, start,
+ dateTimeConstants.standaloneShortMonths(), pos);
+ }
+ if (value < 0) {
+ return false;
+ }
+ cal.setMonth(value);
+ return true;
+ } else if (value > 0) {
+ cal.setMonth(value - 1);
+ return true;
+ }
+ return false;
+ }
/**
* Method parses GMT type timezone.
=======================================
--- /releases/2.0/user/test/com/google/gwt/i18n/I18NSuite.java Tue Nov 10
12:00:29 2009
+++ /releases/2.0/user/test/com/google/gwt/i18n/I18NSuite.java Mon Nov 30
20:45:32 2009
@@ -20,6 +20,8 @@
import com.google.gwt.i18n.client.CustomPluralsTest;
import com.google.gwt.i18n.client.DateTimeFormat_de_Test;
import com.google.gwt.i18n.client.DateTimeFormat_en_Test;
+import com.google.gwt.i18n.client.DateTimeFormat_fil_Test;
+import com.google.gwt.i18n.client.DateTimeFormat_pl_Test;
import com.google.gwt.i18n.client.DateTimeParse_en_Test;
import com.google.gwt.i18n.client.DateTimeParse_zh_CN_Test;
import com.google.gwt.i18n.client.I18N2Test;
@@ -61,6 +63,8 @@
suite.addTestSuite(CustomPluralsTest.class);
suite.addTestSuite(DateTimeFormat_de_Test.class);
suite.addTestSuite(DateTimeFormat_en_Test.class);
+ suite.addTestSuite(DateTimeFormat_fil_Test.class);
+ suite.addTestSuite(DateTimeFormat_pl_Test.class);
suite.addTestSuite(DateTimeParse_en_Test.class);
suite.addTestSuite(DateTimeParse_zh_CN_Test.class);
suite.addTestSuite(GwtLocaleTest.class);
=======================================
---
/releases/2.0/user/test/com/google/gwt/i18n/client/DateTimeFormat_en_Test.java
Fri Nov 20 11:47:11 2009
+++
/releases/2.0/user/test/com/google/gwt/i18n/client/DateTimeFormat_en_Test.java
Mon Nov 30 20:45:32 2009
@@ -25,11 +25,60 @@
* Tests formatting functionality in {...@link DateTimeFormat} for the English
* language.
*/
+...@suppresswarnings("deprecation")
public class DateTimeFormat_en_Test extends GWTTestCase {
+ @Override
public String getModuleName() {
return "com.google.gwt.i18n.I18NTest";
}
+
+ public void test_ccc() {
+ Date date = new Date(2006 - 1900, 6, 27, 13, 10, 10);
+ assertEquals("Thu", DateTimeFormat.getFormat("ccc").format(date));
+ }
+
+ public void test_cccc() {
+ Date date = new Date(2006 - 1900, 6, 27, 13, 10, 10);
+ assertEquals("Thursday",
DateTimeFormat.getFormat("cccc").format(date));
+ }
+
+ public void test_ccccc() {
+ Date date = new Date(2006 - 1900, 6, 27, 13, 10, 10);
+ assertEquals("T", DateTimeFormat.getFormat("ccccc").format(date));
+ }
+
+ public void test_daylightTimeTransition() {
+ // US PST transitioned to PDT on 2006/4/2 2:00am, jump to 2006/4/2
3:00am.
+ // That's UTC time 2006/4/2 10:00am
+
+ TimeZoneConstants timeZoneData = GWT.create(TimeZoneConstants.class);
+ String str = timeZoneData.americaLosAngeles();
+ TimeZone usPacific = TimeZone.createTimeZone(str);
+
+ Date date = new Date();
+ date.setTime(Date.UTC(2006 - 1900, 3, 2, 9, 59, 0));
+ assertEquals("04/02/2006 01:59:00 PST", DateTimeFormat.getFormat(
+ "MM/dd/yyyy HH:mm:ss z").format(date, usPacific));
+ date.setTime(Date.UTC(2006 - 1900, 3, 2, 10, 01, 0));
+ assertEquals("04/02/2006 03:01:00 PDT", DateTimeFormat.getFormat(
+ "MM/dd/yyyy HH:mm:ss z").format(date, usPacific));
+ date.setTime(Date.UTC(2006 - 1900, 3, 2, 10, 0, 0));
+ assertEquals("04/02/2006 03:00:00 PDT", DateTimeFormat.getFormat(
+ "MM/dd/yyyy HH:mm:ss z").format(date, usPacific));
+
+ // US PDT transition to PST on 2006/10/29 2:00am, jump back to PDT
+ // 2006/4/2 1:00am
+ date.setTime(Date.UTC(2006 - 1900, 10 - 1, 29, 8, 59, 0));
+ assertEquals("10/29/2006 01:59:00 PDT", DateTimeFormat.getFormat(
+ "MM/dd/yyyy HH:mm:ss z").format(date, usPacific));
+ date.setTime(Date.UTC(2006 - 1900, 10 - 1, 29, 9, 01, 0));
+ assertEquals("10/29/2006 01:01:00 PST", DateTimeFormat.getFormat(
+ "MM/dd/yyyy HH:mm:ss z").format(date, usPacific));
+ date.setTime(Date.UTC(2006 - 1900, 10 - 1, 29, 9, 0, 0));
+ assertEquals("10/29/2006 01:00:00 PST", DateTimeFormat.getFormat(
+ "MM/dd/yyyy HH:mm:ss z").format(date, usPacific));
+ }
public void test_EEEEMMMddyy() {
Date date = new Date(2006 - 1900, 6, 27, 13, 10, 10);
@@ -53,6 +102,26 @@
assertEquals("1:10:10 PM", DateTimeFormat.getFormat("h:mm:ss
a").format(
date));
}
+
+ public void test_LL() {
+ Date date = new Date(2006 - 1900, 6, 27, 13, 10, 10);
+ assertEquals("07", DateTimeFormat.getFormat("LL").format(date));
+ }
+
+ public void test_LLL() {
+ Date date = new Date(2006 - 1900, 6, 27, 13, 10, 10);
+ assertEquals("Jul", DateTimeFormat.getFormat("LLL").format(date));
+ }
+
+ public void test_LLLL() {
+ Date date = new Date(2006 - 1900, 6, 27, 13, 10, 10);
+ assertEquals("July", DateTimeFormat.getFormat("LLLL").format(date));
+ }
+
+ public void test_LLLLL() {
+ Date date = new Date(2006 - 1900, 6, 27, 13, 10, 10);
+ assertEquals("J", DateTimeFormat.getFormat("LLLLL").format(date));
+ }
public void test_predefinedFormat() {
Date date = new Date(2006 - 1900, 7, 4, 13, 49, 24);
@@ -227,37 +296,6 @@
date));
assertEquals("13 '", DateTimeFormat.getFormat("HH ''").format(date));
}
-
- public void test_yyyyyMMMMM() {
- Date date = new Date(2006 - 1900, 6, 27, 13, 10, 10);
- assertEquals("2006.J.27 AD 01:10 PM", DateTimeFormat.getFormat(
- "yyyyy.MMMMM.dd GGG hh:mm aaa").format(date));
- }
-
- public void test_timezonev() {
- TimeZoneConstants timeZoneData = GWT.create(TimeZoneConstants.class);
- String str = timeZoneData.americaLosAngeles();
- TimeZone usPacific = TimeZone.createTimeZone(str);
-
- Date date = new Date();
- date.setTime(Date.UTC(2006 - 1900, 6, 27, 13, 10, 10));
-
- assertEquals("07/27/2006 06:10:10 America/Los_Angeles",
- DateTimeFormat.getFormat("MM/dd/yyyy HH:mm:ss v").format(date,
- usPacific));
-
- assertEquals("07/27/2006 06:10:10 America/Los_Angeles",
- DateTimeFormat.getFormat("MM/dd/yyyy HH:mm:ss vv").format(date,
- usPacific));
-
- assertEquals("07/27/2006 06:10:10 America/Los_Angeles",
- DateTimeFormat.getFormat("MM/dd/yyyy HH:mm:ss vvv").format(date,
- usPacific));
-
- assertEquals("07/27/2006 06:10:10 America/Los_Angeles",
- DateTimeFormat.getFormat("MM/dd/yyyy HH:mm:ss vvvv").format(date,
- usPacific));
- }
public void test_simepleTimezonev() {
TimeZone simpleTimeZone = TimeZone.createTimeZone(480);
@@ -278,38 +316,22 @@
"MM/dd/yyyy HH:mm:ss vvvv").format(date, simpleTimeZone));
}
- public void test_timezoneZ() {
- TimeZoneConstants timeZoneData = GWT.create(TimeZoneConstants.class);
- String str = timeZoneData.americaLosAngeles();
- TimeZone usPacific = TimeZone.createTimeZone(str);
-
+ public void test_simpleTimezonez() {
+ TimeZone simpleTimeZone = TimeZone.createTimeZone(420);
Date date = new Date();
date.setTime(Date.UTC(2006 - 1900, 6, 27, 13, 10, 10));
- assertEquals("07/27/2006 06:10:10 -0700", DateTimeFormat.getFormat(
- "MM/dd/yyyy HH:mm:ss Z").format(date, usPacific));
-
- assertEquals("07/27/2006 06:10:10 -0700", DateTimeFormat.getFormat(
- "MM/dd/yyyy HH:mm:ss ZZ").format(date, usPacific));
-
- assertEquals("07/27/2006 06:10:10 -0700", DateTimeFormat.getFormat(
- "MM/dd/yyyy HH:mm:ss ZZZ").format(date, usPacific));
-
- assertEquals("07/27/2006 06:10:10 GMT-07:00", DateTimeFormat.getFormat(
- "MM/dd/yyyy HH:mm:ss ZZZZ").format(date, usPacific));
-
- date.setTime(Date.UTC(2006 - 1900, 1, 27, 13, 10, 10));
- assertEquals("02/27/2006 05:10:10 -0800", DateTimeFormat.getFormat(
- "MM/dd/yyyy HH:mm:ss Z").format(date, usPacific));
-
- assertEquals("02/27/2006 05:10:10 -0800", DateTimeFormat.getFormat(
- "MM/dd/yyyy HH:mm:ss ZZ").format(date, usPacific));
-
- assertEquals("02/27/2006 05:10:10 -0800", DateTimeFormat.getFormat(
- "MM/dd/yyyy HH:mm:ss ZZZ").format(date, usPacific));
-
- assertEquals("02/27/2006 05:10:10 GMT-08:00", DateTimeFormat.getFormat(
- "MM/dd/yyyy HH:mm:ss ZZZZ").format(date, usPacific));
+ assertEquals("07/27/2006 06:10:10 UTC-7", DateTimeFormat.getFormat(
+ "MM/dd/yyyy HH:mm:ss z").format(date, simpleTimeZone));
+
+ assertEquals("07/27/2006 06:10:10 UTC-7", DateTimeFormat.getFormat(
+ "MM/dd/yyyy HH:mm:ss zz").format(date, simpleTimeZone));
+
+ assertEquals("07/27/2006 06:10:10 UTC-7", DateTimeFormat.getFormat(
+ "MM/dd/yyyy HH:mm:ss zzz").format(date, simpleTimeZone));
+
+ assertEquals("07/27/2006 06:10:10 UTC-7", DateTimeFormat.getFormat(
+ "MM/dd/yyyy HH:mm:ss zzzz").format(date, simpleTimeZone));
}
public void test_simpleTimezoneZ() {
@@ -329,6 +351,31 @@
assertEquals("07/27/2006 06:10:10 GMT-07:00", DateTimeFormat.getFormat(
"MM/dd/yyyy HH:mm:ss ZZZZ").format(date, simpleTimeZone));
}
+
+ public void test_timezonev() {
+ TimeZoneConstants timeZoneData = GWT.create(TimeZoneConstants.class);
+ String str = timeZoneData.americaLosAngeles();
+ TimeZone usPacific = TimeZone.createTimeZone(str);
+
+ Date date = new Date();
+ date.setTime(Date.UTC(2006 - 1900, 6, 27, 13, 10, 10));
+
+ assertEquals("07/27/2006 06:10:10 America/Los_Angeles",
+ DateTimeFormat.getFormat("MM/dd/yyyy HH:mm:ss v").format(date,
+ usPacific));
+
+ assertEquals("07/27/2006 06:10:10 America/Los_Angeles",
+ DateTimeFormat.getFormat("MM/dd/yyyy HH:mm:ss vv").format(date,
+ usPacific));
+
+ assertEquals("07/27/2006 06:10:10 America/Los_Angeles",
+ DateTimeFormat.getFormat("MM/dd/yyyy HH:mm:ss vvv").format(date,
+ usPacific));
+
+ assertEquals("07/27/2006 06:10:10 America/Los_Angeles",
+ DateTimeFormat.getFormat("MM/dd/yyyy HH:mm:ss vvvv").format(date,
+ usPacific));
+ }
public void test_timezonez() {
TimeZoneConstants timeZoneData = GWT.create(TimeZoneConstants.class);
@@ -366,54 +413,44 @@
usPacific));
}
- public void test_simpleTimezonez() {
- TimeZone simpleTimeZone = TimeZone.createTimeZone(420);
+ public void test_timezoneZ() {
+ TimeZoneConstants timeZoneData = GWT.create(TimeZoneConstants.class);
+ String str = timeZoneData.americaLosAngeles();
+ TimeZone usPacific = TimeZone.createTimeZone(str);
+
Date date = new Date();
date.setTime(Date.UTC(2006 - 1900, 6, 27, 13, 10, 10));
- assertEquals("07/27/2006 06:10:10 UTC-7", DateTimeFormat.getFormat(
- "MM/dd/yyyy HH:mm:ss z").format(date, simpleTimeZone));
-
- assertEquals("07/27/2006 06:10:10 UTC-7", DateTimeFormat.getFormat(
- "MM/dd/yyyy HH:mm:ss zz").format(date, simpleTimeZone));
-
- assertEquals("07/27/2006 06:10:10 UTC-7", DateTimeFormat.getFormat(
- "MM/dd/yyyy HH:mm:ss zzz").format(date, simpleTimeZone));
-
- assertEquals("07/27/2006 06:10:10 UTC-7", DateTimeFormat.getFormat(
- "MM/dd/yyyy HH:mm:ss zzzz").format(date, simpleTimeZone));
- }
-
- public void test_daylightTimeTransition() {
- // US PST transitioned to PDT on 2006/4/2 2:00am, jump to 2006/4/2
3:00am.
- // That's UTC time 2006/4/2 10:00am
-
- TimeZoneConstants timeZoneData = GWT.create(TimeZoneConstants.class);
- String str = timeZoneData.americaLosAngeles();
- TimeZone usPacific = TimeZone.createTimeZone(str);
-
- Date date = new Date();
- date.setTime(Date.UTC(2006 - 1900, 3, 2, 9, 59, 0));
- assertEquals("04/02/2006 01:59:00 PST", DateTimeFormat.getFormat(
- "MM/dd/yyyy HH:mm:ss z").format(date, usPacific));
- date.setTime(Date.UTC(2006 - 1900, 3, 2, 10, 01, 0));
- assertEquals("04/02/2006 03:01:00 PDT", DateTimeFormat.getFormat(
- "MM/dd/yyyy HH:mm:ss z").format(date, usPacific));
- date.setTime(Date.UTC(2006 - 1900, 3, 2, 10, 0, 0));
- assertEquals("04/02/2006 03:00:00 PDT", DateTimeFormat.getFormat(
- "MM/dd/yyyy HH:mm:ss z").format(date, usPacific));
-
- // US PDT transition to PST on 2006/10/29 2:00am, jump back to PDT
- // 2006/4/2 1:00am
- date.setTime(Date.UTC(2006 - 1900, 10 - 1, 29, 8, 59, 0));
- assertEquals("10/29/2006 01:59:00 PDT", DateTimeFormat.getFormat(
- "MM/dd/yyyy HH:mm:ss z").format(date, usPacific));
- date.setTime(Date.UTC(2006 - 1900, 10 - 1, 29, 9, 01, 0));
- assertEquals("10/29/2006 01:01:00 PST", DateTimeFormat.getFormat(
- "MM/dd/yyyy HH:mm:ss z").format(date, usPacific));
- date.setTime(Date.UTC(2006 - 1900, 10 - 1, 29, 9, 0, 0));
- assertEquals("10/29/2006 01:00:00 PST", DateTimeFormat.getFormat(
- "MM/dd/yyyy HH:mm:ss z").format(date, usPacific));
+ assertEquals("07/27/2006 06:10:10 -0700", DateTimeFormat.getFormat(
+ "MM/dd/yyyy HH:mm:ss Z").format(date, usPacific));
+
+ assertEquals("07/27/2006 06:10:10 -0700", DateTimeFormat.getFormat(
+ "MM/dd/yyyy HH:mm:ss ZZ").format(date, usPacific));
+
+ assertEquals("07/27/2006 06:10:10 -0700", DateTimeFormat.getFormat(
+ "MM/dd/yyyy HH:mm:ss ZZZ").format(date, usPacific));
+
+ assertEquals("07/27/2006 06:10:10 GMT-07:00", DateTimeFormat.getFormat(
+ "MM/dd/yyyy HH:mm:ss ZZZZ").format(date, usPacific));
+
+ date.setTime(Date.UTC(2006 - 1900, 1, 27, 13, 10, 10));
+ assertEquals("02/27/2006 05:10:10 -0800", DateTimeFormat.getFormat(
+ "MM/dd/yyyy HH:mm:ss Z").format(date, usPacific));
+
+ assertEquals("02/27/2006 05:10:10 -0800", DateTimeFormat.getFormat(
+ "MM/dd/yyyy HH:mm:ss ZZ").format(date, usPacific));
+
+ assertEquals("02/27/2006 05:10:10 -0800", DateTimeFormat.getFormat(
+ "MM/dd/yyyy HH:mm:ss ZZZ").format(date, usPacific));
+
+ assertEquals("02/27/2006 05:10:10 GMT-08:00", DateTimeFormat.getFormat(
+ "MM/dd/yyyy HH:mm:ss ZZZZ").format(date, usPacific));
+ }
+
+ public void test_yyyyyMMMMM() {
+ Date date = new Date(2006 - 1900, 6, 27, 13, 10, 10);
+ assertEquals("2006.J.27 AD 01:10 PM", DateTimeFormat.getFormat(
+ "yyyyy.MMMMM.dd GGG hh:mm aaa").format(date));
}
public void testPre1970Milliseconds() {
=======================================
---
/releases/2.0/user/test/com/google/gwt/i18n/client/DateTimeParse_en_Test.java
Fri Apr 17 14:54:39 2009
+++
/releases/2.0/user/test/com/google/gwt/i18n/client/DateTimeParse_en_Test.java
Mon Nov 30 20:45:32 2009
@@ -33,33 +33,6 @@
public String getModuleName() {
return "com.google.gwt.i18n.I18NTest_en";
}
-
- private int parse(String pattern, String toParse, int startIndex, Date
output) {
- DateTimeFormat fmt = DateTimeFormat.getFormat(pattern);
- return fmt.parse(toParse, startIndex, output);
- }
-
- private String format(String pattern, Date toFormat) {
- DateTimeFormat fmt = DateTimeFormat.getFormat(pattern);
- return fmt.format(toFormat);
- }
-
- public void testParseConsumesAllCharacters() {
- String toParse = "July 11, 1938";
- DateTimeFormat longDateFormat = DateTimeFormat.getLongDateFormat();
-
- Date actualDate = longDateFormat.parse(toParse);
- String actualFormat = longDateFormat.format(actualDate);
- assertEquals(toParse, actualFormat);
-
- try {
- String toParseMangled = toParse + " asdfasdfasdf";
- longDateFormat.parse(toParseMangled);
- fail("Should have thrown an exception on failure to parse");
- } catch (IllegalArgumentException e) {
- // Success.
- }
- }
public void testAbutField() {
Date date = new Date();
@@ -130,6 +103,15 @@
assertTrue(parse("yy,MM,dd", "2097,07,21", 0, date) > 0);
assertEquals(2097 - 1900, date.getYear());
}
+
+ public void testDayOfWeek() {
+ Date date = new Date();
+
+ assertTrue(parse("EEE", "Wed", 0, date) > 0);
+ assertEquals(3, date.getDay());
+ assertTrue(parse("EEEE", "Thursday", 0, date) > 0);
+ assertEquals(4, date.getDay());
+ }
public void testEnglishDate() {
Date date = new Date();
@@ -166,6 +148,70 @@
assertEquals(13, date.getSeconds());
assertEquals(900, (date.getTime() % 1000));
}
+
+ public void testHourParsingFhh() {
+ Date date = new Date();
+
+ assertTrue(parse("hhmm", "0022", 0, date) > 0);
+ assertTrue(date.getHours() == 00);
+ assertTrue(date.getMinutes() == 22);
+
+ assertTrue(parse("hhmm", "1122", 0, date) > 0);
+ assertTrue(date.getHours() == 11);
+ assertTrue(date.getMinutes() == 22);
+
+ assertTrue(parse("hhmm", "1222", 0, date) > 0);
+ assertTrue(date.getHours() == 0);
+ assertTrue(date.getMinutes() == 22);
+
+ assertTrue(parse("hhmm", "2322", 0, date) > 0);
+ assertTrue(date.getHours() == 23);
+ assertTrue(date.getMinutes() == 22);
+
+ assertTrue(parse("hhmm", "2422", 0, date) > 0);
+ assertTrue(date.getHours() == 0);
+ assertTrue(date.getMinutes() == 22);
+
+ assertTrue(parse("hhmma", "0022am", 0, date) > 0);
+ assertTrue(date.getHours() == 00);
+ assertTrue(date.getMinutes() == 22);
+
+ assertTrue(parse("hhmma", "1122am", 0, date) > 0);
+ assertTrue(date.getHours() == 11);
+ assertTrue(date.getMinutes() == 22);
+
+ assertTrue(parse("hhmma", "1222am", 0, date) > 0);
+ assertTrue(date.getHours() == 0);
+ assertTrue(date.getMinutes() == 22);
+
+ assertTrue(parse("hhmma", "2322am", 0, date) > 0);
+ assertTrue(date.getHours() == 23);
+ assertTrue(date.getMinutes() == 22);
+
+ assertTrue(parse("hhmma", "2422am", 0, date) > 0);
+ assertTrue(date.getHours() == 0);
+ assertTrue(date.getMinutes() == 22);
+
+ assertTrue(parse("hhmma", "0022pm", 0, date) > 0);
+ assertTrue(date.getHours() == 12);
+ assertTrue(date.getMinutes() == 22);
+
+ assertTrue(parse("hhmma", "1122pm", 0, date) > 0);
+ assertTrue(date.getHours() == 23);
+ assertTrue(date.getMinutes() == 22);
+
+ assertTrue(parse("hhmma", "1222pm", 0, date) > 0);
+ assertTrue(date.getHours() == 12);
+ assertTrue(date.getMinutes() == 22);
+
+ assertTrue(parse("hhmma", "2322pm", 0, date) > 0);
+ assertTrue(date.getHours() == 23);
+ assertTrue(date.getMinutes() == 22);
+
+ assertTrue(parse("hhmma", "2422pm", 0, date) > 0);
+ assertTrue(date.getHours() == 0);
+ assertTrue(date.getMinutes() == 22);
+ }
public void testHourParsingFHH() {
Date date = new Date();
@@ -230,66 +276,65 @@
assertEquals(22, date.getMinutes());
}
- public void testHourParsingFhh() {
+ public void testHourParsingFkk() {
Date date = new Date();
-
- assertTrue(parse("hhmm", "0022", 0, date) > 0);
+ assertTrue(parse("kkmm", "0022", 0, date) > 0);
assertTrue(date.getHours() == 00);
assertTrue(date.getMinutes() == 22);
- assertTrue(parse("hhmm", "1122", 0, date) > 0);
+ assertTrue(parse("kkmm", "1122", 0, date) > 0);
assertTrue(date.getHours() == 11);
assertTrue(date.getMinutes() == 22);
- assertTrue(parse("hhmm", "1222", 0, date) > 0);
- assertTrue(date.getHours() == 0);
+ assertTrue(parse("kkmm", "1222", 0, date) > 0);
+ assertTrue(date.getHours() == 12);
assertTrue(date.getMinutes() == 22);
- assertTrue(parse("hhmm", "2322", 0, date) > 0);
+ assertTrue(parse("kkmm", "2322", 0, date) > 0);
assertTrue(date.getHours() == 23);
assertTrue(date.getMinutes() == 22);
- assertTrue(parse("hhmm", "2422", 0, date) > 0);
+ assertTrue(parse("kkmm", "2422", 0, date) > 0);
assertTrue(date.getHours() == 0);
assertTrue(date.getMinutes() == 22);
- assertTrue(parse("hhmma", "0022am", 0, date) > 0);
+ assertTrue(parse("kkmma", "0022am", 0, date) > 0);
assertTrue(date.getHours() == 00);
assertTrue(date.getMinutes() == 22);
- assertTrue(parse("hhmma", "1122am", 0, date) > 0);
+ assertTrue(parse("kkmma", "1122am", 0, date) > 0);
assertTrue(date.getHours() == 11);
assertTrue(date.getMinutes() == 22);
- assertTrue(parse("hhmma", "1222am", 0, date) > 0);
- assertTrue(date.getHours() == 0);
+ assertTrue(parse("kkmma", "1222am", 0, date) > 0);
+ assertTrue(date.getHours() == 12);
assertTrue(date.getMinutes() == 22);
- assertTrue(parse("hhmma", "2322am", 0, date) > 0);
+ assertTrue(parse("kkmma", "2322am", 0, date) > 0);
assertTrue(date.getHours() == 23);
assertTrue(date.getMinutes() == 22);
- assertTrue(parse("hhmma", "2422am", 0, date) > 0);
+ assertTrue(parse("kkmma", "2422am", 0, date) > 0);
assertTrue(date.getHours() == 0);
assertTrue(date.getMinutes() == 22);
- assertTrue(parse("hhmma", "0022pm", 0, date) > 0);
+ assertTrue(parse("kkmma", "0022pm", 0, date) > 0);
assertTrue(date.getHours() == 12);
assertTrue(date.getMinutes() == 22);
- assertTrue(parse("hhmma", "1122pm", 0, date) > 0);
+ assertTrue(parse("kkmma", "1122pm", 0, date) > 0);
assertTrue(date.getHours() == 23);
assertTrue(date.getMinutes() == 22);
- assertTrue(parse("hhmma", "1222pm", 0, date) > 0);
+ assertTrue(parse("kkmma", "1222pm", 0, date) > 0);
assertTrue(date.getHours() == 12);
assertTrue(date.getMinutes() == 22);
- assertTrue(parse("hhmma", "2322pm", 0, date) > 0);
+ assertTrue(parse("kkmma", "2322pm", 0, date) > 0);
assertTrue(date.getHours() == 23);
assertTrue(date.getMinutes() == 22);
- assertTrue(parse("hhmma", "2422pm", 0, date) > 0);
+ assertTrue(parse("kkmma", "2422pm", 0, date) > 0);
assertTrue(date.getHours() == 0);
assertTrue(date.getMinutes() == 22);
}
@@ -357,67 +402,26 @@
assertTrue(date.getMinutes() == 22);
}
- public void testHourParsingFkk() {
- Date date = new Date();
- assertTrue(parse("kkmm", "0022", 0, date) > 0);
- assertTrue(date.getHours() == 00);
- assertTrue(date.getMinutes() == 22);
-
- assertTrue(parse("kkmm", "1122", 0, date) > 0);
- assertTrue(date.getHours() == 11);
- assertTrue(date.getMinutes() == 22);
-
- assertTrue(parse("kkmm", "1222", 0, date) > 0);
- assertTrue(date.getHours() == 12);
- assertTrue(date.getMinutes() == 22);
-
- assertTrue(parse("kkmm", "2322", 0, date) > 0);
- assertTrue(date.getHours() == 23);
- assertTrue(date.getMinutes() == 22);
-
- assertTrue(parse("kkmm", "2422", 0, date) > 0);
- assertTrue(date.getHours() == 0);
- assertTrue(date.getMinutes() == 22);
-
- assertTrue(parse("kkmma", "0022am", 0, date) > 0);
- assertTrue(date.getHours() == 00);
- assertTrue(date.getMinutes() == 22);
-
- assertTrue(parse("kkmma", "1122am", 0, date) > 0);
- assertTrue(date.getHours() == 11);
- assertTrue(date.getMinutes() == 22);
-
- assertTrue(parse("kkmma", "1222am", 0, date) > 0);
- assertTrue(date.getHours() == 12);
- assertTrue(date.getMinutes() == 22);
-
- assertTrue(parse("kkmma", "2322am", 0, date) > 0);
- assertTrue(date.getHours() == 23);
- assertTrue(date.getMinutes() == 22);
-
- assertTrue(parse("kkmma", "2422am", 0, date) > 0);
- assertTrue(date.getHours() == 0);
- assertTrue(date.getMinutes() == 22);
-
- assertTrue(parse("kkmma", "0022pm", 0, date) > 0);
- assertTrue(date.getHours() == 12);
- assertTrue(date.getMinutes() == 22);
-
- assertTrue(parse("kkmma", "1122pm", 0, date) > 0);
- assertTrue(date.getHours() == 23);
- assertTrue(date.getMinutes() == 22);
-
- assertTrue(parse("kkmma", "1222pm", 0, date) > 0);
- assertTrue(date.getHours() == 12);
- assertTrue(date.getMinutes() == 22);
-
- assertTrue(parse("kkmma", "2322pm", 0, date) > 0);
- assertTrue(date.getHours() == 23);
- assertTrue(date.getMinutes() == 22);
-
- assertTrue(parse("kkmma", "2422pm", 0, date) > 0);
- assertTrue(date.getHours() == 0);
- assertTrue(date.getMinutes() == 22);
+ 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");
+ }
}
public void testLeapYear() {
@@ -431,24 +435,6 @@
assertTrue(date.getMonth() == 2 - 1);
assertTrue(date.getDate() == 29);
}
-
- public void testPartialParsing() {
- // Only specify a date
- DateTimeFormat fmt = DateTimeFormat.getFormat("MM-dd-yyyy");
- 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");
- dateOnly = fmt.parse("4PM");
- assertEquals(dateOnly.getHours(), 16);
- assertEquals(dateOnly.getMinutes(), 0);
- assertEquals(dateOnly.getSeconds(), 0);
- }
public void testLenientParsing() {
Date date = new Date();
@@ -529,6 +515,52 @@
assertTrue(yyFmt.parse(sAmbPrev, 0, date) > 0);
assertEquals(0, yyFmt.parseStrict(sAmbNext, 0, date));
}
+
+ public void testMonth() {
+ Date date = new Date(1980, 1, 1);
+
+ assertTrue(parse("MM", "03", 0, date) > 0);
+ assertEquals(2, date.getMonth());
+ assertTrue(parse("MMM", "Feb", 0, date) > 0);
+ assertEquals(1, date.getMonth());
+ assertTrue(parse("MMMM", "July", 0, date) > 0);
+ assertEquals(6, date.getMonth());
+ }
+
+ public void testParseConsumesAllCharacters() {
+ String toParse = "July 11, 1938";
+ DateTimeFormat longDateFormat = DateTimeFormat.getLongDateFormat();
+
+ Date actualDate = longDateFormat.parse(toParse);
+ String actualFormat = longDateFormat.format(actualDate);
+ assertEquals(toParse, actualFormat);
+
+ try {
+ String toParseMangled = toParse + " asdfasdfasdf";
+ longDateFormat.parse(toParseMangled);
+ fail("Should have thrown an exception on failure to parse");
+ } catch (IllegalArgumentException e) {
+ // Success.
+ }
+ }
+
+ public void testPartialParsing() {
+ // Only specify a date
+ DateTimeFormat fmt = DateTimeFormat.getFormat("MM-dd-yyyy");
+ 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");
+ dateOnly = fmt.parse("4PM");
+ assertEquals(dateOnly.getHours(), 16);
+ assertEquals(dateOnly.getMinutes(), 0);
+ assertEquals(dateOnly.getSeconds(), 0);
+ }
public void testRFC3339() {
Date date = new Date();
@@ -575,6 +607,26 @@
assertEquals(520, date.getTime() % 1000);
}
}
+
+ public void testStandloneDayOfWeek() {
+ Date date = new Date(1980, 1, 1);
+
+ assertTrue(parse("ccc", "Wed", 0, date) > 0);
+ assertEquals(3, date.getDay());
+ assertTrue(parse("cccc", "Thursday", 0, date) > 0);
+ assertEquals(4, date.getDay());
+ }
+
+ public void testStandloneMonth() {
+ Date date = new Date(1980, 1, 1);
+
+ assertTrue(parse("LL", "03", 0, date) > 0);
+ assertEquals(2, date.getMonth());
+ assertTrue(parse("LLL", "Feb", 0, date) > 0);
+ assertEquals(1, date.getMonth());
+ assertTrue(parse("LLLL", "July", 0, date) > 0);
+ assertEquals(6, date.getMonth());
+ }
public void testTimeZone() {
Date date = new Date();
@@ -638,25 +690,13 @@
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");
- }
+ private String format(String pattern, Date toFormat) {
+ DateTimeFormat fmt = DateTimeFormat.getFormat(pattern);
+ return fmt.format(toFormat);
+ }
+
+ private int parse(String pattern, String toParse, int startIndex, Date
output) {
+ DateTimeFormat fmt = DateTimeFormat.getFormat(pattern);
+ return fmt.parse(toParse, startIndex, output);
}
}
--
http://groups.google.com/group/Google-Web-Toolkit-Contributors