Skip to content

Commit

Permalink
Deprecate week_year in favour of weekyear date format (#63307)
Browse files Browse the repository at this point in the history
week_year is misleading as the formatter only has a weekyear. A field
corresponding to 'Y'. 'weekyear' should be used instead

relates #60707
  • Loading branch information
pgomulka authored Oct 7, 2020
1 parent 431cbde commit 233d843
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 5 deletions.
7 changes: 6 additions & 1 deletion server/src/main/java/org/elasticsearch/common/joda/Joda.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
*/
Expand Down Expand Up @@ -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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -870,7 +871,9 @@ private static String randomJodaAndJavaSupportedTimezone(List<String> 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> formatNames = EnumSet.complementOf(EnumSet.of(FormatNames.WEEK_YEAR));
return randomFrom(formatNames).getName();
}

/**
Expand Down

0 comments on commit 233d843

Please sign in to comment.