Skip to content

intervalOverlappingDaysDateTime

intervalOverlappingDaysDateTime(aStart: string, aEnd: string, bStart: string, bEnd: string): number | null

Return how many distinct calendar dates two datetime intervals share.

  • Half-open: an interval holds every t with start <= t < end. The count is the number of calendar days holding at least one moment of the intersection [max(aStart, bStart), min(aEnd, bEnd)). An intersection ending exactly at midnight does not reach that day.
  • Touching intervals (aEnd === bStart) share no moment and count 0; so does an empty interval.
  • Returns 0 when the intervals share nothing (a well-defined answer, not invalid input).
  • Returns null if either interval is invalid (start > end).
  • Returns null on invalid input (wrong type, malformed strings).
ParameterTypeDescription
aStartstringISO 8601 datetime string for the first interval start
aEndstringISO 8601 datetime string for the first interval end
bStartstringISO 8601 datetime string for the second interval start
bEndstringISO 8601 datetime string for the second interval end

number of shared calendar dates, 0 when disjoint, or null on invalid input

import { intervalOverlappingDaysDateTime } from "@northguild/gmt/plain/interval";
intervalOverlappingDaysDateTime("2024-01-01T23:59:00", "2024-01-02T00:01:00", "2024-01-01T23:59:00", "2024-01-02T00:01:00") // 2
output 

plain/interval/intervalOverlappingDaysDateTime.ts