-
Bug
-
Resolution: Unresolved
-
P4
-
23, 24, 25
-
generic
-
generic
This piece:
```
var df = DateFormat.getDateInstance(DateFormat.FULL, new Locale("ja", "JP", "JP"));
Calendar cal = Calendar.getInstance();
cal.clear();
cal.set(2019, Calendar.MAY, 1);
System.out.println(df.format(cal.getTime()));
```
displays "令和1年5月1日水曜日"
which should be "令和元年5月1日水曜日"
This seems to be a regression caused by removing COMPAT, as the date format for the Japanese calendar differs between COMPAT and CLDR (as to year, "yyyy" and "y" respectively). JapaneseImperialCalendar uses "元" only for Calendar.LONG pattern, thus the latter (CLDR) is considered SHORT
One workaround is to explicitly specify patterns with 4 letters of "y", such as
```
var df = new SimpleDateFormat("GGGGyyyy'年'M'月'd'日'EEEE", new Locale("ja", "JP", "JP));
```
The bug is inherently there before the COMPAT removal. If the locale was created with `Locale.forLanguageTag("ja-u-ca-japanese")`, this fails prior to COMPAT removal, because for "ja" locale, CLDR is always chosen, while "ja_JP_JP" locale is only supported by COMPAT.
```
var df = DateFormat.getDateInstance(DateFormat.FULL, new Locale("ja", "JP", "JP"));
Calendar cal = Calendar.getInstance();
cal.clear();
cal.set(2019, Calendar.MAY, 1);
System.out.println(df.format(cal.getTime()));
```
displays "令和1年5月1日水曜日"
which should be "令和元年5月1日水曜日"
This seems to be a regression caused by removing COMPAT, as the date format for the Japanese calendar differs between COMPAT and CLDR (as to year, "yyyy" and "y" respectively). JapaneseImperialCalendar uses "元" only for Calendar.LONG pattern, thus the latter (CLDR) is considered SHORT
One workaround is to explicitly specify patterns with 4 letters of "y", such as
```
var df = new SimpleDateFormat("GGGGyyyy'年'M'月'd'日'EEEE", new Locale("ja", "JP", "JP));
```
The bug is inherently there before the COMPAT removal. If the locale was created with `Locale.forLanguageTag("ja-u-ca-japanese")`, this fails prior to COMPAT removal, because for "ja" locale, CLDR is always chosen, while "ja_JP_JP" locale is only supported by COMPAT.
- caused by
-
JDK-8174269 Remove COMPAT locale data provider from JDK
-
- Resolved
-