diff options
author | tdro <tdro@noreply.example.com> | 2022-11-19 10:21:21 -0500 |
---|---|---|
committer | tdro <tdro@noreply.example.com> | 2022-11-19 10:21:21 -0500 |
commit | b050093fa02c5fc1d1ed70b6a6aafb44a86a2d36 (patch) | |
tree | b540bcd9a2946bd4e1e340c47ede308d4626a0a4 /static | |
parent | 886e656644c9895f7c5350411898ae35f495d9a2 (diff) | |
download | canory-b050093fa02c5fc1d1ed70b6a6aafb44a86a2d36.tar.gz canory-b050093fa02c5fc1d1ed70b6a6aafb44a86a2d36.tar.bz2 canory-b050093fa02c5fc1d1ed70b6a6aafb44a86a2d36.zip |
static/js/timeago: Resolve relative format for future dates
Diffstat (limited to 'static')
-rw-r--r-- | static/js/timeago.ts | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/static/js/timeago.ts b/static/js/timeago.ts index 6e56063..af974fc 100644 --- a/static/js/timeago.ts +++ b/static/js/timeago.ts @@ -21,10 +21,19 @@ const hours: number = Math.floor(minutes / 60); const days: number = Math.floor(hours / 24); - 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 (Math.sign(seconds) === 1) { + 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 (Math.sign(seconds) === -1) { + 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",); } + } } catch (error) { console.error( |