Fix timezone placement in add_missing_timezones()#878
Merged
niccokunzmann merged 11 commits intoJul 17, 2025
Merged
Conversation
Modify Calendar.add_missing_timezones() to insert VTIMEZONE components at the beginning of the calendar instead of appending them to the end. This ensures VTIMEZONE components appear before VEVENT and other components that reference them, following standard iCalendar practices. The fix preserves existing timezone components and inserts new ones immediately after any existing VTIMEZONE components. Fixes #844
Add test_issue_844_timezone_placement.py with comprehensive test coverage for the timezone placement fix, including: - Single and multiple timezone scenarios - Existing timezone preservation - Edge cases (empty calendar, no missing timezones) - Serialized output validation - Forward reference compatibility These tests ensure the fix works correctly and doesn't break existing functionality.
- Add entry to CHANGES.rst for issue #844 fix - Add contributor to docs/credits.rst
5 tasks
Test timezone placement functionality in environments where pytz is not available by temporarily mocking pytz module to raise ImportError.
Use try/except import to handle zoneinfo vs backports.zoneinfo for Python < 3.9 compatibility.
Replace custom try/except import with the official icalendar.compatibility module for consistent Python version compatibility across the codebase.
Pull Request Test Coverage Report for Build 16340146346Details
💛 - Coveralls |
stevepiercy
requested changes
Jul 16, 2025
stevepiercy
left a comment
Member
There was a problem hiding this comment.
Minor formatting for change log. Still needs a technical review.
I'd suggest running tox -e ruff to lint the Python files.
https://github.com/collective/icalendar/blob/main/tox.ini#L44
We should also add that to the Contributing guide and as a CI check. @niccokunzmann what do you think?
- Format method name add_missing_timezones() with backticks - Format component names VTIMEZONE, VEVENT with backticks - Run tox -e ruff as requested for code quality
stevepiercy
approved these changes
Jul 17, 2025
stevepiercy
left a comment
Member
There was a problem hiding this comment.
This still needs a technical review. docstrings and news look good.
niccokunzmann
approved these changes
Jul 17, 2025
niccokunzmann
left a comment
Member
There was a problem hiding this comment.
Thank you very much for this thorough work!
Member
|
@stevepiercy, I think this is good to discuss in the issue #672. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #844 by modifying Calendar.add_missing_timezones() to insert VTIMEZONE components at the beginning of the calendar instead of appending them to the end.
Problem
The add_missing_timezones() method was placing VTIMEZONE components after VEVENT and other components that reference them. This violates standard iCalendar practices where VTIMEZONE components should appear before components that reference them.
Solution
Changes
Test Coverage
📚 Documentation preview 📚: https://icalendar--878.org.readthedocs.build/