<i18n dev> JDK-8042131: Proposal of Mapped-values formatter for non-IsoChronology
Roger Riggs
roger.riggs at oracle.com
Fri Jun 15 14:38:01 UTC 2018
Hi,
A good suggestion to reconsider, I re-opened the issue.
I have not looked closely to see if/where the spec needs to be changed.
Thanks, Roger
On 6/15/18 5:30 AM, Stephen Colebourne wrote:
> From the looks of it, this is a perfectly reasonable enhancement.
> Sadly I can't sponsor it as I'm not a committer.
>
> Stephen
>
>
> On 15 June 2018 at 10:10, Toshio 5 Nakamura <TOSHIONA at jp.ibm.com> wrote:
>> Hello core-libs and i18n folks,
>>
>> We'd like to request to reconsider JDK-8042131,
>> "DateTimeFormatterBuilder Mapped-values do not work for JapaneseDate".
>> The report was posted by our team long time ago, and was closed as not an
>> issue.
>> At that time, the feature was for only IsoChronology.
>>
>> Now, I found the attached patch can activate the mapped-values formatter
>> for
>> non-IsoChronology.
>>
>> Additionally, the Japanese new era will be expected in May 2019. The first
>> year of
>> each era has a special expression in Japanese, "U+5143 U+5e74" (Gannen).
>> java.util.JapaneseImperialCalendar uses this expression.
>> We'd like to use the expression with JapaneseChronology by mapped-values
>> formatter as an option.
>>
>> Can we have a sponsor of this proposal?
>>
>> --sample usage of Japanese new era--
>> DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder();
>> Map<Long, String> yearMap = new HashMap<>();
>> yearMap.put(1L, "\u5143");
>> builder.appendText(ChronoField.ERA, TextStyle.FULL)
>> .appendText(ChronoField.YEAR_OF_ERA, yearMap)
>> .appendLiteral("\u5e74");
>> ---------------
>>
>> Report:
>> https://bugs.openjdk.java.net/browse/JDK-8042131
>>
>> Patch:
>> --- old/src/java.base/share/classes/java/time/format/DateTimeFormatterBuilder.java 2018-06-15 17:39:11.489303979 +0900
>> +++ new/src/java.base/share/classes/java/time/format/DateTimeFormatterBuilder.java 2018-06-15 17:39:11.157303972 +0900
>> @@ -793,6 +793,11 @@
>> final LocaleStore store = new LocaleStore(map);
>> DateTimeTextProvider provider = new DateTimeTextProvider() {
>> @Override
>> + public String getText(Chronology chrono, TemporalField field,
>> + long value, TextStyle style, Locale locale) {
>> + return store.getText(value, style);
>> + }
>> + @Override
>> public String getText(TemporalField field, long value, TextStyle style, Locale locale) {
>> return store.getText(value, style);
>> }
>> --- old/test/jdk/java/time/test/java/time/format/TestDateTimeFormatterBuilderWithLocale.java 2018-06-15 17:39:12.664304007 +0900
>> +++ new/test/jdk/java/time/test/java/time/format/TestDateTimeFormatterBuilderWithLocale.java 2018-06-15 17:39:12.298303999 +0900
>> @@ -67,14 +67,21 @@
>> import java.time.chrono.Chronology;
>> import java.time.chrono.IsoChronology;
>> import java.time.chrono.JapaneseChronology;
>> +import java.time.chrono.JapaneseEra;
>> import java.time.chrono.MinguoChronology;
>> +import java.time.chrono.ThaiBuddhistChronology;
>> +import java.time.chrono.ChronoLocalDate;
>> import java.time.format.DateTimeFormatter;
>> import java.time.format.DateTimeFormatterBuilder;
>> import java.time.format.FormatStyle;
>> import java.time.LocalDate;
>> import java.time.temporal.Temporal;
>> +import java.time.temporal.ChronoField;
>> +import static java.time.temporal.ChronoUnit.YEARS;
>>
>> import java.util.Locale;
>> +import java.util.Map;
>> +import java.util.HashMap;
>>
>> import static org.testng.Assert.assertEquals;
>>
>> @@ -115,6 +122,31 @@
>> }
>>
>> //-----------------------------------------------------------------------
>> + @DataProvider(name="mappedPatterns")
>> + Object[][] localizedMappedPatterns() {
>> + return new Object[][] {
>> + {IsoChronology.INSTANCE.date(1,1,1), Locale.ENGLISH},
>> + {JapaneseChronology.INSTANCE.date(JapaneseEra.HEISEI,
>> + 1,1,8), Locale.ENGLISH},
>> + {MinguoChronology.INSTANCE.date(1,1,1), Locale.ENGLISH},
>> + {ThaiBuddhistChronology.INSTANCE.date(1,1,1), Locale.ENGLISH},
>> + };
>> + }
>> +
>> + @Test(dataProvider="mappedPatterns")
>> + public void test_getLocalizedMappedPattern(ChronoLocalDate date, Locale locale) {
>> + final String new1st = "1st";
>> + Map<Long, String> yearMap = new HashMap<>();
>> + yearMap.put(1L, new1st);
>> + DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder();
>> + builder.appendText(ChronoField.YEAR_OF_ERA, yearMap);
>> +
>> + String actual = date.format(builder.toFormatter(locale));
>> + assertEquals(actual, new1st);
>> + }
>> +
>> +
>> + //-----------------------------------------------------------------------
>> @DataProvider(name="localePatterns")
>> Object[][] localizedDateTimePatterns() {
>> return new Object[][] {
>>
>> ---
>> Best regards,
>> Toshio Nakamura, IBM Japan
More information about the core-libs-dev
mailing list