js-joda/js-joda-locale

Supprot for CLDR 'Stand-Alone' forms

zyavva opened this issue · 2 comments

I'm missing support for CLDR 'Stand-Alone' forms as specified at http://cldr.unicode.org/translation/date-time#TOC-Stand-Alone-vs.-Format-Styles .
As far i could investigate, 'js-joda-locale' properly recognize defined by pattern 'standalone' styles e.g. "SHORT" vs '"SHORT_STANDALONE" but this informatin is lost while reading values form 'cldrjs'.
Package 'cldr-data' seems to have all necessary data.
My use case for Catalan language is ( ES 6 ):

import { DateTimeFormatter, LocalDate } from 'js-joda';
import { Locale } from '@js-joda/locale';


const catalanShortStandaloneMonth = DateTimeFormatter.ofPattern('EEE d LLL y').withLocale(new Locale('ca'));
const catalanShortMonth = DateTimeFormatter.ofPattern('EEE d MMM y').withLocale(new Locale('ca'));

LocalDate.of(2018, 1, 1).format(catalanShortStandaloneMonth); // expecting 'dl. 1 gen. 2018'
LocalDate.of(2018, 2, 6).format(catalanShortStandaloneMonth); // expecting 'dt. 6 febr. 2018'
LocalDate.of(2018, 3, 7).format(catalanShortStandaloneMonth); // expecting 'dc. 7 març 2018'

LocalDate.of(2018, 1, 1).format(catalanShortMonth); // expecting 'dl. 1 de gen. 2018'
LocalDate.of(2018, 2, 6).format(catalanShortMonth); // expecting 'dt. 6 de febr. 2018'
LocalDate.of(2018, 3, 7).format(catalanShortMonth); // expecting 'dc. 7 de març 2018'

Btw I'm not sure if I'm properly using 'Locale' API.

Hi @wojtek-wlodarczyk

thanks for using js-joda-locale and thanks for your report ...

i thought i had all the JSR-310 patterns implemented, maybe we are just using the wrong field ... i'll take a look at your issue, but i currenlty don't have much time ...

Just one question... i can't seem to find your LLL pattern in https://js-joda.github.io/js-joda/class/src/format/DateTimeFormatter.js~DateTimeFormatter.html#static-method-ofPattern description. What output would you expect and can you find it documented in the JSR-310 docs?
Maybe we are just missing the implementation here?

Regards, Pattrick

Hi

Thanks for prompt response and for maintaining those libraries - it saved my sanity while implementing time manipulation in JS ;)
In purpose of this implementation I had to migrate some existing functionality from Moment.js and it was already using those "standalone abbreviated" forms of months in Catalan.

After brief look I couldn't find anything explicit about this case in JSR-310 specification, but for sure DateTimeFormatter API from specification defines 'L' symbol:

M/L     month-of-year               number/text       7; 07; Jul; July; J

Testing with JRE 8 gives expected results:

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Locale;

import static java.util.Arrays.asList;

public class Test {

    public static void main(String[] args) {
        DateTimeFormatter catalanShortStandaloneMonth =
                DateTimeFormatter.ofPattern("EEE d LLL y").withLocale(new Locale("ca"));
        DateTimeFormatter catalanShortMonth =
                DateTimeFormatter.ofPattern("EEE d MMM y").withLocale(new Locale("ca"));

        List<LocalDate> dates = asList(
                LocalDate.of(2018, 1, 1),
                LocalDate.of(2018, 2, 6),
                LocalDate.of(2018, 3, 7)
        );

        dates.forEach(date -> {
            System.out.println(date.format(catalanShortMonth));
            System.out.println(date.format(catalanShortStandaloneMonth));
        });
    }
}

// dl. 1 de gen. 2018
// dl. 1 gen. 2018
// dt. 6 de febr. 2018
// dt. 6 feb. 2018
// dc. 7 de març 2018
// dc. 7 març 2018

So for now I'm not sure if specification justify this issue - I'll take closer look.

From the implementation point of view: although API docs at:

https://js-joda.github.io/js-joda/class/src/format/DateTimeFormatter.js~DateTimeFormatter.html#static-method-ofPattern

doesn't mention L symbol, it seems that it is resolved to different "style" than M by js-joda code - in my test case those "styles" are: SHORT and SHORT_STANDALONE.

As far I have investigated, those "styles" are keys in map read form cldrjs API - issue is that both keys maps to the same values.

I would expect that those "keys" "leads" to different paths in cldr-data files:

For example in:

/cldr-data/main/ca/ca-gregorian.json

I can find desired values under paths:

["main"]["ca"]["dates"]["calendars"]["gregorian"]["months"]["format"]["abbreviated"]["1"] == "de gen."
["main"]["ca"]["dates"]["calendars"]["gregorian"]["months"]["stand-alone"]["abbreviated"]["1"] == "gen."

Anyway, totally understand limited time on Your side.

I'll try to check it closer when I have some more time.

Regards
Wojtek