Merge #101 into release/v1.4.0

# Conflicts:
#	app/src/main/java/de/jeanlucmakiola/agendula/data/tasks/TasksRepository.kt
#	app/src/main/java/de/jeanlucmakiola/agendula/data/tasks/TasksRepositoryImpl.kt
#	app/src/main/java/de/jeanlucmakiola/agendula/data/tasks/room/RoomTaskMapper.kt
#	app/src/main/java/de/jeanlucmakiola/agendula/data/tasks/room/TaskFormWriter.kt
#	app/src/main/java/de/jeanlucmakiola/agendula/domain/TaskForm.kt
#	app/src/main/java/de/jeanlucmakiola/agendula/domain/export/ExportModels.kt
#	app/src/main/java/de/jeanlucmakiola/agendula/ui/edit/TaskEditViewModel.kt
#	app/src/test/java/de/jeanlucmakiola/agendula/data/tasks/room/TaskFormWriterSeriesTest.kt
This commit is contained in:
makiolaj committed 2026-11-18 19:47:30 +01:00
commit 55f149d0f3
50 files changed
+2431 -285

No files matched your search

@@ -2,7 +2,9 @@ package de.jeanlucmakiola.agendula.data.reminders
import com.google.common.truth.Truth.assertThat
import de.jeanlucmakiola.agendula.data.prefs.Settings
import de.jeanlucmakiola.agendula.domain.TaskEnd
import de.jeanlucmakiola.agendula.domain.TaskReminder
import de.jeanlucmakiola.agendula.domain.untimedInstantOf
import de.jeanlucmakiola.agendula.domain.allDayInstantOf
import de.jeanlucmakiola.agendula.domain.testTask
import de.jeanlucmakiola.agendula.domain.asReminderLead
@@ -40,6 +42,40 @@ class ReminderPlannerTest {
assertThat(trigger).isEqualTo(millis(date.minusDays(1).atTime(8, 30), berlin))
}
@Test
fun `a due without a time rings at the all-day time of its day, not at its last second`() {
val start = Instant.fromEpochMilliseconds(millis(date.minusDays(1).atTime(14, 0), berlin))
val due = untimedInstantOf(TaskEnd.DUE, date, berlin)
val task = testTask(id = 1, start = start, due = due).copy(untimed = TaskEnd.DUE)
val plan = ReminderPlanner.plan(
tasks = listOf(task),
perTask = mapOf(1L to listOf(TaskReminder(0), TaskReminder(0, fromStart = true))),
settings = Settings(allDayReminderMinuteOfDay = 9 * 60),
now = start.toEpochMilliseconds() - 60_000,
zone = berlin,
)
assertThat(plan.map { it.triggerAt }).containsExactly(
millis(date.atTime(9, 0), berlin),
start.toEpochMilliseconds(),
)
}
@Test
fun `a dismissal on a client that rang the untimed end at its stored moment silences it here`() {
val start = untimedInstantOf(TaskEnd.START, date, berlin)
val due = Instant.fromEpochMilliseconds(millis(date.atTime(17, 0), berlin))
val task = testTask(id = 1, start = start, due = due).copy(untimed = TaskEnd.START)
val dismissed = Instant.fromEpochMilliseconds(millis(date.atTime(7, 30), berlin))
val plan = ReminderPlanner.plan(
tasks = listOf(task),
perTask = mapOf(1L to listOf(TaskReminder(0, fromStart = true, acknowledgedAt = dismissed))),
settings = Settings(allDayReminderMinuteOfDay = 9 * 60),
now = dismissed.toEpochMilliseconds(),
zone = berlin,
)
assertThat(plan).isEmpty()
}
@Test
fun `a default from before the task existed does not ring`() {
val created = Instant.fromEpochMilliseconds(millis(date.atTime(14, 0), berlin))
@@ -2,10 +2,12 @@ package de.jeanlucmakiola.agendula.data.tasks
import com.google.common.truth.Truth.assertThat
import de.jeanlucmakiola.agendula.data.prefs.Settings
import de.jeanlucmakiola.agendula.domain.TaskEnd
import de.jeanlucmakiola.agendula.domain.TaskForm
import de.jeanlucmakiola.agendula.domain.TaskReminder
import de.jeanlucmakiola.agendula.domain.allDayInstantOf
import de.jeanlucmakiola.agendula.domain.testTask
import de.jeanlucmakiola.agendula.domain.untimedInstantOf
import de.jeanlucmakiola.agendula.domain.asReminderLead
import de.jeanlucmakiola.floret.reminders.asReminderLeads
import org.junit.jupiter.api.Test
@@ -29,6 +31,38 @@ class StoredRemindersTest {
private fun stored(form: TaskForm, current: de.jeanlucmakiola.agendula.domain.Task? = null, with: Settings = settings) =
StoredReminders.of(form, current, with, now.toEpochMilliseconds(), zone)
@Test
fun `an end without a time is past or not by the time it rings at, not the one it is stored at`() {
val today = LocalDate.of(2026, 10, 1)
val withTimes = Settings(
defaultReminders = listOf(TaskReminder(60), TaskReminder(0, fromStart = true)).map { it.asReminderLead() },
allDayReminderMinuteOfDay = 13 * 60,
)
val untimedDue = TaskForm(
title = "t", listId = 1, start = now - 1.hours,
due = untimedInstantOf(TaskEnd.DUE, today, zone), untimed = TaskEnd.DUE,
)
val untimedStart = TaskForm(
title = "t", listId = 1, start = untimedInstantOf(TaskEnd.START, today, zone),
due = now + 5.days, untimed = TaskEnd.START,
)
assertThat(stored(untimedDue, with = withTimes.copy(allDayReminderMinuteOfDay = 9 * 60))).isEmpty()
assertThat(stored(untimedStart, with = withTimes)).contains(TaskReminder(0, fromStart = true))
}
@Test
fun `an untouched untimed end from another zone does not count as moved`() {
val day = LocalDate.of(2026, 9, 3)
val current = testTask(id = 1, start = now - 30.days, due = untimedInstantOf(TaskEnd.DUE, day, ZoneId.of("America/New_York")))
.copy(untimed = TaskEnd.DUE, timeZone = "America/New_York")
val own = TaskReminder(0, fromStart = true)
val form = TaskForm(
title = "t", listId = 1, start = current.start, due = current.formValueOf(TaskEnd.DUE),
untimed = TaskEnd.DUE, reminders = listOf(own),
)
assertThat(stored(form, current)).containsExactly(own)
}
@Test
fun `a new task takes the defaults for the dates it has`() {
val form = TaskForm(title = "t", listId = 1, start = now + 2.days, due = now + 5.days)
@@ -5,9 +5,12 @@ import de.jeanlucmakiola.agendula.data.tasks.room.AlarmReference
import de.jeanlucmakiola.agendula.data.tasks.room.TaskAlarmEntity
import de.jeanlucmakiola.agendula.data.tasks.room.TaskEntity
import de.jeanlucmakiola.agendula.domain.PRIORITY_NONE
import de.jeanlucmakiola.agendula.domain.TaskEnd
import de.jeanlucmakiola.agendula.domain.untimedDate
import de.jeanlucmakiola.agendula.domain.TaskStatus
import de.jeanlucmakiola.agendula.domain.ical.ICalComponent
import de.jeanlucmakiola.agendula.domain.ical.ICalParser
import de.jeanlucmakiola.agendula.domain.ical.ICalValues
import org.junit.jupiter.api.Nested
import org.junit.jupiter.api.Test
import kotlin.time.Duration.Companion.days
@@ -434,6 +437,168 @@ class VTodoMapperTest {
}
}
/** One end without a time beside a timed one (#101). */
@Nested
inner class UntimedEnd {
private val mixed = TaskEntity(
listId = 1L,
uid = "t-1",
dtstart = Instant.parse("2026-08-31T22:00:00Z"),
due = Instant.parse("2026-09-01T15:00:00Z"),
timezone = "Europe/Berlin",
untimed = TaskEnd.START,
)
@Test
fun `the untimed end is written as a marked date-time, so both ends share a value type`() {
val written = VTodoMapper.write(mixed)
val start = written.property("DTSTART")!!
val due = written.property("DUE")!!
assertThat(start.value).isEqualTo("20260901T000000")
assertThat(start.param("TZID")).isEqualTo("Europe/Berlin")
assertThat(start.param(ICalValues.NO_TIME_PARAM)).isEqualTo("TRUE")
assertThat(start.param("VALUE")).isNull()
assertThat(due.value).isEqualTo("20260901T170000")
assertThat(due.param(ICalValues.NO_TIME_PARAM)).isNull()
assertThat(VTodoMapper.validate(written)).isEmpty()
}
@Test
fun `a written mixed task reads back as itself, with nothing left in the residue`() {
val read = VTodoMapper.read(VTodoMapper.write(mixed)).entity
assertThat(read.untimed).isEqualTo(TaskEnd.START)
assertThat(read.isAllDay).isFalse()
assertThat(read.dtstart).isEqualTo(mixed.dtstart)
assertThat(read.due).isEqualTo(mixed.due)
assertThat(read.unknownProperties).isNull()
}
@Test
fun `an untimed due round-trips too`() {
val dueOnly = mixed.copy(
dtstart = Instant.parse("2026-09-01T07:00:00Z"),
due = Instant.parse("2026-09-01T21:59:59Z"),
untimed = TaskEnd.DUE,
)
val written = VTodoMapper.write(dueOnly)
assertThat(written.property("DUE")?.param(ICalValues.NO_TIME_PARAM)).isEqualTo("TRUE")
assertThat(written.property("DTSTART")?.param(ICalValues.NO_TIME_PARAM)).isNull()
assertThat(VTodoMapper.read(written).entity.untimed).isEqualTo(TaskEnd.DUE)
}
@Test
fun `a value another client rewrote without the mark has a time again`() {
val read = VTodoMapper.read(
vtodo("DTSTART;TZID=Europe/Berlin:20260901T000000", "DUE;TZID=Europe/Berlin:20260901T170000"),
).entity
assertThat(read.untimed).isNull()
}
@Test
fun `a mark on both ends is not ours to read, and stays as it arrived`() {
val mapped = VTodoMapper.read(
vtodo(
"DTSTART;X-AGENDULA-NO-TIME=TRUE;TZID=Europe/Berlin:20260901T000000",
"DUE;X-AGENDULA-NO-TIME=TRUE;TZID=Europe/Berlin:20260901T235959",
),
)
assertThat(mapped.entity.untimed).isNull()
assertThat(mapped.entity.unknownProperties).contains("DTSTART;X-AGENDULA-NO-TIME=TRUE")
assertThat(mapped.entity.unknownProperties).contains("DUE;X-AGENDULA-NO-TIME=TRUE")
}
@Test
fun `a marked value another client moved off its day boundary has a time, and loses the mark`() {
val mapped = VTodoMapper.read(
vtodo(
"DTSTART;TZID=Europe/Berlin:20260901T090000",
"DUE;X-AGENDULA-NO-TIME=TRUE;TZID=Europe/Berlin:20260901T150000",
),
)
assertThat(mapped.entity.untimed).isNull()
assertThat(VTodoMapper.write(mapped.entity).property("DUE")?.param(ICalValues.NO_TIME_PARAM)).isNull()
}
@Test
fun `a mark on a UTC value says nothing about its day and is not read`() {
val read = VTodoMapper.read(
vtodo("DTSTART;TZID=Europe/Berlin:20260901T090000", "DUE;X-AGENDULA-NO-TIME=TRUE:20260901T215959Z"),
).entity
assertThat(read.untimed).isNull()
}
@Test
fun `an untimed due in another zone than the task's is not read as one`() {
val read = VTodoMapper.read(
vtodo(
"DTSTART;TZID=Europe/Berlin:20260901T090000",
"DUE;X-AGENDULA-NO-TIME=TRUE;TZID=America/New_York:20260901T235959",
),
).entity
assertThat(read.untimed).isNull()
}
@Test
fun `a floating untimed end is placed in the task's zone, and written back zoned`() {
val mapped = VTodoMapper.read(
vtodo("DTSTART;X-AGENDULA-NO-TIME=TRUE:20260901T000000", "DUE;TZID=Europe/Berlin:20260901T170000"),
)
assertThat(mapped.entity.untimed).isEqualTo(TaskEnd.START)
assertThat(mapped.entity.dtstart).isEqualTo(Instant.parse("2026-08-31T22:00:00Z"))
assertThat(mapped.entity.unknownProperties).isNull()
val start = VTodoMapper.write(mapped.entity).property("DTSTART")!!
assertThat(start.value).isEqualTo("20260901T000000")
assertThat(start.param("TZID")).isEqualTo("Europe/Berlin")
}
@Test
fun `without a zone the untimed end is written floating, never as UTC`() {
val start = VTodoMapper.write(mixed.copy(timezone = null)).property("DTSTART")!!
assertThat(start.value).endsWith("T000000")
assertThat(start.param("TZID")).isNull()
assertThat(start.param(ICalValues.NO_TIME_PARAM)).isEqualTo("TRUE")
}
@Test
fun `a floating untimed start on a day without a midnight still reads as one`() {
val read = VTodoMapper.read(
vtodo(
"DTSTART;X-AGENDULA-NO-TIME=TRUE:20260906T000000",
"DUE;TZID=America/Santiago:20260906T170000",
),
).entity
assertThat(read.untimed).isEqualTo(TaskEnd.START)
assertThat(read.dtstart!!.untimedDate(read.timezone)).isEqualTo(java.time.LocalDate.of(2026, 9, 6))
}
@Test
fun `a mark on a DATE is ignored, the task is all-day`() {
val read = VTodoMapper.read(
vtodo("DTSTART;X-AGENDULA-NO-TIME=TRUE;VALUE=DATE:20260901", "DUE;VALUE=DATE:20260902"),
).entity
assertThat(read.isAllDay).isTrue()
assertThat(read.untimed).isNull()
}
@Test
fun `giving the untimed end a time evicts the marked residue copy`() {
val residue = "DTSTART;X-AGENDULA-NO-TIME=TRUE;TZID=Europe/Berlin:20260901T000000\r\n"
val entity = mixed.copy(untimed = null, unknownProperties = residue)
val start = VTodoMapper.write(entity).properties("DTSTART")
assertThat(start).hasSize(1)
assertThat(start.single().param(ICalValues.NO_TIME_PARAM)).isNull()
}
@Test
fun `all-day wins over a stray untimed flag`() {
val entity = mixed.copy(isAllDay = true, dtstart = Instant.parse("2026-09-01T00:00:00Z"))
val start = VTodoMapper.write(entity).property("DTSTART")!!
assertThat(start.param("VALUE")).isEqualTo("DATE")
assertThat(start.param(ICalValues.NO_TIME_PARAM)).isNull()
}
}
private fun entity(
sequence: Int = 0,
completedAt: Instant? = null,
@@ -5,6 +5,7 @@ import de.jeanlucmakiola.agendula.data.tasks.TasksContract
import de.jeanlucmakiola.agendula.data.tasks.TasksContract.Instances
import de.jeanlucmakiola.agendula.data.tasks.TasksContract.Tasks
import de.jeanlucmakiola.agendula.data.tasks.room.TaskEntity
import de.jeanlucmakiola.agendula.domain.TaskEnd
import de.jeanlucmakiola.agendula.domain.TaskStatus
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertThrows
@@ -405,6 +406,19 @@ class ProviderTaskWriterTest {
assertThrows<IllegalArgumentException> { patch(task, Tasks.IS_ALLDAY to "yes") }
}
@Test
fun `an untimed end keeps its mark until a client moves it (#101)`() {
val start = Instant.parse("2026-10-19T22:00:00Z")
val due = Instant.parse("2026-10-20T15:00:00Z")
val mixed = task.copy(dtstart = start, due = due, timezone = "Europe/Berlin", untimed = TaskEnd.START)
assertThat(patch(mixed, Tasks.TITLE to "New").untimed).isEqualTo(TaskEnd.START)
assertThat(patch(mixed, Tasks.DUE to millis(due + 1.hours)).untimed).isEqualTo(TaskEnd.START)
assertThat(patch(mixed, Tasks.DTSTART to millis(start + 9.hours)).untimed).isNull()
assertThat(patch(mixed, Tasks.IS_ALLDAY to 1).untimed).isNull()
assertThat(patch(mixed, Tasks.TZ to "America/New_York").untimed).isNull()
}
// --- no-op writes -------------------------------------------------------------
@Test
@@ -0,0 +1,45 @@
package de.jeanlucmakiola.agendula.data.tasks.room
import com.google.common.truth.Truth.assertThat
import de.jeanlucmakiola.agendula.domain.TaskEnd
import de.jeanlucmakiola.agendula.domain.untimedInstantOf
import org.junit.jupiter.api.Test
import java.time.LocalDate
import java.time.ZoneId
import kotlin.time.Instant
class OccurrenceTimesTest {
private val berlin = ZoneId.of("Europe/Berlin")
private fun at(date: LocalDate, hour: Int) =
Instant.fromEpochMilliseconds(date.atTime(hour, 0).atZone(berlin).toInstant().toEpochMilli())
@Test
fun `a due without a time stays on its day across a clock change (#101)`() {
val master = TaskEntity(
listId = 1,
uid = "u",
dtstart = at(LocalDate.of(2026, 10, 24), 10),
due = untimedInstantOf(TaskEnd.DUE, LocalDate.of(2026, 10, 26), berlin),
timezone = "Europe/Berlin",
untimed = TaskEnd.DUE,
rrule = "FREQ=WEEKLY",
)
val (_, due) = occurrenceTimes(master, at(LocalDate.of(2026, 10, 31), 10))
assertThat(due).isEqualTo(untimedInstantOf(TaskEnd.DUE, LocalDate.of(2026, 11, 2), berlin))
}
@Test
fun `a timed due keeps the master's length`() {
val master = TaskEntity(
listId = 1,
uid = "u",
dtstart = at(LocalDate.of(2026, 9, 1), 10),
due = at(LocalDate.of(2026, 9, 1), 12),
timezone = "Europe/Berlin",
)
val (_, due) = occurrenceTimes(master, at(LocalDate.of(2026, 9, 8), 10))
assertThat(due).isEqualTo(at(LocalDate.of(2026, 9, 8), 12))
}
}
@@ -1,7 +1,10 @@
package de.jeanlucmakiola.agendula.data.tasks.room
import com.google.common.truth.Truth.assertThat
import de.jeanlucmakiola.agendula.domain.TaskEnd
import de.jeanlucmakiola.agendula.domain.TaskForm
import de.jeanlucmakiola.agendula.domain.untimedInstantOf
import java.time.LocalDate
import org.junit.jupiter.api.Test
import kotlin.time.Duration.Companion.days
import kotlin.time.Duration.Companion.hours
@@ -172,4 +175,52 @@ class TaskFormWriterSeriesTest {
assertThat(TaskFormWriter.countOf("FREQ=DAILY;count=4;INTERVAL=2")).isEqualTo(4)
assertThat(TaskFormWriter.countOf("FREQ=DAILY")).isNull()
}
@Test
fun `an untimed start moved for the whole series across a clock change stays on its day (#101)`() {
val berlin = java.time.ZoneId.of("Europe/Berlin")
val untimed = master.copy(
dtstart = untimedInstantOf(TaskEnd.START, LocalDate.of(2026, 1, 5), berlin),
due = Instant.parse("2026-01-05T16:00:00Z"),
untimed = TaskEnd.START,
rrule = "FREQ=WEEKLY",
)
val occurrenceStart = untimedInstantOf(TaskEnd.START, LocalDate.of(2026, 3, 23), berlin)
val form = TaskForm(
title = "Water plants",
listId = 1,
start = untimedInstantOf(TaskEnd.START, LocalDate.of(2026, 3, 30), berlin),
due = Instant.parse("2026-03-30T15:00:00Z"),
untimed = TaskEnd.START,
rrule = "FREQ=WEEKLY",
)
val edited = TaskFormWriter.seriesEdit(untimed, occurrenceStart, Instant.parse("2026-03-23T16:00:00Z"), form, now, "Europe/Berlin")
assertThat(edited.dtstart).isEqualTo(untimedInstantOf(TaskEnd.START, LocalDate.of(2026, 1, 12), berlin))
assertThat(edited.untimed).isEqualTo(TaskEnd.START)
}
@Test
fun `its exceptions move by whole days with it`() {
val berlin = java.time.ZoneId.of("Europe/Berlin")
val untimed = master.copy(
dtstart = untimedInstantOf(TaskEnd.START, LocalDate.of(2026, 3, 20), berlin),
due = null,
untimed = TaskEnd.START,
rrule = "FREQ=DAILY",
exdate = "20260327T000000",
)
val occurrence = untimedInstantOf(TaskEnd.START, LocalDate.of(2026, 3, 28), berlin)
val form = TaskForm(
title = "Water plants",
listId = 1,
start = untimedInstantOf(TaskEnd.START, LocalDate.of(2026, 3, 30), berlin),
due = Instant.parse("2026-03-31T10:00:00Z"),
untimed = TaskEnd.START,
rrule = "FREQ=DAILY",
)
val edited = TaskFormWriter.seriesEdit(untimed, occurrence, null, form, now, "Europe/Berlin")
assertThat(edited.exdate).isEqualTo("20260329T000000")
}
}
@@ -57,4 +57,34 @@ class AllDayTimeTest {
val back = there.rebasedForAllDay(allDay = true, zone = newYork)
assertThat(back).isEqualTo(original)
}
@Test
fun `an untimed end is the first or the last second of its day in the zone`() {
val start = untimedInstantOf(TaskEnd.START, julyTwentieth, newYork)
val due = untimedInstantOf(TaskEnd.DUE, julyTwentieth, newYork)
assertThat(start).isEqualTo(Instant.parse("2026-07-20T04:00:00Z"))
assertThat(due).isEqualTo(Instant.parse("2026-07-21T03:59:59Z"))
assertThat(start.calendarDate(allDay = false, zone = newYork)).isEqualTo(julyTwentieth)
assertThat(due.calendarDate(allDay = false, zone = newYork)).isEqualTo(julyTwentieth)
}
@Test
fun `an untimed end reads as its date in the task's zone, wherever the device is`() {
val due = untimedInstantOf(TaskEnd.DUE, julyTwentieth, berlin)
val task = testTask(start = due - kotlin.time.Duration.parse("2h"), due = due)
.copy(untimed = TaskEnd.DUE, timeZone = "Europe/Berlin")
assertThat(task.dateOf(TaskEnd.DUE, ZoneId.of("Asia/Tokyo"))).isEqualTo(julyTwentieth)
assertThat(task.shownValue(TaskEnd.DUE)).isEqualTo(allDayInstantOf(julyTwentieth))
assertThat(task.hasTime(TaskEnd.DUE)).isFalse()
assertThat(task.hasTime(TaskEnd.START)).isTrue()
}
@Test
fun `a day that starts in a clock change starts at its first valid moment`() {
val santiago = ZoneId.of("America/Santiago")
val transition = LocalDate.of(2026, 9, 6)
val start = untimedInstantOf(TaskEnd.START, transition, santiago)
assertThat(start.calendarDate(allDay = false, zone = santiago)).isEqualTo(transition)
assertThat(start).isEqualTo(Instant.fromEpochMilliseconds(transition.atStartOfDay(santiago).toInstant().toEpochMilli()))
}
}
@@ -29,4 +29,16 @@ class TaskSortingTest {
assertThat(sorted.map { it.taskId }).containsExactly(2L, 1L).inOrder()
}
@Test
fun `dues without a time sort from the start of their day, all-day or not`() {
val berlin = java.time.ZoneId.systemDefault()
val day = java.time.LocalDate.of(2026, 11, 17)
val allDay = testTask(id = 1, title = "a", due = allDayInstantOf(day), isAllDay = true)
val timed = testTask(id = 2, title = "b", due = kotlin.time.Instant.fromEpochMilliseconds(day.atTime(10, 0).atZone(berlin).toInstant().toEpochMilli()))
val untimed = testTask(id = 3, title = "c", start = timed.due, due = untimedInstantOf(TaskEnd.DUE, day, berlin))
.copy(untimed = TaskEnd.DUE)
val sorted = listOf(timed, untimed, allDay).sortedWith(TaskSorting.DEFAULT)
assertThat(sorted.map { it.taskId }).containsExactly(1L, 3L, 2L).inOrder()
}
}
@@ -2,7 +2,9 @@ package de.jeanlucmakiola.agendula.domain.export
import com.google.common.truth.Truth.assertThat
import de.jeanlucmakiola.agendula.domain.Priority
import de.jeanlucmakiola.agendula.domain.TaskEnd
import de.jeanlucmakiola.agendula.domain.TaskStatus
import de.jeanlucmakiola.agendula.domain.untimedDate
import de.jeanlucmakiola.agendula.domain.allDayInstantOf
import org.junit.jupiter.api.Nested
import org.junit.jupiter.api.Test
@@ -36,9 +38,12 @@ class ICalendarWriterTest {
rdate: String? = null,
parentId: Long? = null,
tags: List<String> = emptyList(),
untimed: TaskEnd? = null,
timeZone: String? = null,
) = ExportTask(
taskId, uid, title, description, location, url, priority, status, percentComplete,
start, due, isAllDay, completedAt, created, lastModified, rrule, rdate, parentId, tags,
untimed = untimed, timeZone = timeZone,
)
private fun write(vararg tasks: ExportTask, name: String = "Groceries"): String =
@@ -148,6 +153,33 @@ class ICalendarWriterTest {
assertThat(lines).contains("DUE;VALUE=DATE:20260802")
}
@Test
fun `an untimed end is a marked floating date-time, its own day wherever it is read`() {
val start = Instant.parse("2025-08-01T22:00:00Z")
val lines = linesOf(write(task(start = start, due = noon, untimed = TaskEnd.START, timeZone = "Europe/Berlin")))
assertThat(lines).contains("DTSTART;X-AGENDULA-NO-TIME=TRUE:20250802T000000")
assertThat(lines).contains("DUE:20250802T120000Z")
}
@Test
fun `the untimed start of a series goes out timed, beside its UTC rule`() {
val start = Instant.parse("2025-08-01T22:00:00Z")
val lines = linesOf(
write(task(start = start, due = noon, untimed = TaskEnd.START, timeZone = "Europe/Berlin", rrule = "FREQ=DAILY;UNTIL=20250901T215959Z")),
)
assertThat(lines).contains("DTSTART:20250801T220000Z")
}
@Test
fun `an exported untimed end reads back as one, on its date`() {
val start = Instant.parse("2025-08-01T22:00:00Z")
val ics = write(task(uid = "u-1", start = start, due = noon, untimed = TaskEnd.START, timeZone = "Europe/Berlin"))
val todo = de.jeanlucmakiola.agendula.domain.ical.ICalParser.parse(ics).components.single { it.name == "VTODO" }
val read = de.jeanlucmakiola.agendula.data.tasks.ical.VTodoMapper.read(todo).entity
assertThat(read.untimed).isEqualTo(TaskEnd.START)
assertThat(read.dtstart!!.untimedDate(read.timezone)).isEqualTo(LocalDate.of(2025, 8, 2))
}
@Test
fun `completion is always a UTC date-time even when all-day`() {
val lines = linesOf(
@@ -0,0 +1,87 @@
package de.jeanlucmakiola.agendula.ui.edit
import com.google.common.truth.Truth.assertThat
import java.time.LocalDate
import java.time.LocalTime
import org.junit.jupiter.api.Test
class QuickPicksTest {
private val today = LocalDate.of(2026, 12, 28)
@Test
fun `quick dates resolve relative to today across a year boundary`() {
assertThat(QuickDate.Today.resolve(today)).isEqualTo(today)
assertThat(QuickDate.Tomorrow.resolve(today)).isEqualTo(LocalDate.of(2026, 12, 29))
assertThat(QuickDate.NextWeek.resolve(today)).isEqualTo(LocalDate.of(2027, 1, 4))
}
@Test
fun `a date maps back to its quick date or to none`() {
assertThat(QuickDate.of(today, today)).isEqualTo(QuickDate.Today)
assertThat(QuickDate.of(LocalDate.of(2027, 1, 4), today)).isEqualTo(QuickDate.NextWeek)
assertThat(QuickDate.of(LocalDate.of(2026, 12, 30), today)).isNull()
assertThat(QuickDate.of(today.minusDays(1), today)).isNull()
}
@Test
fun `a time maps to its preset only on an exact match`() {
assertThat(QuickTime.of(LocalTime.of(8, 0))).isEqualTo(QuickTime.Morning)
assertThat(QuickTime.of(LocalTime.of(20, 0))).isEqualTo(QuickTime.Evening)
assertThat(QuickTime.of(LocalTime.of(8, 1))).isNull()
assertThat(QuickTime.of(LocalTime.of(8, 0, 30, 500))).isEqualTo(QuickTime.Morning)
}
@Test
fun `the default time is the next full hour today and the morning on another day`() {
assertThat(defaultPickerTime(today, today.atTime(9, 41))).isEqualTo(LocalTime.of(10, 0))
assertThat(defaultPickerTime(today, today.atTime(0, 0))).isEqualTo(LocalTime.of(1, 0))
assertThat(defaultPickerTime(today, today.atTime(23, 10))).isEqualTo(LocalTime.of(23, 59))
assertThat(defaultPickerTime(today.plusDays(1), today.atTime(23, 10))).isEqualTo(LocalTime.of(8, 0))
}
@Test
fun `a time without a date lands on the first day it is still ahead`() {
val now = today.atTime(16, 30)
assertThat(defaultPickerDate(LocalTime.of(20, 0), now)).isEqualTo(today)
assertThat(defaultPickerDate(LocalTime.of(16, 30), now)).isEqualTo(today)
assertThat(defaultPickerDate(LocalTime.of(8, 0), now)).isEqualTo(LocalDate.of(2026, 12, 29))
assertThat(defaultPickerDate(LocalTime.of(8, 0), today.atTime(23, 0))).isEqualTo(LocalDate.of(2026, 12, 29))
}
@Test
fun `a time without a date does not land before the floor`() {
val now = today.atTime(16, 30)
val start = LocalDate.of(2027, 1, 4).atTime(9, 0)
assertThat(defaultPickerDate(LocalTime.of(20, 0), now, start)).isEqualTo(LocalDate.of(2027, 1, 4))
assertThat(defaultPickerDate(LocalTime.of(8, 0), now, start)).isEqualTo(LocalDate.of(2027, 1, 5))
assertThat(defaultPickerDate(LocalTime.of(20, 0), now, today.minusDays(3).atTime(9, 0))).isEqualTo(today)
}
@Test
fun `the default time keeps after the floor and before the ceiling`() {
val now = today.atTime(16, 30)
val start = LocalDate.of(2027, 1, 4).atTime(9, 0)
assertThat(defaultPickerTime(start.toLocalDate(), now, floor = start)).isEqualTo(LocalTime.of(10, 0))
assertThat(defaultPickerTime(today.plusDays(1), now, floor = start)).isEqualTo(LocalTime.of(8, 0))
val due = today.atTime(16, 45)
assertThat(defaultPickerTime(today, now, ceiling = due)).isEqualTo(LocalTime.of(16, 45))
}
@Test
fun `a time without a date does not land after the ceiling`() {
val now = today.atTime(16, 30)
val due = today.atTime(10, 0)
assertThat(defaultPickerDate(LocalTime.of(8, 0), now, ceiling = due)).isEqualTo(today)
assertThat(defaultPickerDate(LocalTime.of(12, 0), now, ceiling = due)).isEqualTo(today.minusDays(1))
assertThat(defaultPickerDate(LocalTime.of(20, 0), now, ceiling = today.plusDays(3).atTime(9, 0))).isEqualTo(today)
}
@Test
fun `no time without a date lands on today, or the nearest day the other end allows`() {
assertThat(defaultNoTimeDate(today)).isEqualTo(today)
assertThat(defaultNoTimeDate(today, floor = today.plusDays(2).atTime(9, 0))).isEqualTo(today.plusDays(2))
assertThat(defaultNoTimeDate(today, ceiling = today.minusDays(1).atTime(9, 0))).isEqualTo(today.minusDays(1))
assertThat(defaultNoTimeDate(today, floor = today.minusDays(3).atTime(9, 0))).isEqualTo(today)
}
}
@@ -11,17 +11,21 @@ import de.jeanlucmakiola.agendula.data.tasks.TasksRepository
import de.jeanlucmakiola.agendula.domain.Priority
import de.jeanlucmakiola.agendula.domain.Task
import de.jeanlucmakiola.agendula.domain.TaskDetail
import de.jeanlucmakiola.agendula.domain.TaskEnd
import de.jeanlucmakiola.agendula.domain.TaskFilter
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.domain.recurrence.RecurringScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.test.UnconfinedTestDispatcher
import kotlinx.coroutines.test.resetMain
import kotlinx.coroutines.test.setMain
@@ -29,6 +33,8 @@ import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import java.lang.reflect.Proxy
import java.time.LocalDate
import java.time.LocalTime
import kotlin.time.Clock
import kotlin.time.Duration.Companion.days
import kotlin.time.Instant
@@ -68,11 +74,10 @@ class TaskEditViewModelTest {
}
@Test
fun `untouched reminders survive an all-day switch while the task has no date`() {
fun `untouched reminders survive the task coming back all-day`() {
val vm = editing(reminders = listOf(TaskReminder(0)))
vm.onDueChange(null)
vm.onAllDayChange(true)
vm.onDueChange(due)
vm.onWhenChange(TaskEnd.DUE, LocalDate.now().plusDays(3), null)
assertThat(vm.state.value.reminders).isNotEmpty()
assertThat(vm.state.value.reminders.all { it.allDay.minuteOfDay != null || it.minutesBefore % (24 * 60) == 0 })
@@ -104,10 +109,9 @@ class TaskEditViewModelTest {
}
@Test
fun `an all-day switch or another list does not bring them back`() {
fun `another list does not bring them back`() {
val vm = editing()
vm.onDueChange(null)
vm.onAllDayChange(true)
vm.onListChange(LIST_ID + 1)
assertThat(vm.state.value.reminders).isEmpty()
@@ -141,6 +145,128 @@ class TaskEditViewModelTest {
assertThat(vm.state.value.reminders).containsExactly(reminder)
}
@Test
fun `no time on the due of a timed task leaves the start's time alone (#101)`() {
val vm = editing(start = due - 1.days)
val day = LocalDate.now().plusDays(3)
vm.onWhenChange(TaskEnd.DUE, day, null)
val state = vm.state.value
assertThat(state.isAllDay).isFalse()
assertThat(state.untimed).isEqualTo(TaskEnd.DUE)
assertThat(state.start).isEqualTo(due - 1.days)
assertThat(state.due).isEqualTo(untimedInstantOf(TaskEnd.DUE, day))
assertThat(state.reminders).containsExactly(reminder)
vm.save()
assertThat(repository.saved?.untimed).isEqualTo(TaskEnd.DUE)
assertThat(repository.saved?.isAllDay).isFalse()
}
@Test
fun `no time on both ends makes the task all-day`() {
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)
val state = vm.state.value
assertThat(state.isAllDay).isTrue()
assertThat(state.untimed).isNull()
assertThat(state.start).isEqualTo(allDayInstantOf(day.minusDays(1)))
assertThat(state.due).isEqualTo(allDayInstantOf(day))
}
@Test
fun `a time on one end of an all-day task leaves the other end without one`() {
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.START, day.minusDays(1), LocalTime.of(9, 0))
val state = vm.state.value
assertThat(state.isAllDay).isFalse()
assertThat(state.untimed).isEqualTo(TaskEnd.DUE)
assertThat(state.due).isEqualTo(untimedInstantOf(TaskEnd.DUE, day))
assertThat(state.hasTime(TaskEnd.START)).isTrue()
}
@Test
fun `a time on the untimed end gives the task both times back`() {
val vm = editing(start = due - 1.days)
val day = LocalDate.now().plusDays(3)
vm.onWhenChange(TaskEnd.DUE, day, null)
vm.onWhenChange(TaskEnd.DUE, day, LocalTime.of(17, 0))
assertThat(vm.state.value.untimed).isNull()
assertThat(vm.state.value.isAllDay).isFalse()
}
@Test
fun `a store without untimed ends drops both times together`() {
repository.untimedEnds = false
val vm = editing(start = due - 1.days)
val day = LocalDate.now().plusDays(3)
vm.onWhenChange(TaskEnd.DUE, day, null)
assertThat(vm.state.value.isAllDay).isTrue()
assertThat(vm.state.value.untimed).isNull()
}
@Test
fun `clearing the timed end leaves the other one all-day`() {
val vm = editing(start = due - 1.days)
val day = LocalDate.now().plusDays(3)
vm.onWhenChange(TaskEnd.DUE, day, null)
vm.onStartChange(null)
val state = vm.state.value
assertThat(state.isAllDay).isTrue()
assertThat(state.untimed).isNull()
assertThat(state.due).isEqualTo(allDayInstantOf(day))
}
@Test
fun `a new task's untouched start goes all-day with a due picked without a time`() {
val prefs = settingsPrefs().apply { runBlocking { setDefaultStartToday(true) } }
val vm = TaskEditViewModel(repository, prefs).apply { bindNew() }
val day = LocalDate.now().plusDays(2)
vm.onWhenChange(TaskEnd.DUE, day, null)
assertThat(vm.state.value.isAllDay).isTrue()
assertThat(vm.state.value.start).isEqualTo(allDayInstantOf(LocalDate.now()))
}
@Test
fun `a start the user picked keeps its time beside a due without one`() {
val prefs = settingsPrefs().apply { runBlocking { setDefaultStartToday(true) } }
val vm = TaskEditViewModel(repository, prefs).apply { bindNew() }
vm.onWhenChange(TaskEnd.START, LocalDate.now(), LocalTime.of(9, 0))
vm.onWhenChange(TaskEnd.DUE, LocalDate.now().plusDays(2), null)
assertThat(vm.state.value.untimed).isEqualTo(TaskEnd.DUE)
}
@Test
fun `an untimed end from another zone opens on its own date`() {
val berlinDue = untimedInstantOf(TaskEnd.DUE, LocalDate.of(2026, 11, 20), java.time.ZoneId.of("Pacific/Kiritimati"))
repository.task = task(due - 1.days, berlinDue).copy(untimed = TaskEnd.DUE, timeZone = "Pacific/Kiritimati")
repository.reminders = emptyList()
val vm = TaskEditViewModel(repository, settingsPrefs()).apply { bindEdit(TASK_ID) }
assertThat(vm.state.value.due).isEqualTo(untimedInstantOf(TaskEnd.DUE, LocalDate.of(2026, 11, 20)))
assertThat(vm.state.value.isDirty).isFalse()
}
@Test
fun `clearing the untimed end drops its mark`() {
val vm = editing(start = due - 1.days)
vm.onWhenChange(TaskEnd.DUE, LocalDate.now().plusDays(3), null)
vm.onDueChange(null)
assertThat(vm.state.value.untimed).isNull()
}
@Test
fun `a task stored without dates opens without its reminders`() {
val vm = editing(due = null)
@@ -223,6 +349,9 @@ class TaskEditViewModelTest {
var task: Task? = null
var reminders: List<TaskReminder> = emptyList()
var saved: TaskForm? = null
var untimedEnds = true
override fun supportsUntimedEnds() = untimedEnds
override fun supportsRepeatFromCompletion() = true
override fun taskLists() = flowOf(emptyList<TaskList>())