One elapsed-time notation: ago() reads dur's units app-wide, health runs cell widened
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WgBfkm4rCmtd1T4vHWjEPx
This commit is contained in:
@@ -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`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user