AccurateDuration — GraphQL Custom Scalar

Author – AlexandreCarlton

Date - 2024-03-17

1Overview

This Scalar represents an exact length in time. It is a refinement of the duration as defined by ISO 8601 with the caveat that it does not support calendar components that would otherwise require the knowledge of a date to determine a precise value. As such, the following components are excluded:

Days (unlike calendar days) are supported under the definition of ISO 31-1: 24 hours.

Negative durations per ISO 8601-2 are supported.

3Input/Result specification

ISO 8601 defines a duration as either:

Instead, the specification PDTnHnMn.nS is used, with the further amendments:

3.1Positive examples

String Explanation
PT2M A duration representing 2 minutes.
PT120S A duration representing 120 seconds (2 minutes).
PT0.000000001S A duration representing 1 nanosecond.
-P1D A duration representing 1 negative day.
P1D-2H A duration representing two hours fewer than a full day.

3.2Negative examples

String Explanation
P1Y Calendar years are not supported.
P1M Calendar months are not supported.
P1W Calendar weeks are not supported.
P0.5D Fractional component is only supported for seconds.
PT0.0000000001S Fractional component in seconds only supports at most 9 digits.
PTS Digits must precede units.

4References

  1. 1Overview
  2. 2Recommended name
  3. 3Input/Result specification
    1. 3.1Positive examples
    2. 3.2Negative examples
  4. 4References