Skip to content

isValidZonedRange

isValidZonedRange(props: { value1: string; value2: string; options?: { allowEqual?: boolean; }; }): boolean

Return true if value1 and value2 form a valid zoned range — both parseable as ISO ZonedDateTime strings and the instant at value1 is <= the instant at value2.

  • Both inputs must be valid ISO 8601 zoned datetime strings in extended format, as isValidZonedDateTime requires: basic format, a space or lower-case t separator, a lower-case z and a date without a time return false.
  • Comparison is done by instant, so intervals spanning DST transitions are compared by absolute time.
  • Invalid input, malformed strings, or leap-second strings return false.
  • Annotations are read as isValidZonedDateTime reads them: elective ones are ignored, [u-ca=iso8601] is accepted, and a non-ISO calendar on either endpoint returns false.

props

the two endpoints of the range and its optional settings

OptionTypeDefaultDescription
value1stringRequiredThe start of the range, as an ISO 8601 zoned datetime string.
value2stringRequiredThe end of the range, as an ISO 8601 zoned datetime string.
options?objectNone. Two values at the same instant 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 at the same instant as value2 is a valid range. false requires value1 to be before value2.

boolean indicating whether the zoned range is valid

import { isValidZonedRange } from "@northguild/gmt/zoned/validate";
isValidZonedRange({ value1: "2024-01-01T10:00:00+00:00[UTC]", value2: "2024-12-31T23:59:59+00:00[UTC]" }) // true
output 

zoned/validate/isValidZonedRange.ts