Lower a rule's COUNT on a split even where lib-recur cannot read the rule (#79)

This commit is contained in:
makiolaj committed 2026-11-20 18:01:45 +01:00
1 parent bb7d36385f
commit 5a464a2212
2 files changed
+8 -2

No files matched your search

@@ -296,8 +296,10 @@ object TaskFormWriter {
}
}
/** [rrule]'s `COUNT`, or null without a readable one. */
fun countOf(rrule: String): Int? = RepeatFromCompletion.ruleOf(rrule)?.count
/** [rrule]'s `COUNT`, or null without a readable one; read off the text where lib-recur rejects the rule. */
fun countOf(rrule: String): Int? = runCatching { RepeatFromCompletion.ruleOf(rrule)?.count }.getOrNull()
?: rrule.split(';').firstOrNull { it.substringBefore('=').trim().equals("COUNT", ignoreCase = true) }
?.substringAfter('=')?.trim()?.toIntOrNull()
/** Cancelled, or back to needs-action; either way no longer complete. */
fun cancelled(current: TaskEntity, cancelled: Boolean, now: Instant): TaskEntity = current.copy(
@@ -5,6 +5,7 @@ import de.jeanlucmakiola.agendula.domain.TaskEnd
import de.jeanlucmakiola.agendula.domain.TaskForm
import de.jeanlucmakiola.agendula.domain.untimedInstantOf
import java.time.LocalDate
import de.jeanlucmakiola.agendula.domain.recurrence.RepeatFromCompletion
import org.junit.jupiter.api.Test
import kotlin.time.Duration.Companion.days
import kotlin.time.Duration.Companion.hours
@@ -46,6 +47,9 @@ class TaskFormWriterSeriesTest {
fun `the continuing series only counts what is left`() {
assertThat(TaskFormWriter.remainingCount("FREQ=DAILY;COUNT=30", 10)).isEqualTo("FREQ=DAILY;COUNT=20")
assertThat(TaskFormWriter.remainingCount("FREQ=WEEKLY", 10)).isEqualTo("FREQ=WEEKLY")
// lib-recur rejects a FREQ it does not know, and the COUNT still goes down.
assertThat(RepeatFromCompletion.ruleOf("FREQ=FORTNIGHTLY;COUNT=30")).isNull()
assertThat(TaskFormWriter.remainingCount("FREQ=FORTNIGHTLY;COUNT=30", 10)).isEqualTo("FREQ=FORTNIGHTLY;COUNT=20")
}
@Test