@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.
50 lines • 3.05 kB
TypeScript
/** A range an engine must print complete. */
export interface RangeFieldCase {
/** Short name, unique among the cases. */
readonly name: string;
readonly locale: string;
readonly options: Intl.DateTimeFormatOptions;
readonly from: number;
readonly to: number;
/**
* Each field text a complete range holds, with the fewest and most times it appears. A field a
* range drops counts 0 (below the fewest), one it repeats counts above the most, and a text
* that must never appear (two fields run together) is `0, 0`. A text only one date prints is
* exactly once; a text both dates may print is one or two. The optional last number pins a text
* to the start's side (0) or the end's side (1) of the first dash or tilde.
*/
readonly fields: readonly (readonly [text: string, min: number, max: number, side?: 0 | 1])[];
}
/**
* One case per cause of the sweep (794,400 formatters, Node 22.22.2, 24.21.0 and 26.12.1), each the
* shortest range that shows it. The gate (`isRangeFieldCompatNeeded`) stays on while any one of
* them is broken, as the causes are fixed one at a time upstream.
*
* - chinese drops `relatedYear` from a range a year apart;
* - `hi` drops a `B` day period, `ta` prints one for two (ICU-23622), `bgc` writes `PM` where the
* single writes the long period (ICU-23625);
* - hebrew prints the end's month with the wrong value (`fur`);
* - malformed CLDR patterns (CLDR-19912): `yo` prints the end's weekday twice and a year on the
* wrong side, `sw` drops the start's month, `rw` repeats a day, `ta` shortens a zone name, `hy` and
* `az` drop the end's year or era in a `G` pattern, `it` and `brx` run two numbers together,
* `zh` `iso8601` runs a month and a day together (CLDR-19913);
* - ICU takes the `y` pattern when only the era differs (ICU-23623): `scn` drops the start's era,
* `ko` japanese writes `S` and `R` for the eras;
* - `ja` writes `0時` for the hour 12 under `hourCycle: "h12"` (ICU-23624).
*/
export declare const rangeFieldCases: readonly RangeFieldCase[];
/**
* `"complete"` when the engine's range holds every field text of the case the stated number of times, else the range text itself
* (so a canary shows what the engine printed). A locale the runtime has no data for formats in the
* fallback locale and cannot show a defect of its own data, so it answers `"complete"`
* (ECMA-402 ResolveLocale falls back to the default locale).
*
* @param locale the locale
* @param options the formatter options (UTC is added)
* @param from range start, epoch milliseconds
* @param to range end, epoch milliseconds
* @returns `"complete"`, or the engine's range text
*
* @example rangeFieldProblem("yo", { year: "numeric", month: "numeric", day: "numeric", weekday: "short" }, 1720622100000, 1720708500000) // "Ọjọ́rú, 10-07-2024 – Ọjọ́bọ 11-07-2024, Ọjọ́bọ" where the engine repeats a weekday
*/
export declare function rangeFieldProblem(locale: string, options: Intl.DateTimeFormatOptions, from: number, to: number): string;