calendar: events ending exactly at midnight now render on their last day
- Commit
77e3fbb0fd23af05f20fb26e6cd95a0d0aef2785- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-30 19:42 UTC (5 days ago)
- Parents
d5aad72
A timed event ending at 00:00 (e.g. 22:00-24:00) vanished from the hourly grid: spanDays correctly treats a midnight end as exclusive, but EventPositioner read the last span day's end from the end wall time — 00:00 of the next day — producing a slice end of 0, before an evening start (dropped) or equal to a 00:00 start (shrunk to the 30-minute zero-duration fallback). Multi-day events ending at midnight likewise rendered 30 minutes on their last day. When an instance ends after it begins with a 00:00 end wall time and an end date past the day being sliced, the end now reads as 24:00 on that day; genuine zero-duration midnight events keep their existing 30-minute slice. Three regression tests (verified failing pre-fix). Verified: :calendar:testDevUnitTest 327 tests (one pre-existing Holiday-calendars scaffold-search failure from other in-flight work, untouched) and :calendar:lint passes.
Diff
calendar/src/main/java/com/vayunmathur/calendar/ui/EventPositioner.kt
diff --git a/calendar/src/main/java/com/vayunmathur/calendar/ui/EventPositioner.kt b/calendar/src/main/java/com/vayunmathur/calendar/ui/EventPositioner.ktindex 16eb34f439..39f082f928 100644--- a/calendar/src/main/java/com/vayunmathur/calendar/ui/EventPositioner.kt+++ b/calendar/src/main/java/com/vayunmathur/calendar/ui/EventPositioner.kt@@ -29,7 +29,19 @@ fun computePositionedEventsForDay(instances: List<Instance>, day: LocalDate): Li val startMinutes = if (day == instance.spanDays.first()) { instance.startDateTime.hour * 60 + instance.startDateTime.minute } else 0- val endMinutes = if (day == instance.spanDays.last()) {+ // An end exactly at midnight belongs to the day it closes, not the day+ // it opens: spanDays already excludes the midnight day (the end is+ // exclusive), so that instant reads as 24:00 on the last span day.+ // Taking its wall time (00:00) instead would give this day an end+ // before its start (an evening event is dropped outright) or a+ // 30-minute zero-duration slice (a whole-day event).+ val endsAtMidnightAfterDay = day == instance.spanDays.last() &&+ instance.end > instance.begin &&+ instance.endDateTime.date > day &&+ instance.endDateTime.hour == 0 && instance.endDateTime.minute == 0+ val endMinutes = if (endsAtMidnightAfterDay) {+ 24 * 60+ } else if (day == instance.spanDays.last()) { instance.endDateTime.hour * 60 + instance.endDateTime.minute } else 24 * 60
calendar/src/test/java/com/vayunmathur/calendar/ui/EventPositionerTest.kt
diff --git a/calendar/src/test/java/com/vayunmathur/calendar/ui/EventPositionerTest.kt b/calendar/src/test/java/com/vayunmathur/calendar/ui/EventPositionerTest.ktindex f8a1835961..e7bb406776 100644--- a/calendar/src/test/java/com/vayunmathur/calendar/ui/EventPositionerTest.kt+++ b/calendar/src/test/java/com/vayunmathur/calendar/ui/EventPositionerTest.kt@@ -9,8 +9,10 @@ import org.junit.Assert.assertEquals import org.junit.Test class EventPositionerTest {+ // Instance wall times resolve in the system zone (see Instance.displayZone),+ // so fixtures must be built there too or their minutes shift by the offset. private fun millis(date: LocalDate, minutes: Int): Long =- date.atTime(minutes / 60, minutes % 60).toInstant(TimeZone.UTC).toEpochMilliseconds()+ date.atTime(minutes / 60, minutes % 60).toInstant(TimeZone.currentSystemDefault()).toEpochMilliseconds() private fun timedInstance(atMinutes: Int): Instance { val day = LocalDate(2026, 9, 22)@@ -39,4 +41,58 @@ class EventPositionerTest { assertEquals(1, positioned.size) assertEquals(30, positioned[0].endMinutes - positioned[0].startMinutes) }++ private fun rangedInstance(beginDay: LocalDate, beginMinutes: Int, endDay: LocalDate, endMinutes: Int): Instance {+ val begin = millis(beginDay, beginMinutes)+ val end = millis(endDay, endMinutes)+ return Instance(+ id = 1L,+ eventID = 2L,+ begin = begin,+ end = end,+ timezone = "UTC",+ allDay = false,+ eventTitle = "Late shift",+ color = 0,+ rrule = null,+ )+ }++ @Test+ fun `event ending exactly at midnight keeps its evening slice`() {+ val day = LocalDate(2026, 9, 22)+ val next = LocalDate(2026, 9, 23)+ // 22:00 -> 00:00 the next day: spanDays is just the 22nd, but the slice+ // must run to 24:00 on that day, not collapse to 00:00 and be dropped.+ val instance = rangedInstance(day, 22 * 60, next, 0)+ assertEquals(listOf(day), instance.spanDays)+ val positioned = computePositionedEventsForDay(listOf(instance), day)+ assertEquals(1, positioned.size)+ assertEquals(22 * 60, positioned[0].startMinutes)+ assertEquals(24 * 60, positioned[0].endMinutes)+ }++ @Test+ fun `timed event covering a whole day to midnight fills that day`() {+ val day = LocalDate(2026, 9, 22)+ val next = LocalDate(2026, 9, 23)+ val instance = rangedInstance(day, 0, next, 0)+ val positioned = computePositionedEventsForDay(listOf(instance), day)+ assertEquals(1, positioned.size)+ assertEquals(0, positioned[0].startMinutes)+ assertEquals(24 * 60, positioned[0].endMinutes)+ }++ @Test+ fun `multi-day event ending at midnight fills its last day`() {+ val first = LocalDate(2026, 9, 22)+ val last = LocalDate(2026, 9, 23)+ val end = LocalDate(2026, 9, 24)+ val instance = rangedInstance(first, 9 * 60, end, 0)+ assertEquals(listOf(first, last), instance.spanDays)+ val positioned = computePositionedEventsForDay(listOf(instance), last)+ assertEquals(1, positioned.size)+ assertEquals(0, positioned[0].startMinutes)+ assertEquals(24 * 60, positioned[0].endMinutes)+ } }