Source Code Cross Referenced for DateTimeParse_en_Test.java in  » Ajax » GWT » com » google » gwt » i18n » client » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Ajax » GWT » com.google.gwt.i18n.client 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2007 Google Inc.
003:         * 
004:         * Licensed under the Apache License, Version 2.0 (the "License"); you may not
005:         * use this file except in compliance with the License. You may obtain a copy of
006:         * the License at
007:         * 
008:         * http://www.apache.org/licenses/LICENSE-2.0
009:         * 
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
012:         * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
013:         * License for the specific language governing permissions and limitations under
014:         * the License.
015:         */
016:
017:        package com.google.gwt.i18n.client;
018:
019:        import com.google.gwt.junit.client.GWTTestCase;
020:
021:        import java.util.Date;
022:
023:        /**
024:         * Tests parsing functionality in {@link DateTimeFormat} for the English
025:         * language.
026:         */
027:        public class DateTimeParse_en_Test extends GWTTestCase {
028:
029:            public String getModuleName() {
030:                return "com.google.gwt.i18n.I18NTest_en";
031:            }
032:
033:            private int parse(String pattern, String toParse, int startIndex,
034:                    Date output) {
035:                DateTimeFormat fmt = DateTimeFormat.getFormat(pattern);
036:                return fmt.parse(toParse, startIndex, output);
037:            }
038:
039:            private String format(String pattern, Date toFormat) {
040:                DateTimeFormat fmt = DateTimeFormat.getFormat(pattern);
041:                return fmt.format(toFormat);
042:            }
043:
044:            public void testParseConsumesAllCharacters() {
045:                String toParse = "July 11, 1938";
046:                DateTimeFormat longDateFormat = DateTimeFormat
047:                        .getLongDateFormat();
048:
049:                try {
050:                    Date actualDate = longDateFormat.parse(toParse);
051:                    String actualFormat = longDateFormat.format(actualDate);
052:                    assertEquals(toParse, actualFormat);
053:                } catch (IllegalArgumentException e) {
054:                    fail("Should not have thrown an exception");
055:                }
056:
057:                try {
058:                    String toParseMangled = toParse + " asdfasdfasdf";
059:                    longDateFormat.parse(toParseMangled);
060:                    fail("Should have thrown an exception on failure to parse");
061:                } catch (IllegalArgumentException e) {
062:                    // Success.
063:                }
064:            }
065:
066:            public void testAbutField() {
067:                Date date = new Date();
068:
069:                assertTrue(parse("hhmm", "1122", 0, date) > 0);
070:                assertTrue(date.getHours() == 11);
071:                assertTrue(date.getMinutes() == 22);
072:
073:                assertTrue(parse("hhmm", "122", 0, date) > 0);
074:                assertTrue(date.getHours() == 1);
075:                assertTrue(date.getMinutes() == 22);
076:
077:                assertTrue(parse("hhmmss", "112233", 0, date) > 0);
078:                assertTrue(date.getHours() == 11);
079:                assertTrue(date.getMinutes() == 22);
080:                assertTrue(date.getSeconds() == 33);
081:
082:                assertTrue(parse("hhmmss", "12233", 0, date) > 0);
083:                assertTrue(date.getHours() == 1);
084:                assertTrue(date.getMinutes() == 22);
085:                assertTrue(date.getSeconds() == 33);
086:
087:                assertTrue(parse("yyyyMMdd", "19991202", 0, date) > 0);
088:                assertTrue(date.getYear() == (1999 - 1900));
089:                assertTrue(date.getMonth() == 12 - 1);
090:                assertTrue(date.getDate() == 02);
091:
092:                assertTrue(parse("yyyyMMdd", "9991202", 0, date) > 0);
093:                assertTrue(date.getYear() == (999 - 1900));
094:                assertTrue(date.getMonth() == 12 - 1);
095:                assertTrue(date.getDate() == 02);
096:
097:                assertTrue(parse("yyyyMMdd", "991202", 0, date) > 0);
098:                assertTrue(date.getYear() == (99 - 1900));
099:                assertTrue(date.getMonth() == 12 - 1);
100:                assertTrue(date.getDate() == 02);
101:
102:                assertTrue(parse("yyyyMMdd", "91202", 0, date) > 0);
103:                assertTrue(date.getYear() == (9 - 1900));
104:                assertTrue(date.getMonth() == 12 - 1);
105:                assertTrue(date.getDate() == 02);
106:            }
107:
108:            public void testAmbiguousYear() {
109:                Date date = new Date();
110:                if (date.getMonth() == 0 && date.getDate() == 1
111:                        || date.getMonth() == 11 && date.getDate() >= 31) {
112:                    // we are using current time to resolve ambiguous year.
113:                    // This test case is not designed to work on new year's eve and new year.
114:                    return;
115:                }
116:
117:                Date orgDate = new Date();
118:                orgDate.setYear(orgDate.getYear() + 20);
119:
120:                orgDate.setMonth(0);
121:                orgDate.setDate(1);
122:                String str = format("MM/dd/yy", orgDate);
123:                assertTrue(parse("MM/dd/yy", str, 0, date) > 0);
124:                assertTrue(date.getYear() == orgDate.getYear());
125:
126:                orgDate.setMonth(11);
127:                orgDate.setDate(31);
128:                str = format("MM/dd/yy", orgDate);
129:                assertTrue(parse("MM/dd/yy", str, 0, date) > 0);
130:                assertTrue(date.getYear() + 100 == orgDate.getYear());
131:
132:                assertTrue(parse("yy,MM,dd", "2097,07,21", 0, date) > 0);
133:                assertTrue(date.getYear() == 2097 - 1900);
134:            }
135:
136:            public void testEnglishDate() {
137:                Date date = new Date();
138:
139:                assertTrue(parse("yyyy MMM dd hh:mm", "2006 Jul 10 15:44", 0,
140:                        date) > 0);
141:                assertTrue(date.getYear() == 2006 - 1900);
142:                assertTrue(date.getMonth() == 7 - 1);
143:                assertTrue(date.getDate() == 10);
144:                assertTrue(date.getHours() == 15);
145:                assertTrue(date.getMinutes() == 44);
146:            }
147:
148:            /**
149:             * Add as many tests as you like.
150:             */
151:            public void testFractionalSeconds() {
152:                Date date = new Date();
153:
154:                assertTrue(parse("hh:mm:ss.SSS", "11:12:13.956", 0, date) > 0);
155:                assertTrue(date.getHours() == 11);
156:                assertTrue(date.getMinutes() == 12);
157:                assertTrue(date.getSeconds() == 13);
158:                assertTrue((date.getTime() % 1000) == 956);
159:
160:                assertTrue(parse("hh:mm:ss.SSS", "11:12:13.95", 0, date) > 0);
161:                assertTrue(date.getHours() == 11);
162:                assertTrue(date.getMinutes() == 12);
163:                assertTrue(date.getSeconds() == 13);
164:                assertTrue((date.getTime() % 1000) == 950);
165:
166:                assertTrue(parse("hh:mm:ss.SSS", "11:12:13.9", 0, date) > 0);
167:                assertTrue(date.getHours() == 11);
168:                assertTrue(date.getMinutes() == 12);
169:                assertTrue(date.getSeconds() == 13);
170:                assertTrue((date.getTime() % 1000) == 900);
171:            }
172:
173:            public void testHourParsingFHH() {
174:                Date date = new Date();
175:                assertTrue(parse("HHmm", "0022", 0, date) > 0);
176:                assertTrue(date.getHours() == 00);
177:                assertTrue(date.getMinutes() == 22);
178:
179:                assertTrue(parse("HHmm", "1122", 0, date) > 0);
180:                assertTrue(date.getHours() == 11);
181:                assertTrue(date.getMinutes() == 22);
182:
183:                assertTrue(parse("HHmm", "1222", 0, date) > 0);
184:                assertTrue(date.getHours() == 12);
185:                assertTrue(date.getMinutes() == 22);
186:
187:                assertTrue(parse("HHmm", "2322", 0, date) > 0);
188:                assertTrue(date.getHours() == 23);
189:                assertTrue(date.getMinutes() == 22);
190:
191:                assertTrue(parse("HHmm", "2422", 0, date) > 0);
192:                assertTrue(date.getHours() == 0);
193:                assertTrue(date.getMinutes() == 22);
194:
195:                assertTrue(parse("HHmma", "0022am", 0, date) > 0);
196:                assertTrue(date.getHours() == 00);
197:                assertTrue(date.getMinutes() == 22);
198:
199:                assertTrue(parse("HHmma", "1122am", 0, date) > 0);
200:                assertTrue(date.getHours() == 11);
201:                assertTrue(date.getMinutes() == 22);
202:
203:                assertTrue(parse("HHmma", "1222am", 0, date) > 0);
204:                assertTrue(date.getHours() == 12);
205:                assertTrue(date.getMinutes() == 22);
206:
207:                assertTrue(parse("HHmma", "2322am", 0, date) > 0);
208:                assertTrue(date.getHours() == 23);
209:                assertTrue(date.getMinutes() == 22);
210:
211:                assertTrue(parse("HHmma", "2422am", 0, date) > 0);
212:                assertTrue(date.getHours() == 0);
213:                assertTrue(date.getMinutes() == 22);
214:
215:                assertTrue(parse("HHmma", "0022pm", 0, date) > 0);
216:                assertTrue(date.getHours() == 12);
217:                assertTrue(date.getMinutes() == 22);
218:
219:                assertTrue(parse("HHmma", "1122pm", 0, date) > 0);
220:                assertTrue(date.getHours() == 23);
221:                assertTrue(date.getMinutes() == 22);
222:
223:                assertTrue(parse("HHmma", "1222pm", 0, date) > 0);
224:                assertTrue(date.getHours() == 12);
225:                assertTrue(date.getMinutes() == 22);
226:
227:                assertTrue(parse("HHmma", "2322pm", 0, date) > 0);
228:                assertTrue(date.getHours() == 23);
229:                assertTrue(date.getMinutes() == 22);
230:
231:                assertTrue(parse("HHmma", "2422pm", 0, date) > 0);
232:                assertTrue(date.getHours() == 0);
233:                assertTrue(date.getMinutes() == 22);
234:            }
235:
236:            public void testHourParsingFhh() {
237:                Date date = new Date();
238:
239:                assertTrue(parse("hhmm", "0022", 0, date) > 0);
240:                assertTrue(date.getHours() == 00);
241:                assertTrue(date.getMinutes() == 22);
242:
243:                assertTrue(parse("hhmm", "1122", 0, date) > 0);
244:                assertTrue(date.getHours() == 11);
245:                assertTrue(date.getMinutes() == 22);
246:
247:                assertTrue(parse("hhmm", "1222", 0, date) > 0);
248:                assertTrue(date.getHours() == 0);
249:                assertTrue(date.getMinutes() == 22);
250:
251:                assertTrue(parse("hhmm", "2322", 0, date) > 0);
252:                assertTrue(date.getHours() == 23);
253:                assertTrue(date.getMinutes() == 22);
254:
255:                assertTrue(parse("hhmm", "2422", 0, date) > 0);
256:                assertTrue(date.getHours() == 0);
257:                assertTrue(date.getMinutes() == 22);
258:
259:                assertTrue(parse("hhmma", "0022am", 0, date) > 0);
260:                assertTrue(date.getHours() == 00);
261:                assertTrue(date.getMinutes() == 22);
262:
263:                assertTrue(parse("hhmma", "1122am", 0, date) > 0);
264:                assertTrue(date.getHours() == 11);
265:                assertTrue(date.getMinutes() == 22);
266:
267:                assertTrue(parse("hhmma", "1222am", 0, date) > 0);
268:                assertTrue(date.getHours() == 0);
269:                assertTrue(date.getMinutes() == 22);
270:
271:                assertTrue(parse("hhmma", "2322am", 0, date) > 0);
272:                assertTrue(date.getHours() == 23);
273:                assertTrue(date.getMinutes() == 22);
274:
275:                assertTrue(parse("hhmma", "2422am", 0, date) > 0);
276:                assertTrue(date.getHours() == 0);
277:                assertTrue(date.getMinutes() == 22);
278:
279:                assertTrue(parse("hhmma", "0022pm", 0, date) > 0);
280:                assertTrue(date.getHours() == 12);
281:                assertTrue(date.getMinutes() == 22);
282:
283:                assertTrue(parse("hhmma", "1122pm", 0, date) > 0);
284:                assertTrue(date.getHours() == 23);
285:                assertTrue(date.getMinutes() == 22);
286:
287:                assertTrue(parse("hhmma", "1222pm", 0, date) > 0);
288:                assertTrue(date.getHours() == 12);
289:                assertTrue(date.getMinutes() == 22);
290:
291:                assertTrue(parse("hhmma", "2322pm", 0, date) > 0);
292:                assertTrue(date.getHours() == 23);
293:                assertTrue(date.getMinutes() == 22);
294:
295:                assertTrue(parse("hhmma", "2422pm", 0, date) > 0);
296:                assertTrue(date.getHours() == 0);
297:                assertTrue(date.getMinutes() == 22);
298:            }
299:
300:            public void testHourParsingFKK() {
301:                Date date = new Date();
302:                assertTrue(parse("KKmm", "0022", 0, date) > 0);
303:                assertTrue(date.getHours() == 00);
304:                assertTrue(date.getMinutes() == 22);
305:
306:                assertTrue(parse("KKmm", "1122", 0, date) > 0);
307:                assertTrue(date.getHours() == 11);
308:                assertTrue(date.getMinutes() == 22);
309:
310:                assertTrue(parse("KKmm", "1222", 0, date) > 0);
311:                assertTrue(date.getHours() == 12);
312:                assertTrue(date.getMinutes() == 22);
313:
314:                assertTrue(parse("KKmm", "2322", 0, date) > 0);
315:                assertTrue(date.getHours() == 23);
316:                assertTrue(date.getMinutes() == 22);
317:
318:                assertTrue(parse("KKmm", "2422", 0, date) > 0);
319:                assertTrue(date.getHours() == 0);
320:                assertTrue(date.getMinutes() == 22);
321:
322:                assertTrue(parse("KKmma", "0022am", 0, date) > 0);
323:                assertTrue(date.getHours() == 00);
324:                assertTrue(date.getMinutes() == 22);
325:
326:                assertTrue(parse("KKmma", "1122am", 0, date) > 0);
327:                assertTrue(date.getHours() == 11);
328:                assertTrue(date.getMinutes() == 22);
329:
330:                assertTrue(parse("KKmma", "1222am", 0, date) > 0);
331:                assertTrue(date.getHours() == 12);
332:                assertTrue(date.getMinutes() == 22);
333:
334:                assertTrue(parse("KKmma", "2322am", 0, date) > 0);
335:                assertTrue(date.getHours() == 23);
336:                assertTrue(date.getMinutes() == 22);
337:
338:                assertTrue(parse("KKmma", "2422am", 0, date) > 0);
339:                assertTrue(date.getHours() == 0);
340:                assertTrue(date.getMinutes() == 22);
341:
342:                assertTrue(parse("KKmma", "0022pm", 0, date) > 0);
343:                assertTrue(date.getHours() == 12);
344:                assertTrue(date.getMinutes() == 22);
345:
346:                assertTrue(parse("KKmma", "1122pm", 0, date) > 0);
347:                assertTrue(date.getHours() == 23);
348:                assertTrue(date.getMinutes() == 22);
349:
350:                assertTrue(parse("KKmma", "1222pm", 0, date) > 0);
351:                assertTrue(date.getHours() == 12);
352:                assertTrue(date.getMinutes() == 22);
353:
354:                assertTrue(parse("KKmma", "2322pm", 0, date) > 0);
355:                assertTrue(date.getHours() == 23);
356:                assertTrue(date.getMinutes() == 22);
357:
358:                assertTrue(parse("KKmma", "2422pm", 0, date) > 0);
359:                assertTrue(date.getHours() == 0);
360:                assertTrue(date.getMinutes() == 22);
361:            }
362:
363:            public void testHourParsingFkk() {
364:                Date date = new Date();
365:                assertTrue(parse("kkmm", "0022", 0, date) > 0);
366:                assertTrue(date.getHours() == 00);
367:                assertTrue(date.getMinutes() == 22);
368:
369:                assertTrue(parse("kkmm", "1122", 0, date) > 0);
370:                assertTrue(date.getHours() == 11);
371:                assertTrue(date.getMinutes() == 22);
372:
373:                assertTrue(parse("kkmm", "1222", 0, date) > 0);
374:                assertTrue(date.getHours() == 12);
375:                assertTrue(date.getMinutes() == 22);
376:
377:                assertTrue(parse("kkmm", "2322", 0, date) > 0);
378:                assertTrue(date.getHours() == 23);
379:                assertTrue(date.getMinutes() == 22);
380:
381:                assertTrue(parse("kkmm", "2422", 0, date) > 0);
382:                assertTrue(date.getHours() == 0);
383:                assertTrue(date.getMinutes() == 22);
384:
385:                assertTrue(parse("kkmma", "0022am", 0, date) > 0);
386:                assertTrue(date.getHours() == 00);
387:                assertTrue(date.getMinutes() == 22);
388:
389:                assertTrue(parse("kkmma", "1122am", 0, date) > 0);
390:                assertTrue(date.getHours() == 11);
391:                assertTrue(date.getMinutes() == 22);
392:
393:                assertTrue(parse("kkmma", "1222am", 0, date) > 0);
394:                assertTrue(date.getHours() == 12);
395:                assertTrue(date.getMinutes() == 22);
396:
397:                assertTrue(parse("kkmma", "2322am", 0, date) > 0);
398:                assertTrue(date.getHours() == 23);
399:                assertTrue(date.getMinutes() == 22);
400:
401:                assertTrue(parse("kkmma", "2422am", 0, date) > 0);
402:                assertTrue(date.getHours() == 0);
403:                assertTrue(date.getMinutes() == 22);
404:
405:                assertTrue(parse("kkmma", "0022pm", 0, date) > 0);
406:                assertTrue(date.getHours() == 12);
407:                assertTrue(date.getMinutes() == 22);
408:
409:                assertTrue(parse("kkmma", "1122pm", 0, date) > 0);
410:                assertTrue(date.getHours() == 23);
411:                assertTrue(date.getMinutes() == 22);
412:
413:                assertTrue(parse("kkmma", "1222pm", 0, date) > 0);
414:                assertTrue(date.getHours() == 12);
415:                assertTrue(date.getMinutes() == 22);
416:
417:                assertTrue(parse("kkmma", "2322pm", 0, date) > 0);
418:                assertTrue(date.getHours() == 23);
419:                assertTrue(date.getMinutes() == 22);
420:
421:                assertTrue(parse("kkmma", "2422pm", 0, date) > 0);
422:                assertTrue(date.getHours() == 0);
423:                assertTrue(date.getMinutes() == 22);
424:            }
425:
426:            public void testLeapYear() {
427:                Date date = new Date();
428:
429:                assertTrue(parse("MMdd, yyyy", "0229, 2001", 0, date) > 0);
430:                assertTrue(date.getMonth() == 3 - 1);
431:                assertTrue(date.getDate() == 1);
432:
433:                assertTrue(parse("MMdd, yyyy", "0229, 2000", 0, date) > 0);
434:                assertTrue(date.getMonth() == 2 - 1);
435:                assertTrue(date.getDate() == 29);
436:            }
437:
438:            public void testPartialParsing() {
439:                // Only specify a date
440:                DateTimeFormat fmt = DateTimeFormat.getFormat("MM-dd-yyyy");
441:                Date dateActual = new Date(87, 10, 22);
442:                Date dateOnly = fmt.parse("11-22-1987");
443:                assertEquals(dateOnly.getHours(), 0);
444:                assertEquals(dateOnly.getMinutes(), 0);
445:                assertEquals(dateOnly.getSeconds(), 0);
446:                assertEquals(dateOnly.getTime(), dateActual.getTime());
447:
448:                // Only specify a time, should use current date
449:                fmt = DateTimeFormat.getFormat("hha");
450:                dateOnly = fmt.parse("4PM");
451:                assertEquals(dateOnly.getHours(), 16);
452:                assertEquals(dateOnly.getMinutes(), 0);
453:                assertEquals(dateOnly.getSeconds(), 0);
454:            }
455:
456:            public void testRFC3339() {
457:                Date date = new Date();
458:
459:                {
460:                    // Parse a string formatted according to RFC3389.
461:                    String rfc3339str = "1985-04-12T23:20:50.52-08:00";
462:                    assertTrue(parse("yyyy-MM-dd'T'HH:mm:ss.SSZ", rfc3339str,
463:                            0, date) > 0);
464:
465:                    // Create the expected time as UTC. The "+8" is due to the tz offset.
466:                    long expectedTimeUTC = Date.UTC(1985 - 1900, 3, 12, 23 + 8,
467:                            20, 50);
468:                    Date expectedDate = new Date(expectedTimeUTC);
469:                    assertEquals(expectedDate.getYear(), date.getYear());
470:                    assertEquals(expectedDate.getMonth(), date.getMonth());
471:                    assertEquals(expectedDate.getDate(), date.getDate());
472:                    assertEquals(expectedDate.getHours(), date.getHours());
473:                    assertEquals(expectedDate.getMinutes(), date.getMinutes());
474:                    assertEquals(expectedDate.getSeconds(), date.getSeconds());
475:                    // Make sure our parse captured the extra 520 milliseconds.
476:                    assertEquals(520, date.getTime() % 1000);
477:                }
478:
479:                {
480:                    // Parse a string formatted according to RFC3389.
481:                    String rfc3339str = "1985-04-12T23:20:50.52Z";
482:                    if (rfc3339str.endsWith("Z")) {
483:                        StringBuffer strbuf = new StringBuffer(rfc3339str);
484:                        strbuf.deleteCharAt(rfc3339str.length() - 1);
485:                        strbuf.append("+00:00");
486:                        rfc3339str = strbuf.toString();
487:                    }
488:                    assertTrue(parse("yyyy-MM-dd'T'HH:mm:ss.SSZ", rfc3339str,
489:                            0, date) > 0);
490:
491:                    // Create the expected time as UTC. The "+0" is because it's already GMT.
492:                    long expectedTimeUTC = Date.UTC(85, 3, 12, 23 + 0, 20, 50);
493:                    Date expectedDate = new Date(expectedTimeUTC);
494:                    assertEquals(expectedDate.getYear(), date.getYear());
495:                    assertEquals(expectedDate.getMonth(), date.getMonth());
496:                    assertEquals(expectedDate.getDate(), date.getDate());
497:                    assertEquals(expectedDate.getHours(), date.getHours());
498:                    assertEquals(expectedDate.getMinutes(), date.getMinutes());
499:                    assertEquals(expectedDate.getSeconds(), date.getSeconds());
500:                    // Make sure our parse captured the extra 520 milliseconds.
501:                    assertEquals(520, date.getTime() % 1000);
502:                }
503:            }
504:
505:            public void testTimeZone() {
506:                Date date = new Date();
507:
508:                assertTrue(parse("MM/dd/yyyy, hh:mm:ss zzz",
509:                        "07/21/2003, 11:22:33 GMT-0700", 0, date) > 0);
510:                int gmtNegative07 = date.getHours();
511:
512:                assertTrue(parse("MM/dd/yyyy, hh:mm:ss zzz",
513:                        "07/21/2003, 11:22:33 GMT-0600", 0, date) > 0);
514:                int gmtNegative06 = date.getHours();
515:                assertTrue((gmtNegative07 + 24 - gmtNegative06) % 24 == 1);
516:
517:                assertTrue(parse("MM/dd/yyyy, hh:mm:ss zzz",
518:                        "07/21/2003, 11:22:33 GMT-0800", 0, date) > 0);
519:                int gmtNegative08 = date.getHours();
520:                assertTrue((gmtNegative08 + 24 - gmtNegative07) % 24 == 1);
521:
522:                assertTrue(parse("MM/dd/yyyy, HH:mm:ss zzz",
523:                        "07/21/2003, 11:22:33 GMT+0800", 0, date) > 0);
524:                int gmtPositive08 = date.getHours();
525:                assertTrue((gmtNegative08 + 24 - gmtPositive08) % 24 == 16);
526:            }
527:
528:            public void testWeekDay() {
529:                Date date = new Date();
530:
531:                assertTrue(parse("EEEE, MM/dd/yyyy", "Wednesday, 08/16/2006",
532:                        0, date) > 0);
533:                assertTrue(date.getYear() == 2006 - 1900);
534:                assertTrue(date.getMonth() == 8 - 1);
535:                assertTrue(date.getDate() == 16);
536:                assertTrue(parse("EEEE, MM/dd/yyyy", "Tuesday, 08/16/2006", 0,
537:                        date) == 0);
538:                assertTrue(parse("EEEE, MM/dd/yyyy", "Thursday, 08/16/2006", 0,
539:                        date) == 0);
540:                assertTrue(parse("EEEE, MM/dd/yyyy", "Wed, 08/16/2006", 0, date) > 0);
541:                assertTrue(parse("EEEE, MM/dd/yyyy", "Wasdfed, 08/16/2006", 0,
542:                        date) == 0);
543:
544:                date.setDate(25);
545:                assertTrue(parse("EEEE, MM/yyyy", "Wed, 09/2006", 0, date) > 0);
546:                assertTrue(date.getDate() == 27);
547:
548:                date.setDate(30);
549:                assertTrue(parse("EEEE, MM/yyyy", "Wed, 09/2006", 0, date) > 0);
550:                assertTrue(date.getDate() == 27);
551:
552:                date.setDate(30);
553:                assertTrue(parse("EEEE, MM/yyyy", "Mon, 09/2006", 0, date) > 0);
554:                assertTrue(date.getDate() == 25);
555:            }
556:
557:            public void testYearParsing() {
558:                Date date = new Date();
559:
560:                assertTrue(parse("yyMMdd", "991202", 0, date) > 0);
561:                assertTrue(date.getYear() == (1999 - 1900));
562:                assertTrue(date.getMonth() == 12 - 1);
563:                assertTrue(date.getDate() == 02);
564:
565:                assertTrue(parse("yyyyMMdd", "20051202", 0, date) > 0);
566:                assertTrue(date.getYear() == (2005 - 1900));
567:                assertTrue(date.getMonth() == 12 - 1);
568:                assertTrue(date.getDate() == 02);
569:            }
570:
571:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.