diff options
-rw-r--r-- | assets/js/index.js | 13 | ||||
-rw-r--r-- | static/js/timeago.ts | 12 | ||||
-rw-r--r-- | themes/default/layouts/partials/meta-context-menu.html | 14 |
3 files changed, 37 insertions, 2 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); 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); } diff --git a/themes/default/layouts/partials/meta-context-menu.html b/themes/default/layouts/partials/meta-context-menu.html index 064d0d8..9429355 100644 --- a/themes/default/layouts/partials/meta-context-menu.html +++ b/themes/default/layouts/partials/meta-context-menu.html @@ -27,11 +27,21 @@ <micro-metadata-datetime> <a href="{{ $href }}"> {{- safeHTML (readFile (print (partial "function-paths.html").static "/icons/feather/calendar.svg")) -}} - <span>{{ .Date | time.Format "Jan 2 2006" -}}</span> + <time + data-type="localDate" + datetime="{{ .Date | time.Format "2006-01-02T15:04:05Z" }}" + > + {{ .Date | time.Format "Jan 2 2006" -}} + </time> </a> <a href="{{ $href }}"> {{- safeHTML (readFile (print (partial "function-paths.html").static "/icons/feather/clock.svg")) -}} - <span>{{ .Date | time.Format "15:04 MST" -}}</span> + <time + data-type="localTime" + datetime="{{ .Date | time.Format "2006-01-02T15:04:05Z" }}" + > + {{ .Date | time.Format "15:04 MST" -}} + </time> </a> </micro-metadata-datetime> </context-menu> |