source: josm/test/unit/org/openstreetmap/josm/tools/DateParserTest.java@ 298

Last change on this file since 298 was 298, checked in by imi, 17 years ago
  • added license description to head of each source file
File size: 1.1 KB
Line 
1// License: GPL. Copyright 2007 by Immanuel Scholz and others
2package org.openstreetmap.josm.tools;
3
4import java.text.ParseException;
5import java.text.SimpleDateFormat;
6import java.util.Date;
7
8import junit.framework.TestCase;
9
10import org.openstreetmap.josm.tools.DateParser;
11
12public class DateParserTest extends TestCase {
13
14 public void testWrong() throws Exception {
15 try {
16 DateParser.parse("imi");
17 assertTrue(false);
18 } catch (ParseException pe) {
19 }
20 }
21
22 public void testRight() throws Exception {
23 Date d = new SimpleDateFormat("dd MM yyyy HH mm ss SSS Z").parse("23 11 2001 23 05 42 123 +0100");
24 Date d2 = new Date(d.getTime()-123);
25 assertEquals(d2, DateParser.parse("11/23/2001 23:05:42"));
26 assertEquals(d2, DateParser.parse("11/23/2001T23:05:42"));
27 assertEquals(d2, DateParser.parse("11/23/2001T23:05:42+001"));
28 assertEquals(d2, DateParser.parse("2001-11-23T23:05:42+01:00"));
29 assertEquals(d, DateParser.parse("11/23/2001T23:05:42.123"));
30 assertEquals(d, DateParser.parse("11/23/2001T23:05:42.123+001"));
31 }
32}
Note: See TracBrowser for help on using the repository browser.