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.
This commit is contained in:
Jennie Robinson Faber 2026-05-18 17:56:17 +01:00
parent 0927b66b4f
commit 9858316b30

View file

@ -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) {