Skip to content

fix(prop): reject a zero-length period - #2103

Open
rahul05ranjan wants to merge 3 commits into
PyCalendar:mainfrom
rahul05ranjan:fix/zero-length-period
Open

rahul05ranjan wants to merge 3 commits into
PyCalendar:mainfrom
rahul05ranjan:fix/zero-length-period

Conversation

@rahul05ranjan

@rahul05ranjan rahul05ranjan commented Nov 12, 2026 •

Copy link
Copy Markdown

Linked issue

Description

vPeriod rejected a period only when the start came strictly after the end, so a zero-length period was accepted, parsed, and written back out. RFC 5545 section 3.3.9 defines both period forms strictly:

  • period-explicit: "The start MUST be before the end."
  • period-start: "a start and positive duration of time."

So a period whose end equals its start — written either as two equal date-times or as a zero duration (P0D) — is as invalid as a reversed one.

The constructor's comparison changes from start > end to start >= end, so both of the issue's cases get the same ValueError as a reversed period:

>>> vPeriod((start, start))
ValueError: Start time is not before end time
>>> vPeriod((start, timedelta(0)))
ValueError: Start time is not before end time

The message now says the start is not before the end, accurate for the equal case as well; the one existing test matching the old wording is updated. This covers every construction path — direct construction, from_ical round-trips through vDDDTypes, jCal and xCal parsing — since they all build the period through this constructor.

Two follow-ups in the same PR, both consequences of the same RFC rule:

  • The xCal parser raised XCalParsingError("Expected positive duration") only for negative durations; it now raises it for a zero duration too (P0D), with the same message.
  • The xCal test fixtures listed (start, P0D) among the valid round-trip specs; those two specs move to the invalid list, where the RFC puts them. No other test in the suite uses a zero-length period (verified by grepping the whole test tree for P0D / DURATION_0 in period contexts).

Dates read as midnight keep working; a period from one midnight to the next is unaffected because its end is a day after its start.

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

Verification run locally with system Python 3.13.5 (PYTHONPATH=src python3 -m pytest), no extra dependencies needed:

  • src/icalendar/tests/prop/test_vPeriod.py, test_period.py, test_issue_1633.py, test_equality.py, and the full src/icalendar/tests/rfc_7265_jcal/ and src/icalendar/tests/rfc_6321_xcal/ directories (all period, jCal and xCal suites): 5731 + 3614 collected runs green, including two new parametrized rejection cases and a regression test for the issue's exact repro — both fail on the un-fixed HEAD. The xCal P0D specs now assert the "Expected positive duration" error.
  • A full-suite run on this branch and on a clean checkout of main in a worktree shows identical failure sets except for the period-related tests fixed here: main and this branch both have 585 environment-related failures (time-zone identification and Sphinx-version-directive tests, broken identically on both sides — the host has a newer dateutil/Sphinx than the repo pins), and this branch additionally had the 36 xCal zero-duration tests before the fixture move, which now pass.
  • Both repro cases from the issue raise ValueError (the full-suite checkbox is left for CI; the suites listed above were run in full locally).

I used AI to assist me with this change.

vPeriod raised ValueError only when the start came after the end, so a
period whose end equaled its start - written either as two equal
date-times or as a zero duration - was accepted and serialized back out.
RFC 5545 section 3.3.9 requires the end of a period to come after its
start, so a period with no length is as invalid as a reversed one.

Reject start == end with the same ValueError the reversed case gets. The
message now says the start is not before the end, which covers both
cases, and the one test matching the old message is updated.

Fixes PyCalendar#2087

Co-authored-by: rahul05ranjan <11793455+rahul05ranjan@users.noreply.github.com>
RFC 5545 section 3.3.9 defines the period-start form with a positive
duration, so a zero duration is as invalid as a negative one. The xCal
parser's check now matches, raising the same "Expected positive
duration" XCalParsingError for P0D, and the xCal test fixtures move the
zero-duration specs from the valid round-trip lists to the invalid ones,
where they already belonged: the constructor's start >= end rejection
from the previous commit caught them first.

Co-authored-by: rahul05ranjan <11793455+rahul05ranjan@users.noreply.github.com>
@github-actions

Copy link
Copy Markdown
Contributor

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

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

Copy link
Copy Markdown
Contributor

One or more PR-quality checks did not pass. Review the PR Quality Checks summary in the workflow run for the failed checks and their details, then make any necessary updates.

Checklist items may remain unchecked while work is in progress. Please tick each item as you complete it.

If you used AI assistance, follow the project's Responsible AI use policy and provide the required disclosures.

@rahul05ranjan

Copy link
Copy Markdown
Author

76d7918b2a87

@github-actions

Copy link
Copy Markdown
Contributor

Automated contributor detected

@rahul05ranjan did not pass an automated contributor check on this pull request.

If you believe this is a mistake, leave a comment and a maintainer will review it.

Automated check by AgentScan

@github-actions github-actions Bot added the agentscan:automated-account AgentScan flagged this item as coming from an automated account, and it needs review label Nov 13, 2026

@angatha angatha left a comment

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.

Changes itself look fine

Comment thread news/2087.bugfix Outdated
@@ -0,0 +1 @@
:class:`~icalendar.prop.dt.period.vPeriod` now rejects a zero-length period whose end equals its start, as :rfc:`5545#section-3.3.9` requires the end to come after the start.

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.

Please add your github handle

Co-authored-by: rahul05ranjan <11793455+rahul05ranjan@users.noreply.github.com>
@rahul05ranjan

Copy link
Copy Markdown
Author

Done in 6b4f970 — added the handle following the convention in the other news entries.

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

agentscan:automated-account AgentScan flagged this item as coming from an automated account, and it needs review 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.

[Bug] Zero-length periods are accepted

2 participants