01: /*
02: * Copyright 2006 Google Inc.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
05: * use this file except in compliance with the License. You may obtain a copy of
06: * the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13: * License for the specific language governing permissions and limitations under
14: * the License.
15: */
16:
17: package com.google.gwt.i18n.client;
18:
19: import com.google.gwt.junit.client.GWTTestCase;
20:
21: import java.util.Date;
22:
23: /**
24: * Tests formatting functionality in {@link DateTimeFormat} for the Chinese
25: * language.
26: */
27: public class DateTimeParse_zh_CN_Test extends GWTTestCase {
28:
29: public String getModuleName() {
30: return "com.google.gwt.i18n.I18NTest_zh_CN";
31: }
32:
33: public void testChineseDateParse() {
34: Date date = new Date();
35:
36: {
37: String time_15_26_28 = "\u4e0b\u534803\u65f626\u520628\u79d2 GMT-07:00";
38: DateTimeFormat.getFullTimeFormat().parse(time_15_26_28, 0,
39: date);
40:
41: /*
42: * Create the expected time as UTC. The "+7" is due to the tz offset.
43: * NOTE: we use the same date explicitly because Java and JavaScript
44: * disagree about whether or not daylight savings time is in effect on day
45: * 0 of the epoch.
46: */
47: long expectedTimeUTC = Date.UTC(date.getYear(), date
48: .getMonth(), date.getDate(), 15 + 7, 26, 28);
49: Date expectedDate = new Date(expectedTimeUTC);
50: assertEquals(expectedDate.getHours(), date.getHours());
51: assertEquals(expectedDate.getMinutes(), date.getMinutes());
52: assertEquals(expectedDate.getSeconds(), date.getSeconds());
53: }
54:
55: {
56: String date_2006_07_24 = "2006\u5E747\u670824\u65e5\u661f\u671f\u4e00";
57: assertTrue(DateTimeFormat.getFullDateFormat().parse(
58: date_2006_07_24, 0, date) > 0);
59:
60: // Create the expected date object, adjusting for the local timezone.
61: long localTzOffset = new Date().getTimezoneOffset();
62: long expectedTimeUTC = Date.UTC(2006 - 1900, 7 - 1, 24, 0,
63: 0, 0);
64: long localTzOffsetMillis = localTzOffset * 60 * 1000;
65: expectedTimeUTC += localTzOffsetMillis;
66: Date expectedDate = new Date(expectedTimeUTC);
67:
68: // Compare the actual and expected results.
69: addCheckpoint("2a");
70: assertEquals(expectedDate.getYear(), date.getYear());
71: addCheckpoint("2b");
72: assertEquals(expectedDate.getMonth(), date.getMonth());
73: addCheckpoint("2c");
74: assertEquals(expectedDate.getDate(), date.getDate());
75: }
76:
77: {
78: String date_2006_07_24 = "2006\u5E747\u670824\u65e5";
79: DateTimeFormat.getLongDateFormat().parse(date_2006_07_24,
80: 0, date);
81:
82: // Create the expected date object, adjusting for the local timezone.
83: long localTzOffset = new Date().getTimezoneOffset();
84: long expectedTimeUTC = Date.UTC(2006 - 1900, 7 - 1, 24, 0,
85: 0, 0);
86: long localTzOffsetMillis = localTzOffset * 60 * 1000;
87: expectedTimeUTC += localTzOffsetMillis;
88: Date expectedDate = new Date(expectedTimeUTC);
89:
90: // Compare the actual and expected results.
91: addCheckpoint("3a");
92: assertEquals(expectedDate.getYear(), date.getYear());
93: addCheckpoint("3b");
94: assertEquals(expectedDate.getMonth(), date.getMonth());
95: addCheckpoint("3c");
96: assertEquals(expectedDate.getDate(), date.getDate());
97: }
98: }
99: }
|