diff --git a/crates/forge-web/assets/nav.js b/crates/forge-web/assets/nav.js index 5df3573..e2475ce 100644 --- a/crates/forge-web/assets/nav.js +++ b/crates/forge-web/assets/nav.js @@ -1572,10 +1572,22 @@ return { idx: 1 + 2 * units[u][1] + (n === 1 ? 0 : 1), n: n, next: next }; } + // The wording for a time still ahead, `secs` whole seconds away. Under a minute reads "in 1 minute". + // The wording holds until the gap drops below `from`, the start of its unit's count. + function relAhead(secs) { + var units = [[60, 0], [3600, 1], [86400, 2], [2592000, 3], [31536000, 4]]; + var u = 0; + while (u < 4 && secs >= units[u + 1][0]) { u++; } + var size = units[u][0]; + var n = Math.max(1, Math.floor(secs / size)); + var from = secs < 60 ? 0 : n * size; + return { idx: 11 + 2 * units[u][1] + (n === 1 ? 0 : 1), n: n, from: from }; + } + function relUpdate() { relTimer = null; var words = (document.documentElement.getAttribute('data-rel-words') || '').split('|'); - if (words.length < 11) { return; } // no wording from the server: nothing to re-word + if (words.length < 21) { return; } // no wording from the server: nothing to re-word var nowSec = (Date.now() + relSkew) / 1000; var soonest = Infinity; Array.prototype.forEach.call(document.querySelectorAll('time[data-rel]'), function (el) { @@ -1583,10 +1595,17 @@ if (isNaN(at)) { return; } var unix = Math.floor(at / 1000); var age = nowSec - unix; - var w = relWording(Math.max(0, Math.floor(age))); + var w, changeAt; // changeAt: the moment, in seconds, when the wording next changes + if (age < 0) { + w = relAhead(Math.floor(-age)); + changeAt = unix - w.from; + } else { + w = relWording(Math.floor(age)); + changeAt = unix + w.next; + } var label = words[w.idx].replace('{n}', w.n); if (el.textContent !== label) { el.textContent = label; } - soonest = Math.min(soonest, unix + w.next - nowSec); + soonest = Math.min(soonest, changeAt - nowSec); }); if (soonest !== Infinity) { relTimer = setTimeout(relUpdate, Math.max(0, Math.ceil(soonest * 1000)) + 50); diff --git a/crates/forge-web/src/i18n/alerts.rs b/crates/forge-web/src/i18n/alerts.rs index 316d1f4..d481990 100644 --- a/crates/forge-web/src/i18n/alerts.rs +++ b/crates/forge-web/src/i18n/alerts.rs @@ -167,14 +167,6 @@ pub fn settings_link(lang: Lang) -> &'static str { } } -/// "since