update: fix invoice proccessor

This commit is contained in:
Mahyargdz
2025-05-10 12:30:39 +03:30
parent 24bc359c3f
commit ad4bf79afb
3 changed files with 18 additions and 6 deletions
@@ -2,6 +2,20 @@ export function numberFormat(number: number, locale: string = "fa-IR") {
return Intl.NumberFormat(locale).format(number);
}
export function dateFormat(date: Date, locale: string = "fa-IR") {
return new Intl.DateTimeFormat(locale).format(date);
export function dateFormat(date: Date | string | number, locale: string = "fa-IR") {
try {
// Convert to Date object if it's a string or number
const dateObj = date instanceof Date ? date : new Date(date);
// Check if the date is valid
if (isNaN(dateObj.getTime())) {
console.warn("Invalid date provided to dateFormat:", date);
return "Invalid Date";
}
return new Intl.DateTimeFormat(locale).format(dateObj);
} catch (error) {
console.error("Error formatting date:", error);
return "Invalid Date";
}
}