Skip to content

Commit 528721d

Browse files
committed
Throw away test dates with year greater than 9999
1 parent 8f42478 commit 528721d

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

x-pack/plugin/logsdb/src/test/java/org/elasticsearch/xpack/logsdb/patternedtext/PatternedTextVsMatchOnlyTextTests.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,15 @@ private static String randomSeparator() {
258258
}
259259

260260
private static String randomTimestamp() {
261-
long millis = randomMillisUpToYear9999();
262-
ZonedDateTime zonedDateTime = ZonedDateTime.ofInstant(Instant.ofEpochMilli(millis), randomZone());
261+
ZonedDateTime zonedDateTime;
262+
do {
263+
long millis = randomMillisUpToYear9999();
264+
zonedDateTime = ZonedDateTime.ofInstant(Instant.ofEpochMilli(millis), randomZone());
265+
266+
// The random millis are below year 10000 in UTC, but if the date is within 1 day of year 10000, the year can be 10000 in the
267+
// selected timezone. Since the date formatter cannot handle years greater than 9999, select another date.
268+
} while (zonedDateTime.getYear() == 10000);
269+
263270
DateFormatter formatter = DateFormatter.forPattern(randomDateFormatterPattern()).withLocale(randomLocale(random()));
264271
return formatter.format(zonedDateTime);
265272
}

0 commit comments

Comments
 (0)