diff --git a/src/util/time.ts b/src/util/time.ts index ccfe5889..e10c8223 100644 --- a/src/util/time.ts +++ b/src/util/time.ts @@ -112,3 +112,29 @@ 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: '2-digit', + minute: '2-digit', + second: '2-digit', + }).format(d); +} diff --git a/src/views/Trends.vue b/src/views/Trends.vue index bf25ca77..c35748fb 100644 --- a/src/views/Trends.vue +++ b/src/views/Trends.vue @@ -89,7 +89,7 @@ div