From db29d0e2788f63cc9eb0a43ec58313387acb0c0d Mon Sep 17 00:00:00 2001 From: Paul Nothaft Date: Fri, 1 May 2026 23:22:56 +0200 Subject: [PATCH] fix(events): coerce expires_in_days to Number before addDays MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The "Expires on" preview under the days-after-event input rendered nonsense dates (e.g. 25.04.2026 + 120 days → 08.01.2095, ~68 years out). Cause: handleInputChange stores e.target.value verbatim, which is a string for , so formData.expires_in_days is "120" not 120. date-fns addDays does: _date.setDate(_date.getDate() + amount) When amount is a string, the + is string concatenation: 25 + "120" = "25120". setDate("25120") then sets day-of-month to 25120, which carries over by ~68 years. Fix: cast to Number at the call site. The validation/API-payload codepaths already work because the comparisons at line 330 and the JSON payload coerce numerically through different paths — only addDays was actually broken. The TypeScript type FormData.expires_in_days: number is a lie because handleInputChange's [field]: e.target.value sets a string regardless. Tightening that handler is a separate cleanup; this commit only fixes the visible date bug. --- frontend/src/pages/admin/CreateEventPage.tsx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/frontend/src/pages/admin/CreateEventPage.tsx b/frontend/src/pages/admin/CreateEventPage.tsx index 56862b57..bde500f9 100644 --- a/frontend/src/pages/admin/CreateEventPage.tsx +++ b/frontend/src/pages/admin/CreateEventPage.tsx @@ -780,7 +780,12 @@ export const CreateEventPage: React.FC = () => { {formData.event_date && (

- {t('events.expiresOn')}: {format(addDays(new Date(formData.event_date), formData.expires_in_days))} + {/* Coerce to Number — handleInputChange stores the + value as a string, and date-fns + addDays does `_date.setDate(_date.getDate() + amount)` + which string-concatenates (25 + "120" = "25120") and + ends up ~68 years in the future. */} + {t('events.expiresOn')}: {format(addDays(new Date(formData.event_date), Number(formData.expires_in_days)))}

)}