data datetime ai_generated true

ISO 8601 duration P1M parsed as 1 minute instead of 1 month, or vice versa

ID: data/iso8601-duration-parsing-inconsistent

Also available as: JSON · Markdown
85%Fix Rate
88%Confidence
3Evidence
2023-01-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
8601 active

Root Cause

ISO 8601 durations use M for both months (P1M) and minutes (PT1M). P1M = 1 month, PT1M = 1 minute. The T separator is critical. Many parsers and developers confuse P1M30S (1 month 30 seconds) with PT1M30S (1 minute 30 seconds).

generic

Workarounds

  1. 95% success Always include T separator before time components in durations
    PT1H30M = 1 hour 30 minutes; P1DT12H = 1 day 12 hours; P1M = 1 month (not 1 minute!)
  2. 90% success Use isodate or dateutil library for robust ISO 8601 duration parsing
    import isodate; duration = isodate.parse_duration('PT1M30S')  # timedelta(seconds=90)
  3. 82% success Use total seconds representation for unambiguous duration serialization
    Store durations as seconds (integer) internally. Convert to ISO 8601 only for API responses.

Dead Ends

Common approaches that don't work:

  1. Use P1M30S to mean 1 minute and 30 seconds 92% fail

    P1M30S means 1 month and 30 seconds, NOT 1 minute 30 seconds. The T separator is required before time components: PT1M30S.

  2. Parse ISO 8601 durations with simple regex 78% fail

    Duration semantics are complex: P1M = 28-31 days depending on month. P1Y = 365 or 366 days. Simple regex can't capture calendar-dependent semantics.