Initial commit: Alma Beauti Next.js site.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
export function faDigits(value: number | string) {
|
||||
return String(value).replace(/\d/g, (digit) => "۰۱۲۳۴۵۶۷۸۹"[Number(digit)]);
|
||||
}
|
||||
|
||||
export function formatFaDate(value?: string | null) {
|
||||
if (!value) return "";
|
||||
try {
|
||||
return new Intl.DateTimeFormat("fa-IR", {
|
||||
year: "numeric",
|
||||
month: "long",
|
||||
day: "numeric",
|
||||
}).format(new Date(value));
|
||||
} catch {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
export function formatFaDateLong(value?: string | null) {
|
||||
if (!value) return "";
|
||||
try {
|
||||
const parts = new Intl.DateTimeFormat("fa-IR", {
|
||||
weekday: "long",
|
||||
day: "numeric",
|
||||
month: "long",
|
||||
year: "numeric",
|
||||
}).formatToParts(new Date(value));
|
||||
const get = (type: string) => parts.find((part) => part.type === type)?.value ?? "";
|
||||
return [get("weekday"), get("day"), get("month"), get("year")].filter(Boolean).join(" ");
|
||||
} catch {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user