Skip to content

Commit 4275db0

Browse files
committed
refactor: handle invalid data in the formatDate
1 parent 0e4f4be commit 4275db0

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

app/utils/formatters.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,11 @@ export function toIsoDateString(date: Date): string {
1111
*/
1212
export function formatDate(date: string | undefined): string {
1313
if (!date) return ''
14-
try {
15-
return new Date(date).toLocaleDateString('en-US', {
16-
year: 'numeric',
17-
month: 'short',
18-
day: 'numeric',
19-
})
20-
} catch {
21-
return date
22-
}
14+
const d = new Date(date)
15+
if (isNaN(d.getTime())) return date
16+
return d.toLocaleDateString('en-US', {
17+
year: 'numeric',
18+
month: 'short',
19+
day: 'numeric',
20+
})
2321
}

0 commit comments

Comments
 (0)