seatgeek / businesstime

A simple python utility for calculating business time aware timedeltas between two datetimes
BSD 2-Clause "Simplified" License
85 stars 36 forks source link

Add UK bank holidays #31

Closed christopherdcunha closed 5 years ago

christopherdcunha commented 6 years ago

This PR will conflict with https://github.com/seatgeek/businesstime/pull/30

As @le01phuo mentions in his PR. The holidays package is probably a better option.

christopherdcunha commented 5 years ago

Ping @erwaller (I'm assuming you're a core contributor). Is there anything extra I need to do to get this reviewed?

erwaller commented 5 years ago

Thanks for this @christopherdcunha and sorry for the long delay!

Looks like these are the UK holidays through end of 2019? Is the list usually published ~one year in advance?

christopherdcunha commented 5 years ago

No worries for the delay @erwaller and thanks for merging!

Yes, it seems that only one year's worth of holidays is published on https://www.gov.uk (i.e. at the moment, holidays up to 2020-12-31 are published). I'm not 100% sure that all these days are discoverable by code, BUT I can see that this is what python-holidays does.

As suggested by @le01phuo, it might be easier to defer this to another library (like python-holidays) and users of your library should be asked to do something like this:

from businesstime.holidays import Holidays
import holidays

class EnglandHolidays(Holidays):
    holidays = holidays.England()['2012-1-1': '2020-12-31']

    def isholiday(self, dt):
        if isinstance(dt, datetime.datetime):
            return dt.date() in self.holidays
        return dt in self.holidays

EDIT: One quirk about the python-holidays library is that it seems to flag holidays that occur on weekends even though they've been substituted for weekdays in practice. e.g. NYE occurs on a Sunday, so the actual holiday will be on the Monday (Jan 2).