Checkpoint: Correction de la gestion des objets Date JavaScript dans toutes les fonctions de formatage. Les dates récupérées de la base de données via tRPC sont automatiquement converties en objets Date JavaScript par SuperJSON. Toutes les fonctions formatDate et safeFormatDate ont été mises à jour pour détecter et gérer correctement les objets Date en plus des chaînes MySQL, évitant ainsi les erreurs "Format de date non reconnu".
This commit is contained in:
@@ -171,7 +171,17 @@ export default function AdminSequenceInscrits() {
|
|||||||
if (!dateValue) return "N/A";
|
if (!dateValue) return "N/A";
|
||||||
|
|
||||||
try {
|
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 dateStr = String(dateValue);
|
||||||
const match = dateStr.match(/(\d{4})-(\d{2})-(\d{2})[T ]?(\d{2}):(\d{2})/);
|
const match = dateStr.match(/(\d{4})-(\d{2})-(\d{2})[T ]?(\d{2}):(\d{2})/);
|
||||||
|
|
||||||
|
|||||||
@@ -99,12 +99,22 @@ export default function AdminSequences() {
|
|||||||
const safeFormatDate = (dateValue: any): string => {
|
const safeFormatDate = (dateValue: any): string => {
|
||||||
if (!dateValue) return "";
|
if (!dateValue) return "";
|
||||||
try {
|
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
|
// 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}/)) {
|
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
|
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 dateStr = String(dateValue);
|
||||||
const match = dateStr.match(/(\d{4})-(\d{2})-(\d{2})[T ]?(\d{2}):(\d{2})/);
|
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";
|
if (!dateValue) return "N/A";
|
||||||
|
|
||||||
try {
|
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 dateStr = String(dateValue);
|
||||||
const match = dateStr.match(/(\d{4})-(\d{2})-(\d{2})[T ]?(\d{2}):(\d{2})/);
|
const match = dateStr.match(/(\d{4})-(\d{2})-(\d{2})[T ]?(\d{2}):(\d{2})/);
|
||||||
|
|
||||||
|
|||||||
@@ -113,6 +113,12 @@ export default function Inscription() {
|
|||||||
if (!dateValue) return "N/A";
|
if (!dateValue) return "N/A";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
let localDate: Date;
|
||||||
|
|
||||||
|
// 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
|
// Parser la date MySQL sans conversion UTC
|
||||||
const dateStr = String(dateValue);
|
const dateStr = String(dateValue);
|
||||||
const match = dateStr.match(/(\d{4})-(\d{2})-(\d{2})[T ]?(\d{2}):(\d{2})/);
|
const match = dateStr.match(/(\d{4})-(\d{2})-(\d{2})[T ]?(\d{2}):(\d{2})/);
|
||||||
@@ -124,14 +130,15 @@ export default function Inscription() {
|
|||||||
|
|
||||||
const [, year, month, day, hours, minutes] = match;
|
const [, year, month, day, hours, minutes] = match;
|
||||||
|
|
||||||
// Créer une Date en heure locale pour le formatage avec date-fns
|
// Créer une Date en heure locale
|
||||||
const localDate = new Date(
|
localDate = new Date(
|
||||||
parseInt(year),
|
parseInt(year),
|
||||||
parseInt(month) - 1,
|
parseInt(month) - 1,
|
||||||
parseInt(day),
|
parseInt(day),
|
||||||
parseInt(hours),
|
parseInt(hours),
|
||||||
parseInt(minutes)
|
parseInt(minutes)
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return format(localDate, "EEEE d MMMM yyyy 'à' HH:mm", { locale: fr });
|
return format(localDate, "EEEE d MMMM yyyy 'à' HH:mm", { locale: fr });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
2
todo.md
2
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 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 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
|
||||||
|
|||||||
Reference in New Issue
Block a user