# sumIntervals

Industry: Core

## Signature

```ts
sumIntervals(intervals: Interval[]): string
```

Return 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.until` with `largestUnit: "hour"` renders it — an instant has no calendar, so there are no days. `PT49H30M`, not `P2DT1H30M`.
- 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 `""` when `intervals` is not an array or any element is not a valid `Interval`.

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| `intervals` | `Interval[]` | array of `{ start, end }` records of ISO 8601 instant strings |

## Returns

ISO 8601 duration string of the covered time, or "" on invalid input

## Related types

- [`Interval`](/gmt/reference/types/Interval/)

## Examples

```ts
import { sumIntervals } from "@northguild/gmt/interval/calculate";

sumIntervals([{ start: "2024-01-01T00:00:00Z", end: "2024-01-03T01:30:00Z" }]) // "PT49H30M"
```

## Source

[interval/calculate/sumIntervals.ts](https://github.com/northguild/gmt/blob/main/packages/gmt/src/interval/calculate/sumIntervals.ts)
