Skip to content

Commit

Permalink
Merge branch 'beta' into international_childrens_day
Browse files Browse the repository at this point in the history
  • Loading branch information
PPsyrius committed Jun 15, 2023
2 parents b36ad6d + bf54ecd commit 52177be
Show file tree
Hide file tree
Showing 22 changed files with 926 additions and 458 deletions.
5 changes: 5 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
Version 0.27
============

- Refactor HolidayBase::pop_named (#1306 by @arkid15r)
- Refactor holiday groups (#1295 by @arkid15r)
- Add Brunei Darussalam holidays (#1168 by @PPsyrius, @arkid15r)
- Add Burkina Faso holidays (#1278 by @KJhellico)
- Add Chad holidays (#1279 by @KJhellico)
- Improve calendars and special holidays readability (#1296 by @arkid15r)
- Update Argentina holidays: fix movable holidays prior to 2010 (#1258 by @PPsyrius)
- Add Columbus day to InternationalHolidays (#1256 by @PPsyrius)
- Add Isle Of Man 1970 test (#1304 by @arkid15r)
- Migrate Angola holidays to holiday groups (#1276 by @kasya)
- Migrate Colombia to holiday groups (#1259 by @PPsyrius)
- Migrate South Africa holidays to holiday groups (#1301 by @KJhellico)
- Migrate remaining countries to custom calendar types (#1277 by @KJhellico)
- Migrate some African countries to holiday groups (#1302 by @KJhellico)
- Run entity import tests on latest Python version only (#1305 by @arkid15r)

Version 0.26
============
Expand Down
72 changes: 34 additions & 38 deletions holidays/countries/eswatini.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,12 @@
from datetime import date
from datetime import timedelta as td

from dateutil.easter import easter

from holidays.constants import JAN, APR, MAY, JUL, SEP, DEC
from holidays.constants import JAN, APR, JUL, SEP, DEC
from holidays.holiday_base import HolidayBase
from holidays.holiday_groups import ChristianHolidays, InternationalHolidays


class Eswatini(HolidayBase):
class Eswatini(HolidayBase, ChristianHolidays, InternationalHolidays):
"""
https://swazilii.org/sz/legislation/act/1938/71
https://www.officeholidays.com/countries/swaziland
Expand All @@ -32,59 +31,56 @@ class Eswatini(HolidayBase):
2000: (JAN, 3, "Y2K changeover"),
}

def _populate(self, year):
def _add_with_observed(
hol_date: date, hol_name: str, days: int = +1
) -> None:
# As of 2021/1/1, whenever a public holiday falls on a Sunday
# it rolls over to the following Monday
self[hol_date] = hol_name
if self.observed and self._is_sunday(hol_date) and year >= 2021:
self[hol_date + td(days=days)] = f"{hol_name} (Observed)"
def __init__(self, *args, **kwargs):
ChristianHolidays.__init__(self)
InternationalHolidays.__init__(self)
super().__init__(*args, **kwargs)

def _add_observed(self, dt: date, days: int = +1) -> None:
# As of 2021/1/1, whenever a public holiday falls on a Sunday
# it rolls over to the following Monday
if self.observed and self._is_sunday(dt) and self._year >= 2021:
self._add_holiday("%s (Observed)" % self[dt], dt + td(days=days))

def _populate(self, year):
# Observed since 1939
if year <= 1938:
return None

super()._populate(year)

_add_with_observed(date(year, JAN, 1), "New Year's Day")
self._add_observed(self._add_new_years_day("New Year's Day"))

easter_date = easter(year)
self[easter_date + td(days=-2)] = "Good Friday"
self[easter_date + td(days=+1)] = "Easter Monday"
self[easter_date + td(days=+39)] = "Ascension Day"
self._add_good_friday("Good Friday")

self._add_easter_monday("Easter Monday")

self._add_ascension_thursday("Ascension Day")

if year >= 1987:
# https://www.officeholidays.com/holidays/swaziland/birthday-of-king-mswati-iii
# In 2071, 2076, 2082 Apr 20 is Easter Monday,
# so observed on Apr 21 (Tue)
_add_with_observed(
date(year, APR, 19),
"King's Birthday",
+2 if year in {2071, 2076, 2082} else +1,
apr_19 = self._add_holiday("King's Birthday", APR, 19)
self._add_observed(
apr_19, days=+2 if apr_19 == self._easter_sunday else +1
)

if year >= 1969:
# In 2038 Apr 26 is Easter Monday,
# so observed on Apr 27 (Tue)
_add_with_observed(
date(year, APR, 25),
"National Flag Day",
+2 if year == 2038 else +1,
apr_25 = self._add_holiday("National Flag Day", APR, 25)
self._add_observed(
apr_25, days=+2 if apr_25 == self._easter_sunday else +1
)

_add_with_observed(date(year, MAY, 1), "Worker's Day")
self._add_observed(self._add_labor_day("Worker's Day"))

if year >= 1983:
# https://www.officeholidays.com/holidays/swaziland/birthday-of-late-king-sobhuza
_add_with_observed(
date(year, JUL, 22), "Birthday of Late King Sobhuza"
self._add_observed(
self._add_holiday("Birthday of Late King Sobhuza", JUL, 22)
)

_add_with_observed(date(year, SEP, 6), "Independence Day")
_add_with_observed(date(year, DEC, 25), "Christmas Day", days=+2)
_add_with_observed(date(year, DEC, 26), "Boxing Day")
self._add_observed(self._add_holiday("Independence Day", SEP, 6))

self._add_observed(self._add_christmas_day("Christmas Day"), days=+2)

self._add_observed(self._add_christmas_day_two("Boxing Day"))


class Swaziland(Eswatini):
Expand Down
84 changes: 52 additions & 32 deletions holidays/countries/lesotho.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,56 +9,76 @@
# Website: https://github.com/dr-prodigy/python-holidays
# License: MIT (see LICENSE file)

from datetime import date
from datetime import timedelta as td

from dateutil.easter import easter

from holidays.constants import JAN, MAR, APR, MAY, JUL, OCT, DEC
from holidays.constants import MAR, APR, MAY, JUL, OCT
from holidays.holiday_base import HolidayBase
from holidays.holiday_groups import ChristianHolidays, InternationalHolidays


class Lesotho(HolidayBase):
class Lesotho(HolidayBase, ChristianHolidays, InternationalHolidays):
"""
https://tinyurl.com/lesothosmallurl1324251
https://www.timeanddate.com/holidays/lesotho/
References:
- https://en.wikipedia.org/wiki/Public_holidays_in_Lesotho
- https://www.ilo.org/dyn/travail/docs/2093/Public%20Holidays%20Act%201995.pdf # noqa: E501
- https://www.timeanddate.com/holidays/lesotho/
"""

country = "LS"
special_holidays = {
# https://tinyurl.com/lesothourl
2002: ((APR, 4, "Heroes Day"), (MAY, 25, "Africa Day"))
2002: (MAY, 25, "Africa Day"),
}

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

def _populate(self, year):
if year <= 1995:
return None

super()._populate(year)

if year > 1995:
# https://www.ilo.org/dyn/travail/docs/2093/Public%20Holidays%20Act%201995.pdf
self[date(year, JAN, 1)] = "New Year's Day"
self[date(year, MAR, 11)] = "Moshoeshoe's Day"
# New Year's Day.
self._add_new_years_day("New Year's Day")

# Moshoeshoe's Day.
self._add_holiday("Moshoeshoe's Day", MAR, 11)

if year <= 2002:
# Heroes Day.
self._add_holiday("Heroes Day", APR, 4)

if year >= 2003:
# Africa/Heroes Day.
self._add_africa_day("Africa/Heroes Day")

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

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

# Workers' Day.
self._add_labor_day("Workers' Day")

if year < 2002:
self[date(year, APR, 4)] = "Heroes Day"
# Ascension Day.
self._add_ascension_thursday("Ascension Day")

if year > 2002:
self[date(year, MAY, 25)] = "Africa/Heroes Day"
# https://en.wikipedia.org/wiki/Letsie_III
self._add_holiday(
# King's Birthday.
"King's Birthday",
*((JUL, 17) if year >= 1998 else (MAY, 2)),
)

easter_date = easter(year)
self[easter_date + td(days=-2)] = "Good Friday"
self[easter_date + td(days=+1)] = "Easter Monday"
self[easter_date + td(days=+39)] = "Ascension Day"
self[date(year, MAY, 1)] = "Workers' Day"
# Independence Day.
self._add_holiday("Independence Day", OCT, 4)

if year > 1997:
# https://en.wikipedia.org/wiki/Letsie_III
self[date(year, JUL, 17)] = "King's Birthday"
if year <= 1997:
self[date(year, MAY, 2)] = "King's Birthday"
# Christmas Day.
self._add_christmas_day("Christmas Day")

self[date(year, OCT, 4)] = "National Independence Day"
self[date(year, DEC, 25)] = "Christmas Day"
self[date(year, DEC, 26)] = "Boxing Day"
# Boxing Day.
self._add_christmas_day_two("Boxing Day")


class LS(Lesotho):
Expand Down
60 changes: 34 additions & 26 deletions holidays/countries/malawi.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,51 +12,59 @@
from datetime import date
from datetime import timedelta as td

from dateutil.easter import easter

from holidays.constants import JAN, MAR, MAY, JUL, OCT, DEC
from holidays.constants import JAN, MAR, MAY, JUL, OCT
from holidays.holiday_base import HolidayBase
from holidays.holiday_groups import ChristianHolidays, InternationalHolidays


class Malawi(HolidayBase):
class Malawi(HolidayBase, ChristianHolidays, InternationalHolidays):
"""
https://www.officeholidays.com/countries/malawi
https://www.timeanddate.com/holidays/malawi/
"""

country = "MW"

def _populate(self, year):
def _add_with_observed(
hol_date: date, hol_name: str, days: int = +1
) -> None:
self[hol_date] = hol_name
if self.observed and self._is_weekend(hol_date):
obs_date = hol_date + td(
days=+2 if self._is_saturday(hol_date) else days
)
self[obs_date] = f"{hol_name} (Observed)"
def __init__(self, *args, **kwargs):
ChristianHolidays.__init__(self)
InternationalHolidays.__init__(self)
super().__init__(*args, **kwargs)

def _add_observed(self, dt: date, days: int = +1) -> None:
if self.observed and self._is_weekend(dt):
self._add_holiday(
"%s (Observed)" % self[dt],
dt + td(+2 if self._is_saturday(dt) else days),
)

def _populate(self, year):
# Observed since 2000
if year <= 1999:
return None

super()._populate(year)

_add_with_observed(date(year, JAN, 1), "New Year's Day")
_add_with_observed(date(year, JAN, 15), "John Chilembwe Day")
_add_with_observed(date(year, MAR, 3), "Martyrs Day")
self._add_observed(self._add_new_years_day("New Year's Day"))

self._add_observed(self._add_holiday("John Chilembwe Day", JAN, 15))

self._add_observed(self._add_holiday("Martyrs Day", MAR, 3))

self._add_good_friday("Good Friday")

self._add_easter_monday("Easter Monday")

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

self._add_observed(self._add_holiday("Kamuzu Day", MAY, 14))

self._add_observed(self._add_holiday("Independence Day", JUL, 6))

self._add_observed(self._add_holiday("Mother's Day", OCT, 15))

easter_date = easter(year)
self[easter_date + td(days=-2)] = "Good Friday"
self[easter_date + td(days=+1)] = "Easter Monday"
self._add_observed(self._add_christmas_day("Christmas Day"), days=+2)

_add_with_observed(date(year, MAY, 1), "Labour Day")
_add_with_observed(date(year, MAY, 14), "Kamuzu Day")
_add_with_observed(date(year, JUL, 6), "Independence Day")
_add_with_observed(date(year, OCT, 15), "Mother's Day")
_add_with_observed(date(year, DEC, 25), "Christmas Day", days=+2)
_add_with_observed(date(year, DEC, 26), "Boxing Day", days=+2)
self._add_observed(self._add_christmas_day_two("Boxing Day"), days=+2)


class MW(Malawi):
Expand Down
Loading

0 comments on commit 52177be

Please sign in to comment.