From fdea5cd6467911e0b2c640f7e49d29536d114eb6 Mon Sep 17 00:00:00 2001 From: Connor Johnstone Date: Sat, 13 Sep 2025 18:27:09 -0400 Subject: [PATCH] Fix timezone conversion bug for events displaying on wrong day MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Preserve original local dates when converting times to UTC for storage - Prevent events created late in day from appearing on next day due to timezone offset - Remove hacky bandaid logic in week view that tried to handle timezone shifts - Use stored event date directly instead of calculating from UTC conversion - Ensure events always display on intended day regardless of timezone Fixes issue where events created within last 4 hours of day would show on wrong day after UTC conversion caused date component to shift to next day. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- frontend/src/components/event_form/types.rs | 9 ++++++--- frontend/src/components/week_view.rs | 13 +++++-------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/frontend/src/components/event_form/types.rs b/frontend/src/components/event_form/types.rs index ada91f1..1e81c94 100644 --- a/frontend/src/components/event_form/types.rs +++ b/frontend/src/components/event_form/types.rs @@ -164,17 +164,20 @@ impl EventCreationData { self.end_time.format("%H:%M").to_string(), ) } else { - // Convert local date/time to UTC + // Convert local date/time to UTC, but preserve original local dates let start_local = Local.from_local_datetime(&self.start_date.and_time(self.start_time)).single(); let end_local = Local.from_local_datetime(&self.end_date.and_time(self.end_time)).single(); if let (Some(start_dt), Some(end_dt)) = (start_local, end_local) { let start_utc = start_dt.with_timezone(&chrono::Utc); let end_utc = end_dt.with_timezone(&chrono::Utc); + + // IMPORTANT: Use original local dates, not UTC dates! + // This ensures events display on the correct day regardless of timezone conversion ( - start_utc.format("%Y-%m-%d").to_string(), + self.start_date.format("%Y-%m-%d").to_string(), start_utc.format("%H:%M").to_string(), - end_utc.format("%Y-%m-%d").to_string(), + self.end_date.format("%Y-%m-%d").to_string(), end_utc.format("%H:%M").to_string(), ) } else { diff --git a/frontend/src/components/week_view.rs b/frontend/src/components/week_view.rs index 3bb1ad4..14965a6 100644 --- a/frontend/src/components/week_view.rs +++ b/frontend/src/components/week_view.rs @@ -1229,15 +1229,12 @@ fn pixels_to_time(pixels: f64, time_increment: u32) -> NaiveTime { fn calculate_event_position(event: &VEvent, date: NaiveDate, time_increment: u32, print_pixels_per_hour: Option, print_start_hour: Option) -> (f32, f32, bool) { // Convert UTC times to local time for display let local_start = event.dtstart.with_timezone(&Local); - let event_date = local_start.date_naive(); - - // Position events based on when they appear in local time, not their original date - // For timezone issues: an event created at 10 PM Sunday might be stored as Monday UTC - // but should still display on Sunday's column since that's when the user sees it - let should_display_here = event_date == date || - (event_date == date - chrono::Duration::days(1) && local_start.hour() >= 20); - if !should_display_here { + // Events should display based on their stored date (which now preserves the original local date) + // not the calculated local date from UTC conversion, since we fixed the creation logic + let event_date = event.dtstart.date_naive(); // Use the stored date, not the converted local date + + if event_date != date { return (0.0, 0.0, false); // Event not on this date }