Checkpoint: Correction du décalage horaire dans la gestion des séquences - Utilisation des méthodes UTC (getUTCHours, getUTCMinutes, etc.) pour l'affichage des dates et conversion locale vers UTC lors de l'envoi au serveur. Les heures saisies (ex: 9h00) sont maintenant correctement enregistrées et affichées.

This commit is contained in:
Manus Sandbox
2025-11-27 04:17:13 -05:00
parent 46f8a6bcfd
commit 6f6d7e8f7f
2 changed files with 28 additions and 7 deletions

View File

@@ -106,11 +106,12 @@ export default function AdminSequences() {
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');
// Utiliser les méthodes UTC pour éviter le décalage horaire
const year = dateValue.getUTCFullYear();
const month = String(dateValue.getUTCMonth() + 1).padStart(2, '0');
const day = String(dateValue.getUTCDate()).padStart(2, '0');
const hours = String(dateValue.getUTCHours()).padStart(2, '0');
const minutes = String(dateValue.getUTCMinutes()).padStart(2, '0');
return `${year}-${month}-${day}T${hours}:${minutes}`;
}
@@ -154,6 +155,15 @@ export default function AdminSequences() {
setIsEditOpen(true);
};
// Convertir une date locale (datetime-local) en ISO UTC
const convertLocalToUTC = (localDateStr: string): string => {
if (!localDateStr) return localDateStr;
// datetime-local retourne "YYYY-MM-DDTHH:mm"
// On doit le traiter comme heure locale et le convertir en UTC
const localDate = new Date(localDateStr);
return localDate.toISOString();
};
const handleSubmit = (e: React.FormEvent) => {
e.preventDefault();
@@ -168,10 +178,14 @@ export default function AdminSequences() {
lieu: formData.lieu,
publicCible: formData.publicCible,
capaciteMax: parseInt(formData.capaciteMax),
dateBlocage: formData.dateBlocage,
dateBlocage: convertLocalToUTC(formData.dateBlocage),
statut: formData.statut,
formateurId: formData.formateur ? parseInt(formData.formateur) : null,
dates: formData.dates,
dates: formData.dates.map(d => ({
...d,
dateDebut: convertLocalToUTC(d.dateDebut),
dateFin: convertLocalToUTC(d.dateFin),
})),
};
if (editingSequence) {