frontend/src/lib/format.ts
/**
* Formats a timestamp into a human-readable age string (e.g., "3h" or "2d5h")
*
* @param timestamp - ISO 8601 timestamp string
* @returns Formatted age string
*/
export function formatAge(timestamp: string): string {
const created = new Date(timestamp);
const now = new Date();
const diffHours = Math.floor((now.getTime() - created.getTime()) / (1000 * 60 * 60));
if (diffHours < 24) {
return `${diffHours}h`;
}
const diffDays = Math.floor(diffHours / 24);
return `${diffDays}d${diffHours % 24}h`;
}