From 5264453baab2b5810a98a49040cf18d771e13f23 Mon Sep 17 00:00:00 2001 From: Peter Stone Date: Mon, 13 Jul 2026 18:17:25 +0000 Subject: fix(web): account for Google Calendar's exclusive all-day end-date A single-day all-day event's End.Date is one calendar day past its own day (Google Calendar convention, already documented by TestParseEventTime_AllDayEvent). isMultiDayEvent/multiDayVariant didn't adjust for this, so every all-day event -- including single-day ones -- was misclassified as multi-day and duplicated across Today and Tomorrow. --- internal/handlers/timeline.go | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'internal/handlers/timeline.go') diff --git a/internal/handlers/timeline.go b/internal/handlers/timeline.go index e8eadde..9656d4c 100644 --- a/internal/handlers/timeline.go +++ b/internal/handlers/timeline.go @@ -24,6 +24,21 @@ func dateOnly(t time.Time) time.Time { return time.Date(t.Year(), t.Month(), t.Day(), 0, 0, 0, 0, t.Location()) } +// effectiveEndDay returns the last calendar day the item's occurrence +// actually covers. Google Calendar's all-day End.Date is EXCLUSIVE -- a +// single-day all-day event on July 13 has End = July 14 at midnight (see +// TestParseEventTime_AllDayEvent in internal/api/google_calendar_test.go) +// -- so for an all-day item this subtracts one day to get the real last +// day. Timed events' End is already the real end instant, so no +// adjustment is needed there. +func effectiveEndDay(item models.TimelineItem, tz *time.Location) time.Time { + endDay := dateOnly(item.EndTime.In(tz)) + if item.IsAllDay { + return endDay.AddDate(0, 0, -1) + } + return endDay +} + // isMultiDayEvent reports whether item is a calendar event whose Start and // End fall on different calendar days (in the display timezone). Only // events are ever considered multi-day -- tasks, cards, meals, and Google @@ -33,7 +48,9 @@ func isMultiDayEvent(item models.TimelineItem) bool { return false } tz := config.GetDisplayTimezone() - return !dateOnly(item.EndTime.In(tz)).Equal(dateOnly(item.Time.In(tz))) + startDay := dateOnly(item.Time.In(tz)) + endDay := effectiveEndDay(item, tz) + return endDay.After(startDay) } // multiDayVariant returns how a multi-day item should render on renderDay: @@ -44,7 +61,7 @@ func isMultiDayEvent(item models.TimelineItem) bool { func multiDayVariant(item models.TimelineItem, renderDay time.Time) string { tz := config.GetDisplayTimezone() startDay := dateOnly(item.Time.In(tz)) - endDay := dateOnly(item.EndTime.In(tz)) + endDay := effectiveEndDay(item, tz) day := dateOnly(renderDay.In(tz)) switch { -- cgit v1.2.3