From b4d061cb93d992febb5b70c9d7645afdd3a41890 Mon Sep 17 00:00:00 2001 From: Peter Stone Date: Mon, 26 Jan 2026 16:37:25 -1000 Subject: Fix Google Calendar timezone handling - Use event's TimeZone field when parsing DateTime - Handle cases where DateTime has no timezone offset - Parse in event timezone then convert to local for display Co-Authored-By: Claude Opus 4.5 --- internal/api/google_calendar.go | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'internal') diff --git a/internal/api/google_calendar.go b/internal/api/google_calendar.go index dc61f3d..1b1971a 100644 --- a/internal/api/google_calendar.go +++ b/internal/api/google_calendar.go @@ -26,11 +26,29 @@ func parseEventTime(item *calendar.Event) (start, end time.Time) { start, _ = time.ParseInLocation("2006-01-02", item.Start.Date, time.Local) end, _ = time.ParseInLocation("2006-01-02", item.End.Date, time.Local) } else { - // Timed event - parse RFC3339 then convert to local + // Timed event - use the event's timezone if specified + var loc *time.Location + if item.Start.TimeZone != "" { + loc, _ = time.LoadLocation(item.Start.TimeZone) + } + if loc == nil { + loc = time.Local + } + + // Try parsing with timezone offset first (RFC3339) start, _ = time.Parse(time.RFC3339, item.Start.DateTime) end, _ = time.Parse(time.RFC3339, item.End.DateTime) - start = start.Local() - end = end.Local() + + // If the parsed time is zero (parse failed) or missing timezone info, + // parse in the event's timezone + if start.IsZero() || item.Start.DateTime[len(item.Start.DateTime)-1] != 'Z' && !strings.Contains(item.Start.DateTime, "+") && !strings.Contains(item.Start.DateTime, "-") { + start, _ = time.ParseInLocation("2006-01-02T15:04:05", item.Start.DateTime, loc) + end, _ = time.ParseInLocation("2006-01-02T15:04:05", item.End.DateTime, loc) + } + + // Convert to local timezone for display + start = start.In(time.Local) + end = end.In(time.Local) } return } -- cgit v1.2.3