diff options
author | tdro <tdro@noreply.example.com> | 2023-10-15 17:17:20 -0400 |
---|---|---|
committer | tdro <tdro@noreply.example.com> | 2023-10-15 17:17:20 -0400 |
commit | a098764110b882a261fe0bf6ad14b7a0ea6e9f72 (patch) | |
tree | bb8b2f36eeec78e05aca6c241e25d38cdba2586e /assets | |
parent | 30f40a84cf28fbffca82d04a35904eb2674593ae (diff) | |
download | canory-a098764110b882a261fe0bf6ad14b7a0ea6e9f72.tar.gz canory-a098764110b882a261fe0bf6ad14b7a0ea6e9f72.tar.bz2 canory-a098764110b882a261fe0bf6ad14b7a0ea6e9f72.zip |
static/js/timeago: Localize time
Diffstat (limited to 'assets')
-rw-r--r-- | assets/js/index.js | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/assets/js/index.js b/assets/js/index.js index dc4fef1..3d133fd 100644 --- a/assets/js/index.js +++ b/assets/js/index.js @@ -593,6 +593,19 @@ const days = Math.round(hours / 24); 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); |