Skip to content

intervalContainsUtc

intervalContainsUtc(intervalStart: string, intervalEnd: string, pointOrStart: string, pointEnd?: string): boolean

Return true when pointOrStart lies in the half-open interval [intervalStart, intervalEnd) (3-arg), or when the inner interval [innerStart, innerEnd) lies within it (4-arg).

  • Half-open: an interval holds every instant t with start <= t < end, so intervalEnd itself is outside (the rule CORE-6’s intervalContains uses). An empty interval (start === end) contains no point.
  • 4-arg: the inner interval must start at or after intervalStart, end at or before intervalEnd, and overlap the outer interval. An empty inner interval therefore counts only strictly inside, never at an edge (CORE-6’s clampInterval clamps it away there).
  • The 3-argument form delegates to CORE-6’s intervalContains once the arguments pass the UTC-string gate.
  • Uses Temporal.Instant.compare for comparison.
  • Returns false if intervalStart > intervalEnd (invalid outer interval).
  • Returns false if innerStart > innerEnd in 4-arg mode (invalid inner interval).
  • Returns false on invalid input (wrong type, non-Z strings, malformed strings, leap seconds).
ParameterTypeDescription
intervalStartstringISO 8601 UTC datetime string for the outer interval start
intervalEndstringISO 8601 UTC datetime string for the outer interval end (excluded)
pointOrStartstringISO 8601 UTC datetime string for the point (3-arg) or inner start (4-arg)
pointEndstringoptional ISO 8601 UTC datetime string for the inner interval end (4-arg mode)

true if the point or inner interval is contained, or false on invalid input

import { intervalContainsUtc } from "@northguild/gmt/utc/interval";
intervalContainsUtc("2024-01-01T09:00:00Z", "2024-01-01T17:00:00Z", "2024-01-01T12:00:00Z") // true
output 

utc/interval/intervalContainsUtc.ts