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 --- static/js/timeago.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'static/js') diff --git a/static/js/timeago.ts b/static/js/timeago.ts index 178bdf4..55616f0 100644 --- a/static/js/timeago.ts +++ b/static/js/timeago.ts @@ -27,10 +27,10 @@ const time: millisecond = new Date(element.dateTime) || new Date(); const interval: second = ((new Date().getTime() - time.getTime()) / 1000); - const seconds: number = Math.floor(interval); - const minutes: number = Math.floor(seconds / 60); - const hours: number = Math.floor(minutes / 60); - const days: number = Math.floor(hours / 24); + const seconds: number = Math.round(interval); + const minutes: number = Math.round(seconds / 60); + const hours: number = Math.round(minutes / 60); + const days: number = Math.round(hours / 24); const past = Math.sign(seconds) === 1; const future = Math.sign(seconds) === -1; @@ -39,14 +39,14 @@ if (seconds <= 60) { return element.textContent = relative.format(-1 * seconds, "second",); } if (minutes <= 120) { return element.textContent = relative.format(-1 * minutes, "minute",); } if (hours <= 48) { return element.textContent = relative.format(-1 * hours, "hour",); } - if (days <= 60) { return element.textContent = relative.format(-1 * days, "day",); } + if (days <= 7) { return element.textContent = relative.format(-1 * days, "day",); } } if (future) { - if (-1 * days >= 60) { return element.textContent = relative.format(-1 * days, "day",); } - if (-1 * hours >= 48) { return element.textContent = relative.format(-1 * hours, "hour",); } - if (-1 * minutes >= 120) { return element.textContent = relative.format(-1 * minutes, "minute",); } - if (-1 * seconds >= 0) { return element.textContent = relative.format(-1 * seconds, "second",); } + if (-1 * days >= 4) { return element.textContent = relative.format(-1 * days, "day",); } + if (-1 * hours >= 3) { return element.textContent = relative.format(-1 * hours, "hour",); } + if (-1 * minutes >= 2) { return element.textContent = relative.format(-1 * minutes, "minute",); } + if (-1 * seconds >= 1) { return element.textContent = relative.format(-1 * seconds, "second",); } } } catch (error) { console.error( -- cgit v1.2.3