Long weekend Function added
Proposed change
- Added a new function called list_long_weekends
- It detects long weekends automatically by combining holidays with the adjacent weekend day.
- Weekend days are considered according to the country.
- TestListLongWeekends has been added.
Resolves #2422
Type of change
- [ ] New country/market holidays support (thank you!)
- [ ] Supported country/market holidays update (calendar discrepancy fix, localization)
- [ ] Existing code/documentation/test/process quality improvement (best practice, cleanup, refactoring, optimization)
- [ ] Dependency update (version deprecation/pin/upgrade)
- [ ] Bugfix (non-breaking change which fixes an issue)
- [ ] Breaking change (a code change causing existing functionality to break)
- [x] New feature (new
holidaysfunctionality in general)
Checklist
- [x] I've read and followed the contributing guidelines.
- [x] I've run
make checklocally; all checks and tests passed.
[!CAUTION]
Review failed
Failed to post review comments
Summary by CodeRabbit
New Features
- Long weekend detection: New functionality to identify consecutive holiday periods and extended weekends. Customize minimum duration thresholds and optionally filter results by weekend overlap requirements. Supports diverse weekend definitions and seamlessly integrates with all holiday calendar systems for flexible adaptation to different regional holiday patterns and structures.
✏️ Tip: You can customize this high-level summary in your review settings.
Walkthrough
Adds a public utility list_long_weekends(instance: HolidayBase, *, minimum_holiday_length: int = 3, require_weekend_overlap: bool = True) in holidays/utils.py, exports it via __all__, imports _timedelta and date for date arithmetic, and adds comprehensive tests in tests/test_utils.py.
Changes
| Cohort / File(s) | Summary of changes |
|---|---|
Utilitiesholidays/utils.py |
Added list_long_weekends(instance: HolidayBase, *, minimum_holiday_length: int = 3, require_weekend_overlap: bool = True) -> list[list[date]]; added imports from datetime import date and from holidays.calendars.gregorian import _timedelta; updated __all__ to include "list_long_weekends". Function computes contiguous date blocks around holidays by expanding to previous/next working days, filters by minimum length and optional weekend overlap, deduplicates blocks, and returns lists of date objects. |
Teststests/test_utils.py |
Added TestListLongWeekends test suite and multiple CountryStub classes (CS1–CS5) to cover scenarios: single and multiple long weekends, across-year spans, custom weekend definitions (e.g., FRI/SAT), toggling require_weekend_overlap, custom minimum_holiday_length, no-holiday cases, and integration checks using real country/market holiday sets. Added imports for FRI, SAT, and list_long_weekends. |
Estimated code review effort
🎯 3 (Moderate) | ⏱️ ~25 minutes
Potential attention points:
- Use of
holidays.calendars.gregorian._timedeltaversusdatetime.timedelta. - Weekend-overlap condition and its effect when
require_weekend_overlap=False. - Correctness of contiguous-block construction and
already_checkeddeduplication. - Tests that use real holiday sets and custom weekend definitions.
Pre-merge checks and finishing touches
❌ Failed checks (1 warning)
| Check name | Status | Explanation | Resolution |
|---|---|---|---|
| Docstring Coverage | ⚠️ Warning | Docstring coverage is 11.11% which is insufficient. The required threshold is 80.00%. | You can run @coderabbitai generate docstrings to improve docstring coverage. |
✅ Passed checks (4 passed)
| Check name | Status | Explanation |
|---|---|---|
| Title check | ✅ Passed | The title clearly summarizes the main feature being added: a new list_long_weekends function in utils to identify holiday-based long weekends. |
| Description check | ✅ Passed | The description is directly related to the changeset, explaining the new list_long_weekends function, its behavior with country-specific weekends, and the added test coverage. |
| Linked Issues check | ✅ Passed | The PR addresses the core requirement from issue #2422 by implementing a function to find holiday-based long weekends that considers country-specific weekend definitions. |
| Out of Scope Changes check | ✅ Passed | All changes are scoped to the new list_long_weekends feature and its test coverage; no unrelated modifications detected. |
✨ Finishing touches
- [ ] 📝 Generate docstrings
🧪 Generate unit tests (beta)
- [ ] Create PR with unit tests
- [ ] Post copyable unit tests in a comment
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Comment @coderabbitai help to get the list of available commands and usage tips.
Codecov Report
:white_check_mark: All modified and coverable lines are covered by tests.
:white_check_mark: Project coverage is 100.00%. Comparing base (aac0608) to head (0ae01ce).
Additional details and impacted files
@@ Coverage Diff @@
## dev #3001 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 306 306
Lines 18245 18269 +24
Branches 2327 2333 +6
=========================================
+ Hits 18245 18269 +24
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
:rocket: New features to boost your workflow:
- :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
Quality Gate passed
Issues
0 New issues
0 Accepted issues
Measures
0 Security Hotspots
0.0% Coverage on New Code
0.0% Duplication on New Code