sumIntervals
Signature
Section titled “Signature”sumIntervals(intervals: Interval[]): stringReturn the time covered by a list of half-open intervals, as an exact ISO 8601 duration.
- Covered time is the length of the union: overlapping time counts once, touching intervals add up, empty intervals add nothing.
- Hours are the largest unit, exactly as
Temporal.Instant.prototype.untilwithlargestUnit: "hour"renders it — an instant has no calendar, so there are no days.PT49H30M, notP2DT1H30M. - Exact to the nanosecond at any size, including past 2^53 nanoseconds (about 104 days) and across the whole representable instant range (
PT4800000000H). - Measures elapsed time, never wall-clock distance: a New York day across spring-forward is
PT23H. []returns"PT0S"— no time covered, not invalid input.- Returns
""whenintervalsis not an array or any element is not a validInterval.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
intervals | Interval[] | array of { start, end } records of ISO 8601 instant strings |
Returns
Section titled “Returns”ISO 8601 duration string of the covered time, or "" on invalid input
Related types
Section titled “Related types”Examples
Section titled “Examples”import { sumIntervals } from "@northguild/gmt/interval/calculate";
sumIntervals([{ start: "2024-01-01T00:00:00Z", end: "2024-01-03T01:30:00Z" }]) // "PT49H30M"