clampInterval
Signature
Section titled “Signature”clampInterval(interval: Interval, bounds: Interval): Interval | nullReturn the part of interval that lies inside bounds, or null when none of it does.
- Exactly
intersectIntervals(interval, bounds): half-open, so an interval that only touchesboundsclamps tonull, as does an empty interval at an edge ofbounds. - Endpoints are the caller’s own strings. Where an endpoint of
intervaland ofboundsare the same instant,interval’s spelling is used (GMT rule: the first argument wins ties). - For zone-aligned bounds (a local business day), build them with
floorToZonefirst. - Returns
nullon invalid input — either argument not anInterval, or inverted.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
interval | Interval | { start, end } record of ISO 8601 instant strings to clamp; its strings win ties |
bounds | Interval | { start, end } record of ISO 8601 instant strings to clamp into |
Returns
Section titled “Returns”{ start, end } inside bounds, or null when nothing remains or on invalid input
Related types
Section titled “Related types”Examples
Section titled “Examples”import { clampInterval } from "@northguild/gmt/interval/calculate";
clampInterval({ start: "2024-01-01T08:00:00Z", end: "2024-01-01T12:00:00Z" }, { start: "2024-01-01T09:00:00Z", end: "2024-01-01T17:00:00Z" }) // { start: "2024-01-01T09:00:00Z", end: "2024-01-01T12:00:00Z" }