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.

114 lines • 7 kB
type Options = Intl.DateTimeFormatOptions; /** * Map a `timeStyle` to the one a plain value may use. * * - CLDR's `long` and `full` time formats are the ones carrying a * `timeZoneName`. AdjustDateTimeStyleFormat removes that field and asks the * format matcher for a format with the remaining fields. Which pattern the * best-fit matcher picks is implementation-defined; GMT uses the locale's * own `medium` time format, which has exactly the same fields (hour, minute, * second, day period) and no zone. Checked against ICU 78 for 85 * languages, alone and combined with `dateStyle: "full"`. * * @param timeStyle the caller's `timeStyle` * @returns `"medium"` for `"long"`/`"full"`, otherwise the input */ export declare function plainTimeStyle<T extends Options["timeStyle"]>(timeStyle: T): T | "medium"; /** * Resolve caller options into runtime `Intl.DateTimeFormat` options that * format a PlainDate: date fields only, never a time or zone field. * * - Returns `null` where Temporal throws a TypeError: `timeStyle` without * `dateStyle` ([[TemporalPlainDateFormat]] is null), or only non-date * fields (GetDateTimeFormat returns null). * - Validation of the options themselves (invalid values, styles mixed with * fields) is left to the caller constructing a formatter with `options`. * * @param options caller's `Intl.DateTimeFormatOptions` * @returns runtime options anchored at UTC, or `null` when no format exists */ export declare function plainDateFormatOptions(options: Options): Options | null; /** * Resolve caller options into runtime `Intl.DateTimeFormat` options that * format a PlainTime: time fields only, never a date, era or zone field. * * - Returns `null` where Temporal throws a TypeError: a `dateStyle` * (CreateDateTimeFormat with required ~time~), or only non-time fields * (GetDateTimeFormat returns null). * - `era` and `timeZoneName` are not inherited (GetDateTimeFormat ~relevant~), * so with no time field hour, minute and second default to `"numeric"`. * - A `long`/`full` `timeStyle` is mapped through {@link plainTimeStyle}. * * @param options caller's `Intl.DateTimeFormatOptions` * @returns runtime options anchored at UTC, or `null` when no format exists */ export declare function plainTimeFormatOptions(options: Options): Options | null; /** * Resolve caller options into runtime `Intl.DateTimeFormat` options that * format a PlainDateTime: date and time fields, never a zone field. * * - `timeZoneName` is not inherited (GetDateTimeFormat ~relevant~), and a * `long`/`full` `timeStyle` is mapped through {@link plainTimeStyle}. * - With no date or time field and no style, year, month, day, hour, minute * and second default to `"numeric"` (defaults ~all~). * * @param options caller's `Intl.DateTimeFormatOptions` * @returns runtime options anchored at UTC */ export declare function plainDateTimeFormatOptions(options: Options): Options; /** * Resolve caller options into runtime `Intl.DateTimeFormat` options that * format a PlainMonthDay: month and day only, always through the Gregorian calendar. * * - **Calendar (GMT rule).** `calendar` is always `"gregory"`. An ISO month-day and a Gregorian * one name the same month and day, and ICU formats `calendar: "iso8601"` without the locale's * month-day pattern (Node prints `" 25"` for `{ month: "long", day: "numeric" }`, browsers * `Dezember 25` for de-DE). HandleDateTimeTemporalMonthDay throws * a RangeError for any calendar mismatch, so `PlainMonthDay#toLocaleString` with a locale's * default calendar throws and this does not. * - **`dateStyle`** (AdjustDateTimeStyleFormat, « [[Month]], [[Day]] »). The month and day widths * are the locale's own `dateStyle` pattern's, read by {@link dateStyleWidths}: de-DE `medium` * is `25.12.`, ja-JP `long` `12/25` and en-US `medium` `Dec 25`, as native * `PlainMonthDay#toLocaleString` prints them. Polyfill 0.5.1 maps the style to fixed widths * instead (`25. Dez.`, `12月25日`). * - **Fields** (GetDateTimeFormat, required and defaults ~month-day~, inherit ~relevant~): only * `month` and `day` are copied. `era`, `year`, `weekday`, time fields and `timeZoneName` are * dropped. With neither `month` nor `day`, a `weekday`, `year`, `dayPeriod`, `hour`, `minute`, * `second` or `fractionalSecondDigits` gives `null` (anyPresent); otherwise month and day default * to `"numeric"`. * - Never passes `year`, so no pattern that prints a year is formatted. * - Returns `null` for a `timeStyle` (a month-day has no time format). * * @param options caller's `Intl.DateTimeFormatOptions` * @param locale the caller's locale, already checked; read only for a `dateStyle` * @returns runtime options anchored at UTC, or `null` when no format exists */ export declare function plainMonthDayFormatOptions(options: Options, locale: string | string[] | undefined): Options | null; /** * Resolve caller options into runtime `Intl.DateTimeFormat` options that * format a PlainYearMonth: year, month and era only, always through the Gregorian calendar. * * - **Calendar (GMT rule).** `calendar` is always `"gregory"`. ICU given `calendar: "iso8601"` and * `{ year: "numeric", month: "long" }` prints `"1970 "` on Node 24 with no month name, and * HandleDateTimeTemporalYearMonth throws a RangeError for any calendar mismatch, so * `PlainYearMonth#toLocaleString` with the locale's default calendar throws and this does not. * - **`dateStyle`** (AdjustDateTimeStyleFormat, « [[Era]], [[Year]], [[Month]] »). The widths * are the locale's own `dateStyle` pattern's, read by {@link dateStyleWidths}: de-DE `medium` * is `10/2026`, zh-CN `full` `2026/10` and en-US `short` `10/26`, as native * `PlainYearMonth#toLocaleString` prints them. Polyfill 0.5.1's `yearMonthAmend` maps the style * to fixed widths instead (`Okt. 2026`, `2026年10月`). * - **Fields** (GetDateTimeFormat, required and defaults ~year-month~, inherit ~relevant~): `year`, * `month` and `era` are copied (`era` qualifies the year). `day`, `weekday`, `dayPeriod`, time * fields and `timeZoneName` are dropped. With neither `year` nor `month`, a `weekday`, `day`, * `dayPeriod`, `hour`, `minute`, `second` or `fractionalSecondDigits` gives `null` * (anyPresent); otherwise year and month default to `"numeric"`, keeping a copied `era`. * - **V8 `Y` crash.** The result passes `year`, so it must only be given to `format`, never to * `formatToParts` or `formatRangeToParts`, where V8 before 15.5 traps. * - Returns `null` for a `timeStyle` (a year-month has no time format). * * @param options caller's `Intl.DateTimeFormatOptions` * @param locale the caller's locale, already checked; read only for a `dateStyle` * @returns runtime options anchored at UTC, or `null` when no format exists */ export declare function plainYearMonthFormatOptions(options: Options, locale: string | string[] | undefined): Options | null; export {};