From 4cd3611251a03f9d8ed43461a93b464078b2fa44 Mon Sep 17 00:00:00 2001 From: MickaelK Date: Fri, 4 Oct 2024 19:24:31 +1000 Subject: [PATCH] fix (time): better date formating --- public/assets/pages/filespage/thing.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/public/assets/pages/filespage/thing.js b/public/assets/pages/filespage/thing.js index 1c99cbe4..dd4f69ec 100644 --- a/public/assets/pages/filespage/thing.js +++ b/public/assets/pages/filespage/thing.js @@ -86,7 +86,7 @@ export function createThing({ $thing.setAttribute("data-n", n); $thing.setAttribute("data-path", path); $thing.classList.add("view-" + view); - $time.textContent = formatTime(new Date(time)); + $time.textContent = formatTime(time); $img.setAttribute("src", (type === "file" ? IMAGE.FILE : IMAGE.FOLDER)); $label.textContent = name; @@ -192,7 +192,9 @@ export function createThing({ return $thing; } -function formatTime(date) { +function formatTime(unixTime) { + if (unixTime <= 0) return ""; + const date = new Date(unixTime); if (!date) return ""; // Intl.DateTimeFormat is slow and in the hot path, so // let's render date manually if possible