intervalIntersectionDateTime
Signature
Section titled “Signature”intervalIntersectionDateTime(aStart: string, aEnd: string, bStart: string, bEnd: string): { start: string; end: string; } | nullReturn the overlapping span of two datetime intervals, or null when they do not overlap.
- Uses
Temporal.PlainDateTime.comparefor comparison. - Half-open: an interval holds every
twithstart <= t < end. The intersection is[max(aStart, bStart), min(aEnd, bEnd))whenaStart < bEnd && bStart < aEnd(CORE-6’sintersectIntervals), otherwisenull. - Touching intervals (
aEnd === bStart) share no moment and returnnull. - An empty interval (
start === end) intersects only an interval it lies strictly inside, and then returns itself. - Returns
nullif either interval is invalid (start > end). - Returns
nullon 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”{ start, end } with the overlapping span, or null on invalid input / no overlap
Members
| 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 can equal start, which makes the interval empty. |
Examples
Section titled “Examples”import { intervalIntersectionDateTime } from "@northguild/gmt/plain/interval";
intervalIntersectionDateTime("2024-01-01T09:00:00", "2024-01-01T13:00:00", "2024-01-01T12:00:00", "2024-01-01T17:00:00") // { start: "2024-01-01T12:00:00", end: "2024-01-01T13:00:00" }