Skip to content

isBetweenDateTime

isBetweenDateTime(dateTime: string, start: string, end: string, options?: { inclusiveStart?: boolean; inclusiveEnd?: boolean; }): boolean

Return true when dateTime is between start and end (inclusive by default).

  • Uses Temporal.PlainDateTime.compare to compare date-times.
  • Returns false if start > end (invalid range).
  • Returns false if any input is invalid.
ParameterTypeDescription
dateTimestringISO PlainDateTime string to check
startstringISO PlainDateTime string for the start of the range
endstringISO PlainDateTime string for the end of the range

options

Whether each end of the range counts as inside it

OptionTypeDefaultDescription
inclusiveStart?booleantrueWhether dateTime equal to start counts as inside the range. false requires it to be after start.
inclusiveEnd?booleantrueWhether dateTime equal to end counts as inside the range. false requires it to be before end.

boolean indicating whether dateTime is between start and end

import { isBetweenDateTime } from "@northguild/gmt/plain/compare";
isBetweenDateTime("2024-02-29T12:00:00", "2024-02-01T00:00:00", "2024-02-28T23:59:59") // false
output 

plain/compare/isBetweenDateTime.ts