From 411556293c5e258f7884c7c792d5e4a90b6e9ad3 Mon Sep 17 00:00:00 2001 From: Jalil Arfaoui Date: Wed, 22 Oct 2025 00:11:15 +0200 Subject: [PATCH] =?UTF-8?q?feat:=20ajoute=20des=20utilitaires=20de=20forma?= =?UTF-8?q?tage=20de=20dates=20et=20les=20utilise=20dans=20les=20composant?= =?UTF-8?q?s=20et=20pages=20=C3=A9v=C3=A9nement?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Affiche.astro | 3 +- src/components/Evenement.astro | 10 ++----- src/pages/evenements/[slug].astro | 9 ++---- src/utils/date.ts | 47 +++++++++++++++++++++++++++++++ 4 files changed, 53 insertions(+), 16 deletions(-) create mode 100644 src/utils/date.ts diff --git a/src/components/Affiche.astro b/src/components/Affiche.astro index c6e8d3f..5d05a39 100644 --- a/src/components/Affiche.astro +++ b/src/components/Affiche.astro @@ -1,4 +1,5 @@ --- +import { formatDateSansHeure } from "../utils/date"; const { evenement, showOverlay = true } = Astro.props; --- @@ -11,7 +12,7 @@ const { evenement, showOverlay = true } = Astro.props; {showOverlay && (
{evenement.nom} - {new Date(evenement.date).toLocaleDateString("fr-FR", { timeZone: 'Europe/Paris' })} + {formatDateSansHeure(evenement.date)}
)} diff --git a/src/components/Evenement.astro b/src/components/Evenement.astro index 4ce80ff..2faf20f 100644 --- a/src/components/Evenement.astro +++ b/src/components/Evenement.astro @@ -1,5 +1,6 @@ --- import { documentToHtmlString } from "@contentful/rich-text-html-renderer"; +import { formatDateAvecHeure } from "../utils/date"; const { evenement } = Astro.props; --- @@ -14,14 +15,7 @@ const { evenement } = Astro.props;
- le {new Date(evenement.date).toLocaleString("fr-FR", { - timeZone: 'Europe/Paris', - day: 'numeric', - month: 'long', - year: 'numeric', - hour: '2-digit', - minute: '2-digit' - })} + le {formatDateAvecHeure(evenement.date)}
à {evenement.lieu} diff --git a/src/pages/evenements/[slug].astro b/src/pages/evenements/[slug].astro index 80ca90c..3c17e15 100644 --- a/src/pages/evenements/[slug].astro +++ b/src/pages/evenements/[slug].astro @@ -4,6 +4,7 @@ import { documentToHtmlString } from "@contentful/rich-text-html-renderer"; import {fetchEvenement, fetchAllEvenements} from "../../lib/contentful"; import Layout from "../../layouts/Layout.astro"; import Card from "../../components/Card.astro"; +import { formatDateAvecHeure } from "../../utils/date"; export const prerender = false @@ -38,13 +39,7 @@ const Wrapper = lieuUrl ? 'a' : 'div'

{nom}

- {date ? new Date(date as string).toLocaleString("fr-FR", { - day: 'numeric', - month: 'long', - year: 'numeric', - hour: '2-digit', - minute: '2-digit' - }) : ""} + {date ? formatDateAvecHeure(date as string) : ""} {lieu && ( à {lieu} diff --git a/src/utils/date.ts b/src/utils/date.ts new file mode 100644 index 0000000..f400333 --- /dev/null +++ b/src/utils/date.ts @@ -0,0 +1,47 @@ +/** + * Utilitaires de formatage des dates pour l'application Les Particules + * + * Toutes les dates sont formatées en fuseau horaire Europe/Paris + * pour garantir la cohérence à travers toute l'application. + */ + +const TIMEZONE = 'Europe/Paris'; +const LOCALE = 'fr-FR'; + +/** + * Formate une date complète avec heure (jour mois année, heure:minute) + * Exemple: "15 novembre 2024, 18:00" + */ +export function formatDateAvecHeure(date: string | Date): string { + return new Date(date).toLocaleString(LOCALE, { + timeZone: TIMEZONE, + day: 'numeric', + month: 'long', + year: 'numeric', + hour: '2-digit', + minute: '2-digit' + }); +} + +/** + * Formate une date sans l'heure (jour mois année) + * Exemple: "15 novembre 2024" + */ +export function formatDateSansHeure(date: string | Date): string { + return new Date(date).toLocaleDateString(LOCALE, { + timeZone: TIMEZONE, + day: 'numeric', + month: 'long', + year: 'numeric' + }); +} + +/** + * Formate une date courte (jour mois année) + * Exemple: "15/11/2024" + */ +export function formatDateCourte(date: string | Date): string { + return new Date(date).toLocaleDateString(LOCALE, { + timeZone: TIMEZONE + }); +} \ No newline at end of file