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

java.time: DateTimeFormatter containing "DD" fails on 3-digit day-of-year value

    Details

    • Subcomponent:
    • Resolved In Build:
      b118
    • CPU:
      x86_64
    • OS:
      windows_7

      Description

      FULL PRODUCT VERSION :
      java version "1.8.0_40"
      Java(TM) SE Runtime Environment (build 1.8.0_40-b25)
      Java HotSpot(TM) 64-Bit Server VM (build 25.40-b25, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 6.1.7601]

      A DESCRIPTION OF THE PROBLEM :
      With the new java.time API, a DateTimeFormatter containing "DD" fails on a 3-digit day-of-year value.
      So for example, "123 2010" and "003 1980" fail to be parsed with: DateTimeFormatter.ofPattern("DD yyyy")

      On the other hand, "123 2010" and "003 1980" are parsed correctly with both:
      DateTimeFormatter.ofPattern("D yyyy")
      and
      DateTimeFormatter.ofPattern("DDD yyyy")

      The javadoc says: "Up to three letters of 'D' can be specified."
      So this implies that it is legal to specify two letters of 'D' & the above is effectively a bug.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Execute the attached test case & observe the difference in exepcted and actual result.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      output is:
      true
      true
      true
      ACTUAL -
      output is:
      false
      false
      false

      REPRODUCIBILITY :
      This bug can be reproduced always.

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

      import java.time.LocalDate;
      import java.time.format.DateTimeFormatter;
      import java.time.format.DateTimeParseException;

      public class BugTest {

      private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("DD yyyy");

      public static void main(String[] args) {
      System.out.println(isParsable("003 1980"));
      System.out.println(isParsable("023 1980"));
      System.out.println(isParsable("123 1980"));
      }

      private static boolean isParsable(String input) {
      try {
      LocalDate.parse(input, FORMATTER);
      return true;
      } catch (DateTimeParseException e) {
      return false;
      }
      }

      }

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

        Issue Links

          Activity

          Hide
          akolarkunnu Abdul Kolarkunnu added a comment -
          I think this is not a bug, In the pattern the meaning of
          D - At least one digit, but it accepts as many digits as possible
          DD – Maximum two digits
          DDD – Maximum 3 digits.

          That's why it giving correct output for D and DDD, and not for DD
          Show
          akolarkunnu Abdul Kolarkunnu added a comment - I think this is not a bug, In the pattern the meaning of D - At least one digit, but it accepts as many digits as possible DD – Maximum two digits DDD – Maximum 3 digits. That's why it giving correct output for D and DDD, and not for DD
          Hide
          rriggs Roger Riggs added a comment -
          Yes, DD only parses two digits; not a bug; the use of DD with three digits of input is incorrect.
          Show
          rriggs Roger Riggs added a comment - Yes, DD only parses two digits; not a bug; the use of DD with three digits of input is incorrect.
          Hide
          scolebourne Stephen Colebourne added a comment -
          Just to note that there are similarities with JDK-8148949. The CLDR/SimpleDateFormat interpretation of "DD" is probably to output as follows:

          1 -> 01
          12 -> 12
          123 -> 123

          ie. always output, padding to width 2, and parse just like "D".

          If JDK-8148949 is going to be addressed, this probably should be too.
          Show
          scolebourne Stephen Colebourne added a comment - Just to note that there are similarities with JDK-8148949 . The CLDR/SimpleDateFormat interpretation of "DD" is probably to output as follows: 1 -> 01 12 -> 12 123 -> 123 ie. always output, padding to width 2, and parse just like "D". If JDK-8148949 is going to be addressed, this probably should be too.
          Hide
          ntv Nadeesh Tv added a comment - - edited
          Since CLDR specifying 'D' as http://unicode.org/reports/tr35/tr35-dates.html D 1..3 345 Day of year

          I would like to change the pattern in DateFormatterBuilder to

           D..D 1..3 appendValue(ChronoField.DAY_OF_YEAR, n, 19, SignStyle.NORMAL)



          @ Stephen, Roger Please share your opinion
          Show
          ntv Nadeesh Tv added a comment - - edited Since CLDR specifying 'D' as http://unicode.org/reports/tr35/tr35-dates.html D 1..3 345 Day of year I would like to change the pattern in DateFormatterBuilder to  D..D 1..3 appendValue(ChronoField.DAY_OF_YEAR, n, 19, SignStyle.NORMAL) @ Stephen, Roger Please share your opinion
          Show
          ntv Nadeesh Tv added a comment - http://mail.openjdk.java.net/pipermail/core-libs-dev/2016-April/040502.html
          Hide
          hgupdate HG Updates added a comment -
          URL: http://hg.openjdk.java.net/jdk9/dev/jdk/rev/01f92e15cf1e
          User: ntv
          Date: 2016-05-08 07:47:02 +0000
          Show
          hgupdate HG Updates added a comment - URL: http://hg.openjdk.java.net/jdk9/dev/jdk/rev/01f92e15cf1e User: ntv Date: 2016-05-08 07:47:02 +0000
          Hide
          hgupdate HG Updates added a comment -
          URL: http://hg.openjdk.java.net/jdk9/jdk9/jdk/rev/01f92e15cf1e
          User: lana
          Date: 2016-05-11 16:05:08 +0000
          Show
          hgupdate HG Updates added a comment - URL: http://hg.openjdk.java.net/jdk9/jdk9/jdk/rev/01f92e15cf1e User: lana Date: 2016-05-11 16:05:08 +0000

            People

            • Assignee:
              ntv Nadeesh Tv
              Reporter:
              webbuggrp Webbug Group
            • Votes:
              0 Vote for this issue
              Watchers:
              7 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: