in src/lib/utils/date.ts [8:24]
export function formatDate(date: Date, locale?: string, options?: Intl.DateTimeFormatOptions): string {
// Provide a default locale and options if not provided
const effectiveLocale = locale || undefined; // Using undefined will use the system's locale
const effectiveOptions: Intl.DateTimeFormatOptions = options || {
year: "numeric",
month: "long",
day: "numeric",
};
try {
return date.toLocaleDateString(effectiveLocale, effectiveOptions);
} catch (error) {
console.error("Error formatting date:", error);
// Fallback to a simple format if toLocaleDateString fails
return `${date.getFullYear()}-${(date.getMonth() + 1).toString().padStart(2, "0")}-${date.getDate().toString().padStart(2, "0")}`;
}
}