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

ZonedDateTime could not parse timezone name with zh_CN locale correctly.

    XMLWordPrintable

Details

    • Bug
    • Resolution: Duplicate
    • P4
    • None
    • 11
    • core-libs

    Description

      JDK: jdk 11 build 12, 21
      Env: Windows 7

      ZonedDateTime could not parse timezone name with zh_CN locale correctly. java.time.format.DateTimeParseException is thrown. But specify -Djava.locale.providers=CLDR explicitly, it works.

      REGRESSION: Last worked with jdk 11 build 11.

      Error log:
      Exception in thread "main" java.time.format.DateTimeParseException: Text '2015 069 12 13 北美太平洋时间' could not be parsed at index 15
              at java.base/java.time.format.DateTimeFormatter.parseResolved0(DateTimeFormatter.java:2046)
              at java.base/java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1948)
              at java.base/java.time.ZonedDateTime.parse(ZonedDateTime.java:598)
              at Test3.test_appendZoneText_parseGenericTimeZonePatterns(Test3.java:30)
              at Test3.main(Test3.java:15)

      Run following test with jdk 11 build 11,12, 21, below is the result:
      jdk 11 build 11:
          java Test3: Pass
          java -Djava.locale.providers=CLDR Test3: Pass
      jdk 11 build 12:
          java Test3: throw an exception
          java -Djava.locale.providers=CLDR Test3: Pass
      jdk 11 build 21:
          java Test3: throw an exception
          java -Djava.locale.providers=CLDR Test3: Pass

      ---------- BEGIN SOURCE ----------
      import java.time.LocalDateTime;
      import java.time.Month;
      import java.time.ZoneId;
      import java.time.ZonedDateTime;
      import java.time.format.DateTimeFormatter;
      import java.time.format.DateTimeFormatterBuilder;
      import java.util.Locale;

      public class Test3 {
          public static void main(String[] args){
              Locale.setDefault(Locale.forLanguageTag("zh-CN"));
              for(Object[] arr : data_parseGenericTimeZonePatterns()){
                  test_appendZoneText_parseGenericTimeZonePatterns((String)arr[0], (LocalDateTime)arr[1], (ZoneId)arr[2], (String)arr[3]);
              }
          }
          private static Object[][] data_parseGenericTimeZonePatterns() {
              return new Object[][] {
                      {"yyyy DDD HH mm vvvv", LocalDateTime.of(2015, Month.MARCH, 10, 12, 13), ZoneId.of("America/Los_Angeles"),
                              "2015 069 12 13 \u5317\u7f8e\u592a\u5e73\u6d0b\u65f6\u95f4"},
                      {"yyyy DDD HH mm vvvv", LocalDateTime.of(2015, Month.NOVEMBER, 10, 12, 13), ZoneId.of("America/Los_Angeles"),
                              "2015 314 12 13 \u5317\u7f8e\u592a\u5e73\u6d0b\u65f6\u95f4"},
              };
          }

          private static void test_appendZoneText_parseGenericTimeZonePatterns(
                  String pattern, LocalDateTime ldt, ZoneId zId, String input) {
              DateTimeFormatter df = new DateTimeFormatterBuilder().appendPattern(pattern).toFormatter();
              ZonedDateTime expected = ZonedDateTime.parse(input, df);
              ZonedDateTime actual = ZonedDateTime.of(ldt, zId);
          }
      }
      ---------- END SOURCE ----------

      FREQUENCY: always

      Attachments

        Issue Links

          Activity

            People

              naoto Naoto Sato
              dzhou Dora Zhou (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: