One elapsed-time notation: ago() reads dur's units app-wide, health runs cell widened

This commit is contained in:
2026-10-15 17:10:36 +02:00
parent 6a847a2f28
commit 87f5b6b58a
10 changed files with 22 additions and 41 deletions
+10
View File
@@ -81,3 +81,13 @@ export function dur(ms: number, digits = 3): string {
]
return `${Number((rounded / factor).toPrecision(digits))} ${unit}`
}
/**
* How long ago a moment was, in `dur`'s notation: "4.52 min ago". A number is
* unix seconds, a string an ISO timestamp.
*/
export function ago(ts: string | number | null | undefined): string {
if (!ts) return "—"
const stamp = typeof ts === "number" ? ts * 1000 : Date.parse(ts)
return `${dur(Math.max(0, Date.now() - stamp))} ago`
}