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