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

ZonedDateTime/OffsetDateTime.toString return invalid ISO-8601 for years <= 1893

    XMLWordPrintable

Details

    • CSR
    • Resolution: Approved
    • P4
    • 18
    • core-libs
    • None
    • behavioral
    • minimal
    • Doc clarification only.
    • Java API
    • SE

    Description

      Summary

      Clarify the toString() methods in java.time.ZonedDateTime and java.time.OffsetDateTime classes wrt ISO 8601 conformance.

      Problem

      Current implementations of toString() method deviate from the ISO 8601 format if the offsets contain non-zero seconds. This can happen for LMT rules.

      Solution

      Clarify each toString() method, by supplying the appropriate conditions to each method.

      Specification

      Apply the following changes to each toString() method's description:

      --- a/src/java.base/share/classes/java/time/OffsetDateTime.java
      +++ b/src/java.base/share/classes/java/time/OffsetDateTime.java
      @@ -1897,7 +1897,7 @@
           /**
            * Outputs this date-time as a {@code String}, such as {@code 2007-12-03T10:15:30+01:00}.
            * <p>
      -     * The output will be one of the following ISO-8601 formats:
      +     * The output will be one of the following formats:
            * <ul>
            * <li>{@code uuuu-MM-dd'T'HH:mmXXXXX}</li>
            * <li>{@code uuuu-MM-dd'T'HH:mm:ssXXXXX}</li>
      @@ -1906,7 +1906,8 @@
            * <li>{@code uuuu-MM-dd'T'HH:mm:ss.SSSSSSSSSXXXXX}</li>
            * </ul>
            * The format used will be the shortest that outputs the full value of
      -     * the time where the omitted parts are implied to be zero.
      +     * the time where the omitted parts are implied to be zero. The output
      +     * is compatible with ISO 8601 if the seconds in the offset are zero.
            *
            * @return a string representation of this date-time, not null
            */

      and

      --- a/src/java.base/share/classes/java/time/ZonedDateTime.java
      +++ b/src/java.base/share/classes/java/time/ZonedDateTime.java
      
      @@ -2207,7 +2207,8 @@
            * <p>
            * The format consists of the {@code LocalDateTime} followed by the {@code ZoneOffset}.
            * If the {@code ZoneId} is not the same as the offset, then the ID is output.
      -     * The output is compatible with ISO-8601 if the offset and ID are the same.
      +     * The output is compatible with ISO-8601 if the offset and ID are the same,
      +     * and the seconds in the offset are zero.
            *
            * @return a string representation of this date-time, not null
            */

      Attachments

        Issue Links

          Activity

            People

              naoto Naoto Sato
              webbuggrp Webbug Group
              Brian Burkhalter, Iris Clark, Lance Andersen, Roger Riggs
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: