import type { Locale } from '@/i18n/types' export function todayIso(): string { return new Date().toISOString().slice(0, 10) } export function nowIso(): string { return new Date().toISOString() } const LOCALE_TAG: Record = { fr: 'fr-FR', en: 'en-US', } export function formatDate(isoDate: string, locale: Locale): string { const match = isoDate.match(/^(\d{4})-(\d{2})-(\d{2})$/) if (!match) throw new Error(`Invalid ISO date: ${isoDate}`) const [, y, mo, d] = match const date = new Date(Date.UTC(Number(y), Number(mo) - 1, Number(d))) if (Number.isNaN(date.getTime())) throw new Error(`Invalid ISO date: ${isoDate}`) return new Intl.DateTimeFormat(LOCALE_TAG[locale], { day: 'numeric', month: 'long', year: 'numeric', timeZone: 'UTC', }).format(date) }