Skip to content

isValidDateRange

isValidDateRange(props: IsValidDateRangeProps): boolean

Return whether value1 is before value2.

  • Validates both dates with isValidDate, so each endpoint’s RFC 9557 annotations are read as Temporal.PlainDate.from reads them (an elective [foo=bar] or [u-ca=iso8601] is ignored).
  • Rejects leap seconds in either date.

props

The two values to compare and how equal values are treated

The argument object of isValidDateRange.

import type { IsValidDateRangeProps } from "@northguild/gmt";
OptionTypeDefaultDescription
value1stringRequiredThe start of the range, an ISO PlainDate string.
value2stringRequiredThe end of the range, an ISO PlainDate string.
options?objectNone. Equal values are not a valid range.The settings for the comparison. It must be an object or omitted; any other value, null included, returns false.
options.allowEqual?booleanfalseWhether value1 equal to value2 is a valid range. false requires value1 to be before value2.

boolean indicating whether the date range is valid

import { isValidDateRange } from "@northguild/gmt/plain/validate";
isValidDateRange({ value1: "2024-02-28", value2: "2024-02-29" }) // true
output 

plain/validate/isValidDateRange.ts