Containment and Overlap
Use these functions to answer “is this point in the range?”, “does this interval fit inside that one?”, and “do these two ranges share any time?”.
Point-in-interval (3-arg)
Section titled “Point-in-interval (3-arg)”import { intervalContainsDate, intervalContainsTime, intervalContainsDateTime, intervalContainsUtc, intervalContainsUnix, intervalContainsZoned,} from "@northguild/gmt";
intervalContainsDate("2024-01-01", "2024-12-31", "2024-06-15"); // trueintervalContainsTime("09:00:00", "17:00:00", "12:00:00"); // trueintervalContainsUnix(0, 1700000000, 170000000); // trueInterval-in-interval (4-arg)
Section titled “Interval-in-interval (4-arg)”intervalContainsDate("2024-01-01", "2024-12-31", "2024-03-01", "2024-09-01"); // trueintervalEngulfs* is identical to the 4-argument intervalContains* mode — use
whichever name reads better at the call site.
Overlap vs adjacency
Section titled “Overlap vs adjacency”intervalsOverlap* returns true only when intervals share actual time. Adjacent
intervals (one’s end equals the other’s start) do not overlap:
import { intervalsOverlapDate } from "@northguild/gmt";
intervalsOverlapDate("2024-01-01", "2024-06-30", "2024-04-01", "2024-12-31"); // trueintervalsOverlapDate("2024-01-01", "2024-06-30", "2024-06-30", "2024-12-31"); // false — adjacentintervalAbuts* is the complementary check — true only when intervals touch at
exactly one boundary with zero gap and zero overlap:
import { intervalAbutsDate } from "@northguild/gmt";
intervalAbutsDate("2024-01-01", "2024-06-30", "2024-06-30", "2024-12-31"); // trueintervalAbutsDate("2024-01-01", "2024-06-29", "2024-06-30", "2024-12-31"); // false — gapIntersection
Section titled “Intersection”intervalIntersection* returns the overlapping span, or null when the intervals
are disjoint. Adjacent intervals count as overlapping and return a single-point span:
import { intervalIntersectionDate } from "@northguild/gmt";
intervalIntersectionDate("2024-01-01", "2024-06-30", "2024-04-01", "2024-12-31");// { start: "2024-04-01", end: "2024-06-30" }
intervalIntersectionDate("2024-01-01", "2024-06-30", "2024-07-01", "2024-12-31");// null — disjointSee also
Section titled “See also”- Interval Basics — validation, construction, return conventions
- Set Operations — union, difference, xor
intervalContainsDatereferenceintervalsOverlapDatereference