Language locales have different calendars than country locales in 9+

naoto.sato at oracle.com naoto.sato at oracle.com
Fri Jul 31 22:40:25 UTC 2020


On 7/31/20 3:08 PM, Bernd Eckenfels wrote:
> Hello,
> 
> Is there a good description what calendar is actually used for a language-only locale? Is there a typical association of calendars with locales or is it a global default? If the unicode data does not have such a value, would it be better to fall back to the next provider (like COMPAT)?

In CLDR, those calendar data are tied to territory:

https://unicode-org.github.io/cldr-staging/charts/37/supplemental/territory_information.html

So if the locale is language only, it falls back to the default values. 
There is a provider fallback mechanism for non-supported locales, i.e., 
if xx-YY is not supproted by CLDR, it will look into the next locale 
provider such as COMPAT, but as "de-DE/de" are supported by CLDR, it 
won't look into COMPAT. This is because CLDR itself has its own 
fallback, such as de-DE -> de -> ROOT, and if COMPAT cuts in between, 
unpredictable behavior may occur.

> 
> I understand that it was hinted at in the release notes, but this is a very severe change in major locales - at least I was not expecting that (as opposed to textual changes to timezones or month names).

Yes, I understand. However JDK is simply using CLDR's data as they are.

> 
> I am a bit burned by using compat flags as they might get removed in the futur, is there any plans on how long the JRE locale provider will be available, I.e. ist it s safe bet to use it?

Cannot comment on the future, but not likely in the near future, as some 
features such as collation is not implemented in CLDR provider.

Naoto

> 
> Gruss
> Bernd
> 
> 
> --
> http://bernd.eckenfels.net
> ________________________________
> Von: naoto.sato at oracle.com <naoto.sato at oracle.com>
> Gesendet: Friday, July 31, 2020 11:24:33 PM
> An: Bernd Eckenfels <ecki at zusammenkunft.net>; core-libs-dev <core-libs-dev at openjdk.java.net>
> Betreff: Re: Language locales have different calendars than country locales in 9+
> 
> Hi Bernd,
> 
> As you pointed out, the change you see here is the result of this change
> in JDK9:
> 
> https://bugs.openjdk.java.net/browse/JDK-8008577
> 
> where the default locale provider was switched to CLDR. Although we
> don't describe those behavior changes in the spec (as it is regarded as
> l10n changes which may differ across implementations), it was generally
> noted in JDK9's release note:
> 
> ---
> As a result, users may see differences in locale sensitive services
> behavior and/or translations. [1]
> ---
> 
> You can use the COMPAT provider through the java.locale.providers system
> property if you need the pre-JDK9 behavior.
> 
> HTH,
> Naoto
> 
> [1] https://www.oracle.com/java/technologies/javase/v9-issues-relnotes.html
> 
> On 7/31/20 1:17 PM, Bernd Eckenfels wrote:
>> Hello,
>>
>> Just wanted to mention a thing I noticed when switching from 8 to 11. I knew before that the Locale data provider has changed, and I could notice that for example in the writing style for abbreviated words in dates. However something I did not expect is, that the definition of Calemdars change as well.
>>
>> Locale.GERMAN and Locale.GERMANY construct different calemdars under Java 11 with CLDR as opposed to Java 8 or Java 11 with compat. The most notably changes are when calculating calendar weeks (min days in first week) or the start of a week (Sunday vs. Monday).
>>
>> I haven't seen that explicitely mentioned and I also wonder if this should be mentioned in the Locale JavaDoc that language locales and country locales might differ severely in that aspect.
>>
>>
>> GERMANY:
>> Calendar.minDays 4 java.util.GregorianCalendar[time=1596218932830,areFieldsSet=true,areAllFieldsSet=true,lenient=true,zone=…,firstDayOfWeek=2,minimalDaysInFirstWeek=4,ERA=1,YEAR=2020,MONTH=6,WEEK_OF_YEAR=31,WEEK_OF_MONTH=5,DAY_OF_MONTH=31,DAY_OF_YEAR=213,DAY_OF_WEEK=6,DAY_OF_WEEK_IN_MONTH=5,AM_PM=1,HOUR=8,HOUR_OF_DAY=20,MINUTE=8,SECOND=52,MILLISECOND=830,ZONE_OFFSET=3600000,DST_OFFSET=3600000]
>> 11.0.1+13-LTS de_DE 2011-01-01 2010-52
>>
>> GERMAN
>> Calendar.minDays 1 java.util.GregorianCalendar[time=1596218932879,areFieldsSet=true,areAllFieldsSet=true,lenient=true,zone=...,firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,YEAR=2020,MONTH=6,WEEK_OF_YEAR=31,WEEK_OF_MONTH=5,DAY_OF_MONTH=31,DAY_OF_YEAR=213,DAY_OF_WEEK=6,DAY_OF_WEEK_IN_MONTH=5,AM_PM=1,HOUR=8,HOUR_OF_DAY=20,MINUTE=8,SECOND=52,MILLISECOND=879,ZONE_OFFSET=3600000,DST_OFFSET=3600000]
>> 11.0.1+13-LTS de    2011-01-01 2011-01
>>
>> Sample code:
>>
>>       Date d = new Date(1293843600000L);
>>
>>       Locale l = Locale.GERMANY;
>>
>>       Calendar c = Calendar.getInstance(l);
>>       System.out.println("Calendar.minDays "+ c.getMinimalDaysInFirstWeek() + " " + c);
>>
>>       SimpleDateFormat sdf = newSimpleDateFormat("yyyy-MM-DD YYYY-ww", l);
>>       System.out.printf("%s %-5s %s%n", System.getProperty("java.vm.version"), l, sdf.format(d));
>>
>>
>> --
>> http://bernd.eckenfels.net
>>


More information about the core-libs-dev mailing list