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

Add Halloween to US Holiday Schedule

Open schmittyice-hyp opened this issue 3 years ago • 1 comments

Please add Halloween (Oct 31st) to US Holiday schedule. I use this code to automate my outdoor lights based on holiday. Halloween is a fun holiday to change lights.

schmittyice-hyp avatar Sep 15 '22 21:09 schmittyice-hyp

Hi @schmittyice-hyp! Thanks for the idea!

I love this holiday! And it's quite unfortunate that at this moment python-holidays provides official holiday list (both federal and regional ones) only.

I don't know what your automation looks like but it sounds like you might benefit from forking the repo and adding that holiday by yourself for using the fork further in your automation. Another way would be extending the python-holidays to optionally include non-official holidays based on some parameter value. This may or may not be ready before this year's Halloween.

-- Ark

arkid15r avatar Sep 16 '22 16:09 arkid15r

You can easily add this on your own. Here is a simple example:

class HalloweenHolidays(holidays.HolidayBase):
    def _populate(self, year):
        self[date(year, 10, 31)] = "Halloween"

german_holidays = holidays.country_holidays('DE', subdiv='NW', years=2022)
german_holidays += HalloweenHolidays()

for date, name in sorted(german_holidays.items()):
    print(date, name)

This is all documented quite well. You can create new custom holiday classes and merge different holiday classes. This way I add halloween to the german holidays and debug print the result afterwards.

NicoHood avatar Oct 11 '22 11:10 NicoHood

At the current time, I agree with @NicoHood : the right way to go is using a custom class to implement your required additional days. Anyway, thanks everyone for your interest and support!

dr-prodigy avatar Nov 13 '22 12:11 dr-prodigy