Fix Todo.duration and Event.duration to return DURATION property when set (fixes #867)#880
Fix Todo.duration and Event.duration to return DURATION property when set (fixes #867)#880niccokunzmann merged 13 commits into
Conversation
Make Todo.duration return the DURATION property directly when set, rather than always trying to calculate from start and end. This allows todos with DURATION but no DTSTART to work correctly per RFC 5545. Fixes issue #867 where Todo.duration raised IncompleteComponent error when DTSTART was missing but DURATION property was set.
Apply same fix to Event.duration for consistency. When DURATION property is explicitly set, return it directly rather than calculating from start/end. Addresses issue #867 comment that the same issue affects Events.
Test all scenarios including: - Todo with DURATION but no DTSTART (original issue #867) - Event with DURATION property precedence - Backward compatibility with calculated duration - Edge cases and complex duration formats - Exact reproduction of caldav project failure
Modify test_incomplete_event to separate components with DURATION property from those without. Components with DURATION should return the property value, not raise IncompleteComponent error. This corrects the test expectation to match the fixed behavior.
Document the bug fix for Todo.duration and Event.duration in the Bug fixes section.
Pull Request Test Coverage Report for Build 16350280384Details
💛 - Coveralls |
- Consistent with review pattern from other PRs - No functional changes, only formatting improvements
|
Hi @SashankBhamidi, I'm so sorry, evidently the We should do reformatting of the entire codebase in a separate PR to keep your changes clean. Would you please revert the changes in the other files that have nothing to do with your original PR? Again, my apologies for the bad instructions. We definitely need to document this procedure. |
… feedback" This reverts commit ef7f85e.
This reverts commit 2cc6d82.
Format only the files that were modified for issue #867: - src/icalendar/cal/event.py - src/icalendar/cal/todo.py - src/icalendar/tests/test_issue_867_todo_duration_fix.py - src/icalendar/tests/test_issue_662_component_properties.py This addresses stevepiercy's feedback to format only touched files.
Thanks for the clarification! I've reverted the excessive ruff formatting and now only apply formatting to the files specifically modified for this feature. |
If you install the pre-commit, then this would be done on every commit automatically. |
niccokunzmann
left a comment
There was a problem hiding this comment.
@SashankBhamidi Thanks for all your contributions! Would you like to resolve the merge conflict?
This looks good from my side, too and should fix the issue.
Replace duplicate test methods with parametrized tests to reduce code duplication as suggested by niccokunzmann in review feedback.
|
@niccokunzmann Done! I've implemented the parametrized tests and resolved the merge conflicts. The duplicate Event/Todo test functions are now combined using |
|
Thank you very much! |
Summary
This PR fixes issue #867 where
Todo.durationraises anIncompleteComponenterror when theDURATIONproperty is set butDTSTARTis missing. The fix ensures that bothTodo.durationandEvent.durationreturn the explicitDURATIONproperty value when it exists, before falling back to calculated duration from start/end times.Changes Made
Todo.duration(src/icalendar/cal/todo.py:215-226): Now checks for explicitDURATIONproperty first, then falls back to calculated durationEvent.duration(src/icalendar/cal/event.py:305-316): Applied same fix for consistency across componentsProblem Solved
Before this fix,
Todo.durationwould always try to calculate duration fromDTSTARTandDUE/DTEND, causing anIncompleteComponenterror whenDTSTARTwas missing - even if an explicitDURATIONproperty was set. This violated RFC 5545 which allowsDURATIONto exist withoutDTSTARTfor todos.The caldav project was affected by this bug, as their tests expect
Todo.durationto work with explicitDURATIONproperties.RFC 5545 Compliance
This fix ensures proper RFC 5545 compliance:
DURATIONcan exist withoutDTSTART(as per RFC 5545)DURATIONproperty takes precedence over calculated durationTest Coverage
All existing tests pass, confirming no regressions.
Fixes #867
📚 Documentation preview 📚: https://icalendar--880.org.readthedocs.build/