fix: enhance formatDate function to handle undefined and string inputs, ensuring robust date formatting

This commit is contained in:
Yoga Pangestu 2026-04-23 14:12:06 +07:00
parent c1c87da623
commit cb2c16f0c4

View File

@ -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',