forge
Explore
Log in

Don't you dare go Hollow

Relative times are live on token, session, key, passkey, security, health and review pages

Browse files at this commit

0a2c24cd7a5d7f5bc68c202309069e809ff07ceeAhmet Kaan GümüşParent: 4867bd3
  • feat
    • relative times are live on token, session, key, passkey, security, health and review pages
Show full message
⚡ feat: relative times are live on token, session, key, passkey, security, health and review pages

Stamps render as <time data-rel> that nav.js re-words as the clock moves. Future times read
"in 3 months" (and "3 ay sonra"), so token expiry reads naturally.
crates/forge-web/assets/nav.jsmodified+22 -3
@@ -1572,10 +1572,22 @@
15721572 return { idx: 1 + 2 * units[u][1] + (n === 1 ? 0 : 1), n: n, next: next };
15731573 }
15741574
1575+ // The wording for a time still ahead, `secs` whole seconds away. Under a minute reads "in 1 minute".
1576+ // The wording holds until the gap drops below `from`, the start of its unit's count.
1577+ function relAhead(secs) {
1578+ var units = [[60, 0], [3600, 1], [86400, 2], [2592000, 3], [31536000, 4]];
1579+ var u = 0;
1580+ while (u < 4 && secs >= units[u + 1][0]) { u++; }
1581+ var size = units[u][0];
1582+ var n = Math.max(1, Math.floor(secs / size));
1583+ var from = secs < 60 ? 0 : n * size;
1584+ return { idx: 11 + 2 * units[u][1] + (n === 1 ? 0 : 1), n: n, from: from };
1585+ }
1586+
15751587 function relUpdate() {
15761588 relTimer = null;
15771589 var words = (document.documentElement.getAttribute('data-rel-words') || '').split('|');
1578- if (words.length < 11) { return; } // no wording from the server: nothing to re-word
1590+ if (words.length < 21) { return; } // no wording from the server: nothing to re-word
15791591 var nowSec = (Date.now() + relSkew) / 1000;
15801592 var soonest = Infinity;
15811593 Array.prototype.forEach.call(document.querySelectorAll('time[data-rel]'), function (el) {
@@ -1583,10 +1595,17 @@
15831595 if (isNaN(at)) { return; }
15841596 var unix = Math.floor(at / 1000);
15851597 var age = nowSec - unix;
1586- var w = relWording(Math.max(0, Math.floor(age)));
1598+ var w, changeAt; // changeAt: the moment, in seconds, when the wording next changes
1599+ if (age < 0) {
1600+ w = relAhead(Math.floor(-age));
1601+ changeAt = unix - w.from;
1602+ } else {
1603+ w = relWording(Math.floor(age));
1604+ changeAt = unix + w.next;
1605+ }
15871606 var label = words[w.idx].replace('{n}', w.n);
15881607 if (el.textContent !== label) { el.textContent = label; }
1589- soonest = Math.min(soonest, unix + w.next - nowSec);
1608+ soonest = Math.min(soonest, changeAt - nowSec);
15901609 });
15911610 if (soonest !== Infinity) {
15921611 relTimer = setTimeout(relUpdate, Math.max(0, Math.ceil(soonest * 1000)) + 50);
crates/forge-web/src/i18n/alerts.rsmodified+0 -8
@@ -167,14 +167,6 @@ pub fn settings_link(lang: Lang) -> &'static str {
167167 }
168168 }
169169
170-/// "since <time>" on the banner.
171-pub fn since(lang: Lang, when: &str) -> String {
172- match lang {
173- Lang::En => format!("since {when}"),
174- Lang::Tr => format!("{when} tarihinden beri"),
175- }
176-}
177-
178170 /// Email subject: the title, tagged with the instance.
179171 pub fn mail_subject(lang: Lang, title: &str) -> String {
180172 match lang {
crates/forge-web/src/i18n/mod.rsmodified+45 -120
@@ -1122,27 +1122,37 @@ pub fn just_now(lang: Lang) -> &'static str {
11221122 /// "3 days ago", or "3 gün önce". Turkish nouns stay singular after a number.
11231123 pub fn ago(lang: Lang, n: i64, unit: TimeUnit) -> String {
11241124 match lang {
1125- Lang::En => {
1126- let word = match unit {
1127- TimeUnit::Minute => "minute",
1128- TimeUnit::Hour => "hour",
1129- TimeUnit::Day => "day",
1130- TimeUnit::Month => "month",
1131- TimeUnit::Year => "year",
1132- };
1133- let plural = if n == 1 { "" } else { "s" };
1134- format!("{n} {word}{plural} ago")
1135- }
1136- Lang::Tr => {
1137- let word = match unit {
1138- TimeUnit::Minute => "dakika",
1139- TimeUnit::Hour => "saat",
1140- TimeUnit::Day => "gün",
1141- TimeUnit::Month => "ay",
1142- TimeUnit::Year => "yıl",
1143- };
1144- format!("{n} {word} önce")
1145- }
1125+ Lang::En => format!("{n} {}{} ago", unit_name(lang, unit), plural(n)),
1126+ Lang::Tr => format!("{n} {} önce", unit_name(lang, unit)),
1127+ }
1128+}
1129+
1130+/// "in 3 days", or "3 gün sonra": a time still to come.
1131+pub fn from_now(lang: Lang, n: i64, unit: TimeUnit) -> String {
1132+ match lang {
1133+ Lang::En => format!("in {n} {}{}", unit_name(lang, unit), plural(n)),
1134+ Lang::Tr => format!("{n} {} sonra", unit_name(lang, unit)),
1135+ }
1136+}
1137+
1138+/// The English plural suffix for a count.
1139+fn plural(n: i64) -> &'static str {
1140+ if n == 1 { "" } else { "s" }
1141+}
1142+
1143+/// The unit's word: "day" or "gün". Turkish nouns stay singular after a number.
1144+fn unit_name(lang: Lang, unit: TimeUnit) -> &'static str {
1145+ match (lang, unit) {
1146+ (Lang::En, TimeUnit::Minute) => "minute",
1147+ (Lang::En, TimeUnit::Hour) => "hour",
1148+ (Lang::En, TimeUnit::Day) => "day",
1149+ (Lang::En, TimeUnit::Month) => "month",
1150+ (Lang::En, TimeUnit::Year) => "year",
1151+ (Lang::Tr, TimeUnit::Minute) => "dakika",
1152+ (Lang::Tr, TimeUnit::Hour) => "saat",
1153+ (Lang::Tr, TimeUnit::Day) => "gün",
1154+ (Lang::Tr, TimeUnit::Month) => "ay",
1155+ (Lang::Tr, TimeUnit::Year) => "yıl",
11461156 }
11471157 }
11481158
@@ -1164,69 +1174,12 @@ pub fn visibility_label(lang: Lang, visibility: forge_core::Visibility) -> &'sta
11641174 }
11651175 }
11661176
1167-/// "Added 2026-01-02", with the last use appended when there is one.
1168-pub fn added_line(lang: Lang, created: &str, last_used: Option<&str>) -> String {
1169- let added = match lang {
1170- Lang::En => format!("{} {created}", t(lang, Key::Added)),
1171- Lang::Tr => format!("{created} tarihinde {}", t(lang, Key::Added)),
1172- };
1173- match last_used {
1174- None => added,
1175- Some(used) => match lang {
1176- Lang::En => format!("{added} · {} {used}", t(lang, Key::LastUsed)),
1177- Lang::Tr => format!("{added} · {}: {used}", t(lang, Key::LastUsed)),
1178- },
1179- }
1180-}
1181-
1182-/// A token's dates: "Created X · last used Y · expires Z". A missing use or expiry reads "never".
1183-pub fn token_meta(
1184- lang: Lang,
1185- created: &str,
1186- last_used: Option<&str>,
1187- expires: Option<&str>,
1188-) -> String {
1189- let used = last_used.unwrap_or(t(lang, Key::Never));
1190- let expiry = expires.unwrap_or(t(lang, Key::Never));
1191- dated_line(
1192- lang,
1193- (Key::Created, created),
1194- (Key::LastUsed, used),
1195- (Key::ExpiresLabel, expiry),
1196- )
1197-}
1198-
1199-/// A web session's dates: "Signed in X · last seen Y · expires Z".
1200-pub fn session_meta(lang: Lang, signed_in: &str, last_seen: &str, expires: &str) -> String {
1201- dated_line(
1202- lang,
1203- (Key::SignedIn, signed_in),
1204- (Key::LastSeen, last_seen),
1205- (Key::ExpiresLabel, expires),
1206- )
1207-}
1208-
1209-/// Three labelled dates joined with " · ". English reads "Label value"; Turkish reads "Etiket: value".
1210-fn dated_line(lang: Lang, a: (Key, &str), b: (Key, &str), c: (Key, &str)) -> String {
1177+/// The label before a date in a dated line: "Created", or "Oluşturuldu:" in Turkish, where the
1178+/// colon sets it apart from the date.
1179+pub fn dated_label(lang: Lang, key: Key) -> String {
12111180 match lang {
1212- Lang::En => format!(
1213- "{} {} · {} {} · {} {}",
1214- t(lang, a.0),
1215- a.1,
1216- t(lang, b.0),
1217- b.1,
1218- t(lang, c.0),
1219- c.1
1220- ),
1221- Lang::Tr => format!(
1222- "{}: {} · {}: {} · {}: {}",
1223- t(lang, a.0),
1224- a.1,
1225- t(lang, b.0),
1226- b.1,
1227- t(lang, c.0),
1228- c.1
1229- ),
1181+ Lang::En => t(lang, key).to_owned(),
1182+ Lang::Tr => format!("{}:", t(lang, key)),
12301183 }
12311184 }
12321185
@@ -1238,22 +1191,17 @@ pub fn unsupported_key_type(lang: Lang, algorithm: &str) -> String {
12381191 }
12391192 }
12401193
1241-/// "Last changed 3 days ago", with the relative time already rendered.
1242-pub fn last_changed_line(lang: Lang, when: &str) -> String {
1194+/// The label before the password's change time: "Last changed", or "Son değişiklik:" in Turkish.
1195+pub fn last_changed_label(lang: Lang) -> &'static str {
12431196 match lang {
1244- Lang::En => format!("Last changed {when}"),
1245- Lang::Tr => format!("Son değişiklik: {when}"),
1197+ Lang::En => "Last changed",
1198+ Lang::Tr => "Son değişiklik:",
12461199 }
12471200 }
12481201
1249-/// The state of the latest verification mail on the Email row, such as "verification mail sent
1250-/// 5 minutes ago". `sent_ago` is the relative time of the send, when known.
1251-pub fn email_mail_line(
1252- lang: Lang,
1253- state: forge_core::mail::MailState,
1254- attempts: u32,
1255- sent_ago: Option<&str>,
1256-) -> String {
1202+/// The state of the latest verification mail on the Email row, such as "verification mail sent".
1203+/// The send time, when known, follows it as a live relative time.
1204+pub fn email_mail_line(lang: Lang, state: forge_core::mail::MailState, attempts: u32) -> String {
12571205 use forge_core::mail::MailState;
12581206 match (state, lang) {
12591207 (MailState::Queued | MailState::Sending, _) => t(lang, Key::EmailMailQueued).to_owned(),
@@ -1267,32 +1215,9 @@ pub fn email_mail_line(
12671215 attempts + 1
12681216 )
12691217 }
1270- (MailState::Sent, Lang::En) => match sent_ago {
1271- Some(ago) => format!("verification mail sent {ago}"),
1272- None => "verification mail sent".to_owned(),
1273- },
1274- (MailState::Sent, Lang::Tr) => match sent_ago {
1275- Some(ago) => format!("doğrulama iletisi {ago} gönderildi"),
1276- None => "doğrulama iletisi gönderildi".to_owned(),
1277- },
1278- }
1279-}
1280-
1281-/// The device's "Added 2026-10-18 · Last used 5 minutes ago" line. A part without a stamp is
1282-/// left out.
1283-pub fn device_line(lang: Lang, added: Option<&str>, used: Option<&str>) -> String {
1284- let (added_word, used_word) = match lang {
1285- Lang::En => ("Added", "Last used"),
1286- Lang::Tr => ("Eklendi", "Son kullanım"),
1287- };
1288- let mut parts = Vec::new();
1289- if let Some(day) = added {
1290- parts.push(format!("{added_word} {day}"));
1291- }
1292- if let Some(when) = used {
1293- parts.push(format!("{used_word} {when}"));
1218+ (MailState::Sent, Lang::En) => "verification mail sent".to_owned(),
1219+ (MailState::Sent, Lang::Tr) => "doğrulama iletisi gönderildi".to_owned(),
12941220 }
1295- parts.join(" · ")
12961221 }
12971222
12981223 /// "7 of 10 recovery codes unused".
crates/forge-web/src/pages/admin_health.rsmodified+41 -22
@@ -23,13 +23,15 @@ use crate::i18n::{self, Lang};
2323 use crate::live::{Topic, stream_changes};
2424 use crate::pages::admin_users::admin_only;
2525 use crate::state::AppState;
26-use crate::views::{human_size, now_unix, relative_time, shell};
26+use crate::views::{human_size, now_unix, rel_time, shell};
2727
2828 /// One cell of the grid.
2929 struct Tile {
3030 title: &'static str,
3131 big: String,
3232 sub: String,
33+ /// A stamp shown after `sub` as a live relative time.
34+ stamp: Option<String>,
3335 /// `""`, `ok` or `bad`.
3436 tone: &'static str,
3537 /// Percent of a meter to fill, for disk tiles.
@@ -41,6 +43,7 @@ fn tile(title: &'static str, big: impl Into<String>, sub: impl Into<String>) ->
4143 title,
4244 big: big.into(),
4345 sub: sub.into(),
46+ stamp: None,
4447 tone: "",
4548 meter: None,
4649 }
@@ -113,6 +116,7 @@ fn disk_tile(lang: Lang, title: &'static str, space: Option<(u64, u64)>, label:
113116 at(lang, A::Free),
114117 human_size(lang, total)
115118 ),
119+ stamp: None,
116120 tone: if pct >= 90 { "bad" } else { "" },
117121 meter: Some(pct),
118122 }
@@ -220,12 +224,9 @@ async fn tiles(state: &AppState, lang: Lang, tz: &str) -> Result<Vec<Tile>> {
220224 Some(false) => at(lang, A::Failed),
221225 None => at(lang, A::Pending),
222226 },
223- format!(
224- "{} ({})",
225- format_in_tz(at_unix, tz),
226- relative_time(lang, at_unix, now)
227- ),
227+ format_in_tz(at_unix, tz),
228228 );
229+ t.stamp = Some(run.started_at.clone());
229230 t.tone = match run.ok {
230231 Some(true) => "ok",
231232 Some(false) => "bad",
@@ -254,11 +255,13 @@ async fn tiles(state: &AppState, lang: Lang, tz: &str) -> Result<Vec<Tile>> {
254255 } else {
255256 at(lang, A::Ok)
256257 },
257- ok_unix.map_or_else(
258- || at(lang, A::Never).to_owned(),
259- |t| relative_time(lang, t, now),
260- ),
258+ if ok_unix.is_some() {
259+ ""
260+ } else {
261+ at(lang, A::Never)
262+ },
261263 );
264+ t.stamp = status.last_ok_at.clone();
262265 t.tone = if errored || lagging { "bad" } else { "ok" };
263266 t
264267 }
@@ -289,7 +292,9 @@ async fn tiles(state: &AppState, lang: Lang, tz: &str) -> Result<Vec<Tile>> {
289292 struct AlertRow {
290293 title: String,
291294 body: String,
292- since: String,
295+ /// The raised time as the server formats it, and its stamp for the live relative time.
296+ date: String,
297+ stamp: String,
293298 }
294299
295300 /// The alerts active now, worded for the viewer.
@@ -305,19 +310,25 @@ async fn alert_rows(state: &AppState, lang: Lang, tz: &str) -> Result<Vec<AlertR
305310 AlertRow {
306311 title: alert_text::title(lang, &alert.kind, &alert.subject, false),
307312 body: alert_text::body(lang, &alert.kind, &alert.subject, &alert.detail, false),
308- since: alert_text::since(
309- lang,
310- &format!(
311- "{} ({})",
312- format_in_tz(raised, tz),
313- relative_time(lang, raised, now)
314- ),
315- ),
313+ date: format_in_tz(raised, tz),
314+ stamp: alert.raised_at.clone(),
316315 }
317316 })
318317 .collect())
319318 }
320319
320+/// The alert's raised time: "since <date> · <live time>", worded per language.
321+#[component]
322+async fn since_line(lang: Lang, date: &str, stamp: &str) -> Result<impl View> {
323+ Ok(view! {
324+ if matches!(lang, Lang::Tr) {
325+ (date) " · " rel_time(lang: lang, stamp: stamp) " tarihinden beri"
326+ } else {
327+ "since " (date) " · " rel_time(lang: lang, stamp: stamp)
328+ }
329+ })
330+}
331+
321332 #[component]
322333 async fn health_view(lang: Lang, tiles: Vec<Tile>, alerts: Vec<AlertRow>) -> Result<impl View> {
323334 let count = alerts.len();
@@ -334,7 +345,7 @@ async fn health_view(lang: Lang, tiles: Vec<Tile>, alerts: Vec<AlertRow>) -> Res
334345 for a in alerts.into_iter() {
335346 <li>
336347 <strong>(a.title.as_str())</strong>
337- <span class="muted small">(a.since.as_str())</span>
348+ <span class="muted small">since_line(lang: lang, date: a.date.as_str(), stamp: a.stamp.as_str())</span>
338349 if !a.body.is_empty() {
339350 <div class="small">(a.body.as_str())</div>
340351 }
@@ -349,8 +360,16 @@ async fn health_view(lang: Lang, tiles: Vec<Tile>, alerts: Vec<AlertRow>) -> Res
349360 <section class=(format!("tile {}", t.tone))>
350361 <h2>(t.title)</h2>
351362 <div class="big">(t.big.as_str())</div>
352- if !t.sub.is_empty() {
353- <div class="sub">(t.sub.as_str())</div>
363+ if !t.sub.is_empty() || t.stamp.is_some() {
364+ <div class="sub">
365+ (t.sub.as_str())
366+ if let Some(stamp) = t.stamp.as_deref() {
367+ if !t.sub.is_empty() {
368+ " · "
369+ }
370+ rel_time(lang: lang, stamp: stamp)
371+ }
372+ </div>
354373 }
355374 if let Some(pct) = t.meter {
356375 <progress class="meter" max="100" value=(pct.to_string())></progress>
crates/forge-web/src/pages/passkeys.rsmodified+11 -19
@@ -14,7 +14,6 @@ use base64::Engine;
1414 use base64::engine::general_purpose::URL_SAFE_NO_PAD;
1515 use forge_core::session::new_csrf_token;
1616 use forge_core::store::passkeys::{MAX_PASSKEYS, PasskeyRow, clean_name};
17-use forge_core::time::stamp_to_unix;
1817 use forge_core::{AuditAction, User};
1918 use http::header::{HeaderValue, RETRY_AFTER};
2019 use serde::Deserialize;
@@ -36,14 +35,14 @@ use webauthn_rs_proto::ResidentKeyRequirement;
3635 use crate::api;
3736 use crate::audit::{self, Actor, Target};
3837 use crate::auth::{
39- check_pre_csrf, clear_pending_login, clear_pre_csrf, login, require_csrf, safe_next, unix_now,
38+ check_pre_csrf, clear_pending_login, clear_pre_csrf, login, require_csrf, safe_next,
4039 };
4140 use crate::client_ip::client_ip;
4241 use crate::i18n::{self, Key, Lang, t};
4342 use crate::mail::account::{PasskeyChange, send_passkey_notice};
4443 use crate::state::AppState;
4544 use crate::throttle::{self, LOGIN_IP_LIMIT};
46-use crate::views::relative_time;
45+use crate::views::added_status;
4746
4847 /// How long a started ceremony stays valid.
4948 const CEREMONY_TTL: Duration = Duration::from_secs(5 * 60);
@@ -626,8 +625,9 @@ async fn audit_failed(cx: &Cx, state: &AppState, user: Option<&User>, reason: &s
626625 pub struct PasskeyItem {
627626 pub id: String,
628627 pub name: String,
629- /// "Added 2026-10-18 · Last used 5 minutes ago".
630- pub status: String,
628+ /// The stamps behind the "Added … · Last used …" line.
629+ pub created_at: String,
630+ pub last_used_at: Option<String>,
631631 }
632632
633633 /// What the passkey section of the security page needs.
@@ -639,24 +639,16 @@ pub struct PasskeyPanel {
639639
640640 pub async fn build_panel(
641641 state: &AppState,
642- lang: Lang,
643642 user_id: &str,
644643 ) -> forge_core::Result<PasskeyPanel> {
645- let now = i64::try_from(unix_now()).unwrap_or(i64::MAX);
646644 let rows = state.store.list_passkeys(user_id).await?;
647645 let items = rows
648646 .into_iter()
649- .map(|row| {
650- let ago = row
651- .last_used_at
652- .as_deref()
653- .and_then(stamp_to_unix)
654- .map(|unix| relative_time(lang, unix, now));
655- PasskeyItem {
656- status: i18n::device_line(lang, row.created_at.get(..10), ago.as_deref()),
657- id: row.id,
658- name: row.name,
659- }
647+ .map(|row| PasskeyItem {
648+ id: row.id,
649+ name: row.name,
650+ created_at: row.created_at,
651+ last_used_at: row.last_used_at,
660652 })
661653 .collect();
662654 Ok(PasskeyPanel {
@@ -702,7 +694,7 @@ pub async fn passkeys_panel(lang: Lang, csrf: &str, panel: PasskeyPanel) -> Resu
702694 <svg class="security-icon" viewBox="0 0 24 24" aria-hidden="true"><circle cx="9" cy="8" r="4"/><path d="M2 21v-1a6 6 0 0 1 6-6h2"/><circle cx="18" cy="14" r="2.5"/></svg>
703695 <div class="security-row-main">
704696 <p class="security-row-title">(item.name.as_str())</p>
705- <p class="security-row-status">(item.status.as_str())</p>
697+ <p class="security-row-status">added_status(lang: lang, added: Some(item.created_at.as_str()), used: item.last_used_at.as_deref())</p>
706698 </div>
707699 <details class="security-action">
708700 <summary>(s(lang, "Rename", "Yeniden adlandır"))</summary>
crates/forge-web/src/pages/review_requests.rsmodified+3 -5
@@ -21,7 +21,7 @@ use crate::notify;
2121 use crate::pages::issue_parts::{ItemKind, check_write, may_change, parse_number};
2222 use crate::pages::repo_ctx::{RepoCtx, load_repo};
2323 use crate::state::AppState;
24-use crate::views::{now_unix, relative_time, repo_href, shell};
24+use crate::views::{rel_time, repo_href, shell};
2525
2626 path_param!(owner);
2727 path_param!(repo);
@@ -208,7 +208,6 @@ async fn review_requests(cx: &Cx) -> Result<impl View> {
208208 let user = &viewer.0;
209209 let lang = i18n::lang(cx, Some(user));
210210 let items = state.store.review_requests_for_user(&user.id).await?;
211- let now = now_unix();
212211 let mut rows = Vec::new();
213212 for item in items {
214213 // A repo the viewer can no longer read is not listed.
@@ -227,7 +226,6 @@ async fn review_requests(cx: &Cx) -> Result<impl View> {
227226 if authorize(Some(user), &repo, role, org_role, Action::Read).is_err() {
228227 continue;
229228 }
230- let unix = crate::pages::issue_parts::stamp_unix(&item.created_at);
231229 rows.push((
232230 format!("{}/{}", item.repo_owner, item.repo_name),
233231 repo_href(
@@ -238,7 +236,7 @@ async fn review_requests(cx: &Cx) -> Result<impl View> {
238236 ),
239237 format!("#{} {}", item.number, item.title),
240238 ga::requested_by(lang, &item.requested_by),
241- relative_time(lang, unix, now),
239+ item.created_at.clone(),
242240 ));
243241 }
244242 let heading = ga::t(lang, AK::ReviewRequests);
@@ -259,7 +257,7 @@ async fn review_requests(cx: &Cx) -> Result<impl View> {
259257 <span class="muted small">(row.0.as_str())</span>
260258 <a class="notif-title" href=(row.1.as_str())>(row.2.as_str())</a>
261259 <span class="muted small">(row.3.as_str())</span>
262- <span class="muted small">(row.4.as_str())</span>
260+ <span class="muted small">rel_time(lang: lang, stamp: row.4.as_str())</span>
263261 </li>
264262 }
265263 </ul>
crates/forge-web/src/pages/settings_gpg.rsmodified+3 -3
@@ -13,10 +13,10 @@ use topcoat::view::{View, component, view};
1313
1414 use crate::audit::{self, Actor, Target};
1515 use crate::auth::{require_csrf, require_user};
16-use crate::i18n::{self, Key, Lang, added_line, t};
16+use crate::i18n::{self, Key, Lang, t};
1717 use crate::signatures;
1818 use crate::state::AppState;
19-use crate::views::{alert, shell, user_facing_message};
19+use crate::views::{added_status, alert, shell, user_facing_message};
2020
2121 #[derive(Deserialize)]
2222 struct AddKeyForm {
@@ -60,7 +60,7 @@ async fn gpg_view(
6060 <div class="item-main">
6161 <code class="small">(key.fingerprint.clone())</code>
6262 <span class="muted small">(key.emails.join(", "))</span>
63- <span class="muted small">(added_line(lang, key.created_at.as_str(), None))</span>
63+ <span class="muted small">added_status(lang: lang, added: Some(key.created_at.as_str()), used: None)</span>
6464 </div>
6565 <form method="post" action="/settings/gpg/delete">
6666 <input type="hidden" name="csrf" value=(csrf)>
crates/forge-web/src/pages/settings_keys.rsmodified+3 -3
@@ -13,9 +13,9 @@ use topcoat::view::{View, component, view};
1313
1414 use crate::audit::{self, Actor, Target};
1515 use crate::auth::{require_csrf, require_user};
16-use crate::i18n::{self, Key, Lang, added_line, t, unsupported_key_type};
16+use crate::i18n::{self, Key, Lang, t, unsupported_key_type};
1717 use crate::state::AppState;
18-use crate::views::{alert, shell, user_facing_message};
18+use crate::views::{added_status, alert, shell, user_facing_message};
1919
2020 /// Algorithms accepted for web-registered keys. `ssh-rsa` is rejected with its own message.
2121 const ACCEPTED: &[&str] = &[
@@ -158,7 +158,7 @@ async fn keys_view(
158158 <strong>(key.title.clone())</strong>
159159 <span class="muted small">(key.algorithm.clone())</span>
160160 <code class="small">(key.fingerprint.clone())</code>
161- <span class="muted small">(added_line(lang, key.created_at.as_str(), key.last_used_at.as_deref()))</span>
161+ <span class="muted small">added_status(lang: lang, added: Some(key.created_at.as_str()), used: key.last_used_at.as_deref())</span>
162162 </div>
163163 <form method="post" action="/settings/keys/delete">
164164 <input type="hidden" name="csrf" value=(csrf)>
crates/forge-web/src/pages/settings_security.rsmodified+22 -30
@@ -6,7 +6,6 @@ use std::time::{Duration, Instant};
66
77 use forge_core::mail::MailKind;
88 use forge_core::names::normalize_name;
9-use forge_core::time::stamp_to_unix;
109 use forge_core::totp;
1110 use forge_core::{AuditAction, Session, User, secret};
1211 use http::header::{HeaderValue, RETRY_AFTER};
@@ -29,7 +28,7 @@ use crate::i18n::{self, Key, Lang, password_too_long, password_too_short, t};
2928 use crate::pages::passkeys::{PasskeyPanel, build_panel, passkeys_panel, s};
3029 use crate::state::AppState;
3130 use crate::throttle::{self, LOGIN_USER_LIMIT, TWO_FACTOR_USER_LIMIT};
32-use crate::views::{alert, relative_time, shell, user_facing_message};
31+use crate::views::{added_status, alert, rel_time, shell, user_facing_message};
3332
3433 /// Shortest and longest new passwords, in characters.
3534 const MIN_PASSWORD_CHARS: usize = 10;
@@ -145,8 +144,9 @@ enum TwoFactorPanel {
145144 /// The enabled authenticator device, with the recovery code count, as the page shows it.
146145 struct DeviceView {
147146 name: String,
148- /// "Added 2026-10-18 · Last used 5 minutes ago".
149- status: String,
147+ /// The stamps behind the "Added … · Last used …" line.
148+ added: Option<String>,
149+ used: Option<String>,
150150 /// "7 of 10 recovery codes unused".
151151 codes_line: String,
152152 /// True when few recovery codes are left, so the line warns.
@@ -164,6 +164,8 @@ struct SecurityPage {
164164 stored_email: String,
165165 /// The Email row's state: "Verified", or "Not verified" with the verification mail's state.
166166 email_status: String,
167+ /// When the latest verification mail went out, shown after the state as a live time.
168+ email_sent: Option<String>,
167169 notice: Option<&'static str>,
168170 password_error: Option<String>,
169171 email_error: Option<String>,
@@ -172,7 +174,7 @@ struct SecurityPage {
172174 codes: Option<Vec<String>>,
173175 /// Secret (base32) and `otpauth://` URI while enrollment is waiting for a code.
174176 pending: Option<(String, String)>,
175- /// "Last changed 3 days ago", when the change time is known.
177+ /// When the password last changed, shown as a live time, when known.
176178 password_changed: Option<String>,
177179 /// The enabled device. `None` when two-factor is off.
178180 two_factor: Option<DeviceView>,
@@ -191,6 +193,7 @@ async fn security_body(page: SecurityPage) -> Result<impl View> {
191193 email_verified,
192194 stored_email,
193195 email_status,
196+ email_sent,
194197 notice,
195198 password_error,
196199 email_error,
@@ -262,8 +265,8 @@ async fn security_body(page: SecurityPage) -> Result<impl View> {
262265 <svg class="security-icon" viewBox="0 0 24 24" aria-hidden="true"><rect x="5" y="11" width="14" height="10" rx="2"/><path d="M8 11V8a4 4 0 0 1 8 0v3"/></svg>
263266 <div class="security-row-main">
264267 <h2 class="security-row-title">(t(lang, Key::Password))</h2>
265- if let Some(line) = password_changed {
266- <p class="security-row-status">(line.as_str())</p>
268+ if let Some(stamp) = password_changed {
269+ <p class="security-row-status">(i18n::last_changed_label(lang)) " " rel_time(lang: lang, stamp: stamp.as_str())</p>
267270 }
268271 </div>
269272 <details class="security-action" open=(password_open)>
@@ -299,7 +302,7 @@ async fn security_body(page: SecurityPage) -> Result<impl View> {
299302 if stored_email.is_empty() {
300303 <p class="security-row-status">(t(lang, Key::EmailNoAddress))</p>
301304 } else {
302- <p class="security-row-status"><span class="security-email">(stored_email.as_str())</span> (" · ")(email_status.as_str())</p>
305+ <p class="security-row-status"><span class="security-email">(stored_email.as_str())</span> (" · ")(email_status.as_str()) if let Some(stamp) = email_sent { " " rel_time(lang: lang, stamp: stamp.as_str()) }</p>
303306 }
304307 </div>
305308 if show_resend {
@@ -378,7 +381,7 @@ async fn security_body(page: SecurityPage) -> Result<impl View> {
378381 <svg class="security-icon" viewBox="0 0 24 24" aria-hidden="true"><rect x="7" y="3" width="10" height="18" rx="2"/><path d="M11 18h2"/></svg>
379382 <div class="security-row-main">
380383 <p class="security-row-title">(device.name.as_str())</p>
381- <p class="security-row-status">(device.status.as_str())</p>
384+ <p class="security-row-status">added_status(lang: lang, added: device.added.as_deref(), used: device.used.as_deref())</p>
382385 </div>
383386 </li>
384387 <li class="security-row security-device">
@@ -519,12 +522,6 @@ async fn build_page(
519522 shown: Shown,
520523 ) -> forge_core::Result<SecurityPage> {
521524 // Relative times are rendered against one `now`, so every line on the page agrees.
522- let now = i64::try_from(unix_now()).unwrap_or(i64::MAX);
523- let ago = |stamp: Option<&str>| {
524- stamp
525- .and_then(stamp_to_unix)
526- .map(|unix| relative_time(lang, unix, now))
527- };
528525 let totp_state = state.store.totp_state(&viewer.0.id).await?;
529526 let (pending, two_factor) = match totp_state {
530527 Some(totp) if totp.enabled => {
@@ -533,11 +530,8 @@ async fn build_page(
533530 name: totp
534531 .name
535532 .unwrap_or_else(|| t(lang, Key::AuthenticatorApp).to_owned()),
536- status: i18n::device_line(
537- lang,
538- totp.created_at.as_deref().and_then(|stamp| stamp.get(..10)),
539- ago(totp.last_used_at.as_deref()).as_deref(),
540- ),
533+ added: totp.created_at.clone(),
534+ used: totp.last_used_at.clone(),
541535 codes_line: i18n::codes_left_line(lang, unused, RECOVERY_CODE_COUNT as u64),
542536 codes_low: unused <= LOW_RECOVERY_CODES,
543537 };
@@ -556,13 +550,7 @@ async fn build_page(
556550 },
557551 None => (None, None),
558552 };
559- let password_changed = state
560- .store
561- .password_changed_at(&viewer.0.id)
562- .await?
563- .as_deref()
564- .and_then(|stamp| ago(Some(stamp)))
565- .map(|when| i18n::last_changed_line(lang, &when));
553+ let password_changed = state.store.password_changed_at(&viewer.0.id).await?;
566554 let owned_repos = state
567555 .store
568556 .list_repos_by_owner(&viewer.0.id)
@@ -572,6 +560,7 @@ async fn build_page(
572560 .collect();
573561 let stored_email = viewer.0.email.clone().unwrap_or_default();
574562 let email_verified = state.store.email_is_verified(&viewer.0.id).await?;
563+ let mut email_sent = None;
575564 let email_status = if stored_email.is_empty() {
576565 String::new()
577566 } else if email_verified {
@@ -583,9 +572,11 @@ async fn build_page(
583572 .latest_mail_for(&viewer.0.id, MailKind::Verification)
584573 .await?
585574 {
586- let sent_ago = ago(mail.sent_at.as_deref());
587- let line = i18n::email_mail_line(lang, mail.state, mail.attempts, sent_ago.as_deref());
575+ let line = i18n::email_mail_line(lang, mail.state, mail.attempts);
588576 status = format!("{status} · {line}");
577+ if matches!(mail.state, forge_core::mail::MailState::Sent) {
578+ email_sent = mail.sent_at;
579+ }
589580 }
590581 status
591582 };
@@ -593,11 +584,12 @@ async fn build_page(
593584 lang,
594585 csrf: viewer.1.csrf_token.clone(),
595586 delete_error: shown.delete_error,
596- passkeys: build_panel(state, lang, &viewer.0.id).await?,
587+ passkeys: build_panel(state, &viewer.0.id).await?,
597588 owned_repos,
598589 email_verified,
599590 stored_email,
600591 email_status,
592+ email_sent,
601593 email: shown
602594 .email_draft
603595 .unwrap_or_else(|| viewer.0.email.clone().unwrap_or_default()),
crates/forge-web/src/pages/settings_sessions.rsmodified+3 -3
@@ -11,9 +11,9 @@ use topcoat::view::{View, component, view};
1111
1212 use crate::audit::{self, Actor, Target};
1313 use crate::auth::{logout, require_csrf, require_user};
14-use crate::i18n::{self, Key, Lang, session_meta, t};
14+use crate::i18n::{self, Key, Lang, t};
1515 use crate::state::AppState;
16-use crate::views::shell;
16+use crate::views::{rel_time, shell};
1717
1818 #[derive(Deserialize)]
1919 struct RevokeForm {
@@ -47,7 +47,7 @@ async fn sessions_view(
4747 <li class="item">
4848 <div class="item-main">
4949 <strong>(session.user_agent.clone().unwrap_or_else(|| t(lang, Key::UnknownBrowser).into()))</strong>
50- <span class="muted small">(session_meta(lang, session.created_at.as_str(), session.last_seen.as_str(), session.expires_at.as_str()))</span>
50+ <span class="muted small">(i18n::dated_label(lang, Key::SignedIn)) " " rel_time(lang: lang, stamp: session.created_at.as_str()) " · " (i18n::dated_label(lang, Key::LastSeen)) " " rel_time(lang: lang, stamp: session.last_seen.as_str()) " · " (i18n::dated_label(lang, Key::ExpiresLabel)) " " rel_time(lang: lang, stamp: session.expires_at.as_str())</span>
5151 if session.id == current_id {
5252 <span class="badge public">(t(lang, Key::ThisSession))</span>
5353 }
crates/forge-web/src/pages/settings_tokens.rsmodified+3 -3
@@ -21,10 +21,10 @@ use crate::audit::{self, Actor, Target};
2121 use crate::auth::{require_csrf, require_user};
2222 use crate::i18n::packages::{self as pk, K as PK};
2323 use crate::i18n::releases_ci::{self as rc, K as RC};
24-use crate::i18n::{self, Key, Lang, t, token_meta, token_name_length};
24+use crate::i18n::{self, Key, Lang, t, token_name_length};
2525 use crate::pages::admin_runners::confirm_post;
2626 use crate::state::AppState;
27-use crate::views::{alert, shell};
27+use crate::views::{alert, rel_time, rel_time_or_never, shell};
2828
2929 /// Scopes are fixed to `repo` for M1.
3030 const SCOPES: &[&str] = &["repo"];
@@ -109,7 +109,7 @@ async fn tokens_view(
109109 <li class="item">
110110 <div class="item-main">
111111 <strong>(token.name.clone())</strong>
112- <span class="muted small">(token_meta(lang, token.created_at.as_str(), token.last_used_at.as_deref(), token.expires_at.as_deref()))</span>
112+ <span class="muted small">(i18n::dated_label(lang, Key::Created)) " " rel_time(lang: lang, stamp: token.created_at.as_str()) " · " (i18n::dated_label(lang, Key::LastUsed)) " " rel_time_or_never(lang: lang, stamp: token.last_used_at.as_deref()) " · " (i18n::dated_label(lang, Key::ExpiresLabel)) " " rel_time_or_never(lang: lang, stamp: token.expires_at.as_deref())</span>
113113 </div>
114114 confirm_post(lang: lang, csrf: csrf, action: "/settings/tokens/delete", label: t(lang, Key::Delete), message: delete_message(lang, token.name.as_str()), confirm: delete_confirm(lang), danger: true, fields: vec![("id", token.id.clone())])
115115 </li>
crates/forge-web/src/views/mod.rsmodified+77 -10
@@ -962,11 +962,18 @@ fn civil_from_days(days: i64) -> (i64, i64, i64) {
962962 }
963963
964964 /// "just now", "5 minutes ago", "1 day ago", relative to `now`; Turkish reads "az önce" and
965-/// "5 dakika önce".
965+/// "5 dakika önce". A time still to come reads "in 3 months", or "3 ay sonra"; under a minute
966+/// ahead it reads "in 1 minute".
966967 pub fn relative_time(lang: Lang, unix: i64, now: i64) -> String {
967968 use i18n::TimeUnit;
968- let secs = now.saturating_sub(unix).max(0);
969+ let ahead = unix > now;
970+ let secs = if ahead {
971+ unix.saturating_sub(now)
972+ } else {
973+ now.saturating_sub(unix)
974+ };
969975 let (n, unit) = match secs {
976+ 0..60 if ahead => (1, TimeUnit::Minute),
970977 0..60 => return i18n::just_now(lang).to_owned(),
971978 60..3_600 => (secs / 60, TimeUnit::Minute),
972979 3_600..86_400 => (secs / 3_600, TimeUnit::Hour),
@@ -974,29 +981,87 @@ pub fn relative_time(lang: Lang, unix: i64, now: i64) -> String {
974981 2_592_000..31_536_000 => (secs / 2_592_000, TimeUnit::Month),
975982 _ => (secs / 31_536_000, TimeUnit::Year),
976983 };
977- i18n::ago(lang, n, unit)
984+ if ahead {
985+ i18n::from_now(lang, n, unit)
986+ } else {
987+ i18n::ago(lang, n, unit)
988+ }
978989 }
979990
980991 /// The wording `relative_time` uses, for nav.js to re-word a `<time data-rel>` as the clock moves:
981-/// "just now", then the singular and the plural of each unit with `{n}` for the number, joined by `|`.
982-/// The order is fixed: minute, hour, day, month, year.
992+/// "just now", then the singular and the plural of each past unit with `{n}` for the number, then
993+/// the singular and the plural of each future unit, all joined by `|`. The order is fixed: minute,
994+/// hour, day, month, year.
983995 pub fn rel_words(lang: Lang) -> String {
984996 use i18n::TimeUnit;
985- let mut words = vec![i18n::just_now(lang).to_owned()];
986- for unit in [
997+ let units = [
987998 TimeUnit::Minute,
988999 TimeUnit::Hour,
9891000 TimeUnit::Day,
9901001 TimeUnit::Month,
9911002 TimeUnit::Year,
992- ] {
1003+ ];
1004+ let mut words = vec![i18n::just_now(lang).to_owned()];
1005+ for unit in units {
9931006 for n in [1, 2] {
9941007 words.push(i18n::ago(lang, n, unit).replacen(&n.to_string(), "{n}", 1));
9951008 }
9961009 }
1010+ for unit in units {
1011+ for n in [1, 2] {
1012+ words.push(i18n::from_now(lang, n, unit).replacen(&n.to_string(), "{n}", 1));
1013+ }
1014+ }
9971015 words.join("|")
9981016 }
9991017
1018+/// A live relative time for an RFC 3339 stamp: a `<time data-rel>` that nav.js re-words as the
1019+/// clock moves. A stamp that does not parse renders empty.
1020+#[component]
1021+pub async fn rel_time(lang: Lang, stamp: &str) -> Result<impl View> {
1022+ let label = forge_core::time::stamp_to_unix(stamp)
1023+ .map_or_else(String::new, |unix| relative_time(lang, unix, now_unix()));
1024+ Ok(view! {
1025+ <time data-rel="true" datetime=(stamp)>(label)</time>
1026+ })
1027+}
1028+
1029+/// A live relative time, or "never" when there is no stamp.
1030+#[component]
1031+pub async fn rel_time_or_never(lang: Lang, stamp: Option<&str>) -> Result<impl View> {
1032+ Ok(view! {
1033+ if let Some(stamp) = stamp {
1034+ rel_time(lang: lang, stamp: stamp)
1035+ } else {
1036+ (t(lang, Key::Never))
1037+ }
1038+ })
1039+}
1040+
1041+/// A key's or device's dates: "Added 3 days ago · Last used 5 minutes ago". A part without a
1042+/// stamp is left out.
1043+#[component]
1044+pub async fn added_status(
1045+ lang: Lang,
1046+ added: Option<&str>,
1047+ used: Option<&str>,
1048+) -> Result<impl View> {
1049+ let sep = if added.is_some() && used.is_some() {
1050+ " · "
1051+ } else {
1052+ ""
1053+ };
1054+ Ok(view! {
1055+ if let Some(stamp) = added {
1056+ (i18n::dated_label(lang, Key::Added)) " " rel_time(lang: lang, stamp: stamp)
1057+ }
1058+ (sep)
1059+ if let Some(stamp) = used {
1060+ (i18n::dated_label(lang, Key::LastUsed)) " " rel_time(lang: lang, stamp: stamp)
1061+ }
1062+ })
1063+}
1064+
10001065 /// First seven characters of an object id.
10011066 pub fn short_oid(oid: &str) -> &str {
10021067 oid.get(..7).unwrap_or(oid)
@@ -1297,7 +1362,7 @@ mod tests {
12971362 assert_eq!(relative_time(Lang::En, 0, 120), "2 minutes ago");
12981363 assert_eq!(relative_time(Lang::En, 0, 3_600), "1 hour ago");
12991364 assert_eq!(relative_time(Lang::En, 0, 2 * 86_400), "2 days ago");
1300- assert_eq!(relative_time(Lang::En, 10, 0), "just now");
1365+ assert_eq!(relative_time(Lang::En, 0, 10), "just now");
13011366 assert_eq!(relative_time(Lang::En, 0, 30 * 86_400), "1 month ago");
13021367 assert_eq!(relative_time(Lang::En, 0, 365 * 86_400), "1 year ago");
13031368 assert_eq!(relative_time(Lang::En, 0, 2 * 365 * 86_400), "2 years ago");
@@ -1312,7 +1377,9 @@ mod tests {
13121377 assert_eq!(
13131378 rel_words(Lang::En),
13141379 "just now|{n} minute ago|{n} minutes ago|{n} hour ago|{n} hours ago|{n} day ago|\
1315- {n} days ago|{n} month ago|{n} months ago|{n} year ago|{n} years ago"
1380+ {n} days ago|{n} month ago|{n} months ago|{n} year ago|{n} years ago|\
1381+ in {n} minute|in {n} minutes|in {n} hour|in {n} hours|in {n} day|in {n} days|\
1382+ in {n} month|in {n} months|in {n} year|in {n} years"
13161383 );
13171384 assert_eq!(rel_words(Lang::Tr).split('|').nth(4), Some("{n} saat önce"));
13181385 }