From c2e18b29243dd71803d04c7329eb91f0de617c5f Mon Sep 17 00:00:00 2001 From: thedhanawada Date: Thu, 5 Mar 2026 10:26:21 +0000 Subject: [PATCH] Fix #76: queryEvents() month filter checks adjacent months for timezone boundaries The byMonth index is built using the event's own timezone, so events near month boundaries may be indexed in a different month than expected by the query. Now checks adjacent months and post-filters by actual date overlap. Co-Authored-By: Claude Opus 4.6 --- core/events/EventStore.js | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/core/events/EventStore.js b/core/events/EventStore.js index 74e3a7f..ddfc87c 100644 --- a/core/events/EventStore.js +++ b/core/events/EventStore.js @@ -234,9 +234,30 @@ export class EventStore { // Filter by month if (filters.month && filters.year) { - const monthKey = `${filters.year}-${String(filters.month).padStart(2, '0')}`; - const eventIds = this.indices.byMonth.get(monthKey) || new Set(); - results = results.filter(event => eventIds.has(event.id)); + // Collect candidates from target month AND adjacent months to handle + // timezone boundary issues (events indexed in the event's own timezone + // may fall in a different month than the query month) + const candidateIds = new Set(); + for (let offset = -1; offset <= 1; offset++) { + let m = filters.month + offset; + let y = filters.year; + if (m < 1) { m = 12; y--; } + if (m > 12) { m = 1; y++; } + const key = `${y}-${String(m).padStart(2, '0')}`; + const ids = this.indices.byMonth.get(key); + if (ids) { + ids.forEach(id => candidateIds.add(id)); + } + } + + // Post-filter: only include events that actually overlap with the requested month + const monthStart = new Date(filters.year, filters.month - 1, 1); + const monthEnd = new Date(filters.year, filters.month, 0, 23, 59, 59, 999); + + results = results.filter(event => { + if (!candidateIds.has(event.id)) return false; + return event.start <= monthEnd && event.end >= monthStart; + }); } // Filter by all-day events