From bf8aaf38a031a900d5fd3656af84a56f6a24d81e Mon Sep 17 00:00:00 2001 From: Jean-Luc Makiola Date: Fri, 20 Nov 2026 11:42:58 +0100 Subject: [PATCH] Give the other end the picked time where the store can't keep a date alone (#101) --- .../agendula/ui/edit/TaskEditViewModel.kt | 8 ++++---- .../agendula/ui/edit/TaskEditViewModelTest.kt | 18 +++++++++++++++++- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/de/jeanlucmakiola/agendula/ui/edit/TaskEditViewModel.kt b/app/src/main/java/de/jeanlucmakiola/agendula/ui/edit/TaskEditViewModel.kt index f97b7ab..5041510 100644 --- a/app/src/main/java/de/jeanlucmakiola/agendula/ui/edit/TaskEditViewModel.kt +++ b/app/src/main/java/de/jeanlucmakiola/agendula/ui/edit/TaskEditViewModel.kt @@ -32,8 +32,6 @@ import de.jeanlucmakiola.agendula.domain.populatedFields import de.jeanlucmakiola.agendula.domain.htmlToPlainText import de.jeanlucmakiola.agendula.domain.looksLikeHtml import de.jeanlucmakiola.agendula.domain.DefaultStartDate -import de.jeanlucmakiola.agendula.domain.allDayInstantOf -import de.jeanlucmakiola.agendula.domain.calendarDate import de.jeanlucmakiola.agendula.domain.dueWindows import de.jeanlucmakiola.agendula.domain.showsIn import de.jeanlucmakiola.floret.time.DayWindow @@ -445,7 +443,8 @@ class TaskEditViewModel @Inject constructor( * Sets [end] to [date] at [time], or to the date alone when [time] is null * (#101). With the other end also without a time, or a store that cannot * keep one end apart, that makes the whole task all-day; a time on one end - * of an all-day task leaves the other end's date without one. + * of an all-day task leaves the other end's date without one, or, where the + * store cannot keep that, gives it the same time. */ fun onWhenChange(end: TaskEnd, date: LocalDate, time: LocalTime?) = update { s -> val other = end.other @@ -467,7 +466,8 @@ class TaskEditViewModel @Inject constructor( when { allDay == s.isAllDay -> at allDay -> allDayInstantOf(at.calendarDate(allDay = false)) - else -> untimedInstantOf(other, at.calendarDate(allDay = true)) + s.untimedEnds -> untimedInstantOf(other, at.calendarDate(allDay = true)) + else -> localToInstant(at.calendarDate(allDay = true), checkNotNull(time)) } } val untimed = when { diff --git a/app/src/test/java/de/jeanlucmakiola/agendula/ui/edit/TaskEditViewModelTest.kt b/app/src/test/java/de/jeanlucmakiola/agendula/ui/edit/TaskEditViewModelTest.kt index abc6dc4..d895e7c 100644 --- a/app/src/test/java/de/jeanlucmakiola/agendula/ui/edit/TaskEditViewModelTest.kt +++ b/app/src/test/java/de/jeanlucmakiola/agendula/ui/edit/TaskEditViewModelTest.kt @@ -23,8 +23,8 @@ import de.jeanlucmakiola.agendula.domain.TaskForm import de.jeanlucmakiola.agendula.domain.TaskList import de.jeanlucmakiola.agendula.domain.TaskReminder import de.jeanlucmakiola.agendula.domain.TaskStatus -import de.jeanlucmakiola.agendula.domain.allDayInstantOf import de.jeanlucmakiola.agendula.domain.untimedInstantOf +import de.jeanlucmakiola.agendula.ui.common.localToInstant import de.jeanlucmakiola.agendula.domain.recurrence.RecurringScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.ExperimentalCoroutinesApi @@ -288,6 +288,22 @@ class TaskEditViewModelTest { assertThat(vm.state.value.untimed).isNull() } + @Test + fun `a store without untimed ends gives both ends the time picked for one`() { + repository.untimedEnds = false + val vm = editing(start = due - 1.days) + val day = LocalDate.now().plusDays(3) + vm.onWhenChange(TaskEnd.DUE, day, null) + vm.onWhenChange(TaskEnd.START, day.minusDays(1), null) + vm.onWhenChange(TaskEnd.DUE, day, LocalTime.of(17, 0)) + + val state = vm.state.value + assertThat(state.isAllDay).isFalse() + assertThat(state.untimed).isNull() + assertThat(state.due).isEqualTo(localToInstant(day, LocalTime.of(17, 0))) + assertThat(state.start).isEqualTo(localToInstant(day.minusDays(1), LocalTime.of(17, 0))) + } + @Test fun `clearing the timed end leaves the other one all-day`() { val vm = editing(start = due - 1.days)