8210633: Cannot parse JapaneseDate string with DateTimeFormatterBuilder Mapped-values
Reviewed-by: scolebourne, rriggs
--- a/src/java.base/share/classes/java/time/format/DateTimeFormatterBuilder.java Tue Sep 25 13:31:51 2018 -0700
+++ b/src/java.base/share/classes/java/time/format/DateTimeFormatterBuilder.java Tue Sep 25 13:57:24 2018 -0700
@@ -802,7 +802,13 @@
return store.getText(value, style);
}
@Override
- public Iterator<Entry<String, Long>> getTextIterator(TemporalField field, TextStyle style, Locale locale) {
+ public Iterator<Entry<String, Long>> getTextIterator(Chronology chrono,
+ TemporalField field, TextStyle style, Locale locale) {
+ return store.getTextIterator(style);
+ }
+ @Override
+ public Iterator<Entry<String, Long>> getTextIterator(TemporalField field,
+ TextStyle style, Locale locale) {
return store.getTextIterator(style);
}
};
--- a/test/jdk/java/time/test/java/time/format/TestDateTimeFormatterBuilderWithLocale.java Tue Sep 25 13:31:51 2018 -0700
+++ b/test/jdk/java/time/test/java/time/format/TestDateTimeFormatterBuilderWithLocale.java Tue Sep 25 13:57:24 2018 -0700
@@ -74,9 +74,11 @@
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeFormatterBuilder;
import java.time.format.FormatStyle;
+import java.time.format.ResolverStyle;
import java.time.LocalDate;
import java.time.temporal.ChronoField;
import java.time.temporal.Temporal;
+import java.time.temporal.TemporalAccessor;
import java.util.HashMap;
import java.util.Locale;
@@ -133,13 +135,22 @@
@Test(dataProvider="mapTextLookup")
public void test_appendText_mapTextLookup(ChronoLocalDate date, Locale locale) {
- final String new1st = "1st";
- Map<Long, String> yearMap = new HashMap<>();
- yearMap.put(1L, new1st);
- builder.appendText(ChronoField.YEAR_OF_ERA, yearMap);
+ final String firstYear = "firstYear";
+ final String firstMonth = "firstMonth";
+ final String firstYearMonth = firstYear + firstMonth;
+ final long first = 1L;
- String actual = date.format(builder.toFormatter(locale));
- assertEquals(actual, new1st);
+ DateTimeFormatter formatter = builder
+ .appendText(ChronoField.YEAR_OF_ERA, Map.of(first, firstYear))
+ .appendText(ChronoField.MONTH_OF_YEAR, Map.of(first, firstMonth))
+ .toFormatter(locale)
+ .withResolverStyle(ResolverStyle.STRICT);
+
+ assertEquals(date.format(formatter), firstYearMonth);
+
+ TemporalAccessor ta = formatter.parse(firstYearMonth);
+ assertEquals(ta.getLong(ChronoField.YEAR_OF_ERA), first);
+ assertEquals(ta.getLong(ChronoField.MONTH_OF_YEAR), first);
}