Skip to content

Should "format": "duration" allow fractional seconds? #1603

Open
@GREsau

Description

@GREsau

Draft 2020-12 7.3.1. Dates, Times, and Duration states:

Date and time format names are derived from RFC 3339, section 5.6. The duration format is from the ISO 8601 ABNF as given in Appendix A of RFC 3339.

  • ...
  • duration: A string instance is valid against this attribute if it is a valid representation according to the "duration" ABNF rule (referenced above)

And the relevant section from RFC 3339:

Durations:

   dur-second        = 1*DIGIT "S"
   dur-minute        = 1*DIGIT "M" [dur-second]
   dur-hour          = 1*DIGIT "H" [dur-minute]
   dur-time          = "T" (dur-hour / dur-minute / dur-second)
   dur-day           = 1*DIGIT "D"
   dur-week          = 1*DIGIT "W"
   dur-month         = 1*DIGIT "M" [dur-day]
   dur-year          = 1*DIGIT "Y" [dur-month]
   dur-date          = (dur-day / dur-month / dur-year) [dur-time]

   duration          = "P" (dur-date / dur-time / dur-week)

Following this to the letter would mean that fractional seconds are not valid, e.g. "PT0.5S" (half a second) is not a valid duration. While there's no test in the JSON Schema test suite for this, the few validators that I tested do match this behaviour i.e. they disallow fractional seconds.

While this behaviour is not necessarily "incorrect", nor is it ambiguous, I'm concerned that it limits the utility and interoperability of the duration format, and is counter to consumer expectations. For example:

Now that I think about it, the same issue exists for negative durations, e.g. "-PT1S" (negative one second) is not a valid duration according to JSON Schema, despite being widely supported by various standards based on ISO 8601.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions