subtractIntervals
Signature
Section titled “Signature”subtractIntervals(from: Interval, remove: Interval[]): Interval[]Return the parts of from that no interval in remove covers, as sorted half-open intervals.
- A removal strictly inside
fromsplits it in two; one covering an edge trims it; one covering all of it leaves[]. - Half-open: a removal that only touches
fromremoves nothing, and pieces never include an instant any removal covers. removemay be unsorted and overlapping. Removing an empty interval changes nothing; subtracting from an emptyfromreturns[].- Endpoints are the caller’s own strings, and
from’s spelling is kept whereverfromand a removal name the same instant (GMT rule). []is both a legitimate result (everything removed) and the invalid-input sentinel; check inputs withisValidIntervalwhen the difference matters.- The positional
intervalDifferenceUtc(…) follow the same half-open rule for a single removal: pieces end exactly where the removal starts. - For zone-aligned removals (non-working local days), build them with
floorToZonefirst. - Returns
[]whenfromis not a validInterval,removeis not an array, or any element ofremoveis not a validInterval— even one outsidefrom.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
from | Interval | { start, end } record of ISO 8601 instant strings to subtract from |
remove | Interval[] | array of { start, end } records of ISO 8601 instant strings to remove |
Returns
Section titled “Returns”sorted, non-touching { start, end } records of what remains, or [] on invalid input
Related types
Section titled “Related types”Examples
Section titled “Examples”import { subtractIntervals } from "@northguild/gmt/interval/calculate";
subtractIntervals({ start: "2024-01-01T09:00:00Z", end: "2024-01-01T17:00:00Z" }, [{ start: "2024-01-01T12:00:00Z", end: "2024-01-01T13:00:00Z" }]) // [{ start: "2024-01-01T09:00:00Z", end: "2024-01-01T12:00:00Z" }, { start: "2024-01-01T13:00:00Z", end: "2024-01-01T17:00:00Z" }]