We're updating the issue view to help you get more done. 

ambiguous era values in japanese calendar

Description

Some calendar fields might have ambiguous values depending on the language:
One example is the japanese calendar. The emperor Shōwa exists 3 times. When parsing a date string, the first emperor is used. Most probably the last one is correct.

The following source shows the example:

1 2 3 4 5 6 7 8 9 10 11 12 com.ibm.icu.text.DateFormat dfGreg = new com.ibm.icu.text.SimpleDateFormat("yyyy/MM/dd", Locale.US); Date dt = dfGreg.parse("1972/03/01", new ParsePosition(0)); com.ibm.icu.text.DateFormat df = com.ibm.icu.text.DateFormat.getInstance(new com.ibm.icu.util.JapaneseCalendar(), Locale.US); if (df instanceof com.ibm.icu.text.SimpleDateFormat) { ((com.ibm.icu.text.SimpleDateFormat)df).applyPattern("G yyyy/MM/dd hh:mm:ss a z"); } String format = df.format(dt); // format: "Shōwa 0047/03/01 12:00:00 AM GMT+01:00" dt = df.parse(format, new ParsePosition(0)); String formatAfterParse = dfGreg.format(dt); // formatAfterParse: "0880/03/01"

This could be resolved by changing the method matchString. Changing
"if (length > bestMatchLength ..."
to
"if (length >= bestMatchLength ..."
would have the result, that always the last matching is used.
Of could finding new unique emperor names would be the best solution.

Best regards
Christian

Environment

Status

Assignee

TracBot

Reporter

TracBot

Labels

tracCreated

Apr 14, 2009, 3:48 PM

tracOwner

jspieth

tracProject

ICU4J

tracReporter

anonymous

tracStatus

accepted

Components

Priority

assess