intervalIntersectionDateTime
Signature
Section titled “Signature”intervalIntersectionDateTime(aStart: string, aEnd: string, bStart: string, bEnd: string): { start: string; end: string; }import { intervalIntersectionDateTime } from "@northguild/gmt/plain/interval";Return the overlapping span of two datetime intervals, or null when they do not overlap.
- Uses
Temporal.PlainDateTime.comparefor comparison. - Adjacent intervals (e.g.
aEnd === bStart) share one instant and DO overlap. - 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
Examples
Section titled “Examples”intervalIntersectionDateTime("2024-01-01T10:00:00", "2024-06-30T23:59:59", "2024-04-01T00:00:00", "2024-12-31T23:59:59") // { start: "2024-04-01T00:00:00", end: "2024-06-30T23:59:59" }intervalIntersectionDateTime("2024-01-01T10:00:00", "2024-06-30T23:59:59", "2024-07-01T00:00:00", "2024-12-31T23:59:59") // nullintervalIntersectionDateTime("2024-01-01T10:00:00", "2024-06-30T23:59:59", "2024-07-02T00:00:00", "2024-12-31T23:59:59") // nullintervalIntersectionDateTime("invalid", "2024-06-30T23:59:59", "2024-04-01T00:00:00", "2024-12-31T23:59:59") // null