Repository navigation
Preserve TZID when parsing jCal TIME properties #2155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
shrohan2003
wants to merge
1
commit into
PyCalendar:main
Choose a base branch
from
shrohan2003:fix/jcal-time-tzid
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Preserve the timezone when parsing jCal TIME properties with a TZID, including through component parsing and serialization. Codex (GPT-6) assisted with reproduction, implementation, and regression tests. | ||
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
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -263,11 +263,14 @@ def from_jcal(cls, jcal_property: list) -> Self: | |||||||||||||||||||||||||
| ~icalendar.error.JCalParsingError: If the provided jCal is invalid. | ||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||
| JCalParsingError.validate_property(jcal_property, cls) | ||||||||||||||||||||||||||
| params = Parameters.from_jcal_property(jcal_property) | ||||||||||||||||||||||||||
| with JCalParsingError.reraise_with_path_added(3): | ||||||||||||||||||||||||||
| value = cls.parse_jcal_value(jcal_property[3]) | ||||||||||||||||||||||||||
| if params.tzid: | ||||||||||||||||||||||||||
| value = tzp.localize(value, params.tzid) | ||||||||||||||||||||||||||
|
Comment on lines
267
to
+270
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please reject
Suggested change
|
||||||||||||||||||||||||||
| return cls( | ||||||||||||||||||||||||||
| value, | ||||||||||||||||||||||||||
| params=Parameters.from_jcal_property(jcal_property), | ||||||||||||||||||||||||||
| params=params, | ||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| def to_xcal(self, element: Element) -> None: | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| """Preserve TIME timezones through the jCal component parsing entry point.""" | ||
|
|
||
| from copy import deepcopy | ||
| from datetime import time | ||
|
|
||
| import pytest | ||
|
|
||
| from icalendar import Event | ||
| from icalendar.prop import vTime | ||
| from icalendar.timezone.tzid import tzid_from_dt | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("zone", ["Asia/Dhaka", "Europe/Berlin", "UTC"]) | ||
| def test_jcal_time_retains_timezone(tzp, zone): | ||
| """Parsing and reserializing a TIME must preserve its timezone semantics.""" | ||
| expected = vTime(tzp.localize(time(8, 30), zone)) | ||
| property_jcal = expected.to_jcal("x-time") | ||
| original = deepcopy(property_jcal) | ||
|
|
||
| parsed = vTime.from_jcal(property_jcal) | ||
| assert tzid_from_dt(parsed.dt) == tzid_from_dt(expected.dt) | ||
| assert parsed.to_jcal("x-time") == property_jcal | ||
|
|
||
| event_jcal = ["vevent", [property_jcal], []] | ||
| event = Event.from_jcal(event_jcal) | ||
| assert tzid_from_dt(event["X-TIME"].dt) == tzid_from_dt(expected.dt) | ||
| assert event.to_jcal() == event_jcal | ||
| assert property_jcal == original | ||
|
|
||
|
|
||
| def test_jcal_floating_time_stays_floating(): | ||
| """A time without a TZID or UTC suffix remains floating.""" | ||
| property_jcal = ["x-time", {}, "time", "08:30:00"] | ||
| parsed = vTime.from_jcal(property_jcal) | ||
| assert parsed.dt == time(8, 30) | ||
| assert parsed.dt.tzinfo is None | ||
| assert parsed.to_jcal("x-time") == property_jcal |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.