8180469: Wrong short form text for supplemental Japanese era

Reviewed-by: rriggs
This commit is contained in:
Naoto Sato 2017-08-31 08:35:16 -07:00
parent 7eb1d1757a
commit 183e692a6e
2 changed files with 16 additions and 12 deletions

View File

@ -87,9 +87,15 @@ public class CalendarNameProviderImpl extends CalendarNameProvider implements Av
Era[] jeras = CalendarSystem.forName("japanese").getEras();
if (jeras.length == value) {
Era supEra = jeras[value - 1]; // 0-based index
return style == LONG ?
supEra.getName() :
supEra.getAbbreviation();
if (javatime) {
return getBaseStyle(style) == NARROW_FORMAT ?
supEra.getAbbreviation() :
supEra.getName();
} else {
return (style & LONG) != 0 ?
supEra.getName() :
supEra.getAbbreviation();
}
}
}
return null;

View File

@ -25,7 +25,7 @@ import java.text.SimpleDateFormat;
import java.time.chrono.JapaneseChronology;
import java.time.chrono.JapaneseDate;
import java.time.chrono.JapaneseEra;
import java.time.format.DateTimeFormatterBuilder;
import java.time.format.DateTimeFormatter;
import java.time.format.TextStyle;
import java.util.Calendar;
import java.util.Date;
@ -166,17 +166,15 @@ public class SupplementalJapaneseEraTest {
errors++;
}
// test long/abbreviated names with java.time.format
got = new DateTimeFormatterBuilder()
.appendPattern("GGGG")
.appendLiteral(" ")
.appendPattern("G")
.toFormatter(Locale.US)
// test full/short/narrow names with java.time.format
got = DateTimeFormatter
.ofPattern("GGGG G GGGGG")
.withLocale(Locale.US)
.withChronology(JapaneseChronology.INSTANCE)
.format(jdate);
expected = NEW_ERA_NAME + " " + NEW_ERA_ABBR;
expected = NEW_ERA_NAME + " " + NEW_ERA_NAME + " " + NEW_ERA_ABBR;
if (!expected.equals(got)) {
System.err.printf("java.time formatter long/abbr names: got=\"%s\", expected=\"%s\"%n", got, expected);
System.err.printf("java.time formatter full/short/narrow names: got=\"%s\", expected=\"%s\"%n", got, expected);
errors++;
}
}