From 8c90164c1bce98d97a19f2499ff9d0867d051bd1 Mon Sep 17 00:00:00 2001 From: Przemyslaw Gomulka Date: Thu, 17 Oct 2019 16:53:58 +0200 Subject: [PATCH 01/15] Revert "Set start of the week to Monday for root locale (#43652)" This reverts commit 8d1ea8651976c40100df65cd58f26cb00325de96. --- .../elasticsearch/common/time/IsoLocale.java | 40 -- .../310_date_agg_per_day_of_week.yml | 47 --- .../common/time/DateFormatters.java | 383 +++++++++--------- .../elasticsearch/common/time/EpochTime.java | 8 +- .../index/mapper/DateFieldMapper.java | 3 +- .../index/mapper/ObjectMapper.java | 4 +- .../index/mapper/RangeFieldMapper.java | 5 +- .../joda/JavaJodaTimeDuellingTests.java | 2 +- .../common/time/DateFormattersTests.java | 2 +- .../xpack/sql/proto/StringUtils.java | 8 +- 10 files changed, 207 insertions(+), 295 deletions(-) delete mode 100644 libs/core/src/main/java/org/elasticsearch/common/time/IsoLocale.java delete mode 100644 rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/310_date_agg_per_day_of_week.yml 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 deleted file mode 100644 index 4d6d37d92345e..0000000000000 --- a/libs/core/src/main/java/org/elasticsearch/common/time/IsoLocale.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * 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 deleted file mode 100644 index a8952ac4e16d6..0000000000000 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/310_date_agg_per_day_of_week.yml +++ /dev/null @@ -1,47 +0,0 @@ ---- -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 65899c3c128cc..7a82b6b968c8c 100644 --- a/server/src/main/java/org/elasticsearch/common/time/DateFormatters.java +++ b/server/src/main/java/org/elasticsearch/common/time/DateFormatters.java @@ -41,6 +41,7 @@ import java.time.temporal.TemporalQueries; import java.time.temporal.TemporalQuery; import java.time.temporal.WeekFields; +import java.util.Locale; import static java.time.temporal.ChronoField.DAY_OF_MONTH; import static java.time.temporal.ChronoField.DAY_OF_WEEK; @@ -55,7 +56,7 @@ public class DateFormatters { private static final DateTimeFormatter TIME_ZONE_FORMATTER_NO_COLON = new DateTimeFormatterBuilder() .appendOffset("+HHmm", "Z") - .toFormatter(IsoLocale.ROOT) + .toFormatter(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT); private static final DateTimeFormatter STRICT_YEAR_MONTH_DAY_FORMATTER = new DateTimeFormatterBuilder() @@ -68,7 +69,7 @@ public class DateFormatters { .appendValue(DAY_OF_MONTH, 2, 2, SignStyle.NOT_NEGATIVE) .optionalEnd() .optionalEnd() - .toFormatter(IsoLocale.ROOT) + .toFormatter(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT); @@ -78,7 +79,7 @@ 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(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT); private static final DateTimeFormatter STRICT_DATE_OPTIONAL_TIME_PRINTER = new DateTimeFormatterBuilder() @@ -101,7 +102,7 @@ public class DateFormatters { .optionalEnd() .optionalEnd() .optionalEnd() - .toFormatter(IsoLocale.ROOT) + .toFormatter(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT); private static final DateTimeFormatter STRICT_DATE_OPTIONAL_TIME_FORMATTER = new DateTimeFormatterBuilder() @@ -133,7 +134,7 @@ public class DateFormatters { .optionalEnd() .optionalEnd() .optionalEnd() - .toFormatter(IsoLocale.ROOT) + .toFormatter(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT); /** @@ -161,7 +162,7 @@ public class DateFormatters { .append(TIME_ZONE_FORMATTER_NO_COLON) .optionalEnd() .optionalEnd() - .toFormatter(IsoLocale.ROOT) + .toFormatter(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT); private static final DateTimeFormatter STRICT_DATE_OPTIONAL_TIME_PRINTER_NANOS = new DateTimeFormatterBuilder() @@ -184,7 +185,7 @@ public class DateFormatters { .optionalEnd() .optionalEnd() .optionalEnd() - .toFormatter(IsoLocale.ROOT) + .toFormatter(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT); /** @@ -228,7 +229,7 @@ public class DateFormatters { .append(TIME_ZONE_FORMATTER_NO_COLON) .optionalEnd() .optionalEnd() - .toFormatter(IsoLocale.ROOT) + .toFormatter(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT)); ///////////////////////////////////////// @@ -244,7 +245,7 @@ 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(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT); /* @@ -253,12 +254,12 @@ 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) + .toFormatter(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT), - new DateTimeFormatterBuilder().append(BASIC_TIME_NO_MILLIS_BASE).appendZoneOrOffsetId().toFormatter(IsoLocale.ROOT) + new DateTimeFormatterBuilder().append(BASIC_TIME_NO_MILLIS_BASE).appendZoneOrOffsetId().toFormatter(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT), new DateTimeFormatterBuilder().append(BASIC_TIME_NO_MILLIS_BASE).append(TIME_ZONE_FORMATTER_NO_COLON) - .toFormatter(IsoLocale.ROOT) + .toFormatter(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT) ); @@ -267,7 +268,7 @@ 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(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT); private static final DateTimeFormatter BASIC_TIME_PRINTER = new DateTimeFormatterBuilder() @@ -275,7 +276,7 @@ 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, 3, 3, true) - .toFormatter(IsoLocale.ROOT) + .toFormatter(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT); /* @@ -285,21 +286,21 @@ 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) + .toFormatter(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT), - new DateTimeFormatterBuilder().append(BASIC_TIME_FORMATTER).appendZoneOrOffsetId().toFormatter(IsoLocale.ROOT) + new DateTimeFormatterBuilder().append(BASIC_TIME_FORMATTER).appendZoneOrOffsetId().toFormatter(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT), new DateTimeFormatterBuilder().append(BASIC_TIME_FORMATTER).append(TIME_ZONE_FORMATTER_NO_COLON) - .toFormatter(IsoLocale.ROOT) + .toFormatter(Locale.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(Locale.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(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT); /* @@ -308,12 +309,12 @@ 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_PRINTER).appendOffset("+HH:MM", "Z").toFormatter(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT), - new DateTimeFormatterBuilder().append(BASIC_T_TIME_FORMATTER).appendZoneOrOffsetId().toFormatter(IsoLocale.ROOT) + new DateTimeFormatterBuilder().append(BASIC_T_TIME_FORMATTER).appendZoneOrOffsetId().toFormatter(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT), new DateTimeFormatterBuilder().append(BASIC_T_TIME_FORMATTER).append(TIME_ZONE_FORMATTER_NO_COLON). - toFormatter(IsoLocale.ROOT) + toFormatter(Locale.ROOT) ); /* @@ -323,14 +324,14 @@ 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(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT), new DateTimeFormatterBuilder().appendLiteral("T").append(BASIC_TIME_NO_MILLIS_BASE) - .appendZoneOrOffsetId().toFormatter(IsoLocale.ROOT) + .appendZoneOrOffsetId().toFormatter(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT), new DateTimeFormatterBuilder().appendLiteral("T").append(BASIC_TIME_NO_MILLIS_BASE) .append(TIME_ZONE_FORMATTER_NO_COLON) - .toFormatter(IsoLocale.ROOT) + .toFormatter(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT) ); @@ -338,19 +339,19 @@ 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(IsoLocale.ROOT) + .toFormatter(Locale.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(Locale.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(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT); /* @@ -358,16 +359,16 @@ public class DateFormatters { * 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_PRINTER).appendOffset("+HH:MM", "Z").toFormatter(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT), - new DateTimeFormatterBuilder().append(BASIC_DATE_TIME_FORMATTER).appendZoneOrOffsetId().toFormatter(IsoLocale.ROOT) + new DateTimeFormatterBuilder().append(BASIC_DATE_TIME_FORMATTER).appendZoneOrOffsetId().toFormatter(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT), - new DateTimeFormatterBuilder().append(BASIC_DATE_TIME_FORMATTER).append(TIME_ZONE_FORMATTER_NO_COLON).toFormatter(IsoLocale.ROOT) + new DateTimeFormatterBuilder().append(BASIC_DATE_TIME_FORMATTER).append(TIME_ZONE_FORMATTER_NO_COLON).toFormatter(Locale.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(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT); /* @@ -376,13 +377,13 @@ 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(IsoLocale.ROOT) + .appendOffset("+HH:MM", "Z").toFormatter(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT), new DateTimeFormatterBuilder().append(BASIC_DATE_T).append(BASIC_TIME_NO_MILLIS_BASE) - .appendZoneOrOffsetId().toFormatter(IsoLocale.ROOT) + .appendZoneOrOffsetId().toFormatter(Locale.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(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT) ); @@ -391,7 +392,7 @@ public class DateFormatters { * digit year and three digit dayOfYear (uuuuDDD). */ private static final DateFormatter BASIC_ORDINAL_DATE = new JavaDateFormatter("basic_ordinal_date", - DateTimeFormatter.ofPattern("uuuuDDD", IsoLocale.ROOT)); + DateTimeFormatter.ofPattern("uuuuDDD", Locale.ROOT)); /* * Returns a formatter for a full ordinal date and time, using a four @@ -399,13 +400,13 @@ 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(IsoLocale.ROOT) + .appendOffset("+HH:MM", "Z").toFormatter(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT), new DateTimeFormatterBuilder().appendPattern("yyyyDDD").append(BASIC_T_TIME_FORMATTER) - .appendZoneOrOffsetId().toFormatter(IsoLocale.ROOT) + .appendZoneOrOffsetId().toFormatter(Locale.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(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT) ); @@ -416,13 +417,13 @@ public class DateFormatters { */ private static final DateFormatter BASIC_ORDINAL_DATE_TIME_NO_MILLIS = new JavaDateFormatter("basic_ordinal_date_time_no_millis", new DateTimeFormatterBuilder().appendPattern("uuuuDDD").appendLiteral("T").append(BASIC_TIME_NO_MILLIS_BASE) - .appendOffset("+HH:MM", "Z").toFormatter(IsoLocale.ROOT) + .appendOffset("+HH:MM", "Z").toFormatter(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT), new DateTimeFormatterBuilder().appendPattern("uuuuDDD").appendLiteral("T").append(BASIC_TIME_NO_MILLIS_BASE) - .appendZoneOrOffsetId().toFormatter(IsoLocale.ROOT) + .appendZoneOrOffsetId().toFormatter(Locale.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) + .append(TIME_ZONE_FORMATTER_NO_COLON).toFormatter(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT) ); @@ -431,7 +432,7 @@ 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(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT); ///////////////////////////////////////// @@ -451,7 +452,7 @@ 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(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT); private static final DateTimeFormatter STRICT_BASIC_WEEK_DATE_PRINTER = new DateTimeFormatterBuilder() @@ -460,7 +461,7 @@ 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(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT); /* @@ -483,7 +484,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(IsoLocale.ROOT) + .toFormatter(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT), new DateTimeFormatterBuilder() .append(STRICT_BASIC_WEEK_DATE_PRINTER) @@ -492,7 +493,7 @@ 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(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT), new DateTimeFormatterBuilder() .append(STRICT_BASIC_WEEK_DATE_PRINTER) @@ -501,7 +502,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(IsoLocale.ROOT) + .toFormatter(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT) ); @@ -512,8 +513,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", IsoLocale.ROOT)) - .toFormatter(IsoLocale.ROOT) + .append(DateTimeFormatter.ofPattern("'T'HHmmss.SSSX", Locale.ROOT)) + .toFormatter(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT), new DateTimeFormatterBuilder() .append(STRICT_BASIC_WEEK_DATE_FORMATTER) @@ -523,7 +524,7 @@ public class DateFormatters { .appendValue(SECOND_OF_MINUTE, 2, 2, SignStyle.NOT_NEGATIVE) .appendFraction(NANO_OF_SECOND, 1, 9, true) .appendZoneOrOffsetId() - .toFormatter(IsoLocale.ROOT) + .toFormatter(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT), new DateTimeFormatterBuilder() .append(STRICT_BASIC_WEEK_DATE_FORMATTER) @@ -533,7 +534,7 @@ 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(IsoLocale.ROOT) + .toFormatter(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT) ); @@ -541,19 +542,19 @@ public class DateFormatters { * 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(IsoLocale.ROOT)); + DateTimeFormatter.ISO_LOCAL_DATE.withResolverStyle(ResolverStyle.LENIENT).withLocale(Locale.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("uuuu-MM-dd'T'HH", IsoLocale.ROOT)); + DateTimeFormatter.ofPattern("uuuu-MM-dd'T'HH", Locale.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("uuuu-MM-dd'T'HH:mm", IsoLocale.ROOT)); + DateTimeFormatter.ofPattern("uuuu-MM-dd'T'HH:mm", Locale.ROOT)); /* * A strict date formatter that formats or parses a date without an offset, such as '2011-12-03'. @@ -569,7 +570,7 @@ 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(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT)); /* @@ -577,7 +578,7 @@ public class DateFormatters { */ private static final DateFormatter STRICT_YEAR = new JavaDateFormatter("strict_year", new DateTimeFormatterBuilder() .appendValue(ChronoField.YEAR, 4, 10, SignStyle.EXCEEDS_PAD) - .toFormatter(IsoLocale.ROOT) + .toFormatter(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT)); /* @@ -592,7 +593,7 @@ public class DateFormatters { .append(STRICT_HOUR_MINUTE_SECOND_FORMATTER) .appendFraction(NANO_OF_SECOND, 3, 9, true) .appendOffset("+HH:MM", "Z") - .toFormatter(IsoLocale.ROOT) + .toFormatter(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT); private static final DateTimeFormatter STRICT_DATE_FORMATTER = new DateTimeFormatterBuilder() @@ -602,7 +603,7 @@ public class DateFormatters { .optionalStart() .appendFraction(NANO_OF_SECOND, 1, 9, true) .optionalEnd() - .toFormatter(IsoLocale.ROOT) + .toFormatter(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT); /* @@ -610,10 +611,10 @@ public class DateFormatters { * (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(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT), new DateTimeFormatterBuilder().append(STRICT_DATE_FORMATTER).append(TIME_ZONE_FORMATTER_NO_COLON) - .toFormatter(IsoLocale.ROOT) + .toFormatter(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT) ); @@ -623,7 +624,7 @@ public class DateFormatters { .appendValue(DAY_OF_YEAR, 3, 3, SignStyle.NOT_NEGATIVE) .appendLiteral('T') .append(STRICT_HOUR_MINUTE_SECOND_FORMATTER) - .toFormatter(IsoLocale.ROOT) + .toFormatter(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT); /* @@ -632,13 +633,13 @@ 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(IsoLocale.ROOT) + .appendOffset("+HH:MM", "Z").toFormatter(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT), new DateTimeFormatterBuilder().append(STRICT_ORDINAL_DATE_TIME_NO_MILLIS_BASE) - .appendZoneOrOffsetId().toFormatter(IsoLocale.ROOT) + .appendZoneOrOffsetId().toFormatter(Locale.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(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT) ); @@ -646,7 +647,7 @@ public class DateFormatters { .append(STRICT_YEAR_MONTH_DAY_FORMATTER) .appendLiteral('T') .append(STRICT_HOUR_MINUTE_SECOND_FORMATTER) - .toFormatter(IsoLocale.ROOT) + .toFormatter(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT); /* @@ -655,13 +656,13 @@ 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(IsoLocale.ROOT) + .appendOffset("+HH:MM", "Z").toFormatter(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT), new DateTimeFormatterBuilder().append(STRICT_DATE_TIME_NO_MILLIS_FORMATTER) - .appendZoneOrOffsetId().toFormatter(IsoLocale.ROOT) + .appendZoneOrOffsetId().toFormatter(Locale.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(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT) ); @@ -669,13 +670,13 @@ public class DateFormatters { 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(Locale.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(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT); /* @@ -705,7 +706,7 @@ public class DateFormatters { .append(STRICT_YEAR_MONTH_DAY_FORMATTER) .appendLiteral("T") .append(STRICT_HOUR_MINUTE_SECOND_MILLIS_PRINTER) - .toFormatter(IsoLocale.ROOT) + .toFormatter(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT), new DateTimeFormatterBuilder() .append(STRICT_YEAR_MONTH_DAY_FORMATTER) @@ -713,7 +714,7 @@ public class DateFormatters { .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(IsoLocale.ROOT) + .toFormatter(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT) ); @@ -723,7 +724,7 @@ public class DateFormatters { .append(STRICT_YEAR_MONTH_DAY_FORMATTER) .appendLiteral("T") .append(STRICT_HOUR_MINUTE_SECOND_MILLIS_PRINTER) - .toFormatter(IsoLocale.ROOT) + .toFormatter(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT), new DateTimeFormatterBuilder() .append(STRICT_YEAR_MONTH_DAY_FORMATTER) @@ -731,7 +732,7 @@ public class DateFormatters { .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(IsoLocale.ROOT) + .toFormatter(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT) ); @@ -739,14 +740,14 @@ public class DateFormatters { * Returns a formatter for a two digit hour of day. (HH) */ private static final DateFormatter STRICT_HOUR = - new JavaDateFormatter("strict_hour", DateTimeFormatter.ofPattern("HH", IsoLocale.ROOT)); + new JavaDateFormatter("strict_hour", DateTimeFormatter.ofPattern("HH", Locale.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", IsoLocale.ROOT)); + new JavaDateFormatter("strict_hour_minute", DateTimeFormatter.ofPattern("HH:mm", Locale.ROOT)); private static final DateTimeFormatter STRICT_ORDINAL_DATE_TIME_PRINTER = new DateTimeFormatterBuilder() .appendValue(ChronoField.YEAR, 4, 10, SignStyle.EXCEEDS_PAD) @@ -759,7 +760,7 @@ public class DateFormatters { .appendValue(SECOND_OF_MINUTE, 2, 2, SignStyle.NOT_NEGATIVE) .appendFraction(NANO_OF_SECOND, 3, 9, true) .optionalEnd() - .toFormatter(IsoLocale.ROOT) + .toFormatter(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT); private static final DateTimeFormatter STRICT_ORDINAL_DATE_TIME_FORMATTER_BASE = new DateTimeFormatterBuilder() @@ -773,7 +774,7 @@ public class DateFormatters { .appendValue(SECOND_OF_MINUTE, 2, 2, SignStyle.NOT_NEGATIVE) .appendFraction(NANO_OF_SECOND, 1, 9, true) .optionalEnd() - .toFormatter(IsoLocale.ROOT) + .toFormatter(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT); /* @@ -782,13 +783,13 @@ 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(IsoLocale.ROOT) + .appendOffset("+HH:MM", "Z").toFormatter(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT), new DateTimeFormatterBuilder().append(STRICT_ORDINAL_DATE_TIME_FORMATTER_BASE) - .appendZoneOrOffsetId().toFormatter(IsoLocale.ROOT) + .appendZoneOrOffsetId().toFormatter(Locale.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(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT) ); @@ -800,7 +801,7 @@ public class DateFormatters { .appendLiteral(':') .appendValue(SECOND_OF_MINUTE, 2, 2, SignStyle.NOT_NEGATIVE) .appendFraction(NANO_OF_SECOND, 1, 9, true) - .toFormatter(IsoLocale.ROOT) + .toFormatter(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT); private static final DateTimeFormatter STRICT_TIME_PRINTER = new DateTimeFormatterBuilder() @@ -810,7 +811,7 @@ public class DateFormatters { .appendLiteral(':') .appendValue(SECOND_OF_MINUTE, 2, 2, SignStyle.NOT_NEGATIVE) .appendFraction(NANO_OF_SECOND, 3, 3, true) - .toFormatter(IsoLocale.ROOT) + .toFormatter(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT); /* @@ -819,12 +820,12 @@ 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_PRINTER).appendOffset("+HH:MM", "Z").toFormatter(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT), - new DateTimeFormatterBuilder().append(STRICT_TIME_FORMATTER_BASE).appendZoneOrOffsetId().toFormatter(IsoLocale.ROOT) + new DateTimeFormatterBuilder().append(STRICT_TIME_FORMATTER_BASE).appendZoneOrOffsetId().toFormatter(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT), new DateTimeFormatterBuilder().append(STRICT_TIME_FORMATTER_BASE).append(TIME_ZONE_FORMATTER_NO_COLON) - .toFormatter(IsoLocale.ROOT) + .toFormatter(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT) ); @@ -836,13 +837,13 @@ 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(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT), new DateTimeFormatterBuilder().appendLiteral('T').append(STRICT_TIME_FORMATTER_BASE) - .appendZoneOrOffsetId().toFormatter(IsoLocale.ROOT) + .appendZoneOrOffsetId().toFormatter(Locale.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(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT) ); @@ -852,7 +853,7 @@ 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(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT); /* @@ -861,12 +862,12 @@ 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) + .toFormatter(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT), - new DateTimeFormatterBuilder().append(STRICT_TIME_NO_MILLIS_BASE).appendZoneOrOffsetId().toFormatter(IsoLocale.ROOT) + new DateTimeFormatterBuilder().append(STRICT_TIME_NO_MILLIS_BASE).appendZoneOrOffsetId().toFormatter(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT), new DateTimeFormatterBuilder().append(STRICT_TIME_NO_MILLIS_BASE).append(TIME_ZONE_FORMATTER_NO_COLON) - .toFormatter(IsoLocale.ROOT) + .toFormatter(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT) ); @@ -877,13 +878,13 @@ 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(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT), new DateTimeFormatterBuilder().appendLiteral("T").append(STRICT_TIME_NO_MILLIS_BASE) - .appendZoneOrOffsetId().toFormatter(IsoLocale.ROOT) + .appendZoneOrOffsetId().toFormatter(Locale.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(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT) ); @@ -894,13 +895,13 @@ public class DateFormatters { .appendValue(IsoFields.WEEK_OF_WEEK_BASED_YEAR, 2) .appendLiteral('-') .appendValue(DAY_OF_WEEK, 1) - .toFormatter(IsoLocale.ROOT) + .toFormatter(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT); private static final DateTimeFormatter ISO_WEEK_DATE_T = new DateTimeFormatterBuilder() .append(ISO_WEEK_DATE) .appendLiteral('T') - .toFormatter(IsoLocale.ROOT) + .toFormatter(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT); /* @@ -915,13 +916,13 @@ 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(Locale.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(Locale.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(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT) ); @@ -931,13 +932,13 @@ 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(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT), new DateTimeFormatterBuilder().append(ISO_WEEK_DATE_T).append(STRICT_TIME_FORMATTER_BASE) - .appendZoneOrOffsetId().toFormatter(IsoLocale.ROOT) + .appendZoneOrOffsetId().toFormatter(Locale.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(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT) ); @@ -946,14 +947,14 @@ 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(Locale.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(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT); /* @@ -972,7 +973,7 @@ public class DateFormatters { .append(STRICT_WEEKYEAR_WEEK_FORMATTER) .appendLiteral("-") .appendValue(WeekFields.ISO.dayOfWeek()) - .toFormatter(IsoLocale.ROOT) + .toFormatter(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT)); /* @@ -981,7 +982,7 @@ public class DateFormatters { * 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("uuuu-MM-dd'T'HH:mm:ss", IsoLocale.ROOT)); + DateTimeFormatter.ofPattern("uuuu-MM-dd'T'HH:mm:ss", Locale.ROOT)); /* * A basic formatter for a full date as four digit year, two digit @@ -992,13 +993,13 @@ 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(IsoLocale.ROOT) + .toFormatter(Locale.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) + .toFormatter(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT).withZone(ZoneOffset.UTC) ); @@ -1008,7 +1009,7 @@ public class DateFormatters { .appendLiteral('-') .appendValue(DAY_OF_YEAR, 3) .optionalStart() - .toFormatter(IsoLocale.ROOT) + .toFormatter(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT); /* @@ -1039,14 +1040,14 @@ public class DateFormatters { .appendValue(DAY_OF_MONTH, 1, 2, SignStyle.NOT_NEGATIVE) .optionalEnd() .optionalEnd() - .toFormatter(IsoLocale.ROOT) + .toFormatter(Locale.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).withResolverStyle(ResolverStyle.STRICT); + .toFormatter(Locale.ROOT).withResolverStyle(ResolverStyle.STRICT); /* * a date formatter with optional time, being very lenient, format is @@ -1079,13 +1080,13 @@ public class DateFormatters { .optionalEnd() .optionalEnd() .optionalEnd() - .toFormatter(IsoLocale.ROOT).withResolverStyle(ResolverStyle.STRICT)); + .toFormatter(Locale.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(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT); private static final DateTimeFormatter HOUR_MINUTE_SECOND_MILLIS_FORMATTER = new DateTimeFormatterBuilder() @@ -1095,7 +1096,7 @@ public class DateFormatters { .appendLiteral(':') .appendValue(SECOND_OF_MINUTE, 1, 2, SignStyle.NOT_NEGATIVE) .appendFraction(NANO_OF_SECOND, 1, 3, true) - .toFormatter(IsoLocale.ROOT) + .toFormatter(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT); private static final DateTimeFormatter HOUR_MINUTE_SECOND_FRACTION_FORMATTER = new DateTimeFormatterBuilder() @@ -1105,21 +1106,21 @@ public class DateFormatters { .appendLiteral(':') .appendValue(SECOND_OF_MINUTE, 1, 2, SignStyle.NOT_NEGATIVE) .appendFraction(NANO_OF_SECOND, 1, 9, true) - .toFormatter(IsoLocale.ROOT) + .toFormatter(Locale.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(Locale.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(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT); /* @@ -1135,17 +1136,17 @@ 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(Locale.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(Locale.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(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT); private static final DateTimeFormatter WEEK_DATE_FORMATTER = new DateTimeFormatterBuilder() @@ -1154,21 +1155,21 @@ 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(Locale.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(Locale.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(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT)); /* @@ -1176,12 +1177,12 @@ public class DateFormatters { * day. (uuuu-MM-dd'T'HH) */ private static final DateFormatter DATE_HOUR = new JavaDateFormatter("date_hour", - DateTimeFormatter.ofPattern("uuuu-MM-dd'T'HH", IsoLocale.ROOT), + DateTimeFormatter.ofPattern("uuuu-MM-dd'T'HH", Locale.ROOT), new DateTimeFormatterBuilder() .append(DATE_FORMATTER) .appendLiteral("T") .appendValue(HOUR_OF_DAY, 1, 2, SignStyle.NOT_NEGATIVE) - .toFormatter(IsoLocale.ROOT) + .toFormatter(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT)); /* @@ -1195,13 +1196,13 @@ public class DateFormatters { .append(STRICT_YEAR_MONTH_DAY_FORMATTER) .appendLiteral("T") .append(STRICT_HOUR_MINUTE_SECOND_MILLIS_PRINTER) - .toFormatter(IsoLocale.ROOT) + .toFormatter(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT), new DateTimeFormatterBuilder() .append(DATE_FORMATTER) .appendLiteral("T") .append(HOUR_MINUTE_SECOND_MILLIS_FORMATTER) - .toFormatter(IsoLocale.ROOT) + .toFormatter(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT)); private static final DateFormatter DATE_HOUR_MINUTE_SECOND_FRACTION = @@ -1210,13 +1211,13 @@ public class DateFormatters { .append(STRICT_YEAR_MONTH_DAY_FORMATTER) .appendLiteral("T") .append(STRICT_HOUR_MINUTE_SECOND_MILLIS_PRINTER) - .toFormatter(IsoLocale.ROOT) + .toFormatter(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT), new DateTimeFormatterBuilder() .append(DATE_FORMATTER) .appendLiteral("T") .append(HOUR_MINUTE_SECOND_FRACTION_FORMATTER) - .toFormatter(IsoLocale.ROOT) + .toFormatter(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT)); /* @@ -1224,12 +1225,12 @@ public class DateFormatters { * 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("uuuu-MM-dd'T'HH:mm", IsoLocale.ROOT), + DateTimeFormatter.ofPattern("uuuu-MM-dd'T'HH:mm", Locale.ROOT), new DateTimeFormatterBuilder() .append(DATE_FORMATTER) .appendLiteral("T") .append(HOUR_MINUTE_FORMATTER) - .toFormatter(IsoLocale.ROOT) + .toFormatter(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT)); /* @@ -1238,12 +1239,12 @@ public class DateFormatters { * minute. (uuuu-MM-dd'T'HH:mm:ss) */ private static final DateFormatter DATE_HOUR_MINUTE_SECOND = new JavaDateFormatter("date_hour_minute_second", - DateTimeFormatter.ofPattern("uuuu-MM-dd'T'HH:mm:ss", IsoLocale.ROOT), + DateTimeFormatter.ofPattern("uuuu-MM-dd'T'HH:mm:ss", Locale.ROOT), new DateTimeFormatterBuilder() .append(DATE_FORMATTER) .appendLiteral("T") .append(HOUR_MINUTE_SECOND_FORMATTER) - .toFormatter(IsoLocale.ROOT) + .toFormatter(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT)); private static final DateTimeFormatter DATE_TIME_FORMATTER = new DateTimeFormatterBuilder() @@ -1255,7 +1256,7 @@ public class DateFormatters { .appendValue(SECOND_OF_MINUTE, 1, 2, SignStyle.NOT_NEGATIVE) .appendFraction(NANO_OF_SECOND, 1, 9, true) .optionalEnd() - .toFormatter(IsoLocale.ROOT) + .toFormatter(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT); /* @@ -1265,10 +1266,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(IsoLocale.ROOT) + .toFormatter(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT), new DateTimeFormatterBuilder().append(DATE_TIME_FORMATTER).append(TIME_ZONE_FORMATTER_NO_COLON) - .toFormatter(IsoLocale.ROOT) + .toFormatter(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT) ); @@ -1295,7 +1296,7 @@ public class DateFormatters { .appendLiteral(':') .appendValue(SECOND_OF_MINUTE, 2, 2, SignStyle.NOT_NEGATIVE) .appendZoneId() - .toFormatter(IsoLocale.ROOT) + .toFormatter(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT); private static final DateTimeFormatter DATE_TIME_PREFIX = new DateTimeFormatterBuilder() @@ -1306,7 +1307,7 @@ public class DateFormatters { .appendLiteral(':') .appendValue(SECOND_OF_MINUTE, 1, 2, SignStyle.NOT_NEGATIVE) .optionalEnd() - .toFormatter(IsoLocale.ROOT) + .toFormatter(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT); /* @@ -1315,16 +1316,16 @@ 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(IsoLocale.ROOT) + new DateTimeFormatterBuilder().append(DATE_TIME_PREFIX).appendOffset("+HH:MM", "Z").toFormatter(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT), new DateTimeFormatterBuilder().append(DATE_TIME_PREFIX).append(TIME_ZONE_FORMATTER_NO_COLON) - .toFormatter(IsoLocale.ROOT) + .toFormatter(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT), new DateTimeFormatterBuilder().append(DATE_TIME_PREFIX) - .optionalStart().appendZoneOrOffsetId().optionalEnd().toFormatter(IsoLocale.ROOT) + .optionalStart().appendZoneOrOffsetId().optionalEnd().toFormatter(Locale.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(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT) ); @@ -1344,7 +1345,7 @@ public class DateFormatters { * hour. (HH:mm) */ private static final DateFormatter HOUR_MINUTE = - new JavaDateFormatter("hour_minute", DateTimeFormatter.ofPattern("HH:mm", IsoLocale.ROOT), HOUR_MINUTE_FORMATTER); + new JavaDateFormatter("hour_minute", DateTimeFormatter.ofPattern("HH:mm", Locale.ROOT), HOUR_MINUTE_FORMATTER); /* * A strict formatter that formats or parses a hour, minute and second, such as '09:43:25'. @@ -1355,7 +1356,7 @@ public class DateFormatters { .append(HOUR_MINUTE_FORMATTER) .appendLiteral(":") .appendValue(SECOND_OF_MINUTE, 1, 2, SignStyle.NOT_NEGATIVE) - .toFormatter(IsoLocale.ROOT) + .toFormatter(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT) ); @@ -1363,8 +1364,8 @@ public class DateFormatters { * Returns a formatter for a two digit hour of day. (HH) */ 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) + DateTimeFormatter.ofPattern("HH", Locale.ROOT), + new DateTimeFormatterBuilder().appendValue(HOUR_OF_DAY, 1, 2, SignStyle.NOT_NEGATIVE).toFormatter(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT) ); @@ -1377,7 +1378,7 @@ public class DateFormatters { .appendValue(SECOND_OF_MINUTE, 1, 2, SignStyle.NOT_NEGATIVE) .appendFraction(NANO_OF_SECOND, 1, 9, true) .optionalEnd() - .toFormatter(IsoLocale.ROOT) + .toFormatter(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT); /* @@ -1386,13 +1387,13 @@ 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(IsoLocale.ROOT) + .appendOffset("+HH:MM", "Z").toFormatter(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT), new DateTimeFormatterBuilder().append(ORDINAL_DATE_TIME_FORMATTER_BASE) - .appendZoneOrOffsetId().toFormatter(IsoLocale.ROOT) + .appendZoneOrOffsetId().toFormatter(Locale.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(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT) ); @@ -1400,7 +1401,7 @@ public class DateFormatters { .append(ORDINAL_DATE_FORMATTER) .appendLiteral('T') .append(HOUR_MINUTE_SECOND_FORMATTER) - .toFormatter(IsoLocale.ROOT) + .toFormatter(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT); /* @@ -1409,13 +1410,13 @@ 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(IsoLocale.ROOT) + .appendOffset("+HH:MM", "Z").toFormatter(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT), new DateTimeFormatterBuilder().append(ORDINAL_DATE_TIME_NO_MILLIS_BASE) - .appendZoneOrOffsetId().toFormatter(IsoLocale.ROOT) + .appendZoneOrOffsetId().toFormatter(Locale.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(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT) ); @@ -1425,13 +1426,13 @@ 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(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT), new DateTimeFormatterBuilder().append(WEEK_DATE_FORMATTER).appendLiteral("T").append(TIME_PREFIX) - .appendZoneOrOffsetId().toFormatter(IsoLocale.ROOT) + .appendZoneOrOffsetId().toFormatter(Locale.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(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT) ); @@ -1441,13 +1442,13 @@ 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(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT), new DateTimeFormatterBuilder().append(WEEK_DATE_FORMATTER).append(T_TIME_NO_MILLIS_FORMATTER) - .appendZoneOrOffsetId().toFormatter(IsoLocale.ROOT) + .appendZoneOrOffsetId().toFormatter(Locale.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(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT) ); @@ -1458,14 +1459,14 @@ 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", IsoLocale.ROOT)) - .toFormatter(IsoLocale.ROOT) + .append(DateTimeFormatter.ofPattern("'T'HHmmss.SSSX", Locale.ROOT)) + .toFormatter(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT), new DateTimeFormatterBuilder().append(BASIC_WEEK_DATE_FORMATTER).append(BASIC_T_TIME_FORMATTER) - .appendZoneOrOffsetId().toFormatter(IsoLocale.ROOT) + .appendZoneOrOffsetId().toFormatter(Locale.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(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT) ); @@ -1475,14 +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) + .append(STRICT_BASIC_WEEK_DATE_PRINTER).append(DateTimeFormatter.ofPattern("'T'HHmmssX", Locale.ROOT)) + .toFormatter(Locale.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(Locale.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(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT) ); @@ -1492,11 +1493,11 @@ 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(STRICT_TIME_PRINTER).appendOffset("+HH:MM", "Z").toFormatter(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT), - new DateTimeFormatterBuilder().append(TIME_PREFIX).appendZoneOrOffsetId().toFormatter(IsoLocale.ROOT) + new DateTimeFormatterBuilder().append(TIME_PREFIX).appendZoneOrOffsetId().toFormatter(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT), - new DateTimeFormatterBuilder().append(TIME_PREFIX).append(TIME_ZONE_FORMATTER_NO_COLON).toFormatter(IsoLocale.ROOT) + new DateTimeFormatterBuilder().append(TIME_PREFIX).append(TIME_ZONE_FORMATTER_NO_COLON).toFormatter(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT) ); @@ -1506,12 +1507,12 @@ 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) + .toFormatter(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT), - new DateTimeFormatterBuilder().append(TIME_NO_MILLIS_FORMATTER).appendZoneOrOffsetId().toFormatter(IsoLocale.ROOT) + new DateTimeFormatterBuilder().append(TIME_NO_MILLIS_FORMATTER).appendZoneOrOffsetId().toFormatter(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT), new DateTimeFormatterBuilder().append(TIME_NO_MILLIS_FORMATTER).append(TIME_ZONE_FORMATTER_NO_COLON) - .toFormatter(IsoLocale.ROOT) + .toFormatter(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT) ); @@ -1522,13 +1523,13 @@ 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(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT), new DateTimeFormatterBuilder().appendLiteral("T").append(TIME_PREFIX) - .appendZoneOrOffsetId().toFormatter(IsoLocale.ROOT) + .appendZoneOrOffsetId().toFormatter(Locale.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(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT) ); @@ -1539,12 +1540,12 @@ 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) + .appendOffset("+HH:MM", "Z").toFormatter(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT), - new DateTimeFormatterBuilder().append(T_TIME_NO_MILLIS_FORMATTER).appendZoneOrOffsetId().toFormatter(IsoLocale.ROOT) + new DateTimeFormatterBuilder().append(T_TIME_NO_MILLIS_FORMATTER).appendZoneOrOffsetId().toFormatter(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT), new DateTimeFormatterBuilder().append(T_TIME_NO_MILLIS_FORMATTER).append(TIME_ZONE_FORMATTER_NO_COLON) - .toFormatter(IsoLocale.ROOT) + .toFormatter(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT) ); @@ -1556,10 +1557,10 @@ 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(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT), new DateTimeFormatterBuilder().appendValue(ChronoField.YEAR).appendLiteral("-").appendValue(MONTH_OF_YEAR) - .toFormatter(IsoLocale.ROOT) + .toFormatter(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT) ); @@ -1574,7 +1575,7 @@ public class DateFormatters { .appendValue(MONTH_OF_YEAR) .appendLiteral("-") .appendValue(DAY_OF_MONTH) - .toFormatter(IsoLocale.ROOT) + .toFormatter(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT) ); @@ -1593,7 +1594,7 @@ public class DateFormatters { .appendValue(WeekFields.ISO.weekBasedYear()) .appendLiteral("-W") .appendValue(WeekFields.ISO.weekOfWeekBasedYear()) - .toFormatter(IsoLocale.ROOT) + .toFormatter(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT) ); @@ -1606,7 +1607,7 @@ public class DateFormatters { .append(STRICT_WEEKYEAR_WEEK_FORMATTER) .appendLiteral("-") .appendValue(WeekFields.ISO.dayOfWeek()) - .toFormatter(IsoLocale.ROOT) + .toFormatter(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT), new DateTimeFormatterBuilder() .appendValue(WeekFields.ISO.weekBasedYear()) @@ -1614,7 +1615,7 @@ public class DateFormatters { .appendValue(WeekFields.ISO.weekOfWeekBasedYear()) .appendLiteral("-") .appendValue(WeekFields.ISO.dayOfWeek()) - .toFormatter(IsoLocale.ROOT) + .toFormatter(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT) ); @@ -1799,7 +1800,7 @@ public class DateFormatters { try { return new JavaDateFormatter(input, new DateTimeFormatterBuilder() .appendPattern(input) - .toFormatter(IsoLocale.ROOT) + .toFormatter(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT)); } catch (IllegalArgumentException e) { throw new IllegalArgumentException("Invalid format: [" + input + "]: " + e.getMessage(), e); @@ -1896,7 +1897,7 @@ public static ZonedDateTime from(TemporalAccessor accessor) { * when YearOfEra was used instead of Year. * This is to make it compatible with Joda behaviour */ - static final TemporalQuery LOCAL_DATE_QUERY = new TemporalQuery<>() { + static final TemporalQuery LOCAL_DATE_QUERY = new TemporalQuery() { @Override public LocalDate queryFrom(TemporalAccessor temporal) { if (temporal.isSupported(ChronoField.EPOCH_DAY)) { 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 5875e8572aebb..22b29bd0edf45 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(IsoLocale.ROOT); + .toFormatter(Locale.ROOT); // this supports seconds ending in dot private static final DateTimeFormatter SECONDS_FORMATTER2 = new DateTimeFormatterBuilder() .appendValue(SECONDS, 1, 19, SignStyle.NORMAL) .appendLiteral('.') - .toFormatter(IsoLocale.ROOT); + .toFormatter(Locale.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(IsoLocale.ROOT); + .toFormatter(Locale.ROOT); // this supports milliseconds ending in dot private static final DateTimeFormatter MILLISECONDS_FORMATTER2 = new DateTimeFormatterBuilder() .append(MILLISECONDS_FORMATTER1) .appendLiteral('.') - .toFormatter(IsoLocale.ROOT); + .toFormatter(Locale.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 57bc296b081fe..cfd6fdcec7a25 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/DateFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/DateFieldMapper.java @@ -43,7 +43,6 @@ 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; @@ -136,7 +135,7 @@ public static class Builder extends FieldMapper.Builder { private Boolean coerce; - private Locale locale = IsoLocale.ROOT; + private Locale locale = Locale.ROOT; private String pattern; public Builder(String name, RangeType type) { @@ -424,7 +423,7 @@ && fieldType().dateTimeFormatter().pattern().equals(DateFieldMapper.DEFAULT_DATE } if (fieldType().rangeType == RangeType.DATE && (includeDefaults || (fieldType().dateTimeFormatter() != null - && fieldType().dateTimeFormatter().locale() != IsoLocale.ROOT))) { + && fieldType().dateTimeFormatter().locale() != Locale.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 f54891f4e4d53..1ead658ba7165 100644 --- a/server/src/test/java/org/elasticsearch/common/joda/JavaJodaTimeDuellingTests.java +++ b/server/src/test/java/org/elasticsearch/common/joda/JavaJodaTimeDuellingTests.java @@ -37,9 +37,9 @@ import java.time.temporal.TemporalAccessor; import java.util.Locale; +import static org.hamcrest.CoreMatchers.equalTo; 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 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 e478b6dfcc499..c5956e5c29a23 100644 --- a/server/src/test/java/org/elasticsearch/common/time/DateFormattersTests.java +++ b/server/src/test/java/org/elasticsearch/common/time/DateFormattersTests.java @@ -115,7 +115,7 @@ public void testParsersWithMultipleInternalFormats() throws Exception { } public void testLocales() { - assertThat(DateFormatters.forPattern("strict_date_optional_time").locale(), is(IsoLocale.ROOT)); + assertThat(DateFormatters.forPattern("strict_date_optional_time").locale(), is(Locale.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 c558766e88547..b0d618191f6f7 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,8 +6,6 @@ package org.elasticsearch.xpack.sql.proto; -import org.elasticsearch.common.time.IsoLocale; - import java.sql.Timestamp; import java.time.Duration; import java.time.OffsetTime; @@ -15,6 +13,7 @@ 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; @@ -26,6 +25,7 @@ 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() @@ -39,7 +39,7 @@ public final class StringUtils { .appendValue(SECOND_OF_MINUTE, 2) .appendFraction(MILLI_OF_SECOND, 3, 3, true) .appendOffsetId() - .toFormatter(IsoLocale.ROOT); + .toFormatter(Locale.ROOT); public static final DateTimeFormatter ISO_DATE_WITH_NANOS = new DateTimeFormatterBuilder() .parseCaseInsensitive() @@ -63,7 +63,7 @@ public final class StringUtils { .appendValue(SECOND_OF_MINUTE, 2) .appendFraction(MILLI_OF_SECOND, 3, 3, true) .appendOffsetId() - .toFormatter(IsoLocale.ROOT); + .toFormatter(Locale.ROOT); private static final int SECONDS_PER_MINUTE = 60; private static final int SECONDS_PER_HOUR = SECONDS_PER_MINUTE * 60; From 8696ec739d604fdf56003b725cb4747409d26bdb Mon Sep 17 00:00:00 2001 From: Przemyslaw Gomulka Date: Fri, 9 Aug 2019 15:24:05 +0200 Subject: [PATCH 02/15] Set start of the week to Monday for root locale (#43652) Introducing a IsoLocal.ROOT constant which should be used instead of java.util.Locale.ROOT in ES when dealing with dates. IsoLocal.ROOT customises start of the week to be Monday instead of Sunday. closes #42588 an issue with investigation details relates #41670 bug raised (this won't fix it on its own. joda.parseInto has to be reimplemented closes #43275 an issue raised by community member change skip reason compile error not orking spi working unit test cleanup change providers for 9+ revert changes IsoLocale cleanup move spi files to server make unit test pass from gradle expermienting with gradle tasks uncomment jar hell check only add settings in buildplugin allign options for locale providers --- .../gradle/test/RestIntegTestTask.groovy | 1 + .../310_date_agg_per_day_of_week.yml | 47 +++++++++++++++++++ .../common/time/IsoCalendarDataProvider.java | 41 ++++++++++++++++ .../java.util.spi.CalendarDataProvider | 1 + .../joda/JavaJodaTimeDuellingTests.java | 1 + 5 files changed, 91 insertions(+) create mode 100644 rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/310_date_agg_per_day_of_week.yml create mode 100644 server/src/main/java/org/elasticsearch/common/time/IsoCalendarDataProvider.java create mode 100644 server/src/main/resources/META-INF/services/java.util.spi.CalendarDataProvider diff --git a/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/RestIntegTestTask.groovy b/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/RestIntegTestTask.groovy index f07ce2b08f438..5808e22780b3e 100644 --- a/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/RestIntegTestTask.groovy +++ b/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/RestIntegTestTask.groovy @@ -24,6 +24,7 @@ import org.elasticsearch.gradle.testclusters.RestTestRunnerTask import org.elasticsearch.gradle.tool.Boilerplate import org.elasticsearch.gradle.tool.ClasspathUtils import org.gradle.api.DefaultTask +import org.gradle.api.JavaVersion import org.gradle.api.Task import org.gradle.api.file.FileCopyDetails import org.gradle.api.tasks.Copy 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..d71402d0c9017 --- /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.3.99" + reason: "only backported to 7.4 (7x)" + + - 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/IsoCalendarDataProvider.java b/server/src/main/java/org/elasticsearch/common/time/IsoCalendarDataProvider.java new file mode 100644 index 0000000000000..36a93049adeb8 --- /dev/null +++ b/server/src/main/java/org/elasticsearch/common/time/IsoCalendarDataProvider.java @@ -0,0 +1,41 @@ +/* + * 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.Calendar; +import java.util.Locale; +import java.util.spi.CalendarDataProvider; + +public class IsoCalendarDataProvider extends CalendarDataProvider { + + @Override + public int getFirstDayOfWeek(Locale locale) { + return Calendar.MONDAY; + } + + @Override + public int getMinimalDaysInFirstWeek(Locale locale) { + return 4; + } + + @Override + public Locale[] getAvailableLocales() { + return new Locale[]{Locale.ROOT}; + } +} diff --git a/server/src/main/resources/META-INF/services/java.util.spi.CalendarDataProvider b/server/src/main/resources/META-INF/services/java.util.spi.CalendarDataProvider new file mode 100644 index 0000000000000..6e006ccf815f8 --- /dev/null +++ b/server/src/main/resources/META-INF/services/java.util.spi.CalendarDataProvider @@ -0,0 +1 @@ +org.elasticsearch.common.time.IsoCalendarDataProvider \ No newline at end of file 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 1ead658ba7165..abb23d24cb286 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.elasticsearch.test.ESTestCase; import org.joda.time.DateTime; import org.joda.time.DateTimeZone; +import org.joda.time.format.DateTimeFormat; import org.joda.time.format.ISODateTimeFormat; import java.time.LocalDateTime; From dc0c9533854a3ec49018cd8e424a4d3ae99ea396 Mon Sep 17 00:00:00 2001 From: Przemyslaw Gomulka Date: Thu, 17 Oct 2019 20:43:34 +0200 Subject: [PATCH 03/15] working parsing of weekbased fields --- distribution/src/config/jvm.options | 2 +- .../elasticsearch/common/time/DateFormatters.java | 13 +++++++------ .../elasticsearch/xpack/sql/proto/StringUtils.java | 2 +- .../function/scalar/datetime/DateTimeField.java | 6 +++--- .../analyzer/VerifierErrorMessagesTests.java | 6 +++--- 5 files changed, 15 insertions(+), 14 deletions(-) diff --git a/distribution/src/config/jvm.options b/distribution/src/config/jvm.options index 1c329d39e1465..6ebf089e381b6 100644 --- a/distribution/src/config/jvm.options +++ b/distribution/src/config/jvm.options @@ -105,4 +105,4 @@ ${error.file} -Xlog:gc*,gc+age=trace,safepoint:file=${loggc}:utctime,pid,tags:filecount=32,filesize=64m # due to internationalization enhancements in JDK 9 Elasticsearch need to set the provider to COMPAT otherwise # time/date parsing will break in an incompatible way for some date patterns and locals --Djava.locale.providers=COMPAT +-Djava.locale.providers=SPI,COMPAT 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 7a82b6b968c8c..0d5ec5747904b 100644 --- a/server/src/main/java/org/elasticsearch/common/time/DateFormatters.java +++ b/server/src/main/java/org/elasticsearch/common/time/DateFormatters.java @@ -38,6 +38,7 @@ import java.time.temporal.IsoFields; import java.time.temporal.TemporalAccessor; import java.time.temporal.TemporalAdjusters; +import java.time.temporal.TemporalField; import java.time.temporal.TemporalQueries; import java.time.temporal.TemporalQuery; import java.time.temporal.WeekFields; @@ -1853,7 +1854,7 @@ public static ZonedDateTime from(TemporalAccessor accessor) { LocalTime localTime = accessor.query(TemporalQueries.localTime()); boolean isLocalDateSet = localDate != null; boolean isLocalTimeSet = localTime != null; - + WeekFields ISO = WeekFields.of(DayOfWeek.MONDAY, 4); // the first two cases are the most common, so this allows us to exit early when parsing dates if (isLocalDateSet && isLocalTimeSet) { return of(localDate, localTime, zoneId); @@ -1873,14 +1874,14 @@ public static ZonedDateTime from(TemporalAccessor accessor) { } else if (accessor.isSupported(MONTH_OF_YEAR)) { // missing year, falling back to the epoch and then filling return getLocaldate(accessor).atStartOfDay(zoneId); - } else if (accessor.isSupported(WeekFields.ISO.weekBasedYear())) { - if (accessor.isSupported(WeekFields.ISO.weekOfWeekBasedYear())) { - return Year.of(accessor.get(WeekFields.ISO.weekBasedYear())) + } else if (accessor.isSupported(ISO.weekBasedYear())) { + if (accessor.isSupported(ISO.weekOfWeekBasedYear())) { + return Year.of(accessor.get(ISO.weekBasedYear())) .atDay(1) - .with(WeekFields.ISO.weekOfWeekBasedYear(), accessor.getLong(WeekFields.ISO.weekOfWeekBasedYear())) + .with(ISO.weekOfWeekBasedYear(), accessor.getLong(ISO.weekOfWeekBasedYear())) .atStartOfDay(zoneId); } else { - return Year.of(accessor.get(WeekFields.ISO.weekBasedYear())) + return Year.of(accessor.get(ISO.weekBasedYear())) .atDay(1) .with(TemporalAdjusters.firstInMonth(DayOfWeek.MONDAY)) .atStartOfDay(zoneId); 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 b0d618191f6f7..780fce2604c04 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 @@ -52,7 +52,7 @@ public final class StringUtils { .appendValue(SECOND_OF_MINUTE, 2) .appendFraction(NANO_OF_SECOND, 3, 9, true) .appendOffsetId() - .toFormatter(IsoLocale.ROOT); + .toFormatter(Locale.ROOT); public static final DateTimeFormatter ISO_TIME_WITH_MILLIS = new DateTimeFormatterBuilder() .parseCaseInsensitive() diff --git a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/expression/function/scalar/datetime/DateTimeField.java b/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/expression/function/scalar/datetime/DateTimeField.java index 60b3ec3c550f6..9cbb6ab7f2020 100644 --- a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/expression/function/scalar/datetime/DateTimeField.java +++ b/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/expression/function/scalar/datetime/DateTimeField.java @@ -5,13 +5,13 @@ */ package org.elasticsearch.xpack.sql.expression.function.scalar.datetime; -import org.elasticsearch.common.time.IsoLocale; import org.elasticsearch.xpack.sql.util.StringUtils; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.stream.Collectors; @@ -21,7 +21,7 @@ static Map initializeResolutionMap(D[] valu Map nameToPart = new HashMap<>(); for (D datePart : values) { - String lowerCaseName = datePart.name().toLowerCase(IsoLocale.ROOT); + String lowerCaseName = datePart.name().toLowerCase(Locale.ROOT); nameToPart.put(lowerCaseName, datePart); for (String alias : datePart.aliases()) { @@ -36,7 +36,7 @@ static List initializeValidValues(D[] values) } static D resolveMatch(Map resolutionMap, String possibleMatch) { - return resolutionMap.get(possibleMatch.toLowerCase(IsoLocale.ROOT)); + return resolutionMap.get(possibleMatch.toLowerCase(Locale.ROOT)); } static List findSimilar(Iterable similars, String match) { diff --git a/x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/analysis/analyzer/VerifierErrorMessagesTests.java b/x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/analysis/analyzer/VerifierErrorMessagesTests.java index c6be820bbcb49..cf9cf8d0ea77b 100644 --- a/x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/analysis/analyzer/VerifierErrorMessagesTests.java +++ b/x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/analysis/analyzer/VerifierErrorMessagesTests.java @@ -5,7 +5,6 @@ */ package org.elasticsearch.xpack.sql.analysis.analyzer; -import org.elasticsearch.common.time.IsoLocale; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.xpack.sql.TestUtils; import org.elasticsearch.xpack.sql.analysis.index.EsIndex; @@ -30,6 +29,7 @@ import java.util.Arrays; import java.util.LinkedHashMap; +import java.util.Locale; import java.util.Map; import static java.util.Collections.emptyMap; @@ -587,7 +587,7 @@ public void testInvalidTypeForStringFunction_WithOneArgString() { } public void testInvalidTypeForStringFunction_WithOneArgNumeric() { - String functionName = randomFrom(Arrays.asList(Char.class, Space.class)).getSimpleName().toUpperCase(IsoLocale.ROOT); + String functionName = randomFrom(Arrays.asList(Char.class, Space.class)).getSimpleName().toUpperCase(Locale.ROOT); assertEquals("1:8: argument of [" + functionName + "('foo')] must be [integer], found value ['foo'] type [keyword]", error("SELECT " + functionName + "('foo')")); assertEquals("1:8: argument of [" + functionName + "(1.2)] must be [integer], found value [1.2] type [double]", @@ -619,7 +619,7 @@ public void testInvalidTypeForStringFunction_WithTwoArgs() { } public void testInvalidTypeForNumericFunction_WithTwoArgs() { - String functionName = randomFrom(Arrays.asList(Round.class, Truncate.class)).getSimpleName().toUpperCase(IsoLocale.ROOT); + String functionName = randomFrom(Arrays.asList(Round.class, Truncate.class)).getSimpleName().toUpperCase(Locale.ROOT); assertEquals("1:8: first argument of [" + functionName + "('foo', 2)] must be [numeric], found value ['foo'] type [keyword]", error("SELECT " + functionName + "('foo', 2)")); assertEquals("1:8: second argument of [" + functionName + "(1.2, 'bar')] must be [integer], found value ['bar'] type [keyword]", From 352344b9c6cc5bb852b08e7a645d6beaef2d4c5e Mon Sep 17 00:00:00 2001 From: Przemyslaw Gomulka Date: Thu, 17 Oct 2019 21:15:42 +0200 Subject: [PATCH 04/15] checkstyle --- .../main/java/org/elasticsearch/common/time/DateFormatters.java | 1 - 1 file changed, 1 deletion(-) 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 0d5ec5747904b..7dd79a233b6a4 100644 --- a/server/src/main/java/org/elasticsearch/common/time/DateFormatters.java +++ b/server/src/main/java/org/elasticsearch/common/time/DateFormatters.java @@ -38,7 +38,6 @@ import java.time.temporal.IsoFields; import java.time.temporal.TemporalAccessor; import java.time.temporal.TemporalAdjusters; -import java.time.temporal.TemporalField; import java.time.temporal.TemporalQueries; import java.time.temporal.TemporalQuery; import java.time.temporal.WeekFields; From 8ca12f00c036a4890457bf348da320c252415e68 Mon Sep 17 00:00:00 2001 From: Przemyslaw Gomulka Date: Fri, 18 Oct 2019 12:29:46 +0200 Subject: [PATCH 05/15] support for weekbased dates convertions to zoned --- .../common/time/DateFormatters.java | 47 ++++++++++--------- .../joda/JavaJodaTimeDuellingTests.java | 1 - .../common/time/DateFormattersTests.java | 31 ++++++++++++ 3 files changed, 57 insertions(+), 22 deletions(-) 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 7dd79a233b6a4..992d7c6195706 100644 --- a/server/src/main/java/org/elasticsearch/common/time/DateFormatters.java +++ b/server/src/main/java/org/elasticsearch/common/time/DateFormatters.java @@ -22,7 +22,6 @@ import org.elasticsearch.common.Strings; import org.elasticsearch.common.SuppressForbidden; -import java.time.DayOfWeek; import java.time.Instant; import java.time.LocalDate; import java.time.LocalTime; @@ -37,7 +36,6 @@ import java.time.temporal.ChronoField; import java.time.temporal.IsoFields; 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; @@ -53,6 +51,7 @@ import static java.time.temporal.ChronoField.SECOND_OF_MINUTE; public class DateFormatters { + private static final WeekFields WEEK_FIELDS = WeekFields.of(Locale.ROOT); private static final DateTimeFormatter TIME_ZONE_FORMATTER_NO_COLON = new DateTimeFormatterBuilder() .appendOffset("+HHmm", "Z") @@ -1853,7 +1852,7 @@ public static ZonedDateTime from(TemporalAccessor accessor) { LocalTime localTime = accessor.query(TemporalQueries.localTime()); boolean isLocalDateSet = localDate != null; boolean isLocalTimeSet = localTime != null; - WeekFields ISO = WeekFields.of(DayOfWeek.MONDAY, 4); + // the first two cases are the most common, so this allows us to exit early when parsing dates if (isLocalDateSet && isLocalTimeSet) { return of(localDate, localTime, zoneId); @@ -1862,7 +1861,7 @@ public static ZonedDateTime from(TemporalAccessor accessor) { } else if (isLocalDateSet) { return localDate.atStartOfDay(zoneId); } else if (isLocalTimeSet) { - return of(getLocaldate(accessor), localTime, zoneId); + return of(getLocalDate(accessor), localTime, zoneId); } else if (accessor.isSupported(ChronoField.YEAR) || accessor.isSupported(ChronoField.YEAR_OF_ERA) ) { if (accessor.isSupported(MONTH_OF_YEAR)) { return getFirstOfMonth(accessor).atStartOfDay(zoneId); @@ -1872,19 +1871,9 @@ public static ZonedDateTime from(TemporalAccessor accessor) { } } else if (accessor.isSupported(MONTH_OF_YEAR)) { // missing year, falling back to the epoch and then filling - return getLocaldate(accessor).atStartOfDay(zoneId); - } else if (accessor.isSupported(ISO.weekBasedYear())) { - if (accessor.isSupported(ISO.weekOfWeekBasedYear())) { - return Year.of(accessor.get(ISO.weekBasedYear())) - .atDay(1) - .with(ISO.weekOfWeekBasedYear(), accessor.getLong(ISO.weekOfWeekBasedYear())) - .atStartOfDay(zoneId); - } else { - return Year.of(accessor.get(ISO.weekBasedYear())) - .atDay(1) - .with(TemporalAdjusters.firstInMonth(DayOfWeek.MONDAY)) - .atStartOfDay(zoneId); - } + return getLocalDate(accessor).atStartOfDay(zoneId); + } else if (accessor.isSupported(WEEK_FIELDS.weekBasedYear())) { + return localDateFromWeekBasedDate(accessor).atStartOfDay(zoneId); } // we should not reach this piece of code, everything being parsed we should be able to @@ -1892,6 +1881,19 @@ public static ZonedDateTime from(TemporalAccessor accessor) { throw new IllegalArgumentException("temporal accessor [" + accessor + "] cannot be converted to zoned date time"); } + private static LocalDate localDateFromWeekBasedDate(TemporalAccessor accessor) { + if (accessor.isSupported(WEEK_FIELDS.weekOfWeekBasedYear())) { + return LocalDate.ofEpochDay(0) + .with(IsoFields.WEEK_BASED_YEAR, accessor.get(WEEK_FIELDS.weekBasedYear())) + .with(IsoFields.WEEK_OF_WEEK_BASED_YEAR, accessor.get(WEEK_FIELDS.weekOfWeekBasedYear())) + .with(ChronoField.DAY_OF_WEEK, 1); + } else { + return LocalDate.ofEpochDay(0) + .with(IsoFields.WEEK_BASED_YEAR, accessor.get(WEEK_FIELDS.weekBasedYear())) + .with(ChronoField.DAY_OF_WEEK, 1); + } + } + /** * extending the java.time.temporal.TemporalQueries.LOCAL_DATE implementation to also create local dates * when YearOfEra was used instead of Year. @@ -1919,15 +1921,17 @@ public String toString() { } }; - private static LocalDate getLocaldate(TemporalAccessor accessor) { - int year = getYear(accessor); - if (accessor.isSupported(MONTH_OF_YEAR)) { + private static LocalDate getLocalDate(TemporalAccessor accessor) { + if (accessor.isSupported(WEEK_FIELDS.weekBasedYear())) { + return localDateFromWeekBasedDate(accessor); + } else if (accessor.isSupported(MONTH_OF_YEAR)) { + int year = getYear(accessor); if (accessor.isSupported(DAY_OF_MONTH)) { return LocalDate.of(year, accessor.get(MONTH_OF_YEAR), accessor.get(DAY_OF_MONTH)); } else { return LocalDate.of(year, accessor.get(MONTH_OF_YEAR), 1); } - } + } else return LOCALDATE_EPOCH; } @@ -1939,6 +1943,7 @@ private static int getYear(TemporalAccessor accessor) { if(accessor.isSupported(ChronoField.YEAR_OF_ERA)){ return accessor.get(ChronoField.YEAR_OF_ERA); } + return 1970; } 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 abb23d24cb286..1ead658ba7165 100644 --- a/server/src/test/java/org/elasticsearch/common/joda/JavaJodaTimeDuellingTests.java +++ b/server/src/test/java/org/elasticsearch/common/joda/JavaJodaTimeDuellingTests.java @@ -27,7 +27,6 @@ import org.elasticsearch.test.ESTestCase; import org.joda.time.DateTime; import org.joda.time.DateTimeZone; -import org.joda.time.format.DateTimeFormat; import org.joda.time.format.ISODateTimeFormat; import java.time.LocalDateTime; 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 c5956e5c29a23..87fcc3b19b3b8 100644 --- a/server/src/test/java/org/elasticsearch/common/time/DateFormattersTests.java +++ b/server/src/test/java/org/elasticsearch/common/time/DateFormattersTests.java @@ -40,6 +40,37 @@ public class DateFormattersTests extends ESTestCase { +// public void testWeekBasedYear(){ +// DateTimeFormatter formatter = new DateTimeFormatterBuilder() +// .appendPattern("YYYY") +// .toFormatter(Locale.ROOT); +// TemporalAccessor parse = formatter.parse("2018"); +// assertTrue(parse.isSupported(WeekFields.ISO.weekBasedYear())); // never passes.. +// assertTrue(parse.isSupported(WeekFields.of(Locale.ROOT).weekBasedYear())); +// always passes, we will run with SPI CalendarDataProvider, so the one below have to pass too +// assertTrue(parse.isSupported(WeekFields.of(DayOfWeek.MONDAY,4).weekBasedYear())); // passes with SPI +// /* +// public class IsoCalendarDataProvider extends CalendarDataProvider { +// +// @Override +// public int getFirstDayOfWeek(Locale locale) { +// return Calendar.MONDAY; +// } +// +// @Override +// public int getMinimalDaysInFirstWeek(Locale locale) { +// return 4; +// } +// +// @Override +// public Locale[] getAvailableLocales() { +// return new Locale[]{Locale.ROOT}; +// } +//} +// */ +// +// +// } // this is not in the duelling tests, because the epoch millis parser in joda time drops the milliseconds after the comma // but is able to parse the rest // as this feature is supported it also makes sense to make it exact From 2eb27f5ff5949a6d0fe5d5baf6ddfa6ab55b346e Mon Sep 17 00:00:00 2001 From: Przemyslaw Gomulka Date: Fri, 18 Oct 2019 14:15:57 +0200 Subject: [PATCH 06/15] do not use ISOWeekFields --- .../common/time/DateFormatters.java | 24 +++++++------- .../script/JodaCompatibleZonedDateTime.java | 10 +++--- .../common/time/DateFormattersTests.java | 31 ------------------- .../JodaCompatibleZonedDateTimeTests.java | 4 +-- 4 files changed, 19 insertions(+), 50 deletions(-) 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 992d7c6195706..5a67820d65389 100644 --- a/server/src/main/java/org/elasticsearch/common/time/DateFormatters.java +++ b/server/src/main/java/org/elasticsearch/common/time/DateFormatters.java @@ -51,7 +51,7 @@ import static java.time.temporal.ChronoField.SECOND_OF_MINUTE; public class DateFormatters { - private static final WeekFields WEEK_FIELDS = WeekFields.of(Locale.ROOT); + public static final WeekFields WEEK_FIELDS = WeekFields.of(Locale.ROOT); private static final DateTimeFormatter TIME_ZONE_FORMATTER_NO_COLON = new DateTimeFormatterBuilder() .appendOffset("+HHmm", "Z") @@ -945,14 +945,14 @@ public class DateFormatters { * Returns a formatter for a four digit weekyear */ private static final DateFormatter STRICT_WEEKYEAR = new JavaDateFormatter("strict_weekyear", new DateTimeFormatterBuilder() - .appendValue(WeekFields.ISO.weekBasedYear(), 4, 10, SignStyle.EXCEEDS_PAD) + .appendValue(WEEK_FIELDS.weekBasedYear(), 4, 10, SignStyle.EXCEEDS_PAD) .toFormatter(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT)); private static final DateTimeFormatter STRICT_WEEKYEAR_WEEK_FORMATTER = new DateTimeFormatterBuilder() - .appendValue(WeekFields.ISO.weekBasedYear(), 4, 10, SignStyle.EXCEEDS_PAD) + .appendValue(WEEK_FIELDS.weekBasedYear(), 4, 10, SignStyle.EXCEEDS_PAD) .appendLiteral("-W") - .appendValue(WeekFields.ISO.weekOfWeekBasedYear(), 2, 2, SignStyle.NOT_NEGATIVE) + .appendValue(WEEK_FIELDS.weekOfWeekBasedYear(), 2, 2, SignStyle.NOT_NEGATIVE) .toFormatter(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT); @@ -971,7 +971,7 @@ public class DateFormatters { new DateTimeFormatterBuilder() .append(STRICT_WEEKYEAR_WEEK_FORMATTER) .appendLiteral("-") - .appendValue(WeekFields.ISO.dayOfWeek()) + .appendValue(WEEK_FIELDS.dayOfWeek()) .toFormatter(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT)); @@ -1161,7 +1161,7 @@ public class DateFormatters { * 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(WEEK_FIELDS.weekBasedYear()).toFormatter(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT)); /* @@ -1590,9 +1590,9 @@ public class DateFormatters { */ private static final DateFormatter WEEKYEAR_WEEK = new JavaDateFormatter("weekyear_week", STRICT_WEEKYEAR_WEEK_FORMATTER, new DateTimeFormatterBuilder() - .appendValue(WeekFields.ISO.weekBasedYear()) + .appendValue(WEEK_FIELDS.weekBasedYear()) .appendLiteral("-W") - .appendValue(WeekFields.ISO.weekOfWeekBasedYear()) + .appendValue(WEEK_FIELDS.weekOfWeekBasedYear()) .toFormatter(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT) ); @@ -1605,15 +1605,15 @@ public class DateFormatters { new DateTimeFormatterBuilder() .append(STRICT_WEEKYEAR_WEEK_FORMATTER) .appendLiteral("-") - .appendValue(WeekFields.ISO.dayOfWeek()) + .appendValue(WEEK_FIELDS.dayOfWeek()) .toFormatter(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT), new DateTimeFormatterBuilder() - .appendValue(WeekFields.ISO.weekBasedYear()) + .appendValue(WEEK_FIELDS.weekBasedYear()) .appendLiteral("-W") - .appendValue(WeekFields.ISO.weekOfWeekBasedYear()) + .appendValue(WEEK_FIELDS.weekOfWeekBasedYear()) .appendLiteral("-") - .appendValue(WeekFields.ISO.dayOfWeek()) + .appendValue(WEEK_FIELDS.dayOfWeek()) .toFormatter(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT) ); diff --git a/server/src/main/java/org/elasticsearch/script/JodaCompatibleZonedDateTime.java b/server/src/main/java/org/elasticsearch/script/JodaCompatibleZonedDateTime.java index 2c09456ed4302..1370f988ac7d1 100644 --- a/server/src/main/java/org/elasticsearch/script/JodaCompatibleZonedDateTime.java +++ b/server/src/main/java/org/elasticsearch/script/JodaCompatibleZonedDateTime.java @@ -23,6 +23,7 @@ import org.elasticsearch.common.SuppressForbidden; import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.common.time.DateFormatter; +import org.elasticsearch.common.time.DateFormatters; import org.elasticsearch.common.time.DateUtils; import org.joda.time.DateTime; @@ -50,7 +51,6 @@ import java.time.temporal.TemporalQuery; import java.time.temporal.TemporalUnit; import java.time.temporal.ValueRange; -import java.time.temporal.WeekFields; import java.util.Locale; import java.util.Objects; @@ -474,14 +474,14 @@ public int getSecondOfMinute() { @Deprecated public int getWeekOfWeekyear() { - logDeprecatedMethod("getWeekOfWeekyear()", "get(WeekFields.ISO.weekOfWeekBasedYear())"); - return dt.get(WeekFields.ISO.weekOfWeekBasedYear()); + logDeprecatedMethod("getWeekOfWeekyear()", "get(DateFormatters.WEEK_FIELDS.weekOfWeekBasedYear())"); + return dt.get(DateFormatters.WEEK_FIELDS.weekOfWeekBasedYear()); } @Deprecated public int getWeekyear() { - logDeprecatedMethod("getWeekyear()", "get(WeekFields.ISO.weekBasedYear())"); - return dt.get(WeekFields.ISO.weekBasedYear()); + logDeprecatedMethod("getWeekyear()", "get(DateFormatters.WEEK_FIELDS.weekBasedYear())"); + return dt.get(DateFormatters.WEEK_FIELDS.weekBasedYear()); } @Deprecated 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 87fcc3b19b3b8..c5956e5c29a23 100644 --- a/server/src/test/java/org/elasticsearch/common/time/DateFormattersTests.java +++ b/server/src/test/java/org/elasticsearch/common/time/DateFormattersTests.java @@ -40,37 +40,6 @@ public class DateFormattersTests extends ESTestCase { -// public void testWeekBasedYear(){ -// DateTimeFormatter formatter = new DateTimeFormatterBuilder() -// .appendPattern("YYYY") -// .toFormatter(Locale.ROOT); -// TemporalAccessor parse = formatter.parse("2018"); -// assertTrue(parse.isSupported(WeekFields.ISO.weekBasedYear())); // never passes.. -// assertTrue(parse.isSupported(WeekFields.of(Locale.ROOT).weekBasedYear())); -// always passes, we will run with SPI CalendarDataProvider, so the one below have to pass too -// assertTrue(parse.isSupported(WeekFields.of(DayOfWeek.MONDAY,4).weekBasedYear())); // passes with SPI -// /* -// public class IsoCalendarDataProvider extends CalendarDataProvider { -// -// @Override -// public int getFirstDayOfWeek(Locale locale) { -// return Calendar.MONDAY; -// } -// -// @Override -// public int getMinimalDaysInFirstWeek(Locale locale) { -// return 4; -// } -// -// @Override -// public Locale[] getAvailableLocales() { -// return new Locale[]{Locale.ROOT}; -// } -//} -// */ -// -// -// } // this is not in the duelling tests, because the epoch millis parser in joda time drops the milliseconds after the comma // but is able to parse the rest // as this feature is supported it also makes sense to make it exact diff --git a/server/src/test/java/org/elasticsearch/script/JodaCompatibleZonedDateTimeTests.java b/server/src/test/java/org/elasticsearch/script/JodaCompatibleZonedDateTimeTests.java index 4750ee36b0bd6..9ed651bf70a41 100644 --- a/server/src/test/java/org/elasticsearch/script/JodaCompatibleZonedDateTimeTests.java +++ b/server/src/test/java/org/elasticsearch/script/JodaCompatibleZonedDateTimeTests.java @@ -213,12 +213,12 @@ public void testSecondOfMinute() { public void testWeekOfWeekyear() { assertMethodDeprecation(() -> assertThat(javaTime.getWeekOfWeekyear(), equalTo(jodaTime.getWeekOfWeekyear())), - "getWeekOfWeekyear()", "get(WeekFields.ISO.weekOfWeekBasedYear())"); + "getWeekOfWeekyear()", "get(DateFormatters.WEEK_FIELDS.weekOfWeekBasedYear())"); } public void testWeekyear() { assertMethodDeprecation(() -> assertThat(javaTime.getWeekyear(), equalTo(jodaTime.getWeekyear())), - "getWeekyear()", "get(WeekFields.ISO.weekBasedYear())"); + "getWeekyear()", "get(DateFormatters.WEEK_FIELDS.weekBasedYear())"); } public void testYearOfCentury() { From 88dc04165c899acfdf71cf06a579d13756fcf3ac Mon Sep 17 00:00:00 2001 From: Przemyslaw Gomulka Date: Fri, 18 Oct 2019 15:42:14 +0200 Subject: [PATCH 07/15] adding tests and gradle setting --- .../elasticsearch/gradle/BuildPlugin.groovy | 2 ++ .../common/time/DateFormatters.java | 10 +++---- .../common/time/DateFormattersTests.java | 26 +++++++++++++++++++ .../common/time/JavaDateMathParserTests.java | 14 ++++++++++ 4 files changed, 47 insertions(+), 5 deletions(-) diff --git a/buildSrc/src/main/groovy/org/elasticsearch/gradle/BuildPlugin.groovy b/buildSrc/src/main/groovy/org/elasticsearch/gradle/BuildPlugin.groovy index d958cb8a69bb8..5accd45d647ba 100644 --- a/buildSrc/src/main/groovy/org/elasticsearch/gradle/BuildPlugin.groovy +++ b/buildSrc/src/main/groovy/org/elasticsearch/gradle/BuildPlugin.groovy @@ -857,6 +857,8 @@ class BuildPlugin implements Plugin { 'tests.security.manager': 'true', 'jna.nosys': 'true' + test.systemProperty ('java.locale.providers','SPI,COMPAT') + // ignore changing test seed when build is passed -Dignore.tests.seed for cacheability experimentation if (System.getProperty('ignore.tests.seed') != null) { nonInputProperties.systemProperty('tests.seed', project.property('testSeed')) 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 5a67820d65389..293be893d293a 100644 --- a/server/src/main/java/org/elasticsearch/common/time/DateFormatters.java +++ b/server/src/main/java/org/elasticsearch/common/time/DateFormatters.java @@ -1884,13 +1884,13 @@ public static ZonedDateTime from(TemporalAccessor accessor) { private static LocalDate localDateFromWeekBasedDate(TemporalAccessor accessor) { if (accessor.isSupported(WEEK_FIELDS.weekOfWeekBasedYear())) { return LocalDate.ofEpochDay(0) - .with(IsoFields.WEEK_BASED_YEAR, accessor.get(WEEK_FIELDS.weekBasedYear())) - .with(IsoFields.WEEK_OF_WEEK_BASED_YEAR, accessor.get(WEEK_FIELDS.weekOfWeekBasedYear())) - .with(ChronoField.DAY_OF_WEEK, 1); + .with(WEEK_FIELDS.weekBasedYear(), accessor.get(WEEK_FIELDS.weekBasedYear())) + .with(WEEK_FIELDS.weekOfWeekBasedYear(), accessor.get(WEEK_FIELDS.weekOfWeekBasedYear())) + .with(ChronoField.DAY_OF_WEEK, WEEK_FIELDS.getFirstDayOfWeek().getValue()); } else { return LocalDate.ofEpochDay(0) - .with(IsoFields.WEEK_BASED_YEAR, accessor.get(WEEK_FIELDS.weekBasedYear())) - .with(ChronoField.DAY_OF_WEEK, 1); + .with(WEEK_FIELDS.weekBasedYear(), accessor.get(WEEK_FIELDS.weekBasedYear())) + .with(ChronoField.DAY_OF_WEEK, WEEK_FIELDS.getFirstDayOfWeek().getValue()); } } 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 c5956e5c29a23..a3b8a732d195d 100644 --- a/server/src/test/java/org/elasticsearch/common/time/DateFormattersTests.java +++ b/server/src/test/java/org/elasticsearch/common/time/DateFormattersTests.java @@ -40,6 +40,32 @@ public class DateFormattersTests extends ESTestCase { + public void testWeekBasedDates() { + // as per WeekFields.ISO first week starts on Monday and has minimum 4 days + DateFormatter dateFormatter = DateFormatters.forPattern("YYYY-ww"); + + // first week of 2016 starts on Monday 2016-01-04 as previous week in 2016 has only 3 days + assertThat(DateFormatters.from(dateFormatter.parse("2016-01")) , + equalTo(ZonedDateTime.of(2016,01,04, 0,0,0,0,ZoneOffset.UTC))); + + // first week of 2015 starts on Monday 2014-12-29 because 4days belong to 2019 + assertThat(DateFormatters.from(dateFormatter.parse("2015-01")) , + equalTo(ZonedDateTime.of(2014,12,29, 0,0,0,0,ZoneOffset.UTC))); + + + // as per WeekFields.ISO first week starts on Monday and has minimum 4 days + dateFormatter = DateFormatters.forPattern("YYYY"); + + // first week of 2016 starts on Monday 2016-01-04 as previous week in 2016 has only 3 days + assertThat(DateFormatters.from(dateFormatter.parse("2016")) , + equalTo(ZonedDateTime.of(2016,01,04, 0,0,0,0,ZoneOffset.UTC))); + + // first week of 2015 starts on Monday 2014-12-29 because 4days belong to 2019 + assertThat(DateFormatters.from(dateFormatter.parse("2015")) , + equalTo(ZonedDateTime.of(2014,12,29, 0,0,0,0,ZoneOffset.UTC))); + } + + // this is not in the duelling tests, because the epoch millis parser in joda time drops the milliseconds after the comma // but is able to parse the rest // as this feature is supported it also makes sense to make it exact diff --git a/server/src/test/java/org/elasticsearch/common/time/JavaDateMathParserTests.java b/server/src/test/java/org/elasticsearch/common/time/JavaDateMathParserTests.java index 34903e024d05d..8a4aacb6bbd19 100644 --- a/server/src/test/java/org/elasticsearch/common/time/JavaDateMathParserTests.java +++ b/server/src/test/java/org/elasticsearch/common/time/JavaDateMathParserTests.java @@ -50,6 +50,20 @@ public void testOverridingLocaleOrZoneAndCompositeRoundUpParser() { assertDateEquals(gotMillis, "297276785531", "297276785531"); } + public void testWeekDates() { + DateFormatter formatter = DateFormatter.forPattern("YYYY-ww"); + assertDateMathEquals(formatter.toDateMathParser(), "2016-01", "2016-01-04T23:59:59.999Z", 0, true, ZoneOffset.UTC); + + formatter = DateFormatter.forPattern("YYYY"); + assertDateMathEquals(formatter.toDateMathParser(), "2016", "2016-01-04T23:59:59.999Z", 0, true, ZoneOffset.UTC); + + formatter = DateFormatter.forPattern("YYYY-ww"); + assertDateMathEquals(formatter.toDateMathParser(), "2015-01", "2014-12-29T23:59:59.999Z", 0, true, ZoneOffset.UTC); + + formatter = DateFormatter.forPattern("YYYY"); + assertDateMathEquals(formatter.toDateMathParser(), "2015", "2014-12-29T23:59:59.999Z", 0, true, ZoneOffset.UTC); + } + public void testBasicDates() { assertDateMathEquals("2014-05-30", "2014-05-30T00:00:00.000"); assertDateMathEquals("2014-05-30T20", "2014-05-30T20:00:00.000"); From ac5b55b9c705aa1fca122fe8a83aec415e7d0f55 Mon Sep 17 00:00:00 2001 From: Przemyslaw Gomulka Date: Fri, 18 Oct 2019 18:40:11 +0200 Subject: [PATCH 08/15] sql test fix --- .../elasticsearch/index/mapper/DateFieldMapperTests.java | 2 +- .../function/scalar/datetime/NonIsoDateTimeProcessor.java | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/server/src/test/java/org/elasticsearch/index/mapper/DateFieldMapperTests.java b/server/src/test/java/org/elasticsearch/index/mapper/DateFieldMapperTests.java index 579cf297fedd4..4f7fad85326f4 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/DateFieldMapperTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/DateFieldMapperTests.java @@ -235,7 +235,7 @@ public void testChangeLocale() throws IOException { mapper.parse(new SourceToParse("test", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() - .field("field", "Mi., 06 Dez. 2000 02:55:00 -0800") + .field("field", "Mi, 06 Dez 2000 02:55:00 -0800") .endObject()), XContentType.JSON)); } diff --git a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/expression/function/scalar/datetime/NonIsoDateTimeProcessor.java b/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/expression/function/scalar/datetime/NonIsoDateTimeProcessor.java index 7f916be31bdb1..6341a8b5880f4 100644 --- a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/expression/function/scalar/datetime/NonIsoDateTimeProcessor.java +++ b/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/expression/function/scalar/datetime/NonIsoDateTimeProcessor.java @@ -8,12 +8,14 @@ import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; +import org.elasticsearch.common.time.DateFormatters; import java.io.IOException; import java.time.LocalDateTime; import java.time.ZoneId; import java.time.ZonedDateTime; import java.time.temporal.ChronoField; +import java.time.temporal.WeekFields; import java.util.Calendar; import java.util.Locale; import java.util.Objects; @@ -37,8 +39,8 @@ public enum NonIsoDateTimeExtractor { cal.clear(); cal.set(ld.get(ChronoField.YEAR), ld.get(ChronoField.MONTH_OF_YEAR) - 1, ld.get(ChronoField.DAY_OF_MONTH), ld.get(ChronoField.HOUR_OF_DAY), ld.get(ChronoField.MINUTE_OF_HOUR), ld.get(ChronoField.SECOND_OF_MINUTE)); - - return cal.get(Calendar.WEEK_OF_YEAR); +// for Locale.ROOT I would expect the same behavior as ISO, if there is a different locale, then it should be used WeekFields.of(Locale) + return zdt.get(WeekFields.SUNDAY_START.weekOfWeekBasedYear());//cal.get(Calendar.WEEK_OF_YEAR); }); private final Function apply; From b7ae80c3f7b013a1e0ee11aa7bf699d639b2972b Mon Sep 17 00:00:00 2001 From: Przemyslaw Gomulka Date: Mon, 21 Oct 2019 09:58:23 +0200 Subject: [PATCH 09/15] test fix --- .../function/scalar/datetime/NonIsoDateTimeProcessor.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/expression/function/scalar/datetime/NonIsoDateTimeProcessor.java b/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/expression/function/scalar/datetime/NonIsoDateTimeProcessor.java index 6341a8b5880f4..e0ccc46c79cd3 100644 --- a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/expression/function/scalar/datetime/NonIsoDateTimeProcessor.java +++ b/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/expression/function/scalar/datetime/NonIsoDateTimeProcessor.java @@ -8,9 +8,9 @@ import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.common.time.DateFormatters; import java.io.IOException; +import java.time.DayOfWeek; import java.time.LocalDateTime; import java.time.ZoneId; import java.time.ZonedDateTime; @@ -40,7 +40,7 @@ public enum NonIsoDateTimeExtractor { cal.set(ld.get(ChronoField.YEAR), ld.get(ChronoField.MONTH_OF_YEAR) - 1, ld.get(ChronoField.DAY_OF_MONTH), ld.get(ChronoField.HOUR_OF_DAY), ld.get(ChronoField.MINUTE_OF_HOUR), ld.get(ChronoField.SECOND_OF_MINUTE)); // for Locale.ROOT I would expect the same behavior as ISO, if there is a different locale, then it should be used WeekFields.of(Locale) - return zdt.get(WeekFields.SUNDAY_START.weekOfWeekBasedYear());//cal.get(Calendar.WEEK_OF_YEAR); + return zdt.get(WeekFields.of(DayOfWeek.SUNDAY,1).weekOfWeekBasedYear());//cal.get(Calendar.WEEK_OF_YEAR); }); private final Function apply; From 207a8ea92e1d5438a9c536d1f24512bb8a47372a Mon Sep 17 00:00:00 2001 From: Przemyslaw Gomulka Date: Mon, 21 Oct 2019 11:17:45 +0200 Subject: [PATCH 10/15] fix license service test --- .../license/LicenseServiceTests.java | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/license/LicenseServiceTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/license/LicenseServiceTests.java index 1f65efc630915..57394e647c9ea 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/license/LicenseServiceTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/license/LicenseServiceTests.java @@ -17,23 +17,11 @@ /** * Due to changes in JDK9 where locale data is used from CLDR, the licence message will differ in jdk 8 and jdk9+ * https://openjdk.java.net/jeps/252 + * We run ES with -Djava.locale.providers=SPI,COMPAT and same option has to be applied when running this test from IDE */ public class LicenseServiceTests extends ESTestCase { - public void testLogExpirationWarningOnJdk9AndNewer() { - assumeTrue("this is for JDK9+", JavaVersion.current().compareTo(JavaVersion.parse("9")) >= 0); - - long time = LocalDate.of(2018, 11, 15).atStartOfDay(ZoneOffset.UTC).toInstant().toEpochMilli(); - final boolean expired = randomBoolean(); - final String message = LicenseService.buildExpirationMessage(time, expired).toString(); - if (expired) { - assertThat(message, startsWith("LICENSE [EXPIRED] ON [THU, NOV 15, 2018].\n")); - } else { - assertThat(message, startsWith("License [will expire] on [Thu, Nov 15, 2018].\n")); - } - } - - public void testLogExpirationWarningOnJdk8() { + public void testLogExpirationWarning() { assumeTrue("this is for JDK8 only", JavaVersion.current().equals(JavaVersion.parse("8"))); long time = LocalDate.of(2018, 11, 15).atStartOfDay(ZoneOffset.UTC).toInstant().toEpochMilli(); @@ -45,5 +33,4 @@ public void testLogExpirationWarningOnJdk8() { assertThat(message, startsWith("License [will expire] on [Thursday, November 15, 2018].\n")); } } - } From 963e3f18044564cb73cd96185fcfba16fd790aa3 Mon Sep 17 00:00:00 2001 From: Przemyslaw Gomulka Date: Mon, 21 Oct 2019 11:59:56 +0200 Subject: [PATCH 11/15] fix test when COMPAT is used --- .../elasticsearch/search/query/SearchQueryIT.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/server/src/test/java/org/elasticsearch/search/query/SearchQueryIT.java b/server/src/test/java/org/elasticsearch/search/query/SearchQueryIT.java index e289f565ea64c..6b375e7bf3464 100644 --- a/server/src/test/java/org/elasticsearch/search/query/SearchQueryIT.java +++ b/server/src/test/java/org/elasticsearch/search/query/SearchQueryIT.java @@ -1579,21 +1579,21 @@ public void testRangeQueryWithLocaleMapping() throws Exception { .endObject().endObject().endObject())); indexRandom(true, - client().prepareIndex("test", "type1", "1").setSource("date_field", "Mi., 06 Dez. 2000 02:55:00 -0800"), - client().prepareIndex("test", "type1", "2").setSource("date_field", "Do., 07 Dez. 2000 02:55:00 -0800") + client().prepareIndex("test", "type1", "1").setSource("date_field", "Mi, 06 Dez 2000 02:55:00 -0800"), + client().prepareIndex("test", "type1", "2").setSource("date_field", "Do, 07 Dez 2000 02:55:00 -0800") ); SearchResponse searchResponse = client().prepareSearch("test") .setQuery(QueryBuilders.rangeQuery("date_field") - .gte("Di., 05 Dez. 2000 02:55:00 -0800") - .lte("Do., 07 Dez. 2000 00:00:00 -0800")) + .gte("Di, 05 Dez 2000 02:55:00 -0800") + .lte("Do, 07 Dez 2000 00:00:00 -0800")) .get(); assertHitCount(searchResponse, 1L); searchResponse = client().prepareSearch("test") .setQuery(QueryBuilders.rangeQuery("date_field") - .gte("Di., 05 Dez. 2000 02:55:00 -0800") - .lte("Fr., 08 Dez. 2000 00:00:00 -0800")) + .gte("Di, 05 Dez 2000 02:55:00 -0800") + .lte("Fr, 08 Dez 2000 00:00:00 -0800")) .get(); assertHitCount(searchResponse, 2L); } From ac60ba35a5809150173ae1e4d521d2e91ac0fabf Mon Sep 17 00:00:00 2001 From: Przemyslaw Gomulka Date: Mon, 21 Oct 2019 13:37:18 +0200 Subject: [PATCH 12/15] test fix for master only --- .../test/search.aggregation/310_date_agg_per_day_of_week.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 index d71402d0c9017..a8952ac4e16d6 100644 --- 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 @@ -1,8 +1,8 @@ --- setup: - skip: - version: " - 7.3.99" - reason: "only backported to 7.4 (7x)" + version: " - 7.99.99" #TODO change this after backport + reason: "not backported yet" - do: indices.create: From 45fe6f72b882e568503f096e9cdae5e8aea409b7 Mon Sep 17 00:00:00 2001 From: Przemyslaw Gomulka Date: Tue, 22 Oct 2019 09:57:55 +0200 Subject: [PATCH 13/15] comment to a unit test --- .../scalar/datetime/NonIsoDateTimeProcessorTests.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/expression/function/scalar/datetime/NonIsoDateTimeProcessorTests.java b/x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/expression/function/scalar/datetime/NonIsoDateTimeProcessorTests.java index a2ee6796f668d..a1971cecad1d5 100644 --- a/x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/expression/function/scalar/datetime/NonIsoDateTimeProcessorTests.java +++ b/x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/expression/function/scalar/datetime/NonIsoDateTimeProcessorTests.java @@ -16,7 +16,6 @@ import static org.elasticsearch.xpack.sql.util.DateUtils.UTC; public class NonIsoDateTimeProcessorTests extends AbstractSqlWireSerializingTestCase { - public static NonIsoDateTimeProcessor randomNonISODateTimeProcessor() { return new NonIsoDateTimeProcessor(randomFrom(NonIsoDateTimeExtractor.values()), UTC); @@ -45,6 +44,8 @@ protected ZoneId instanceZoneId(NonIsoDateTimeProcessor instance) { public void testNonISOWeekOfYearInUTC() { NonIsoDateTimeProcessor proc = new NonIsoDateTimeProcessor(NonIsoDateTimeExtractor.WEEK_OF_YEAR, UTC); + // 1 Jan 1988 is Friday - under Sunday,1 rule it is the first week of the year (under ISO rule it would be 53 of the previous year + // hence the 5th Jan 1988 Tuesday is the second week of a year assertEquals(2, proc.process(dateTime(568372930000L))); //1988-01-05T09:22:10Z[UTC] assertEquals(6, proc.process(dateTime(981278530000L))); //2001-02-04T09:22:10Z[UTC] assertEquals(7, proc.process(dateTime(224241730000L))); //1977-02-08T09:22:10Z[UTC] @@ -94,4 +95,4 @@ public void testNonISODayOfWeekInNonUTCTimeZone() { assertEquals(6, proc.process(dateTime(333451330000L))); assertEquals(5, proc.process(dateTime(874660930000L))); } -} \ No newline at end of file +} From 4cf85c1fd1114e6a4a76918313630b4a5613c22f Mon Sep 17 00:00:00 2001 From: Przemyslaw Gomulka Date: Tue, 22 Oct 2019 10:06:23 +0200 Subject: [PATCH 14/15] todo for removing groovy systemproperty setup --- .../src/main/groovy/org/elasticsearch/gradle/BuildPlugin.groovy | 1 + 1 file changed, 1 insertion(+) diff --git a/buildSrc/src/main/groovy/org/elasticsearch/gradle/BuildPlugin.groovy b/buildSrc/src/main/groovy/org/elasticsearch/gradle/BuildPlugin.groovy index 5accd45d647ba..0dd4d2d6ac92b 100644 --- a/buildSrc/src/main/groovy/org/elasticsearch/gradle/BuildPlugin.groovy +++ b/buildSrc/src/main/groovy/org/elasticsearch/gradle/BuildPlugin.groovy @@ -857,6 +857,7 @@ class BuildPlugin implements Plugin { 'tests.security.manager': 'true', 'jna.nosys': 'true' + //TODO remove once jvm.options are added to test system properties test.systemProperty ('java.locale.providers','SPI,COMPAT') // ignore changing test seed when build is passed -Dignore.tests.seed for cacheability experimentation From c003a41a82af0dc55fa9bc3cd2c91a89a07cb72a Mon Sep 17 00:00:00 2001 From: Przemyslaw Gomulka Date: Tue, 22 Oct 2019 10:20:03 +0200 Subject: [PATCH 15/15] remove unused code --- .../scalar/datetime/NonIsoDateTimeProcessor.java | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/expression/function/scalar/datetime/NonIsoDateTimeProcessor.java b/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/expression/function/scalar/datetime/NonIsoDateTimeProcessor.java index e0ccc46c79cd3..785a815a45c2a 100644 --- a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/expression/function/scalar/datetime/NonIsoDateTimeProcessor.java +++ b/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/expression/function/scalar/datetime/NonIsoDateTimeProcessor.java @@ -11,15 +11,11 @@ import java.io.IOException; import java.time.DayOfWeek; -import java.time.LocalDateTime; import java.time.ZoneId; import java.time.ZonedDateTime; import java.time.temporal.ChronoField; import java.time.temporal.WeekFields; -import java.util.Calendar; -import java.util.Locale; import java.util.Objects; -import java.util.TimeZone; import java.util.function.Function; public class NonIsoDateTimeProcessor extends BaseDateTimeProcessor { @@ -32,15 +28,7 @@ public enum NonIsoDateTimeExtractor { return dayOfWeek == 8 ? 1 : dayOfWeek; }), WEEK_OF_YEAR(zdt -> { - // by ISO 8601 standard, the first week of a year is the first week with a majority (4 or more) of its days in January. - // Other Locales may have their own standards (see Arabic or Japanese calendars). - LocalDateTime ld = zdt.toLocalDateTime(); - Calendar cal = Calendar.getInstance(TimeZone.getTimeZone(zdt.getZone()), Locale.ROOT); - cal.clear(); - cal.set(ld.get(ChronoField.YEAR), ld.get(ChronoField.MONTH_OF_YEAR) - 1, ld.get(ChronoField.DAY_OF_MONTH), - ld.get(ChronoField.HOUR_OF_DAY), ld.get(ChronoField.MINUTE_OF_HOUR), ld.get(ChronoField.SECOND_OF_MINUTE)); -// for Locale.ROOT I would expect the same behavior as ISO, if there is a different locale, then it should be used WeekFields.of(Locale) - return zdt.get(WeekFields.of(DayOfWeek.SUNDAY,1).weekOfWeekBasedYear());//cal.get(Calendar.WEEK_OF_YEAR); + return zdt.get(WeekFields.of(DayOfWeek.SUNDAY, 1).weekOfWeekBasedYear()); }); private final Function apply;