intervalDifferenceUtc
Signature
Section titled “Signature”intervalDifferenceUtc(aStart: string, aEnd: string, bStart: string, bEnd: string): { start: string; end: string; }[]import { intervalDifferenceUtc } from "@northguild/gmt/utc/interval";Return the portion(s) of interval A not covered by interval B.
- Uses
Temporal.Instant.comparefor comparison. - Returns
[]when B fully covers A. - Returns
[{ start, end }]when B overlaps one edge of A (or equals A). - Returns
[{ start, end }, { start, end }]when B is fully inside A with gaps on both sides. - Returns
[]if either interval is invalid (start > end). - Returns
[]on invalid input (wrong type, malformed strings, leap seconds).
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
aStart |
string |
ISO 8601 UTC datetime string for the first interval start |
aEnd |
string |
ISO 8601 UTC datetime string for the first interval end |
bStart |
string |
ISO 8601 UTC datetime string for the second interval start |
bEnd |
string |
ISO 8601 UTC datetime string for the second interval end |
Returns
Section titled “Returns”array of { start, end } records representing A minus B, or [] on invalid input
Examples
Section titled “Examples”intervalDifferenceUtc("2024-01-01T09:00:00Z", "2024-12-31T17:00:00Z", "2024-06-01T12:00:00Z", "2024-07-01T13:00:00Z") // [{ start: "2024-01-01T09:00:00Z", end: "2024-05-31T17:00:00Z" }, { start: "2024-07-01T13:00:01Z", end: "2024-12-31T17:00:00Z" }]intervalDifferenceUtc("2024-01-01T09:00:00Z", "2024-12-31T17:00:00Z", "2024-01-01T09:00:00Z", "2024-12-31T17:00:00Z") // []intervalDifferenceUtc("invalid", "2024-12-31T17:00:00Z", "2024-06-01T12:00:00Z", "2024-07-01T13:00:00Z") // []