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

Cannot parse JapaneseDate string with DateTimeFormatterBuilder Mapped-values

    XMLWordPrintable

Details

    Backports

      Description

        A DESCRIPTION OF THE PROBLEM :
        At JDK-8042131, the behaivor of DateTimeformatter.format was fixed.
        However, parse method is still wrong.

        I guess the anonymouse class in DateTimeFormatterBuilder.appendText(TemporalField field, Map<Long, String> textLookup) should override getTextIterator(TemporalField field, TextStyle style, Locale locale) too.


        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        Compile and run the test case.

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        {Era=2, YearOfEra=1, MonthOfYear=4},Japanese
        ACTUAL -
        Exception in thread "main" java.time.format.DateTimeParseException: Text 'Heisei 1st-4gatsu' could not be parsed at index 8
        at java.base/java.time.format.DateTimeFormatter.parseResolved0(DateTimeFormatter.java:2046)
        at java.base/java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1874)
        at FormatterBuilderTest_ja_jp.main(FormatterBuilderTest_ja_jp.java:26)

        ---------- BEGIN SOURCE ----------

        import java.util.*;
        import java.time.format.*;
        import java.time.temporal.*;
        import java.time.chrono.*;

        public class FormatterBuilderTest_ja_jp {

            public static void main(String[] args) {
                Map<Long, String> years = Map.of(1L, "1st");
                Map<Long, String> monthes = new HashMap<>();
                for (long l = 1; l <= 12; l++) {
                    monthes.put(l, l + "gatsu");
                }
                DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder()
                        .appendText(ChronoField.ERA, TextStyle.FULL)
                        .appendLiteral(' ')
                        .appendText(ChronoField.YEAR_OF_ERA, years)
                        .appendLiteral('-')
                        .appendText(ChronoField.MONTH_OF_YEAR, monthes);

                DateTimeFormatter formatter = builder.toFormatter(Locale.US)
                        .withChronology(JapaneseChronology.INSTANCE);

        // System.out.println(formatter.parse("Heisei 1-April"));
                System.out.println(formatter.parse("Heisei 1st-4gatsu"));
            }
        }

        ---------- END SOURCE ----------

        FREQUENCY : always


        Attachments

          Issue Links

            Activity

              People

                naoto Naoto Sato
                webbuggrp Webbug Group
                Votes:
                0 Vote for this issue
                Watchers:
                10 Start watching this issue

                Dates

                  Created:
                  Updated:
                  Resolved: