Skip to content

Duration: ISO 8601 format/parse and a Schema codec (exact units only) #9888

Closed

Description

@jayhemnani9910

What is the problem this feature would solve?

v3 had Duration.formatIso, Duration.fromIso and Duration.unsafeFormatIso (#4343, for #4319). v4 dropped them, and the migration guide says to "retain a local formatter" or use a separate ISO parser.

ISO 8601 durations are a common wire format: OpenAPI format: duration, config files (timeout: PT30S), Temporal.Duration#toString(). In v4 each app needs its own parser, and there is no Schema codec.

v3 also treated a year as 365 days and a month as 30 days, so P1M was wrong for most months.

What is the feature you are proposing to solve the problem?

Duration.formatIso(self: Duration): Option<string>
Duration.fromIso(input: string): Option<Duration>
Schema.DurationFromIsoString // string <-> Duration, JSON Schema format: "duration"
  • Exact units only: W, D, H, M (after T), S. A day is 24 hours.
  • Y and month M are rejected, since they have no fixed length.
  • Optional sign, fraction on the last time unit only, up to 9 digits.
  • Output matches Temporal.Duration#toString(): P1DT2H3M4.5S, PT0S, -PT1.5S.
  • Infinite durations give Option.none() (and an encode failure in the codec).

What alternatives have you considered?

  • A local helper in each app, which is what the migration guide suggests.
  • Duration.fromInput(Temporal.Duration.from(s)), but Node 24 has no Temporal without a flag, and it gives no Schema codec.

I have a working branch with tests (checked against Temporal.Duration where available): jayhemnani9910/effect@main...feat/duration-iso. I can open a PR if this direction is OK.

Activity

  1. fubhy commented on Oct 24, 2026

    @fubhy
    Member

    Yes. Tbh. this was probably removed in error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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