diff --git a/server/src/main/java/org/elasticsearch/common/joda/Joda.java b/server/src/main/java/org/elasticsearch/common/joda/Joda.java index f797d6e5dda14..3604c4ae1ebb4 100644 --- a/server/src/main/java/org/elasticsearch/common/joda/Joda.java +++ b/server/src/main/java/org/elasticsearch/common/joda/Joda.java @@ -148,7 +148,12 @@ public static JodaDateFormatter forPattern(String input) { formatter = ISODateTimeFormat.weekDateTime(); } else if ("weekDateTimeNoMillis".equals(input) || "week_date_time_no_millis".equals(input)) { formatter = ISODateTimeFormat.weekDateTimeNoMillis(); - } else if ("weekyear".equals(input) || "week_year".equals(input)) { + } else if ("week_year".equals(input)) { + deprecationLogger.getOrCompute() + .deprecate("week_year_format_name", "Format name \"week_year\" is deprecated and will be removed in a future version. " + + "Use \"weekyear\" format instead"); + formatter = ISODateTimeFormat.weekyear(); + } else if ("weekyear".equals(input) ) { formatter = ISODateTimeFormat.weekyear(); } else if ("weekyearWeek".equals(input) || "weekyear_week".equals(input)) { formatter = ISODateTimeFormat.weekyearWeek(); 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 216955a493d92..3a1d35a6af706 100644 --- a/server/src/main/java/org/elasticsearch/common/time/DateFormatters.java +++ b/server/src/main/java/org/elasticsearch/common/time/DateFormatters.java @@ -1174,6 +1174,9 @@ public class DateFormatters { new DateTimeFormatterBuilder().appendValue(WEEK_FIELDS_ROOT.weekBasedYear()).toFormatter(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT)); + private static final DateFormatter WEEKYEAR = new JavaDateFormatter("weekyear", + new DateTimeFormatterBuilder().appendValue(WEEK_FIELDS_ROOT.weekBasedYear()).toFormatter(Locale.ROOT) + .withResolverStyle(ResolverStyle.STRICT)); /* * Returns a formatter for a four digit year. (uuuu) */ @@ -1721,7 +1724,12 @@ public class DateFormatters { } else if (FormatNames.WEEK_DATE_TIME_NO_MILLIS.matches(input)) { return WEEK_DATE_TIME_NO_MILLIS; } else if (FormatNames.WEEK_YEAR.matches(input)) { + deprecationLogger.getOrCompute() + .deprecate("week_year_format_name", "Format name \"week_year\" is deprecated and will be removed in a future version. " + + "Use \"weekyear\" format instead"); return WEEK_YEAR; + } else if (FormatNames.WEEKYEAR.matches(input)) { + return WEEKYEAR; } else if (FormatNames.WEEK_YEAR_WEEK.matches(input)) { return WEEKYEAR_WEEK; } else if (FormatNames.WEEKYEAR_WEEK_DAY.matches(input)) { diff --git a/server/src/main/java/org/elasticsearch/common/time/FormatNames.java b/server/src/main/java/org/elasticsearch/common/time/FormatNames.java index 09be339c56d69..a710d5f95269c 100644 --- a/server/src/main/java/org/elasticsearch/common/time/FormatNames.java +++ b/server/src/main/java/org/elasticsearch/common/time/FormatNames.java @@ -59,6 +59,7 @@ public enum FormatNames { WEEK_DATE_TIME("week_date_time"), WEEK_DATE_TIME_NO_MILLIS("week_date_time_no_millis"), WEEK_YEAR("week_year"), + WEEKYEAR("weekyear"), WEEK_YEAR_WEEK("weekyear_week"), WEEKYEAR_WEEK_DAY("weekyear_week_day"), YEAR("year"), 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 4721f7797634d..03398645261b0 100644 --- a/server/src/test/java/org/elasticsearch/common/joda/JavaJodaTimeDuellingTests.java +++ b/server/src/test/java/org/elasticsearch/common/joda/JavaJodaTimeDuellingTests.java @@ -502,9 +502,9 @@ public void testDuellingFormatsValidParsing() { assertSameDate("2012-1-31", "year_month_day"); assertSameDate("2012-12-1", "year_month_day"); - assertSameDate("2018", "week_year"); - assertSameDate("1", "week_year"); - assertSameDate("2017", "week_year"); + assertSameDate("2018", "weekyear"); + assertSameDate("1", "weekyear"); + assertSameDate("2017", "weekyear"); assertSameDate("2018-W29", "weekyear_week"); assertSameDate("2018-W1", "weekyear_week"); diff --git a/test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java b/test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java index 9d81bc7f5725d..efeec57cd20d6 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java @@ -128,6 +128,7 @@ import java.util.Arrays; import java.util.Collection; import java.util.Collections; +import java.util.EnumSet; import java.util.HashSet; import java.util.LinkedHashMap; import java.util.List; @@ -870,7 +871,9 @@ private static String randomJodaAndJavaSupportedTimezone(List zoneIds) { * Generate a random valid date formatter pattern. */ public static String randomDateFormatterPattern() { - return randomFrom(FormatNames.values()).getName(); + //WEEKYEAR should be used instead of WEEK_YEAR + EnumSet formatNames = EnumSet.complementOf(EnumSet.of(FormatNames.WEEK_YEAR)); + return randomFrom(formatNames).getName(); } /**