aboutsummaryrefslogtreecommitdiff
path: root/static/js
diff options
context:
space:
mode:
authortdro <tdro@noreply.example.com>2023-10-07 20:19:06 -0400
committertdro <tdro@noreply.example.com>2023-10-07 20:19:06 -0400
commitc83c49b0e18f0593a62a8a7754d1ff49ac097289 (patch)
treeecf67e580ce99de31816573afd88fdff5e57bfcb /static/js
parent6f2f44c7ff0e3ff8ffd4e6bb394a0b39c0f89adf (diff)
downloadcanory-c83c49b0e18f0593a62a8a7754d1ff49ac097289.tar.gz
canory-c83c49b0e18f0593a62a8a7754d1ff49ac097289.tar.bz2
canory-c83c49b0e18f0593a62a8a7754d1ff49ac097289.zip
themes/default: Make time and dates consistent
Don't mix local time with UTC and fix future date calculation
Diffstat (limited to 'static/js')
-rw-r--r--static/js/timeago.ts18
1 files changed, 9 insertions, 9 deletions
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(