chore: first commit
This commit is contained in:
+21
@@ -0,0 +1,21 @@
|
||||
export function numberFormat(number: number, locale: string = "fa-IR") {
|
||||
return Intl.NumberFormat(locale).format(number);
|
||||
}
|
||||
|
||||
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";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user