intervalDifferenceDateTime
Signature
Section titled “Signature”intervalDifferenceDateTime(aStart: string, aEnd: string, bStart: string, bEnd: string): { start: string; end: string; }[]Return the portion(s) of interval A not covered by interval B.
- Uses
Temporal.PlainDateTime.comparefor comparison. - Half-open: an interval holds every
twithstart <= t < end. A returned piece ends exactly where B starts, or starts exactly where B ends, because B’sendis not in B (CORE-6’ssubtractIntervals). No piece is stepped by one unit. - B touching A (
bStart === aEndorbEnd === aStart), or empty, removes nothing. - An empty A (
aStart === aEnd) has nothing left: returns[]. Every returned piece is non-empty. - Returns
[]when B fully covers A, which includes B equal to A. - Returns
[{ start, end }]when B overlaps exactly one edge of A, leaving one piece. - Returns
[{ start, end }, { start, end }]when B is fully inside A with gaps on both sides. - Returns A unchanged when B lies entirely before or after it.
- Returns
[]if either interval is invalid (start > end). - Returns
[]on invalid input (wrong type, malformed strings).
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
aStart | string | ISO 8601 datetime string for the first interval start |
aEnd | string | ISO 8601 datetime string for the first interval end |
bStart | string | ISO 8601 datetime string for the second interval start |
bEnd | string | ISO 8601 datetime string for the second interval end |
Returns
Section titled “Returns”array of { start, end } records representing A minus B, or [] on invalid input
Members of each item
| Member | Type | Description |
|---|---|---|
start | string | The date-time the interval begins at, as an ISO 8601 date-time string with no offset or time zone. |
end | string | The first date-time after the interval, in the same format as start. It is exclusive: the interval holds everything from start up to but not including this value. It is always later than start. |
Examples
Section titled “Examples”import { intervalDifferenceDateTime } from "@northguild/gmt/plain/interval";
intervalDifferenceDateTime("2024-01-01T09:00:00", "2024-01-01T17:00:00", "2024-01-01T12:00:00", "2024-01-01T13:00:00") // [{ start: "2024-01-01T09:00:00", end: "2024-01-01T12:00:00" }, { start: "2024-01-01T13:00:00", end: "2024-01-01T17:00:00" }]