Skip to content

isValidUtc

isValidUtc(value: string): boolean
import { isValidUtc } from "@northguild/gmt/utc/validate";

Return true when the provided string is a valid ISO 8601 UTC datetime.

  • Uses regex to check format before parsing.
  • Rejects leap seconds (e.g., “2024-12-31T23:59:60Z”).
  • Uses Temporal.Instant.from for validation.
  • Requires a time component — date-only strings (“2024-01-01Z”) are rejected.
Parameter Type Description
value string input UTC datetime string (ISO 8601)

boolean indicating whether the input is a valid UTC datetime

isValidUtc("2024-03-17T14:30:45Z") // true
isValidUtc("2024-01-01Z") // false — date-only not supported
isValidUtc("2024-12-31T23:59:60Z") // false
isValidUtc("invalid") // false

utc/validate/isValidUtc.ts