Skip to content

isValidTimeRange

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

Return true if value1 and value2 form a valid time range — both parseable as ISO PlainTime strings and value1 before value2.

  • Both inputs must be ISO 8601 time strings (e.g. "14:30:00"), as isValidTime accepts, annotations included.
  • Ordered by Temporal.PlainTime.compare, to the nanosecond.
  • Invalid input, malformed strings, or leap-second strings return false.

props

The two values to compare and how equal values are treated

OptionTypeDefaultDescription
value1stringRequiredThe start of the range, an ISO PlainTime string.
value2stringRequiredThe end of the range, an ISO PlainTime 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 time range is valid

import { isValidTimeRange } from "@northguild/gmt/plain/validate";
isValidTimeRange({ value1: "09:00:00", value2: "17:00:00" }) // true
output 

plain/validate/isValidTimeRange.ts