mirror of
https://github.com/fluxerapp/fluxer.git
synced 2026-09-03 05:10:25 +03:00
19 lines
616 B
TypeScript
19 lines
616 B
TypeScript
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
const formatterCache = new Map<string, Intl.DateTimeFormat>();
|
|
|
|
function buildCacheKey(locale: string, options: Intl.DateTimeFormatOptions): string {
|
|
return `${locale}:${JSON.stringify(options)}`;
|
|
}
|
|
|
|
export function getDateFormatter(locale: string, options: Intl.DateTimeFormatOptions = {}): Intl.DateTimeFormat {
|
|
const key = buildCacheKey(locale, options);
|
|
const cached = formatterCache.get(key);
|
|
if (cached !== undefined) {
|
|
return cached;
|
|
}
|
|
const formatter = new Intl.DateTimeFormat(locale, options);
|
|
formatterCache.set(key, formatter);
|
|
return formatter;
|
|
}
|