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:
@@ -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})/);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user