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

Compatibility updates and clarification of what happens when division is not provided #5

Merged
merged 5 commits into from
May 8, 2019
Merged
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
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ indent_size = 4
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.json]
indent_size = 2
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
dist: xenial
language: python
python:
- 3.7
- 3.6
- 3.5
- 3.4
Expand Down
10 changes: 10 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@ Install using ``pip install govuk-bank-holidays``. Sample usage:
# choose a different locale for holiday titles and notes
bank_holidays = BankHolidays(locale='cy')

Bank holidays differ around the UK. The GOV.UK source currently lists these for 3 "divisions":

- England and Wales
- Scotland
- Northern Ireland

… and many methods in this library take a ``division`` parameter (c.f. constants on ``BankHolidays`` class).

NB: If no division is specified, only holidays common to *all* divisions are returned.

Development
-----------

Expand Down
162 changes: 162 additions & 0 deletions govuk_bank_holidays/bank-holidays.json
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,54 @@
"date": "2019-12-26",
"notes": "",
"bunting": true
},
{
"title": "New Year’s Day",
"date": "2020-01-01",
"notes": "",
"bunting": true
},
{
"title": "Good Friday",
"date": "2020-04-10",
"notes": "",
"bunting": false
},
{
"title": "Easter Monday",
"date": "2020-04-13",
"notes": "",
"bunting": true
},
{
"title": "Early May bank holiday",
"date": "2020-05-04",
"notes": "",
"bunting": true
},
{
"title": "Spring bank holiday",
"date": "2020-05-25",
"notes": "",
"bunting": true
},
{
"title": "Summer bank holiday",
"date": "2020-08-31",
"notes": "",
"bunting": true
},
{
"title": "Christmas Day",
"date": "2020-12-25",
"notes": "",
"bunting": true
},
{
"title": "Boxing Day",
"date": "2020-12-28",
"notes": "Substitute day",
"bunting": true
}
]
},
Expand Down Expand Up @@ -834,6 +882,60 @@
"date": "2019-12-26",
"notes": "",
"bunting": true
},
{
"title": "New Year’s Day",
"date": "2020-01-01",
"notes": "",
"bunting": true
},
{
"title": "2nd January",
"date": "2020-01-02",
"notes": "",
"bunting": true
},
{
"title": "Good Friday",
"date": "2020-04-10",
"notes": "",
"bunting": false
},
{
"title": "Early May bank holiday",
"date": "2020-05-04",
"notes": "",
"bunting": true
},
{
"title": "Spring bank holiday",
"date": "2020-05-25",
"notes": "",
"bunting": true
},
{
"title": "Summer bank holiday",
"date": "2020-08-03",
"notes": "",
"bunting": true
},
{
"title": "St Andrew’s Day",
"date": "2020-11-30",
"notes": "",
"bunting": true
},
{
"title": "Christmas Day",
"date": "2020-12-25",
"notes": "",
"bunting": true
},
{
"title": "Boxing Day",
"date": "2020-12-28",
"notes": "Substitute day",
"bunting": true
}
]
},
Expand Down Expand Up @@ -1325,6 +1427,66 @@
"date": "2019-12-26",
"notes": "",
"bunting": true
},
{
"title": "New Year’s Day",
"date": "2020-01-01",
"notes": "",
"bunting": true
},
{
"title": "St Patrick’s Day",
"date": "2020-03-17",
"notes": "",
"bunting": true
},
{
"title": "Good Friday",
"date": "2020-04-10",
"notes": "",
"bunting": false
},
{
"title": "Easter Monday",
"date": "2020-04-13",
"notes": "",
"bunting": true
},
{
"title": "Early May bank holiday",
"date": "2020-05-04",
"notes": "",
"bunting": true
},
{
"title": "Spring bank holiday",
"date": "2020-05-25",
"notes": "",
"bunting": true
},
{
"title": "Battle of the Boyne (Orangemen’s Day)",
"date": "2020-07-13",
"notes": "Substitute day",
"bunting": false
},
{
"title": "Summer bank holiday",
"date": "2020-08-31",
"notes": "",
"bunting": true
},
{
"title": "Christmas Day",
"date": "2020-12-25",
"notes": "",
"bunting": true
},
{
"title": "Boxing Day",
"date": "2020-12-28",
"notes": "Substitute day",
"bunting": true
}
]
}
Expand Down
9 changes: 7 additions & 2 deletions govuk_bank_holidays/bank_holidays.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ def load_backup_data(cls):
with open(os.path.join(os.path.dirname(__file__), 'bank-holidays.json')) as f:
return json.load(f)

def __init__(self, locale=None, weekend={5, 6}, use_cached_holidays=False):
def __init__(self, locale=None, weekend=(5, 6), use_cached_holidays=False):
"""
Load UK bank holidays
:param locale: the locale into which holidays should be translated; defaults to no translation
:param weekend: days of the week that are never work days; defaults to Saturday and Sunday
:param use_cached_holidays: use the cached local copy of the holiday list
"""
self.weekend = weekend
self.weekend = set(weekend)
if use_cached_holidays:
data = self.load_backup_data()
else:
Expand Down Expand Up @@ -87,6 +87,7 @@ def __iter__(self):
def get_holidays(self, division=None, year=None):
"""
Gets a list of all known bank holidays, optionally filtered by division and/or year
NB: If no division is specified, only holidays common to *all* divisions are returned.
:param division: see division constants; defaults to common holidays
:param year: defaults to all available years
:return: list of dicts with titles, dates, etc
Expand All @@ -108,6 +109,7 @@ def get_holidays(self, division=None, year=None):
def get_next_holiday(self, division=None, date=None):
"""
Returns the next known bank holiday
NB: If no division is specified, only holidays common to *all* divisions are returned.
:param division: see division constants; defaults to common holidays
:param date: search starting from this date; defaults to today
:return: dict
Expand All @@ -120,6 +122,7 @@ def get_next_holiday(self, division=None, date=None):
def is_holiday(self, date, division=None):
"""
True if the date is a known bank holiday
NB: If no division is specified, only holidays common to *all* divisions are returned.
:param date: the date to check
:param division: see division constants; defaults to common holidays
:return: bool
Expand All @@ -129,6 +132,7 @@ def is_holiday(self, date, division=None):
def get_next_work_day(self, division=None, date=None):
"""
Returns the next work day, skipping weekends and bank holidays
NB: If no division is specified, only holidays common to *all* divisions are returned.
:param division: see division constants; defaults to common holidays
:param date: search starting from this date; defaults to today
:return: datetime.date; NB: get_next_holiday returns a dict
Expand All @@ -144,6 +148,7 @@ def get_next_work_day(self, division=None, date=None):
def is_work_day(self, date, division=None):
"""
True if the date is not a weekend or a known bank holiday
NB: If no division is specified, only holidays common to *all* divisions are returned.
:param date: the date to check
:param division: see division constants; defaults to common holidays
:return: bool
Expand Down
2 changes: 1 addition & 1 deletion govuk_bank_holidays/setup_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class MessagesCommand(setuptools.Command):
user_options = []

def __init__(self, *args, **kwargs):
super(MessagesCommand, self).__init__(*args, **kwargs)
setuptools.Command.__init__(self, *args, **kwargs)
self.domain = 'messages'
self.cwd = os.getcwd()
self.root_path = os.path.join(os.path.dirname(__file__), os.pardir)
Expand Down
3 changes: 3 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
exclude = .git/,.eggs/,build/,dist/,env/,venv/
max-complexity = 10
max-line-length = 120

[wheel]
universal = 1
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
name='govuk-bank-holidays',
version=package_info.__version__,
author=package_info.__author__,
author_email='dev@digital.justice.gov.uk',
url='https://github.com/ministryofjustice/govuk-bank-holidays',
packages=['govuk_bank_holidays'],
include_package_data=True,
Expand All @@ -42,6 +43,7 @@
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
],
cmdclass=setup_extensions.command_classes,
install_requires=install_requires,
Expand Down
6 changes: 3 additions & 3 deletions tests/test_bank_holidays.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,16 @@ def assertExpectedFormat(self, holidays):
def test_holidays(self):
bank_holidays = self.get_bank_holidays_using_local_data()
holidays = bank_holidays.get_holidays()
self.assertEqual(len(holidays), 49)
self.assertEqual(len(holidays), 55)
self.assertExpectedFormat(holidays)

def test_holidays_for_division(self):
bank_holidays = self.get_bank_holidays_using_local_data()
holidays = bank_holidays.get_holidays(division=BankHolidays.ENGLAND_AND_WALES)
self.assertEqual(len(holidays), 65)
self.assertEqual(len(holidays), 73)
self.assertExpectedFormat(holidays)
holidays = bank_holidays.get_holidays(division=BankHolidays.SCOTLAND)
self.assertEqual(len(holidays), 73)
self.assertEqual(len(holidays), 82)
self.assertExpectedFormat(holidays)
self.assertIn(u'St Andrew\u2019s Day', map(lambda holiday: holiday['title'], holidays))

Expand Down