@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.
99 lines • 4.15 kB
TypeScript
import { Temporal } from "./temporal.js";
import { RollConvention } from "../types/roll-convention.js";
import "../types/index.js";
/** The cores of the `isValid*` functions, so a public function never calls another. */
/**
* The check behind `isValidTimeZone`: an IANA name or a UTC offset to the minute. A pass is
* remembered, so a repeat builds nothing.
*
* @param timeZone the candidate; a value that is not a string is not a zone
* @returns whether it names a zone
*
* @example isZoneId("Europe/London") // true
* @example isZoneId("Not/AZone") // false
*/
export declare function isZoneId(timeZone: unknown): boolean;
/**
* The check behind `isValidTime`: a plain ISO 8601 time of day.
*
* @param value the candidate string
* @returns whether Temporal reads it as a `PlainTime` and it has the strict shape
*
* @example isTimeString("17:00") // true
* @example isTimeString("25:00") // false
*/
export declare function isTimeString(value: string): boolean;
/**
* The check behind `isValidDate`: a plain ISO 8601 calendar date.
*
* @param value the candidate string
* @returns whether Temporal reads it as an ISO calendar `PlainDate` and it has the strict shape
*
* @example isDateString("2024-02-29") // true
* @example isDateString("2024-02-30") // false
*/
export declare function isDateString(value: string): boolean;
/**
* The check behind `isValidDateTime`: the ISO calendar `PlainDateTime` a plain ISO 8601
* date-time string names, or `null`.
*
* @param value the candidate string
* @returns the `PlainDateTime` Temporal reads when it has the strict shape and the ISO calendar, else `null`
*
* @example plainDateTimeOf("2024-02-29T12:00")?.day // 29
* @example plainDateTimeOf("2024-02-29T23:59:60") // null
*/
export declare function plainDateTimeOf(value: string): Temporal.PlainDateTime | null;
/**
* The check behind `isValidMonthDay`: the ISO calendar `PlainMonthDay` a month-day string names,
* or `null`.
*
* The part before the first annotation must match `plainMonthDay`, which refuses the basic form,
* a year, a time, `Z`, an offset and a day no year has (`--02-30`) before Temporal is asked.
* Temporal then reads the annotations (`monthDayFrom`, defect D20) and the calendar must be ISO.
*
* @param value the candidate
* @returns the `PlainMonthDay` when the string is a month-day in the ISO calendar, else `null`
*
* @example plainMonthDayOf("--02-29")?.day // 29
* @example plainMonthDayOf("--02-30") // null
* @example plainMonthDayOf(null) // null
*/
export declare function plainMonthDayOf(value: unknown): Temporal.PlainMonthDay | null;
/**
* The check behind `isValidYearMonth`: the ISO calendar `PlainYearMonth` a year-month string
* names, or `null`.
*
* The part before the first annotation must match `plainYearMonth`, which refuses the basic form,
* a date, a time, `Z` and an offset before Temporal is asked. Temporal then enforces the range
* (`-271821-04` to `+275760-09`) and reads the annotations (`yearMonthFrom`, defect D20), and the
* calendar must be ISO.
*
* @param value the candidate
* @returns the `PlainYearMonth` when the string is a year-month in the ISO calendar, else `null`
*
* @example plainYearMonthOf("2026-10")?.month // 10
* @example plainYearMonthOf("2026-10-01") // null
* @example plainYearMonthOf(null) // null
*/
export declare function plainYearMonthOf(value: unknown): Temporal.PlainYearMonth | null;
/**
* The check behind `isValidDuration`: an ISO 8601 duration string.
*
* @param value the candidate
* @returns whether it is a string Temporal reads as a `Duration`
*
* @example isDurationString("P1DT2H") // true
* @example isDurationString("2 days") // false
*/
export declare function isDurationString(value: unknown): boolean;
/**
* The check behind `isValidRollConvention`: membership in the roll set.
*
* @param convention the candidate
* @returns whether it is one of the six conventions
*
* @example isRollConventionName("following") // true
* @example isRollConventionName("nearest") // false
*/
export declare function isRollConventionName(convention: unknown): convention is RollConvention;