python-holidays icon indicating copy to clipboard operation
python-holidays copied to clipboard

Long weekend Function added

Open AryaPhansalkar opened this issue 2 months ago • 3 comments

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 holidays functionality in general)

Checklist

  • [x] I've read and followed the contributing guidelines.
  • [x] I've run make check locally; all checks and tests passed.

AryaPhansalkar avatar Oct 10 '25 17:10 AryaPhansalkar

[!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
Utilities
holidays/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.
Tests
tests/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._timedelta versus datetime.timedelta.
  • Weekend-overlap condition and its effect when require_weekend_overlap=False.
  • Correctness of contiguous-block construction and already_checked deduplication.
  • 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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

coderabbitai[bot] avatar Oct 10 '25 17:10 coderabbitai[bot]

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.

codecov[bot] avatar Oct 10 '25 18:10 codecov[bot]