diff --git a/lucene/spatial-extras/src/java/org/apache/lucene/spatial/prefix/tree/DateRangePrefixTree.java b/lucene/spatial-extras/src/java/org/apache/lucene/spatial/prefix/tree/DateRangePrefixTree.java index 31e0a008d12..2466b235dae 100644 --- a/lucene/spatial-extras/src/java/org/apache/lucene/spatial/prefix/tree/DateRangePrefixTree.java +++ b/lucene/spatial-extras/src/java/org/apache/lucene/spatial/prefix/tree/DateRangePrefixTree.java @@ -488,7 +488,7 @@ public class DateRangePrefixTree extends NumberRangePrefixTree { checkDelimeter(str, offset-1, ':'); //minute: - parsedVal = parseAndCheck( str, offset, 1, 60); + parsedVal = parseAndCheck( str, offset, 0, 59); cal.set(Calendar.MINUTE, parsedVal); offset += 3; if (lastOffset < offset) @@ -496,7 +496,7 @@ public class DateRangePrefixTree extends NumberRangePrefixTree { checkDelimeter(str, offset-1, ':'); //second: - parsedVal = parseAndCheck( str, offset, 1, 60); + parsedVal = parseAndCheck( str, offset, 0, 59); cal.set(Calendar.SECOND, parsedVal); offset += 3; if (lastOffset < offset) diff --git a/lucene/spatial-extras/src/test/org/apache/lucene/spatial/prefix/tree/DateRangePrefixTreeTest.java b/lucene/spatial-extras/src/test/org/apache/lucene/spatial/prefix/tree/DateRangePrefixTreeTest.java index f9f3d12df74..0670a268c8d 100644 --- a/lucene/spatial-extras/src/test/org/apache/lucene/spatial/prefix/tree/DateRangePrefixTreeTest.java +++ b/lucene/spatial-extras/src/test/org/apache/lucene/spatial/prefix/tree/DateRangePrefixTreeTest.java @@ -94,7 +94,7 @@ public class DateRangePrefixTreeTest extends LuceneTestCase { roundTrip(cal); } - public void testToStringISO8601() { + public void testToStringISO8601() throws ParseException { Calendar cal = tree.newCal(); cal.setTimeInMillis(random().nextLong()); // create ZonedDateTime from the calendar, then get toInstant.toString which is the ISO8601 we emulate @@ -110,6 +110,7 @@ public class DateRangePrefixTreeTest extends LuceneTestCase { .toInstant().toString(); String resultToString = tree.toString(cal) + 'Z'; assertEquals(expectedISO8601, resultToString); + assertEquals(cal, tree.parseCalendar(expectedISO8601)); } //copies from DateRangePrefixTree @@ -211,7 +212,11 @@ public class DateRangePrefixTreeTest extends LuceneTestCase { } public void testInvalidDateException() throws ParseException { - + { + Calendar jurasic = tree.parseCalendar("-187183959-07-06T11:00:57.156"); + assertEquals(187183960, jurasic.get(Calendar.YEAR)); + assertEquals(0, jurasic.get(Calendar.ERA)); + } expectThrows(ParseException.class, () -> { tree.parseCalendar("2000-11T13"); });