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 /assets | |
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 'assets')
-rw-r--r-- | assets/js/index.js | 36 |
1 files changed, 26 insertions, 10 deletions
diff --git a/assets/js/index.js b/assets/js/index.js index 7deaee1..b26ece2 100644 --- a/assets/js/index.js +++ b/assets/js/index.js @@ -503,17 +503,33 @@ const minutes = Math.floor(seconds / 60); const hours = Math.floor(minutes / 60); const days = 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 (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 (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("Error: Unable to resolve relative time format!", error); |