Skip to content

Fix/start end duration mismatch - #1835

Open
aspire488 wants to merge 24 commits into
PyCalendar:mainfrom
aspire488:fix/start-end-duration-mismatch
Open

aspire488 wants to merge 24 commits into
PyCalendar:mainfrom
aspire488:fix/start-end-duration-mismatch

Conversation

@aspire488

@aspire488 aspire488 commented Sep 25, 2026 •

Copy link
Copy Markdown

Linked issue

Description

When a VEVENT contains both DTEND and DURATION, the current validation rejects the component before callers can resolve its effective end time.

This change keeps the explicit DURATION as the effective duration when both properties are present. The existing end-property fallback then derives the effective end from DTSTART + DURATION.

Added regression coverage for a VEVENT containing both DTEND and DURATION.

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.

Additional information

Responsible AI disclosure: AI assistance was used to help inspect the existing code, draft the implementation, and draft the regression test. The resulting changes were reviewed against the reported issue and existing implementation before submission.

Closing Criteria

  • fix the errors
  • mark a breaking change
  • Also consider which behaviour to have in VTODO and fix that
  • update the upgrade guide on how to check if all are present (DTSTART, DTEND, DURATION for event, also checking for VTODO inconsistency) or validate()
  • Add a test for that inconsistency to [validate()] of the respective components
  • Make sure that validate() also validates subcomponents
  • use the example from above and the real one from Cleansing of corrupted icalendar data icalendar_compatibility#3 (comment)

@github-actions github-actions Bot added the ai-suspicion This contribution is possibly created with lots of AI help without enough human understanding. label Sep 25, 2026
@github-actions

Copy link
Copy Markdown
Contributor

This pull request did not pass quality checks and AI use is suspected. Please review Contribute and make any necessary amendments.

@github-actions

Copy link
Copy Markdown
Contributor

Profile summary:

GitHub user: aspire488
🟢 No concerns found with user's profile.
🟢 No concerns found with recent PR activity.
🟢 No concerns found with recent issue activity.

For a more detailed report, run `gh-profiler aspire488`.
Full profile
GitHub user: aspire488
🟢 No concerns found with user's profile.
   🟢 Account age: 1 year, 4 months
   🟢 Profile information:
        name: Joel 
        email: joeljigo3@gmail.com
        bio: CSE Student building AI systems, developer tools & automation — learning by shipping.
      Empty fields: company, blog, location

🟢 No concerns found with recent PR activity.
   62 PRs opened in the last 21 days.
      31 opened against repos the user owns.
      0 opened against repos in publicly associated orgs.
      31 opened against external repos.

   🟢 6 of 31 external PRs closed without merging in the last 21 days.

🟢 No concerns found with recent issue activity.
   13 new issues opened in the last 21 days.
      12 opened in repos the user owns.
      0 opened in repos in publicly associated orgs.
      1 opened in external repos.

   🟢 1 external issues closed as NOT_PLANNED.
   🟢 0 external issues opened with the same title.

@read-the-docs-community

read-the-docs-community Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

Documentation build overview

📚 icalendar | 🛠️ Build #34918537 | 📁 Comparing 2d85e6e against latest (a16ffc0)

  🔍 Preview build  

3 files changed
± _modules/icalendar/attr.html
± reference/api/icalendar.prop.broken.html
± reference/api/icalendar.prop.unknown.html

@angatha

angatha commented Oct 1, 2026

Copy link
Copy Markdown
Collaborator

Can you please address the test failures?

Comment thread news/1796.bugfix Resolved
Comment thread src/icalendar/attr.py Outdated
Comment on lines +1776 to +1778
# contain both. Prefer the explicit DURATION because it is the
# unambiguous duration representation and lets callers still read the
# component rather than failing the entire lookup.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This explanation is not more than an opinion. You can include the explanation given in #1796

@aspire488

Copy link
Copy Markdown
Author

Addressed the latest feedback.
Added @aspire488 attribution to the changelog entry.
Updated the DTEND + DURATION handling: matching end times are accepted with DURATION as the effective value; conflicting end times still raise InvalidCalendar because they are ambiguous.
Added regression coverage for both matching and conflicting cases.
Preserved the existing date/DURATION validation behavior.
Latest commit: d15c467
Thanks for the clarification on #1796

@niccokunzmann niccokunzmann left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@aspire488 Thanks for the PR! This is indeed a contribution as it works around one special case. Although it does not address the issue, this is worth merging.

Could you reword "Closes" to "Contributes to".

I would say, we can merge this and open another PR that addresses the issue.

Comment on lines +298 to +299
# If DTEND and DURATION describe different end times, the
# calendar is ambiguous and validation must still fail.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
# If DTEND and DURATION describe different end times, the
# calendar is ambiguous and validation must still fail.
def test_duration_and_end_do_not_match(self):
"""If DTEND and DURATION describe different end times, the
calendar is ambiguous and validation must still fail.
See https://github.com/collective/icalendar/issues/1796
"""

@coveralls-official

coveralls-official Bot commented Oct 3, 2026 •

Copy link
Copy Markdown

Coverage Status

coverage: 97.823% (+0.03%) from 97.796% — aspire488:fix/start-end-duration-mismatch into collective:main

@niccokunzmann

niccokunzmann commented Oct 28, 2026 •

Copy link
Copy Markdown
Member

@aspire488 Is this ready for another review?

There are merge conflicts, could you merge main?

@aspire488

Copy link
Copy Markdown
Author

Thanks for the review! I'll merge the latest "main" into my branch, resolve the conflicts, and verify the tests before requesting another review. I'll also ensure the outstanding review feedback is addressed.

@aspire488
aspire488 force-pushed the fix/start-end-duration-mismatch branch from 2d85e6e to fdc741d Compare November 1, 2026 13:44
Comment thread news/1796.bugfix Resolved
aspire488 and others added 2 commits November 5, 2026 13:47
AI: OpenAI GPT-6. Used to inspect the project guidance, refine the changelog wording, and prepare the single-line entry and regression-change summary.

@niccokunzmann niccokunzmann left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you! This is almost ready - I found a bug here that is hard to find. Please address this. It seems ready to merge

Comment thread src/icalendar/attr/__init__.py Outdated
f"may be in a {component_name}, not both."
)
raise InvalidCalendar(msg)
if start is not None and end != start + duration:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
if start is not None and end != start + duration:
if start is not None and end != normalize_pytz(start + duration):

Hi, this is something hard to catch be we need to be consistent in style: Every operation requires this, so that pytz does work with icalendar.

@angatha have a look - this is something to keep in mind.
pytz was introduced before Python queried the timezone offset using the date-time. So, the timezones from pytz are static and need to be normalized after each calculation to ensure that a timezone transition takes place. This only affects dt that span across a timezone boundary.

@niccokunzmann

Copy link
Copy Markdown
Member

I changed it to "contributes to" because it does not fully close the issue.

aspire488 and others added 4 commits November 19, 2026 22:15
Applies the reviewer's suggestion: mismatching end times are ambiguous,
so validation must fail rather than prefer DURATION.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@aspire488

Copy link
Copy Markdown
Author

Addressed the two open points:

  1. src/icalendar/attr/__init__.py — the rationale is rewritten from [Bug] Solve start/end/duration mismatch #1796 instead of asserting one. It now states the RFC 5545 §3.6.1 rule (DTEND and DURATION must not both be present), then [Bug] Solve start/end/duration mismatch #1796's request to read such calendars as best we can rather than rejecting them outright, and why a contradiction is still refused: the component says nothing about which end was meant, so returning either would be picking one at random.
  2. The comparison now reads elif end != normalize_pytz(start + duration): inline, as suggested in review, so the pytz normalisation sits at the point of comparison.

The mismatched-end case still raises InvalidCalendar, matching the test docstring requested in review.

Verification:

  • 27 passed in test_consolidation_attr_functions.py
  • full src/icalendar/tests: the same 10 failures exist on main in my environment (test_rfc_6868.py LazyCalendar cases, test_with_doctest.py hypothesis doctest), and this branch adds none
  • ruff check and ruff format --check clean

Could this get another review?



The comment asserted a resolution that neither the RFC nor the issue
states. Word it from PyCalendar#1796 itself: both values are accepted when they
describe the same end, and still rejected when they contradict, which
is the case the review asked the tests to keep covering.

Compare against normalize_pytz(start + duration) inline as suggested in
review, so the pytz normalisation is visible at the point of comparison.

Comment and control flow only; behaviour is unchanged.

AI model and version: DeepSeek V4.1 Flash (as reported by the Freebuff
agent runtime).
How AI was used: the maintainer review on PyCalendar#1835 was summarised in the
prompt "work on follow ups of my external existing PRs", asking for the
rationale to come from issue PyCalendar#1796 rather than the author's opinion and
for the normalize_pytz comparison suggested in review. The output is the
comment and comparison change in src/icalendar/attr/__init__.py, written
to this commit; it was reviewed and the test suite run against it.
@aspire488
aspire488 force-pushed the fix/start-end-duration-mismatch branch from f5f436f to 715bb3f Compare December 6, 2026 06:30

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

Labels

ai-suspicion This contribution is possibly created with lots of AI help without enough human understanding.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants