Changeset 17987 in josm


Ignore:
Timestamp:
2021-07-10T22:54:00+02:00 (3 years ago)
Author:
Don-vip
Message:

fix #20992 - see #17829 - support UTC dates with 6 digits

Location:
trunk
Files:
1 added
3 edited

Legend:

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

    r17911 r17987  
    136136            }
    137137            return local.toInstant();
     138        } else if (checkLayout(str, "xxxx/xx/xx xx:xx:xx.xxxxxx")) {
     139            return ZonedDateTime.of(
     140                parsePart4(str, 0),
     141                parsePart2(str, 5),
     142                parsePart2(str, 8),
     143                parsePart2(str, 11),
     144                parsePart2(str, 14),
     145                parsePart2(str, 17),
     146                parsePart6(str, 20) * 1_000,
     147                ZoneOffset.UTC
     148            ).toInstant();
    138149        } else {
    139150            // example date format "18-AUG-08 13:33:03"
     
    232243    }
    233244
     245    private static int parsePart6(String str, int off) {
     246        return 100000 * num(str.charAt(off))
     247              + 10000 * num(str.charAt(off + 1))
     248               + 1000 * num(str.charAt(off + 2))
     249                + 100 * num(str.charAt(off + 3))
     250                 + 10 * num(str.charAt(off + 4))
     251                      + num(str.charAt(off + 5));
     252    }
     253
    234254    /**
    235255     * Returns a new {@code SimpleDateFormat} for date only, according to <a href="https://en.wikipedia.org/wiki/ISO_8601">ISO 8601</a>.
  • trunk/test/unit/org/openstreetmap/josm/io/rtklib/RtkLibPosReaderTest.java

    r17715 r17987  
    7676        assertEquals(6, in.getNumberOfCoordinates());
    7777    }
     78
     79    /**
     80     * Tests reading another RTKLib pos file with yet another different date format.
     81     * @throws Exception if any error occurs
     82     */
     83    @Test
     84    void testReader3() throws Exception {
     85        RtkLibPosReader in = read("nodist/data/rtklib_example3.pos");
     86        assertEquals(1, in.getNumberOfCoordinates());
     87    }
    7888}
  • trunk/test/unit/org/openstreetmap/josm/tools/date/DateUtilsTest.java

    r17912 r17987  
    103103        assertEquals(481161600000L, DateUtils.fromString("1985-04").getTime());
    104104        assertEquals(473385600000L, DateUtils.fromString("1985").getTime());
     105    }
     106
     107    @Test
     108    void testRtklib() {
     109        // examples taken from rtklib .pos files
     110        assertEquals("2019-04-21T08:20:32Z", DateUtils.parseInstant("2019/04/21 08:20:32").toString());
     111        assertEquals("2019-06-08T08:23:12.123Z", DateUtils.parseInstant("2019/06/08 08:23:12.123").toString());
     112        assertEquals("2021-03-30T15:04:01.123456Z", DateUtils.parseInstant("2021/03/30 15:04:01.123456").toString());
    105113    }
    106114
Note: See TracChangeset for help on using the changeset viewer.