Changeset 17114 in josm
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/tools/date/DateUtils.java
r17104 r17114 68 68 public static long tsFromString(String str) { 69 69 // "2007-07-25T09:26:24{Z|{+|-}01[:00]}" 70 if (checkLayout(str, "xxxx-xx-xx")) { 70 if (checkLayout(str, "xxxx-xx-xx") || 71 checkLayout(str, "xxxx-xx") || 72 checkLayout(str, "xxxx")) { 71 73 final ZonedDateTime local = ZonedDateTime.of( 72 74 parsePart4(str, 0), 73 parsePart2(str, 5),74 parsePart2(str, 8),75 str.length() > 5 ? parsePart2(str, 5) : 1, 76 str.length() > 8 ? parsePart2(str, 8) : 1, 75 77 0, 0, 0, 0, ZoneOffset.UTC); 76 78 return local.toInstant().toEpochMilli(); … … 129 131 try { 130 132 // slow path for fractional seconds different from millisecond precision 131 return Instant.parse(str).toEpochMilli();133 return ZonedDateTime.parse(str).toInstant().toEpochMilli(); 132 134 } catch (IllegalArgumentException | DateTimeParseException ex) { 133 135 throw new UncheckedParseException("The date string (" + str + ") could not be parsed.", ex); -
trunk/test/unit/org/openstreetmap/josm/data/osm/search/SearchCompilerTest.java
r16618 r17114 432 432 @Test 433 433 public void testTimestamp() throws SearchParseError { 434 final Match search = SearchCompiler.compile("timestamp:2010/2011");435 434 final Node n1 = new Node(); 436 435 n1.setTimestamp(DateUtils.fromString("2010-01-22")); 437 assertTrue(search.match(n1)); 436 assertTrue(SearchCompiler.compile("timestamp:2010/2011").match(n1)); 437 assertTrue(SearchCompiler.compile("timestamp:2010-01/2011").match(n1)); 438 assertTrue(SearchCompiler.compile("timestamp:2010-01-22/2011").match(n1)); 439 assertFalse(SearchCompiler.compile("timestamp:2010-01-23/2011").match(n1)); 440 assertFalse(SearchCompiler.compile("timestamp:2010/2010-01-21").match(n1)); 438 441 n1.setTimestamp(DateUtils.fromString("2016-01-22")); 439 assertFalse( search.match(n1));442 assertFalse(SearchCompiler.compile("timestamp:2010/2011").match(n1)); 440 443 } 441 444 -
trunk/test/unit/org/openstreetmap/josm/tools/date/DateUtilsTest.java
r17104 r17114 96 96 assertEquals(851042397000L, DateUtils.fromString("1996-12-19T16:39:57-08:00").getTime()); 97 97 assertEquals(-1041337172130L, DateUtils.fromString("1937-01-01T12:00:27.87+00:20").getTime()); 98 // (partial) dates 99 assertEquals(482112000000L, DateUtils.fromString("1985-04-12").getTime()); 100 assertEquals(481161600000L, DateUtils.fromString("1985-04").getTime()); 101 assertEquals(473385600000L, DateUtils.fromString("1985").getTime()); 98 102 } 99 103
Note:
See TracChangeset
for help on using the changeset viewer.