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

DateTimeFormatter.appendZoneOrOffsetId() fails to resolve a ZoneOffset for OffsetDateTime

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 8
    • Fix Version/s: 9
    • Component/s: core-libs
    • Labels:
      None
    • Subcomponent:
    • Resolved In Build:
      b55

      Backports

        Description

        public class Test {

          private static final DateTimeFormatter FORMAT = new DateTimeFormatterBuilder()
            .appendValue(ChronoField.YEAR, 1, 9, SignStyle.NORMAL)
            .appendLiteral('-')
            .appendValue(ChronoField.MONTH_OF_YEAR, 1, 2, SignStyle.NEVER)
            .appendLiteral('-')
            .appendValue(ChronoField.DAY_OF_MONTH, 1, 2, SignStyle.NEVER)
            .optionalStart() // time component
            .appendLiteral(' ')
            .appendValue(ChronoField.HOUR_OF_DAY, 1, 2, SignStyle.NEVER)
            .appendLiteral(':')
            .appendValue(ChronoField.MINUTE_OF_HOUR, 1, 2, SignStyle.NEVER)
            .appendLiteral(':')
            .appendValue(ChronoField.SECOND_OF_MINUTE, 1, 2, SignStyle.NEVER)
            .optionalStart() // nanos
            .appendLiteral('.')
            .appendFraction(ChronoField.NANO_OF_SECOND, 1, 9, false)
            .optionalEnd() // nanos
            .optionalEnd() // time componont
            .optionalStart() // zone or offset
            .appendLiteral(' ')
            .appendZoneOrOffsetId() //TODO doesn't work as it should due to bug in JRE
            .optionalEnd() // zone or offset
            .toFormatter();

          public static void main(String[] args) throws Exception {
            for (String s : new String[] {"1970-01-01 00:00:00 +00:00", "1999-12-31 23:59:59 -08:00"}) {
              try {
                System.out.println("\t"+OffsetDateTime.parse(s, FORMAT));
              }
              catch (Exception e) {
                System.err.println("\t"+e);
              }
            }
          }

        }

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  sherman Xueming Shen
                  Reporter:
                  sherman Xueming Shen
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  3 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved: