From b2ede3f5255bca25e2830cccd1005f8181394846 Mon Sep 17 00:00:00 2001 From: "Torsten Schulz (local)" Date: Wed, 29 Apr 2026 15:36:19 +0200 Subject: [PATCH] Refactor upcoming event filtering: Update buildUpcomingWhere function to compare dates at the date-only level, addressing timezone issues. This change enhances the accuracy of event retrieval and improves code clarity. --- controllers/eventController.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/controllers/eventController.js b/controllers/eventController.js index 78ba934..ac8c7dc 100644 --- a/controllers/eventController.js +++ b/controllers/eventController.js @@ -1,13 +1,14 @@ const { Event, Institution, EventPlace, ContactPerson, EventType, EventContactPerson, sequelize } = require('../models'); -const { Op } = require('sequelize'); -const { startOfDay } = require('date-fns'); +const { Op, fn, col, where: sequelizeWhere } = require('sequelize'); +const { format, startOfDay } = require('date-fns'); function buildUpcomingWhere() { - const today = startOfDay(new Date()); + // Compare on date-only level to avoid timezone/DATETIME offset issues. + const todayDate = format(startOfDay(new Date()), 'yyyy-MM-dd'); return { [Op.or]: [ // Fixed-date events: only today or future. - { date: { [Op.gte]: today } }, + sequelizeWhere(fn('DATE', col('date')), { [Op.gte]: todayDate }), // Recurring/undated events: date is null (dayOfWeek may be set). { date: { [Op.eq]: null } }, ], @@ -72,7 +73,7 @@ const filterEvents = async (req, res) => { const events = await Event.findAll({ where: { alsoOnHomepage: 1, - date: { [Op.gte]: startOfDay(new Date()) } + ...buildUpcomingWhere(), }, include: [ { model: Institution, as: 'institution' },