@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.
38 lines (37 loc) • 1.04 kB
JavaScript
// src/internal/patternKey.ts
/** The options that make a formatter print time. */
const TIME_KEYS = [
"hour",
"minute",
"second",
"fractionalSecondDigits",
"dayPeriod",
"timeZoneName",
"timeStyle"
];
/** The options that give a formatter a date pattern. */
const DATE_KEYS = [
"era",
"year",
"month",
"day",
"weekday",
"dateStyle"
];
/**
* The verdict-cache key: the pattern, never the zone (a zone moves the instant, not the pattern).
* Only the options that choose the pattern are read; locale, calendar, numbering system and hour
* cycle come from what the formatter resolved, so a value `Intl` ignores or resolves to the same
* thing (`calendar: "always"`, `hour12` next to an `hourCycle`) shares one verdict.
*/
function verdictKey(options, resolved) {
return JSON.stringify([
resolved.locale,
resolved.calendar,
resolved.numberingSystem,
resolved.hourCycle ?? "",
options.formatMatcher ?? "",
[...DATE_KEYS, ...TIME_KEYS].map((key) => options[key] ?? "")
]);
}
export { DATE_KEYS, TIME_KEYS, verdictKey };