From eff43864b34ab2be2eae4e9ac0e780d34fab57b3 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Sun, 15 May 2022 15:22:50 -0400 Subject: [PATCH] [LANG-1680] FastDateFormat does not support the 'L'-Pattern from SimpleDateFormat. - Use final. - Fix typos. - In-line single use local variables. --- src/changes/changes.xml | 1 + .../apache/commons/lang3/time/DateUtils.java | 4 +- .../commons/lang3/time/DateUtilsTest.java | 58 +++++++++---------- .../lang3/time/FastDateFormatTest.java | 4 +- 4 files changed, 33 insertions(+), 34 deletions(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index c2f6ee637..e239b4f69 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -80,6 +80,7 @@ The type attribute can be add,update,fix,remove. Make final mappingFunction variable #876. Remove unnecessary variable creations #882. Minor changes #769. + FastDateFormat does not support the 'L'-Pattern from SimpleDateFormat. Add EnumUtils.getEnumSystemProperty(...). Add TriConsumer. diff --git a/src/main/java/org/apache/commons/lang3/time/DateUtils.java b/src/main/java/org/apache/commons/lang3/time/DateUtils.java index 493136e51..25a8275d8 100644 --- a/src/main/java/org/apache/commons/lang3/time/DateUtils.java +++ b/src/main/java/org/apache/commons/lang3/time/DateUtils.java @@ -1860,9 +1860,9 @@ public class DateUtils { // Unfortunately standalone month names are not available in DateFormatSymbols, // so we have to extract them. final Calendar calendar = Calendar.getInstance(locale); - Map displayNames = calendar.getDisplayNames(Calendar.MONTH, style, locale); + final Map displayNames = calendar.getDisplayNames(Calendar.MONTH, style, locale); final String[] monthNames = new String[displayNames.size()]; - for (Map.Entry entry: displayNames.entrySet()) { + for (final Map.Entry entry: displayNames.entrySet()) { monthNames[entry.getValue()] = entry.getKey(); } return monthNames; diff --git a/src/test/java/org/apache/commons/lang3/time/DateUtilsTest.java b/src/test/java/org/apache/commons/lang3/time/DateUtilsTest.java index 9e71e9873..7e9b40fad 100644 --- a/src/test/java/org/apache/commons/lang3/time/DateUtilsTest.java +++ b/src/test/java/org/apache/commons/lang3/time/DateUtilsTest.java @@ -1697,40 +1697,38 @@ public class DateUtilsTest { @Test public void testGetStandaloneLongMonthNames() { - Locale testLocale = Locale.GERMAN; - String[] standaloneShortMonths = DateUtils.getStandaloneLongMonths(testLocale); - assertEquals(12, standaloneShortMonths.length); - assertEquals("Januar", standaloneShortMonths[0]); - assertEquals("Februar", standaloneShortMonths[1]); - assertEquals("M\u00e4rz", standaloneShortMonths[2]); - assertEquals("April", standaloneShortMonths[3]); - assertEquals("Mai", standaloneShortMonths[4]); - assertEquals("Juni", standaloneShortMonths[5]); - assertEquals("Juli", standaloneShortMonths[6]); - assertEquals("August", standaloneShortMonths[7]); - assertEquals("September", standaloneShortMonths[8]); - assertEquals("Oktober", standaloneShortMonths[9]); - assertEquals("November", standaloneShortMonths[10]); - assertEquals("Dezember", standaloneShortMonths[11]); + final String[] monthNames = DateUtils.getStandaloneLongMonths(Locale.GERMAN); + assertEquals(12, monthNames.length); + assertEquals("Januar", monthNames[0]); + assertEquals("Februar", monthNames[1]); + assertEquals("M\u00e4rz", monthNames[2]); + assertEquals("April", monthNames[3]); + assertEquals("Mai", monthNames[4]); + assertEquals("Juni", monthNames[5]); + assertEquals("Juli", monthNames[6]); + assertEquals("August", monthNames[7]); + assertEquals("September", monthNames[8]); + assertEquals("Oktober", monthNames[9]); + assertEquals("November", monthNames[10]); + assertEquals("Dezember", monthNames[11]); } @Test public void testGetStandaloneShortMonthNames() { - Locale testLocale = Locale.GERMAN; - String[] standaloneShortMonths = DateUtils.getStandaloneShortMonths(testLocale); - assertEquals(12, standaloneShortMonths.length); - assertEquals("Jan", standaloneShortMonths[0]); - assertEquals("Feb", standaloneShortMonths[1]); - assertEquals("M\u00e4r", standaloneShortMonths[2]); - assertEquals("Apr", standaloneShortMonths[3]); - assertEquals("Mai", standaloneShortMonths[4]); - assertEquals("Jun", standaloneShortMonths[5]); - assertEquals("Jul", standaloneShortMonths[6]); - assertEquals("Aug", standaloneShortMonths[7]); - assertEquals("Sep", standaloneShortMonths[8]); - assertEquals("Okt", standaloneShortMonths[9]); - assertEquals("Nov", standaloneShortMonths[10]); - assertEquals("Dez", standaloneShortMonths[11]); + final String[] monthNames = DateUtils.getStandaloneShortMonths(Locale.GERMAN); + assertEquals(12, monthNames.length); + assertEquals("Jan", monthNames[0]); + assertEquals("Feb", monthNames[1]); + assertEquals("M\u00e4r", monthNames[2]); + assertEquals("Apr", monthNames[3]); + assertEquals("Mai", monthNames[4]); + assertEquals("Jun", monthNames[5]); + assertEquals("Jul", monthNames[6]); + assertEquals("Aug", monthNames[7]); + assertEquals("Sep", monthNames[8]); + assertEquals("Okt", monthNames[9]); + assertEquals("Nov", monthNames[10]); + assertEquals("Dez", monthNames[11]); } } diff --git a/src/test/java/org/apache/commons/lang3/time/FastDateFormatTest.java b/src/test/java/org/apache/commons/lang3/time/FastDateFormatTest.java index 725cd295f..68271ef25 100644 --- a/src/test/java/org/apache/commons/lang3/time/FastDateFormatTest.java +++ b/src/test/java/org/apache/commons/lang3/time/FastDateFormatTest.java @@ -329,7 +329,7 @@ public class FastDateFormatTest { @Test public void testStandaloneShortMonthForm() { final TimeZone utc = FastTimeZone.getGmtTimeZone(); - Instant testInstant = LocalDate.of(1970, 9, 15).atStartOfDay(ZoneId.of("UTC")).toInstant(); + final Instant testInstant = LocalDate.of(1970, 9, 15).atStartOfDay(ZoneId.of("UTC")).toInstant(); final Date date = Date.from(testInstant); String dateAsString = FastDateFormat.getInstance("yyyy-LLL-dd", utc, Locale.GERMAN).format(date); @@ -345,7 +345,7 @@ public class FastDateFormatTest { @Test public void testStandaloneLongMonthForm() { final TimeZone utc = FastTimeZone.getGmtTimeZone(); - Instant testInstant = LocalDate.of(1970, 9, 15).atStartOfDay(ZoneId.of("UTC")).toInstant(); + final Instant testInstant = LocalDate.of(1970, 9, 15).atStartOfDay(ZoneId.of("UTC")).toInstant(); final Date date = Date.from(testInstant); String dateAsString = FastDateFormat.getInstance("yyyy-LLLL-dd", utc, Locale.GERMAN).format(date);