From cb2c16f0c46428d0a552bb7d4d50223ff44dd6c9 Mon Sep 17 00:00:00 2001 From: Yoga Pangestu Date: Thu, 23 Apr 2026 14:12:06 +0700 Subject: [PATCH] fix: enhance formatDate function to handle undefined and string inputs, ensuring robust date formatting --- resources/js/lib/formatters.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/resources/js/lib/formatters.ts b/resources/js/lib/formatters.ts index 7b0cdc1..e02c5aa 100644 --- a/resources/js/lib/formatters.ts +++ b/resources/js/lib/formatters.ts @@ -6,15 +6,20 @@ export const formatTime = (date: Date) => { }); }; -export const formatDate = (date: Date) => { - return date.toLocaleDateString('id-ID', { +export const formatDate = (date: Date | string | undefined) => { + if (!date) return '-'; + + const parsedDate = date instanceof Date ? date : new Date(date); + + if (isNaN(parsedDate.getTime())) return '-'; + + return parsedDate.toLocaleDateString('id-ID', { weekday: 'long', day: 'numeric', month: 'long', year: 'numeric', }); }; - export const formatCurrency = (value: number) => { return new Intl.NumberFormat('id-ID', { style: 'currency',