<i18n dev> Additional infomation for JDK-8048123

Mitsuru Matsushima m-matsushima at bk.jp.nec.com
Thu Jun 22 08:06:51 UTC 2017


Sorry, I did not know the mailing list strips out attachments.
(Thanks for telling me, Martin.)

I try to write down the test code and comparison table image below.

At the Comparison table, I added the "Supplemental Era" behavior and "Expected?" behavior.
Japanese usually use '平' or 'H' for abbreviated name of "平成".
Thus, I think it's useful that the both of them are usable.
So I added the "Expected?" behavior.
(Ah, however it seems difficult that different behavior for short form...)
(I don't know why CLDR don't describe wide name for Japanese era and why describe wide name as abbreviated name.)

Comparison table:
=======================================
                  | SimpleDateFormat| DateTimeFormatter        
                  |--------|--------|--------|--------|--------
                  | Full   | Short  | Full   | Short  | Narrow 
------------------|--------|--------|--------|--------|--------
 COMPAT           | 平成   | H      | 平成   | H      | H      
 CLDR             | 平成   | 平成   | 平成   | 平成   | H      
 HOST             | 平成   | 平     | 平成   | 平     | 平成   
------------------|--------|--------|--------|--------|--------
 Supplemental Era | NewEra | N.E    | NewEra | N.E    | N.E    
------------------|--------|--------|--------|--------|--------
 Expected?        | 平成   | H      | 平成   | 平     | H      
=======================================


Test code: 
Execute with java.locale.provider system property.
=======================================
public class SupplementalEraTest2 {

    public static void main(String... args) {
        System.out.println("java.locale.providers="
                + System.getProperty("java.locale.providers"));
        // set supplemental era
        System.setProperty(
                "jdk.calendar.japanese.supplemental.era",
                "name=NewEra,abbr=N.E,since=1546300800000");

        final int[][] dateSrcs = {
            //{1989, 1, 7}, {1989, 1, 8}, // Heisei before and after
            {2018, 12, 31}, {2019, 1, 1}, // NewEra before and after
        };

        System.out.println(">>>>> SimpleDateFormat");
        printWithSimpleDateFormat(dateSrcs);

        System.out.println(">>>>> DateTimeFormatter");
        printWithDateTimeFormatter(dateSrcs);
    }

    private static void printWithSimpleDateFormat(int[][] dateSrcs) {
        final Locale jpLocale = new Locale("ja", "JP", "JP");
        final Calendar cal = Calendar.getInstance();
        final Date[] dates = Arrays.stream(dateSrcs)
                .map((int[] d) -> {  // first month is 0
                    cal.set(d[0], d[1] - 1, d[2], 0, 0, 0);
                    return cal.getTime();
                }).toArray(Date[]::new);
        System.out.println("---Full format");
        SimpleDateFormat fmtLong = new SimpleDateFormat(
                "GGGG", jpLocale);
        Arrays.stream(dates).map(fmtLong::format).forEach(System.out::println);
        System.out.println("---Short format");
        SimpleDateFormat fmtShort = new SimpleDateFormat(
                "G", jpLocale);
        Arrays.stream(dates).map(fmtShort::format).forEach(System.out::println);
    }

    private static void printWithDateTimeFormatter(int[][] dateSrcs) {
        final Locale jpLocale = new Locale("ja", "JP", "JP");
        final LocalDate[] lDates = Arrays.stream(dateSrcs)
                .map((int[] d) -> LocalDate.of(d[0], d[1], d[2]))
                .toArray(LocalDate[]::new);
        System.out.println("---Full format");
        final DateTimeFormatter fmtrFull = DateTimeFormatter.ofPattern("GGGG")
                .withChronology(JapaneseChronology.INSTANCE).withLocale(jpLocale);
        Arrays.stream(lDates).map(fmtrFull::format).forEach(System.out::println);

        System.out.println("---Short format");
        DateTimeFormatter fmtrShort = DateTimeFormatter.ofPattern("G")
                .withChronology(JapaneseChronology.INSTANCE).withLocale(jpLocale);
        Arrays.stream(lDates).map(fmtrShort::format).forEach(System.out::println);

        System.out.println("---Narrow format");
        DateTimeFormatter fmtrNarrow = DateTimeFormatter.ofPattern("GGGGG")
                .withChronology(JapaneseChronology.INSTANCE).withLocale(jpLocale);
        Arrays.stream(lDates).map(fmtrNarrow::format).forEach(System.out::println);
    }
}
=======================================

Mitsuru

> -----Original Message-----
> From: Matsushima Mitsuru(松島 充)
> Sent: Wednesday, June 21, 2017 9:40 PM
> To: i18n-dev at openjdk.java.net
> Cc: Matsushima Mitsuru(松島 充) <m-matsushima at bk.jp.nec.com>
> Subject: Additional infomation for JDK-8048123
> 
> Hi.
> 
> I reported JDK-8048123 before.
> But I notice this issue is more complex.
> 
> It's unable to attach files at the web form, so I post to ml.
> 
> At first, I thought it's a issue of the fix for JDK-8173423.
> However, I think it's a issue of CalendarNameProviders now.
> 
> I tested attatched AupplementalEraTest2.java with 3 providers (COMPAT, CLDR and HOST).
> And I compared the result as dateFormatComparison.png.
> 
> I think SHORT and NARROW should be same form.
> Thus, I think the values of follows are wrong.
> 
>  -At SimpleDateFormat:
>    SHORT form of CLDR
>  -At DateTimeFormatter:
>    NARROW form of COMPAT and CLDR
>    Narrow form of HOST
> 
> 
> TEST ENVIRONMENT:
>  JDK: 9-ea+174
>  OS: Microsoft Windows [Version 6.1.7601] Japanese
> 
> 
> Mitsuru



More information about the i18n-dev mailing list