fix: enhance formatDate function to handle undefined and string inputs, ensuring robust date formatting
This commit is contained in:
parent
c1c87da623
commit
cb2c16f0c4
@ -6,15 +6,20 @@ export const formatTime = (date: Date) => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export const formatDate = (date: Date) => {
|
export const formatDate = (date: Date | string | undefined) => {
|
||||||
return date.toLocaleDateString('id-ID', {
|
if (!date) return '-';
|
||||||
|
|
||||||
|
const parsedDate = date instanceof Date ? date : new Date(date);
|
||||||
|
|
||||||
|
if (isNaN(parsedDate.getTime())) return '-';
|
||||||
|
|
||||||
|
return parsedDate.toLocaleDateString('id-ID', {
|
||||||
weekday: 'long',
|
weekday: 'long',
|
||||||
day: 'numeric',
|
day: 'numeric',
|
||||||
month: 'long',
|
month: 'long',
|
||||||
year: 'numeric',
|
year: 'numeric',
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export const formatCurrency = (value: number) => {
|
export const formatCurrency = (value: number) => {
|
||||||
return new Intl.NumberFormat('id-ID', {
|
return new Intl.NumberFormat('id-ID', {
|
||||||
style: 'currency',
|
style: 'currency',
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user