Count rung reminders before a save as the planner does (#178)
This commit is contained in:
1 parent
1787580a48
commit
42c1df84bd
2 files changed
+6
-6
No files matched your search
@@ -371,12 +371,10 @@ class TasksRepositoryImpl @Inject constructor(
|
||||
return logFailure("Reading the reminders before a save failed") {
|
||||
val own = dataSource.reminders(current.taskId)
|
||||
val now = Clock.System.now().toEpochMilliseconds()
|
||||
val all = ReminderPlanner.triggers(current, own, settings, ZoneId.systemDefault(), sinceCreated = false)
|
||||
// As triggers() counts them: a default before the task was created never rang.
|
||||
val created = current.created?.toEpochMilliseconds()
|
||||
val counted = if (own == null && created != null) all.filter { it.triggerAt >= created } else all
|
||||
if (counted.any { it.triggerAt <= now }) return null
|
||||
all
|
||||
val zone = ZoneId.systemDefault()
|
||||
// Those the planner arms count as rung; not a default from before the task, nor one from a start of now.
|
||||
if (ReminderPlanner.triggers(current, own, settings, zone).any { it.triggerAt <= now }) return null
|
||||
ReminderPlanner.triggers(current, own, settings, zone, sinceCreated = false)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -439,6 +439,8 @@ class ReminderPlannerTest {
|
||||
|
||||
assertThat(ReminderPlanner.plan(listOf(task), emptyMap(), Settings(), now, berlin)).isEmpty()
|
||||
assertThat(ReminderPlanner.plan(listOf(task), mapOf(13L to atStart), Settings(), now, berlin)).isEmpty()
|
||||
assertThat(ReminderPlanner.triggers(task, atStart, Settings(), berlin, sinceCreated = false))
|
||||
.containsExactly(ScheduledReminder(13, start.toEpochMilliseconds()))
|
||||
val nextDay = task.copy(start = Instant.fromEpochMilliseconds(start.toEpochMilliseconds() + 86_400_000))
|
||||
assertThat(ReminderPlanner.plan(listOf(nextDay), mapOf(13L to atStart), Settings(), now, berlin))
|
||||
.containsExactly(ScheduledReminder(13, nextDay.start!!.toEpochMilliseconds()))
|
||||
|
||||
Reference in new issue
Block a user