33 أسطر
804 B
TypeScript
33 أسطر
804 B
TypeScript
export function formatDateTime(value?: string | null) {
|
|
if (!value) return "-";
|
|
try {
|
|
return new Intl.DateTimeFormat("en-US", {
|
|
year: "numeric",
|
|
month: "short",
|
|
day: "2-digit",
|
|
hour: "2-digit",
|
|
minute: "2-digit",
|
|
hour12: true,
|
|
}).format(new Date(value));
|
|
} catch {
|
|
return value;
|
|
}
|
|
}
|
|
|
|
export function formatCurrency(value?: number | null, currency = "SAR") {
|
|
if (typeof value !== "number") return "-";
|
|
try {
|
|
return new Intl.NumberFormat("en-US", {
|
|
style: "currency",
|
|
currency,
|
|
maximumFractionDigits: 0,
|
|
}).format(value);
|
|
} catch {
|
|
return `${value} ${currency}`;
|
|
}
|
|
}
|
|
|
|
export function formatCount(value?: number | null) {
|
|
return typeof value === "number" ? new Intl.NumberFormat("en-US").format(value) : "0";
|
|
}
|