Changeset 9739 in josm


Ignore:
Timestamp:
2016-02-04T22:14:23+01:00 (6 years ago)
Author:
simon04
Message:

see #12485 - Fix parsing of sub-seconds

Sometimes there are really strange bugs …

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/tools/date/DateUtils.java

    r9394 r9739  
    9595                parsePart2(str, 14),
    9696                parsePart2(str, 17));
     97            c.set(Calendar.MILLISECOND, 0);
    9798
    9899            if (str.length() == 25) {
     
    116117                parsePart2(str, 14),
    117118                parsePart2(str, 17));
     119            c.set(Calendar.MILLISECOND, 0);
    118120            long millis = parsePart3(str, 20);
    119121            if (str.length() == 29) {
  • trunk/test/unit/org/openstreetmap/josm/tools/date/DateUtilsTest.java

    r9401 r9739  
    44import static org.junit.Assert.assertEquals;
    55
     6import java.util.Date;
    67import java.util.TimeZone;
    78
     
    7475        DateUtils.fromString("2014-");
    7576    }
     77
     78    /**
     79     * Tests that formatting a date w/ milliseconds does not cause incorrect parsing afterwards
     80     */
     81    @Test
     82    public void testFormattingMillisecondsDoesNotCauseIncorrectParsing() {
     83        DateUtils.fromDate(new Date(123));
     84        assertEquals(1453694709000L, DateUtils.fromString("2016-01-25T04:05:09.000Z").getTime());
     85        assertEquals(1453694709200L, DateUtils.fromString("2016-01-25T04:05:09.200Z").getTime());
     86        assertEquals(1453694709400L, DateUtils.fromString("2016-01-25T04:05:09.400Z").getTime());
     87    }
    7688}
Note: See TracChangeset for help on using the changeset viewer.