Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8042131

DateTimeFormatterBuilder Mapped-values do not work for JapaneseDate

XMLWordPrintable

    • b19

        DateTimeFormatterBuilder Mapped-values do not work for JapaneseDate. They
        work for LocalDate.

        The problem occurs with both toFormatter(Locale.US) and toFormatter(Locale.JAPANESE).


        TESTCASE
        --------
        import java.text.*;
        import java.util.*;
        import java.time.*;
        import java.time.format.*;
        import java.time.temporal.*;
        import java.time.chrono.*;

        public class FormatterBuilderTest_ja_jp{
            public static void main(String[] args) {
                String str;
                DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder();
                Map<Long, String> yearMap = new HashMap<>();
                yearMap.put(1L, "1st");

                Map<Long, String> monthMap = new HashMap<>();
                for (long l = 1; l <= 12; l++) {
                    monthMap.put(l, l+"gatsu");
                }

                builder.appendText(ChronoField.ERA, TextStyle.FULL);
                builder.appendLiteral(' ');
                builder.appendText(ChronoField.YEAR_OF_ERA, yearMap);
                builder.appendLiteral('-');
                builder.appendText(ChronoField.MONTH_OF_YEAR, monthMap);

                DateTimeFormatter formatter = builder.toFormatter(Locale.US);
                // DateTimeFormatter formatter =
        builder.toFormatter(Locale.JAPANESE);

                JapaneseDate date = JapaneseDate.of(JapaneseEra.HEISEI, 1, 4, 1);
                str = date.format(formatter);
                System.out.println(str);

                LocalDate local = LocalDate.of( 1, 4, 1);
                str = local.format(formatter);
                System.out.println(str);
            }
        }

        REPRODUCTION INSTRUCTIONS
        -------------------------
        Compile and run the testcase.

        Observed output:
        > Heisei 1-April <== Problem
        > Anno Domini 1st-4gatsu

        Expected output:
        > Heisei 1st-4gatsu
        > Anno Domini 1st-4gatsu

              naoto Naoto Sato
              asaha Abhijit Saha
              Votes:
              0 Vote for this issue
              Watchers:
              9 Start watching this issue

                Created:
                Updated:
                Resolved: