fix(07): WR-03 replace dead try/catch in formatDateTime with isNaN guard
new Date() never throws so the catch was unreachable. Invalid dates rendered as NaN.NaN.NaN, NaN:NaN Uhr. Use isNaN(d.getTime()) guard to fall back to the raw string instead.
This commit is contained in:
@@ -26,17 +26,17 @@ function DownloadIcon() {
|
||||
|
||||
/** Formats an ISO date string as "26.06.2026, 14:32 Uhr" */
|
||||
function formatDateTime(isoString: string): string {
|
||||
try {
|
||||
const d = new Date(isoString);
|
||||
const day = String(d.getDate()).padStart(2, '0');
|
||||
const month = String(d.getMonth() + 1).padStart(2, '0');
|
||||
const year = d.getFullYear();
|
||||
const hours = String(d.getHours()).padStart(2, '0');
|
||||
const minutes = String(d.getMinutes()).padStart(2, '0');
|
||||
return `${day}.${month}.${year}, ${hours}:${minutes} Uhr`;
|
||||
} catch {
|
||||
return isoString;
|
||||
}
|
||||
const d = new Date(isoString);
|
||||
// new Date() never throws — it returns an Invalid Date object for bad input.
|
||||
// Check explicitly so malformed strings fall back gracefully instead of
|
||||
// rendering as "NaN.NaN.NaN, NaN:NaN Uhr" (WR-03).
|
||||
if (isNaN(d.getTime())) return isoString;
|
||||
const day = String(d.getDate()).padStart(2, '0');
|
||||
const month = String(d.getMonth() + 1).padStart(2, '0');
|
||||
const year = d.getFullYear();
|
||||
const hours = String(d.getHours()).padStart(2, '0');
|
||||
const minutes = String(d.getMinutes()).padStart(2, '0');
|
||||
return `${day}.${month}.${year}, ${hours}:${minutes} Uhr`;
|
||||
}
|
||||
|
||||
interface InvoiceHistoryTableProps {
|
||||
|
||||
Reference in New Issue
Block a user