From 9858316b30468c06eb0e35e9fee68fe57dd992fb Mon Sep 17 00:00:00 2001 From: Jennie Robinson Faber Date: Mon, 18 May 2026 17:56:17 +0100 Subject: [PATCH] fix(admin-events): preserve datetime on edit round-trip Editing an event was pulling its UTC startDate/endDate, slicing off the "Z" with toISOString().slice(0, 16), and then handing the bare digits to a datetime-local input. The input reinterprets them as local time, so each save shifted the time by the browser's UTC offset. Same pattern for registrationDeadline and earlyBirdDeadline. Format the value using local-time components instead so the round-trip matches what the admin sees. --- app/pages/admin/events/create.vue | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/app/pages/admin/events/create.vue b/app/pages/admin/events/create.vue index 07267e5..7f910fe 100644 --- a/app/pages/admin/events/create.vue +++ b/app/pages/admin/events/create.vue @@ -649,6 +649,16 @@ const eventForm = reactive({ }, }); +// Format a Date/ISO value into a datetime-local string using local-time components. +// `toISOString().slice(0,16)` drifts by the browser's UTC offset on edit round-trip. +const formatForDatetimeLocal = (value) => { + if (!value) return ""; + const d = new Date(value); + if (isNaN(d.getTime())) return ""; + const pad = (n) => String(n).padStart(2, "0"); + return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}T${pad(d.getHours())}:${pad(d.getMinutes())}`; +}; + // Agenda management functions const addAgendaItem = () => { eventForm.agenda.push(""); @@ -711,8 +721,8 @@ if (route.query.edit) { description: event.description, content: event.content || "", featureImage: event.featureImage || null, - startDate: new Date(event.startDate).toISOString().slice(0, 16), - endDate: new Date(event.endDate).toISOString().slice(0, 16), + startDate: formatForDatetimeLocal(event.startDate), + endDate: formatForDatetimeLocal(event.endDate), eventType: event.eventType, location: event.location || "", isOnline: event.isOnline, @@ -723,9 +733,7 @@ if (route.query.edit) { tags: event.tags || [], maxAttendees: event.maxAttendees || "", registrationRequired: event.registrationRequired, - registrationDeadline: event.registrationDeadline - ? new Date(event.registrationDeadline).toISOString().slice(0, 16) - : "", + registrationDeadline: formatForDatetimeLocal(event.registrationDeadline), agenda: event.agenda || [], tickets: event.tickets || { enabled: false, @@ -746,13 +754,10 @@ if (route.query.edit) { description: "", }, }); - // Handle early bird deadline formatting if (event.tickets?.public?.earlyBirdDeadline) { - eventForm.tickets.public.earlyBirdDeadline = new Date( + eventForm.tickets.public.earlyBirdDeadline = formatForDatetimeLocal( event.tickets.public.earlyBirdDeadline, - ) - .toISOString() - .slice(0, 16); + ); } } } catch (error) {