aboutsummaryrefslogtreecommitdiff
path: root/static
diff options
context:
space:
mode:
authortdro <tdro@noreply.example.com>2023-10-15 17:17:20 -0400
committertdro <tdro@noreply.example.com>2023-10-15 17:17:20 -0400
commita098764110b882a261fe0bf6ad14b7a0ea6e9f72 (patch)
treebb8b2f36eeec78e05aca6c241e25d38cdba2586e /static
parent30f40a84cf28fbffca82d04a35904eb2674593ae (diff)
downloadcanory-a098764110b882a261fe0bf6ad14b7a0ea6e9f72.tar.gz
canory-a098764110b882a261fe0bf6ad14b7a0ea6e9f72.tar.bz2
canory-a098764110b882a261fe0bf6ad14b7a0ea6e9f72.zip
static/js/timeago: Localize time
Diffstat (limited to 'static')
-rw-r--r--static/js/timeago.ts12
1 files changed, 12 insertions, 0 deletions
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); }