Skip to content

Preserve TZID when parsing jCal TIME properties - #2155

Open
shrohan2003 wants to merge 1 commit into
PyCalendar:mainfrom
shrohan2003:fix/jcal-time-tzid
Open

shrohan2003 wants to merge 1 commit into
PyCalendar:mainfrom
shrohan2003:fix/jcal-time-tzid

Conversation

@shrohan2003

Copy link
Copy Markdown

Linked issue

Closes #2154

Description

Parsing a jCal TIME with TZID=Asia/Dhaka currently produces a naive time and removes the timezone parameter. Re-serializing an event consequently changes a zoned time into a floating time. Apply the TZID before constructing vTime, following the existing vDatetime.from_jcal() approach.

Regression tests cover property and Event round trips with both pytz and zoneinfo, preserve the input, and check UTC and floating times. Four timezone cases fail before the fix. The full suite passes with 22,425 passed, 43 skipped, and 577 xfailed on Python 3.13.18. Ruff lint and format checks pass.

Checklist

  • I added a change log entry, following the instructions in all subsections under Change log requirements.
  • I followed icalendar's Artificial intelligence policy and disclosed my Responsible AI use in my commit messages, if applicable.
  • I added or updated tests, if applicable.
  • I ran and ensured all tests pass locally by following Run tests.
  • I added or edited documentation as necessary, both as docstrings to be rendered in the API documentation and narrative documentation, following the Style guide.

Localize the parsed time before constructing vTime so its constructor
retains the supplied TZID. Cover direct property and Event round trips
with pytz and zoneinfo, along with UTC and floating times.

Codex (GPT-6) assisted with investigation, implementation, and testing.
The user requested additional verified open-source bug fixes and PRs.
Validation: four regression cases failed before the fix; the full suite
passes with 22425 passed, 43 skipped, and 577 xfailed. Ruff passes.
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for the pull request, @shrohan2003! A maintainer will review it shortly.

Comment thread news/2154.bugfix
@@ -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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
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.
Preserved the timezone when parsing jCal TIME properties, including when parsing components and serializing them. Codex (GPT-6) assisted with reproducing the issue, implementing the fix, and writing regression tests. :user:`shrohan2003`

Comment on lines 267 to +270
with JCalParsingError.reraise_with_path_added(3):
value = cls.parse_jcal_value(jcal_property[3])
if params.tzid:
value = tzp.localize(value, params.tzid)

@SemTiOne SemTiOne Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please reject TZID when the jCal TIME value ends in Z, as vTime.from_xcal() does. zoneinfo silently replaces UTC with the local timezone. Also add a regression test for both providers.

Suggested change
with JCalParsingError.reraise_with_path_added(3):
value = cls.parse_jcal_value(jcal_property[3])
if params.tzid:
value = tzp.localize(value, params.tzid)
with JCalParsingError.reraise_with_path_added(3):
value = cls.parse_jcal_value(jcal_property[3])
if params.tzid:
if is_utc(value):
raise JCalParsingError(
f"Cannot mix {params.tzid} with UTC", cls
)
value = tzp.localize(value, params.tzid)

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

jCal TIME parsing drops TZID and turns zoned times into floating times

2 participants