@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.
170 lines • 7.08 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;
/**
* A broad pre-check, not a public test: whether the string has a second-60 field in ANY spelling
* Temporal reads (lower-case `t`, a space, basic format, a bare time with or without `T`). It runs
* in front of a strict gate that rejects the string anyway, so over-matching only rejects earlier.
* `hasSecond60` is the public test and reads GMT's exact kind shapes instead
* (`hasSecond60Shape`); never use this one as that.
*
* @param value the candidate; a value that is not a string has no second field
* @returns whether the string has a second-60 field
*
* @example hasSecond60Field("2016-12-31T23:59:60Z") // true
* @example hasSecond60Field("2016-12-31T23:59:59Z") // false
*/
export declare function hasSecond60Field(value: unknown): boolean;
/**
* The check behind `isValidTime`: the `PlainTime` a plain ISO 8601 time-of-day string names, or
* `null`.
*
* @param value the candidate; a value that is not a string is not a time
* @returns the `PlainTime` Temporal reads when it has the strict shape, else `null`
*
* @example plainTimeOf("17:00")?.hour // 17
* @example plainTimeOf("25:00") // null
* @example plainTimeOf(null) // null
*/
export declare function plainTimeOf(value: unknown): Temporal.PlainTime | null;
/**
* Whether `value` is a plain ISO 8601 time of day.
*
* @param value the candidate string
* @returns whether `plainTimeOf` reads it
*
* @example isTimeString("17:00") // true
* @example isTimeString("25:00") // false
*/
export declare function isTimeString(value: string): boolean;
/**
* The check behind `isValidDate`: the ISO calendar `PlainDate` a plain ISO 8601 date string
* names, or `null`.
*
* @param value the candidate; a value that is not a string is not a date
* @returns the `PlainDate` Temporal reads when it has the strict shape and the ISO calendar, else `null`
*
* @example plainDateOf("2024-02-29")?.day // 29
* @example plainDateOf("2024-02-30") // null
* @example plainDateOf(null) // null
*/
export declare function plainDateOf(value: unknown): Temporal.PlainDate | null;
/**
* Whether `value` is a plain ISO 8601 calendar date.
*
* @param value the candidate string
* @returns whether `plainDateOf` reads it
*
* @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; a value that is not a string is not a date-time
* @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
* @example plainDateTimeOf(null) // null
*/
export declare function plainDateTimeOf(value: unknown): Temporal.PlainDateTime | null;
/**
* The check behind `isValidIsoDateLike`: whether `value` is an ISO calendar `PlainDate` or
* `PlainDateTime` string.
*
* @param value the candidate; a value that is not a string is not date-like
* @returns whether it is a strict ISO date or date-time in the ISO calendar
*
* @example isoDateLikeOf("2024-02-29") // true
* @example isoDateLikeOf("2024-02-29T12:34:56") // true
* @example isoDateLikeOf("2024-02-30") // false
*/
export declare function isoDateLikeOf(value: unknown): boolean;
/**
* The check behind `isValidMonthDay`: the ISO calendar `PlainMonthDay` a month-day string names,
* or `null`.
*
* The whole string must match `plainMonthDay`, which refuses the basic form, a year, a time, `Z`,
* an offset, any annotation (zone, calendar or elective) and a day no year has (`--02-30`)
* before Temporal is asked.
*
* @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 whole string must match `plainYearMonth`, which refuses the basic form, a date, a time, `Z`,
* an offset and any annotation (zone, calendar or elective) before Temporal is asked. Temporal
* then enforces the range (`-271821-04` to `+275760-09`).
*
* @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`: the `Duration` an ISO 8601 duration string names, or `null`.
*
* @param value the candidate; a value that is not a string is not a duration
* @returns the `Duration` Temporal reads, else `null`
*
* @example durationOf("P1DT2H")?.hours // 2
* @example durationOf("2 days") // null
* @example durationOf(null) // null
*/
export declare function durationOf(value: unknown): Temporal.Duration | null;
/**
* Whether `value` is an ISO 8601 duration string.
*
* @param value the candidate
* @returns whether `durationOf` reads it
*
* @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;
/**
* The check behind `isValidNanoPattern`: a decimal integer string in the epoch-nanosecond range.
*
* @param value the candidate; a value that is not a string is not a nanosecond pattern
* @returns whether it is a nanosecond pattern in range
*
* @example isNanoPattern("1700000000000000000") // true
* @example isNanoPattern("1.5") // false
*/
export declare function isNanoPattern(value: unknown): boolean;