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

Incorrect DateTimeFormatter format with JDK9

XMLWordPrintable

      FULL PRODUCT VERSION :
      openjdk version "9.0.4"
      OpenJDK Runtime Environment (build 9.0.4+11)
      OpenJDK 64-Bit Server VM (build 9.0.4+11, mixed mode)

      -and-

      java version "9.0.4"
      Java(TM) SE Runtime Environment (build 9.0.4+11)
      Java HotSpot(TM) 64-Bit Server VM (build 9.0.4+11, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      OSX 10.12.6

      A DESCRIPTION OF THE PROBLEM :
      DateTimeFormatter is now adding COMMA between date and time parts.

      Inconsistent with java8 and javadoc

      (https://docs.oracle.com/javase/9/docs/api/java/time/format/DateTimeFormatter.html#ofLocalizedDateTime-java.time.format.FormatStyle-java.time.format.FormatStyle-)

      REGRESSION. Last worked in version 8u161

      ADDITIONAL REGRESSION INFORMATION:
      java version "1.8.0_161"
      Java(TM) SE Runtime Environment (build 1.8.0_161-b12)
      Java HotSpot(TM) 64-Bit Server VM (build 25.161-b12, mixed mode)

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
          void 'dtf test'() {
              given:
              def testDate = LocalDateTime.parse("2009-06-03T07:03:47")
              def expected = "6/3/09 7:03 AM"
              def dtf = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT, FormatStyle.SHORT).withLocale(Locale.US)

              when:
              def actual = dtf.format(testDate)
              // actual == "6/3/09, 7:03 AM" note comma between date/time
              
              then:
              actual == expected
          }

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      test passes with java8
      ACTUAL -
      Condition not satisfied:

      actual == expected
      | | |
      | | 6/3/09 7:03 AM
      | false
      | 1 difference (93% similarity)
      | 6/3/09(,) 7:03 AM
      | 6/3/09(-) 7:03 AM
      6/3/09, 7:03 AM

      Expected :6/3/09 7:03 AM

      Actual :6/3/09, 7:03 AM

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
          void 'dtf test'() {
              given:
              def testDate = LocalDateTime.parse("2009-06-03T07:03:47")
              def expected = "6/3/09 7:03 AM"
              def dtf = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT, FormatStyle.SHORT).withLocale(Locale.US)

              when:
              def actual = dtf.format(testDate)
              // actual == "6/3/09, 7:03 AM" note comma between date/time
              
              then:
              actual == expected
          }
      ---------- END SOURCE ----------

            psonal Pallavi Sonal (Inactive)
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: