Hi Umaoka-san,

Yes, it's a known problem. I filed a bug report:

https://bugs.openjdk.java.net/browse/JDK-8054214

Thanks,
Masayoshi

On 9/19/2014 8:44 AM, Yoshito Umaoka wrote:
In July, Okutsu-san sent a review request for JDK-8048123.
I found this is very useful as temporary workaround until new Java patch embedding the new era.

However, I think I found one issue. If you use java.util.Calendar, with locale ja-JP-u-ca-japanese, it seems to work as you expect. However, with new java.time package, era field prints out integer value of era. Below is an example code which reproduce the issue.

// Pseudo new era
// 1602288000000L => 2020-10-10 / Heisei 32-10-10
System.setProperty("jdk.calendar.japanese.supplemental.era",
"name=新元号,abbr=N,since=1602288000000");

// The day before the switch over
ChronoLocalDate date = JapaneseDate.of(JapaneseEra.HEISEI, 32, 10, 9);

DateTimeFormatter fmt = DateTimeFormatter.ofLocalizedDate(FormatStyle.FULL)
.withChronology(JapaneseChronology.INSTANCE).withLocale(Locale.JAPAN);

System.out.println(fmt.format(date)); // Output: "平成32年10月9日"

// Plus one day
date = date.plus(1, ChronoUnit.DAYS);

System.out.println(fmt.format(date)); // Output: "31年10月10日"


The output above becomes "31年10月10日", which is actually composed by Era "3" + Year-Month-Day "1年10月10日". So, java.time.format.DateTimeFormatter does not use era name defined in the property, instead, use era's integer value.

In addition to this, the equivalent code with old java.util.Calendar below:

// Pseudo new era
// 1602288000000L => 2020-10-10 / Heisei 32-10-10
System.setProperty("jdk.calendar.japanese.supplemental.era",
"name=新元号,abbr=N,since=1602288000000");

Locale loc = Locale.forLanguageTag("ja-JP-u-ca-japanese");
Calendar cal = Calendar.getInstance(loc);
cal.set(32, 10 - 1, 9); // Set October 9, Heisei 32

DateFormat fmt = DateFormat.getDateInstance(DateFormat.FULL, loc);
System.out.println(fmt.format(cal.getTime())); // Output: 平成32年10月9日

// plus one day
cal.add(Calendar.DATE, 1);

System.out.println(fmt.format(cal.getTime())); // Output: 新元号元年10 月10日

prints out "元年" (which is correct) instead of "1年" (which is acceptable, but not correct). This is not related to new era switch over actually, but it should be fixed.

Are you aware of these issues?

-Yoshito



Reply via email to