Skip to content

intervalAbutsUtc

intervalAbutsUtc(aStart: string, aEnd: string, bStart: string, bEnd: string): boolean
import { intervalAbutsUtc } from "@northguild/gmt/utc/interval";

Return true when two UTC intervals are exactly adjacent — one’s end equals the other’s

  • start with zero gap and zero overlap.
  • Uses Temporal.Instant.compare for comparison.
  • Returns true when aEnd + 1 nanosecond === bStart or bEnd + 1 nanosecond === aStart.
  • Returns false when intervals overlap, are disjoint with a gap, or are invalid.
  • Returns false on invalid input (wrong type, malformed strings, leap seconds).
Parameter Type Description
aStart string ISO 8601 UTC datetime string for the first interval start
aEnd string ISO 8601 UTC datetime string for the first interval end
bStart string ISO 8601 UTC datetime string for the second interval start
bEnd string ISO 8601 UTC datetime string for the second interval end

true if intervals are exactly adjacent, or false on invalid input

intervalAbutsUtc("2024-01-01T09:00:00Z", "2024-06-30T12:00:00Z", "2024-06-30T12:00:00.000000001Z", "2024-12-31T17:00:00Z") // true
intervalAbutsUtc("2024-06-30T12:00:00Z", "2024-12-31T17:00:00Z", "2024-01-01T09:00:00Z", "2024-06-30T12:00:00.000000001Z") // true
intervalAbutsUtc("2024-01-01T09:00:00Z", "2024-06-30T12:00:00Z", "2024-06-30T12:00:01Z", "2024-12-31T17:00:00Z") // false (gap)
intervalAbutsUtc("2024-01-01T09:00:00Z", "2024-06-30T13:00:00Z", "2024-06-30T12:00:00Z", "2024-12-31T17:00:00Z") // false (overlap)
intervalAbutsUtc("invalid", "2024-06-30T12:00:00Z", "2024-06-30T12:00:00Z", "2024-12-31T17:00:00Z") // false

utc/interval/intervalAbutsUtc.ts