Skip to content

Commit 9828e7a

Browse files
committed
Merge PR 808: fix: advance a fixed-time task completed early
#808 A task with a fixed-time RRULE that was completed before its DTSTART got the same occurrence back and did not move; it now advances to the next occurrence. Also a TODO note on all-day fixed-time tasks. Commits: - 513fc89 fix: advance a fixed-time task completed early - 136ebea docs: TODO: all-day fixed-time task completion Fixes #782 Assisted-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Reviewed-by: Tobias Brox <tobias@redpill-linpro.com>
2 parents 3c4b2c4 + 136ebea commit 9828e7a

4 files changed

Lines changed: 52 additions & 0 deletions

File tree

‎caldav/calendarobjectresource.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2652,6 +2652,10 @@ def _next(self, ts=None, i=None, dtstart=None, rrule=None, by=None, no_count=Tru
26522652
dtstart = dtstart.astimezone(timezone.utc)
26532653
if not ts:
26542654
ts = dtstart
2655+
elif isinstance(ts, datetime) and isinstance(dtstart, datetime) and ts < dtstart:
2656+
## Completed before DTSTART (case 1A): the occurrence at
2657+
## DTSTART is the one done, so look past it (issue #782)
2658+
ts = dtstart
26552659
## Counting is taken care of other places
26562660
if no_count and "COUNT" in rrule:
26572661
rrule = rrule.copy()

‎changes/782.fixed.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
`complete(handle_rrule=True)` on a recurring task with fixed times (`BY*` parts in the `RRULE`, e.g. `FREQ=YEARLY;BYMONTH=4,9`) did not advance the task when it was completed before its `DTSTART`: the next occurrence was looked for after the completion time, which found the occurrence just completed. It is now looked for after `DTSTART`.

‎docs/design/TODO.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
`search()` decides the `!=` / `<>`, `!contains` and `def` operators client-side and leaves them out of the server query (https://github.com/python-caldav/caldav/issues/568). A caldav-server-tester probe for `negate-condition` support, and the compatibility_hints flag it would feed, would let `search()` send `!contains` as a negated `text-match` to the servers that honour it.
66

7+
## Completing an all-day fixed-time recurring task
8+
9+
`Todo._next()` in `caldav/calendarobjectresource.py` raises `TypeError` (naive vs aware) for a task with `DTSTART;VALUE=DATE` and `BY*` parts in its `RRULE`: dateutil turns the date into a naive datetime and compares it with the UTC completion timestamp, so `complete(handle_rrule=True)` fails for such tasks. Fix: convert a date DTSTART to an aware datetime (or the timestamp to a date) before both the comparison and `rrulestr()`, with a unit test. Found in the review of the fix for https://github.com/python-caldav/caldav/issues/782.
10+
711
## Calendar cleanup in integration tests
812

913
For servers where calendars cannot be created, the test will take the first available calendar it finds and wipe it. That is not acceptable without the user explicitly configuring that this is OK.

‎tests/test_caldav_unit.py‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6002,6 +6002,49 @@ def test_build_safe_completed_count_one_skips_next(self) -> None:
60026002
)
60036003
assert todo.icalendar_component["RRULE"]["COUNT"] == [1]
60046004

6005+
## Issue https://github.com/python-caldav/caldav/issues/782: a
6006+
## fixed-time task (BY* in the RRULE) done before its DTSTART
6007+
EARLY = todo6.replace("RRULE:FREQ=YEARLY", "RRULE:FREQ=YEARLY;BYMONTH=4,9")
6008+
6009+
def test_next_fixed_time_completed_early(self) -> None:
6010+
todo = self._make_todo(self.EARLY)
6011+
## done two days before the 1992-04-15 13:30 occurrence
6012+
early = datetime(1992, 4, 13, 10, tzinfo=timezone.utc)
6013+
assert todo._next(early) == datetime(1992, 9, 15, 13, 30, tzinfo=timezone.utc)
6014+
## done after DTSTART: unchanged
6015+
late = datetime(1992, 4, 16, 10, tzinfo=timezone.utc)
6016+
assert todo._next(late) == datetime(1992, 9, 15, 13, 30, tzinfo=timezone.utc)
6017+
6018+
def test_next_floating_fixed_time_completed_early(self) -> None:
6019+
"""A floating DTSTART is taken as local time before the comparison."""
6020+
todo = self._make_todo(
6021+
self.EARLY.replace("DTSTART:19920415T133000Z", "DTSTART:19920415T133000").replace(
6022+
"DUE:19920516T045959Z", "DUE:19920516T045959"
6023+
)
6024+
)
6025+
dtstart = datetime(1992, 4, 15, 13, 30).astimezone(timezone.utc)
6026+
assert todo._next(dtstart - timedelta(days=2)) == datetime(1992, 9, 15, 13, 30).astimezone(
6027+
timezone.utc
6028+
)
6029+
6030+
def test_safe_completion_completed_early_advances(self) -> None:
6031+
todo = self._make_todo(self.EARLY)
6032+
completed = todo._build_recurring_safe_completed(
6033+
datetime(1992, 4, 13, 10, tzinfo=timezone.utc)
6034+
)
6035+
assert completed is not None
6036+
assert todo.icalendar_component["DTSTART"].dt == datetime(
6037+
1992, 9, 15, 13, 30, tzinfo=timezone.utc
6038+
)
6039+
6040+
def test_thisandfuture_completed_early_advances(self) -> None:
6041+
todo = self._make_todo(self.EARLY)
6042+
todo._prepare_recurring_thisandfuture(datetime(1992, 4, 13, 10, tzinfo=timezone.utc))
6043+
thisandfuture = todo.icalendar_instance.subcomponents[-1]
6044+
nxt = datetime(1992, 9, 15, 13, 30, tzinfo=timezone.utc)
6045+
assert thisandfuture["RECURRENCE-ID"].dt == nxt
6046+
assert thisandfuture["DTSTART"].dt == nxt
6047+
60056048
def test_safe_completion_issues_two_puts(self, monkeypatch: Any) -> None:
60066049
"""The standalone completed copy must not be PUT twice.
60076050

0 commit comments

Comments
 (0)