diff --git a/app/src/main/java/de/jeanlucmakiola/calendula/data/reminders/ReminderTimeText.kt b/app/src/main/java/de/jeanlucmakiola/calendula/data/reminders/ReminderTimeText.kt index c169d709..138f8362 100644 --- a/app/src/main/java/de/jeanlucmakiola/calendula/data/reminders/ReminderTimeText.kt +++ b/app/src/main/java/de/jeanlucmakiola/calendula/data/reminders/ReminderTimeText.kt @@ -32,7 +32,8 @@ import java.util.Locale * - all-day, multi-day: "Tomorrow – 12 Jun 2026" (relative start, explicit end) * * All-day instances store UTC midnights with an exclusive end, so they are read - * in UTC and the end day is the last *covered* day (issue #308). + * in UTC and the end day is the last *covered* day (issue #308). A timed event + * from local midnight to local midnight reads like one too, in [zone] (#296). */ fun reminderTimeText( beginMillis: Long, @@ -47,11 +48,14 @@ fun reminderTimeText( tomorrowLabel: String, yesterdayLabel: String, ): String { - if (isAllDay) { + val wholeDays = !isAllDay && endMillis > beginMillis && + isStartOfDay(beginMillis, zone) && isStartOfDay(endMillis, zone) + if (isAllDay || wholeDays) { + val dayZone = if (isAllDay) ZoneOffset.UTC else zone val dateFormat = DateTimeFormatter.ofLocalizedDate(FormatStyle.MEDIUM).withLocale(locale) // (atZone().toLocalDate() instead of LocalDate.ofInstant — API 34+) - val firstDay = Instant.ofEpochMilli(beginMillis).atZone(ZoneOffset.UTC).toLocalDate() - val lastDay = Instant.ofEpochMilli(endMillis).atZone(ZoneOffset.UTC).toLocalDate() + val firstDay = Instant.ofEpochMilli(beginMillis).atZone(dayZone).toLocalDate() + val lastDay = Instant.ofEpochMilli(endMillis).atZone(dayZone).toLocalDate() .minusDays(1) .coerceAtLeast(firstDay) val start = relativeDayPrefix( @@ -134,3 +138,8 @@ private fun LocalDate.previousOrSame(target: DayOfWeek): LocalDate { } private const val RANGE = " – " + +private fun isStartOfDay(millis: Long, zone: ZoneId): Boolean { + val at = Instant.ofEpochMilli(millis).atZone(zone) + return at.toLocalDate().atStartOfDay(zone).toInstant().toEpochMilli() == millis +} diff --git a/app/src/main/java/de/jeanlucmakiola/calendula/domain/EventDisplayOrder.kt b/app/src/main/java/de/jeanlucmakiola/calendula/domain/EventDisplayOrder.kt index 2e141f1d..d71a5448 100644 --- a/app/src/main/java/de/jeanlucmakiola/calendula/domain/EventDisplayOrder.kt +++ b/app/src/main/java/de/jeanlucmakiola/calendula/domain/EventDisplayOrder.kt @@ -10,9 +10,16 @@ fun EventInstance.displayPriority(zone: TimeZone): Int = when { else -> 2 } -/** Shared order for agenda and split day lists. Grid bars add their lane geometry. */ -fun eventDisplayComparator(zone: TimeZone): Comparator = - compareBy { it.displayPriority(zone) } - .thenBy { it.start } - .thenBy { it.title } - .thenBy { it.instanceId } +/** + * Shared order for agenda and split day lists. Grid bars add their lane geometry. + * Each event's priority is worked out once, not on every comparison. + */ +fun List.sortedForDisplay(zone: TimeZone): List = + map { it to it.displayPriority(zone) } + .sortedWith( + compareBy> { it.second } + .thenBy { it.first.start } + .thenBy { it.first.title } + .thenBy { it.first.instanceId }, + ) + .map { it.first } diff --git a/app/src/main/java/de/jeanlucmakiola/calendula/ui/agenda/AgendaUiState.kt b/app/src/main/java/de/jeanlucmakiola/calendula/ui/agenda/AgendaUiState.kt index a5018451..d2d09b18 100644 --- a/app/src/main/java/de/jeanlucmakiola/calendula/ui/agenda/AgendaUiState.kt +++ b/app/src/main/java/de/jeanlucmakiola/calendula/ui/agenda/AgendaUiState.kt @@ -2,7 +2,7 @@ package de.jeanlucmakiola.calendula.ui.agenda import de.jeanlucmakiola.calendula.domain.EventInstance import de.jeanlucmakiola.calendula.domain.coversWholeDays -import de.jeanlucmakiola.calendula.domain.eventDisplayComparator +import de.jeanlucmakiola.calendula.domain.sortedForDisplay import de.jeanlucmakiola.calendula.domain.FailureReason import de.jeanlucmakiola.calendula.domain.spanFirstDay import de.jeanlucmakiola.calendula.domain.spanLastDay @@ -88,7 +88,7 @@ fun groupAgendaDays( return byDay.map { (date, dayEvents) -> AgendaDay( date = date, - events = dayEvents.sortedWith(eventDisplayComparator(zone)), + events = dayEvents.sortedForDisplay(zone), ) } } diff --git a/app/src/main/java/de/jeanlucmakiola/calendula/ui/common/TimelineDrag.kt b/app/src/main/java/de/jeanlucmakiola/calendula/ui/common/TimelineDrag.kt index 73c5db79..bd264e85 100644 --- a/app/src/main/java/de/jeanlucmakiola/calendula/ui/common/TimelineDrag.kt +++ b/app/src/main/java/de/jeanlucmakiola/calendula/ui/common/TimelineDrag.kt @@ -755,12 +755,21 @@ class TimelineDragController { /** Keep [landed]'s copy on the target as [settling] until [release]; [end] is a resize's. */ private fun settle(landed: TimelineDrag, end: Instant? = null) { + // Landed on midnight to midnight, the event moves to the all-day strip + // (#296): no block will seat its copy or carry the selection. + val leavesGrid = landed.eventSpanMin > 0 && + landed.eventStartMin.mod(MINUTES_PER_DAY) == 0 && + landed.eventSpanMin % MINUTES_PER_DAY == 0 + if (leavesGrid && !landed.event.isDraft && selection?.event?.instanceId == landed.event.instanceId) { + selection = null + selectionCovered = false + } settlingSelected = selection?.event?.instanceId == landed.event.instanceId // An edge piece is a hint for the finger, not a preview of the landing // slot: the event belongs to a day this timeline has no column for, so // [noteGrid] can never seat it and it would sit at the top of today for // the whole settle timeout, long after the event moved off-screen. - settling = if (landed.edgeOnly) landed.copy(pieces = emptyList()) else landed + settling = if (landed.edgeOnly || leavesGrid) landed.copy(pieces = emptyList()) else landed liftedInstanceId = landed.event.instanceId settledOrigin = landed.event.eventId to landed.event.start settledAbandonedMark = abandonedTicks?.value ?: 0 diff --git a/app/src/main/java/de/jeanlucmakiola/calendula/ui/month/MonthViewModel.kt b/app/src/main/java/de/jeanlucmakiola/calendula/ui/month/MonthViewModel.kt index dac7a722..a0f17831 100644 --- a/app/src/main/java/de/jeanlucmakiola/calendula/ui/month/MonthViewModel.kt +++ b/app/src/main/java/de/jeanlucmakiola/calendula/ui/month/MonthViewModel.kt @@ -21,7 +21,7 @@ import de.jeanlucmakiola.calendula.ui.agenda.anchorTodayIfMissing import de.jeanlucmakiola.calendula.ui.common.CalendarSpan import de.jeanlucmakiola.calendula.ui.common.PageStateCache import de.jeanlucmakiola.calendula.domain.isDeclined -import de.jeanlucmakiola.calendula.domain.eventDisplayComparator +import de.jeanlucmakiola.calendula.domain.sortedForDisplay import de.jeanlucmakiola.calendula.ui.week.coversDay import de.jeanlucmakiola.calendula.ui.week.layoutAllDay import de.jeanlucmakiola.calendula.ui.week.spansMultipleDays @@ -532,7 +532,7 @@ internal fun instancesByDay( days.associateWith { day -> instances .filter { it.coversDay(day, zone) } - .sortedWith(eventDisplayComparator(zone)) + .sortedForDisplay(zone) } /** diff --git a/app/src/main/java/de/jeanlucmakiola/calendula/ui/week/WeekViewModel.kt b/app/src/main/java/de/jeanlucmakiola/calendula/ui/week/WeekViewModel.kt index 802affb4..4bfa8cfd 100644 --- a/app/src/main/java/de/jeanlucmakiola/calendula/ui/week/WeekViewModel.kt +++ b/app/src/main/java/de/jeanlucmakiola/calendula/ui/week/WeekViewModel.kt @@ -292,17 +292,17 @@ internal fun layoutAllDay( days: List, zone: TimeZone, ): List { - data class Raw(val event: EventInstance, val startCol: Int, val endCol: Int) + data class Raw(val event: EventInstance, val startCol: Int, val endCol: Int, val priority: Int) val raw = events .mapNotNull { ev -> val covered = days.indices.filter { ev.coversDay(days[it], zone) } - if (covered.isEmpty()) null else Raw(ev, covered.first(), covered.last()) + if (covered.isEmpty()) null else Raw(ev, covered.first(), covered.last(), ev.displayPriority(zone)) } // Declined bars are packed after every other one, so on any day they // cover they land in a lane below it (#230). .sortedWith( - compareBy { it.event.displayPriority(zone) } + compareBy { it.priority } .thenBy { it.startCol } .thenBy { it.endCol } .thenBy { it.event.start } diff --git a/app/src/main/java/de/jeanlucmakiola/calendula/widget/countdown/Countdown.kt b/app/src/main/java/de/jeanlucmakiola/calendula/widget/countdown/Countdown.kt index 30ba653a..2c766175 100644 --- a/app/src/main/java/de/jeanlucmakiola/calendula/widget/countdown/Countdown.kt +++ b/app/src/main/java/de/jeanlucmakiola/calendula/widget/countdown/Countdown.kt @@ -1,6 +1,7 @@ package de.jeanlucmakiola.calendula.widget.countdown import de.jeanlucmakiola.calendula.domain.EventInstance +import de.jeanlucmakiola.calendula.domain.coversWholeDays import de.jeanlucmakiola.calendula.domain.isDeclined import kotlinx.datetime.DateTimeUnit import kotlinx.datetime.TimeZone @@ -74,12 +75,13 @@ fun nextLabelChange(event: EventInstance, now: Instant, zone: TimeZone): Instant } /** - * The next-event mode's pick: timed, not declined, not over; of those, the one - * whose countdown changes soonest — a running event's end, else a start. + * The next-event mode's pick: timed and not filling whole days (#296), not + * declined, not over; of those, the one whose countdown changes soonest — a + * running event's end, else a start. */ -fun pickNextEvent(instances: List, now: Instant): EventInstance? = +fun pickNextEvent(instances: List, now: Instant, zone: TimeZone): EventInstance? = instances - .filter { !it.isAllDay && !it.isDeclined && it.end > now } + .filter { !it.coversWholeDays(zone) && !it.isDeclined && it.end > now } .minByOrNull { target(it, now) } /** A pinned event's occurrence to count to: the running or next one. */ diff --git a/app/src/main/java/de/jeanlucmakiola/calendula/widget/countdown/CountdownData.kt b/app/src/main/java/de/jeanlucmakiola/calendula/widget/countdown/CountdownData.kt index c332ce6d..db9ac1d7 100644 --- a/app/src/main/java/de/jeanlucmakiola/calendula/widget/countdown/CountdownData.kt +++ b/app/src/main/java/de/jeanlucmakiola/calendula/widget/countdown/CountdownData.kt @@ -75,7 +75,11 @@ internal suspend fun Context.loadCountdown( val repository = widgetEntryPoint().calendarRepository() val event = when (options.mode) { CountdownMode.NEXT -> - pickNextEvent(repository.instances(now..now + NextEventHorizon).first().withoutCalendars(load.hiddenCalendars), now) + pickNextEvent( + repository.instances(now..now + NextEventHorizon).first().withoutCalendars(load.hiddenCalendars), + now, + systemZone(), + ) CountdownMode.PINNED -> options.eventId?.let { id -> pickPinnedOccurrence(repository.eventOccurrences(id, now - 1.days..now + PinnedHorizon), now, systemZone()) } diff --git a/app/src/main/java/de/jeanlucmakiola/calendula/widget/countdown/CountdownWidget.kt b/app/src/main/java/de/jeanlucmakiola/calendula/widget/countdown/CountdownWidget.kt index eccbcee1..975155d9 100644 --- a/app/src/main/java/de/jeanlucmakiola/calendula/widget/countdown/CountdownWidget.kt +++ b/app/src/main/java/de/jeanlucmakiola/calendula/widget/countdown/CountdownWidget.kt @@ -40,6 +40,7 @@ import androidx.glance.text.TextStyle import de.jeanlucmakiola.calendula.MainActivity import de.jeanlucmakiola.calendula.R import de.jeanlucmakiola.calendula.domain.EventInstance +import de.jeanlucmakiola.calendula.domain.coversWholeDays import de.jeanlucmakiola.calendula.ui.common.CalendarView import de.jeanlucmakiola.calendula.ui.common.eventAccent import de.jeanlucmakiola.calendula.widget.CalendulaWidgetReceiver @@ -210,12 +211,13 @@ private fun whenText(context: Context, event: EventInstance, data: CountdownData val at = if (running) counted.end else counted.start val date = at.toLocalDateTime(systemZone()).date val day = relativeDayLabel(context, date, data.today) + val wholeDays = event.coversWholeDays(systemZone()) return when { - event.isAllDay && running -> context.getString( + wholeDays && running -> context.getString( R.string.widget_countdown_until, relativeDayLabel(context, date.minus(1, DateTimeUnit.DAY), data.today), ) - event.isAllDay -> "$day · ${context.getString(R.string.event_detail_all_day)}" + wholeDays -> "$day · ${context.getString(R.string.event_detail_all_day)}" running -> context.getString(R.string.agenda_span_ends, "$day · ${formatWidgetTime(at, data.is24Hour)}") else -> "$day · ${formatWidgetTime(at, data.is24Hour)}" } diff --git a/app/src/test/java/de/jeanlucmakiola/calendula/data/reminders/ReminderTimeTextTest.kt b/app/src/test/java/de/jeanlucmakiola/calendula/data/reminders/ReminderTimeTextTest.kt index 13d20b6c..c5dd544a 100644 --- a/app/src/test/java/de/jeanlucmakiola/calendula/data/reminders/ReminderTimeTextTest.kt +++ b/app/src/test/java/de/jeanlucmakiola/calendula/data/reminders/ReminderTimeTextTest.kt @@ -212,4 +212,30 @@ class ReminderTimeTextTest { ) assertThat(text).isEqualTo("Today") } + + @Test + fun `a timed event from local midnight to midnight reads like an all-day one`() { + val oneDay = text( + beginMillis = millisAt(LocalDateTime.of(2026, 6, 12, 0, 0), berlin), + endMillis = millisAt(LocalDateTime.of(2026, 6, 13, 0, 0), berlin), + today = LocalDate.of(2026, 6, 11), + ) + assertThat(oneDay).isEqualTo("Tomorrow") + val twoDays = text( + beginMillis = millisAt(LocalDateTime.of(2026, 6, 11, 0, 0), berlin), + endMillis = millisAt(LocalDateTime.of(2026, 6, 13, 0, 0), berlin), + ) + assertThat(twoDays).startsWith("Today – ") + } + + @Test + fun `midnight is read in the device zone`() { + // Midnight in Berlin is 22:00 the day before in UTC, so it is timed there. + val text = text( + beginMillis = millisAt(LocalDateTime.of(2026, 6, 12, 0, 0), berlin), + endMillis = millisAt(LocalDateTime.of(2026, 6, 13, 0, 0), berlin), + zone = ZoneOffset.UTC, + ) + assertThat(text).contains("22:00") + } } diff --git a/app/src/test/java/de/jeanlucmakiola/calendula/widget/countdown/CountdownTest.kt b/app/src/test/java/de/jeanlucmakiola/calendula/widget/countdown/CountdownTest.kt index 6cd4ed40..0ccab507 100644 --- a/app/src/test/java/de/jeanlucmakiola/calendula/widget/countdown/CountdownTest.kt +++ b/app/src/test/java/de/jeanlucmakiola/calendula/widget/countdown/CountdownTest.kt @@ -68,9 +68,16 @@ class CountdownTest { val over = event(now - 2.hours, now - 1.hours, id = 3) val later = event(now + 3.hours, id = 4) val running = event(now - 1.hours, now + 2.hours, id = 5) - assertThat(pickNextEvent(listOf(allDay, declined, over, later), now)?.eventId).isEqualTo(4) + assertThat(pickNextEvent(listOf(allDay, declined, over, later), now, zone)?.eventId).isEqualTo(4) // A running event ending before the next one starts comes first. - assertThat(pickNextEvent(listOf(later, running), now)?.eventId).isEqualTo(5) + assertThat(pickNextEvent(listOf(later, running), now, zone)?.eventId).isEqualTo(5) + } + + @Test + fun `next-event mode skips a timed event filling whole days`() { + val wholeDay = event(Instant.parse("2026-10-22T00:00:00Z"), Instant.parse("2026-10-23T00:00:00Z"), id = 1) + val later = event(now + 30.hours, id = 2) + assertThat(pickNextEvent(listOf(wholeDay, later), now, zone)?.eventId).isEqualTo(2) } @Test