Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,15 @@ private static String randomSeparator() {
}

private static String randomTimestamp() {
long millis = randomMillisUpToYear9999();
ZonedDateTime zonedDateTime = ZonedDateTime.ofInstant(Instant.ofEpochMilli(millis), randomZone());
ZonedDateTime zonedDateTime;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: maybe use randomValueOtherThanMany?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @dnhatn! Oh nice, randomValueOtherThanMany makes it much cleaner

do {
long millis = randomMillisUpToYear9999();
zonedDateTime = ZonedDateTime.ofInstant(Instant.ofEpochMilli(millis), randomZone());

// 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
// selected timezone. Since the date formatter cannot handle years greater than 9999, select another date.
} while (zonedDateTime.getYear() == 10000);

DateFormatter formatter = DateFormatter.forPattern(randomDateFormatterPattern()).withLocale(randomLocale(random()));
return formatter.format(zonedDateTime);
}
Expand Down