feat: blog section
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
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 });
|
||||
}
|
||||
Reference in New Issue
Block a user