datetime/iso_interval_parse_utils library
ISO 8601 time-interval parser — roadmap #646.
Parses the three interval forms from ISO 8601 into a DateTimeRange:
start/end— two timestamps (2026-01-01T00:00Z/2026-01-02T00:00Z)start/duration— a timestamp plus a duration (2026-01-01/P1M)duration/end— a duration ending at a timestamp (P7D/2026-01-08)
The timestamp halves use Dart's native ISO 8601 datetime parsing; the
duration half is an ISO 8601 duration (P[nY][nM][nW][nD][T[nH][nM][nS]])
applied with calendar arithmetic (years/months add as calendar units, not a
fixed number of days). Anything malformed throws a FormatException.
Functions
-
parseIsoInterval(
String input) → DateTimeRange< DateTime> -
Parses an ISO 8601 time interval into a DateTimeRange. Accepts the
start/end,start/duration, andduration/endforms, separated by/. Throws a FormatException if the separator is missing, either half is malformed, both halves are durations, orstartends up afterend.