diff --git a/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/DateFormat.java b/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/DateFormat.java index be5d7e47f1c02..c4b96bb06b0b2 100644 --- a/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/DateFormat.java +++ b/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/DateFormat.java @@ -98,9 +98,9 @@ Function getFunction(String format, ZoneId zoneId, Locale final DateFormatter formatter = dateFormatter; return text -> { TemporalAccessor accessor = formatter.parse(text); - // if there is no year, we fall back to the current one and + // if there is no year nor year-of-era, 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) { + if (accessor.isSupported(ChronoField.YEAR) == false && accessor.isSupported(ChronoField.YEAR_OF_ERA) == false ) { int year = LocalDate.now(ZoneOffset.UTC).getYear(); ZonedDateTime newTime = Instant.EPOCH.atZone(ZoneOffset.UTC).withYear(year); for (ChronoField field : FIELDS) { diff --git a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/DateFormatTests.java b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/DateFormatTests.java index e44e62be8629a..a9adab4e7f5db 100644 --- a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/DateFormatTests.java +++ b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/DateFormatTests.java @@ -44,7 +44,7 @@ public void testParseJava() { equalTo("11 24 01:29:01")); } - public void testParseJavaWithTimeZone() { + public void testParseYearOfEraJavaWithTimeZone() { Function javaFunction = DateFormat.Java.getFunction("yyyy-MM-dd'T'HH:mm:ss.SSSZZ", ZoneOffset.UTC, Locale.ROOT); ZonedDateTime datetime = javaFunction.apply("2018-02-05T13:44:56.657+0100"); @@ -52,6 +52,14 @@ public void testParseJavaWithTimeZone() { assertThat(expectedDateTime, is("2018-02-05T12:44:56.657Z")); } + public void testParseYearJavaWithTimeZone() { + Function javaFunction = DateFormat.Java.getFunction("uuuu-MM-dd'T'HH:mm:ss.SSSZZ", + ZoneOffset.UTC, Locale.ROOT); + ZonedDateTime datetime = javaFunction.apply("2018-02-05T13:44:56.657+0100"); + String expectedDateTime = DateFormatter.forPattern("yyyy-MM-dd'T'HH:mm:ss.SSSXXX").withZone(ZoneOffset.UTC).format(datetime); + assertThat(expectedDateTime, is("2018-02-05T12:44:56.657Z")); + } + public void testParseJavaDefaultYear() { String format = randomFrom("8dd/MM", "dd/MM"); ZoneId timezone = DateUtils.of("Europe/Amsterdam"); diff --git a/server/src/main/java/org/elasticsearch/common/time/DateFormatters.java b/server/src/main/java/org/elasticsearch/common/time/DateFormatters.java index 01fb4a61a36e1..65899c3c128cc 100644 --- a/server/src/main/java/org/elasticsearch/common/time/DateFormatters.java +++ b/server/src/main/java/org/elasticsearch/common/time/DateFormatters.java @@ -39,6 +39,7 @@ import java.time.temporal.TemporalAccessor; import java.time.temporal.TemporalAdjusters; import java.time.temporal.TemporalQueries; +import java.time.temporal.TemporalQuery; import java.time.temporal.WeekFields; import static java.time.temporal.ChronoField.DAY_OF_MONTH; @@ -54,7 +55,8 @@ public class DateFormatters { private static final DateTimeFormatter TIME_ZONE_FORMATTER_NO_COLON = new DateTimeFormatterBuilder() .appendOffset("+HHmm", "Z") - .toFormatter(IsoLocale.ROOT); + .toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT); private static final DateTimeFormatter STRICT_YEAR_MONTH_DAY_FORMATTER = new DateTimeFormatterBuilder() .appendValue(ChronoField.YEAR, 4, 10, SignStyle.EXCEEDS_PAD) @@ -66,7 +68,9 @@ public class DateFormatters { .appendValue(DAY_OF_MONTH, 2, 2, SignStyle.NOT_NEGATIVE) .optionalEnd() .optionalEnd() - .toFormatter(IsoLocale.ROOT); + .toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT); + private static final DateTimeFormatter STRICT_HOUR_MINUTE_SECOND_FORMATTER = new DateTimeFormatterBuilder() .appendValue(HOUR_OF_DAY, 2, 2, SignStyle.NOT_NEGATIVE) @@ -74,7 +78,8 @@ public class DateFormatters { .appendValue(MINUTE_OF_HOUR, 2, 2, SignStyle.NOT_NEGATIVE) .appendLiteral(':') .appendValue(SECOND_OF_MINUTE, 2, 2, SignStyle.NOT_NEGATIVE) - .toFormatter(IsoLocale.ROOT); + .toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT); private static final DateTimeFormatter STRICT_DATE_OPTIONAL_TIME_PRINTER = new DateTimeFormatterBuilder() .append(STRICT_YEAR_MONTH_DAY_FORMATTER) @@ -96,7 +101,8 @@ public class DateFormatters { .optionalEnd() .optionalEnd() .optionalEnd() - .toFormatter(IsoLocale.ROOT); + .toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT); private static final DateTimeFormatter STRICT_DATE_OPTIONAL_TIME_FORMATTER = new DateTimeFormatterBuilder() .append(STRICT_YEAR_MONTH_DAY_FORMATTER) @@ -127,7 +133,8 @@ public class DateFormatters { .optionalEnd() .optionalEnd() .optionalEnd() - .toFormatter(IsoLocale.ROOT); + .toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT); /** * Returns a generic ISO datetime parser where the date is mandatory and the time is optional. @@ -154,7 +161,8 @@ public class DateFormatters { .append(TIME_ZONE_FORMATTER_NO_COLON) .optionalEnd() .optionalEnd() - .toFormatter(IsoLocale.ROOT); + .toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT); private static final DateTimeFormatter STRICT_DATE_OPTIONAL_TIME_PRINTER_NANOS = new DateTimeFormatterBuilder() .append(STRICT_YEAR_MONTH_DAY_FORMATTER) @@ -176,7 +184,8 @@ public class DateFormatters { .optionalEnd() .optionalEnd() .optionalEnd() - .toFormatter(IsoLocale.ROOT); + .toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT); /** * Returns a generic ISO datetime parser where the date is mandatory and the time is optional with nanosecond resolution. @@ -219,7 +228,8 @@ public class DateFormatters { .append(TIME_ZONE_FORMATTER_NO_COLON) .optionalEnd() .optionalEnd() - .toFormatter(IsoLocale.ROOT)); + .toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT)); ///////////////////////////////////////// // @@ -234,7 +244,8 @@ public class DateFormatters { .appendValue(HOUR_OF_DAY, 2, 2, SignStyle.NOT_NEGATIVE) .appendValue(MINUTE_OF_HOUR, 2, 2, SignStyle.NOT_NEGATIVE) .appendValue(SECOND_OF_MINUTE, 2, 2, SignStyle.NOT_NEGATIVE) - .toFormatter(IsoLocale.ROOT); + .toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT); /* * Returns a basic formatter for a two digit hour of day, two digit minute @@ -242,10 +253,13 @@ public class DateFormatters { */ private static final DateFormatter BASIC_TIME_NO_MILLIS = new JavaDateFormatter("basic_time_no_millis", new DateTimeFormatterBuilder().append(BASIC_TIME_NO_MILLIS_BASE).appendOffset("+HH:MM", "Z") - .toFormatter(IsoLocale.ROOT), - new DateTimeFormatterBuilder().append(BASIC_TIME_NO_MILLIS_BASE).appendZoneOrOffsetId().toFormatter(IsoLocale.ROOT), + .toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT), + new DateTimeFormatterBuilder().append(BASIC_TIME_NO_MILLIS_BASE).appendZoneOrOffsetId().toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT), new DateTimeFormatterBuilder().append(BASIC_TIME_NO_MILLIS_BASE).append(TIME_ZONE_FORMATTER_NO_COLON) .toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT) ); private static final DateTimeFormatter BASIC_TIME_FORMATTER = new DateTimeFormatterBuilder() @@ -253,14 +267,16 @@ public class DateFormatters { .appendValue(MINUTE_OF_HOUR, 2, 2, SignStyle.NOT_NEGATIVE) .appendValue(SECOND_OF_MINUTE, 2, 2, SignStyle.NOT_NEGATIVE) .appendFraction(NANO_OF_SECOND, 1, 9, true) - .toFormatter(IsoLocale.ROOT); + .toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT); private static final DateTimeFormatter BASIC_TIME_PRINTER = new DateTimeFormatterBuilder() .appendValue(HOUR_OF_DAY, 2, 2, SignStyle.NOT_NEGATIVE) .appendValue(MINUTE_OF_HOUR, 2, 2, SignStyle.NOT_NEGATIVE) .appendValue(SECOND_OF_MINUTE, 2, 2, SignStyle.NOT_NEGATIVE) .appendFraction(NANO_OF_SECOND, 3, 3, true) - .toFormatter(IsoLocale.ROOT); + .toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT); /* * Returns a basic formatter for a two digit hour of day, two digit minute @@ -269,17 +285,22 @@ public class DateFormatters { */ private static final DateFormatter BASIC_TIME = new JavaDateFormatter("basic_time", new DateTimeFormatterBuilder().append(BASIC_TIME_PRINTER).appendOffset("+HH:MM", "Z") - .toFormatter(IsoLocale.ROOT), - new DateTimeFormatterBuilder().append(BASIC_TIME_FORMATTER).appendZoneOrOffsetId().toFormatter(IsoLocale.ROOT), + .toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT), + new DateTimeFormatterBuilder().append(BASIC_TIME_FORMATTER).appendZoneOrOffsetId().toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT), new DateTimeFormatterBuilder().append(BASIC_TIME_FORMATTER).append(TIME_ZONE_FORMATTER_NO_COLON) .toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT) ); private static final DateTimeFormatter BASIC_T_TIME_PRINTER = - new DateTimeFormatterBuilder().appendLiteral("T").append(BASIC_TIME_PRINTER).toFormatter(IsoLocale.ROOT); + new DateTimeFormatterBuilder().appendLiteral("T").append(BASIC_TIME_PRINTER).toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT); private static final DateTimeFormatter BASIC_T_TIME_FORMATTER = - new DateTimeFormatterBuilder().appendLiteral("T").append(BASIC_TIME_FORMATTER).toFormatter(IsoLocale.ROOT); + new DateTimeFormatterBuilder().appendLiteral("T").append(BASIC_TIME_FORMATTER).toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT); /* * Returns a basic formatter for a two digit hour of day, two digit minute @@ -287,8 +308,10 @@ public class DateFormatters { * offset prefixed by 'T' ('T'HHmmss.SSSZ). */ private static final DateFormatter BASIC_T_TIME = new JavaDateFormatter("basic_t_time", - new DateTimeFormatterBuilder().append(BASIC_T_TIME_PRINTER).appendOffset("+HH:MM", "Z").toFormatter(IsoLocale.ROOT), - new DateTimeFormatterBuilder().append(BASIC_T_TIME_FORMATTER).appendZoneOrOffsetId().toFormatter(IsoLocale.ROOT), + new DateTimeFormatterBuilder().append(BASIC_T_TIME_PRINTER).appendOffset("+HH:MM", "Z").toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT), + new DateTimeFormatterBuilder().append(BASIC_T_TIME_FORMATTER).appendZoneOrOffsetId().toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT), new DateTimeFormatterBuilder().append(BASIC_T_TIME_FORMATTER).append(TIME_ZONE_FORMATTER_NO_COLON). toFormatter(IsoLocale.ROOT) ); @@ -300,88 +323,107 @@ public class DateFormatters { */ private static final DateFormatter BASIC_T_TIME_NO_MILLIS = new JavaDateFormatter("basic_t_time_no_millis", new DateTimeFormatterBuilder().appendLiteral("T").append(BASIC_TIME_NO_MILLIS_BASE) - .appendOffset("+HH:MM", "Z").toFormatter(IsoLocale.ROOT), + .appendOffset("+HH:MM", "Z").toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT), new DateTimeFormatterBuilder().appendLiteral("T").append(BASIC_TIME_NO_MILLIS_BASE) - .appendZoneOrOffsetId().toFormatter(IsoLocale.ROOT), + .appendZoneOrOffsetId().toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT), new DateTimeFormatterBuilder().appendLiteral("T").append(BASIC_TIME_NO_MILLIS_BASE) .append(TIME_ZONE_FORMATTER_NO_COLON) - .toFormatter(IsoLocale.ROOT) + .toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT) ); private static final DateTimeFormatter BASIC_YEAR_MONTH_DAY_FORMATTER = new DateTimeFormatterBuilder() .appendValue(ChronoField.YEAR, 4, 4, SignStyle.NORMAL) .appendValue(MONTH_OF_YEAR, 2, 2, SignStyle.NOT_NEGATIVE) .appendValue(DAY_OF_MONTH, 2, 2, SignStyle.NOT_NEGATIVE) - .toFormatter(IsoLocale.ROOT); + .toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT); private static final DateTimeFormatter BASIC_DATE_TIME_FORMATTER = new DateTimeFormatterBuilder() .append(BASIC_YEAR_MONTH_DAY_FORMATTER) .append(BASIC_T_TIME_FORMATTER) - .toFormatter(IsoLocale.ROOT); + .toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT); private static final DateTimeFormatter BASIC_DATE_TIME_PRINTER = new DateTimeFormatterBuilder() .append(BASIC_YEAR_MONTH_DAY_FORMATTER) .append(BASIC_T_TIME_PRINTER) - .toFormatter(IsoLocale.ROOT); + .toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT); /* * Returns a basic formatter that combines a basic date and time, separated - * by a 'T' (yyyyMMdd'T'HHmmss.SSSZ). + * by a 'T' (uuuuMMdd'T'HHmmss.SSSZ). */ private static final DateFormatter BASIC_DATE_TIME = new JavaDateFormatter("basic_date_time", - new DateTimeFormatterBuilder().append(BASIC_DATE_TIME_PRINTER).appendOffset("+HH:MM", "Z").toFormatter(IsoLocale.ROOT), - new DateTimeFormatterBuilder().append(BASIC_DATE_TIME_FORMATTER).appendZoneOrOffsetId().toFormatter(IsoLocale.ROOT), + new DateTimeFormatterBuilder().append(BASIC_DATE_TIME_PRINTER).appendOffset("+HH:MM", "Z").toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT), + new DateTimeFormatterBuilder().append(BASIC_DATE_TIME_FORMATTER).appendZoneOrOffsetId().toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT), new DateTimeFormatterBuilder().append(BASIC_DATE_TIME_FORMATTER).append(TIME_ZONE_FORMATTER_NO_COLON).toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT) ); private static final DateTimeFormatter BASIC_DATE_T = - new DateTimeFormatterBuilder().append(BASIC_YEAR_MONTH_DAY_FORMATTER).appendLiteral("T").toFormatter(IsoLocale.ROOT); + new DateTimeFormatterBuilder().append(BASIC_YEAR_MONTH_DAY_FORMATTER).appendLiteral("T").toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT); /* * Returns a basic formatter that combines a basic date and time without millis, - * separated by a 'T' (yyyyMMdd'T'HHmmssZ). + * separated by a 'T' (uuuuMMdd'T'HHmmssZ). */ private static final DateFormatter BASIC_DATE_TIME_NO_MILLIS = new JavaDateFormatter("basic_date_time_no_millis", new DateTimeFormatterBuilder().append(BASIC_DATE_T).append(BASIC_TIME_NO_MILLIS_BASE) - .appendOffset("+HH:MM", "Z").toFormatter(IsoLocale.ROOT), + .appendOffset("+HH:MM", "Z").toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT), new DateTimeFormatterBuilder().append(BASIC_DATE_T).append(BASIC_TIME_NO_MILLIS_BASE) - .appendZoneOrOffsetId().toFormatter(IsoLocale.ROOT), + .appendZoneOrOffsetId().toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT), new DateTimeFormatterBuilder().append(BASIC_DATE_T).append(BASIC_TIME_NO_MILLIS_BASE) - .append(TIME_ZONE_FORMATTER_NO_COLON).toFormatter(IsoLocale.ROOT) + .append(TIME_ZONE_FORMATTER_NO_COLON).toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT) ); /* * Returns a formatter for a full ordinal date, using a four - * digit year and three digit dayOfYear (yyyyDDD). + * digit year and three digit dayOfYear (uuuuDDD). */ private static final DateFormatter BASIC_ORDINAL_DATE = new JavaDateFormatter("basic_ordinal_date", - DateTimeFormatter.ofPattern("yyyyDDD", IsoLocale.ROOT)); + DateTimeFormatter.ofPattern("uuuuDDD", IsoLocale.ROOT)); /* * Returns a formatter for a full ordinal date and time, using a four - * digit year and three digit dayOfYear (yyyyDDD'T'HHmmss.SSSZ). + * digit year and three digit dayOfYear (uuuuDDD'T'HHmmss.SSSZ). */ private static final DateFormatter BASIC_ORDINAL_DATE_TIME = new JavaDateFormatter("basic_ordinal_date_time", new DateTimeFormatterBuilder().appendPattern("yyyyDDD").append(BASIC_T_TIME_PRINTER) - .appendOffset("+HH:MM", "Z").toFormatter(IsoLocale.ROOT), + .appendOffset("+HH:MM", "Z").toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT), new DateTimeFormatterBuilder().appendPattern("yyyyDDD").append(BASIC_T_TIME_FORMATTER) - .appendZoneOrOffsetId().toFormatter(IsoLocale.ROOT), + .appendZoneOrOffsetId().toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT), new DateTimeFormatterBuilder().appendPattern("yyyyDDD").append(BASIC_T_TIME_FORMATTER) - .append(TIME_ZONE_FORMATTER_NO_COLON).toFormatter(IsoLocale.ROOT) + .append(TIME_ZONE_FORMATTER_NO_COLON).toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT) ); /* * Returns a formatter for a full ordinal date and time without millis, - * using a four digit year and three digit dayOfYear (yyyyDDD'T'HHmmssZ). + * using a four digit year and three digit dayOfYear (uuuuDDD'T'HHmmssZ). */ private static final DateFormatter BASIC_ORDINAL_DATE_TIME_NO_MILLIS = new JavaDateFormatter("basic_ordinal_date_time_no_millis", - new DateTimeFormatterBuilder().appendPattern("yyyyDDD").appendLiteral("T").append(BASIC_TIME_NO_MILLIS_BASE) - .appendOffset("+HH:MM", "Z").toFormatter(IsoLocale.ROOT), - new DateTimeFormatterBuilder().appendPattern("yyyyDDD").appendLiteral("T").append(BASIC_TIME_NO_MILLIS_BASE) - .appendZoneOrOffsetId().toFormatter(IsoLocale.ROOT), - new DateTimeFormatterBuilder().appendPattern("yyyyDDD").appendLiteral("T").append(BASIC_TIME_NO_MILLIS_BASE) - .append(TIME_ZONE_FORMATTER_NO_COLON).toFormatter(IsoLocale.ROOT) + new DateTimeFormatterBuilder().appendPattern("uuuuDDD").appendLiteral("T").append(BASIC_TIME_NO_MILLIS_BASE) + .appendOffset("+HH:MM", "Z").toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT), + new DateTimeFormatterBuilder().appendPattern("uuuuDDD").appendLiteral("T").append(BASIC_TIME_NO_MILLIS_BASE) + .appendZoneOrOffsetId().toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT), + new DateTimeFormatterBuilder().appendPattern("uuuuDDD").appendLiteral("T").append(BASIC_TIME_NO_MILLIS_BASE) + .append(TIME_ZONE_FORMATTER_NO_COLON).toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT) ); private static final DateTimeFormatter BASIC_WEEK_DATE_FORMATTER = new DateTimeFormatterBuilder() @@ -389,7 +431,8 @@ public class DateFormatters { .appendLiteral("W") .appendValue(IsoFields.WEEK_OF_WEEK_BASED_YEAR, 1, 2, SignStyle.NEVER) .appendValue(ChronoField.DAY_OF_WEEK) - .toFormatter(IsoLocale.ROOT); + .toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT); ///////////////////////////////////////// // @@ -408,7 +451,8 @@ public class DateFormatters { .appendLiteral("W") .appendValue(IsoFields.WEEK_OF_WEEK_BASED_YEAR, 1, 2, SignStyle.NEVER) .appendValue(ChronoField.DAY_OF_WEEK) - .toFormatter(IsoLocale.ROOT); + .toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT); private static final DateTimeFormatter STRICT_BASIC_WEEK_DATE_PRINTER = new DateTimeFormatterBuilder() .parseStrict() @@ -416,7 +460,8 @@ public class DateFormatters { .appendLiteral("W") .appendValue(IsoFields.WEEK_OF_WEEK_BASED_YEAR, 2, 2, SignStyle.NEVER) .appendValue(ChronoField.DAY_OF_WEEK) - .toFormatter(IsoLocale.ROOT); + .toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT); /* * Returns a basic formatter for a full date as four digit weekyear, two @@ -438,7 +483,8 @@ public class DateFormatters { .appendValue(MINUTE_OF_HOUR, 2, 2, SignStyle.NOT_NEGATIVE) .appendValue(SECOND_OF_MINUTE, 2, 2, SignStyle.NOT_NEGATIVE) .appendOffset("+HH:MM", "Z") - .toFormatter(IsoLocale.ROOT), + .toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT), new DateTimeFormatterBuilder() .append(STRICT_BASIC_WEEK_DATE_PRINTER) .appendLiteral("T") @@ -446,7 +492,8 @@ public class DateFormatters { .appendValue(MINUTE_OF_HOUR, 2, 2, SignStyle.NOT_NEGATIVE) .appendValue(SECOND_OF_MINUTE, 2, 2, SignStyle.NOT_NEGATIVE) .appendZoneOrOffsetId() - .toFormatter(IsoLocale.ROOT), + .toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT), new DateTimeFormatterBuilder() .append(STRICT_BASIC_WEEK_DATE_PRINTER) .appendLiteral("T") @@ -455,6 +502,7 @@ public class DateFormatters { .appendValue(SECOND_OF_MINUTE, 2, 2, SignStyle.NOT_NEGATIVE) .append(TIME_ZONE_FORMATTER_NO_COLON) .toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT) ); /* @@ -463,9 +511,10 @@ public class DateFormatters { */ private static final DateFormatter STRICT_BASIC_WEEK_DATE_TIME = new JavaDateFormatter("strict_basic_week_date_time", new DateTimeFormatterBuilder() - .append(STRICT_BASIC_WEEK_DATE_PRINTER) - .append(DateTimeFormatter.ofPattern("'T'HHmmss.SSSX", IsoLocale.ROOT)) - .toFormatter(IsoLocale.ROOT), + .append(STRICT_BASIC_WEEK_DATE_PRINTER) + .append(DateTimeFormatter.ofPattern("'T'HHmmss.SSSX", IsoLocale.ROOT)) + .toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT), new DateTimeFormatterBuilder() .append(STRICT_BASIC_WEEK_DATE_FORMATTER) .appendLiteral("T") @@ -474,7 +523,8 @@ public class DateFormatters { .appendValue(SECOND_OF_MINUTE, 2, 2, SignStyle.NOT_NEGATIVE) .appendFraction(NANO_OF_SECOND, 1, 9, true) .appendZoneOrOffsetId() - .toFormatter(IsoLocale.ROOT), + .toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT), new DateTimeFormatterBuilder() .append(STRICT_BASIC_WEEK_DATE_FORMATTER) .appendLiteral("T") @@ -484,6 +534,7 @@ public class DateFormatters { .appendFraction(NANO_OF_SECOND, 1, 9, true) .append(TIME_ZONE_FORMATTER_NO_COLON) .toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT) ); /* @@ -496,13 +547,13 @@ public class DateFormatters { * A date formatter that formats or parses a date plus an hour without an offset, such as '2011-12-03T01'. */ private static final DateFormatter STRICT_DATE_HOUR = new JavaDateFormatter("strict_date_hour", - DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH", IsoLocale.ROOT)); + DateTimeFormatter.ofPattern("uuuu-MM-dd'T'HH", IsoLocale.ROOT)); /* * A date formatter that formats or parses a date plus an hour/minute without an offset, such as '2011-12-03T01:10'. */ private static final DateFormatter STRICT_DATE_HOUR_MINUTE = new JavaDateFormatter("strict_date_hour_minute", - DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm", IsoLocale.ROOT)); + DateTimeFormatter.ofPattern("uuuu-MM-dd'T'HH:mm", IsoLocale.ROOT)); /* * A strict date formatter that formats or parses a date without an offset, such as '2011-12-03'. @@ -515,17 +566,19 @@ public class DateFormatters { */ private static final DateFormatter STRICT_YEAR_MONTH = new JavaDateFormatter("strict_year_month", new DateTimeFormatterBuilder() - .appendValue(ChronoField.YEAR, 4, 10, SignStyle.EXCEEDS_PAD) - .appendLiteral("-") - .appendValue(MONTH_OF_YEAR, 2, 2, SignStyle.NOT_NEGATIVE) - .toFormatter(IsoLocale.ROOT)); + .appendValue(ChronoField.YEAR, 4, 10, SignStyle.EXCEEDS_PAD) + .appendLiteral("-") + .appendValue(MONTH_OF_YEAR, 2, 2, SignStyle.NOT_NEGATIVE) + .toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT)); /* * A strict formatter that formats or parses a year, such as '2011'. */ private static final DateFormatter STRICT_YEAR = new JavaDateFormatter("strict_year", new DateTimeFormatterBuilder() .appendValue(ChronoField.YEAR, 4, 10, SignStyle.EXCEEDS_PAD) - .toFormatter(IsoLocale.ROOT)); + .toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT)); /* * A strict formatter that formats or parses a hour, minute and second, such as '09:43:25'. @@ -539,7 +592,8 @@ public class DateFormatters { .append(STRICT_HOUR_MINUTE_SECOND_FORMATTER) .appendFraction(NANO_OF_SECOND, 3, 9, true) .appendOffset("+HH:MM", "Z") - .toFormatter(IsoLocale.ROOT); + .toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT); private static final DateTimeFormatter STRICT_DATE_FORMATTER = new DateTimeFormatterBuilder() .append(STRICT_YEAR_MONTH_DAY_FORMATTER) @@ -548,16 +602,19 @@ public class DateFormatters { .optionalStart() .appendFraction(NANO_OF_SECOND, 1, 9, true) .optionalEnd() - .toFormatter(IsoLocale.ROOT); + .toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT); /* * Returns a formatter that combines a full date and time, separated by a 'T' - * (yyyy-MM-dd'T'HH:mm:ss.SSSZZ). + * (uuuu-MM-dd'T'HH:mm:ss.SSSZZ). */ private static final DateFormatter STRICT_DATE_TIME = new JavaDateFormatter("strict_date_time", STRICT_DATE_PRINTER, - new DateTimeFormatterBuilder().append(STRICT_DATE_FORMATTER).appendZoneOrOffsetId().toFormatter(IsoLocale.ROOT), + new DateTimeFormatterBuilder().append(STRICT_DATE_FORMATTER).appendZoneOrOffsetId().toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT), new DateTimeFormatterBuilder().append(STRICT_DATE_FORMATTER).append(TIME_ZONE_FORMATTER_NO_COLON) .toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT) ); private static final DateTimeFormatter STRICT_ORDINAL_DATE_TIME_NO_MILLIS_BASE = new DateTimeFormatterBuilder() @@ -566,50 +623,60 @@ public class DateFormatters { .appendValue(DAY_OF_YEAR, 3, 3, SignStyle.NOT_NEGATIVE) .appendLiteral('T') .append(STRICT_HOUR_MINUTE_SECOND_FORMATTER) - .toFormatter(IsoLocale.ROOT); + .toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT); /* * Returns a formatter for a full ordinal date and time without millis, - * using a four digit year and three digit dayOfYear (yyyy-DDD'T'HH:mm:ssZZ). + * using a four digit year and three digit dayOfYear (uuuu-DDD'T'HH:mm:ssZZ). */ private static final DateFormatter STRICT_ORDINAL_DATE_TIME_NO_MILLIS = new JavaDateFormatter("strict_ordinal_date_time_no_millis", new DateTimeFormatterBuilder().append(STRICT_ORDINAL_DATE_TIME_NO_MILLIS_BASE) - .appendOffset("+HH:MM", "Z").toFormatter(IsoLocale.ROOT), + .appendOffset("+HH:MM", "Z").toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT), new DateTimeFormatterBuilder().append(STRICT_ORDINAL_DATE_TIME_NO_MILLIS_BASE) - .appendZoneOrOffsetId().toFormatter(IsoLocale.ROOT), + .appendZoneOrOffsetId().toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT), new DateTimeFormatterBuilder().append(STRICT_ORDINAL_DATE_TIME_NO_MILLIS_BASE) - .append(TIME_ZONE_FORMATTER_NO_COLON).toFormatter(IsoLocale.ROOT) + .append(TIME_ZONE_FORMATTER_NO_COLON).toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT) ); private static final DateTimeFormatter STRICT_DATE_TIME_NO_MILLIS_FORMATTER = new DateTimeFormatterBuilder() .append(STRICT_YEAR_MONTH_DAY_FORMATTER) .appendLiteral('T') .append(STRICT_HOUR_MINUTE_SECOND_FORMATTER) - .toFormatter(IsoLocale.ROOT); + .toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT); /* * Returns a formatter that combines a full date and time without millis, - * separated by a 'T' (yyyy-MM-dd'T'HH:mm:ssZZ). + * separated by a 'T' (uuuu-MM-dd'T'HH:mm:ssZZ). */ private static final DateFormatter STRICT_DATE_TIME_NO_MILLIS = new JavaDateFormatter("strict_date_time_no_millis", new DateTimeFormatterBuilder().append(STRICT_DATE_TIME_NO_MILLIS_FORMATTER) - .appendOffset("+HH:MM", "Z").toFormatter(IsoLocale.ROOT), + .appendOffset("+HH:MM", "Z").toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT), new DateTimeFormatterBuilder().append(STRICT_DATE_TIME_NO_MILLIS_FORMATTER) - .appendZoneOrOffsetId().toFormatter(IsoLocale.ROOT), + .appendZoneOrOffsetId().toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT), new DateTimeFormatterBuilder().append(STRICT_DATE_TIME_NO_MILLIS_FORMATTER) - .append(TIME_ZONE_FORMATTER_NO_COLON).toFormatter(IsoLocale.ROOT) + .append(TIME_ZONE_FORMATTER_NO_COLON).toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT) ); // NOTE: this is not a strict formatter to retain the joda time based behaviour, even though it's named like this private static final DateTimeFormatter STRICT_HOUR_MINUTE_SECOND_MILLIS_FORMATTER = new DateTimeFormatterBuilder() .append(STRICT_HOUR_MINUTE_SECOND_FORMATTER) .appendFraction(NANO_OF_SECOND, 1, 9, true) - .toFormatter(IsoLocale.ROOT); + .toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT); private static final DateTimeFormatter STRICT_HOUR_MINUTE_SECOND_MILLIS_PRINTER = new DateTimeFormatterBuilder() .append(STRICT_HOUR_MINUTE_SECOND_FORMATTER) .appendFraction(NANO_OF_SECOND, 3, 3, true) - .toFormatter(IsoLocale.ROOT); + .toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT); /* * Returns a formatter for a two digit hour of day, two digit minute of @@ -630,7 +697,7 @@ public class DateFormatters { /* * Returns a formatter that combines a full date, two digit hour of day, * two digit minute of hour, two digit second of minute, and three digit - * fraction of second (yyyy-MM-dd'T'HH:mm:ss.SSS). + * fraction of second (uuuu-MM-dd'T'HH:mm:ss.SSS). */ private static final DateFormatter STRICT_DATE_HOUR_MINUTE_SECOND_FRACTION = new JavaDateFormatter( "strict_date_hour_minute_second_fraction", @@ -638,7 +705,8 @@ public class DateFormatters { .append(STRICT_YEAR_MONTH_DAY_FORMATTER) .appendLiteral("T") .append(STRICT_HOUR_MINUTE_SECOND_MILLIS_PRINTER) - .toFormatter(IsoLocale.ROOT), + .toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT), new DateTimeFormatterBuilder() .append(STRICT_YEAR_MONTH_DAY_FORMATTER) .appendLiteral("T") @@ -646,6 +714,7 @@ public class DateFormatters { // this one here is lenient as well to retain joda time based bwc compatibility .appendFraction(NANO_OF_SECOND, 1, 9, true) .toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT) ); private static final DateFormatter STRICT_DATE_HOUR_MINUTE_SECOND_MILLIS = new JavaDateFormatter( @@ -654,7 +723,8 @@ public class DateFormatters { .append(STRICT_YEAR_MONTH_DAY_FORMATTER) .appendLiteral("T") .append(STRICT_HOUR_MINUTE_SECOND_MILLIS_PRINTER) - .toFormatter(IsoLocale.ROOT), + .toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT), new DateTimeFormatterBuilder() .append(STRICT_YEAR_MONTH_DAY_FORMATTER) .appendLiteral("T") @@ -662,6 +732,7 @@ public class DateFormatters { // this one here is lenient as well to retain joda time based bwc compatibility .appendFraction(NANO_OF_SECOND, 1, 9, true) .toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT) ); /* @@ -688,7 +759,8 @@ public class DateFormatters { .appendValue(SECOND_OF_MINUTE, 2, 2, SignStyle.NOT_NEGATIVE) .appendFraction(NANO_OF_SECOND, 3, 9, true) .optionalEnd() - .toFormatter(IsoLocale.ROOT); + .toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT); private static final DateTimeFormatter STRICT_ORDINAL_DATE_TIME_FORMATTER_BASE = new DateTimeFormatterBuilder() .appendValue(ChronoField.YEAR, 4, 10, SignStyle.EXCEEDS_PAD) @@ -701,19 +773,23 @@ public class DateFormatters { .appendValue(SECOND_OF_MINUTE, 2, 2, SignStyle.NOT_NEGATIVE) .appendFraction(NANO_OF_SECOND, 1, 9, true) .optionalEnd() - .toFormatter(IsoLocale.ROOT); + .toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT); /* * Returns a formatter for a full ordinal date and time, using a four - * digit year and three digit dayOfYear (yyyy-DDD'T'HH:mm:ss.SSSZZ). + * digit year and three digit dayOfYear (uuuu-DDD'T'HH:mm:ss.SSSZZ). */ private static final DateFormatter STRICT_ORDINAL_DATE_TIME = new JavaDateFormatter("strict_ordinal_date_time", new DateTimeFormatterBuilder().append(STRICT_ORDINAL_DATE_TIME_PRINTER) - .appendOffset("+HH:MM", "Z").toFormatter(IsoLocale.ROOT), + .appendOffset("+HH:MM", "Z").toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT), new DateTimeFormatterBuilder().append(STRICT_ORDINAL_DATE_TIME_FORMATTER_BASE) - .appendZoneOrOffsetId().toFormatter(IsoLocale.ROOT), + .appendZoneOrOffsetId().toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT), new DateTimeFormatterBuilder().append(STRICT_ORDINAL_DATE_TIME_FORMATTER_BASE) - .append(TIME_ZONE_FORMATTER_NO_COLON).toFormatter(IsoLocale.ROOT) + .append(TIME_ZONE_FORMATTER_NO_COLON).toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT) ); // Note: milliseconds parsing is not strict, others are @@ -724,7 +800,8 @@ public class DateFormatters { .appendLiteral(':') .appendValue(SECOND_OF_MINUTE, 2, 2, SignStyle.NOT_NEGATIVE) .appendFraction(NANO_OF_SECOND, 1, 9, true) - .toFormatter(IsoLocale.ROOT); + .toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT); private static final DateTimeFormatter STRICT_TIME_PRINTER = new DateTimeFormatterBuilder() .appendValue(HOUR_OF_DAY, 2, 2, SignStyle.NOT_NEGATIVE) @@ -733,7 +810,8 @@ public class DateFormatters { .appendLiteral(':') .appendValue(SECOND_OF_MINUTE, 2, 2, SignStyle.NOT_NEGATIVE) .appendFraction(NANO_OF_SECOND, 3, 3, true) - .toFormatter(IsoLocale.ROOT); + .toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT); /* * Returns a formatter for a two digit hour of day, two digit minute of @@ -741,10 +819,13 @@ public class DateFormatters { * time zone offset (HH:mm:ss.SSSZZ). */ private static final DateFormatter STRICT_TIME = new JavaDateFormatter("strict_time", - new DateTimeFormatterBuilder().append(STRICT_TIME_PRINTER).appendOffset("+HH:MM", "Z").toFormatter(IsoLocale.ROOT), - new DateTimeFormatterBuilder().append(STRICT_TIME_FORMATTER_BASE).appendZoneOrOffsetId().toFormatter(IsoLocale.ROOT), + new DateTimeFormatterBuilder().append(STRICT_TIME_PRINTER).appendOffset("+HH:MM", "Z").toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT), + new DateTimeFormatterBuilder().append(STRICT_TIME_FORMATTER_BASE).appendZoneOrOffsetId().toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT), new DateTimeFormatterBuilder().append(STRICT_TIME_FORMATTER_BASE).append(TIME_ZONE_FORMATTER_NO_COLON) .toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT) ); /* @@ -755,11 +836,14 @@ public class DateFormatters { private static final DateFormatter STRICT_T_TIME = new JavaDateFormatter("strict_t_time", new DateTimeFormatterBuilder().appendLiteral('T').append(STRICT_TIME_PRINTER) .appendOffset("+HH:MM", "Z") - .toFormatter(IsoLocale.ROOT), + .toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT), new DateTimeFormatterBuilder().appendLiteral('T').append(STRICT_TIME_FORMATTER_BASE) - .appendZoneOrOffsetId().toFormatter(IsoLocale.ROOT), + .appendZoneOrOffsetId().toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT), new DateTimeFormatterBuilder().appendLiteral('T').append(STRICT_TIME_FORMATTER_BASE) - .append(TIME_ZONE_FORMATTER_NO_COLON).toFormatter(IsoLocale.ROOT) + .append(TIME_ZONE_FORMATTER_NO_COLON).toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT) ); private static final DateTimeFormatter STRICT_TIME_NO_MILLIS_BASE = new DateTimeFormatterBuilder() @@ -768,7 +852,8 @@ public class DateFormatters { .appendValue(MINUTE_OF_HOUR, 2, 2, SignStyle.NOT_NEGATIVE) .appendLiteral(':') .appendValue(SECOND_OF_MINUTE, 2, 2, SignStyle.NOT_NEGATIVE) - .toFormatter(IsoLocale.ROOT); + .toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT); /* * Returns a formatter for a two digit hour of day, two digit minute of @@ -776,10 +861,13 @@ public class DateFormatters { */ private static final DateFormatter STRICT_TIME_NO_MILLIS = new JavaDateFormatter("strict_time_no_millis", new DateTimeFormatterBuilder().append(STRICT_TIME_NO_MILLIS_BASE).appendOffset("+HH:MM", "Z") - .toFormatter(IsoLocale.ROOT), - new DateTimeFormatterBuilder().append(STRICT_TIME_NO_MILLIS_BASE).appendZoneOrOffsetId().toFormatter(IsoLocale.ROOT), + .toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT), + new DateTimeFormatterBuilder().append(STRICT_TIME_NO_MILLIS_BASE).appendZoneOrOffsetId().toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT), new DateTimeFormatterBuilder().append(STRICT_TIME_NO_MILLIS_BASE).append(TIME_ZONE_FORMATTER_NO_COLON) .toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT) ); /* @@ -789,26 +877,31 @@ public class DateFormatters { */ private static final DateFormatter STRICT_T_TIME_NO_MILLIS = new JavaDateFormatter("strict_t_time_no_millis", new DateTimeFormatterBuilder().appendLiteral("T").append(STRICT_TIME_NO_MILLIS_BASE) - .appendOffset("+HH:MM", "Z").toFormatter(IsoLocale.ROOT), + .appendOffset("+HH:MM", "Z").toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT), new DateTimeFormatterBuilder().appendLiteral("T").append(STRICT_TIME_NO_MILLIS_BASE) - .appendZoneOrOffsetId().toFormatter(IsoLocale.ROOT), + .appendZoneOrOffsetId().toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT), new DateTimeFormatterBuilder().appendLiteral("T").append(STRICT_TIME_NO_MILLIS_BASE) - .append(TIME_ZONE_FORMATTER_NO_COLON).toFormatter(IsoLocale.ROOT) + .append(TIME_ZONE_FORMATTER_NO_COLON).toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT) ); private static final DateTimeFormatter ISO_WEEK_DATE = new DateTimeFormatterBuilder() - .parseCaseInsensitive() - .appendValue(IsoFields.WEEK_BASED_YEAR, 4, 10, SignStyle.EXCEEDS_PAD) - .appendLiteral("-W") - .appendValue(IsoFields.WEEK_OF_WEEK_BASED_YEAR, 2) - .appendLiteral('-') - .appendValue(DAY_OF_WEEK, 1) - .toFormatter(IsoLocale.ROOT); + .parseCaseInsensitive() + .appendValue(IsoFields.WEEK_BASED_YEAR, 4, 10, SignStyle.EXCEEDS_PAD) + .appendLiteral("-W") + .appendValue(IsoFields.WEEK_OF_WEEK_BASED_YEAR, 2) + .appendLiteral('-') + .appendValue(DAY_OF_WEEK, 1) + .toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT); private static final DateTimeFormatter ISO_WEEK_DATE_T = new DateTimeFormatterBuilder() - .append(ISO_WEEK_DATE) - .appendLiteral('T') - .toFormatter(IsoLocale.ROOT); + .append(ISO_WEEK_DATE) + .appendLiteral('T') + .toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT); /* * Returns a formatter for a full date as four digit weekyear, two digit @@ -822,11 +915,14 @@ public class DateFormatters { */ private static final DateFormatter STRICT_WEEK_DATE_TIME_NO_MILLIS = new JavaDateFormatter("strict_week_date_time_no_millis", new DateTimeFormatterBuilder().append(ISO_WEEK_DATE_T) - .append(STRICT_TIME_NO_MILLIS_BASE).appendOffset("+HH:MM", "Z").toFormatter(IsoLocale.ROOT), + .append(STRICT_TIME_NO_MILLIS_BASE).appendOffset("+HH:MM", "Z").toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT), new DateTimeFormatterBuilder().append(ISO_WEEK_DATE_T) - .append(STRICT_TIME_NO_MILLIS_BASE).appendZoneOrOffsetId().toFormatter(IsoLocale.ROOT), + .append(STRICT_TIME_NO_MILLIS_BASE).appendZoneOrOffsetId().toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT), new DateTimeFormatterBuilder().append(ISO_WEEK_DATE_T) - .append(STRICT_TIME_NO_MILLIS_BASE).append(TIME_ZONE_FORMATTER_NO_COLON).toFormatter(IsoLocale.ROOT) + .append(STRICT_TIME_NO_MILLIS_BASE).append(TIME_ZONE_FORMATTER_NO_COLON).toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT) ); /* @@ -835,11 +931,14 @@ public class DateFormatters { */ private static final DateFormatter STRICT_WEEK_DATE_TIME = new JavaDateFormatter("strict_week_date_time", new DateTimeFormatterBuilder().append(ISO_WEEK_DATE_T) - .append(STRICT_TIME_PRINTER).appendOffset("+HH:MM", "Z").toFormatter(IsoLocale.ROOT), + .append(STRICT_TIME_PRINTER).appendOffset("+HH:MM", "Z").toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT), new DateTimeFormatterBuilder().append(ISO_WEEK_DATE_T).append(STRICT_TIME_FORMATTER_BASE) - .appendZoneOrOffsetId().toFormatter(IsoLocale.ROOT), + .appendZoneOrOffsetId().toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT), new DateTimeFormatterBuilder().append(ISO_WEEK_DATE_T).append(STRICT_TIME_FORMATTER_BASE) - .append(TIME_ZONE_FORMATTER_NO_COLON).toFormatter(IsoLocale.ROOT) + .append(TIME_ZONE_FORMATTER_NO_COLON).toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT) ); /* @@ -847,13 +946,15 @@ public class DateFormatters { */ private static final DateFormatter STRICT_WEEKYEAR = new JavaDateFormatter("strict_weekyear", new DateTimeFormatterBuilder() .appendValue(WeekFields.ISO.weekBasedYear(), 4, 10, SignStyle.EXCEEDS_PAD) - .toFormatter(IsoLocale.ROOT)); + .toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT)); private static final DateTimeFormatter STRICT_WEEKYEAR_WEEK_FORMATTER = new DateTimeFormatterBuilder() .appendValue(WeekFields.ISO.weekBasedYear(), 4, 10, SignStyle.EXCEEDS_PAD) .appendLiteral("-W") .appendValue(WeekFields.ISO.weekOfWeekBasedYear(), 2, 2, SignStyle.NOT_NEGATIVE) - .toFormatter(IsoLocale.ROOT); + .toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT); /* * Returns a formatter for a four digit weekyear and two digit week of @@ -868,34 +969,37 @@ public class DateFormatters { */ private static final DateFormatter STRICT_WEEKYEAR_WEEK_DAY = new JavaDateFormatter("strict_weekyear_week_day", new DateTimeFormatterBuilder() - .append(STRICT_WEEKYEAR_WEEK_FORMATTER) - .appendLiteral("-") - .appendValue(WeekFields.ISO.dayOfWeek()) - .toFormatter(IsoLocale.ROOT)); + .append(STRICT_WEEKYEAR_WEEK_FORMATTER) + .appendLiteral("-") + .appendValue(WeekFields.ISO.dayOfWeek()) + .toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT)); /* * Returns a formatter that combines a full date, two digit hour of day, * two digit minute of hour, and two digit second of - * minute. (yyyy-MM-dd'T'HH:mm:ss) + * minute. (uuuu-MM-dd'T'HH:mm:ss) */ private static final DateFormatter STRICT_DATE_HOUR_MINUTE_SECOND = new JavaDateFormatter("strict_date_hour_minute_second", - DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss", IsoLocale.ROOT)); + DateTimeFormatter.ofPattern("uuuu-MM-dd'T'HH:mm:ss", IsoLocale.ROOT)); /* * A basic formatter for a full date as four digit year, two digit - * month of year, and two digit day of month (yyyyMMdd). + * month of year, and two digit day of month (uuuuMMdd). */ private static final DateFormatter BASIC_DATE = new JavaDateFormatter("basic_date", new DateTimeFormatterBuilder() .appendValue(ChronoField.YEAR, 4, 4, SignStyle.NORMAL) .appendValue(MONTH_OF_YEAR, 2, 2, SignStyle.NOT_NEGATIVE) .appendValue(DAY_OF_MONTH, 2, 2, SignStyle.NOT_NEGATIVE) - .toFormatter(IsoLocale.ROOT).withZone(ZoneOffset.UTC), + .toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT).withZone(ZoneOffset.UTC), new DateTimeFormatterBuilder() .appendValue(ChronoField.YEAR, 1, 4, SignStyle.NORMAL) .appendValue(MONTH_OF_YEAR, 1, 2, SignStyle.NOT_NEGATIVE) .appendValue(DAY_OF_MONTH, 1, 2, SignStyle.NOT_NEGATIVE) - .toFormatter(IsoLocale.ROOT).withZone(ZoneOffset.UTC) + .toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT).withZone(ZoneOffset.UTC) ); private static final DateTimeFormatter STRICT_ORDINAL_DATE_FORMATTER = new DateTimeFormatterBuilder() @@ -904,11 +1008,12 @@ public class DateFormatters { .appendLiteral('-') .appendValue(DAY_OF_YEAR, 3) .optionalStart() - .toFormatter(IsoLocale.ROOT); + .toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT); /* * Returns a formatter for a full ordinal date, using a four - * digit year and three digit dayOfYear (yyyy-DDD). + * digit year and three digit dayOfYear (uuuu-DDD). */ private static final DateFormatter STRICT_ORDINAL_DATE = new JavaDateFormatter("strict_ordinal_date", STRICT_ORDINAL_DATE_FORMATTER); @@ -934,17 +1039,18 @@ public class DateFormatters { .appendValue(DAY_OF_MONTH, 1, 2, SignStyle.NOT_NEGATIVE) .optionalEnd() .optionalEnd() - .toFormatter(IsoLocale.ROOT); + .toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT); private static final DateTimeFormatter HOUR_MINUTE_FORMATTER = new DateTimeFormatterBuilder() .appendValue(HOUR_OF_DAY, 1, 2, SignStyle.NOT_NEGATIVE) .appendLiteral(':') .appendValue(MINUTE_OF_HOUR, 1, 2, SignStyle.NOT_NEGATIVE) - .toFormatter(IsoLocale.ROOT); + .toFormatter(IsoLocale.ROOT).withResolverStyle(ResolverStyle.STRICT); /* * a date formatter with optional time, being very lenient, format is - * yyyy-MM-dd'T'HH:mm:ss.SSSZ + * uuuu-MM-dd'T'HH:mm:ss.SSSZ */ private static final DateFormatter DATE_OPTIONAL_TIME = new JavaDateFormatter("date_optional_time", STRICT_DATE_OPTIONAL_TIME_PRINTER, @@ -973,13 +1079,14 @@ public class DateFormatters { .optionalEnd() .optionalEnd() .optionalEnd() - .toFormatter(IsoLocale.ROOT)); + .toFormatter(IsoLocale.ROOT).withResolverStyle(ResolverStyle.STRICT)); private static final DateTimeFormatter HOUR_MINUTE_SECOND_FORMATTER = new DateTimeFormatterBuilder() .append(HOUR_MINUTE_FORMATTER) .appendLiteral(":") .appendValue(SECOND_OF_MINUTE, 1, 2, SignStyle.NOT_NEGATIVE) - .toFormatter(IsoLocale.ROOT); + .toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT); private static final DateTimeFormatter HOUR_MINUTE_SECOND_MILLIS_FORMATTER = new DateTimeFormatterBuilder() .appendValue(HOUR_OF_DAY, 1, 2, SignStyle.NOT_NEGATIVE) @@ -988,7 +1095,8 @@ public class DateFormatters { .appendLiteral(':') .appendValue(SECOND_OF_MINUTE, 1, 2, SignStyle.NOT_NEGATIVE) .appendFraction(NANO_OF_SECOND, 1, 3, true) - .toFormatter(IsoLocale.ROOT); + .toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT); private static final DateTimeFormatter HOUR_MINUTE_SECOND_FRACTION_FORMATTER = new DateTimeFormatterBuilder() .appendValue(HOUR_OF_DAY, 1, 2, SignStyle.NOT_NEGATIVE) @@ -997,23 +1105,26 @@ public class DateFormatters { .appendLiteral(':') .appendValue(SECOND_OF_MINUTE, 1, 2, SignStyle.NOT_NEGATIVE) .appendFraction(NANO_OF_SECOND, 1, 9, true) - .toFormatter(IsoLocale.ROOT); + .toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT); private static final DateTimeFormatter ORDINAL_DATE_FORMATTER = new DateTimeFormatterBuilder() .appendValue(ChronoField.YEAR, 4, 10, SignStyle.EXCEEDS_PAD) .appendLiteral('-') .appendValue(DAY_OF_YEAR, 1, 3, SignStyle.NOT_NEGATIVE) - .toFormatter(IsoLocale.ROOT); + .toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT); private static final DateTimeFormatter ORDINAL_DATE_PRINTER = new DateTimeFormatterBuilder() .appendValue(ChronoField.YEAR, 4, 10, SignStyle.EXCEEDS_PAD) .appendLiteral('-') .appendValue(DAY_OF_YEAR, 3, 3, SignStyle.NOT_NEGATIVE) - .toFormatter(IsoLocale.ROOT); + .toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT); /* * Returns a formatter for a full ordinal date, using a four - * digit year and three digit dayOfYear (yyyy-DDD). + * digit year and three digit dayOfYear (uuuu-DDD). */ private static final DateFormatter ORDINAL_DATE = new JavaDateFormatter("ordinal_date", ORDINAL_DATE_PRINTER, ORDINAL_DATE_FORMATTER); @@ -1024,15 +1135,18 @@ public class DateFormatters { .appendValue(MINUTE_OF_HOUR, 1, 2, SignStyle.NOT_NEGATIVE) .appendLiteral(':') .appendValue(SECOND_OF_MINUTE, 1, 2, SignStyle.NOT_NEGATIVE) - .toFormatter(IsoLocale.ROOT); + .toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT); private static final DateTimeFormatter T_TIME_NO_MILLIS_FORMATTER = - new DateTimeFormatterBuilder().appendLiteral("T").append(TIME_NO_MILLIS_FORMATTER).toFormatter(IsoLocale.ROOT); + new DateTimeFormatterBuilder().appendLiteral("T").append(TIME_NO_MILLIS_FORMATTER).toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT); private static final DateTimeFormatter TIME_PREFIX = new DateTimeFormatterBuilder() .append(TIME_NO_MILLIS_FORMATTER) .appendFraction(NANO_OF_SECOND, 1, 9, true) - .toFormatter(IsoLocale.ROOT); + .toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT); private static final DateTimeFormatter WEEK_DATE_FORMATTER = new DateTimeFormatterBuilder() .appendValue(IsoFields.WEEK_BASED_YEAR, 4, 10, SignStyle.EXCEEDS_PAD) @@ -1040,36 +1154,40 @@ public class DateFormatters { .appendValue(IsoFields.WEEK_OF_WEEK_BASED_YEAR, 1, 2, SignStyle.NOT_NEGATIVE) .appendLiteral('-') .appendValue(DAY_OF_WEEK, 1) - .toFormatter(IsoLocale.ROOT); + .toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT); /* * Returns a formatter for a four digit weekyear. (YYYY) */ private static final DateFormatter WEEK_YEAR = new JavaDateFormatter("week_year", - new DateTimeFormatterBuilder().appendValue(WeekFields.ISO.weekBasedYear()).toFormatter(IsoLocale.ROOT)); + new DateTimeFormatterBuilder().appendValue(WeekFields.ISO.weekBasedYear()).toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT)); /* * Returns a formatter for a four digit year. (uuuu) */ private static final DateFormatter YEAR = new JavaDateFormatter("year", - new DateTimeFormatterBuilder().appendValue(ChronoField.YEAR).toFormatter(IsoLocale.ROOT)); + new DateTimeFormatterBuilder().appendValue(ChronoField.YEAR).toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT)); /* * Returns a formatter that combines a full date and two digit hour of - * day. (yyyy-MM-dd'T'HH) + * day. (uuuu-MM-dd'T'HH) */ private static final DateFormatter DATE_HOUR = new JavaDateFormatter("date_hour", - DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH", IsoLocale.ROOT), + DateTimeFormatter.ofPattern("uuuu-MM-dd'T'HH", IsoLocale.ROOT), new DateTimeFormatterBuilder() .append(DATE_FORMATTER) .appendLiteral("T") .appendValue(HOUR_OF_DAY, 1, 2, SignStyle.NOT_NEGATIVE) - .toFormatter(IsoLocale.ROOT)); + .toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT)); /* * Returns a formatter that combines a full date, two digit hour of day, * two digit minute of hour, two digit second of minute, and three digit - * fraction of second (yyyy-MM-dd'T'HH:mm:ss.SSS). + * fraction of second (uuuu-MM-dd'T'HH:mm:ss.SSS). */ private static final DateFormatter DATE_HOUR_MINUTE_SECOND_MILLIS = new JavaDateFormatter("date_hour_minute_second_millis", @@ -1077,12 +1195,14 @@ public class DateFormatters { .append(STRICT_YEAR_MONTH_DAY_FORMATTER) .appendLiteral("T") .append(STRICT_HOUR_MINUTE_SECOND_MILLIS_PRINTER) - .toFormatter(IsoLocale.ROOT), + .toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT), new DateTimeFormatterBuilder() .append(DATE_FORMATTER) .appendLiteral("T") .append(HOUR_MINUTE_SECOND_MILLIS_FORMATTER) - .toFormatter(IsoLocale.ROOT)); + .toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT)); private static final DateFormatter DATE_HOUR_MINUTE_SECOND_FRACTION = new JavaDateFormatter("date_hour_minute_second_fraction", @@ -1090,37 +1210,41 @@ public class DateFormatters { .append(STRICT_YEAR_MONTH_DAY_FORMATTER) .appendLiteral("T") .append(STRICT_HOUR_MINUTE_SECOND_MILLIS_PRINTER) - .toFormatter(IsoLocale.ROOT), + .toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT), new DateTimeFormatterBuilder() .append(DATE_FORMATTER) .appendLiteral("T") .append(HOUR_MINUTE_SECOND_FRACTION_FORMATTER) - .toFormatter(IsoLocale.ROOT)); + .toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT)); /* * Returns a formatter that combines a full date, two digit hour of day, - * and two digit minute of hour. (yyyy-MM-dd'T'HH:mm) + * and two digit minute of hour. (uuuu-MM-dd'T'HH:mm) */ private static final DateFormatter DATE_HOUR_MINUTE = new JavaDateFormatter("date_hour_minute", - DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm", IsoLocale.ROOT), + DateTimeFormatter.ofPattern("uuuu-MM-dd'T'HH:mm", IsoLocale.ROOT), new DateTimeFormatterBuilder() .append(DATE_FORMATTER) .appendLiteral("T") .append(HOUR_MINUTE_FORMATTER) - .toFormatter(IsoLocale.ROOT)); + .toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT)); /* * Returns a formatter that combines a full date, two digit hour of day, * two digit minute of hour, and two digit second of - * minute. (yyyy-MM-dd'T'HH:mm:ss) + * minute. (uuuu-MM-dd'T'HH:mm:ss) */ private static final DateFormatter DATE_HOUR_MINUTE_SECOND = new JavaDateFormatter("date_hour_minute_second", - DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss", IsoLocale.ROOT), + DateTimeFormatter.ofPattern("uuuu-MM-dd'T'HH:mm:ss", IsoLocale.ROOT), new DateTimeFormatterBuilder() .append(DATE_FORMATTER) .appendLiteral("T") .append(HOUR_MINUTE_SECOND_FORMATTER) - .toFormatter(IsoLocale.ROOT)); + .toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT)); private static final DateTimeFormatter DATE_TIME_FORMATTER = new DateTimeFormatterBuilder() .append(DATE_FORMATTER) @@ -1131,18 +1255,21 @@ public class DateFormatters { .appendValue(SECOND_OF_MINUTE, 1, 2, SignStyle.NOT_NEGATIVE) .appendFraction(NANO_OF_SECOND, 1, 9, true) .optionalEnd() - .toFormatter(IsoLocale.ROOT); + .toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT); /* * Returns a formatter that combines a full date and time, separated by a 'T' - * (yyyy-MM-dd'T'HH:mm:ss.SSSZZ). + * (uuuu-MM-dd'T'HH:mm:ss.SSSZZ). */ private static final DateFormatter DATE_TIME = new JavaDateFormatter("date_time", STRICT_DATE_OPTIONAL_TIME_PRINTER, new DateTimeFormatterBuilder().append(DATE_TIME_FORMATTER).appendOffset("+HH:MM", "Z") - .toFormatter(IsoLocale.ROOT), + .toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT), new DateTimeFormatterBuilder().append(DATE_TIME_FORMATTER).append(TIME_ZONE_FORMATTER_NO_COLON) .toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT) ); /* @@ -1154,10 +1281,10 @@ public class DateFormatters { /* * Returns a formatter for a full date as four digit year, two digit month - * of year, and two digit day of month (yyyy-MM-dd). + * of year, and two digit day of month (uuuu-MM-dd). */ private static final DateFormatter DATE = new JavaDateFormatter("date", - DateTimeFormatter.ISO_LOCAL_DATE.withResolverStyle(ResolverStyle.LENIENT), + DateTimeFormatter.ISO_LOCAL_DATE.withResolverStyle(ResolverStyle.STRICT), DATE_FORMATTER); // only the formatter, nothing optional here @@ -1168,7 +1295,8 @@ public class DateFormatters { .appendLiteral(':') .appendValue(SECOND_OF_MINUTE, 2, 2, SignStyle.NOT_NEGATIVE) .appendZoneId() - .toFormatter(IsoLocale.ROOT); + .toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT); private static final DateTimeFormatter DATE_TIME_PREFIX = new DateTimeFormatterBuilder() .append(DATE_FORMATTER) @@ -1178,21 +1306,26 @@ public class DateFormatters { .appendLiteral(':') .appendValue(SECOND_OF_MINUTE, 1, 2, SignStyle.NOT_NEGATIVE) .optionalEnd() - .toFormatter(IsoLocale.ROOT); + .toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT); /* * Returns a formatter that combines a full date and time without millis, but with a timezone that can be optional - * separated by a 'T' (yyyy-MM-dd'T'HH:mm:ssZ). + * separated by a 'T' (uuuu-MM-dd'T'HH:mm:ssZ). */ private static final DateFormatter DATE_TIME_NO_MILLIS = new JavaDateFormatter("date_time_no_millis", DATE_TIME_NO_MILLIS_PRINTER, - new DateTimeFormatterBuilder().append(DATE_TIME_PREFIX).appendOffset("+HH:MM", "Z").toFormatter(IsoLocale.ROOT), + new DateTimeFormatterBuilder().append(DATE_TIME_PREFIX).appendOffset("+HH:MM", "Z").toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT), new DateTimeFormatterBuilder().append(DATE_TIME_PREFIX).append(TIME_ZONE_FORMATTER_NO_COLON) - .toFormatter(IsoLocale.ROOT), + .toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT), new DateTimeFormatterBuilder().append(DATE_TIME_PREFIX) - .optionalStart().appendZoneOrOffsetId().optionalEnd().toFormatter(IsoLocale.ROOT), + .optionalStart().appendZoneOrOffsetId().optionalEnd().toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT), new DateTimeFormatterBuilder().append(DATE_TIME_PREFIX) - .optionalStart().append(TIME_ZONE_FORMATTER_NO_COLON).optionalEnd().toFormatter(IsoLocale.ROOT) + .optionalStart().append(TIME_ZONE_FORMATTER_NO_COLON).optionalEnd().toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT) ); /* @@ -1223,6 +1356,7 @@ public class DateFormatters { .appendLiteral(":") .appendValue(SECOND_OF_MINUTE, 1, 2, SignStyle.NOT_NEGATIVE) .toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT) ); /* @@ -1231,6 +1365,7 @@ public class DateFormatters { private static final DateFormatter HOUR = new JavaDateFormatter("hour", DateTimeFormatter.ofPattern("HH", IsoLocale.ROOT), new DateTimeFormatterBuilder().appendValue(HOUR_OF_DAY, 1, 2, SignStyle.NOT_NEGATIVE).toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT) ); private static final DateTimeFormatter ORDINAL_DATE_TIME_FORMATTER_BASE = new DateTimeFormatterBuilder() @@ -1242,38 +1377,46 @@ public class DateFormatters { .appendValue(SECOND_OF_MINUTE, 1, 2, SignStyle.NOT_NEGATIVE) .appendFraction(NANO_OF_SECOND, 1, 9, true) .optionalEnd() - .toFormatter(IsoLocale.ROOT); + .toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT); /* * Returns a formatter for a full ordinal date and time, using a four - * digit year and three digit dayOfYear (yyyy-DDD'T'HH:mm:ss.SSSZZ). + * digit year and three digit dayOfYear (uuuu-DDD'T'HH:mm:ss.SSSZZ). */ private static final DateFormatter ORDINAL_DATE_TIME = new JavaDateFormatter("ordinal_date_time", new DateTimeFormatterBuilder().append(STRICT_ORDINAL_DATE_TIME_PRINTER) - .appendOffset("+HH:MM", "Z").toFormatter(IsoLocale.ROOT), + .appendOffset("+HH:MM", "Z").toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT), new DateTimeFormatterBuilder().append(ORDINAL_DATE_TIME_FORMATTER_BASE) - .appendZoneOrOffsetId().toFormatter(IsoLocale.ROOT), + .appendZoneOrOffsetId().toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT), new DateTimeFormatterBuilder().append(ORDINAL_DATE_TIME_FORMATTER_BASE) - .append(TIME_ZONE_FORMATTER_NO_COLON).toFormatter(IsoLocale.ROOT) + .append(TIME_ZONE_FORMATTER_NO_COLON).toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT) ); private static final DateTimeFormatter ORDINAL_DATE_TIME_NO_MILLIS_BASE = new DateTimeFormatterBuilder() .append(ORDINAL_DATE_FORMATTER) .appendLiteral('T') .append(HOUR_MINUTE_SECOND_FORMATTER) - .toFormatter(IsoLocale.ROOT); + .toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT); /* * Returns a formatter for a full ordinal date and time without millis, - * using a four digit year and three digit dayOfYear (yyyy-DDD'T'HH:mm:ssZZ). + * using a four digit year and three digit dayOfYear (uuuu-DDD'T'HH:mm:ssZZ). */ private static final DateFormatter ORDINAL_DATE_TIME_NO_MILLIS = new JavaDateFormatter("ordinal_date_time_no_millis", new DateTimeFormatterBuilder().append(STRICT_ORDINAL_DATE_TIME_NO_MILLIS_BASE) - .appendOffset("+HH:MM", "Z").toFormatter(IsoLocale.ROOT), + .appendOffset("+HH:MM", "Z").toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT), new DateTimeFormatterBuilder().append(ORDINAL_DATE_TIME_NO_MILLIS_BASE) - .appendZoneOrOffsetId().toFormatter(IsoLocale.ROOT), + .appendZoneOrOffsetId().toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT), new DateTimeFormatterBuilder().append(ORDINAL_DATE_TIME_NO_MILLIS_BASE) - .append(TIME_ZONE_FORMATTER_NO_COLON).toFormatter(IsoLocale.ROOT) + .append(TIME_ZONE_FORMATTER_NO_COLON).toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT) ); /* @@ -1282,11 +1425,14 @@ public class DateFormatters { */ private static final DateFormatter WEEK_DATE_TIME = new JavaDateFormatter("week_date_time", new DateTimeFormatterBuilder().append(ISO_WEEK_DATE_T) - .append(STRICT_TIME_PRINTER).appendOffset("+HH:MM", "Z").toFormatter(IsoLocale.ROOT), + .append(STRICT_TIME_PRINTER).appendOffset("+HH:MM", "Z").toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT), new DateTimeFormatterBuilder().append(WEEK_DATE_FORMATTER).appendLiteral("T").append(TIME_PREFIX) - .appendZoneOrOffsetId().toFormatter(IsoLocale.ROOT), + .appendZoneOrOffsetId().toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT), new DateTimeFormatterBuilder().append(WEEK_DATE_FORMATTER).appendLiteral("T").append(TIME_PREFIX) - .append(TIME_ZONE_FORMATTER_NO_COLON).toFormatter(IsoLocale.ROOT) + .append(TIME_ZONE_FORMATTER_NO_COLON).toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT) ); /* @@ -1295,11 +1441,14 @@ public class DateFormatters { */ private static final DateFormatter WEEK_DATE_TIME_NO_MILLIS = new JavaDateFormatter("week_date_time_no_millis", new DateTimeFormatterBuilder().append(ISO_WEEK_DATE_T) - .append(STRICT_TIME_NO_MILLIS_BASE).appendOffset("+HH:MM", "Z").toFormatter(IsoLocale.ROOT), + .append(STRICT_TIME_NO_MILLIS_BASE).appendOffset("+HH:MM", "Z").toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT), new DateTimeFormatterBuilder().append(WEEK_DATE_FORMATTER).append(T_TIME_NO_MILLIS_FORMATTER) - .appendZoneOrOffsetId().toFormatter(IsoLocale.ROOT), + .appendZoneOrOffsetId().toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT), new DateTimeFormatterBuilder().append(WEEK_DATE_FORMATTER).append(T_TIME_NO_MILLIS_FORMATTER) - .append(TIME_ZONE_FORMATTER_NO_COLON).toFormatter(IsoLocale.ROOT) + .append(TIME_ZONE_FORMATTER_NO_COLON).toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT) ); /* @@ -1310,11 +1459,14 @@ public class DateFormatters { new DateTimeFormatterBuilder() .append(STRICT_BASIC_WEEK_DATE_PRINTER) .append(DateTimeFormatter.ofPattern("'T'HHmmss.SSSX", IsoLocale.ROOT)) - .toFormatter(IsoLocale.ROOT), + .toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT), new DateTimeFormatterBuilder().append(BASIC_WEEK_DATE_FORMATTER).append(BASIC_T_TIME_FORMATTER) - .appendZoneOrOffsetId().toFormatter(IsoLocale.ROOT), + .appendZoneOrOffsetId().toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT), new DateTimeFormatterBuilder().append(BASIC_WEEK_DATE_FORMATTER).append(BASIC_T_TIME_FORMATTER) - .append(TIME_ZONE_FORMATTER_NO_COLON).toFormatter(IsoLocale.ROOT) + .append(TIME_ZONE_FORMATTER_NO_COLON).toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT) ); /* @@ -1324,11 +1476,14 @@ public class DateFormatters { private static final DateFormatter BASIC_WEEK_DATE_TIME_NO_MILLIS = new JavaDateFormatter("basic_week_date_time_no_millis", new DateTimeFormatterBuilder() .append(STRICT_BASIC_WEEK_DATE_PRINTER).append(DateTimeFormatter.ofPattern("'T'HHmmssX", IsoLocale.ROOT)) - .toFormatter(IsoLocale.ROOT), + .toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT), new DateTimeFormatterBuilder().append(BASIC_WEEK_DATE_FORMATTER).appendLiteral("T").append(BASIC_TIME_NO_MILLIS_BASE) - .appendZoneOrOffsetId().toFormatter(IsoLocale.ROOT), + .appendZoneOrOffsetId().toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT), new DateTimeFormatterBuilder().append(BASIC_WEEK_DATE_FORMATTER).appendLiteral("T").append(BASIC_TIME_NO_MILLIS_BASE) - .append(TIME_ZONE_FORMATTER_NO_COLON).toFormatter(IsoLocale.ROOT) + .append(TIME_ZONE_FORMATTER_NO_COLON).toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT) ); /* @@ -1337,9 +1492,12 @@ public class DateFormatters { * time zone offset (HH:mm:ss.SSSZZ). */ private static final DateFormatter TIME = new JavaDateFormatter("time", - new DateTimeFormatterBuilder().append(STRICT_TIME_PRINTER).appendOffset("+HH:MM", "Z").toFormatter(IsoLocale.ROOT), - new DateTimeFormatterBuilder().append(TIME_PREFIX).appendZoneOrOffsetId().toFormatter(IsoLocale.ROOT), + new DateTimeFormatterBuilder().append(STRICT_TIME_PRINTER).appendOffset("+HH:MM", "Z").toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT), + new DateTimeFormatterBuilder().append(TIME_PREFIX).appendZoneOrOffsetId().toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT), new DateTimeFormatterBuilder().append(TIME_PREFIX).append(TIME_ZONE_FORMATTER_NO_COLON).toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT) ); /* @@ -1348,10 +1506,13 @@ public class DateFormatters { */ private static final DateFormatter TIME_NO_MILLIS = new JavaDateFormatter("time_no_millis", new DateTimeFormatterBuilder().append(STRICT_TIME_NO_MILLIS_BASE).appendOffset("+HH:MM", "Z") - .toFormatter(IsoLocale.ROOT), - new DateTimeFormatterBuilder().append(TIME_NO_MILLIS_FORMATTER).appendZoneOrOffsetId().toFormatter(IsoLocale.ROOT), + .toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT), + new DateTimeFormatterBuilder().append(TIME_NO_MILLIS_FORMATTER).appendZoneOrOffsetId().toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT), new DateTimeFormatterBuilder().append(TIME_NO_MILLIS_FORMATTER).append(TIME_ZONE_FORMATTER_NO_COLON) .toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT) ); /* @@ -1361,11 +1522,14 @@ public class DateFormatters { */ private static final DateFormatter T_TIME = new JavaDateFormatter("t_time", new DateTimeFormatterBuilder().appendLiteral('T').append(STRICT_TIME_PRINTER).appendOffset("+HH:MM", "Z") - .toFormatter(IsoLocale.ROOT), + .toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT), new DateTimeFormatterBuilder().appendLiteral("T").append(TIME_PREFIX) - .appendZoneOrOffsetId().toFormatter(IsoLocale.ROOT), + .appendZoneOrOffsetId().toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT), new DateTimeFormatterBuilder().appendLiteral("T").append(TIME_PREFIX) - .append(TIME_ZONE_FORMATTER_NO_COLON).toFormatter(IsoLocale.ROOT) + .append(TIME_ZONE_FORMATTER_NO_COLON).toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT) ); /* @@ -1375,10 +1539,13 @@ public class DateFormatters { */ private static final DateFormatter T_TIME_NO_MILLIS = new JavaDateFormatter("t_time_no_millis", new DateTimeFormatterBuilder().appendLiteral("T").append(STRICT_TIME_NO_MILLIS_BASE) - .appendOffset("+HH:MM", "Z").toFormatter(IsoLocale.ROOT), - new DateTimeFormatterBuilder().append(T_TIME_NO_MILLIS_FORMATTER).appendZoneOrOffsetId().toFormatter(IsoLocale.ROOT), + .appendOffset("+HH:MM", "Z").toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT), + new DateTimeFormatterBuilder().append(T_TIME_NO_MILLIS_FORMATTER).appendZoneOrOffsetId().toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT), new DateTimeFormatterBuilder().append(T_TIME_NO_MILLIS_FORMATTER).append(TIME_ZONE_FORMATTER_NO_COLON) .toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT) ); /* @@ -1389,9 +1556,11 @@ public class DateFormatters { .appendValue(ChronoField.YEAR, 4, 10, SignStyle.EXCEEDS_PAD) .appendLiteral("-") .appendValue(MONTH_OF_YEAR, 2, 2, SignStyle.NOT_NEGATIVE) - .toFormatter(IsoLocale.ROOT), + .toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT), new DateTimeFormatterBuilder().appendValue(ChronoField.YEAR).appendLiteral("-").appendValue(MONTH_OF_YEAR) .toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT) ); /* @@ -1406,6 +1575,7 @@ public class DateFormatters { .appendLiteral("-") .appendValue(DAY_OF_MONTH) .toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT) ); /* @@ -1424,6 +1594,7 @@ public class DateFormatters { .appendLiteral("-W") .appendValue(WeekFields.ISO.weekOfWeekBasedYear()) .toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT) ); /* @@ -1435,7 +1606,8 @@ public class DateFormatters { .append(STRICT_WEEKYEAR_WEEK_FORMATTER) .appendLiteral("-") .appendValue(WeekFields.ISO.dayOfWeek()) - .toFormatter(IsoLocale.ROOT), + .toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT), new DateTimeFormatterBuilder() .appendValue(WeekFields.ISO.weekBasedYear()) .appendLiteral("-W") @@ -1443,6 +1615,7 @@ public class DateFormatters { .appendLiteral("-") .appendValue(WeekFields.ISO.dayOfWeek()) .toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT) ); @@ -1452,7 +1625,8 @@ public class DateFormatters { // ///////////////////////////////////////// - static DateFormatter forPattern(String input) { + static DateFormatter + forPattern(String input) { if (Strings.hasLength(input)) { input = input.trim(); } @@ -1625,7 +1799,8 @@ static DateFormatter forPattern(String input) { try { return new JavaDateFormatter(input, new DateTimeFormatterBuilder() .appendPattern(input) - .toFormatter(IsoLocale.ROOT)); + .toFormatter(IsoLocale.ROOT) + .withResolverStyle(ResolverStyle.STRICT)); } catch (IllegalArgumentException e) { throw new IllegalArgumentException("Invalid format: [" + input + "]: " + e.getMessage(), e); } @@ -1673,7 +1848,7 @@ public static ZonedDateTime from(TemporalAccessor accessor) { zoneId = ZoneOffset.UTC; } - LocalDate localDate = accessor.query(TemporalQueries.localDate()); + LocalDate localDate = accessor.query(LOCAL_DATE_QUERY); LocalTime localTime = accessor.query(TemporalQueries.localTime()); boolean isLocalDateSet = localDate != null; boolean isLocalTimeSet = localTime != null; @@ -1687,11 +1862,12 @@ public static ZonedDateTime from(TemporalAccessor accessor) { return localDate.atStartOfDay(zoneId); } else if (isLocalTimeSet) { return of(getLocaldate(accessor), localTime, zoneId); - } else if (accessor.isSupported(ChronoField.YEAR)) { + } else if (accessor.isSupported(ChronoField.YEAR) || accessor.isSupported(ChronoField.YEAR_OF_ERA) ) { if (accessor.isSupported(MONTH_OF_YEAR)) { return getFirstOfMonth(accessor).atStartOfDay(zoneId); } else { - return Year.of(accessor.get(ChronoField.YEAR)).atDay(1).atStartOfDay(zoneId); + int year = getYear(accessor); + return Year.of(year).atDay(1).atStartOfDay(zoneId); } } else if (accessor.isSupported(MONTH_OF_YEAR)) { // missing year, falling back to the epoch and then filling @@ -1715,18 +1891,56 @@ public static ZonedDateTime from(TemporalAccessor accessor) { throw new IllegalArgumentException("temporal accessor [" + accessor + "] cannot be converted to zoned date time"); } + /** + * extending the java.time.temporal.TemporalQueries.LOCAL_DATE implementation to also create local dates + * when YearOfEra was used instead of Year. + * This is to make it compatible with Joda behaviour + */ + static final TemporalQuery LOCAL_DATE_QUERY = new TemporalQuery<>() { + @Override + public LocalDate queryFrom(TemporalAccessor temporal) { + if (temporal.isSupported(ChronoField.EPOCH_DAY)) { + return LocalDate.ofEpochDay(temporal.getLong(ChronoField.EPOCH_DAY)); + } else if( temporal.isSupported(ChronoField.YEAR_OF_ERA) || temporal.isSupported(ChronoField.YEAR)) { + int year = getYear(temporal); + if(temporal.isSupported(ChronoField.MONTH_OF_YEAR) && temporal.isSupported(ChronoField.DAY_OF_MONTH)){ + return LocalDate.of(year, temporal.get(ChronoField.MONTH_OF_YEAR), temporal.get(ChronoField.DAY_OF_MONTH)); + } else if (temporal.isSupported(DAY_OF_YEAR)) { + return LocalDate.ofYearDay(year, temporal.get(DAY_OF_YEAR)); + } + } + return null; + } + + @Override + public String toString() { + return "LocalDate"; + } + }; + private static LocalDate getLocaldate(TemporalAccessor accessor) { + int year = getYear(accessor); if (accessor.isSupported(MONTH_OF_YEAR)) { if (accessor.isSupported(DAY_OF_MONTH)) { - return LocalDate.of(1970, accessor.get(MONTH_OF_YEAR), accessor.get(DAY_OF_MONTH)); + return LocalDate.of(year, accessor.get(MONTH_OF_YEAR), accessor.get(DAY_OF_MONTH)); } else { - return LocalDate.of(1970, accessor.get(MONTH_OF_YEAR), 1); + return LocalDate.of(year, accessor.get(MONTH_OF_YEAR), 1); } } return LOCALDATE_EPOCH; } + private static int getYear(TemporalAccessor accessor) { + if(accessor.isSupported(ChronoField.YEAR)){ + return accessor.get(ChronoField.YEAR); + } + if(accessor.isSupported(ChronoField.YEAR_OF_ERA)){ + return accessor.get(ChronoField.YEAR_OF_ERA); + } + return 1970; + } + @SuppressForbidden(reason = "ZonedDateTime.of is fine here") private static ZonedDateTime of(LocalDate localDate, LocalTime localTime, ZoneId zoneId) { return ZonedDateTime.of(localDate, localTime, zoneId); @@ -1734,6 +1948,6 @@ private static ZonedDateTime of(LocalDate localDate, LocalTime localTime, ZoneId @SuppressForbidden(reason = "LocalDate.of is fine here") private static LocalDate getFirstOfMonth(TemporalAccessor accessor) { - return LocalDate.of(accessor.get(ChronoField.YEAR), accessor.get(MONTH_OF_YEAR), 1); + return LocalDate.of(getYear(accessor), accessor.get(MONTH_OF_YEAR), 1); } } diff --git a/server/src/test/java/org/elasticsearch/common/joda/JavaJodaTimeDuellingTests.java b/server/src/test/java/org/elasticsearch/common/joda/JavaJodaTimeDuellingTests.java index 07cca6a33dd5c..f54891f4e4d53 100644 --- a/server/src/test/java/org/elasticsearch/common/joda/JavaJodaTimeDuellingTests.java +++ b/server/src/test/java/org/elasticsearch/common/joda/JavaJodaTimeDuellingTests.java @@ -848,6 +848,10 @@ public void testIso8601Parsers() { assertSameDate("2018-10-10T10:11:12,123+05:30", format, jodaFormatter, javaFormatter); } + public void testParsingLocalDateFromYearOfEra(){ + //with strict resolving, YearOfEra expect an era, otherwise it won't resolve to a date + assertSameDate("2018363","yyyyDDD",Joda.forPattern("YYYYDDD"),DateFormatter.forPattern("uuuuDDD")); + } public void testParsingMissingTimezone() { long millisJava = DateFormatter.forPattern("8yyyy-MM-dd HH:mm:ss").parseMillis("2018-02-18 17:47:17"); long millisJoda = DateFormatter.forPattern("yyyy-MM-dd HH:mm:ss").parseMillis("2018-02-18 17:47:17"); diff --git a/server/src/test/java/org/elasticsearch/search/aggregations/pipeline/DateDerivativeIT.java b/server/src/test/java/org/elasticsearch/search/aggregations/pipeline/DateDerivativeIT.java index 395d7498732c3..8de113b3239a8 100644 --- a/server/src/test/java/org/elasticsearch/search/aggregations/pipeline/DateDerivativeIT.java +++ b/server/src/test/java/org/elasticsearch/search/aggregations/pipeline/DateDerivativeIT.java @@ -198,7 +198,7 @@ public void testSingleValuedFieldNormalised_timeZone_CET_DstStart() throws Excep List builders = new ArrayList<>(); ZoneId timezone = ZoneId.of("CET"); - DateFormatter formatter = DateFormatter.forPattern("yyyy-MM-dd'T'HH:mm:ss").withZone(timezone); + DateFormatter formatter = DateFormatter.forPattern("uuuu-MM-dd'T'HH:mm:ss").withZone(timezone); // epoch millis: 1332547200000 addNTimes(1, IDX_DST_START, DateFormatters.from(formatter.parse("2012-03-24T01:00:00")), builders); // day with dst shift, only 23h long @@ -223,7 +223,7 @@ public void testSingleValuedFieldNormalised_timeZone_CET_DstStart() throws Excep List buckets = deriv.getBuckets(); assertThat(buckets.size(), equalTo(4)); - DateFormatter dateFormatter = DateFormatter.forPattern("yyyy-MM-dd"); + DateFormatter dateFormatter = DateFormatter.forPattern("uuuu-MM-dd"); ZonedDateTime expectedKeyFirstBucket = LocalDate.from(dateFormatter.parse("2012-03-24")).atStartOfDay(timezone).withZoneSameInstant(ZoneOffset.UTC); assertBucket(buckets.get(0), expectedKeyFirstBucket, 1L, nullValue(), null, null); @@ -250,7 +250,7 @@ public void testSingleValuedFieldNormalised_timeZone_CET_DstEnd() throws Excepti ZoneId timezone = ZoneId.of("CET"); List builders = new ArrayList<>(); - DateFormatter formatter = DateFormatter.forPattern("yyyy-MM-dd'T'HH:mm:ss").withZone(timezone); + DateFormatter formatter = DateFormatter.forPattern("uuuu-MM-dd'T'HH:mm:ss").withZone(timezone); addNTimes(1, IDX_DST_END, DateFormatters.from(formatter.parse("2012-10-27T01:00:00")), builders); // day with dst shift -1h, 25h long addNTimes(2, IDX_DST_END, DateFormatters.from(formatter.parse("2012-10-28T01:00:00")), builders); @@ -274,7 +274,7 @@ public void testSingleValuedFieldNormalised_timeZone_CET_DstEnd() throws Excepti List buckets = deriv.getBuckets(); assertThat(buckets.size(), equalTo(4)); - DateFormatter dateFormatter = DateFormatter.forPattern("yyyy-MM-dd").withZone(ZoneOffset.UTC); + DateFormatter dateFormatter = DateFormatter.forPattern("uuuu-MM-dd").withZone(ZoneOffset.UTC); ZonedDateTime expectedKeyFirstBucket = LocalDate.from(dateFormatter.parse("2012-10-27")).atStartOfDay(timezone).withZoneSameInstant(ZoneOffset.UTC); @@ -303,7 +303,7 @@ public void testSingleValuedFieldNormalised_timeZone_AsiaKathmandu() throws Exce ZoneId timezone = ZoneId.of("Asia/Kathmandu"); List builders = new ArrayList<>(); - DateFormatter formatter = DateFormatter.forPattern("yyyy-MM-dd'T'HH:mm:ss").withZone(timezone); + DateFormatter formatter = DateFormatter.forPattern("uuuu-MM-dd'T'HH:mm:ss").withZone(timezone); addNTimes(1, IDX_DST_KATHMANDU, DateFormatters.from(formatter.parse("1985-12-31T22:30:00")), builders); // the shift happens during the next bucket, which includes the 45min that do not start on the full hour addNTimes(2, IDX_DST_KATHMANDU, DateFormatters.from(formatter.parse("1985-12-31T23:30:00")), builders); @@ -327,7 +327,7 @@ public void testSingleValuedFieldNormalised_timeZone_AsiaKathmandu() throws Exce List buckets = deriv.getBuckets(); assertThat(buckets.size(), equalTo(4)); - DateFormatter dateFormatter = DateFormatter.forPattern("yyyy-MM-dd'T'HH:mm:ss").withZone(ZoneOffset.UTC); + DateFormatter dateFormatter = DateFormatter.forPattern("uuuu-MM-dd'T'HH:mm:ss").withZone(ZoneOffset.UTC); ZonedDateTime expectedKeyFirstBucket = LocalDateTime.from(dateFormatter.parse("1985-12-31T22:00:00")).atZone(timezone).withZoneSameInstant(ZoneOffset.UTC); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/IndexLifecycleOriginationDateParser.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/IndexLifecycleOriginationDateParser.java index 05b362d733e9c..795ddcbc62e91 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/IndexLifecycleOriginationDateParser.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/IndexLifecycleOriginationDateParser.java @@ -17,7 +17,7 @@ public class IndexLifecycleOriginationDateParser { - private static final DateFormatter DATE_FORMATTER = DateFormatter.forPattern("yyyy.MM.dd"); + private static final DateFormatter DATE_FORMATTER = DateFormatter.forPattern("uuuu.MM.dd"); private static final String INDEX_NAME_REGEX = "^.*-(\\d{4}.\\d{2}.\\d{2})(-[\\d]+)?$"; private static final Pattern INDEX_NAME_PATTERN = Pattern.compile(INDEX_NAME_REGEX); diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/IndexLifecycleOriginationDateParserTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/IndexLifecycleOriginationDateParserTests.java index 520a316aaee4c..9775e0aa280e7 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/IndexLifecycleOriginationDateParserTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/IndexLifecycleOriginationDateParserTests.java @@ -17,7 +17,7 @@ public class IndexLifecycleOriginationDateParserTests extends ESTestCase { - private static final DateFormatter dateFormatter = DateFormatter.forPattern("yyyy.MM.dd"); + private static final DateFormatter dateFormatter = DateFormatter.forPattern("uuuu.MM.dd"); public void testShouldParseIndexNameReturnsFalseWhenOriginationDateIsSet() { Settings settings = Settings.builder()