From c83c49b0e18f0593a62a8a7754d1ff49ac097289 Mon Sep 17 00:00:00 2001 From: tdro Date: Sat, 7 Oct 2023 20:19:06 -0400 Subject: themes/default: Make time and dates consistent Don't mix local time with UTC and fix future date calculation --- assets/js/index.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'assets/js') diff --git a/assets/js/index.js b/assets/js/index.js index 72e6736..4ae6d7c 100644 --- a/assets/js/index.js +++ b/assets/js/index.js @@ -566,10 +566,10 @@ try { const time = new Date(element.dateTime) || new Date(); const interval = (new Date().getTime() - time.getTime()) / 1000; - const seconds = Math.floor(interval); - const minutes = Math.floor(seconds / 60); - const hours = Math.floor(minutes / 60); - const days = Math.floor(hours / 24); + const seconds = Math.round(interval); + const minutes = Math.round(seconds / 60); + const hours = Math.round(minutes / 60); + const days = Math.round(hours / 24); const past = Math.sign(seconds) === 1; const future = Math.sign(seconds) === -1; if (past) { @@ -582,21 +582,21 @@ if (hours <= 48) { return element.textContent = relative.format(-1 * hours, "hour"); } - if (days <= 60) { + if (days <= 7) { return element.textContent = relative.format(-1 * days, "day"); } } if (future) { - if (-1 * days >= 60) { + if (-1 * days >= 4) { return element.textContent = relative.format(-1 * days, "day"); } - if (-1 * hours >= 48) { + if (-1 * hours >= 3) { return element.textContent = relative.format(-1 * hours, "hour"); } - if (-1 * minutes >= 120) { + if (-1 * minutes >= 2) { return element.textContent = relative.format(-1 * minutes, "minute"); } - if (-1 * seconds >= 0) { + if (-1 * seconds >= 1) { return element.textContent = relative.format(-1 * seconds, "second"); } } -- cgit v1.2.3