diff --git a/libs/core/src/main/java/org/elasticsearch/common/time/IsoLocale.java b/libs/core/src/main/java/org/elasticsearch/common/time/IsoLocale.java new file mode 100644 index 0000000000000..4d6d37d92345e --- /dev/null +++ b/libs/core/src/main/java/org/elasticsearch/common/time/IsoLocale.java @@ -0,0 +1,40 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.elasticsearch.common.time; + +import java.util.Locale; + +/** + * Locale constants to be used across elasticsearch code base. + * java.util.Locale.ROOT should not be used as it defaults start of the week incorrectly to Sunday. + */ +public final class IsoLocale { + private IsoLocale() { + throw new UnsupportedOperationException(); + } + + /** + * We want to use Locale.ROOT but with a start of the week as defined in ISO8601 to be compatible with the behaviour in joda-time + * https://github.com/elastic/elasticsearch/issues/42588 + * @see java.time.temporal.WeekFields#of(Locale) + */ + public static final Locale ROOT = new Locale.Builder() + .setLocale(Locale.ROOT) + .setUnicodeLocaleKeyword("fw", "mon").build(); +} diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/310_date_agg_per_day_of_week.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/310_date_agg_per_day_of_week.yml new file mode 100644 index 0000000000000..a8952ac4e16d6 --- /dev/null +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/310_date_agg_per_day_of_week.yml @@ -0,0 +1,47 @@ +--- +setup: + - skip: + version: " - 7.99.99" #TODO change this after backport + reason: "not backported yet" + + - do: + indices.create: + index: test + body: + mappings: + properties: + date: + type: date + + - do: + index: + index: test + id: 1 + body: { "date": "2009-11-15T14:12:12" } + + - do: + indices.refresh: + index: [test] + +--- +# The inserted document has a field date=2009-11-15T14:12:12 which is Sunday. +# When aggregating per day of the week this should be considered as last day of the week (7) +# and this value should be used in 'key_as_string' +"Date aggregartion per day of week": + - do: + search: + rest_total_hits_as_int: true + index: test + body: + aggregations: + test: + "date_histogram": { + "field": "date", + "calendar_interval": "day", + "format": "e", + "offset": 0 + } + + - match: {hits.total: 1} + - length: { aggregations.test.buckets: 1 } + - match: { aggregations.test.buckets.0.key_as_string: "7" } 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 6f2e0e9e12e70..8cb71866ad252 100644 --- a/server/src/main/java/org/elasticsearch/common/time/DateFormatters.java +++ b/server/src/main/java/org/elasticsearch/common/time/DateFormatters.java @@ -42,7 +42,6 @@ import java.time.temporal.WeekFields; import java.util.ArrayList; import java.util.List; -import java.util.Locale; import static java.time.temporal.ChronoField.DAY_OF_MONTH; import static java.time.temporal.ChronoField.DAY_OF_WEEK; @@ -57,7 +56,7 @@ public class DateFormatters { private static final DateTimeFormatter TIME_ZONE_FORMATTER_NO_COLON = new DateTimeFormatterBuilder() .appendOffset("+HHmm", "Z") - .toFormatter(Locale.ROOT); + .toFormatter(IsoLocale.ROOT); private static final DateTimeFormatter STRICT_YEAR_MONTH_DAY_FORMATTER = new DateTimeFormatterBuilder() .appendValue(ChronoField.YEAR, 4, 10, SignStyle.EXCEEDS_PAD) @@ -65,7 +64,7 @@ public class DateFormatters { .appendValue(MONTH_OF_YEAR, 2, 2, SignStyle.NOT_NEGATIVE) .appendLiteral('-') .appendValue(DAY_OF_MONTH, 2, 2, SignStyle.NOT_NEGATIVE) - .toFormatter(Locale.ROOT); + .toFormatter(IsoLocale.ROOT); private static final DateTimeFormatter STRICT_HOUR_MINUTE_SECOND_FORMATTER = new DateTimeFormatterBuilder() .appendValue(HOUR_OF_DAY, 2, 2, SignStyle.NOT_NEGATIVE) @@ -73,7 +72,7 @@ public class DateFormatters { .appendValue(MINUTE_OF_HOUR, 2, 2, SignStyle.NOT_NEGATIVE) .appendLiteral(':') .appendValue(SECOND_OF_MINUTE, 2, 2, SignStyle.NOT_NEGATIVE) - .toFormatter(Locale.ROOT); + .toFormatter(IsoLocale.ROOT); private static final DateTimeFormatter STRICT_DATE_OPTIONAL_TIME_PRINTER = new DateTimeFormatterBuilder() .append(STRICT_YEAR_MONTH_DAY_FORMATTER) @@ -95,7 +94,7 @@ public class DateFormatters { .optionalEnd() .optionalEnd() .optionalEnd() - .toFormatter(Locale.ROOT); + .toFormatter(IsoLocale.ROOT); private static final DateTimeFormatter STRICT_DATE_OPTIONAL_TIME_FORMATTER = new DateTimeFormatterBuilder() .append(STRICT_YEAR_MONTH_DAY_FORMATTER) @@ -126,7 +125,7 @@ public class DateFormatters { .optionalEnd() .optionalEnd() .optionalEnd() - .toFormatter(Locale.ROOT); + .toFormatter(IsoLocale.ROOT); /** * Returns a generic ISO datetime parser where the date is mandatory and the time is optional. @@ -153,7 +152,7 @@ public class DateFormatters { .append(TIME_ZONE_FORMATTER_NO_COLON) .optionalEnd() .optionalEnd() - .toFormatter(Locale.ROOT); + .toFormatter(IsoLocale.ROOT); private static final DateTimeFormatter STRICT_DATE_OPTIONAL_TIME_PRINTER_NANOS = new DateTimeFormatterBuilder() .append(STRICT_YEAR_MONTH_DAY_FORMATTER) @@ -175,7 +174,7 @@ public class DateFormatters { .optionalEnd() .optionalEnd() .optionalEnd() - .toFormatter(Locale.ROOT); + .toFormatter(IsoLocale.ROOT); /** * Returns a generic ISO datetime parser where the date is mandatory and the time is optional with nanosecond resolution. @@ -218,7 +217,7 @@ public class DateFormatters { .append(TIME_ZONE_FORMATTER_NO_COLON) .optionalEnd() .optionalEnd() - .toFormatter(Locale.ROOT)); + .toFormatter(IsoLocale.ROOT)); ///////////////////////////////////////// // @@ -233,16 +232,18 @@ 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(Locale.ROOT); + .toFormatter(IsoLocale.ROOT); /* * Returns a basic formatter for a two digit hour of day, two digit minute * of hour, two digit second of minute, and time zone offset (HHmmssZ). */ 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(Locale.ROOT), - new DateTimeFormatterBuilder().append(BASIC_TIME_NO_MILLIS_BASE).appendZoneOrOffsetId().toFormatter(Locale.ROOT), - new DateTimeFormatterBuilder().append(BASIC_TIME_NO_MILLIS_BASE).append(TIME_ZONE_FORMATTER_NO_COLON).toFormatter(Locale.ROOT) + 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), + new DateTimeFormatterBuilder().append(BASIC_TIME_NO_MILLIS_BASE).append(TIME_ZONE_FORMATTER_NO_COLON) + .toFormatter(IsoLocale.ROOT) ); private static final DateTimeFormatter BASIC_TIME_FORMATTER = new DateTimeFormatterBuilder() @@ -250,14 +251,14 @@ 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(Locale.ROOT); + .toFormatter(IsoLocale.ROOT); 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(Locale.ROOT); + .toFormatter(IsoLocale.ROOT); /* * Returns a basic formatter for a two digit hour of day, two digit minute @@ -265,16 +266,18 @@ public class DateFormatters { * offset (HHmmss.SSSZ). */ private static final DateFormatter BASIC_TIME = new JavaDateFormatter("basic_time", - new DateTimeFormatterBuilder().append(BASIC_TIME_PRINTER).appendOffset("+HH:MM", "Z").toFormatter(Locale.ROOT), - new DateTimeFormatterBuilder().append(BASIC_TIME_FORMATTER).appendZoneOrOffsetId().toFormatter(Locale.ROOT), - new DateTimeFormatterBuilder().append(BASIC_TIME_FORMATTER).append(TIME_ZONE_FORMATTER_NO_COLON).toFormatter(Locale.ROOT) + new DateTimeFormatterBuilder().append(BASIC_TIME_PRINTER).appendOffset("+HH:MM", "Z") + .toFormatter(IsoLocale.ROOT), + new DateTimeFormatterBuilder().append(BASIC_TIME_FORMATTER).appendZoneOrOffsetId().toFormatter(IsoLocale.ROOT), + new DateTimeFormatterBuilder().append(BASIC_TIME_FORMATTER).append(TIME_ZONE_FORMATTER_NO_COLON) + .toFormatter(IsoLocale.ROOT) ); private static final DateTimeFormatter BASIC_T_TIME_PRINTER = - new DateTimeFormatterBuilder().appendLiteral("T").append(BASIC_TIME_PRINTER).toFormatter(Locale.ROOT); + new DateTimeFormatterBuilder().appendLiteral("T").append(BASIC_TIME_PRINTER).toFormatter(IsoLocale.ROOT); private static final DateTimeFormatter BASIC_T_TIME_FORMATTER = - new DateTimeFormatterBuilder().appendLiteral("T").append(BASIC_TIME_FORMATTER).toFormatter(Locale.ROOT); + new DateTimeFormatterBuilder().appendLiteral("T").append(BASIC_TIME_FORMATTER).toFormatter(IsoLocale.ROOT); /* * Returns a basic formatter for a two digit hour of day, two digit minute @@ -282,9 +285,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(Locale.ROOT), - new DateTimeFormatterBuilder().append(BASIC_T_TIME_FORMATTER).appendZoneOrOffsetId().toFormatter(Locale.ROOT), - new DateTimeFormatterBuilder().append(BASIC_T_TIME_FORMATTER).append(TIME_ZONE_FORMATTER_NO_COLON).toFormatter(Locale.ROOT) + 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_FORMATTER).append(TIME_ZONE_FORMATTER_NO_COLON). + toFormatter(IsoLocale.ROOT) ); /* @@ -294,40 +298,42 @@ 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(Locale.ROOT), - new DateTimeFormatterBuilder().appendLiteral("T").append(BASIC_TIME_NO_MILLIS_BASE).appendZoneOrOffsetId().toFormatter(Locale.ROOT), - new DateTimeFormatterBuilder().appendLiteral("T").append(BASIC_TIME_NO_MILLIS_BASE).append(TIME_ZONE_FORMATTER_NO_COLON) - .toFormatter(Locale.ROOT) + .appendOffset("+HH:MM", "Z").toFormatter(IsoLocale.ROOT), + new DateTimeFormatterBuilder().appendLiteral("T").append(BASIC_TIME_NO_MILLIS_BASE) + .appendZoneOrOffsetId().toFormatter(IsoLocale.ROOT), + new DateTimeFormatterBuilder().appendLiteral("T").append(BASIC_TIME_NO_MILLIS_BASE) + .append(TIME_ZONE_FORMATTER_NO_COLON) + .toFormatter(IsoLocale.ROOT) ); 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(Locale.ROOT); + .toFormatter(IsoLocale.ROOT); private static final DateTimeFormatter BASIC_DATE_TIME_FORMATTER = new DateTimeFormatterBuilder() .append(BASIC_YEAR_MONTH_DAY_FORMATTER) .append(BASIC_T_TIME_FORMATTER) - .toFormatter(Locale.ROOT); + .toFormatter(IsoLocale.ROOT); private static final DateTimeFormatter BASIC_DATE_TIME_PRINTER = new DateTimeFormatterBuilder() .append(BASIC_YEAR_MONTH_DAY_FORMATTER) .append(BASIC_T_TIME_PRINTER) - .toFormatter(Locale.ROOT); + .toFormatter(IsoLocale.ROOT); /* * Returns a basic formatter that combines a basic date and time, separated * by a 'T' (yyyyMMdd'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(Locale.ROOT), - new DateTimeFormatterBuilder().append(BASIC_DATE_TIME_FORMATTER).appendZoneOrOffsetId().toFormatter(Locale.ROOT), - new DateTimeFormatterBuilder().append(BASIC_DATE_TIME_FORMATTER).append(TIME_ZONE_FORMATTER_NO_COLON).toFormatter(Locale.ROOT) + 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_FORMATTER).append(TIME_ZONE_FORMATTER_NO_COLON).toFormatter(IsoLocale.ROOT) ); private static final DateTimeFormatter BASIC_DATE_T = - new DateTimeFormatterBuilder().append(BASIC_YEAR_MONTH_DAY_FORMATTER).appendLiteral("T").toFormatter(Locale.ROOT); + new DateTimeFormatterBuilder().append(BASIC_YEAR_MONTH_DAY_FORMATTER).appendLiteral("T").toFormatter(IsoLocale.ROOT); /* * Returns a basic formatter that combines a basic date and time without millis, @@ -335,11 +341,11 @@ public class DateFormatters { */ 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(Locale.ROOT), + .appendOffset("+HH:MM", "Z").toFormatter(IsoLocale.ROOT), new DateTimeFormatterBuilder().append(BASIC_DATE_T).append(BASIC_TIME_NO_MILLIS_BASE) - .appendZoneOrOffsetId().toFormatter(Locale.ROOT), + .appendZoneOrOffsetId().toFormatter(IsoLocale.ROOT), new DateTimeFormatterBuilder().append(BASIC_DATE_T).append(BASIC_TIME_NO_MILLIS_BASE) - .append(TIME_ZONE_FORMATTER_NO_COLON).toFormatter(Locale.ROOT) + .append(TIME_ZONE_FORMATTER_NO_COLON).toFormatter(IsoLocale.ROOT) ); /* @@ -347,7 +353,7 @@ public class DateFormatters { * digit year and three digit dayOfYear (yyyyDDD). */ private static final DateFormatter BASIC_ORDINAL_DATE = new JavaDateFormatter("basic_ordinal_date", - DateTimeFormatter.ofPattern("yyyyDDD", Locale.ROOT)); + DateTimeFormatter.ofPattern("yyyyDDD", IsoLocale.ROOT)); /* * Returns a formatter for a full ordinal date and time, using a four @@ -355,11 +361,11 @@ public class DateFormatters { */ 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(Locale.ROOT), + .appendOffset("+HH:MM", "Z").toFormatter(IsoLocale.ROOT), new DateTimeFormatterBuilder().appendPattern("yyyyDDD").append(BASIC_T_TIME_FORMATTER) - .appendZoneOrOffsetId().toFormatter(Locale.ROOT), + .appendZoneOrOffsetId().toFormatter(IsoLocale.ROOT), new DateTimeFormatterBuilder().appendPattern("yyyyDDD").append(BASIC_T_TIME_FORMATTER) - .append(TIME_ZONE_FORMATTER_NO_COLON).toFormatter(Locale.ROOT) + .append(TIME_ZONE_FORMATTER_NO_COLON).toFormatter(IsoLocale.ROOT) ); @@ -369,11 +375,11 @@ public class DateFormatters { */ 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(Locale.ROOT), + .appendOffset("+HH:MM", "Z").toFormatter(IsoLocale.ROOT), new DateTimeFormatterBuilder().appendPattern("yyyyDDD").appendLiteral("T").append(BASIC_TIME_NO_MILLIS_BASE) - .appendZoneOrOffsetId().toFormatter(Locale.ROOT), + .appendZoneOrOffsetId().toFormatter(IsoLocale.ROOT), new DateTimeFormatterBuilder().appendPattern("yyyyDDD").appendLiteral("T").append(BASIC_TIME_NO_MILLIS_BASE) - .append(TIME_ZONE_FORMATTER_NO_COLON).toFormatter(Locale.ROOT) + .append(TIME_ZONE_FORMATTER_NO_COLON).toFormatter(IsoLocale.ROOT) ); private static final DateTimeFormatter BASIC_WEEK_DATE_FORMATTER = new DateTimeFormatterBuilder() @@ -381,7 +387,7 @@ public class DateFormatters { .appendLiteral("W") .appendValue(IsoFields.WEEK_OF_WEEK_BASED_YEAR, 1, 2, SignStyle.NEVER) .appendValue(ChronoField.DAY_OF_WEEK) - .toFormatter(Locale.ROOT); + .toFormatter(IsoLocale.ROOT); ///////////////////////////////////////// // @@ -400,7 +406,7 @@ public class DateFormatters { .appendLiteral("W") .appendValue(IsoFields.WEEK_OF_WEEK_BASED_YEAR, 1, 2, SignStyle.NEVER) .appendValue(ChronoField.DAY_OF_WEEK) - .toFormatter(Locale.ROOT); + .toFormatter(IsoLocale.ROOT); private static final DateTimeFormatter STRICT_BASIC_WEEK_DATE_PRINTER = new DateTimeFormatterBuilder() .parseStrict() @@ -408,7 +414,7 @@ public class DateFormatters { .appendLiteral("W") .appendValue(IsoFields.WEEK_OF_WEEK_BASED_YEAR, 2, 2, SignStyle.NEVER) .appendValue(ChronoField.DAY_OF_WEEK) - .toFormatter(Locale.ROOT); + .toFormatter(IsoLocale.ROOT); /* * Returns a basic formatter for a full date as four digit weekyear, two @@ -430,7 +436,7 @@ 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(Locale.ROOT), + .toFormatter(IsoLocale.ROOT), new DateTimeFormatterBuilder() .append(STRICT_BASIC_WEEK_DATE_PRINTER) .appendLiteral("T") @@ -438,7 +444,7 @@ public class DateFormatters { .appendValue(MINUTE_OF_HOUR, 2, 2, SignStyle.NOT_NEGATIVE) .appendValue(SECOND_OF_MINUTE, 2, 2, SignStyle.NOT_NEGATIVE) .appendZoneOrOffsetId() - .toFormatter(Locale.ROOT), + .toFormatter(IsoLocale.ROOT), new DateTimeFormatterBuilder() .append(STRICT_BASIC_WEEK_DATE_PRINTER) .appendLiteral("T") @@ -446,7 +452,7 @@ public class DateFormatters { .appendValue(MINUTE_OF_HOUR, 2, 2, SignStyle.NOT_NEGATIVE) .appendValue(SECOND_OF_MINUTE, 2, 2, SignStyle.NOT_NEGATIVE) .append(TIME_ZONE_FORMATTER_NO_COLON) - .toFormatter(Locale.ROOT) + .toFormatter(IsoLocale.ROOT) ); /* @@ -456,8 +462,8 @@ 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", Locale.ROOT)) - .toFormatter(Locale.ROOT), + .append(DateTimeFormatter.ofPattern("'T'HHmmss.SSSX", IsoLocale.ROOT)) + .toFormatter(IsoLocale.ROOT), new DateTimeFormatterBuilder() .append(STRICT_BASIC_WEEK_DATE_FORMATTER) .appendLiteral("T") @@ -466,7 +472,7 @@ public class DateFormatters { .appendValue(SECOND_OF_MINUTE, 2, 2, SignStyle.NOT_NEGATIVE) .appendFraction(NANO_OF_SECOND, 1, 9, true) .appendZoneOrOffsetId() - .toFormatter(Locale.ROOT), + .toFormatter(IsoLocale.ROOT), new DateTimeFormatterBuilder() .append(STRICT_BASIC_WEEK_DATE_FORMATTER) .appendLiteral("T") @@ -475,26 +481,26 @@ public class DateFormatters { .appendValue(SECOND_OF_MINUTE, 2, 2, SignStyle.NOT_NEGATIVE) .appendFraction(NANO_OF_SECOND, 1, 9, true) .append(TIME_ZONE_FORMATTER_NO_COLON) - .toFormatter(Locale.ROOT) + .toFormatter(IsoLocale.ROOT) ); /* * An ISO date formatter that formats or parses a date without an offset, such as '2011-12-03'. */ private static final DateFormatter STRICT_DATE = new JavaDateFormatter("strict_date", - DateTimeFormatter.ISO_LOCAL_DATE.withResolverStyle(ResolverStyle.LENIENT).withLocale(Locale.ROOT)); + DateTimeFormatter.ISO_LOCAL_DATE.withResolverStyle(ResolverStyle.LENIENT).withLocale(IsoLocale.ROOT)); /* * 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", Locale.ROOT)); + DateTimeFormatter.ofPattern("yyyy-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", Locale.ROOT)); + DateTimeFormatter.ofPattern("yyyy-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'. @@ -510,14 +516,14 @@ public class DateFormatters { .appendValue(ChronoField.YEAR, 4, 10, SignStyle.EXCEEDS_PAD) .appendLiteral("-") .appendValue(MONTH_OF_YEAR, 2, 2, SignStyle.NOT_NEGATIVE) - .toFormatter(Locale.ROOT)); + .toFormatter(IsoLocale.ROOT)); /* * 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(Locale.ROOT)); + .toFormatter(IsoLocale.ROOT)); /* * A strict formatter that formats or parses a hour, minute and second, such as '09:43:25'. @@ -531,7 +537,7 @@ public class DateFormatters { .append(STRICT_HOUR_MINUTE_SECOND_FORMATTER) .appendFraction(NANO_OF_SECOND, 3, 9, true) .appendOffset("+HH:MM", "Z") - .toFormatter(Locale.ROOT); + .toFormatter(IsoLocale.ROOT); private static final DateTimeFormatter STRICT_DATE_FORMATTER = new DateTimeFormatterBuilder() .append(STRICT_YEAR_MONTH_DAY_FORMATTER) @@ -540,15 +546,16 @@ public class DateFormatters { .optionalStart() .appendFraction(NANO_OF_SECOND, 1, 9, true) .optionalEnd() - .toFormatter(Locale.ROOT); + .toFormatter(IsoLocale.ROOT); /* * Returns a formatter that combines a full date and time, separated by a 'T' * (yyyy-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(Locale.ROOT), - new DateTimeFormatterBuilder().append(STRICT_DATE_FORMATTER).append(TIME_ZONE_FORMATTER_NO_COLON).toFormatter(Locale.ROOT) + new DateTimeFormatterBuilder().append(STRICT_DATE_FORMATTER).appendZoneOrOffsetId().toFormatter(IsoLocale.ROOT), + new DateTimeFormatterBuilder().append(STRICT_DATE_FORMATTER).append(TIME_ZONE_FORMATTER_NO_COLON) + .toFormatter(IsoLocale.ROOT) ); private static final DateTimeFormatter STRICT_ORDINAL_DATE_TIME_NO_MILLIS_BASE = new DateTimeFormatterBuilder() @@ -557,7 +564,7 @@ public class DateFormatters { .appendValue(DAY_OF_YEAR, 3, 3, SignStyle.NOT_NEGATIVE) .appendLiteral('T') .append(STRICT_HOUR_MINUTE_SECOND_FORMATTER) - .toFormatter(Locale.ROOT); + .toFormatter(IsoLocale.ROOT); /* * Returns a formatter for a full ordinal date and time without millis, @@ -565,18 +572,18 @@ public class DateFormatters { */ 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(Locale.ROOT), + .appendOffset("+HH:MM", "Z").toFormatter(IsoLocale.ROOT), new DateTimeFormatterBuilder().append(STRICT_ORDINAL_DATE_TIME_NO_MILLIS_BASE) - .appendZoneOrOffsetId().toFormatter(Locale.ROOT), + .appendZoneOrOffsetId().toFormatter(IsoLocale.ROOT), new DateTimeFormatterBuilder().append(STRICT_ORDINAL_DATE_TIME_NO_MILLIS_BASE) - .append(TIME_ZONE_FORMATTER_NO_COLON).toFormatter(Locale.ROOT) + .append(TIME_ZONE_FORMATTER_NO_COLON).toFormatter(IsoLocale.ROOT) ); 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(Locale.ROOT); + .toFormatter(IsoLocale.ROOT); /* * Returns a formatter that combines a full date and time without millis, @@ -584,23 +591,23 @@ public class DateFormatters { */ 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(Locale.ROOT), + .appendOffset("+HH:MM", "Z").toFormatter(IsoLocale.ROOT), new DateTimeFormatterBuilder().append(STRICT_DATE_TIME_NO_MILLIS_FORMATTER) - .appendZoneOrOffsetId().toFormatter(Locale.ROOT), + .appendZoneOrOffsetId().toFormatter(IsoLocale.ROOT), new DateTimeFormatterBuilder().append(STRICT_DATE_TIME_NO_MILLIS_FORMATTER) - .append(TIME_ZONE_FORMATTER_NO_COLON).toFormatter(Locale.ROOT) + .append(TIME_ZONE_FORMATTER_NO_COLON).toFormatter(IsoLocale.ROOT) ); // 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(Locale.ROOT); + .toFormatter(IsoLocale.ROOT); 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(Locale.ROOT); + .toFormatter(IsoLocale.ROOT); /* * Returns a formatter for a two digit hour of day, two digit minute of @@ -629,14 +636,14 @@ public class DateFormatters { .append(STRICT_YEAR_MONTH_DAY_FORMATTER) .appendLiteral("T") .append(STRICT_HOUR_MINUTE_SECOND_MILLIS_PRINTER) - .toFormatter(Locale.ROOT), + .toFormatter(IsoLocale.ROOT), new DateTimeFormatterBuilder() .append(STRICT_YEAR_MONTH_DAY_FORMATTER) .appendLiteral("T") .append(STRICT_HOUR_MINUTE_SECOND_FORMATTER) // this one here is lenient as well to retain joda time based bwc compatibility .appendFraction(NANO_OF_SECOND, 1, 9, true) - .toFormatter(Locale.ROOT) + .toFormatter(IsoLocale.ROOT) ); private static final DateFormatter STRICT_DATE_HOUR_MINUTE_SECOND_MILLIS = new JavaDateFormatter( @@ -645,28 +652,28 @@ public class DateFormatters { .append(STRICT_YEAR_MONTH_DAY_FORMATTER) .appendLiteral("T") .append(STRICT_HOUR_MINUTE_SECOND_MILLIS_PRINTER) - .toFormatter(Locale.ROOT), + .toFormatter(IsoLocale.ROOT), new DateTimeFormatterBuilder() .append(STRICT_YEAR_MONTH_DAY_FORMATTER) .appendLiteral("T") .append(STRICT_HOUR_MINUTE_SECOND_FORMATTER) // this one here is lenient as well to retain joda time based bwc compatibility .appendFraction(NANO_OF_SECOND, 1, 9, true) - .toFormatter(Locale.ROOT) + .toFormatter(IsoLocale.ROOT) ); /* * Returns a formatter for a two digit hour of day. (HH) */ private static final DateFormatter STRICT_HOUR = - new JavaDateFormatter("strict_hour", DateTimeFormatter.ofPattern("HH", Locale.ROOT)); + new JavaDateFormatter("strict_hour", DateTimeFormatter.ofPattern("HH", IsoLocale.ROOT)); /* * Returns a formatter for a two digit hour of day and two digit minute of * hour. (HH:mm) */ private static final DateFormatter STRICT_HOUR_MINUTE = - new JavaDateFormatter("strict_hour_minute", DateTimeFormatter.ofPattern("HH:mm", Locale.ROOT)); + new JavaDateFormatter("strict_hour_minute", DateTimeFormatter.ofPattern("HH:mm", IsoLocale.ROOT)); private static final DateTimeFormatter STRICT_ORDINAL_DATE_TIME_PRINTER = new DateTimeFormatterBuilder() .appendValue(ChronoField.YEAR, 4, 10, SignStyle.EXCEEDS_PAD) @@ -679,7 +686,7 @@ public class DateFormatters { .appendValue(SECOND_OF_MINUTE, 2, 2, SignStyle.NOT_NEGATIVE) .appendFraction(NANO_OF_SECOND, 3, 9, true) .optionalEnd() - .toFormatter(Locale.ROOT); + .toFormatter(IsoLocale.ROOT); private static final DateTimeFormatter STRICT_ORDINAL_DATE_TIME_FORMATTER_BASE = new DateTimeFormatterBuilder() .appendValue(ChronoField.YEAR, 4, 10, SignStyle.EXCEEDS_PAD) @@ -692,7 +699,7 @@ public class DateFormatters { .appendValue(SECOND_OF_MINUTE, 2, 2, SignStyle.NOT_NEGATIVE) .appendFraction(NANO_OF_SECOND, 1, 9, true) .optionalEnd() - .toFormatter(Locale.ROOT); + .toFormatter(IsoLocale.ROOT); /* * Returns a formatter for a full ordinal date and time, using a four @@ -700,11 +707,11 @@ public class DateFormatters { */ 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(Locale.ROOT), + .appendOffset("+HH:MM", "Z").toFormatter(IsoLocale.ROOT), new DateTimeFormatterBuilder().append(STRICT_ORDINAL_DATE_TIME_FORMATTER_BASE) - .appendZoneOrOffsetId().toFormatter(Locale.ROOT), + .appendZoneOrOffsetId().toFormatter(IsoLocale.ROOT), new DateTimeFormatterBuilder().append(STRICT_ORDINAL_DATE_TIME_FORMATTER_BASE) - .append(TIME_ZONE_FORMATTER_NO_COLON).toFormatter(Locale.ROOT) + .append(TIME_ZONE_FORMATTER_NO_COLON).toFormatter(IsoLocale.ROOT) ); // Note: milliseconds parsing is not strict, others are @@ -715,7 +722,7 @@ public class DateFormatters { .appendLiteral(':') .appendValue(SECOND_OF_MINUTE, 2, 2, SignStyle.NOT_NEGATIVE) .appendFraction(NANO_OF_SECOND, 1, 9, true) - .toFormatter(Locale.ROOT); + .toFormatter(IsoLocale.ROOT); private static final DateTimeFormatter STRICT_TIME_PRINTER = new DateTimeFormatterBuilder() .appendValue(HOUR_OF_DAY, 2, 2, SignStyle.NOT_NEGATIVE) @@ -724,7 +731,7 @@ public class DateFormatters { .appendLiteral(':') .appendValue(SECOND_OF_MINUTE, 2, 2, SignStyle.NOT_NEGATIVE) .appendFraction(NANO_OF_SECOND, 3, 3, true) - .toFormatter(Locale.ROOT); + .toFormatter(IsoLocale.ROOT); /* * Returns a formatter for a two digit hour of day, two digit minute of @@ -732,9 +739,10 @@ 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(Locale.ROOT), - new DateTimeFormatterBuilder().append(STRICT_TIME_FORMATTER_BASE).appendZoneOrOffsetId().toFormatter(Locale.ROOT), - new DateTimeFormatterBuilder().append(STRICT_TIME_FORMATTER_BASE).append(TIME_ZONE_FORMATTER_NO_COLON).toFormatter(Locale.ROOT) + 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_FORMATTER_BASE).append(TIME_ZONE_FORMATTER_NO_COLON) + .toFormatter(IsoLocale.ROOT) ); /* @@ -743,11 +751,13 @@ public class DateFormatters { * time zone offset prefixed by 'T' ('T'HH:mm:ss.SSSZZ). */ 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(Locale.ROOT), + new DateTimeFormatterBuilder().appendLiteral('T').append(STRICT_TIME_PRINTER) + .appendOffset("+HH:MM", "Z") + .toFormatter(IsoLocale.ROOT), new DateTimeFormatterBuilder().appendLiteral('T').append(STRICT_TIME_FORMATTER_BASE) - .appendZoneOrOffsetId().toFormatter(Locale.ROOT), + .appendZoneOrOffsetId().toFormatter(IsoLocale.ROOT), new DateTimeFormatterBuilder().appendLiteral('T').append(STRICT_TIME_FORMATTER_BASE) - .append(TIME_ZONE_FORMATTER_NO_COLON).toFormatter(Locale.ROOT) + .append(TIME_ZONE_FORMATTER_NO_COLON).toFormatter(IsoLocale.ROOT) ); private static final DateTimeFormatter STRICT_TIME_NO_MILLIS_BASE = new DateTimeFormatterBuilder() @@ -756,16 +766,18 @@ public class DateFormatters { .appendValue(MINUTE_OF_HOUR, 2, 2, SignStyle.NOT_NEGATIVE) .appendLiteral(':') .appendValue(SECOND_OF_MINUTE, 2, 2, SignStyle.NOT_NEGATIVE) - .toFormatter(Locale.ROOT); + .toFormatter(IsoLocale.ROOT); /* * Returns a formatter for a two digit hour of day, two digit minute of * hour, two digit second of minute, and time zone offset (HH:mm:ssZZ). */ 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(Locale.ROOT), - new DateTimeFormatterBuilder().append(STRICT_TIME_NO_MILLIS_BASE).appendZoneOrOffsetId().toFormatter(Locale.ROOT), - new DateTimeFormatterBuilder().append(STRICT_TIME_NO_MILLIS_BASE).append(TIME_ZONE_FORMATTER_NO_COLON).toFormatter(Locale.ROOT) + 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), + new DateTimeFormatterBuilder().append(STRICT_TIME_NO_MILLIS_BASE).append(TIME_ZONE_FORMATTER_NO_COLON) + .toFormatter(IsoLocale.ROOT) ); /* @@ -775,11 +787,11 @@ 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(Locale.ROOT), + .appendOffset("+HH:MM", "Z").toFormatter(IsoLocale.ROOT), new DateTimeFormatterBuilder().appendLiteral("T").append(STRICT_TIME_NO_MILLIS_BASE) - .appendZoneOrOffsetId().toFormatter(Locale.ROOT), + .appendZoneOrOffsetId().toFormatter(IsoLocale.ROOT), new DateTimeFormatterBuilder().appendLiteral("T").append(STRICT_TIME_NO_MILLIS_BASE) - .append(TIME_ZONE_FORMATTER_NO_COLON).toFormatter(Locale.ROOT) + .append(TIME_ZONE_FORMATTER_NO_COLON).toFormatter(IsoLocale.ROOT) ); private static final DateTimeFormatter ISO_WEEK_DATE = new DateTimeFormatterBuilder() @@ -789,12 +801,12 @@ public class DateFormatters { .appendValue(IsoFields.WEEK_OF_WEEK_BASED_YEAR, 2) .appendLiteral('-') .appendValue(DAY_OF_WEEK, 1) - .toFormatter(Locale.ROOT); + .toFormatter(IsoLocale.ROOT); private static final DateTimeFormatter ISO_WEEK_DATE_T = new DateTimeFormatterBuilder() .append(ISO_WEEK_DATE) .appendLiteral('T') - .toFormatter(Locale.ROOT); + .toFormatter(IsoLocale.ROOT); /* * Returns a formatter for a full date as four digit weekyear, two digit @@ -808,11 +820,11 @@ 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(Locale.ROOT), + .append(STRICT_TIME_NO_MILLIS_BASE).appendOffset("+HH:MM", "Z").toFormatter(IsoLocale.ROOT), new DateTimeFormatterBuilder().append(ISO_WEEK_DATE_T) - .append(STRICT_TIME_NO_MILLIS_BASE).appendZoneOrOffsetId().toFormatter(Locale.ROOT), + .append(STRICT_TIME_NO_MILLIS_BASE).appendZoneOrOffsetId().toFormatter(IsoLocale.ROOT), new DateTimeFormatterBuilder().append(ISO_WEEK_DATE_T) - .append(STRICT_TIME_NO_MILLIS_BASE).append(TIME_ZONE_FORMATTER_NO_COLON).toFormatter(Locale.ROOT) + .append(STRICT_TIME_NO_MILLIS_BASE).append(TIME_ZONE_FORMATTER_NO_COLON).toFormatter(IsoLocale.ROOT) ); /* @@ -821,11 +833,11 @@ 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(Locale.ROOT), + .append(STRICT_TIME_PRINTER).appendOffset("+HH:MM", "Z").toFormatter(IsoLocale.ROOT), new DateTimeFormatterBuilder().append(ISO_WEEK_DATE_T).append(STRICT_TIME_FORMATTER_BASE) - .appendZoneOrOffsetId().toFormatter(Locale.ROOT), + .appendZoneOrOffsetId().toFormatter(IsoLocale.ROOT), new DateTimeFormatterBuilder().append(ISO_WEEK_DATE_T).append(STRICT_TIME_FORMATTER_BASE) - .append(TIME_ZONE_FORMATTER_NO_COLON).toFormatter(Locale.ROOT) + .append(TIME_ZONE_FORMATTER_NO_COLON).toFormatter(IsoLocale.ROOT) ); /* @@ -833,13 +845,13 @@ 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(Locale.ROOT)); + .toFormatter(IsoLocale.ROOT)); 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(Locale.ROOT); + .toFormatter(IsoLocale.ROOT); /* * Returns a formatter for a four digit weekyear and two digit week of @@ -857,7 +869,7 @@ public class DateFormatters { .append(STRICT_WEEKYEAR_WEEK_FORMATTER) .appendLiteral("-") .appendValue(WeekFields.ISO.dayOfWeek()) - .toFormatter(Locale.ROOT)); + .toFormatter(IsoLocale.ROOT)); /* * Returns a formatter that combines a full date, two digit hour of day, @@ -865,7 +877,7 @@ public class DateFormatters { * minute. (yyyy-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", Locale.ROOT)); + DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss", IsoLocale.ROOT)); /* * A basic formatter for a full date as four digit year, two digit @@ -876,12 +888,12 @@ public class DateFormatters { .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(Locale.ROOT).withZone(ZoneOffset.UTC), + .toFormatter(IsoLocale.ROOT).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(Locale.ROOT).withZone(ZoneOffset.UTC) + .toFormatter(IsoLocale.ROOT).withZone(ZoneOffset.UTC) ); private static final DateTimeFormatter STRICT_ORDINAL_DATE_FORMATTER = new DateTimeFormatterBuilder() @@ -890,7 +902,7 @@ public class DateFormatters { .appendLiteral('-') .appendValue(DAY_OF_YEAR, 3) .optionalStart() - .toFormatter(Locale.ROOT); + .toFormatter(IsoLocale.ROOT); /* * Returns a formatter for a full ordinal date, using a four @@ -918,13 +930,13 @@ public class DateFormatters { .appendLiteral('-') .appendValue(DAY_OF_MONTH, 1, 2, SignStyle.NOT_NEGATIVE) .optionalEnd() - .toFormatter(Locale.ROOT); + .toFormatter(IsoLocale.ROOT); 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(Locale.ROOT); + .toFormatter(IsoLocale.ROOT); /* * a date formatter with optional time, being very lenient, format is @@ -957,13 +969,13 @@ public class DateFormatters { .optionalEnd() .optionalEnd() .optionalEnd() - .toFormatter(Locale.ROOT)); + .toFormatter(IsoLocale.ROOT)); 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(Locale.ROOT); + .toFormatter(IsoLocale.ROOT); private static final DateTimeFormatter HOUR_MINUTE_SECOND_MILLIS_FORMATTER = new DateTimeFormatterBuilder() .appendValue(HOUR_OF_DAY, 1, 2, SignStyle.NOT_NEGATIVE) @@ -972,7 +984,7 @@ public class DateFormatters { .appendLiteral(':') .appendValue(SECOND_OF_MINUTE, 1, 2, SignStyle.NOT_NEGATIVE) .appendFraction(NANO_OF_SECOND, 1, 3, true) - .toFormatter(Locale.ROOT); + .toFormatter(IsoLocale.ROOT); private static final DateTimeFormatter HOUR_MINUTE_SECOND_FRACTION_FORMATTER = new DateTimeFormatterBuilder() .appendValue(HOUR_OF_DAY, 1, 2, SignStyle.NOT_NEGATIVE) @@ -981,19 +993,19 @@ public class DateFormatters { .appendLiteral(':') .appendValue(SECOND_OF_MINUTE, 1, 2, SignStyle.NOT_NEGATIVE) .appendFraction(NANO_OF_SECOND, 1, 9, true) - .toFormatter(Locale.ROOT); + .toFormatter(IsoLocale.ROOT); 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(Locale.ROOT); + .toFormatter(IsoLocale.ROOT); 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(Locale.ROOT); + .toFormatter(IsoLocale.ROOT); /* * Returns a formatter for a full ordinal date, using a four @@ -1008,15 +1020,15 @@ public class DateFormatters { .appendValue(MINUTE_OF_HOUR, 1, 2, SignStyle.NOT_NEGATIVE) .appendLiteral(':') .appendValue(SECOND_OF_MINUTE, 1, 2, SignStyle.NOT_NEGATIVE) - .toFormatter(Locale.ROOT); + .toFormatter(IsoLocale.ROOT); private static final DateTimeFormatter T_TIME_NO_MILLIS_FORMATTER = - new DateTimeFormatterBuilder().appendLiteral("T").append(TIME_NO_MILLIS_FORMATTER).toFormatter(Locale.ROOT); + new DateTimeFormatterBuilder().appendLiteral("T").append(TIME_NO_MILLIS_FORMATTER).toFormatter(IsoLocale.ROOT); private static final DateTimeFormatter TIME_PREFIX = new DateTimeFormatterBuilder() .append(TIME_NO_MILLIS_FORMATTER) .appendFraction(NANO_OF_SECOND, 1, 9, true) - .toFormatter(Locale.ROOT); + .toFormatter(IsoLocale.ROOT); private static final DateTimeFormatter WEEK_DATE_FORMATTER = new DateTimeFormatterBuilder() .appendValue(IsoFields.WEEK_BASED_YEAR, 4, 10, SignStyle.EXCEEDS_PAD) @@ -1024,31 +1036,31 @@ public class DateFormatters { .appendValue(IsoFields.WEEK_OF_WEEK_BASED_YEAR, 1, 2, SignStyle.NOT_NEGATIVE) .appendLiteral('-') .appendValue(DAY_OF_WEEK, 1) - .toFormatter(Locale.ROOT); + .toFormatter(IsoLocale.ROOT); /* * 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(Locale.ROOT)); + new DateTimeFormatterBuilder().appendValue(WeekFields.ISO.weekBasedYear()).toFormatter(IsoLocale.ROOT)); /* * Returns a formatter for a four digit weekyear. (uuuu) */ private static final DateFormatter YEAR = new JavaDateFormatter("year", - new DateTimeFormatterBuilder().appendValue(ChronoField.YEAR).toFormatter(Locale.ROOT)); + new DateTimeFormatterBuilder().appendValue(ChronoField.YEAR).toFormatter(IsoLocale.ROOT)); /* * Returns a formatter that combines a full date and two digit hour of * day. (yyyy-MM-dd'T'HH) */ private static final DateFormatter DATE_HOUR = new JavaDateFormatter("date_hour", - DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH", Locale.ROOT), + DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH", IsoLocale.ROOT), new DateTimeFormatterBuilder() .append(DATE_FORMATTER) .appendLiteral("T") .appendValue(HOUR_OF_DAY, 1, 2, SignStyle.NOT_NEGATIVE) - .toFormatter(Locale.ROOT)); + .toFormatter(IsoLocale.ROOT)); /* * Returns a formatter that combines a full date, two digit hour of day, @@ -1061,12 +1073,12 @@ public class DateFormatters { .append(STRICT_YEAR_MONTH_DAY_FORMATTER) .appendLiteral("T") .append(STRICT_HOUR_MINUTE_SECOND_MILLIS_PRINTER) - .toFormatter(Locale.ROOT), + .toFormatter(IsoLocale.ROOT), new DateTimeFormatterBuilder() .append(DATE_FORMATTER) .appendLiteral("T") .append(HOUR_MINUTE_SECOND_MILLIS_FORMATTER) - .toFormatter(Locale.ROOT)); + .toFormatter(IsoLocale.ROOT)); private static final DateFormatter DATE_HOUR_MINUTE_SECOND_FRACTION = new JavaDateFormatter("date_hour_minute_second_fraction", @@ -1074,24 +1086,24 @@ public class DateFormatters { .append(STRICT_YEAR_MONTH_DAY_FORMATTER) .appendLiteral("T") .append(STRICT_HOUR_MINUTE_SECOND_MILLIS_PRINTER) - .toFormatter(Locale.ROOT), + .toFormatter(IsoLocale.ROOT), new DateTimeFormatterBuilder() .append(DATE_FORMATTER) .appendLiteral("T") .append(HOUR_MINUTE_SECOND_FRACTION_FORMATTER) - .toFormatter(Locale.ROOT)); + .toFormatter(IsoLocale.ROOT)); /* * 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) */ private static final DateFormatter DATE_HOUR_MINUTE = new JavaDateFormatter("date_hour_minute", - DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm", Locale.ROOT), + DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm", IsoLocale.ROOT), new DateTimeFormatterBuilder() .append(DATE_FORMATTER) .appendLiteral("T") .append(HOUR_MINUTE_FORMATTER) - .toFormatter(Locale.ROOT)); + .toFormatter(IsoLocale.ROOT)); /* * Returns a formatter that combines a full date, two digit hour of day, @@ -1099,12 +1111,12 @@ public class DateFormatters { * minute. (yyyy-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", Locale.ROOT), + DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss", IsoLocale.ROOT), new DateTimeFormatterBuilder() .append(DATE_FORMATTER) .appendLiteral("T") .append(HOUR_MINUTE_SECOND_FORMATTER) - .toFormatter(Locale.ROOT)); + .toFormatter(IsoLocale.ROOT)); private static final DateTimeFormatter DATE_TIME_FORMATTER = new DateTimeFormatterBuilder() .append(DATE_FORMATTER) @@ -1115,7 +1127,7 @@ public class DateFormatters { .appendValue(SECOND_OF_MINUTE, 1, 2, SignStyle.NOT_NEGATIVE) .appendFraction(NANO_OF_SECOND, 1, 9, true) .optionalEnd() - .toFormatter(Locale.ROOT); + .toFormatter(IsoLocale.ROOT); /* * Returns a formatter that combines a full date and time, separated by a 'T' @@ -1123,8 +1135,10 @@ public class DateFormatters { */ 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(Locale.ROOT), - new DateTimeFormatterBuilder().append(DATE_TIME_FORMATTER).append(TIME_ZONE_FORMATTER_NO_COLON).toFormatter(Locale.ROOT) + new DateTimeFormatterBuilder().append(DATE_TIME_FORMATTER).appendOffset("+HH:MM", "Z") + .toFormatter(IsoLocale.ROOT), + new DateTimeFormatterBuilder().append(DATE_TIME_FORMATTER).append(TIME_ZONE_FORMATTER_NO_COLON) + .toFormatter(IsoLocale.ROOT) ); /* @@ -1150,7 +1164,7 @@ public class DateFormatters { .appendLiteral(':') .appendValue(SECOND_OF_MINUTE, 2, 2, SignStyle.NOT_NEGATIVE) .appendZoneId() - .toFormatter(Locale.ROOT); + .toFormatter(IsoLocale.ROOT); private static final DateTimeFormatter DATE_TIME_PREFIX = new DateTimeFormatterBuilder() .append(DATE_FORMATTER) @@ -1160,7 +1174,7 @@ public class DateFormatters { .appendLiteral(':') .appendValue(SECOND_OF_MINUTE, 1, 2, SignStyle.NOT_NEGATIVE) .optionalEnd() - .toFormatter(Locale.ROOT); + .toFormatter(IsoLocale.ROOT); /* * Returns a formatter that combines a full date and time without millis, but with a timezone that can be optional @@ -1168,12 +1182,13 @@ public class DateFormatters { */ 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(Locale.ROOT), - new DateTimeFormatterBuilder().append(DATE_TIME_PREFIX).append(TIME_ZONE_FORMATTER_NO_COLON).toFormatter(Locale.ROOT), + new DateTimeFormatterBuilder().append(DATE_TIME_PREFIX).appendOffset("+HH:MM", "Z").toFormatter(IsoLocale.ROOT), + new DateTimeFormatterBuilder().append(DATE_TIME_PREFIX).append(TIME_ZONE_FORMATTER_NO_COLON) + .toFormatter(IsoLocale.ROOT), new DateTimeFormatterBuilder().append(DATE_TIME_PREFIX) - .optionalStart().appendZoneOrOffsetId().optionalEnd().toFormatter(Locale.ROOT), + .optionalStart().appendZoneOrOffsetId().optionalEnd().toFormatter(IsoLocale.ROOT), new DateTimeFormatterBuilder().append(DATE_TIME_PREFIX) - .optionalStart().append(TIME_ZONE_FORMATTER_NO_COLON).optionalEnd().toFormatter(Locale.ROOT) + .optionalStart().append(TIME_ZONE_FORMATTER_NO_COLON).optionalEnd().toFormatter(IsoLocale.ROOT) ); /* @@ -1192,7 +1207,7 @@ public class DateFormatters { * hour. (HH:mm) */ private static final DateFormatter HOUR_MINUTE = - new JavaDateFormatter("hour_minute", DateTimeFormatter.ofPattern("HH:mm", Locale.ROOT), HOUR_MINUTE_FORMATTER); + new JavaDateFormatter("hour_minute", DateTimeFormatter.ofPattern("HH:mm", IsoLocale.ROOT), HOUR_MINUTE_FORMATTER); /* * A strict formatter that formats or parses a hour, minute and second, such as '09:43:25'. @@ -1203,15 +1218,15 @@ public class DateFormatters { .append(HOUR_MINUTE_FORMATTER) .appendLiteral(":") .appendValue(SECOND_OF_MINUTE, 1, 2, SignStyle.NOT_NEGATIVE) - .toFormatter(Locale.ROOT) + .toFormatter(IsoLocale.ROOT) ); /* * Returns a formatter for a two digit hour of day. (HH) */ private static final DateFormatter HOUR = new JavaDateFormatter("hour", - DateTimeFormatter.ofPattern("HH", Locale.ROOT), - new DateTimeFormatterBuilder().appendValue(HOUR_OF_DAY, 1, 2, SignStyle.NOT_NEGATIVE).toFormatter(Locale.ROOT) + DateTimeFormatter.ofPattern("HH", IsoLocale.ROOT), + new DateTimeFormatterBuilder().appendValue(HOUR_OF_DAY, 1, 2, SignStyle.NOT_NEGATIVE).toFormatter(IsoLocale.ROOT) ); private static final DateTimeFormatter ORDINAL_DATE_TIME_FORMATTER_BASE = new DateTimeFormatterBuilder() @@ -1223,7 +1238,7 @@ public class DateFormatters { .appendValue(SECOND_OF_MINUTE, 1, 2, SignStyle.NOT_NEGATIVE) .appendFraction(NANO_OF_SECOND, 1, 9, true) .optionalEnd() - .toFormatter(Locale.ROOT); + .toFormatter(IsoLocale.ROOT); /* * Returns a formatter for a full ordinal date and time, using a four @@ -1231,18 +1246,18 @@ public class DateFormatters { */ 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(Locale.ROOT), + .appendOffset("+HH:MM", "Z").toFormatter(IsoLocale.ROOT), new DateTimeFormatterBuilder().append(ORDINAL_DATE_TIME_FORMATTER_BASE) - .appendZoneOrOffsetId().toFormatter(Locale.ROOT), + .appendZoneOrOffsetId().toFormatter(IsoLocale.ROOT), new DateTimeFormatterBuilder().append(ORDINAL_DATE_TIME_FORMATTER_BASE) - .append(TIME_ZONE_FORMATTER_NO_COLON).toFormatter(Locale.ROOT) + .append(TIME_ZONE_FORMATTER_NO_COLON).toFormatter(IsoLocale.ROOT) ); private static final DateTimeFormatter ORDINAL_DATE_TIME_NO_MILLIS_BASE = new DateTimeFormatterBuilder() .append(ORDINAL_DATE_FORMATTER) .appendLiteral('T') .append(HOUR_MINUTE_SECOND_FORMATTER) - .toFormatter(Locale.ROOT); + .toFormatter(IsoLocale.ROOT); /* * Returns a formatter for a full ordinal date and time without millis, @@ -1250,11 +1265,11 @@ public class DateFormatters { */ 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(Locale.ROOT), + .appendOffset("+HH:MM", "Z").toFormatter(IsoLocale.ROOT), new DateTimeFormatterBuilder().append(ORDINAL_DATE_TIME_NO_MILLIS_BASE) - .appendZoneOrOffsetId().toFormatter(Locale.ROOT), + .appendZoneOrOffsetId().toFormatter(IsoLocale.ROOT), new DateTimeFormatterBuilder().append(ORDINAL_DATE_TIME_NO_MILLIS_BASE) - .append(TIME_ZONE_FORMATTER_NO_COLON).toFormatter(Locale.ROOT) + .append(TIME_ZONE_FORMATTER_NO_COLON).toFormatter(IsoLocale.ROOT) ); /* @@ -1263,11 +1278,11 @@ 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(Locale.ROOT), + .append(STRICT_TIME_PRINTER).appendOffset("+HH:MM", "Z").toFormatter(IsoLocale.ROOT), new DateTimeFormatterBuilder().append(WEEK_DATE_FORMATTER).appendLiteral("T").append(TIME_PREFIX) - .appendZoneOrOffsetId().toFormatter(Locale.ROOT), + .appendZoneOrOffsetId().toFormatter(IsoLocale.ROOT), new DateTimeFormatterBuilder().append(WEEK_DATE_FORMATTER).appendLiteral("T").append(TIME_PREFIX) - .append(TIME_ZONE_FORMATTER_NO_COLON).toFormatter(Locale.ROOT) + .append(TIME_ZONE_FORMATTER_NO_COLON).toFormatter(IsoLocale.ROOT) ); /* @@ -1276,11 +1291,11 @@ 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(Locale.ROOT), + .append(STRICT_TIME_NO_MILLIS_BASE).appendOffset("+HH:MM", "Z").toFormatter(IsoLocale.ROOT), new DateTimeFormatterBuilder().append(WEEK_DATE_FORMATTER).append(T_TIME_NO_MILLIS_FORMATTER) - .appendZoneOrOffsetId().toFormatter(Locale.ROOT), + .appendZoneOrOffsetId().toFormatter(IsoLocale.ROOT), new DateTimeFormatterBuilder().append(WEEK_DATE_FORMATTER).append(T_TIME_NO_MILLIS_FORMATTER) - .append(TIME_ZONE_FORMATTER_NO_COLON).toFormatter(Locale.ROOT) + .append(TIME_ZONE_FORMATTER_NO_COLON).toFormatter(IsoLocale.ROOT) ); /* @@ -1290,12 +1305,12 @@ public class DateFormatters { private static final DateFormatter BASIC_WEEK_DATE_TIME = new JavaDateFormatter("basic_week_date_time", new DateTimeFormatterBuilder() .append(STRICT_BASIC_WEEK_DATE_PRINTER) - .append(DateTimeFormatter.ofPattern("'T'HHmmss.SSSX", Locale.ROOT)) - .toFormatter(Locale.ROOT), + .append(DateTimeFormatter.ofPattern("'T'HHmmss.SSSX", IsoLocale.ROOT)) + .toFormatter(IsoLocale.ROOT), new DateTimeFormatterBuilder().append(BASIC_WEEK_DATE_FORMATTER).append(BASIC_T_TIME_FORMATTER) - .appendZoneOrOffsetId().toFormatter(Locale.ROOT), + .appendZoneOrOffsetId().toFormatter(IsoLocale.ROOT), new DateTimeFormatterBuilder().append(BASIC_WEEK_DATE_FORMATTER).append(BASIC_T_TIME_FORMATTER) - .append(TIME_ZONE_FORMATTER_NO_COLON).toFormatter(Locale.ROOT) + .append(TIME_ZONE_FORMATTER_NO_COLON).toFormatter(IsoLocale.ROOT) ); /* @@ -1304,12 +1319,12 @@ 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", Locale.ROOT)) - .toFormatter(Locale.ROOT), + .append(STRICT_BASIC_WEEK_DATE_PRINTER).append(DateTimeFormatter.ofPattern("'T'HHmmssX", IsoLocale.ROOT)) + .toFormatter(IsoLocale.ROOT), new DateTimeFormatterBuilder().append(BASIC_WEEK_DATE_FORMATTER).appendLiteral("T").append(BASIC_TIME_NO_MILLIS_BASE) - .appendZoneOrOffsetId().toFormatter(Locale.ROOT), + .appendZoneOrOffsetId().toFormatter(IsoLocale.ROOT), new DateTimeFormatterBuilder().append(BASIC_WEEK_DATE_FORMATTER).appendLiteral("T").append(BASIC_TIME_NO_MILLIS_BASE) - .append(TIME_ZONE_FORMATTER_NO_COLON).toFormatter(Locale.ROOT) + .append(TIME_ZONE_FORMATTER_NO_COLON).toFormatter(IsoLocale.ROOT) ); /* @@ -1318,9 +1333,9 @@ 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(Locale.ROOT), - new DateTimeFormatterBuilder().append(TIME_PREFIX).appendZoneOrOffsetId().toFormatter(Locale.ROOT), - new DateTimeFormatterBuilder().append(TIME_PREFIX).append(TIME_ZONE_FORMATTER_NO_COLON).toFormatter(Locale.ROOT) + 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(TIME_PREFIX).append(TIME_ZONE_FORMATTER_NO_COLON).toFormatter(IsoLocale.ROOT) ); /* @@ -1328,9 +1343,11 @@ public class DateFormatters { * hour, two digit second of minute, andtime zone offset (HH:mm:ssZZ). */ 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(Locale.ROOT), - new DateTimeFormatterBuilder().append(TIME_NO_MILLIS_FORMATTER).appendZoneOrOffsetId().toFormatter(Locale.ROOT), - new DateTimeFormatterBuilder().append(TIME_NO_MILLIS_FORMATTER).append(TIME_ZONE_FORMATTER_NO_COLON).toFormatter(Locale.ROOT) + 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), + new DateTimeFormatterBuilder().append(TIME_NO_MILLIS_FORMATTER).append(TIME_ZONE_FORMATTER_NO_COLON) + .toFormatter(IsoLocale.ROOT) ); /* @@ -1339,11 +1356,12 @@ public class DateFormatters { * time zone offset prefixed by 'T' ('T'HH:mm:ss.SSSZZ). */ private static final DateFormatter T_TIME = new JavaDateFormatter("t_time", - new DateTimeFormatterBuilder().appendLiteral('T').append(STRICT_TIME_PRINTER).appendOffset("+HH:MM", "Z").toFormatter(Locale.ROOT), + new DateTimeFormatterBuilder().appendLiteral('T').append(STRICT_TIME_PRINTER).appendOffset("+HH:MM", "Z") + .toFormatter(IsoLocale.ROOT), new DateTimeFormatterBuilder().appendLiteral("T").append(TIME_PREFIX) - .appendZoneOrOffsetId().toFormatter(Locale.ROOT), + .appendZoneOrOffsetId().toFormatter(IsoLocale.ROOT), new DateTimeFormatterBuilder().appendLiteral("T").append(TIME_PREFIX) - .append(TIME_ZONE_FORMATTER_NO_COLON).toFormatter(Locale.ROOT) + .append(TIME_ZONE_FORMATTER_NO_COLON).toFormatter(IsoLocale.ROOT) ); /* @@ -1353,9 +1371,10 @@ 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(Locale.ROOT), - new DateTimeFormatterBuilder().append(T_TIME_NO_MILLIS_FORMATTER).appendZoneOrOffsetId().toFormatter(Locale.ROOT), - new DateTimeFormatterBuilder().append(T_TIME_NO_MILLIS_FORMATTER).append(TIME_ZONE_FORMATTER_NO_COLON).toFormatter(Locale.ROOT) + .appendOffset("+HH:MM", "Z").toFormatter(IsoLocale.ROOT), + new DateTimeFormatterBuilder().append(T_TIME_NO_MILLIS_FORMATTER).appendZoneOrOffsetId().toFormatter(IsoLocale.ROOT), + new DateTimeFormatterBuilder().append(T_TIME_NO_MILLIS_FORMATTER).append(TIME_ZONE_FORMATTER_NO_COLON) + .toFormatter(IsoLocale.ROOT) ); /* @@ -1366,8 +1385,9 @@ public class DateFormatters { .appendValue(ChronoField.YEAR, 4, 10, SignStyle.EXCEEDS_PAD) .appendLiteral("-") .appendValue(MONTH_OF_YEAR, 2, 2, SignStyle.NOT_NEGATIVE) - .toFormatter(Locale.ROOT), - new DateTimeFormatterBuilder().appendValue(ChronoField.YEAR).appendLiteral("-").appendValue(MONTH_OF_YEAR).toFormatter(Locale.ROOT) + .toFormatter(IsoLocale.ROOT), + new DateTimeFormatterBuilder().appendValue(ChronoField.YEAR).appendLiteral("-").appendValue(MONTH_OF_YEAR) + .toFormatter(IsoLocale.ROOT) ); /* @@ -1381,7 +1401,7 @@ public class DateFormatters { .appendValue(MONTH_OF_YEAR) .appendLiteral("-") .appendValue(DAY_OF_MONTH) - .toFormatter(Locale.ROOT) + .toFormatter(IsoLocale.ROOT) ); /* @@ -1399,7 +1419,7 @@ public class DateFormatters { .appendValue(WeekFields.ISO.weekBasedYear()) .appendLiteral("-W") .appendValue(WeekFields.ISO.weekOfWeekBasedYear()) - .toFormatter(Locale.ROOT) + .toFormatter(IsoLocale.ROOT) ); /* @@ -1411,15 +1431,16 @@ public class DateFormatters { .append(STRICT_WEEKYEAR_WEEK_FORMATTER) .appendLiteral("-") .appendValue(WeekFields.ISO.dayOfWeek()) - .toFormatter(Locale.ROOT), + .toFormatter(IsoLocale.ROOT), new DateTimeFormatterBuilder() .appendValue(WeekFields.ISO.weekBasedYear()) .appendLiteral("-W") .appendValue(WeekFields.ISO.weekOfWeekBasedYear()) .appendLiteral("-") .appendValue(WeekFields.ISO.dayOfWeek()) - .toFormatter(Locale.ROOT) + .toFormatter(IsoLocale.ROOT) ); + ///////////////////////////////////////// // @@ -1598,7 +1619,9 @@ static DateFormatter forPattern(String input) { return STRICT_YEAR_MONTH_DAY; } else { try { - return new JavaDateFormatter(input, new DateTimeFormatterBuilder().appendPattern(input).toFormatter(Locale.ROOT)); + return new JavaDateFormatter(input, new DateTimeFormatterBuilder() + .appendPattern(input) + .toFormatter(IsoLocale.ROOT)); } catch (IllegalArgumentException e) { throw new IllegalArgumentException("Invalid format: [" + input + "]: " + e.getMessage(), e); } @@ -1620,7 +1643,7 @@ static JavaDateFormatter merge(String pattern, List formatters) { dateTimeFormatters.addAll(javaDateFormatter.getParsers()); roundupBuilder.appendOptional(javaDateFormatter.getRoundupParser()); } - DateTimeFormatter roundUpParser = roundupBuilder.toFormatter(Locale.ROOT); + DateTimeFormatter roundUpParser = roundupBuilder.toFormatter(IsoLocale.ROOT); return new JavaDateFormatter(pattern, printer, builder -> builder.append(roundUpParser), dateTimeFormatters.toArray(new DateTimeFormatter[0])); diff --git a/server/src/main/java/org/elasticsearch/common/time/EpochTime.java b/server/src/main/java/org/elasticsearch/common/time/EpochTime.java index 22b29bd0edf45..5875e8572aebb 100644 --- a/server/src/main/java/org/elasticsearch/common/time/EpochTime.java +++ b/server/src/main/java/org/elasticsearch/common/time/EpochTime.java @@ -125,13 +125,13 @@ public long getFrom(TemporalAccessor temporal) { .optionalStart() // optional is used so isSupported will be called when printing .appendFraction(NANOS_OF_SECOND, 0, 9, true) .optionalEnd() - .toFormatter(Locale.ROOT); + .toFormatter(IsoLocale.ROOT); // this supports seconds ending in dot private static final DateTimeFormatter SECONDS_FORMATTER2 = new DateTimeFormatterBuilder() .appendValue(SECONDS, 1, 19, SignStyle.NORMAL) .appendLiteral('.') - .toFormatter(Locale.ROOT); + .toFormatter(IsoLocale.ROOT); // this supports milliseconds without any fraction private static final DateTimeFormatter MILLISECONDS_FORMATTER1 = new DateTimeFormatterBuilder() @@ -139,13 +139,13 @@ public long getFrom(TemporalAccessor temporal) { .optionalStart() .appendFraction(NANOS_OF_MILLI, 0, 6, true) .optionalEnd() - .toFormatter(Locale.ROOT); + .toFormatter(IsoLocale.ROOT); // this supports milliseconds ending in dot private static final DateTimeFormatter MILLISECONDS_FORMATTER2 = new DateTimeFormatterBuilder() .append(MILLISECONDS_FORMATTER1) .appendLiteral('.') - .toFormatter(Locale.ROOT); + .toFormatter(IsoLocale.ROOT); static final DateFormatter SECONDS_FORMATTER = new JavaDateFormatter("epoch_second", SECONDS_FORMATTER1, builder -> builder.parseDefaulting(ChronoField.NANO_OF_SECOND, 999_999_999L), diff --git a/server/src/main/java/org/elasticsearch/index/mapper/DateFieldMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/DateFieldMapper.java index dbdafa6330790..c29fd4c112c19 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/DateFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/DateFieldMapper.java @@ -43,6 +43,7 @@ import org.elasticsearch.common.time.DateFormatters; import org.elasticsearch.common.time.DateMathParser; import org.elasticsearch.common.time.DateUtils; +import org.elasticsearch.common.time.IsoLocale; import org.elasticsearch.common.util.LocaleUtils; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.support.XContentMapValues; @@ -135,7 +136,7 @@ public static class Builder extends FieldMapper.Builder { private Boolean coerce; - private Locale locale = Locale.ROOT; + private Locale locale = IsoLocale.ROOT; private String pattern; public Builder(String name, RangeType type) { @@ -413,7 +414,7 @@ && fieldType().dateTimeFormatter().pattern().equals(DateFieldMapper.DEFAULT_DATE } if (fieldType().rangeType == RangeType.DATE && (includeDefaults || (fieldType().dateTimeFormatter() != null - && fieldType().dateTimeFormatter().locale() != Locale.ROOT))) { + && fieldType().dateTimeFormatter().locale() != IsoLocale.ROOT))) { builder.field("locale", fieldType().dateTimeFormatter().locale()); } if (includeDefaults || coerce.explicit()) { 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 9b14d0ec423ee..99121fdc835d3 100644 --- a/server/src/test/java/org/elasticsearch/common/joda/JavaJodaTimeDuellingTests.java +++ b/server/src/test/java/org/elasticsearch/common/joda/JavaJodaTimeDuellingTests.java @@ -27,6 +27,7 @@ import org.joda.time.DateTimeZone; import org.joda.time.format.ISODateTimeFormat; +import java.time.LocalDateTime; import java.time.ZoneOffset; import java.time.ZonedDateTime; import java.time.format.DateTimeFormatter; @@ -35,8 +36,31 @@ import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.is; +import static org.hamcrest.core.IsEqual.equalTo; public class JavaJodaTimeDuellingTests extends ESTestCase { + @Override + protected boolean enableWarningsCheck() { + return false; + } + + public void testDayOfWeek() { + //7 (ok joda) vs 1 (java by default) but 7 with customized org.elasticsearch.common.time.IsoLocale.ISO8601 + ZonedDateTime now = LocalDateTime.of(2009,11,15,1,32,8,328402) + .atZone(ZoneOffset.UTC); //Sunday + DateFormatter jodaFormatter = Joda.forPattern("e").withLocale(Locale.ROOT).withZone(ZoneOffset.UTC); + DateFormatter javaFormatter = DateFormatter.forPattern("8e").withZone(ZoneOffset.UTC); + assertThat(jodaFormatter.format(now), equalTo(javaFormatter.format(now))); + } + + public void testStartOfWeek() { + //2019-21 (ok joda) vs 2019-22 (java by default) but 2019-21 with customized org.elasticsearch.common.time.IsoLocale.ISO8601 + ZonedDateTime now = LocalDateTime.of(2019,5,26,1,32,8,328402) + .atZone(ZoneOffset.UTC); + DateFormatter jodaFormatter = Joda.forPattern("xxxx-ww").withLocale(Locale.ROOT).withZone(ZoneOffset.UTC); + DateFormatter javaFormatter = DateFormatter.forPattern("8YYYY-ww").withZone(ZoneOffset.UTC); + assertThat(jodaFormatter.format(now), equalTo(javaFormatter.format(now))); + } //these parsers should allow both ',' and '.' as a decimal point public void testDecimalPointParsing(){ diff --git a/server/src/test/java/org/elasticsearch/common/time/DateFormattersTests.java b/server/src/test/java/org/elasticsearch/common/time/DateFormattersTests.java index 8f2a661664304..1f18fb1655d44 100644 --- a/server/src/test/java/org/elasticsearch/common/time/DateFormattersTests.java +++ b/server/src/test/java/org/elasticsearch/common/time/DateFormattersTests.java @@ -116,7 +116,7 @@ public void testParsersWithMultipleInternalFormats() throws Exception { } public void testLocales() { - assertThat(DateFormatters.forPattern("strict_date_optional_time").locale(), is(Locale.ROOT)); + assertThat(DateFormatters.forPattern("strict_date_optional_time").locale(), is(IsoLocale.ROOT)); Locale locale = randomLocale(random()); assertThat(DateFormatters.forPattern("strict_date_optional_time").withLocale(locale).locale(), is(locale)); } diff --git a/x-pack/plugin/sql/sql-proto/src/main/java/org/elasticsearch/xpack/sql/proto/StringUtils.java b/x-pack/plugin/sql/sql-proto/src/main/java/org/elasticsearch/xpack/sql/proto/StringUtils.java index bd90354e5f98c..b7624ad7eee81 100644 --- a/x-pack/plugin/sql/sql-proto/src/main/java/org/elasticsearch/xpack/sql/proto/StringUtils.java +++ b/x-pack/plugin/sql/sql-proto/src/main/java/org/elasticsearch/xpack/sql/proto/StringUtils.java @@ -6,6 +6,8 @@ package org.elasticsearch.xpack.sql.proto; +import org.elasticsearch.common.time.IsoLocale; + import java.sql.Timestamp; import java.time.Duration; import java.time.OffsetTime; @@ -13,7 +15,6 @@ import java.time.ZonedDateTime; import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatterBuilder; -import java.util.Locale; import java.util.Objects; import java.util.concurrent.TimeUnit; @@ -24,7 +25,6 @@ import static java.time.temporal.ChronoField.SECOND_OF_MINUTE; public final class StringUtils { - public static final String EMPTY = ""; public static final DateTimeFormatter ISO_DATE_WITH_MILLIS = new DateTimeFormatterBuilder() @@ -38,7 +38,7 @@ public final class StringUtils { .appendValue(SECOND_OF_MINUTE, 2) .appendFraction(MILLI_OF_SECOND, 3, 3, true) .appendOffsetId() - .toFormatter(Locale.ROOT); + .toFormatter(IsoLocale.ROOT); public static final DateTimeFormatter ISO_TIME_WITH_MILLIS = new DateTimeFormatterBuilder() .parseCaseInsensitive() @@ -49,7 +49,7 @@ public final class StringUtils { .appendValue(SECOND_OF_MINUTE, 2) .appendFraction(MILLI_OF_SECOND, 3, 3, true) .appendOffsetId() - .toFormatter(Locale.ROOT); + .toFormatter(IsoLocale.ROOT); private static final int SECONDS_PER_MINUTE = 60; private static final int SECONDS_PER_HOUR = SECONDS_PER_MINUTE * 60;