DateTimeFormatter month pattern letter “L” fails

“stand-alone” month name

I believe ‘L’ is meant for languages that use a different word for the month itself versus the way it is used in a date. For example:

Locale russian = Locale.forLanguageTag("ru");

asList("MMMM", "LLLL").forEach(ptrn -> 
    System.out.println(ptrn + ": " + ofPattern(ptrn, russian).format(Month.MARCH))
);

Output:

MMMM: марта
LLLL: Март

There shouldn’t be any reason to use ‘L’ instead of ‘M’ when parsing a date.

I tried the following to see which locales support stand-alone month name formatting:

Arrays.stream(Locale.getAvailableLocales())
    .collect(partitioningBy(
                loc -> "3".equals(Month.MARCH.getDisplayName(FULL_STANDALONE, loc)),
                mapping(Locale::getDisplayLanguage, toCollection(TreeSet::new))
    )).entrySet().forEach(System.out::println);

The following languages get a locale-specific stand-alone month name from ‘LLLL’:

Catalan, Chinese, Croatian, Czech, Finnish, Greek, Hungarian, Italian, Lithuanian, Norwegian, Polish, Romanian, Russian, Slovak, Turkish, Ukrainian

All other languages get “3” as a stand-alone name for March.

Leave a Comment