feat(lib): implement formatDateFr (fr-FR locale)

This commit is contained in:
Bastien Chanot committed 2026-05-18 20:59:05 +02:00
1 parent ff3989c41f
commit 8b9eb61a69
2 files changed
+40 -2

No files matched your search

+12 -2
View File
@@ -8,8 +8,18 @@ export function todayIso(): string {
/**
* Formats an ISO date string as a French locale date (e.g. "18 mai 2026").
*/
export function formatDateFr(_isoDate: string): string {
throw new Error('not implemented')
export function formatDateFr(isoDate: string): 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('fr-FR', {
day: 'numeric',
month: 'long',
year: 'numeric',
timeZone: 'UTC',
}).format(date)
}
/**