isValidZonedRange
Signature
Section titled “Signature”isValidZonedRange(props: { value1: string; value2: string; options?: { allowEqual?: boolean; }; }): booleanReturn 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
isValidZonedDateTimerequires: basic format, a space or lower-casetseparator, a lower-casezand a date without a time returnfalse. - 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
isValidZonedDateTimereads them: elective ones are ignored,[u-ca=iso8601]is accepted, and a non-ISO calendar on either endpoint returnsfalse.
Options
Section titled “Options”props
the two endpoints of the range and its optional settings
| Option | Type | Default | Description |
|---|---|---|---|
value1 | string | Required | The start of the range, as an ISO 8601 zoned datetime string. |
value2 | string | Required | The end of the range, as an ISO 8601 zoned datetime string. |
options? | object | None. 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? | boolean | false | Whether value1 at the same instant as value2 is a valid range. false requires value1 to be before value2. |
Returns
Section titled “Returns”boolean indicating whether the zoned range is valid
Examples
Section titled “Examples”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