Giter VIP home page Giter VIP logo

govuk-bank-holidays's Introduction

GOV.UK Bank Holidays

This library loads the official list of bank holidays in the United Kingdom as supplied by GOV.UK. GOV.UK tend to provide this list for only a year or two into the future.

A cached backup list of known bank holidays is stored in this package though it is not updated often. GOV.UK no longer provide bank holidays for some of the older years still part of this backup list.

Usage

Install using pip install govuk-bank-holidays. Sample usage:

from govuk_bank_holidays.bank_holidays import BankHolidays

bank_holidays = BankHolidays()
for bank_holiday in bank_holidays.get_holidays():
    print(bank_holiday['title'], 'is on', bank_holiday['date'])
print(bank_holidays.get_next_holiday())

# see govuk_bank_holidays/bank_holidays.py source file for more methods and argument details…

# choose a different locale for holiday titles and notes
bank_holidays = BankHolidays(locale='cy')

# use cached holidays if internet connection is not desired
bank_holidays = BankHolidays(use_cached_holidays=True)

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 (see constants defined on BankHolidays class).

NB: If no division is specified, only holidays common to all divisions are returned so some local bank holidays may not be listed. Therefore specifying a division is recommended.

While localisation is provided in English (the default with locale code 'en') and Welsh (locale code 'cy'), please note that the Welsh version may contain errors.

Development

image

image

Please report bugs and open pull requests on GitHub.

To work on changes to this library, it’s recommended to install it in editable mode into a virtual environment, i.e. pip install --editable .

Update cached bank holidays from GOV.UK using python scripts/update-cache.py.

Update translation files using python scripts/messages.py update, e.g. when updating the i18n module or when adding new languages. Compile them using python scripts/messages.py compile; this is required before testing and distribution. Updating and compiling translation files requires the gettext system package to be installed.

Use python -m tests to run all tests locally. Alternatively, you can use tox if you have multiple python versions.

[Only for GitHub team members] Distribute a new version to PyPI by:

  • updating the VERSION tuple in govuk_bank_holidays/__init__.py
  • adding a note to the History
  • publishing a release on GitHub which triggers an upload to PyPI; alternatively, run python scripts/messages.py compile; python -m build; twine upload dist/* locally

History

0.14

Migrated test, build and release processes away from deprecated setuptools commands. Translation files are updated and compiled through scripts which are not included in distribution. The BankHolidays class has a new ALL_DIVISIONS constant.

0.13

The library does not differ from 0.12.

0.12

Removed support for python versions older than 3.7. Updated cached bank holidays file to include latest holidays published by GOV.UK. Moved code style linting from unit test to github action. Added setup.py command to update cached bank holidays from GOV.UK.

0.11

Updated cached bank holidays file to include latest holidays published by GOV.UK. Added python 3.10 to testing matrix.

0.10

Added methods to generate series of holidays and work days before/after starting from a given date.

0.9

Added methods to find previous bank holidays / work days, mirroring the existing methods. Removed support for python versions older than 3.6. Added python 3.9 to testing matrix.

0.8

The library does not differ from 0.7. This release is the first to use GitHub Actions to automatically publish to PyPI.

0.7

Minor documentation update.

0.6

Updated cached bank holidays file to include latest holidays published by GOV.UK. Added python 3.8 to testing matrix. Minor documentation update.

0.5

Updated cached bank holidays file to include latest holidays published by GOV.UK.

0.4

Updated cached bank holidays file to include latest holidays published by GOV.UK. Added python 3.7 to testing matrix. Documentation improved.

0.3

Improved testing. Library unchanged.

0.2

Updated cached bank holidays file to include latest holidays published by GOV.UK. Added option to force use of cached file. Added next work day calculation.

0.1

Initial release.

Copyright (C) 2023 HM Government (Ministry of Justice Digital & Technology). See LICENSE.txt for further details.

govuk-bank-holidays's People

Contributors

dependabot[bot] avatar ibrechin avatar samuelhwilliams avatar ushkarev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

govuk-bank-holidays's Issues

Default branch is not main

Hi there
The default branch for this repository is not set to main
See repository settings/settings/branches to rename the default branch to main and ensure the Branch protection rules is set to main as well
See the repository standards: https://github.com/ministryofjustice/github-repository-standards
See the report: https://operations-engineering-reports.cloud-platform.service.justice.gov.uk/github_repositories
Please contact Operations Engineering on Slack #ask-operations-engineering, if you need any assistance

Some holiday dates in 2019 for england and wales are incorrectly ignored when no division is specified

in get_holidays()

govuk_bank_holidays/bank_holidays.py:98

This line appears to be stripping dates which are scoped in the england-and-wales section which appear in the .json file, which results in this years holiday dates excluding some, such as 2019-04-22.

Reproducable via:

import pprint
from govuk_bank_holidays.bank_holidays import BankHolidays
pprint.pprint([x['date'] for x in BankHolidays().get_holidays()]	)

Notice 2019-04-22 does not appear, along with some others which appear in the .json file.

If a division is specified, all dates show as expected:

import pprint
from govuk_bank_holidays.bank_holidays import BankHolidays
pprint.pprint([x['date'] for x in BankHolidays().get_holidays(division='england-and-wales')])

Seems that when the fallback is hit - additional code is run in the following block, and I can't quite figure out why / what it's supposed to be doing

        if division:
            holidays = self.data[division]
        else:
            holidays = self.data[self.ENGLAND_AND_WALES]
            dates_in_common = six.moves.reduce(
                set.intersection,
                (set(map(lambda holiday: holiday['date'], division_holidays))
                 for division, division_holidays in six.iteritems(self.data))
            )
            holidays = filter(lambda holiday: holiday['date'] in dates_in_common, holidays)

This would fix the issue, but may well cause others (that i'm not aware of)

        if division:
            holidays = self.data[division]
        else:
            holidays = self.data[self.ENGLAND_AND_WALES]

Reversing next work day

Hey, using your library for some local council work. Need to find out the previous workday. Currently using the is_work_day method, but perhaps we could change up the get_next_work_day method to include a step param that we could set to -1 and iterate backwards? Something like this?

    def get_next_work_day(self, division=None, date=None, step=1):
        """
        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
        :param step: step, use -1 to reverse, default 1
        :return: datetime.date; NB: get_next_holiday returns a dict
        """
        date = date or datetime.date.today()
        one_day = datetime.timedelta(days=step)
        holidays = set(holiday['date'] for holiday in self.get_holidays(division=division))
        while True:
            date += one_day
            if date.weekday() not in self.weekend and date not in holidays:
                return date

Any thoughts?

Docs don't state the scope of the library

When choosing to use the library I need to know:

  • What the valid date range is (through experiment dates past 2021 don't work, nor do dates before 2015 the docs should state this)
  • Update policy for the library - will new version be released when new bank holidays are added
  • It would be nice if I didn't have to check the code to work out that I can supply "cy" or "en" and what they mean. Also, example code for each division would be good.

Dictionary Support

The command .get_holidays() provides a list of 42 dictionaries, but summer bank holidays aren't included in the list. Is there a reason for that?

A branch protection setting is not enabled: Include administrators

Hi there
The default branch protection setting called Include administrators is not enabled for this repository
See repository settings/Branches/Branch protection rules
Either add a new Branch protection rule or edit the existing branch protection rule and select the Include administrators option
This will enable the branch protection rules to admin uses as well
See the repository standards: https://github.com/ministryofjustice/github-repository-standards
See the report: https://operations-engineering-reports.cloud-platform.service.justice.gov.uk/github_repositories
Please contact Operations Engineering on Slack #ask-operations-engineering, if you need any assistance

Pointless

What I want Is the future bank holidays..
for next ten years.. to populate my db..

A branch protection setting is not enabled: administrators require review

Hi there
The default branch protection setting called administrators require review is not enabled for this repository
See repository settings/Branches/Branch protection rules
Either add a new Branch protection rule or edit the existing branch protection rule and select the Require a pull request before merging option
See the repository standards: https://github.com/ministryofjustice/github-repository-standards
See the report: https://operations-engineering-reports.cloud-platform.service.justice.gov.uk/github_repositories
Please contact Operations Engineering on Slack #ask-operations-engineering, if you need any assistance

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.