[LANG-1680] FastDateFormat does not support the 'L'-Pattern from

SimpleDateFormat.

- Use final.
- Fix typos.
- In-line single use local variables.
This commit is contained in:
Gary Gregory 2022-05-15 15:22:50 -04:00
parent 127869e88f
commit eff43864b3
4 changed files with 33 additions and 34 deletions

View File

@ -80,6 +80,7 @@ The <action> type attribute can be add,update,fix,remove.
<action type="fix" dev="ggregory" due-to="Arturo Bernal">Make final mappingFunction variable #876.</action>
<action type="fix" dev="ggregory" due-to="Arturo Bernal">Remove unnecessary variable creations #882.</action>
<action type="fix" dev="ggregory" due-to="Arturo Bernal">Minor changes #769.</action>
<action issue="LANG-1680" type="fix" dev="ggregory" due-to="Michael Krause, Steve Bosman, Gary Gregory">FastDateFormat does not support the 'L'-Pattern from SimpleDateFormat.</action>
<!-- ADD -->
<action type="add" dev="ggregory" due-to="Gary Gregory">Add EnumUtils.getEnumSystemProperty(...).</action>
<action type="add" dev="ggregory" due-to="Gary Gregory">Add TriConsumer.</action>

View File

@ -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<String, Integer> displayNames = calendar.getDisplayNames(Calendar.MONTH, style, locale);
final Map<String, Integer> displayNames = calendar.getDisplayNames(Calendar.MONTH, style, locale);
final String[] monthNames = new String[displayNames.size()];
for (Map.Entry<String, Integer> entry: displayNames.entrySet()) {
for (final Map.Entry<String, Integer> entry: displayNames.entrySet()) {
monthNames[entry.getValue()] = entry.getKey();
}
return monthNames;

View File

@ -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]);
}
}

View File

@ -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);