Skip to content

Commit 7157f5a

Browse files
author
Peter
committed
Duration parsing dependent from current time, fix graphhopper#588
1 parent 6629569 commit 7157f5a

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

core/src/main/java/com/graphhopper/reader/OSMTagParser.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
*/
2929
public class OSMTagParser
3030
{
31+
// Calendar cal = Calendar.getInstance();cal.set(2015, 11, 1); cal.getTimeInMillis(), see #588
32+
private final static Date STATIC_DATE = new Date(1448924400000L);
33+
3134
/**
3235
* Parser according to http://wiki.openstreetmap.org/wiki/Key:duration The value consists of a
3336
* string ala 'hh:mm', format for hours and minutes 'mm', 'hh:mm' or 'hh:mm:ss', or
@@ -50,7 +53,7 @@ public static long parseDuration( String str ) throws IllegalArgumentException
5053
try
5154
{
5255
dur = DatatypeFactory.newInstance().newDuration(str);
53-
seconds = dur.getTimeInMillis(new Date()) / 1000;
56+
seconds = dur.getTimeInMillis(STATIC_DATE) / 1000;
5457
} catch (Exception ex)
5558
{
5659
throw new IllegalArgumentException("Cannot parse duration tag value: " + str, ex);

core/src/test/java/com/graphhopper/reader/OSMTagParserTest.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public class OSMTagParserTest
3030
{
3131
@Test
3232
public void testParseDuration()
33-
{
33+
{
3434
assertEquals(10 * 60, OSMTagParser.parseDuration("00:10"));
3535
assertEquals(35 * 60, OSMTagParser.parseDuration("35"));
3636
assertEquals(70 * 60, OSMTagParser.parseDuration("01:10"));
@@ -40,11 +40,8 @@ public void testParseDuration()
4040
assertEquals(20 * 60, OSMTagParser.parseDuration("0:20:00"));
4141
assertEquals((60 * 2 + 20) * 60 + 2, OSMTagParser.parseDuration("02:20:02"));
4242

43-
// two months, see #588
44-
// 28+31
45-
assertTrue(2 * 28 * 24 * 60 * 60 <= OSMTagParser.parseDuration("P2M"));
46-
// 31+31
47-
assertTrue(2 * 31 * 24 * 60 * 60 >= OSMTagParser.parseDuration("P2M"));
43+
// two months
44+
assertEquals(31 + 31, OSMTagParser.parseDuration("P2M") / (24 * 60 * 60));
4845

4946
// two minutes
5047
assertEquals(2 * 60, OSMTagParser.parseDuration("PT2M"));

0 commit comments

Comments
 (0)