Speed up language switching by caching date formatters

formatDateTime created two Intl formatters per call. Re-formatting 13,000 history rows on a language switch froze the window for more than a second. Cached formatters produce identical output in about 25 ms.
This commit is contained in:
Sucukdeluxe committed 2026-09-26 10:18:58 +02:00
1 parent 1ebe77ae10
commit 02ba0adbae
1 file changed
+16 -2
+16 -2
View File
@@ -10090,13 +10090,27 @@ function formatTime(seconds) {
function pad(n) { return String(Math.floor(n)).padStart(2, '0'); }
const _dateTimeFormatters = new Map();
function getDateTimeFormatters(locale) {
let formatters = _dateTimeFormatters.get(locale);
if (!formatters) {
formatters = {
date: new Intl.DateTimeFormat(locale, { day: '2-digit', month: '2-digit', year: 'numeric' }),
time: new Intl.DateTimeFormat(locale, { hour: '2-digit', minute: '2-digit', second: '2-digit' })
};
_dateTimeFormatters.set(locale, formatters);
}
return formatters;
}
function formatDateTime(value) {
const date = value instanceof Date ? value : new Date(value);
if (Number.isNaN(date.getTime())) return { ts: 0, text: localizeUiText('Unbekannt') };
const formatters = getDateTimeFormatters(getUiLocale());
return {
ts: date.getTime(),
text: date.toLocaleDateString(getUiLocale(), { day: '2-digit', month: '2-digit', year: 'numeric' })
+ ' ' + date.toLocaleTimeString(getUiLocale(), { hour: '2-digit', minute: '2-digit', second: '2-digit' })
text: formatters.date.format(date) + ' ' + formatters.time.format(date)
};
}