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" */
|
/** Formats an ISO date string as "26.06.2026, 14:32 Uhr" */
|
||||||
function formatDateTime(isoString: string): string {
|
function formatDateTime(isoString: string): string {
|
||||||
try {
|
const d = new Date(isoString);
|
||||||
const d = new Date(isoString);
|
// new Date() never throws — it returns an Invalid Date object for bad input.
|
||||||
const day = String(d.getDate()).padStart(2, '0');
|
// Check explicitly so malformed strings fall back gracefully instead of
|
||||||
const month = String(d.getMonth() + 1).padStart(2, '0');
|
// rendering as "NaN.NaN.NaN, NaN:NaN Uhr" (WR-03).
|
||||||
const year = d.getFullYear();
|
if (isNaN(d.getTime())) return isoString;
|
||||||
const hours = String(d.getHours()).padStart(2, '0');
|
const day = String(d.getDate()).padStart(2, '0');
|
||||||
const minutes = String(d.getMinutes()).padStart(2, '0');
|
const month = String(d.getMonth() + 1).padStart(2, '0');
|
||||||
return `${day}.${month}.${year}, ${hours}:${minutes} Uhr`;
|
const year = d.getFullYear();
|
||||||
} catch {
|
const hours = String(d.getHours()).padStart(2, '0');
|
||||||
return isoString;
|
const minutes = String(d.getMinutes()).padStart(2, '0');
|
||||||
}
|
return `${day}.${month}.${year}, ${hours}:${minutes} Uhr`;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface InvoiceHistoryTableProps {
|
interface InvoiceHistoryTableProps {
|
||||||
|
|||||||
Reference in New Issue
Block a user