Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add holidays_between function #14

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion tests/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,13 @@ def test_supported_holidays_are_complete(self):
names.add(v["nom_vacances"])

expected = set(SchoolHolidayDates.SUPPORTED_HOLIDAY_NAMES)
self.assertEqual(names, expected)

self.assertEquals(names, expected)

def test_holidays_between(self):
d = SchoolHolidayDates()

res = d.holidays_between('2022-01-01', '2022-02-01')
for k, v in res.items():
self.assertEquals(sorted(v.keys()), self.EXPECTED_KEYS)

15 changes: 15 additions & 0 deletions vacances_scolaires_france/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,18 @@ def holidays_for_year_zone_and_name(self, year, zone, name):
for k, v in self.holidays_for_year(year).items()
if self.is_holiday_for_zone(k, zone) and v["nom_vacances"] == name
}

def holidays_between(self, start_date, end_date):
"""
To get holidays between 2 dates
:param start_date: the 1st bound of the interval
:param end_date: the 2nd bound of the interval
:return: dict
"""
start_date = datetime.datetime.strptime(start_date, '%Y-%m-%d').date()
end_date = datetime.datetime.strptime(end_date, '%Y-%m-%d').date()

res = {k: v for k, v in self.data.items() if start_date <= k <= end_date}
return res