From 2071c87ffe42fcc3246ef65c492b90014dbf378d Mon Sep 17 00:00:00 2001 From: Bob Date: Thu, 2 Jul 2026 14:15:21 +0000 Subject: [PATCH 1/3] fix(i18n): use Intl.DateTimeFormat for date/time display in Trends and timeline MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replaces hardcoded moment().format('MMM D'), moment().format('ddd, MMM D'), and moment().format('HH:mm:ss') calls with locale-aware Intl.DateTimeFormat helpers, so dates and times respect the browser's locale instead of always rendering in English. Adds three new helpers to src/util/time.ts: - format_date_short(): "Jun 15" → "15 jun" in sv-SE - format_date_with_weekday(): "Mon, Jun 15" → "mån 15 jun" in sv-SE - format_time_of_day(): "14:30:05" or "2:30:05 PM" per locale Fixes the date labels in Trends.vue (range labels, busiest-day label) and the event clocktime in the timeline visualization popup. --- src/util/time.ts | 22 ++++++++++++++++++++++ src/views/Trends.vue | 12 ++++++------ src/visualizations/timeline.ts | 4 ++-- 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/src/util/time.ts b/src/util/time.ts index ccfe5889..74541eb6 100644 --- a/src/util/time.ts +++ b/src/util/time.ts @@ -112,3 +112,25 @@ export function get_short_month_labels(locale?: string | string[]) { new Intl.DateTimeFormat(locale, { month: 'short' }).format(new Date(2020, month, 1, 12)) ); } + +// Format a date as locale-aware short date (e.g. "Jun 15" in en-US, "15 jun" in sv-SE) +export function format_date_short(date: Date | string, locale?: string | string[]) { + const d = date instanceof Date ? date : new Date(date); + return new Intl.DateTimeFormat(locale, { month: 'short', day: 'numeric' }).format(d); +} + +// Format a date with weekday prefix (e.g. "Mon, Jun 15" in en-US, "mån 15 jun" in sv-SE) +export function format_date_with_weekday(date: Date | string, locale?: string | string[]) { + const d = date instanceof Date ? date : new Date(date); + return new Intl.DateTimeFormat(locale, { weekday: 'short', month: 'short', day: 'numeric' }).format(d); +} + +// Format a time-of-day string locale-aware (e.g. "14:30:05" or "2:30:05 PM" per browser locale) +export function format_time_of_day(date: Date | string, locale?: string | string[]) { + const d = date instanceof Date ? date : new Date(date); + return new Intl.DateTimeFormat(locale, { + hour: 'numeric', + minute: '2-digit', + second: '2-digit', + }).format(d); +} diff --git a/src/views/Trends.vue b/src/views/Trends.vue index bf25ca77..7c07d018 100644 --- a/src/views/Trends.vue +++ b/src/views/Trends.vue @@ -89,7 +89,7 @@ div