From a098764110b882a261fe0bf6ad14b7a0ea6e9f72 Mon Sep 17 00:00:00 2001 From: tdro Date: Sun, 15 Oct 2023 17:17:20 -0400 Subject: static/js/timeago: Localize time --- static/js/timeago.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'static') diff --git a/static/js/timeago.ts b/static/js/timeago.ts index 47f6b79..2949d44 100644 --- a/static/js/timeago.ts +++ b/static/js/timeago.ts @@ -39,6 +39,18 @@ const past = Math.sign(seconds) === 1; const future = Math.sign(seconds) === -1; + if (element.dataset.type === "localDate") { + return element.textContent = new Intl.DateTimeFormat([], { + dateStyle: "medium", + }).format(time).replace(",", ""); + } + + if (element.dataset.type === "localTime") { + return element.textContent = new Intl.DateTimeFormat([], { + hour12: false, timeStyle: "short", + }).format(time) + " " + new Intl.DateTimeFormat([], { timeZoneName: "short" }).format(time).split(" ")[1]; + } + if (past) { if (seconds <= 60) { return element.textContent = tiny(relative.format(-1 * seconds, "second",), 1); } if (minutes <= 120) { return element.textContent = tiny(relative.format(-1 * minutes, "minute",), 1); } -- cgit v1.2.3