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) => {
|
||||
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',
|
||||
|
||||
Loading…
Reference in New Issue
Block a user