Move a sub-task's end without a time by whole days when its routine moves on (#101)
This commit is contained in:
1 parent
4d833a4da6
commit
b77311dff7
3 files changed
+35
-3
No files matched your search
@@ -1,6 +1,7 @@
|
||||
package de.jeanlucmakiola.agendula.data.tasks
|
||||
|
||||
import de.jeanlucmakiola.agendula.data.tasks.TasksContract.Tasks
|
||||
import de.jeanlucmakiola.agendula.domain.TaskEnd
|
||||
import de.jeanlucmakiola.agendula.domain.TaskStatus
|
||||
import de.jeanlucmakiola.agendula.domain.isClosed
|
||||
import de.jeanlucmakiola.agendula.domain.recurrence.ExpansionWindow
|
||||
@@ -8,6 +9,8 @@ import de.jeanlucmakiola.agendula.domain.recurrence.RecurrenceExpander
|
||||
import de.jeanlucmakiola.agendula.domain.recurrence.RecurrenceSpec
|
||||
import de.jeanlucmakiola.agendula.domain.recurrence.dateZone
|
||||
import de.jeanlucmakiola.agendula.domain.statusFromInt
|
||||
import de.jeanlucmakiola.agendula.domain.untimedMoved
|
||||
import de.jeanlucmakiola.agendula.domain.zoneOr
|
||||
import java.time.Duration
|
||||
import java.time.LocalDateTime
|
||||
import java.time.ZoneId
|
||||
@@ -54,6 +57,8 @@ internal class SubtaskNode(
|
||||
val dates: SubtaskDates = SubtaskDates.NONE,
|
||||
val isAllDay: Boolean = false,
|
||||
val lastModified: Long? = null,
|
||||
val untimed: TaskEnd? = null,
|
||||
val timeZone: String? = null,
|
||||
)
|
||||
|
||||
/** A sub-task [SubtaskReset] reset: its state and dates before, and the dates the reset gave it. */
|
||||
@@ -90,6 +95,14 @@ internal class SeriesShift(from: Long, to: Long, seriesZone: ZoneId, private val
|
||||
return moved.atZone(zone).toInstant().toEpochMilli()
|
||||
}
|
||||
|
||||
/** An untimed [end] at [at], stored in [timeZone], moved by whole days: the series' change of date. */
|
||||
fun applyUntimed(end: TaskEnd, at: Long, timeZone: String?): Long =
|
||||
untimedMoved(end, Instant.fromEpochMilliseconds(at), days, timeZone, zoneOr(timeZone)).toEpochMilliseconds()
|
||||
|
||||
/** [at] on [end] of a sub-task moved along, by whole days where that end has no time. */
|
||||
fun apply(at: Long, end: TaskEnd, node: SubtaskNode): Long =
|
||||
if (!node.isAllDay && node.untimed == end) applyUntimed(end, at, node.timeZone) else apply(at, node.isAllDay)
|
||||
|
||||
private fun local(at: Long, zone: ZoneId) = LocalDateTime.ofInstant(java.time.Instant.ofEpochMilli(at), zone)
|
||||
|
||||
companion object {
|
||||
@@ -211,8 +224,8 @@ internal object SubtaskReset {
|
||||
val moves = shift != null && !it.dates.isEmpty
|
||||
if (it.state.status != TaskStatus.CANCELLED && !earlier && (started || moves)) {
|
||||
val dates = if (shift == null) it.dates else SubtaskDates(
|
||||
it.dates.start?.let { at -> shift.apply(at, it.isAllDay) },
|
||||
it.dates.due?.let { at -> shift.apply(at, it.isAllDay) },
|
||||
it.dates.start?.let { at -> shift.apply(at, TaskEnd.START, it) },
|
||||
it.dates.due?.let { at -> shift.apply(at, TaskEnd.DUE, it) },
|
||||
)
|
||||
reset += ResetSubtask(it.id, it.state, it.dates, dates)
|
||||
}
|
||||
|
||||
@@ -770,7 +770,10 @@ class RoomTasksDataSource @Inject constructor(
|
||||
tasks.subtasks(id).map { row ->
|
||||
val sub = row.task.also { loaded[it.id] = it }
|
||||
val copy = SubtaskReset.isCopyOf(SubtaskReset.markerParentFromResidue(sub.unknownProperties), parentUid)
|
||||
SubtaskNode(sub.id, sub.isRecurring || copy, sub.progress, sub.dates, sub.isAllDay, sub.lastModified?.toEpochMilliseconds())
|
||||
SubtaskNode(
|
||||
sub.id, sub.isRecurring || copy, sub.progress, sub.dates, sub.isAllDay,
|
||||
sub.lastModified?.toEpochMilliseconds(), sub.untimed, sub.timezone,
|
||||
)
|
||||
}
|
||||
}
|
||||
val lists = reset.mapNotNull { entry ->
|
||||
|
||||
@@ -2,6 +2,7 @@ package de.jeanlucmakiola.agendula.data.tasks
|
||||
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import de.jeanlucmakiola.agendula.data.tasks.TasksContract.Tasks
|
||||
import de.jeanlucmakiola.agendula.domain.TaskEnd
|
||||
import de.jeanlucmakiola.agendula.domain.TaskStatus
|
||||
import de.jeanlucmakiola.agendula.domain.recurrence.RecurrenceSpec
|
||||
import org.junit.jupiter.api.Test
|
||||
@@ -230,6 +231,21 @@ class SubtaskResetTest {
|
||||
assertThat(sameDay.apply(at("2026-11-10T00:00:00Z"), isAllDay = true)).isEqualTo(at("2026-11-10T00:00:00Z"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `an untimed sub-task end moves by whole days, not by the routine's clock change`() {
|
||||
// An eight-hourly routine moves from 20:00 to 04:00 the next day in Berlin: the untimed due goes to the next day's end.
|
||||
val hourly = SeriesShift(at("2026-11-09T19:00:00Z"), at("2026-11-10T03:00:00Z"), berlin)
|
||||
val node = SubtaskNode(2, false, done, SubtaskDates(null, at("2026-11-09T22:59:59Z")), untimed = TaskEnd.DUE, timeZone = "Europe/Berlin")
|
||||
val reset = SubtaskReset.toReset(1L, hourly) { if (it == 1L) listOf(node) else emptyList() }
|
||||
assertThat(reset.single().dates.due).isEqualTo(at("2026-11-10T22:59:59Z"))
|
||||
// A UTC routine a week on across the end of summer time: the Berlin date's last second, not an hour past it.
|
||||
val weekly = SeriesShift(at("2026-10-19T07:00:00Z"), at("2026-10-26T07:00:00Z"), ZoneOffset.UTC)
|
||||
val start = SubtaskNode(3, false, done, SubtaskDates(at("2026-10-19T22:00:00Z"), at("2026-10-20T12:00:00Z")), untimed = TaskEnd.START, timeZone = "Europe/Berlin")
|
||||
val moved = SubtaskReset.toReset(1L, weekly) { if (it == 1L) listOf(start) else emptyList() }.single().dates
|
||||
assertThat(moved.start).isEqualTo(at("2026-10-26T23:00:00Z"))
|
||||
assertThat(moved.due).isEqualTo(at("2026-10-27T12:00:00Z"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `moving on shifts dated sub-tasks, fresh ones included, and leaves undated fresh ones`() {
|
||||
val shift = SeriesShift(at("2026-11-02T08:00:00Z"), at("2026-11-09T08:00:00Z"), ZoneOffset.UTC)
|
||||
|
||||
Reference in new issue
Block a user