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:
parent
c9ed91312a
commit
a142e8cfd8
|
@ -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)) {
|
||||
|
|
Loading…
Reference in New Issue