From c023825113ac128a63d221be027840785f447dc2 Mon Sep 17 00:00:00 2001 From: Russ Cam Date: Wed, 5 Aug 2020 16:08:04 +1000 Subject: [PATCH] Use weekyear for consistency Relates: #60044 and https://github.com/elastic/elasticsearch/pull/59555#pullrequestreview-461250791 With the removal of camel case format names, the format name for `WEEK_YEAR` has been set to `week_year`, but this is inconsistent with the usage in other formats related to weekyear e.g. ``` WEEKYEAR_WEEK("weekyear_week"), WEEKYEAR_WEEK_DAY("weekyear_week_day"), ``` This commit - replaces the snakecase format `week_year` with `weekyear` - renames enum constants from `WEEK_YEAR` to `WEEKYEAR` for consistency with other constants related to weekyear. --- .../org/elasticsearch/common/time/DateFormatters.java | 8 ++++---- .../java/org/elasticsearch/common/time/FormatNames.java | 4 ++-- .../common/joda/JavaJodaTimeDuellingTests.java | 8 ++++---- 3 files changed, 10 insertions(+), 10 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 216955a493d92..e8002c509d37b 100644 --- a/server/src/main/java/org/elasticsearch/common/time/DateFormatters.java +++ b/server/src/main/java/org/elasticsearch/common/time/DateFormatters.java @@ -1170,7 +1170,7 @@ public class DateFormatters { /* * Returns a formatter for a four digit weekyear. (YYYY) */ - private static final DateFormatter WEEK_YEAR = new JavaDateFormatter("week_year", + private static final DateFormatter WEEKYEAR = new JavaDateFormatter("weekyear", new DateTimeFormatterBuilder().appendValue(WEEK_FIELDS_ROOT.weekBasedYear()).toFormatter(Locale.ROOT) .withResolverStyle(ResolverStyle.STRICT)); @@ -1720,9 +1720,9 @@ public class DateFormatters { return WEEK_DATE_TIME; } else if (FormatNames.WEEK_DATE_TIME_NO_MILLIS.matches(input)) { return WEEK_DATE_TIME_NO_MILLIS; - } else if (FormatNames.WEEK_YEAR.matches(input)) { - return WEEK_YEAR; - } else if (FormatNames.WEEK_YEAR_WEEK.matches(input)) { + } else if (FormatNames.WEEKYEAR.matches(input)) { + return WEEKYEAR; + } else if (FormatNames.WEEKYEAR_WEEK.matches(input)) { return WEEKYEAR_WEEK; } else if (FormatNames.WEEKYEAR_WEEK_DAY.matches(input)) { return WEEKYEAR_WEEK_DAY; 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 e7af4e992252a..544ebd11eaa01 100644 --- a/server/src/main/java/org/elasticsearch/common/time/FormatNames.java +++ b/server/src/main/java/org/elasticsearch/common/time/FormatNames.java @@ -58,8 +58,8 @@ public enum FormatNames { WEEK_DATE("week_date"), WEEK_DATE_TIME("week_date_time"), WEEK_DATE_TIME_NO_MILLIS("week_date_time_no_millis"), - WEEK_YEAR("week_year"), - WEEK_YEAR_WEEK("weekyear_week"), + WEEKYEAR("weekyear"), + WEEKYEAR_WEEK("weekyear_week"), WEEKYEAR_WEEK_DAY("weekyear_week_day"), YEAR("year"), YEAR_MONTH("year_month"), 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 eabc4da859d3b..77a328e1b6448 100644 --- a/server/src/test/java/org/elasticsearch/common/joda/JavaJodaTimeDuellingTests.java +++ b/server/src/test/java/org/elasticsearch/common/joda/JavaJodaTimeDuellingTests.java @@ -501,9 +501,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"); @@ -778,7 +778,7 @@ public void testSamePrinterOutput() { assertSamePrinterOutput("week_date", javaDate, jodaDate); assertSamePrinterOutput("week_date_time", javaDate, jodaDate); assertSamePrinterOutput("week_date_time_no_millis", javaDate, jodaDate); - assertSamePrinterOutput("week_year", javaDate, jodaDate); + assertSamePrinterOutput("weekyear", javaDate, jodaDate); assertSamePrinterOutput("weekyear_week", javaDate, jodaDate); assertSamePrinterOutput("weekyear_week_day", javaDate, jodaDate); assertSamePrinterOutput("year", javaDate, jodaDate);