Skip to content

Commit 4ebd7b5

Browse files
committed
disable year-of-era relaxation to fail tests
1 parent 050ec42 commit 4ebd7b5

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/DateFormat.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ Function<String, ZonedDateTime> getFunction(String format, ZoneId zoneId, Locale
100100
TemporalAccessor accessor = formatter.parse(text);
101101
// if there is no year nor year-of-era, we fall back to the current one and
102102
// fill the rest of the date up with the parsed date
103-
if (accessor.isSupported(ChronoField.YEAR) == false && accessor.isSupported(ChronoField.YEAR_OF_ERA) == false ) {
103+
if (accessor.isSupported(ChronoField.YEAR) == false /*&& accessor.isSupported(ChronoField.YEAR_OF_ERA) == false */) {
104104
int year = LocalDate.now(ZoneOffset.UTC).getYear();
105105
ZonedDateTime newTime = Instant.EPOCH.atZone(ZoneOffset.UTC).withYear(year);
106106
for (ChronoField field : FIELDS) {

server/src/main/java/org/elasticsearch/common/time/DateFormatters.java

+8-4
Original file line numberDiff line numberDiff line change
@@ -1841,7 +1841,7 @@ public static ZonedDateTime from(TemporalAccessor accessor) {
18411841
zoneId = ZoneOffset.UTC;
18421842
}
18431843

1844-
LocalDate localDate = accessor.query(LOCAL_DATE_QUERY);
1844+
LocalDate localDate = accessor.query(TemporalQueries.localDate());//accessor.query(LOCAL_DATE_QUERY);
18451845
LocalTime localTime = accessor.query(TemporalQueries.localTime());
18461846
boolean isLocalDateSet = localDate != null;
18471847
boolean isLocalTimeSet = localTime != null;
@@ -1859,8 +1859,10 @@ public static ZonedDateTime from(TemporalAccessor accessor) {
18591859
if (accessor.isSupported(MONTH_OF_YEAR)) {
18601860
return getFirstOfMonth(accessor).atStartOfDay(zoneId);
18611861
} else {
1862-
int year = getYear(accessor);
1863-
return Year.of(year).atDay(1).atStartOfDay(zoneId);
1862+
return Year.of(accessor.get(ChronoField.YEAR)).atDay(1).atStartOfDay(zoneId);
1863+
1864+
// int year = getYear(accessor);
1865+
// return Year.of(year).atDay(1).atStartOfDay(zoneId);
18641866
}
18651867
} else if (accessor.isSupported(MONTH_OF_YEAR)) {
18661868
// missing year, falling back to the epoch and then filling
@@ -1941,6 +1943,8 @@ private static ZonedDateTime of(LocalDate localDate, LocalTime localTime, ZoneId
19411943

19421944
@SuppressForbidden(reason = "LocalDate.of is fine here")
19431945
private static LocalDate getFirstOfMonth(TemporalAccessor accessor) {
1944-
return LocalDate.of(getYear(accessor), accessor.get(MONTH_OF_YEAR), 1);
1946+
// return LocalDate.of(getYear(accessor), accessor.get(MONTH_OF_YEAR), 1);
1947+
return LocalDate.of(accessor.get(ChronoField.YEAR), accessor.get(MONTH_OF_YEAR), 1);
1948+
19451949
}
19461950
}

0 commit comments

Comments
 (0)