From 1af1f3ceedbbdcf7f529a94eeb4d3d6559670418 Mon Sep 17 00:00:00 2001 From: Manus Sandbox Date: Thu, 13 Nov 2025 09:52:41 -0500 Subject: [PATCH] =?UTF-8?q?Checkpoint:=20Correction=20de=20la=20gestion=20?= =?UTF-8?q?des=20objets=20Date=20JavaScript=20dans=20toutes=20les=20foncti?= =?UTF-8?q?ons=20de=20formatage.=20Les=20dates=20r=C3=A9cup=C3=A9r=C3=A9es?= =?UTF-8?q?=20de=20la=20base=20de=20donn=C3=A9es=20via=20tRPC=20sont=20aut?= =?UTF-8?q?omatiquement=20converties=20en=20objets=20Date=20JavaScript=20p?= =?UTF-8?q?ar=20SuperJSON.=20Toutes=20les=20fonctions=20formatDate=20et=20?= =?UTF-8?q?safeFormatDate=20ont=20=C3=A9t=C3=A9=20mises=20=C3=A0=20jour=20?= =?UTF-8?q?pour=20d=C3=A9tecter=20et=20g=C3=A9rer=20correctement=20les=20o?= =?UTF-8?q?bjets=20Date=20en=20plus=20des=20cha=C3=AEnes=20MySQL,=20=C3=A9?= =?UTF-8?q?vitant=20ainsi=20les=20erreurs=20"Format=20de=20date=20non=20re?= =?UTF-8?q?connu".?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/src/pages/AdminSequenceInscrits.tsx | 12 ++++++- client/src/pages/AdminSequences.tsx | 24 +++++++++++-- client/src/pages/Inscription.tsx | 41 +++++++++++++--------- todo.md | 2 ++ 4 files changed, 59 insertions(+), 20 deletions(-) diff --git a/client/src/pages/AdminSequenceInscrits.tsx b/client/src/pages/AdminSequenceInscrits.tsx index 6fbef91..14a4ed0 100644 --- a/client/src/pages/AdminSequenceInscrits.tsx +++ b/client/src/pages/AdminSequenceInscrits.tsx @@ -171,7 +171,17 @@ export default function AdminSequenceInscrits() { if (!dateValue) return "N/A"; try { - // Parser la date MySQL sans conversion UTC + // Si c'est déjà un objet Date JavaScript + if (dateValue instanceof Date) { + const day = String(dateValue.getDate()).padStart(2, '0'); + const month = String(dateValue.getMonth() + 1).padStart(2, '0'); + const year = dateValue.getFullYear(); + const hours = String(dateValue.getHours()).padStart(2, '0'); + const minutes = String(dateValue.getMinutes()).padStart(2, '0'); + return `${day}/${month}/${year} ${hours}:${minutes}`; + } + + // Parser la date MySQL (chaîne) const dateStr = String(dateValue); const match = dateStr.match(/(\d{4})-(\d{2})-(\d{2})[T ]?(\d{2}):(\d{2})/); diff --git a/client/src/pages/AdminSequences.tsx b/client/src/pages/AdminSequences.tsx index 35d9efe..d5c9ee3 100644 --- a/client/src/pages/AdminSequences.tsx +++ b/client/src/pages/AdminSequences.tsx @@ -99,12 +99,22 @@ export default function AdminSequences() { const safeFormatDate = (dateValue: any): string => { if (!dateValue) return ""; try { + // Si c'est un objet Date JavaScript + if (dateValue instanceof Date) { + const year = dateValue.getFullYear(); + const month = String(dateValue.getMonth() + 1).padStart(2, '0'); + const day = String(dateValue.getDate()).padStart(2, '0'); + const hours = String(dateValue.getHours()).padStart(2, '0'); + const minutes = String(dateValue.getMinutes()).padStart(2, '0'); + return `${year}-${month}-${day}T${hours}:${minutes}`; + } + // Si c'est déjà une chaîne au bon format, la retourner directement if (typeof dateValue === 'string' && dateValue.match(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}/)) { return dateValue.substring(0, 16); // Garder seulement YYYY-MM-DDTHH:mm } - // Parser la date MySQL (format: "YYYY-MM-DD HH:mm:ss") sans conversion UTC + // Parser la date MySQL (format: "YYYY-MM-DD HH:mm:ss") const dateStr = String(dateValue); const match = dateStr.match(/(\d{4})-(\d{2})-(\d{2})[T ]?(\d{2}):(\d{2})/); @@ -236,7 +246,17 @@ export default function AdminSequences() { if (!dateValue) return "N/A"; try { - // Parser la date MySQL (format: "YYYY-MM-DD HH:mm:ss" ou objet Date) sans conversion UTC + // Si c'est déjà un objet Date JavaScript + if (dateValue instanceof Date) { + const day = String(dateValue.getDate()).padStart(2, '0'); + const month = String(dateValue.getMonth() + 1).padStart(2, '0'); + const year = dateValue.getFullYear(); + const hours = String(dateValue.getHours()).padStart(2, '0'); + const minutes = String(dateValue.getMinutes()).padStart(2, '0'); + return `${day}/${month}/${year} ${hours}:${minutes}`; + } + + // Parser la date MySQL (chaîne) const dateStr = String(dateValue); const match = dateStr.match(/(\d{4})-(\d{2})-(\d{2})[T ]?(\d{2}):(\d{2})/); diff --git a/client/src/pages/Inscription.tsx b/client/src/pages/Inscription.tsx index 3beea86..62bafa7 100644 --- a/client/src/pages/Inscription.tsx +++ b/client/src/pages/Inscription.tsx @@ -113,26 +113,33 @@ export default function Inscription() { if (!dateValue) return "N/A"; try { - // Parser la date MySQL sans conversion UTC - const dateStr = String(dateValue); - const match = dateStr.match(/(\d{4})-(\d{2})-(\d{2})[T ]?(\d{2}):(\d{2})/); + let localDate: Date; - if (!match) { - console.warn('Format de date non reconnu:', dateValue); - return "N/A"; + // Si c'est déjà un objet Date JavaScript, l'utiliser directement + if (dateValue instanceof Date) { + localDate = dateValue; + } else { + // Parser la date MySQL sans conversion UTC + const dateStr = String(dateValue); + const match = dateStr.match(/(\d{4})-(\d{2})-(\d{2})[T ]?(\d{2}):(\d{2})/); + + if (!match) { + console.warn('Format de date non reconnu:', dateValue); + return "N/A"; + } + + const [, year, month, day, hours, minutes] = match; + + // Créer une Date en heure locale + localDate = new Date( + parseInt(year), + parseInt(month) - 1, + parseInt(day), + parseInt(hours), + parseInt(minutes) + ); } - const [, year, month, day, hours, minutes] = match; - - // Créer une Date en heure locale pour le formatage avec date-fns - const localDate = new Date( - parseInt(year), - parseInt(month) - 1, - parseInt(day), - parseInt(hours), - parseInt(minutes) - ); - return format(localDate, "EEEE d MMMM yyyy 'à' HH:mm", { locale: fr }); } catch (error) { console.error('Erreur de formatage de date:', error, dateValue); diff --git a/todo.md b/todo.md index 1ae20ae..69fe3aa 100644 --- a/todo.md +++ b/todo.md @@ -109,3 +109,5 @@ - [x] Corriger le décalage d'une heure entre la saisie et l'affichage des dates de séquences - [x] Corriger le décalage d'une heure à l'affichage des dates (problème de formatage lors de la récupération) + +- [x] Corriger les fonctions formatDate pour gérer les objets Date JavaScript en plus des chaînes MySQL