fix (time): better date formating

This commit is contained in:
MickaelK 2024-10-04 19:24:31 +10:00
parent 5c87904cb1
commit 4cd3611251

View file

@ -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