From 2b5fd186627ca1b4d230656e9c095f3b5615a604 Mon Sep 17 00:00:00 2001 From: imoize <51510865+imoize@users.noreply.github.com> Date: Sat, 31 Aug 2024 06:48:49 +0700 Subject: [PATCH] fix(Improvement): Precision timestamp display for modified models. --- package/contents/ui/Utils.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/package/contents/ui/Utils.js b/package/contents/ui/Utils.js index 3ded6d6..1368e5a 100644 --- a/package/contents/ui/Utils.js +++ b/package/contents/ui/Utils.js @@ -53,13 +53,21 @@ function getModels() { function diffTime(date) { const now = new Date(); const diffInMs = now - date; - const diffInMinutes = Math.round(diffInMs / (60 * 1000)); - const diffInDays = Math.round(diffInMs / (24 * 60 * 60 * 1000)); + const diffInSeconds = Math.floor(diffInMs / 1000); + const diffInMinutes = Math.floor(diffInSeconds / 60); + const diffInHours = Math.floor(diffInMinutes / 60); + const diffInDays = Math.floor(diffInHours / 24); - if (diffInDays === 0) { + if (diffInDays > 0) { + return `${diffInDays} Day${diffInDays !== 1 ? 's' : ''} Ago`; + } else if (diffInHours > 0) { + return `${diffInHours} Hour${diffInHours !== 1 ? 's' : ''} Ago`; + } else if (diffInMinutes > 0) { return `${diffInMinutes} Minute${diffInMinutes !== 1 ? 's' : ''} Ago`; + } else if (diffInSeconds >= 10) { + return `${diffInSeconds} Second${diffInSeconds !== 1 ? 's' : ''} Ago`; } else { - return `${diffInDays} Day${diffInDays !== 1 ? 's' : ''} Ago`; + return "Just now"; } }