Skip to content

Commit

Permalink
Add Belize holidays (#1181)
Browse files Browse the repository at this point in the history
* Add Belize holidays

* PR suggestion
  • Loading branch information
KJhellico authored May 22, 2023
1 parent aeecd81 commit 22d9f48
Show file tree
Hide file tree
Showing 5 changed files with 492 additions and 1 deletion.
5 changes: 4 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ Available Countries
.. _ISO 3166-1 alpha-2 code: https://en.wikipedia.org/wiki/List_of_ISO_3166_country_codes
.. _ISO 3166-2 code: https://en.wikipedia.org/wiki/ISO_3166-2

We currently support 122 country codes. The standard way to refer to a country
We currently support 123 country codes. The standard way to refer to a country
is by using its `ISO 3166-1 alpha-2 code`_, the same used for domain names, and
for a subdivision its `ISO 3166-2 code`_. The following countries and
subdivisions are available:
Expand Down Expand Up @@ -165,6 +165,9 @@ subdivisions are available:
* - Belgium
- BE
- None
* - Belize
- BZ
- None
* - Bolivia
- BO
- Departments: B, C, H, L, N, O, P, S, T
Expand Down
1 change: 1 addition & 0 deletions holidays/countries/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from .bangladesh import Bangladesh, BD, BGD
from .belarus import Belarus, BY, BLR
from .belgium import Belgium, BE, BEL
from .belize import Belize, BZ, BLZ
from .bolivia import Bolivia, BO, BOL
from .bosnia_and_herzegovina import BosniaAndHerzegovina, BA, BIH
from .botswana import Botswana, BW, BWA
Expand Down
140 changes: 140 additions & 0 deletions holidays/countries/belize.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
# python-holidays
# ---------------
# A fast, efficient Python library for generating country, province and state
# specific sets of holidays on the fly. It aims to make determining whether a
# specific date is a holiday as fast and flexible as possible.
#
# Authors: dr-prodigy <[email protected]> (c) 2017-2023
# ryanss <[email protected]> (c) 2014-2017
# Website: https://github.com/dr-prodigy/python-holidays
# License: MIT (see LICENSE file)

from datetime import date
from datetime import timedelta as td
from typing import Optional

from holidays.calendars import _get_nth_weekday_from
from holidays.constants import JAN, MAR, MAY, AUG, SEP, OCT, NOV, MON
from holidays.holiday_base import HolidayBase
from holidays.holiday_groups import ChristianHolidays, InternationalHolidays


class Belize(HolidayBase, ChristianHolidays, InternationalHolidays):
"""
References:
- https://en.wikipedia.org/wiki/Public_holidays_in_Belize
- http://www.belizelaw.org/web/lawadmin/PDF%20files/cap289.pdf
- https://www.pressoffice.gov.bz/public-and-bank-holidays-2022-updated/
- https://www.pressoffice.gov.bz/government-of-belize-establishes-new-public-and-bank-holidays/ # noqa: E501
"""

country = "BZ"

def __init__(self, *args, **kwargs) -> None:
ChristianHolidays.__init__(self)
InternationalHolidays.__init__(self)
super().__init__(*args, **kwargs)

def _add_movable_holiday(self, *args) -> None:
# Chapter 289 of the laws of Belize states that if the holiday falls
# on a Sunday or a Friday, the following Monday is observed as public
# holiday; further, if the holiday falls on a Tuesday, Wednesday or
# Thursday, the preceding Monday is observed as public holiday
name, dt = self._parse_holiday(*args)
if self.observed:
if self._is_friday(dt) or self._is_sunday(dt):
dt = _get_nth_weekday_from(1, MON, dt)
name = "%s (Observed)" % name
elif (
self._is_tuesday(dt)
or self._is_wednesday(dt)
or self._is_thursday(dt)
):
dt = _get_nth_weekday_from(-1, MON, dt)
name = "%s (Observed)" % name
self._add_holiday(name, dt)

def _add_holiday(self, *args) -> Optional[date]:
# Chapter 289 of the laws of Belize states that if the holiday falls
# on a Sunday, the following Monday is observed as public holiday
name, dt = self._parse_holiday(*args)
if (
self.observed
and self._is_sunday(dt)
and dt + td(days=+1) not in self
):
name = "%s (Observed)" % name
dt += td(days=+1)
return super()._add_holiday(name, dt)

def _populate(self, year: int) -> None:
# Belize was granted independence on 21.09.1981.
if year <= 1981:
return None
super()._populate(year)

# New Year's Day.
self._add_new_years_day("New Year's Day")

if year >= 2021:
# George Price Day.
self._add_holiday("George Price Day", JAN, 15)

# National Heroes and Benefactors Day.
self._add_movable_holiday(
"National Heroes and Benefactors Day", MAR, 9
)

# Good Friday.
self._add_good_friday("Good Friday")

# Holy Saturday.
self._add_holy_saturday("Holy Saturday")

# Easter Monday.
self._add_easter_monday("Easter Monday")

# Labour Day.
self._add_labor_day("Labour Day")

if year <= 2021:
# Commonwealth Day.
self._add_movable_holiday("Commonwealth Day", MAY, 24)

if year >= 2021:
# Emancipation Day.
self._add_movable_holiday("Emancipation Day", AUG, 1)

# Saint George's Caye Day.
self._add_holiday("Saint George's Caye Day", SEP, 10)

# Independence Day.
self._add_holiday("Independence Day", SEP, 21)

# Indigenous Peoples' Resistance Day / Pan American Day.
self._add_movable_holiday(
"Indigenous Peoples' Resistance Day"
if year >= 2021
else "Pan American Day",
date(year, OCT, 12),
)

# Garifuna Settlement Day.
self._add_holiday("Garifuna Settlement Day", NOV, 19)

# Populated before Christmas for right obvserved Christmas calculation
# (if Christmas falls on Sunday, there should be no observed Christmas
# on Monday)
# Boxing Day.
self._add_christmas_day_two("Boxing Day")

# Christmas Day.
self._add_christmas_day("Christmas Day")


class BZ(Belize):
pass


class BLZ(Belize):
pass
1 change: 1 addition & 0 deletions holidays/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"bangladesh": ("Bangladesh", "BD", "BGD"),
"belarus": ("Belarus", "BY", "BLR"),
"belgium": ("Belgium", "BE", "BEL"),
"belize": ("Belize", "BZ", "BLZ"),
"bolivia": ("Bolivia", "BO", "BOL"),
"bosnia_and_herzegovina": ("BosniaAndHerzegovina", "BA", "BIH"),
"botswana": ("Botswana", "BW", "BWA"),
Expand Down
Loading

0 comments on commit 22d9f48

Please sign in to comment.