Skip to content

Reject nonpositive weekday occurrences - #1083

Open
Sskift wants to merge 1 commit into
python-pendulum:masterfrom
Sskift:fix/reject-nonpositive-date-occurrences
Open

Sskift wants to merge 1 commit into
python-pendulum:masterfrom
Sskift:fix/reject-nonpositive-date-occurrences

Conversation

@Sskift

@Sskift Sskift commented Nov 2, 2026

Copy link
Copy Markdown

nth_of() currently accepts zero or negative occurrence numbers and returns the first day of the month, quarter or year. That date can even have a different weekday from the one requested: date(2024, 5, 15).nth_of("month", 0, FRIDAY) returns Wednesday, May 1.

Route nonpositive occurrences through the existing out-of-range error in both Date and DateTime. Positive occurrences keep their current behavior. The docstrings now make the one-based occurrence numbering explicit.

All 18 new regression cases fail before the change and pass after it. The full test suite has 1,885 passes, 5 skips and the existing timezone-name failure in test_instance_with_aware_datetime_any_tzinfo, also present on the baseline. Ruff, formatting and mypy on both changed source files pass.

  • Added tests for changed code.
  • Updated documentation for changed code.

This contribution was prepared with Codex assistance.

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant