UNPKG

@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.

29 lines • 2.06 kB
/** Whether the formatter can print an era or a year (ECMA-402 CreateDateTimeFormat defaults). */ export declare function showsEraOrYear(options: Intl.DateTimeFormatOptions): boolean; /** A time value as `Intl` reads it: a number, a `Date`, or `undefined` for now. */ export declare function toMilliseconds(date: Date | number | undefined): number; /** * The options a chinese or dangi formatter is built with: `year: "2-digit"` becomes `"numeric"` * when the engine pads the related year (D28), else the options as given. * * @param callerOptions the options the formatter was asked for * @param calendar the calendar the formatter resolved * @returns the options to build with * * @example widenRelatedYear({ year: "2-digit" }, "chinese") // { year: "numeric" } where the engine pads the related year * @example widenRelatedYear({ year: "2-digit" }, "gregory") // { year: "2-digit" } */ export declare function widenRelatedYear(callerOptions: Intl.DateTimeFormatOptions, calendar: string): Intl.DateTimeFormatOptions; /** * The formatter itself, or a wrapper that repairs the years of D25, D26 and D27 where the engine * prints them wrongly. * * @param formatter the formatter the week-year guard returned * @param callerOptions the options it was built with * @param twinOf the cached formatter for other options and the same locale (a Gregorian twin) * @returns the formatter, or its wrapper * * @example repairYearPrinting(new Intl.DateTimeFormat("en", { year: "numeric" }), { year: "numeric" }, () => new Intl.DateTimeFormat("en")) // the same formatter * @example repairYearPrinting(new Intl.DateTimeFormat("ja-u-ca-japanese", { year: "2-digit", timeZone: "UTC" }), { year: "2-digit", timeZone: "UTC" }, () => new Intl.DateTimeFormat("ja")).format(Date.UTC(2024, 6, 10)) // "令和06年" where the engine prints 令和6年 */ export declare function repairYearPrinting(formatter: Intl.DateTimeFormat, callerOptions: Intl.DateTimeFormatOptions, twinOf: (options: Intl.DateTimeFormatOptions) => Intl.DateTimeFormat): Intl.DateTimeFormat;