Skip to content

isValidZonedRange

isValidZonedRange({ value1, value2, options, }: { value1: string; value2: string; options?: { allowEqual?: boolean; }; }): boolean
import { isValidZonedRange } from "@northguild/gmt/zoned/validate";

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.
  • Equal value1 === value2 is valid when options.allowEqual is true.
  • 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.
Parameter Type Description
value1 `` first ISO ZonedDateTime string
value2 `` second ISO ZonedDateTime string
options `` optional allowEqual flag

boolean indicating whether the zoned range is valid

isValidZonedRange({ value1: "2024-01-01T10:00:00+00:00[UTC]", value2: "2024-12-31T23:59:59+00:00[UTC]" }) // true
isValidZonedRange({ value1: "2024-12-31T23:59:59+00:00[UTC]", value2: "2024-01-01T10:00:00+00:00[UTC]" }) // false
isValidZonedRange({ value1: "2024-06-15T12:00:00-04:00[America/New_York]", value2: "2024-06-15T12:00:00-04:00[America/New_York]", options: { allowEqual: true } }) // true

zoned/validate/isValidZonedRange.ts