@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.
25 lines (23 loc) • 1.28 kB
JavaScript
import { zonedDateTimeOf } from "./zonedWallClock.js";
import { utcInstantOf } from "./utcInstant.js";
// src/internal/zonedFormatReference.ts
/**
* Whether the `reference` option of the zoned formatters can be read: omitted (`undefined`), a
* zoned or UTC ISO string, or a finite epoch in milliseconds. Any other type — a boolean (which
* ToNumber would read as epoch 1 or 0), `null`, an object or a bigint — is invalid input.
*
* @param reference the option as given
* @returns false for a string of neither form, a non-finite number, or a value of another type
* @example isValidZonedFormatReference("2024-03-15T09:00:00+09:00[Asia/Tokyo]") // true
* @example isValidZonedFormatReference("2024-03-15T13:00:00Z") // true
* @example isValidZonedFormatReference(undefined) // true
* @example isValidZonedFormatReference(Number.NaN) // false
* @example isValidZonedFormatReference("2024-03-15") // false
* @example isValidZonedFormatReference(true) // false
*/
function isValidZonedFormatReference(reference) {
if (reference === void 0) return true;
if (typeof reference === "string") return zonedDateTimeOf(reference) !== null || utcInstantOf(reference) !== null;
return typeof reference === "number" && Number.isFinite(reference);
}
export { isValidZonedFormatReference };