Refactor frontend date formatting helpers and mark Task 10 done

This commit is contained in:
2026-03-21 17:25:45 +01:00
parent a442836c5c
commit 8a6bcc4d94
6 changed files with 111 additions and 150 deletions

View File

@@ -130,3 +130,34 @@ export function formatRelative(
return formatDate(isoUtc, timezone);
}
}
/**
* Format an ISO 8601 timestamp for display with local browser timezone.
*
* Keeps parity with existing code paths in the UI that render full date+time
* strings inside table rows.
*/
export function formatTimestamp(iso: string): string {
try {
return new Date(iso).toLocaleString(undefined, {
year: "numeric",
month: "2-digit",
day: "2-digit",
hour: "2-digit",
minute: "2-digit",
second: "2-digit",
});
} catch {
return iso;
}
}
/**
* Format a duration in seconds to a compact text representation.
*/
export function formatSeconds(seconds: number): string {
if (seconds < 0) return "permanent";
if (seconds < 60) return `${String(seconds)} s`;
if (seconds < 3600) return `${String(Math.round(seconds / 60))} min`;
return `${String(Math.round(seconds / 3600))} h`;
}