diff --git a/src/org/openstreetmap/josm/io/NmeaReader.java b/src/org/openstreetmap/josm/io/NmeaReader.java
index 62179e6..a803059 100644
a
|
b
|
import org.openstreetmap.josm.data.gpx.GpxConstants;
|
19 | 19 | import org.openstreetmap.josm.data.gpx.GpxData; |
20 | 20 | import org.openstreetmap.josm.data.gpx.ImmutableGpxTrack; |
21 | 21 | import org.openstreetmap.josm.data.gpx.WayPoint; |
| 22 | import org.openstreetmap.josm.tools.date.DateUtils; |
22 | 23 | |
23 | 24 | /** |
24 | 25 | * Reads a NMEA file. Based on information from |
… |
… |
public class NmeaReader {
|
165 | 166 | } |
166 | 167 | |
167 | 168 | public NmeaReader(InputStream source) throws IOException { |
| 169 | rmcTimeFmt.setTimeZone(DateUtils.UTC); |
| 170 | rmcTimeFmtStd.setTimeZone(DateUtils.UTC); |
168 | 171 | |
169 | 172 | // create the data tree |
170 | 173 | data = new GpxData(); |
diff --git a/src/org/openstreetmap/josm/tools/date/DateUtils.java b/src/org/openstreetmap/josm/tools/date/DateUtils.java
index b956925..3cbb811 100644
a
|
b
|
import org.openstreetmap.josm.tools.UncheckedParseException;
|
29 | 29 | */ |
30 | 30 | public final class DateUtils { |
31 | 31 | |
| 32 | /** |
| 33 | * The UTC time zone. |
| 34 | */ |
| 35 | public static final TimeZone UTC = TimeZone.getTimeZone("UTC"); |
| 36 | |
32 | 37 | protected DateUtils() { |
33 | 38 | // Hide default constructor for utils classes |
34 | 39 | } |
… |
… |
public final class DateUtils {
|
45 | 50 | * The shared instance is used because the construction, together |
46 | 51 | * with the timezone lookup, is very expensive. |
47 | 52 | */ |
48 | | private static final GregorianCalendar calendar = new GregorianCalendar(TimeZone.getTimeZone("UTC")); |
| 53 | private static final GregorianCalendar calendar = new GregorianCalendar(UTC); |
49 | 54 | private static final GregorianCalendar calendarLocale = new GregorianCalendar(TimeZone.getDefault()); |
50 | 55 | private static final DatatypeFactory XML_DATE; |
51 | 56 | |
diff --git a/test/unit/org/openstreetmap/josm/io/NmeaReaderTest.java b/test/unit/org/openstreetmap/josm/io/NmeaReaderTest.java
index 88f6ad7..b3172ef 100644
a
|
b
|
import java.util.ArrayList;
|
9 | 9 | import java.util.List; |
10 | 10 | import java.util.TimeZone; |
11 | 11 | |
| 12 | import org.junit.Rule; |
12 | 13 | import org.junit.Test; |
13 | 14 | import org.openstreetmap.josm.data.coor.LatLon; |
14 | 15 | import org.openstreetmap.josm.data.gpx.GpxConstants; |
15 | 16 | import org.openstreetmap.josm.data.gpx.WayPoint; |
16 | 17 | import org.openstreetmap.josm.io.NmeaReader.NMEA_TYPE; |
| 18 | import org.openstreetmap.josm.testutils.JOSMTestRules; |
17 | 19 | |
| 20 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; |
18 | 21 | import nl.jqno.equalsverifier.EqualsVerifier; |
19 | 22 | |
20 | 23 | /** |
21 | 24 | * Unit tests of {@link NmeaReader} class. |
22 | 25 | */ |
23 | 26 | public class NmeaReaderTest { |
| 27 | /** |
| 28 | * Set the timezone and timeout. |
| 29 | */ |
| 30 | @Rule |
| 31 | @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") |
| 32 | public JOSMTestRules test = new JOSMTestRules(); |
24 | 33 | |
25 | 34 | /** |
26 | 35 | * Unit test of methods {@link NMEA_TYPE#equals} and {@link NMEA_TYPE#hashCode}. |
… |
… |
public class NmeaReaderTest {
|
36 | 45 | */ |
37 | 46 | @Test |
38 | 47 | public void testReader() throws Exception { |
| 48 | TimeZone.setDefault(TimeZone.getTimeZone("Europe/Berlin")); |
39 | 49 | final NmeaReader in = new NmeaReader(new FileInputStream("data_nodist/btnmeatrack_2016-01-25.nmea")); |
40 | 50 | assertEquals(30, in.getNumberOfCoordinates()); |
41 | 51 | assertEquals(0, in.getParserMalformed()); |
42 | 52 | |
43 | | TimeZone.setDefault(TimeZone.getTimeZone("Europe/Berlin")); |
44 | 53 | final List<WayPoint> wayPoints = new ArrayList<>(in.data.tracks.iterator().next().getSegments().iterator().next().getWayPoints()); |
45 | | assertEquals("2016-01-25T04:05:09.200Z", wayPoints.get(0).get(GpxConstants.PT_TIME)); |
46 | | assertEquals("2016-01-25T04:05:09.400Z", wayPoints.get(1).get(GpxConstants.PT_TIME)); |
47 | | assertEquals("2016-01-25T04:05:09.600Z", wayPoints.get(2).get(GpxConstants.PT_TIME)); |
| 54 | assertEquals("2016-01-25T05:05:09.200Z", wayPoints.get(0).get(GpxConstants.PT_TIME)); |
| 55 | assertEquals("2016-01-25T05:05:09.400Z", wayPoints.get(1).get(GpxConstants.PT_TIME)); |
| 56 | assertEquals("2016-01-25T05:05:09.600Z", wayPoints.get(2).get(GpxConstants.PT_TIME)); |
48 | 57 | |
49 | 58 | final SimpleDateFormat iso8601 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX"); |
50 | | assertEquals("2016-01-25T05:05:09.200+01", iso8601.format(wayPoints.get(0).getTime())); |
51 | | assertEquals("2016-01-25T05:05:09.400+01", iso8601.format(wayPoints.get(1).getTime())); |
52 | | assertEquals("2016-01-25T05:05:09.600+01", iso8601.format(wayPoints.get(2).getTime())); |
| 59 | assertEquals("2016-01-25T06:05:09.200+01", iso8601.format(wayPoints.get(0).getTime())); |
| 60 | assertEquals("2016-01-25T06:05:09.400+01", iso8601.format(wayPoints.get(1).getTime())); |
| 61 | assertEquals("2016-01-25T06:05:09.600+01", iso8601.format(wayPoints.get(2).getTime())); |
53 | 62 | |
54 | 63 | assertEquals(new LatLon(46.98807, -1.400525), wayPoints.get(0).getCoor()); |
55 | 64 | assertEquals("38.9", wayPoints.get(0).get(GpxConstants.PT_ELE)); |
diff --git a/test/unit/org/openstreetmap/josm/testutils/JOSMTestRules.java b/test/unit/org/openstreetmap/josm/testutils/JOSMTestRules.java
index a6033d0..9fba4cd 100644
a
|
b
|
import org.openstreetmap.josm.io.OsmApi;
|
19 | 19 | import org.openstreetmap.josm.io.OsmApiInitializationException; |
20 | 20 | import org.openstreetmap.josm.io.OsmTransferCanceledException; |
21 | 21 | import org.openstreetmap.josm.tools.I18n; |
| 22 | import org.openstreetmap.josm.tools.date.DateUtils; |
22 | 23 | |
23 | 24 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; |
24 | 25 | |
… |
… |
public class JOSMTestRules implements TestRule {
|
164 | 165 | // Tests are running headless by default. |
165 | 166 | System.setProperty("java.awt.headless", "true"); |
166 | 167 | // All tests use the same timezone. |
167 | | TimeZone.setDefault(TimeZone.getTimeZone("UTC")); |
| 168 | TimeZone.setDefault(DateUtils.UTC); |
168 | 169 | // Set log level to info |
169 | 170 | Main.logLevel = 3; |
170 | 171 | |
diff --git a/test/unit/org/openstreetmap/josm/tools/ExifReaderTest.java b/test/unit/org/openstreetmap/josm/tools/ExifReaderTest.java
index ae18936..7ae3e3a 100644
a
|
b
|
import java.util.Date;
|
14 | 14 | import java.util.GregorianCalendar; |
15 | 15 | import java.util.TimeZone; |
16 | 16 | |
| 17 | import org.junit.After; |
17 | 18 | import org.junit.Before; |
| 19 | import org.junit.Rule; |
18 | 20 | import org.junit.Test; |
19 | 21 | import org.openstreetmap.josm.TestUtils; |
20 | 22 | import org.openstreetmap.josm.data.coor.LatLon; |
| 23 | import org.openstreetmap.josm.testutils.JOSMTestRules; |
| 24 | import org.openstreetmap.josm.tools.date.DateUtils; |
21 | 25 | import org.openstreetmap.josm.tools.date.DateUtilsTest; |
22 | 26 | |
| 27 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; |
| 28 | |
23 | 29 | /** |
24 | 30 | * EXIF metadata extraction test |
25 | 31 | * @since 6209 |
26 | 32 | */ |
27 | 33 | public class ExifReaderTest { |
| 34 | /** |
| 35 | * Set the timezone and timeout. |
| 36 | */ |
| 37 | @Rule |
| 38 | @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") |
| 39 | public JOSMTestRules test = new JOSMTestRules(); |
28 | 40 | |
29 | 41 | private File orientationSampleFile, directionSampleFile; |
30 | 42 | |
… |
… |
public class ExifReaderTest {
|
39 | 51 | } |
40 | 52 | |
41 | 53 | /** |
| 54 | * Clean {@link DateUtils} state |
| 55 | */ |
| 56 | @After |
| 57 | public void done() { |
| 58 | DateUtilsTest.setTimeZone(DateUtils.UTC); |
| 59 | } |
| 60 | |
| 61 | /** |
42 | 62 | * Test time extraction |
43 | 63 | * @throws ParseException if {@link ExifReader#readTime} fails to parse date/time of sample file |
44 | 64 | */ |
45 | 65 | @Test |
46 | 66 | public void testReadTime() throws ParseException { |
47 | 67 | Date date = ExifReader.readTime(directionSampleFile); |
48 | | assertEquals(new GregorianCalendar(2010, Calendar.MAY, 15, 17, 12, 05).getTime(), date); |
| 68 | assertEquals(new GregorianCalendar(2010, Calendar.MAY, 15, 15, 12, 05).getTime(), date); |
49 | 69 | } |
50 | 70 | |
51 | 71 | /** |
… |
… |
public class ExifReaderTest {
|
56 | 76 | public void testReadTimeSubSecond1() throws ParseException { |
57 | 77 | Date date = ExifReader.readTime(new File("data_nodist/IMG_20150711_193419.jpg")); |
58 | 78 | String dateStr = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS").format(date); |
59 | | assertEquals("2015-07-11T19:34:19.100", dateStr); |
| 79 | assertEquals("2015-07-11T17:34:19.100", dateStr); |
60 | 80 | } |
61 | 81 | |
62 | 82 | /** |
… |
… |
public class ExifReaderTest {
|
96 | 116 | public void testTicket11685() throws IOException { |
97 | 117 | File file = new File(TestUtils.getRegressionDataFile(11685, "2015-11-08_15-33-27-Xiaomi_YI-Y0030832.jpg")); |
98 | 118 | String dateStr = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS").format(ExifReader.readTime(file)); |
99 | | assertEquals("2015-11-08T15:33:27.500", dateStr); |
| 119 | assertEquals("2015-11-08T14:33:27.500", dateStr); |
100 | 120 | } |
101 | 121 | } |