Files
mr_decor/lib/format-date.ts

16 lines
489 B
TypeScript

import { format, newDate } from "date-fns-jalali";
import { faIR } from "date-fns-jalali/locale";
/**
* Format a Gregorian date (Date or ISO string) to Shamsi (Jalali) Persian string.
* Example: "۱۴ بهمن ۱۴۰۴"
*/
export function formatDateShamsi(
date: Date | string,
formatStr: string = "d MMMM yyyy"
): string {
const d = typeof date === "string" ? new Date(date) : date;
if (Number.isNaN(d.getTime())) return "";
return format(d, formatStr, { locale: faIR });
}