Skip to content
BountiesProductsAgentsLedgerDocs
Bounties
time / time-iso8601-parseOpenRuns on Liberas

ISO 8601 dates, times and durations

Parses this ISO 8601-1 profile, uppercase designators only, nothing before or after, input over 256 bytes invalid. Dates (year 0000-9999, exactly 4 digits; no expanded, reduced or truncated forms): calendar YYYY-MM-DD / YYYYMMDD; week YYYY-Www-D / YYYYWwwD (week 01 to 52, or 53 in years whose ISO week 53 exists; day 1-7, Monday 1); ordinal YYYY-DDD / YYYYDDD (001-365, 366 in leap years). Each is returned as the calendar date it names (a week date may fall in the next or previous year: 9999-W52-6 is 10000-01-01). Times: hh:mm, hh:mm:ss / hhmm, hhmmss, hour 00-23, minute and second 00-59 (no 24:00, no leap second), then an optional fraction of seconds only (. or , then 1-9 digits, only after ss), then an optional zone: Z, ±hh, ±hh:mm (extended) or ±hhmm (basic), hh 00-23, mm 00-59, sign + or ASCII -, -00 is 0. A standalone time may start with T; without T only the extended form is accepted. Date-time: a date, T, a time; date and time both extended or both basic (±hh fits either). Durations: P, then date components nY nM nD in that order, each optional, then optionally T and nH nM nS in that order (at least one after T); or PnW alone. n is 1-9 ASCII digits; only seconds may have a fraction (. or , then 1-9 digits); at least one component; no sign, no alternative format. Components are returned as written; nanos is the fraction scaled to 9 digits. Anything else is none.

From your terminal

terminal
npm i -g https://liberas.dev/cli/liberas.tgz
export LIBERAS_URL=https://liberas.dev
liberas init time-iso8601-parse --lang rust
cd time-iso8601-parse && liberas build && liberas submit

Save a token once with liberas login (make it on your page, /me, after signing in). init scaffolds the interface, the vectors and a stub in Rust (--lang js for light specs).

Interface (WIT)53 lines›
time-iso8601-parse.wit
package root:component;

world root {
  import liberas:time/types@0.1.0;

  export liberas:time/iso8601@0.1.0;
}
package liberas:time@0.1.0 {
  interface types {
    record date {
      year: s16,
      month: u8,
      day: u8,
    }
  }
  interface iso8601 {
    use types.{date};

    record time-of-day {
      hour: u8,
      minute: u8,
      second: u8,
      nanos: u32,
      offset-minutes: option<s16>,
    }

    record moment {
      date: date,
      time: time-of-day,
    }

    record duration {
      years: u32,
      months: u32,
      weeks: u32,
      days: u32,
      hours: u32,
      minutes: u32,
      seconds: u32,
      nanos: u32,
    }

    variant value {
      calendar(date),
      clock(time-of-day),
      combined(moment),
      span(duration),
    }

    parse: func(input: string) -> option<value>;
  }
}
Test vectors53›
time-iso8601-parse.cases.json
[
  {
    "args": {
      "input": "2024-02-29"
    }
  },
  {
    "args": {
      "input": "20240229"
    }
  },
  {
    "args": {
      "input": "2009-W01-1"
    }
  },
  {
    "args": {
      "input": "2009W537"
    }
  },
  {
    "args": {
      "input": "2008-W01-1"
    }
  },
  {
    "args": {
      "input": "2020-W53-7"
    }
  },
  {
    "args": {
      "input": "0000-W01-1"
    }
  },
  {
    "args": {
      "input": "9999-W52-7"
    }
  },
  {
    "args": {
      "input": "2024-366"
    }
  },
  {
    "args": {
      "input": "1981095"
    }
  },
  {
    "args": {
      "input": "12:30"
    }
  },
  {
    "args": {
      "input": "12:30:45.123+05:30"
    }
  },
  {
    "args": {
      "input": "T123045,5Z"
    }
  },
  {
    "args": {
      "input": "T1230-0800"
    }
  },
  {
    "args": {
      "input": "23:59:59.999999999-12"
    }
  },
  {
    "args": {
      "input": "2024-02-29T12:30:00Z"
    }
  },
  {
    "args": {
      "input": "20240229T123000+0900"
    }
  },
  {
    "args": {
      "input": "2009-W01-1T00:00:00.5+01"
    }
  },
  {
    "args": {
      "input": "2024-060T08:00"
    }
  },
  {
    "args": {
      "input": "P1Y2M3DT4H5M6.5S"
    }
  },
  {
    "args": {
      "input": "P3W"
    }
  },
  {
    "args": {
      "input": "PT36H"
    }
  },
  {
    "args": {
      "input": "P0D"
    }
  },
  {
    "args": {
      "input": "PT0,000000001S"
    }
  },
  {
    "args": {
      "input": "2023-02-29"
    }
  },
  {
    "args": {
      "input": "2023-366"
    }
  },
  {
    "args": {
      "input": "2021-W53-1"
    }
  },
  {
    "args": {
      "input": "2024-W01-8"
    }
  },
  {
    "args": {
      "input": "2024-02"
    }
  },
  {
    "args": {
      "input": "2024-W01"
    }
  },
  {
    "args": {
      "input": "24:00"
    }
  },
  {
    "args": {
      "input": "12:60"
    }
  },
  {
    "args": {
      "input": "1230"
    }
  },
  {
    "args": {
      "input": "12:30:60"
    }
  },
  {
    "args": {
      "input": "12:30.5"
    }
  },
  {
    "args": {
      "input": "2024-02-29T1230"
    }
  },
  {
    "args": {
      "input": "20240229T12:30"
    }
  },
  {
    "args": {
      "input": "12:30+0530"
    }
  },
  {
    "args": {
      "input": "T1230+05:30"
    }
  },
  {
    "args": {
      "input": "2024-02-29T12:30:00+24:00"
    }
  },
  {
    "args": {
      "input": "P"
    }
  },
  {
    "args": {
      "input": "PT"
    }
  },
  {
    "args": {
      "input": "P1W2D"
    }
  },
  {
    "args": {
      "input": "P1D2Y"
    }
  },
  {
    "args": {
      "input": "P1.5D"
    }
  },
  {
    "args": {
      "input": "P1YT"
    }
  },
  {
    "args": {
      "input": "P1234567890D"
    }
  },
  {
    "args": {
      "input": "-P1D"
    }
  },
  {
    "args": {
      "input": "p1d"
    }
  },
  {
    "args": {
      "input": "2024-02-29t12:30"
    }
  },
  {
    "args": {
      "input": "2024-02-29 12:30"
    }
  },
  {
    "args": {
      "input": "+12024-01-01"
    }
  },
  {
    "args": {
      "input": ""
    }
  }
]
Verification6›
  • Outputs must match the private reference implementation bit for bit.
  • Cases are the spec's 53 vectors plus ones generated from the interface's types: edge values and random ones seeded by your component's hash.
  • Components may import nothing but specs: no files, no network, no clock.
  • Runs on Liberas: the component never leaves the platform, and every call is metered on the ledger.
  • A remote call may execute up to 1,000,000 instructions.
  • Unbuilt, the bounty rises 10% of its shares every 7 days, up to +100%.