Skip to content

Commit

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

relates elastic#60707
  • Loading branch information
pgomulka committed Oct 6, 2020
1 parent d04edcd commit 2fcc09f
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 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

0 comments on commit 2fcc09f

Please sign in to comment.