Skip to content

Implement full recurrence spec - #566

Closed
stutrek wants to merge 12 commits into
allenporter:mainfrom
stutrek:full-recurrence-spec
Closed

Implement full recurrence spec#566
stutrek wants to merge 12 commits into
allenporter:mainfrom
stutrek:full-recurrence-spec

Conversation

@stutrek

@stutrek stutrek commented Jan 26, 2026

Copy link
Copy Markdown
Contributor

Fixes #513
Builds on #565

My apologies for a large PR, but this is a big item that deserves extensive testing. This fully implements the ical spec for recurring events, in an almost completely backwards compatible way; JSON consumers may break. The code should be commented well enough to help you in your review.

This PR handles:

  • edits to a single event
  • edits to "this and all following events"
  • multiple instances of both
  • Time shifts (e.g., move 9am→2pm, all future instances shift +5 hours)
  • Duration changes
  • Property changes (summary, description, location)

Test coverage is 99%. The only cases not tested are very remote error cases.

Changes

ical/types/recur.py

  • RecurrenceId now parses and preserves the RANGE parameter
  • Added encoding methods for round-trip serialization

ical/recur_adapter.py

  • ThisAndFutureEdit - captures edit with computed time shift
  • ThisAndFutureRecurAdapter - applies modifications during timeline expansion
  • Updated merge_and_expand_items() to detect and apply THISANDFUTURE edits

Test coverage

  • THISANDFUTURE tests covering Events, Todos, Journals
  • Edge cases: timezone handling, multiple edits, single-override precedence, property inheritance
  • RFC spec examples
  • Helper functions
  • Coverage: 99% on recur_adapter.py, 98% on types/recur.py

Not implemented

  • SEQUENCE property validation, which ensures that recurrence id is the same as dtstart (per spec, but rarely enforced)
  • Value type matching validation (DATE vs DATE-TIME)

Performance

The worst I see is that it will run over every edit for every instance of the event. In the real world, this seems like it shouldn't be bad, as very few events will have more than 2 or 3 edits.

Disclaimer

AI did a lot of the heavy lifting, but check the commit list to see that it's not pure slop. I have read every line of code, although Python is not my strongest language. I have taken care to ensure that types are strong, the tests are complete and comply with the spec, and edge cases are handled correctly.

Comment thread ical/types/recur.py
@classmethod
def __encode_property_json__(
cls, value: "str | RecurrenceId"
) -> str | dict[str, str]:

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this may break JSON consumers that don't follow the same patterns as DateTimeEncoder, such as JavaScript.

@allenporter allenporter left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Appreciate the work here. Just wanted to ACK that I see this, and that it may take some time to review.

@codecov

codecov Bot commented Jan 26, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.60140% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 97.23%. Comparing base (1b747da) to head (392e9a6).
⚠️ Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
ical/recur_adapter.py 98.16% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #566      +/-   ##
==========================================
+ Coverage   97.15%   97.23%   +0.08%     
==========================================
  Files          53       53              
  Lines        3234     3366     +132     
==========================================
+ Hits         3142     3273     +131     
- Misses         92       93       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@stutrek

stutrek commented Feb 2, 2026

Copy link
Copy Markdown
Contributor Author

This is probably taken care of by #565 and it's unlikely that I will have the time to give it the energy it needs.

@stutrek stutrek closed this Feb 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants