From 9771a88380d3386e8076b3d11f9743c47680c946 Mon Sep 17 00:00:00 2001 From: Anish Sarkar <104695310+AnishSarkar22@users.noreply.github.com> Date: Fri, 30 Jan 2026 20:51:03 +0530 Subject: [PATCH] fix: refine date handling in Google Calendar connector to ensure accurate same-day queries --- .../app/connectors/google_calendar_connector.py | 11 +++++++---- .../google_calendar_indexer.py | 17 ----------------- 2 files changed, 7 insertions(+), 21 deletions(-) diff --git a/surfsense_backend/app/connectors/google_calendar_connector.py b/surfsense_backend/app/connectors/google_calendar_connector.py index d8160cf25..7e24f3642 100644 --- a/surfsense_backend/app/connectors/google_calendar_connector.py +++ b/surfsense_backend/app/connectors/google_calendar_connector.py @@ -246,15 +246,18 @@ class GoogleCalendarConnector: dt_start = isoparse(start_date) dt_end = isoparse(end_date) + # Set start to beginning of day (00:00:00) and end to end of day (23:59:59) + # This ensures same-date queries work (e.g., start=2026-01-23, end=2026-01-23) + # and matches the Composio connector behavior if dt_start.tzinfo is None: - dt_start = dt_start.replace(tzinfo=pytz.UTC) + dt_start = dt_start.replace(hour=0, minute=0, second=0, tzinfo=pytz.UTC) else: - dt_start = dt_start.astimezone(pytz.UTC) + dt_start = dt_start.astimezone(pytz.UTC).replace(hour=0, minute=0, second=0) if dt_end.tzinfo is None: - dt_end = dt_end.replace(tzinfo=pytz.UTC) + dt_end = dt_end.replace(hour=23, minute=59, second=59, tzinfo=pytz.UTC) else: - dt_end = dt_end.astimezone(pytz.UTC) + dt_end = dt_end.astimezone(pytz.UTC).replace(hour=23, minute=59, second=59) if dt_start >= dt_end: return [], ( diff --git a/surfsense_backend/app/tasks/connector_indexers/google_calendar_indexer.py b/surfsense_backend/app/tasks/connector_indexers/google_calendar_indexer.py index 31796b4cd..81d33b5e2 100644 --- a/surfsense_backend/app/tasks/connector_indexers/google_calendar_indexer.py +++ b/surfsense_backend/app/tasks/connector_indexers/google_calendar_indexer.py @@ -209,23 +209,6 @@ async def index_google_calendar_events( start_date_str = start_date end_date_str = end_date - # If start_date and end_date are the same, adjust end_date to be one day later - # to ensure valid date range (start_date must be strictly before end_date) - if start_date_str == end_date_str: - # Parse the date and add one day to ensure valid range - dt = isoparse(end_date_str) - if dt.tzinfo is None: - dt = dt.replace(tzinfo=pytz.UTC) - else: - dt = dt.astimezone(pytz.UTC) - # Add one day to end_date to make it strictly after start_date - dt_end = dt + timedelta(days=1) - end_date_str = dt_end.strftime("%Y-%m-%d") - logger.info( - f"Adjusted end_date from {end_date} to {end_date_str} " - f"to ensure valid date range (start_date must be strictly before end_date)" - ) - await task_logger.log_task_progress( log_entry, f"Fetching Google Calendar events from {start_date_str} to {end_date_str}",