UNPKG

@burglekitt/gmt

Version:

Temporal-based date and time utilities with timezone support and polyfill integration

34 lines (33 loc) 960 B
import { Temporal } from "@js-temporal/polyfill"; import { plainTime } from "../../regex/index.js"; import { isLeapSecond } from "./isLeapSecond.js"; /** * Return true when `value` is a valid ISO PlainTime string. * * - Uses regex to check format before parsing. * - Rejects leap seconds (e.g., "23:59:60"). * - Rejects invalid times (e.g., "24:00:00", "23:60:00"). * * @param value ISO PlainTime string * @returns boolean indicating validity * * @example isValidTime("12:34:56") // true * @example isValidTime("24:00:00") // false (invalid hour) * @example isValidTime("23:60:00") // false (invalid minute) * @example isValidTime("23:59:60") // false (leap second) */ export function isValidTime(value) { if (isLeapSecond(value)) { return false; } if (!plainTime.test(value)) { return false; } try { Temporal.PlainTime.from(value); return true; } catch { return false; } }