Files
sencho/frontend/src/lib/relativeTime.ts
T
Anso cdb9cd414e feat(routing): redesign node cards to the System Sheet recipe (#1133)
Lift <RoutingNodeCard> primitive from audit §21 / DESIGN §9.13. Migrate
the fleet adapter to consume it: collapse five inline state pills into
a single nodeState prop, replace the k/v stat list with a mono meta
line, drop the per-row HEALTHY chip in favor of a state dot, and add a
real empty-state block with a primary CTA for every state. Compact
density body swap stays inside the component, no -compact fork.
2026-05-21 10:18:03 -04:00

36 lines
1.1 KiB
TypeScript

export function formatTimeUntil(timestamp: number): string {
const diff = timestamp - Date.now();
if (diff < 0) return 'overdue';
if (diff < 60_000) return '<1m';
const mins = Math.floor(diff / 60_000);
if (mins < 60) return `${mins}m`;
const hrs = Math.floor(mins / 60);
if (hrs < 24) return `${hrs}h`;
return `${Math.floor(hrs / 24)}d`;
}
export function formatTimeAgo(timestamp: number): string {
const diff = Date.now() - timestamp;
if (diff < 60_000) return 'just now';
const mins = Math.floor(diff / 60_000);
if (mins < 60) return `${mins}m ago`;
const hrs = Math.floor(mins / 60);
if (hrs < 24) return `${hrs}h ago`;
return `${Math.floor(hrs / 24)}d ago`;
}
/**
* Short age formatter for cockpit-style "12s / 4m / 3h / 2d" badges. Always
* returns under five characters. Negative deltas (clock skew) read as `0s`.
*/
export function formatAgeShort(ms: number): string {
if (ms < 1000) return '0s';
const s = Math.floor(ms / 1000);
if (s < 60) return `${s}s`;
const m = Math.floor(s / 60);
if (m < 60) return `${m}m`;
const h = Math.floor(m / 60);
if (h < 24) return `${h}h`;
return `${Math.floor(h / 24)}d`;
}