@northguild/gmt
Version:
Date and time library for JavaScript and TypeScript, built on TC39 Temporal: time zones, DST, business days, ISO 8601 strings in and out. Never throws.
17 lines (15 loc) • 646 B
JavaScript
import { hasZonedDateTimeShape } from "../../internal/isoStringBody.js";
import { hasSecond60 } from "../../plain/validate/hasSecond60.js";
import { zonedDateTimeFrom } from "../../internal/zonedWallClock.js";
// src/zoned/validate/isValidZonedDateTime.ts
function isValidZonedDateTime(value) {
if (typeof value !== "string" || value.length === 0) return false;
if (hasSecond60(value) || !hasZonedDateTimeShape(value)) return false;
try {
const zonedDateTime = zonedDateTimeFrom(value);
return zonedDateTime.timeZoneId.length > 0 && zonedDateTime.calendarId === "iso8601";
} catch {
return false;
}
}
export { isValidZonedDateTime };