Build local year inside DateFormat lambda

bugfix for https://github.com/elastic/elasticsearch/issues/41797 (#42120)

This makes sure that the year can change between when the lambda is generated and when it is executed without causing the incorrect year to be used.

Resolves #41797
This commit is contained in:
emasab 2019-05-23 18:35:39 +02:00 committed by Lee Hinman
parent c9ed91312a
commit a142e8cfd8
1 changed files with 1 additions and 1 deletions

View File

@ -89,7 +89,6 @@ enum DateFormat {
boolean isUtc = ZoneOffset.UTC.equals(zoneId);
int year = LocalDate.now(ZoneOffset.UTC).getYear();
DateFormatter dateFormatter = DateFormatter.forPattern(format)
.withLocale(locale);
// if UTC zone is set here, the time zone specified in the format will be ignored, leading to wrong dates
@ -102,6 +101,7 @@ enum DateFormat {
// if there is no year, we fall back to the current one and
// fill the rest of the date up with the parsed date
if (accessor.isSupported(ChronoField.YEAR) == false) {
int year = LocalDate.now(ZoneOffset.UTC).getYear();
ZonedDateTime newTime = Instant.EPOCH.atZone(ZoneOffset.UTC).withYear(year);
for (ChronoField field : FIELDS) {
if (accessor.isSupported(field)) {