Spaces:
Sleeping
Sleeping
File size: 922 Bytes
312fdff | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | export function formatPercent(value: number | undefined | null, digits = 1): string {
if (value === undefined || value === null || Number.isNaN(value)) return '—';
const pct = value <= 1 ? value * 100 : value;
return `${pct.toFixed(digits)}%`;
}
export function formatNumber(value: number | undefined | null): string {
if (value === undefined || value === null || Number.isNaN(value)) return '—';
return new Intl.NumberFormat().format(value);
}
export function formatRelativeTime(iso: string | null | undefined): string {
if (!iso) return '—';
const then = new Date(iso).getTime();
if (Number.isNaN(then)) return iso;
const diffSec = Math.round((Date.now() - then) / 1000);
if (diffSec < 60) return `${diffSec}s ago`;
if (diffSec < 3600) return `${Math.floor(diffSec / 60)}m ago`;
if (diffSec < 86400) return `${Math.floor(diffSec / 3600)}h ago`;
return new Date(iso).toLocaleString();
}
|