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

Remove minimum 4 digit requirement from Year.parse()

    XMLWordPrintable

Details

    • Enhancement
    • Status: Resolved
    • P4
    • Resolution: Fixed
    • None
    • 16
    • core-libs
    • None
    • b02

    Description

      As per this question [1], the method Year.parse(CharSequence) is unclear in its behaviour for years before 1000.

      When the method was written, the code for parsing was copied from other methods, such as LocalDate.parse(CharSequence). In those other methods, there is always a month, and often more fields, thus the year is forced to be four digits or more. But for Year.parse(CharSequence) this restriction is not as essential.

      Option 1: Change the method spec to add a line something like "The year must have at least four digits, thus year '981' must be passed in as '0981'."

      Option 2: Change the behaviour to allow any number of digits.

      Note that option 2 would mean that Year.parse("999") would work, but YearMonth.parse("999-05") would not. But I still think this is the right choice. We don't have a Month.parse(CharSequence) method (which is an oversight), but if we did that method would not require the month to be zero prefixed.

      [1] https://stackoverflow.com/questions/61907458/jsr310-year-parse-throws-datetimeparseexception-with-values-1000

      Attachments

        Issue Links

          Activity

            People

              naoto Naoto Sato
              scolebourne Stephen Colebourne
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: