feat(lib): implement formatDateFr (fr-FR locale)
This commit is contained in:
1 parent
ff3989c41f
commit
8b9eb61a69
2 files changed
+40
-2
No files matched your search
+12
-2
@@ -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)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user