source: josm/trunk/test/unit/org/openstreetmap/josm/tools/date/DateUtilsTest.java@ 9383

Last change on this file since 9383 was 9383, checked in by simon04, 8 years ago

Deprecate PrimaryDateParser in favour of DateUtils

  • Property svn:eol-style set to native
File size: 1.9 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.tools.date;
3
4import static org.junit.Assert.assertEquals;
5
6import java.util.TimeZone;
7
8import org.junit.BeforeClass;
9import org.junit.Test;
10
11/**
12 * Unit tests of {@link DateUtils} class.
13 */
14public class DateUtilsTest {
15
16 /**
17 * Setup test.
18 */
19 @BeforeClass
20 public static void setUp() {
21 TimeZone.setDefault(TimeZone.getTimeZone("GMT+8:00"));
22 }
23
24 /**
25 * Test to parse date as returned for map data.
26 */
27 @Test
28 public void testMapDate() {
29 assertEquals(1344870637000L, DateUtils.fromString("2012-08-13T15:10:37Z").getTime());
30 }
31
32 /**
33 * Test to parse date as returned for note data.
34 */
35 @Test
36 public void testNoteDate() {
37 assertEquals(1417298930000L, DateUtils.fromString("2014-11-29 22:08:50 UTC").getTime());
38 }
39
40 /**
41 * Test to parse date as used in EXIF structures.
42 */
43 @Test
44 public void testExifDate() {
45 assertEquals(1443038712000L - 8 * 3600 * 1000, DateUtils.fromString("2015:09:23 20:05:12").getTime());
46 assertEquals(1443038712888L - 8 * 3600 * 1000, DateUtils.fromString("2015:09:23 20:05:12.888").getTime());
47 }
48
49 /**
50 * Test to parse date as used in GPX files
51 */
52 @Test
53 public void testGPXDate() {
54 assertEquals(1277465405000L, DateUtils.fromString("2010-06-25T11:30:05.000Z").getTime());
55 }
56
57 /**
58 * Test to parse date as defined in <a href="https://tools.ietf.org/html/rfc3339">RFC 3339</a>
59 */
60 @Test
61 public void testRfc3339() {
62 // examples taken from RFC
63 assertEquals(482196050520L, DateUtils.fromString("1985-04-12T23:20:50.52Z").getTime());
64 assertEquals(851042397000L, DateUtils.fromString("1996-12-19T16:39:57-08:00").getTime());
65 assertEquals(-1041337172130L, DateUtils.fromString("1937-01-01T12:00:27.87+00:20").getTime());
66 }
67}
Note: See TracBrowser for help on using the repository browser.