diff options
Diffstat (limited to 'internal/handlers/timeline.go')
| -rw-r--r-- | internal/handlers/timeline.go | 21 |
1 files changed, 19 insertions, 2 deletions
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 { |
