From 98663a45369d3538f0a97ef9681675cbaba24745 Mon Sep 17 00:00:00 2001 From: Arkadii Yakovets Date: Tue, 25 Oct 2022 11:09:47 -0700 Subject: [PATCH 001/138] Refactor weekdays/weekends logic. - Deprecate MON-SUN constants in favor of dateutil MO-SA. - Deprecate and move `WEEKENDS` from utils to HolidayBase (on per country basis as some countries have not usual SAT, SUN weekends). - Add `_is_weekend` method into `HolidayBase`. - Change isort multi-line import behavior to bracket-less. - Update flake8 settings in order to make it stricter. - Remove unused imports. - Remove unused/commented out code. --- holidays/__init__.py | 36 ++----- holidays/constants.py | 14 +++ holidays/countries/angola.py | 30 ++---- holidays/countries/argentina.py | 42 +++----- holidays/countries/aruba.py | 6 +- holidays/countries/australia.py | 33 +++---- holidays/countries/azerbaijan.py | 9 +- holidays/countries/bolivia.py | 28 ++---- holidays/countries/botswana.py | 7 +- holidays/countries/brazil.py | 15 +-- holidays/countries/bulgaria.py | 2 +- holidays/countries/burundi.py | 17 ++-- holidays/countries/canada.py | 37 +++---- holidays/countries/chile.py | 37 +++---- holidays/countries/colombia.py | 8 +- holidays/countries/cuba.py | 10 +- holidays/countries/curacao.py | 8 +- holidays/countries/czechia.py | 1 - holidays/countries/djibouti.py | 21 +--- holidays/countries/dominican_republic.py | 6 +- holidays/countries/egypt.py | 18 +--- holidays/countries/eswatini.py | 9 +- holidays/countries/ethiopia.py | 4 +- holidays/countries/germany.py | 4 +- holidays/countries/greece.py | 4 +- holidays/countries/hongkong.py | 56 +++++------ holidays/countries/hungary.py | 29 ++---- holidays/countries/ireland.py | 49 ++++----- holidays/countries/israel.py | 15 +-- holidays/countries/italy.py | 16 +-- holidays/countries/jamaica.py | 10 +- holidays/countries/japan.py | 16 +-- holidays/countries/kenya.py | 6 +- holidays/countries/korea.py | 19 +--- holidays/countries/malawi.py | 7 +- holidays/countries/malaysia.py | 21 +--- holidays/countries/mexico.py | 24 ++--- holidays/countries/morocco.py | 13 --- holidays/countries/mozambique.py | 7 +- holidays/countries/namibia.py | 9 +- holidays/countries/netherlands.py | 8 +- holidays/countries/new_zealand.py | 47 +++------ holidays/countries/nigeria.py | 5 +- holidays/countries/norway.py | 21 ++-- holidays/countries/paraguay.py | 26 ++--- holidays/countries/poland.py | 1 - holidays/countries/portugal.py | 15 +-- holidays/countries/saudi_arabia.py | 24 +++-- holidays/countries/serbia.py | 11 ++- holidays/countries/singapore.py | 25 ++--- holidays/countries/slovakia.py | 1 - holidays/countries/south_africa.py | 28 ++---- holidays/countries/spain.py | 21 +--- holidays/countries/sweden.py | 38 +++---- holidays/countries/tunisia.py | 19 +--- holidays/countries/ukraine.py | 47 +++------ holidays/countries/united_arab_emirates.py | 18 +--- holidays/countries/united_kingdom.py | 58 ++++------- holidays/countries/united_states.py | 110 +++++++++------------ holidays/countries/uruguay.py | 35 +++---- holidays/countries/vietnam.py | 9 +- holidays/countries/zambia.py | 5 +- holidays/countries/zimbabwe.py | 13 ++- holidays/financial/ny_stock_exchange.py | 26 ++--- holidays/holiday_base.py | 25 +++-- pyproject.toml | 1 + setup.cfg | 13 +-- test/__init__.py | 12 --- test/countries/test_czechia.py | 1 - test/countries/test_india.py | 2 +- test/countries/test_malaysia.py | 16 +-- test/countries/test_malta.py | 1 - test/countries/test_poland.py | 1 - test/countries/test_slovakia.py | 1 - test/countries/test_spain.py | 3 - test/countries/test_united_kingdom.py | 1 - test/countries/test_united_states.py | 10 +- test/financial/test_ny_stock_exchange.py | 18 +--- test/test_holiday_base.py | 21 +++- 79 files changed, 514 insertions(+), 926 deletions(-) diff --git a/holidays/__init__.py b/holidays/__init__.py index f3d407360..13db5720b 100644 --- a/holidays/__init__.py +++ b/holidays/__init__.py @@ -8,37 +8,13 @@ # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) -from holidays.constants import ( - MON, - TUE, - WED, - THU, - FRI, - SAT, - SUN, - WEEKEND, - JAN, - FEB, - MAR, - APR, - MAY, - JUN, - JUL, - AUG, - SEP, - OCT, - NOV, - DEC, -) +from holidays.constants import JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP +from holidays.constants import OCT, NOV, DEC from holidays.countries import * from holidays.financial import * -from holidays.holiday_base import * # * import required for IDE docstrings -from holidays.utils import ( - CountryHoliday, - country_holidays, - financial_holidays, - list_supported_countries, - list_supported_financial, -) +from holidays.holiday_base import HolidayBase, HolidaySum +from holidays.utils import CountryHoliday, country_holidays +from holidays.utils import financial_holidays, list_supported_countries +from holidays.utils import list_supported_financial __version__ = "0.17" diff --git a/holidays/constants.py b/holidays/constants.py index 795cbd306..db4319cf9 100644 --- a/holidays/constants.py +++ b/holidays/constants.py @@ -9,7 +9,21 @@ # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) +import warnings + +warnings.warn( + "Weekday constants (MON, TUE, WED, THU, FRI, SAT, SUN) are deprecated " + "in favor of MO, TU, WE, TH, FR, SA, SU objects from " + "dateutil.relativedelta.", + DeprecationWarning, +) MON, TUE, WED, THU, FRI, SAT, SUN = range(7) + + +warnings.warn( + "WEEKEND is deprecated. Use HolidayBase.weekend instead.", + DeprecationWarning, +) WEEKEND = (SAT, SUN) JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC = range(1, 13) diff --git a/holidays/countries/angola.py b/holidays/countries/angola.py index dfc7fcdce..686043fec 100644 --- a/holidays/countries/angola.py +++ b/holidays/countries/angola.py @@ -13,21 +13,9 @@ from dateutil.easter import easter from dateutil.relativedelta import relativedelta as rd +from dateutil.relativedelta import MO, TU, TH, SU -from holidays.constants import ( - MON, - TUE, - THU, - SUN, - JAN, - FEB, - MAR, - APR, - MAY, - SEP, - NOV, - DEC, -) +from holidays.constants import JAN, FEB, MAR, APR, MAY, SEP, NOV, DEC from holidays.holiday_base import HolidayBase @@ -50,7 +38,7 @@ def _populate(self, year: int) -> None: # Since 2018, if the following year's New Year's Day falls on a # Tuesday, the 31st of the current year is also a holiday. if year >= 2018: - if self.observed and date(year, DEC, 31).weekday() == MON: + if self.observed and date(year, DEC, 31).weekday() == MO.weekday: self[date(year, DEC, 31)] = "Ano novo (Day off)" e = easter(year) @@ -60,7 +48,7 @@ def _populate(self, year: int) -> None: # carnival is the Tuesday before Ash Wednesday # which is 40 days before easter excluding sundays carnival = e - rd(days=46) - while carnival.weekday() != TUE: + while carnival.weekday() != TU.weekday: carnival = carnival - rd(days=1) self[carnival] = "Carnaval" @@ -86,17 +74,17 @@ def _populate(self, year: int) -> None: # the Monday or Friday is also a holiday for k, v in list(self.items()): if self.observed and year > 1974: - if k.weekday() == SUN: + if k.weekday() == SU.weekday: self[k + rd(days=1)] = v + " (Observed)" if self.observed and year > 2017: - if k.weekday() == SUN: + if k.weekday() == SU.weekday: pass if self.observed and year > 2017: - if k.weekday() == TUE and k != date(year, JAN, 1): + if k.weekday() == TU.weekday and k != date(year, JAN, 1): self[k - rd(days=1)] = v + " (Day off)" - elif k.weekday() == THU: + elif k.weekday() == TH.weekday: self[k + rd(days=1)] = v + " (Day off)" - if self.observed and year > 1994 and k.weekday() == SUN: + if self.observed and year > 1994 and k.weekday() == SU.weekday: self[k + rd(days=1)] = v + " (Observed)" diff --git a/holidays/countries/argentina.py b/holidays/countries/argentina.py index ebffe07d1..6f8e0e372 100644 --- a/holidays/countries/argentina.py +++ b/holidays/countries/argentina.py @@ -15,21 +15,11 @@ from dateutil.relativedelta import relativedelta as rd from dateutil.relativedelta import TH, FR -from holidays.constants import ( - WEEKEND, - JAN, - MAR, - APR, - MAY, - JUN, - JUL, - AUG, - OCT, - NOV, - DEC, -) +from holidays.constants import JAN, MAR, APR, MAY, JUN, JUL, AUG, OCT, NOV, DEC from holidays.holiday_base import HolidayBase +# from dateutil.rrule import weekday + class Argentina(HolidayBase): # https://www.argentina.gob.ar/interior/feriados @@ -44,7 +34,7 @@ def __init__(self, **kwargs): def _populate(self, year): # New Year's Day - if not self.observed and date(year, JAN, 1).weekday() in WEEKEND: + if not self.observed and self._is_weekend(date(year, JAN, 1)): pass else: self[date(year, JAN, 1)] = "Año Nuevo [New Year's Day]" @@ -60,7 +50,7 @@ def _populate(self, year): "[Memory's National Day for the Truth and Justice]" ) - if not self.observed and date(year, MAR, 24).weekday() in WEEKEND: + if not self.observed and self._is_weekend(date(year, MAR, 24)): pass else: self[date(year, MAR, 24)] = name @@ -73,13 +63,13 @@ def _populate(self, year): self[easter(year) + rd(weekday=TH(-1))] = name_thu self[easter(year) + rd(weekday=FR(-1))] = name_fri - if not self.observed and easter(year).weekday() in WEEKEND: + if not self.observed and self._is_weekend(easter(year)): pass else: self[easter(year)] = name_easter # Veterans Day and the Fallen in the Malvinas War - if not self.observed and date(year, APR, 2).weekday() in WEEKEND: + if not self.observed and self._is_weekend(date(year, APR, 2)): pass else: self[date(year, APR, 2)] = ( @@ -91,14 +81,14 @@ def _populate(self, year): # Labor Day name = "Día del Trabajo [Labour Day]" - if not self.observed and date(year, MAY, 1).weekday() in WEEKEND: + if not self.observed and self._is_weekend(date(year, MAY, 1)): pass else: self[date(year, MAY, 1)] = name # May Revolution Day name = "Día de la Revolucion de Mayo [May Revolution Day]" - if not self.observed and date(year, MAY, 25).weekday() in WEEKEND: + if not self.observed and self._is_weekend(date(year, MAY, 25)): pass else: self[date(year, MAY, 25)] = name @@ -109,7 +99,7 @@ def _populate(self, year): "del General Martín Miguel de Güemes [Day Pass " "to the Immortality of General Martín Miguel de Güemes]" ) - if not self.observed and date(year, JUN, 17).weekday() in WEEKEND: + if not self.observed and self._is_weekend(date(year, JUN, 17)): pass else: self[date(year, JUN, 17)] = name @@ -120,14 +110,14 @@ def _populate(self, year): "del General D. Manuel Belgrano [Day Pass " "to the Immortality of General D. Manuel Belgrano]" ) - if not self.observed and date(year, JUN, 20).weekday() in WEEKEND: + if not self.observed and self._is_weekend(date(year, JUN, 20)): pass else: self[date(year, JUN, 20)] = name # Independence Day name = "Día de la Independencia [Independence Day]" - if not self.observed and date(year, JUL, 9).weekday() in WEEKEND: + if not self.observed and self._is_weekend(date(year, JUL, 9)): pass else: self[date(year, JUL, 9)] = name @@ -138,13 +128,13 @@ def _populate(self, year): "del General D. José de San Martin [Day Pass " "to the Immortality of General D. José de San Martin]" ) - if not self.observed and date(year, AUG, 17).weekday() in WEEKEND: + if not self.observed and self._is_weekend(date(year, AUG, 17)): pass else: self[date(year, AUG, 17)] = name # Respect for Cultural Diversity Day or Columbus day - if not self.observed and date(year, OCT, 12).weekday() in WEEKEND: + if not self.observed and self._is_weekend(date(year, OCT, 12)): pass elif year < 2010: self[date(year, OCT, 12)] = "Día de la Raza [Columbus day]" @@ -156,13 +146,13 @@ def _populate(self, year): ) # National Sovereignty Day name = "Día Nacional de la Soberanía [National Sovereignty Day]" - if not self.observed and date(year, NOV, 20).weekday() in WEEKEND: + if not self.observed and self._is_weekend(date(year, NOV, 20)): pass elif year >= 2010: self[date(year, NOV, 20)] = name # Immaculate Conception - if not self.observed and date(year, DEC, 8).weekday() in WEEKEND: + if not self.observed and self._is_weekend(date(year, DEC, 8)): pass else: self[date(year, DEC, 8)] = ( diff --git a/holidays/countries/aruba.py b/holidays/countries/aruba.py index 8cd858e9c..a2f4d2246 100644 --- a/holidays/countries/aruba.py +++ b/holidays/countries/aruba.py @@ -13,7 +13,7 @@ from dateutil.easter import easter from dateutil.relativedelta import relativedelta as rd -from dateutil.relativedelta import FR +from dateutil.relativedelta import FR, SU from holidays.constants import JAN, MAR, APR, MAY, AUG, DEC from holidays.holiday_base import HolidayBase @@ -59,7 +59,7 @@ def _populate(self, year): # King's Day if year >= 2014: kings_day = date(year, APR, 27) - if kings_day.weekday() == 6: + if kings_day.weekday() == SU.weekday: kings_day = kings_day - rd(days=1) self[kings_day] = "Aña di Rey [King's Day]" @@ -70,7 +70,7 @@ def _populate(self, year): if year <= 1948: queens_day = date(year, AUG, 31) - if queens_day.weekday() == 6: + if queens_day.weekday() == SU.weekday: if year < 1980: queens_day = queens_day + rd(days=1) else: diff --git a/holidays/countries/australia.py b/holidays/countries/australia.py index 280a98a0f..8eb4dd1a4 100644 --- a/holidays/countries/australia.py +++ b/holidays/countries/australia.py @@ -13,23 +13,9 @@ from dateutil.easter import easter from dateutil.relativedelta import relativedelta as rd -from dateutil.relativedelta import MO, TU, WE, FR, SA +from dateutil.relativedelta import MO, TU, WE, FR, SA, SU -from holidays.constants import ( - SAT, - SUN, - WEEKEND, - JAN, - MAR, - APR, - MAY, - JUN, - AUG, - SEP, - OCT, - NOV, - DEC, -) +from holidays.constants import JAN, MAR, APR, MAY, JUN, AUG, SEP, OCT, NOV, DEC from holidays.holiday_base import HolidayBase @@ -56,7 +42,7 @@ def _populate(self, year): name = "New Year's Day" jan1 = date(year, JAN, 1) self[jan1] = name - if self.observed and jan1.weekday() in WEEKEND: + if self.observed and self._is_weekend(jan1): self[jan1 + rd(weekday=MO)] = name + " (Observed)" # Australia Day @@ -67,7 +53,7 @@ def _populate(self, year): else: name = "Australia Day" self[jan26] = name - if self.observed and year >= 1946 and jan26.weekday() in WEEKEND: + if self.observed and year >= 1946 and self._is_weekend(jan26): self[jan26 + rd(weekday=MO)] = name + " (Observed)" elif year >= 1888 and self.subdiv != "SA": name = "Anniversary Day" @@ -110,9 +96,12 @@ def _populate(self, year): apr25 = date(year, APR, 25) self[apr25] = name if self.observed: - if apr25.weekday() == SAT and self.subdiv in ("WA", "NT"): + if apr25.weekday() == SA.weekday and self.subdiv in ( + "WA", + "NT", + ): self[apr25 + rd(weekday=MO)] = name + " (Observed)" - elif apr25.weekday() == SUN and self.subdiv in ( + elif apr25.weekday() == SU.weekday and self.subdiv in ( "ACT", "QLD", "SA", @@ -258,7 +247,7 @@ def _populate(self, year): name = "Christmas Day" dec25 = date(year, DEC, 25) self[dec25] = name - if self.observed and dec25.weekday() in WEEKEND: + if self.observed and self._is_weekend(dec25): self[date(year, DEC, 27)] = name + " (Observed)" # Boxing Day @@ -268,7 +257,7 @@ def _populate(self, year): name = "Boxing Day" dec26 = date(year, DEC, 26) self[dec26] = name - if self.observed and dec26.weekday() in WEEKEND: + if self.observed and self._is_weekend(dec26): self[date(year, DEC, 28)] = name + " (Observed)" diff --git a/holidays/countries/azerbaijan.py b/holidays/countries/azerbaijan.py index b5cabddc7..9b8b13949 100644 --- a/holidays/countries/azerbaijan.py +++ b/holidays/countries/azerbaijan.py @@ -12,8 +12,9 @@ from datetime import date from dateutil.relativedelta import relativedelta as rd +from dateutil.relativedelta import SA, SU -from holidays.constants import SAT, SUN, JAN, MAR, MAY, JUN, OCT, NOV, DEC +from holidays.constants import JAN, MAR, MAY, JUN, OCT, NOV, DEC from holidays.holiday_base import HolidayBase from holidays.utils import _islamic_to_gre @@ -30,7 +31,7 @@ def __init__(self, **kwargs): HolidayBase.__init__(self, **kwargs) def _add_observed(self, holiday: date) -> None: - if self.observed and holiday.weekday() in (SAT, SUN): + if self.observed and self._is_weekend(holiday): next_monday = holiday + rd(days=7 - holiday.weekday()) if next_monday.year == holiday.year and not self.get( next_monday, None @@ -90,12 +91,12 @@ def _populate(self, year: int) -> None: # If the prior year's International Solidarity Day of Azerbaijanis # falls on a Saturday or Monday, the 1st Monday of the current year is # also a holiday. - if self.observed and date(year - 1, DEC, 31).weekday() == SUN: + if self.observed and date(year - 1, DEC, 31).weekday() == SU.weekday: self[date(year, JAN, 1)] = ( "International Solidarity Day of Azerbaijanis" + OBSERVED_SUFFIX ) - elif self.observed and date(year - 1, DEC, 31).weekday() == SAT: + elif self.observed and date(year - 1, DEC, 31).weekday() == SA.weekday: self[date(year, JAN, 2)] = ( "International Solidarity Day of Azerbaijanis" + OBSERVED_SUFFIX diff --git a/holidays/countries/bolivia.py b/holidays/countries/bolivia.py index 5cfbbbe78..e816d19ef 100644 --- a/holidays/countries/bolivia.py +++ b/holidays/countries/bolivia.py @@ -13,22 +13,10 @@ from datetime import date from dateutil.easter import easter -from dateutil.relativedelta import FR +from dateutil.relativedelta import FR, SU from dateutil.relativedelta import relativedelta as rd -from holidays.constants import ( - SUN, - JAN, - APR, - MAY, - JUN, - JUL, - AUG, - SEP, - OCT, - NOV, - DEC, -) +from holidays.constants import JAN, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC from holidays.holiday_base import HolidayBase @@ -57,7 +45,7 @@ def _populate(self, year): if year >= 1825: self[date(year, JAN, 1)] = name - if self.observed and date(year, JAN, 1).weekday() == SUN: + if self.observed and date(year, JAN, 1).weekday() == SU.weekday: self[date(year, JAN, 1) + rd(days=+1)] = f"{name} (Observed)" # Plurinational State Foundation Day. @@ -86,7 +74,7 @@ def _populate(self, year): name = "Dia del trabajo" self[date(year, MAY, 1)] = name - if self.observed and date(year, MAY, 1).weekday() == SUN: + if self.observed and date(year, MAY, 1).weekday() == SU.weekday: self[date(year, MAY, 1) + rd(days=+1)] = f"{name} (Observed)" # Chuquisaca Day. @@ -101,7 +89,7 @@ def _populate(self, year): if year >= 2010: self[date(year, JUN, 21)] = name - if self.observed and date(year, JUN, 21).weekday() == SUN: + if self.observed and date(year, JUN, 21).weekday() == SU.weekday: self[date(year, JUN, 21) + rd(days=+1)] = f"{name} (Observed)" # La Paz Day. @@ -117,7 +105,7 @@ def _populate(self, year): if year >= 1825: self[date(year, AUG, 6)] = name - if self.observed and date(year, AUG, 6).weekday() > 5: + if self.observed and date(year, AUG, 6).weekday() > FR.weekday: self[date(year, AUG, 6) + rd(days=+1)] = f"{name} (Observed)" # Cochabamba Day. @@ -136,7 +124,7 @@ def _populate(self, year): name = "Todos Santos" self[date(year, NOV, 2)] = name - if self.observed and date(year, NOV, 2).weekday() == SUN: + if self.observed and date(year, NOV, 2).weekday() == SU.weekday: self[date(year, NOV, 2) + rd(days=+1)] = f"{name} (Observed)" # Potosí Day. @@ -151,7 +139,7 @@ def _populate(self, year): name = "Navidad" self[date(year, DEC, 25)] = name - if self.observed and date(year, DEC, 25).weekday() == SUN: + if self.observed and date(year, DEC, 25).weekday() == SU.weekday: self[date(year, DEC, 25) + rd(days=+1)] = f"{name} (Observed)" diff --git a/holidays/countries/botswana.py b/holidays/countries/botswana.py index f74d8eae6..509d84493 100644 --- a/holidays/countries/botswana.py +++ b/holidays/countries/botswana.py @@ -13,8 +13,9 @@ from dateutil.easter import easter from dateutil.relativedelta import relativedelta as rd +from dateutil.relativedelta import SA, SU -from holidays.constants import SAT, SUN, MAY, JUL, SEP, OCT, DEC +from holidays.constants import MAY, JUL, SEP, OCT, DEC from holidays.holiday_base import HolidayBase @@ -72,7 +73,7 @@ def _populate(self, year: int): if ( self.observed and year > 2015 - and k.weekday() == SAT + and k.weekday() == SA.weekday and k.year == year and v.upper() in ("BOXING DAY", "LABOUR DAY") ): @@ -81,7 +82,7 @@ def _populate(self, year: int): if ( self.observed and year > 1994 - and k.weekday() == SUN + and k.weekday() == SU.weekday and k.year == year and v.upper() != "NEW YEAR'S DAY HOLIDAY" ): diff --git a/holidays/countries/brazil.py b/holidays/countries/brazil.py index 1edaf9a94..2effa954d 100644 --- a/holidays/countries/brazil.py +++ b/holidays/countries/brazil.py @@ -15,19 +15,8 @@ from dateutil.relativedelta import relativedelta as rd from dateutil.relativedelta import TU -from holidays.constants import ( - JAN, - MAR, - APR, - MAY, - JUN, - JUL, - AUG, - SEP, - OCT, - NOV, - DEC, -) +from holidays.constants import JAN, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT +from holidays.constants import NOV, DEC from holidays.holiday_base import HolidayBase diff --git a/holidays/countries/bulgaria.py b/holidays/countries/bulgaria.py index 706944ad9..8d60aba27 100644 --- a/holidays/countries/bulgaria.py +++ b/holidays/countries/bulgaria.py @@ -14,7 +14,7 @@ from dateutil.easter import EASTER_ORTHODOX, easter from dateutil.relativedelta import relativedelta as rd -from holidays.constants import JAN, MAR, APR, MAY, SEP, NOV, DEC +from holidays.constants import JAN, MAR, MAY, SEP, NOV, DEC from holidays.holiday_base import HolidayBase diff --git a/holidays/countries/burundi.py b/holidays/countries/burundi.py index 4c288fc17..bf828b570 100644 --- a/holidays/countries/burundi.py +++ b/holidays/countries/burundi.py @@ -13,8 +13,9 @@ from dateutil.easter import easter from dateutil.relativedelta import relativedelta as rd +from dateutil.relativedelta import SU -from holidays.constants import SUN, JAN, FEB, APR, MAY, JUL, AUG, OCT, NOV, DEC +from holidays.constants import JAN, FEB, APR, MAY, JUL, AUG, OCT, NOV, DEC from holidays.holiday_base import HolidayBase from holidays.utils import _islamic_to_gre @@ -51,19 +52,19 @@ def _add_holiday(dt: date, hol: str) -> None: # Unity Day name = "Unity Day" self[date(year, FEB, 5)] = name - if date(year, FEB, 5).weekday() == SUN: + if date(year, FEB, 5).weekday() == SU.weekday: self[date(year, FEB, 6)] = name + " (Observed)" # President Ntaryamira Day name = "President Ntaryamira Day" self[date(year, APR, 6)] = "President Ntaryamira Day" - if date(year, APR, 6).weekday() == SUN: + if date(year, APR, 6).weekday() == SU.weekday: self[date(year, APR, 7)] = name + " (Observed)" # Labour Day name = "Labour Day" self[date(year, MAY, 1)] = name - if date(year, MAY, 1).weekday() == SUN: + if date(year, MAY, 1).weekday() == SU.weekday: self[date(year, MAY, 2)] = name + " (Observed)" # Ascension Day @@ -74,7 +75,7 @@ def _add_holiday(dt: date, hol: str) -> None: name = "Independence Day" if year > 1961: self[date(year, JUL, 1)] = name - if date(year, JUL, 1).weekday() == SUN: + if date(year, JUL, 1).weekday() == SU.weekday: self[date(year, JUL, 2)] = name + " (Observed)" # Eid Al Adha- Feast of the Sacrifice @@ -92,19 +93,19 @@ def _add_holiday(dt: date, hol: str) -> None: # Prince Louis Rwagasore Day name = "Prince Louis Rwagasore Day" self[date(year, OCT, 13)] = name - if date(year, OCT, 13).weekday() == SUN: + if date(year, OCT, 13).weekday() == SU.weekday: self[date(year, OCT, 14)] = name + " (Observed)" # President Ndadaye's Day name = "President Ndadaye's Day" self[date(year, OCT, 21)] = name - if date(year, OCT, 21).weekday() == SUN: + if date(year, OCT, 21).weekday() == SU.weekday: self[date(year, OCT, 22)] = name + " (Observed)" # All Saints' Day name = "All Saints' Day" self[date(year, NOV, 1)] = name - if date(year, NOV, 1).weekday() == SUN: + if date(year, NOV, 1).weekday() == SU.weekday: self[date(year, NOV, 2)] = name + " (Observed)" # Christmas Day diff --git a/holidays/countries/canada.py b/holidays/countries/canada.py index 66dd777bf..eaf9e58d6 100644 --- a/holidays/countries/canada.py +++ b/holidays/countries/canada.py @@ -15,23 +15,8 @@ from dateutil.relativedelta import relativedelta as rd from dateutil.relativedelta import MO, FR, SU -from holidays.constants import ( - FRI, - SUN, - WEEKEND, - JAN, - FEB, - MAR, - APR, - MAY, - JUN, - JUL, - AUG, - SEP, - OCT, - NOV, - DEC, -) +from holidays.constants import JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP +from holidays.constants import OCT, NOV, DEC from holidays.holiday_base import HolidayBase @@ -64,11 +49,11 @@ def _populate(self, year): if year >= 1867: name = "New Year's Day" self[date(year, JAN, 1)] = name - if self.observed and date(year, JAN, 1).weekday() == SUN: + if self.observed and date(year, JAN, 1).weekday() == SU.weekday: self[date(year, JAN, 1) + rd(days=+1)] = name + " (Observed)" # The following year's observed New Year's Day can be in this year # when it falls on a Friday (Jan 1st is a Saturday). - if self.observed and date(year, DEC, 31).weekday() == FRI: + if self.observed and date(year, DEC, 31).weekday() == FR.weekday: self[date(year, DEC, 31)] = name + " (Observed)" # Family Day / Louis Riel Day (MB) / Islander Day (PE) @@ -149,7 +134,7 @@ def _populate(self, year): # St. Jean Baptiste Day if self.subdiv == "QC" and year >= 1925: self[date(year, JUN, 24)] = "St. Jean Baptiste Day" - if self.observed and date(year, JUN, 24).weekday() == SUN: + if self.observed and date(year, JUN, 24).weekday() == SU.weekday: self[date(year, JUN, 25)] = "St. Jean Baptiste Day (Observed)" # Discovery Day @@ -175,7 +160,7 @@ def _populate(self, year): if ( year >= 1879 and self.observed - and date(year, JUL, 1).weekday() in WEEKEND + and self._is_weekend(date(year, JUL, 1)) ): self[date(year, JUL, 1) + rd(weekday=MO)] = ( name + " (Observed)" @@ -189,7 +174,7 @@ def _populate(self, year): if ( year >= 1879 and self.observed - and date(year, JUL, 1).weekday() in WEEKEND + and self._is_weekend(date(year, JUL, 1)) ): self[date(year, JUL, 1) + rd(weekday=MO)] = ( name + " (Observed)" @@ -198,7 +183,7 @@ def _populate(self, year): # Nunavut Day if self.subdiv == "NU" and year >= 2001: self[date(year, JUL, 9)] = "Nunavut Day" - if self.observed and date(year, JUL, 9).weekday() == SUN: + if self.observed and date(year, JUL, 9).weekday() == SU.weekday: self[date(year, JUL, 10)] = "Nunavut Day (Observed)" elif self.subdiv == "NU" and year == 2000: self[date(2000, 4, 1)] = "Nunavut Day" @@ -257,7 +242,7 @@ def _populate(self, year): self[date(year, NOV, 11)] = name elif self.subdiv in ("NS", "NL", "NT", "PE", "SK") and year >= 1931: self[date(year, NOV, 11)] = name - if self.observed and date(year, NOV, 11).weekday() == SUN: + if self.observed and date(year, NOV, 11).weekday() == SU.weekday: name = name + " (Observed)" self[date(year, NOV, 11) + rd(weekday=MO)] = name @@ -265,14 +250,14 @@ def _populate(self, year): if year >= 1867: name = "Christmas Day" self[date(year, DEC, 25)] = name - if self.observed and date(year, DEC, 25).weekday() in WEEKEND: + if self.observed and self._is_weekend(date(year, DEC, 25)): self[date(year, DEC, 27)] = name + " (Observed)" # Boxing Day if year >= 1867: name = "Boxing Day" self[date(year, DEC, 26)] = name - if self.observed and date(year, DEC, 26).weekday() in WEEKEND: + if self.observed and self._is_weekend(date(year, DEC, 26)): self[date(year, DEC, 28)] = name + " (Observed)" diff --git a/holidays/countries/chile.py b/holidays/countries/chile.py index a7dfad2be..2163b4614 100644 --- a/holidays/countries/chile.py +++ b/holidays/countries/chile.py @@ -13,24 +13,9 @@ from dateutil.easter import easter from dateutil.relativedelta import relativedelta as rd -from dateutil.relativedelta import MO, FR, SA - -from holidays.constants import ( - TUE, - THU, - FRI, - SAT, - SUN, - JAN, - MAY, - JUN, - JUL, - AUG, - SEP, - OCT, - NOV, - DEC, -) +from dateutil.relativedelta import MO, TU, TH, FR, SA, SU + +from holidays.constants import JAN, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC from holidays.holiday_base import HolidayBase @@ -68,7 +53,7 @@ def _populate(self, year): # New Year's Day (Law 2.977) self[date(year, JAN, 1)] = "Año Nuevo [New Year's Day]" # Day after, if it's a Sunday (Law 20.983) - if year > 2016 and date(year, JAN, 1).weekday() == SUN: + if year > 2016 and date(year, JAN, 1).weekday() == SU.weekday: self[date(year, JAN, 2)] = "Fiestas Patrias [Holiday]" # Holy Week (Law 2.977) @@ -100,12 +85,12 @@ def _populate(self, year): self[date(year, JUN, 29)] = name else: # floating Monday holiday (Law 19.668) - if date(year, JUN, 29).weekday() <= THU: + if date(year, JUN, 29).weekday() <= TH.weekday: self[ date(year, JUN, 29) + rd(date(year, JUN, 29), weekday=MO(-1)) ] = name - elif date(year, JUN, 29).weekday() == FRI: + elif date(year, JUN, 29).weekday() == FR.weekday: self[date(year, JUN, 29) + rd(weekday=MO)] = name else: self[date(year, JUN, 29)] = name @@ -120,11 +105,11 @@ def _populate(self, year): self[date(year, AUG, 15)] = name # National Holiday Friday preceding Independence Day (Law 20.983) - if year > 2016 and date(year, SEP, 18).weekday() == SAT: + if year > 2016 and date(year, SEP, 18).weekday() == SA.weekday: self[date(year, SEP, 17)] = "Fiestas Patrias [Holiday]" # National Holiday Monday preceding Independence Day (Law 20.215) - if year > 2007 and date(year, SEP, 18).weekday() == TUE: + if year > 2007 and date(year, SEP, 18).weekday() == TU.weekday: self[date(year, SEP, 17)] = "Fiestas Patrias [Holiday]" # Independence Day (Law 2.977) @@ -136,7 +121,7 @@ def _populate(self, year): self[date(year, SEP, 19)] = name # National Holiday Friday following Army Day (Law 20.215) - if year > 2007 and date(year, SEP, 19).weekday() == THU: + if year > 2007 and date(year, SEP, 19).weekday() == TH.weekday: self[date(year, SEP, 20)] = "Fiestas Patrias [Holiday]" # Day of the Meeting of Two Worlds (Law 3.810) @@ -151,12 +136,12 @@ def _populate(self, year): else: # floating Monday holiday (Law 19.668) name = "Día del Descubrimiento de dos Mundos [Columbus Day]" - if date(year, OCT, 12).weekday() <= THU: + if date(year, OCT, 12).weekday() <= TH.weekday: self[ date(year, OCT, 12) + rd(date(year, OCT, 12), weekday=MO(-1)) ] = name - elif date(year, OCT, 12).weekday() == FRI: + elif date(year, OCT, 12).weekday() == FR.weekday: self[date(year, OCT, 12) + rd(weekday=MO)] = name else: self[date(year, OCT, 12)] = name diff --git a/holidays/countries/colombia.py b/holidays/countries/colombia.py index 4456662f1..f28149c5e 100644 --- a/holidays/countries/colombia.py +++ b/holidays/countries/colombia.py @@ -15,7 +15,7 @@ from dateutil.relativedelta import relativedelta as rd from dateutil.relativedelta import MO, TH, FR -from holidays.constants import MON, JAN, MAR, MAY, JUN, JUL, AUG, OCT, NOV, DEC +from holidays.constants import JAN, MAR, MAY, JUN, JUL, AUG, OCT, NOV, DEC from holidays.holiday_base import HolidayBase @@ -49,7 +49,11 @@ def _add_with_bridge(self, _date, name): 1984: https://bit.ly/3B7ogt8 """ - if self.observed and _date.weekday() != MON and _date.year > 1983: + if ( + self.observed + and _date.weekday() != MO.weekday + and _date.year > 1983 + ): self[_date + rd(weekday=MO)] = name + " (Observed)" else: self[_date] = name diff --git a/holidays/countries/cuba.py b/holidays/countries/cuba.py index 72d42c198..c8423ab9a 100644 --- a/holidays/countries/cuba.py +++ b/holidays/countries/cuba.py @@ -13,9 +13,9 @@ from dateutil.easter import easter from dateutil.relativedelta import relativedelta as rd -from dateutil.relativedelta import MO +from dateutil.relativedelta import MO, SU -from holidays.constants import SUN, JAN, MAY, JUL, OCT, DEC +from holidays.constants import JAN, MAY, JUL, OCT, DEC from holidays.holiday_base import HolidayBase @@ -45,7 +45,7 @@ def _populate(self, year): if ( year <= 2013 and self.observed - and date(year, JAN, 1).weekday() == SUN + and date(year, JAN, 1).weekday() == SU.weekday ): self[date(year, JAN, 1) + rd(weekday=MO)] = name + " (Observed)" @@ -62,7 +62,7 @@ def _populate(self, year): name = "Día Internacional de los Trabajadores [Labour Day]" self[date(year, MAY, 1)] = name - if self.observed and date(year, MAY, 1).weekday() == SUN: + if self.observed and date(year, MAY, 1).weekday() == SU.weekday: self[date(year, MAY, 1) + rd(weekday=MO)] = name + " (Observed)" self[date(year, JUL, 25)] = ( @@ -81,7 +81,7 @@ def _populate(self, year): name = "Inicio de las Guerras de Independencia [Independence Day]" self[date(year, OCT, 10)] = name - if self.observed and date(year, OCT, 10).weekday() == SUN: + if self.observed and date(year, OCT, 10).weekday() == SU.weekday: self[date(year, OCT, 10) + rd(weekday=MO)] = name + " (Observed)" # In 1969, Christmas was cancelled for the sugar harvest but then was diff --git a/holidays/countries/curacao.py b/holidays/countries/curacao.py index bb043c13b..8320edc79 100644 --- a/holidays/countries/curacao.py +++ b/holidays/countries/curacao.py @@ -13,7 +13,7 @@ from dateutil.easter import easter from dateutil.relativedelta import relativedelta as rd -from dateutil.relativedelta import FR +from dateutil.relativedelta import FR, SU from holidays.constants import JAN, APR, MAY, JUL, AUG, OCT, DEC from holidays.holiday_base import HolidayBase @@ -49,7 +49,7 @@ def _populate(self, year): # King's Day if year >= 2014: kings_day = date(year, APR, 27) - if kings_day.weekday() == 6: + if kings_day.weekday() == SU.weekday: kings_day = kings_day - rd(days=1) self[kings_day] = "Koningsdag [King's Day]" @@ -60,7 +60,7 @@ def _populate(self, year): if year <= 1948: queens_day = date(year, AUG, 31) - if queens_day.weekday() == 6: + if queens_day.weekday() == SU.weekday: if year < 1980: queens_day = queens_day + rd(days=1) else: @@ -70,7 +70,7 @@ def _populate(self, year): # Labour Day labour_day = date(year, MAY, 1) - if labour_day.weekday() == 6: + if labour_day.weekday() == SU.weekday: labour_day = labour_day + rd(days=1) self[labour_day] = "Dia di Obrero [Labour Day]" diff --git a/holidays/countries/czechia.py b/holidays/countries/czechia.py index a0695a3e6..a62df1231 100644 --- a/holidays/countries/czechia.py +++ b/holidays/countries/czechia.py @@ -9,7 +9,6 @@ # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) -import warnings from datetime import date from dateutil.easter import easter diff --git a/holidays/countries/djibouti.py b/holidays/countries/djibouti.py index cbe3b7209..6518fd4d4 100644 --- a/holidays/countries/djibouti.py +++ b/holidays/countries/djibouti.py @@ -11,15 +11,13 @@ from datetime import date -from dateutil.easter import easter from dateutil.relativedelta import relativedelta as rd +from dateutil.relativedelta import FR, SA -from holidays.constants import FRI, SAT, JAN, MAY, JUN +from holidays.constants import JAN, MAY, JUN from holidays.holiday_base import HolidayBase from holidays.utils import _islamic_to_gre -WEEKEND = (FRI, SAT) - # Since Djibouti share most of it's holidays with other muslim countries, # this class is just a copy of Egypt's. @@ -41,25 +39,12 @@ class Djibouti(HolidayBase): # is_weekend function is there, however not activated for accuracy. country = "DJ" + weekend = (FR.weekday, SA.weekday) def __init__(self, **kwargs): HolidayBase.__init__(self, **kwargs) def _populate(self, year): - - """ - # Function to store the holiday name in the appropriate - # date and to shift the Public holiday in case it happens - # on a Saturday(Weekend) - # (NOT USED) - def is_weekend(self, hol_date, hol_name): - if hol_date.weekday() == FRI: - self[hol_date] = hol_name + " [Friday]" - self[hol_date + rd(days=+2)] = "Sunday following " + hol_name - else: - self[hol_date] = hol_name - """ - def _add_holiday(dt: date, hol: str) -> None: """Only add if in current year; prevents adding holidays across years (handles multi-day Islamic holidays that straddle Gregorian diff --git a/holidays/countries/dominican_republic.py b/holidays/countries/dominican_republic.py index 5ac395013..de5c432c5 100644 --- a/holidays/countries/dominican_republic.py +++ b/holidays/countries/dominican_republic.py @@ -13,7 +13,7 @@ from dateutil.easter import easter from dateutil.relativedelta import relativedelta as rd -from dateutil.relativedelta import MO, FR +from dateutil.relativedelta import MO, TU, WE, TH, FR from holidays.constants import JAN, FEB, MAY, JUN, AUG, SEP, NOV, DEC from holidays.holiday_base import HolidayBase @@ -29,10 +29,10 @@ def __init__(self, **kwargs): HolidayBase.__init__(self, **kwargs) @staticmethod - def __change_day_by_law(holiday, latest_days=(3, 4)): + def __change_day_by_law(holiday, latest_days=(TH.weekday, FR.weekday)): # Law No. 139-97 - Holidays Dominican Republic - Jun 27, 1997 if holiday >= date(1997, 6, 27): - if holiday.weekday() in [1, 2]: + if holiday.weekday() in (TU.weekday, WE.weekday): holiday -= rd(weekday=MO(-1)) elif holiday.weekday() in latest_days: holiday += rd(weekday=MO(1)) diff --git a/holidays/countries/egypt.py b/holidays/countries/egypt.py index 983764356..aa8015f54 100644 --- a/holidays/countries/egypt.py +++ b/holidays/countries/egypt.py @@ -14,12 +14,10 @@ from dateutil.easter import easter from dateutil.relativedelta import relativedelta as rd -from holidays.constants import FRI, SAT, JAN, APR, MAY, JUN, JUL, OCT +from holidays.constants import JAN, APR, MAY, JUN, JUL, OCT from holidays.holiday_base import HolidayBase from holidays.utils import _islamic_to_gre -WEEKEND = (FRI, SAT) - class Egypt(HolidayBase): @@ -42,20 +40,6 @@ def __init__(self, **kwargs): HolidayBase.__init__(self, **kwargs) def _populate(self, year): - - """ - # Function to store the holiday name in the appropriate - # date and to shift the Public holiday in case it happens - # on a Saturday(Weekend) - # (NOT USED) - def is_weekend(self, hol_date, hol_name): - if hol_date.weekday() == FRI: - self[hol_date] = hol_name + " [Friday]" - self[hol_date + rd(days=+2)] = "Sunday following " + hol_name - else: - self[hol_date] = hol_name - """ - def _add_holiday(dt: date, hol: str) -> None: """Only add if in current year; prevents adding holidays across years (handles multi-day Islamic holidays that straddle Gregorian diff --git a/holidays/countries/eswatini.py b/holidays/countries/eswatini.py index 5a63e47b2..f1f98ca9c 100644 --- a/holidays/countries/eswatini.py +++ b/holidays/countries/eswatini.py @@ -14,8 +14,9 @@ from dateutil.easter import easter from dateutil.relativedelta import relativedelta as rd +from dateutil.relativedelta import SU -from holidays.constants import SUN, JAN, APR, MAY, JUL, SEP, DEC +from holidays.constants import JAN, APR, MAY, JUL, SEP, DEC from holidays.holiday_base import HolidayBase @@ -70,7 +71,11 @@ def _populate(self, year): # it rolls over to the following Monday for k, v in list(self.items()): - if self.observed and k.weekday() == SUN and k.year == year: + if ( + self.observed + and k.weekday() == SU.weekday + and k.year == year + ): add_days = 1 while self.get(k + rd(days=add_days)) is not None: add_days += 1 diff --git a/holidays/countries/ethiopia.py b/holidays/countries/ethiopia.py index 933945528..e35e4f4cc 100644 --- a/holidays/countries/ethiopia.py +++ b/holidays/countries/ethiopia.py @@ -15,12 +15,10 @@ from dateutil.easter import easter from dateutil.relativedelta import relativedelta as rd -from holidays.constants import SAT, SUN, JAN, MAR, MAY, SEP +from holidays.constants import JAN, MAR, MAY, SEP from holidays.holiday_base import HolidayBase from holidays.utils import _islamic_to_gre -WEEKEND = (SAT, SUN) - # Ethiopian holidays are estimated: it is common for the day to be pushed # if falls in a weekend, although not a rule that can be implemented. # Holidays after 2020: the following four moving date holidays whose exact diff --git a/holidays/countries/germany.py b/holidays/countries/germany.py index 09afe3b7d..19fc30c05 100644 --- a/holidays/countries/germany.py +++ b/holidays/countries/germany.py @@ -144,7 +144,9 @@ def _populate(self, year): # why we need to go back two wednesdays if year-11-23 happens to be # a wednesday base_data = date(year, NOV, 23) - weekday_delta = WE(-2) if base_data.weekday() == 2 else WE(-1) + weekday_delta = ( + WE(-2) if base_data.weekday() == WE.weekday else WE(-1) + ) self[base_data + rd(weekday=weekday_delta)] = "Buß- und Bettag" if year >= 2019: diff --git a/holidays/countries/greece.py b/holidays/countries/greece.py index 5ab05e496..83b2084ce 100644 --- a/holidays/countries/greece.py +++ b/holidays/countries/greece.py @@ -15,7 +15,7 @@ from dateutil.relativedelta import relativedelta as rd from dateutil.relativedelta import MO, TU -from holidays.constants import WEEKEND, JAN, MAR, MAY, AUG, OCT, DEC +from holidays.constants import JAN, MAR, MAY, AUG, OCT, DEC from holidays.holiday_base import HolidayBase @@ -55,7 +55,7 @@ def _populate(self, year): name_observed = name + " (Observed)" self[date(year, MAY, 1)] = name - if self.observed and date(year, MAY, 1).weekday() in WEEKEND: + if self.observed and self._is_weekend(date(year, MAY, 1)): # https://en.wikipedia.org/wiki/Public_holidays_in_Greece labour_day_observed_date = date(year, MAY, 1) + rd(weekday=MO) # In 2016 and 2021, Labour Day coincided with other holidays diff --git a/holidays/countries/hongkong.py b/holidays/countries/hongkong.py index 3d560d34a..cdb82f7fc 100644 --- a/holidays/countries/hongkong.py +++ b/holidays/countries/hongkong.py @@ -9,28 +9,13 @@ # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) -from datetime import date, datetime, timedelta +from datetime import date from dateutil.easter import easter from dateutil.relativedelta import relativedelta as rd -from dateutil.relativedelta import MO, FR, SA +from dateutil.relativedelta import MO, TU, WE, TH, FR, SA, SU -from holidays.constants import ( - MON, - TUE, - WED, - THU, - FRI, - SAT, - SUN, - JAN, - APR, - MAY, - JUL, - SEP, - OCT, - DEC, -) +from holidays.constants import JAN, APR, MAY, JUL, SEP, OCT, DEC from holidays.holiday_base import HolidayBase from holidays.utils import _ChineseLuniSolar @@ -54,7 +39,7 @@ def _populate(self, year): name = "The first day of January" first_date = date(year, JAN, 1) if self.observed: - if first_date.weekday() == SUN: + if first_date.weekday() == SU.weekday: self[ first_date + rd(days=+1) ] = day_following + self.first_lower(name) @@ -74,19 +59,24 @@ def _populate(self, year): new_year_date = date(dt.year, dt.month, dt.day) if self.observed: self[new_year_date] = name - if new_year_date.weekday() in [MON, TUE, WED, THU]: + if new_year_date.weekday() in ( + MO.weekday, + TU.weekday, + WE.weekday, + TH.weekday, + ): self[new_year_date] = name self[new_year_date + rd(days=+1)] = second_day_lunar self[new_year_date + rd(days=+2)] = third_day_lunar - if new_year_date.weekday() == FRI: + if new_year_date.weekday() == FR.weekday: self[new_year_date] = name self[new_year_date + rd(days=+1)] = second_day_lunar self[new_year_date + rd(days=+3)] = fourth_day_lunar - if new_year_date.weekday() == SAT: + if new_year_date.weekday() == SA.weekday: self[new_year_date] = name self[new_year_date + rd(days=+2)] = third_day_lunar self[new_year_date + rd(days=+3)] = fourth_day_lunar - if new_year_date.weekday() == SUN: + if new_year_date.weekday() == SU.weekday: if year in [2006, 2007, 2010]: self[new_year_date + rd(days=-1)] = preceding_day_lunar self[new_year_date + rd(days=+1)] = second_day_lunar @@ -109,7 +99,7 @@ def _populate(self, year): else: ching_ming_date = date(year, APR, 5) if self.observed: - if ching_ming_date.weekday() == SUN: + if ching_ming_date.weekday() == SU.weekday: self[ching_ming_date + rd(days=+1)] = day_following + name ching_ming_date = ching_ming_date + rd(days=+1) else: @@ -143,7 +133,7 @@ def _populate(self, year): dt = self.cnls.lunar_to_gre(year, 4, 8) buddha_date = date(dt.year, dt.month, dt.day) if self.observed: - if buddha_date.weekday() == SUN: + if buddha_date.weekday() == SU.weekday: self[buddha_date + rd(days=+1)] = day_following + name else: self[buddha_date] = name @@ -154,7 +144,7 @@ def _populate(self, year): name = "Labour Day" labour_date = date(year, MAY, 1) if self.observed: - if labour_date.weekday() == SUN: + if labour_date.weekday() == SU.weekday: self[labour_date + rd(days=+1)] = day_following + name else: self[labour_date] = name @@ -166,7 +156,7 @@ def _populate(self, year): dt = self.cnls.lunar_to_gre(year, 5, 5) tuen_ng_date = date(dt.year, dt.month, dt.day) if self.observed: - if tuen_ng_date.weekday() == SUN: + if tuen_ng_date.weekday() == SU.weekday: self[tuen_ng_date + rd(days=+1)] = day_following + name else: self[tuen_ng_date] = name @@ -177,7 +167,7 @@ def _populate(self, year): name = "Hong Kong Special Administrative Region Establishment Day" hksar_date = date(year, JUL, 1) if self.observed: - if hksar_date.weekday() == SUN: + if hksar_date.weekday() == SU.weekday: self[hksar_date + rd(days=+1)] = day_following + name else: self[hksar_date] = name @@ -198,7 +188,7 @@ def _populate(self, year): dt = self.cnls.lunar_to_gre(year, 8, 15) mid_autumn_date = date(dt.year, dt.month, dt.day) if self.observed: - if mid_autumn_date.weekday() == SAT: + if mid_autumn_date.weekday() == SA.weekday: self[mid_autumn_date] = name else: self[mid_autumn_date + rd(days=+1)] = ( @@ -213,7 +203,7 @@ def _populate(self, year): national_date = date(year, OCT, 1) if self.observed: if ( - national_date.weekday() == SUN + national_date.weekday() == SU.weekday or national_date == mid_autumn_date ): self[national_date + rd(days=+1)] = day_following + name @@ -227,7 +217,7 @@ def _populate(self, year): dt = self.cnls.lunar_to_gre(year, 9, 9) chung_yeung_date = date(dt.year, dt.month, dt.day) if self.observed: - if chung_yeung_date.weekday() == SUN: + if chung_yeung_date.weekday() == SU.weekday: self[chung_yeung_date + rd(days=+1)] = day_following + name else: self[chung_yeung_date] = name @@ -240,11 +230,11 @@ def _populate(self, year): second_after_christmas = "The second weekday after " + name christmas_date = date(year, DEC, 25) if self.observed: - if christmas_date.weekday() == SUN: + if christmas_date.weekday() == SU.weekday: self[christmas_date] = name self[christmas_date + rd(days=+1)] = first_after_christmas self[christmas_date + rd(days=+2)] = second_after_christmas - elif christmas_date.weekday() == SAT: + elif christmas_date.weekday() == SA.weekday: self[christmas_date] = name self[christmas_date + rd(days=+2)] = first_after_christmas else: diff --git a/holidays/countries/hungary.py b/holidays/countries/hungary.py index 89561b7b4..685b28318 100644 --- a/holidays/countries/hungary.py +++ b/holidays/countries/hungary.py @@ -13,22 +13,9 @@ from dateutil.easter import easter from dateutil.relativedelta import relativedelta as rd -from dateutil.relativedelta import FR - -from holidays.constants import ( - MON, - TUE, - THU, - WEEKEND, - JAN, - MAR, - APR, - MAY, - AUG, - OCT, - NOV, - DEC, -) +from dateutil.relativedelta import MO, TU, TH, FR + +from holidays.constants import JAN, MAR, APR, MAY, AUG, OCT, NOV, DEC from holidays.holiday_base import HolidayBase @@ -54,7 +41,7 @@ def _populate(self, year: int) -> None: # Since 2014, the last day of the year is an observed day off if New # Year's Day falls on a Tuesday. if year >= 2014: - if self.observed and date(year, DEC, 31).weekday() == MON: + if self.observed and date(year, DEC, 31).weekday() == MO.weekday: self[date(year, DEC, 31)] = "Újév előtti pihenőnap" # National Day @@ -130,7 +117,7 @@ def _populate(self, year: int) -> None: if ( self.observed and 2010 <= year - and date(year, DEC, 24).weekday() not in WEEKEND + and not self._is_weekend(date(year, DEC, 24)) ): self[date(year, DEC, 24)] = "Szenteste" @@ -151,7 +138,7 @@ def _populate(self, year: int) -> None: if ( self.observed and 2014 <= year - and date(year, DEC, 31).weekday() == MON + and date(year, DEC, 31).weekday() == MO.weekday ): self[date(year, DEC, 31)] = "Szilveszter" @@ -169,12 +156,12 @@ def _add_with_observed_day_off( # TODO: should it be a separate flag? if self.observed and since <= day.year: if ( - day.weekday() == TUE + day.weekday() == TU.weekday and before and not (day.month == JAN and day.day == 1) ): self[day - rd(days=1)] = desc + " előtti pihenőnap" - elif day.weekday() == THU and after: + elif day.weekday() == TH.weekday and after: self[day + rd(days=1)] = desc + " utáni pihenőnap" diff --git a/holidays/countries/ireland.py b/holidays/countries/ireland.py index 33e69ef1d..fab5c0dad 100644 --- a/holidays/countries/ireland.py +++ b/holidays/countries/ireland.py @@ -13,26 +13,9 @@ from dateutil.easter import easter from dateutil.relativedelta import relativedelta as rd -from dateutil.relativedelta import MO - -from holidays.constants import ( - MON, - TUE, - WED, - THU, - FRI, - SAT, - SUN, - WEEKEND, - JAN, - FEB, - MAR, - MAY, - JUN, - AUG, - OCT, - DEC, -) +from dateutil.relativedelta import MO, TU, WE, TH, FR, SA, SU + +from holidays.constants import JAN, FEB, MAR, MAY, JUN, AUG, OCT, DEC from holidays.holiday_base import HolidayBase @@ -57,7 +40,7 @@ def _populate(self, year): dt = date(year, FEB, 1) self[dt] = "St. Brigid's Day" - if self.observed and dt.weekday() != FRI: + if self.observed and dt.weekday() != FR.weekday: self[ date(year, FEB, 1) + rd(weekday=MO) ] = "St. Brigid's Day (Observed)" @@ -69,7 +52,7 @@ def _populate(self, year): # St. Patrick's Day name = "St. Patrick's Day" self[date(year, MAR, 17)] = name - if self.observed and date(year, MAR, 17).weekday() in WEEKEND: + if self.observed and self._is_weekend(date(year, MAR, 17)): self[date(year, MAR, 17) + rd(weekday=MO)] = name + " (Observed)" # Easter Monday @@ -82,19 +65,19 @@ def _populate(self, year): dt = date(year, MAY, 8) else: dt = date(year, MAY, 1) - if dt.weekday() == MON: + if dt.weekday() == MO.weekday: self[dt] = name - if dt.weekday() == TUE: + if dt.weekday() == TU.weekday: self[dt + rd(days=+6)] = name - if dt.weekday() == WED: + if dt.weekday() == WE.weekday: self[dt + rd(days=+5)] = name - if dt.weekday() == THU: + if dt.weekday() == TH.weekday: self[dt + rd(days=+4)] = name - if dt.weekday() == FRI: + if dt.weekday() == FR.weekday: self[dt + rd(days=+3)] = name - if dt.weekday() == SAT: + if dt.weekday() == SA.weekday: self[dt + rd(days=+2)] = name - if dt.weekday() == SUN: + if dt.weekday() == SU.weekday: self[dt + rd(days=+1)] = name # June bank holiday (first Monday in June) @@ -109,13 +92,15 @@ def _populate(self, year): # Christmas Day name = "Christmas Day" self[date(year, DEC, 25)] = "Christmas Day" - if self.observed and date(year, DEC, 25).weekday() in WEEKEND: - self[date(year, DEC, 25) + rd(weekday=MON)] = name + " (Observed)" + if self.observed and self._is_weekend(date(year, DEC, 25)): + self[date(year, DEC, 25) + rd(weekday=MO.weekday)] = ( + name + " (Observed)" + ) # St. Stephen's Day name = "St. Stephen's Day" self[date(year, DEC, 26)] = name - if self.observed and date(year, DEC, 26).weekday() in WEEKEND: + if self.observed and self._is_weekend(date(year, DEC, 26)): self[date(year, DEC, 26) + rd(days=2)] = name + " (Observed)" diff --git a/holidays/countries/israel.py b/holidays/countries/israel.py index 99c7624cf..95ac7a53c 100644 --- a/holidays/countries/israel.py +++ b/holidays/countries/israel.py @@ -13,17 +13,10 @@ from datetime import date from convertdate import gregorian, hebrew -from convertdate.holidays import ( - hanukkah, - lag_baomer, - passover, - purim, - rosh_hashanah, - shavuot, - sukkot, - yom_kippur, -) +from convertdate.holidays import hanukkah, lag_baomer, passover, purim +from convertdate.holidays import rosh_hashanah, shavuot, sukkot, yom_kippur from dateutil.relativedelta import relativedelta as rd +from dateutil.relativedelta import SA from holidays.holiday_base import HolidayBase @@ -64,7 +57,7 @@ def _populate(self, year): day_in_week = memorial_day_dt.weekday() if day_in_week in (2, 3): observed_delta = -(day_in_week - 1) - elif 2004 <= year and day_in_week == 5: + elif 2004 <= year and day_in_week == SA.weekday: observed_delta = 1 if observed_delta != 0: diff --git a/holidays/countries/italy.py b/holidays/countries/italy.py index 225f01cb2..66416b3b2 100644 --- a/holidays/countries/italy.py +++ b/holidays/countries/italy.py @@ -16,20 +16,8 @@ from dateutil.relativedelta import relativedelta as rd from dateutil.relativedelta import MO, TU, TH, SU -from holidays.constants import ( - JAN, - FEB, - MAR, - APR, - MAY, - JUN, - JUL, - AUG, - SEP, - OCT, - NOV, - DEC, -) +from holidays.constants import JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP +from holidays.constants import OCT, NOV, DEC from holidays.holiday_base import HolidayBase diff --git a/holidays/countries/jamaica.py b/holidays/countries/jamaica.py index 1bcf7d767..c546a7b18 100644 --- a/holidays/countries/jamaica.py +++ b/holidays/countries/jamaica.py @@ -15,7 +15,7 @@ from dateutil.relativedelta import relativedelta as rd from dateutil.relativedelta import MO, WE, FR, SU -from holidays.constants import SUN, WEEKEND, JAN, FEB, MAY, JUN, AUG, OCT, DEC +from holidays.constants import JAN, FEB, MAY, JUN, AUG, OCT, DEC from holidays.holiday_base import HolidayBase @@ -32,7 +32,7 @@ def _populate(self, year): # New Year's Day name = "New Year's Day" _date = date(year, JAN, 1) - if self.observed and _date.weekday() == SUN: + if self.observed and _date.weekday() == SU.weekday: self[_date + rd(weekday=MO(+1))] = name + " (Observed)" else: self[_date] = name @@ -46,7 +46,7 @@ def _populate(self, year): # Labour Day name = "Labour Day" _date = date(year, MAY, 23) - if self.observed and _date.weekday() == SUN: + if self.observed and _date.weekday() == SU.weekday: self[_date + rd(weekday=MO)] = name + " (Observed)" else: self[_date] = name @@ -57,7 +57,7 @@ def _populate(self, year): # Emancipation Day name = "Emancipation Day" _date = date(year, AUG, 1) - if self.observed and _date.weekday() == SUN: + if self.observed and _date.weekday() == SU.weekday: self[_date + rd(weekday=MO)] = name + " (Observed)" else: self[_date] = name @@ -65,7 +65,7 @@ def _populate(self, year): # Independence Day name = "Independence Day" _date = date(year, AUG, 6) - if self.observed and _date.weekday() in WEEKEND: + if self.observed and self._is_weekend(_date): self[_date + rd(weekday=MO)] = name else: self[_date] = name diff --git a/holidays/countries/japan.py b/holidays/countries/japan.py index 37f6ff0ad..b49d801a7 100644 --- a/holidays/countries/japan.py +++ b/holidays/countries/japan.py @@ -14,20 +14,8 @@ from dateutil.relativedelta import relativedelta as rd from dateutil.relativedelta import MO -from holidays.constants import ( - JAN, - FEB, - MAR, - APR, - MAY, - JUN, - JUL, - AUG, - SEP, - OCT, - NOV, - DEC, -) +from holidays.constants import JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP +from holidays.constants import OCT, NOV, DEC from holidays.holiday_base import HolidayBase diff --git a/holidays/countries/kenya.py b/holidays/countries/kenya.py index 36088c652..3b0575ae1 100644 --- a/holidays/countries/kenya.py +++ b/holidays/countries/kenya.py @@ -13,9 +13,9 @@ from dateutil.easter import easter from dateutil.relativedelta import relativedelta as rd -from dateutil.relativedelta import MO, FR +from dateutil.relativedelta import MO, FR, SU -from holidays.constants import SUN, JAN, MAY, JUN, OCT, DEC +from holidays.constants import JAN, MAY, JUN, OCT, DEC from holidays.holiday_base import HolidayBase @@ -39,7 +39,7 @@ def _populate(self, year): self[date(year, DEC, 25)] = "Christmas Day" self[date(year, DEC, 26)] = "Utamaduni Day" for k, v in list(self.items()): - if self.observed and k.weekday() == SUN: + if self.observed and k.weekday() == SU.weekday: self[k + rd(days=1)] = v + " (Observed)" self[easter(year) - rd(weekday=FR(-1))] = "Good Friday" diff --git a/holidays/countries/korea.py b/holidays/countries/korea.py index b56ada5bb..4e1446932 100644 --- a/holidays/countries/korea.py +++ b/holidays/countries/korea.py @@ -13,24 +13,13 @@ from typing import Tuple from dateutil.relativedelta import relativedelta as rd +from dateutil.relativedelta import SA, SU # Installation: pip install korean_lunar_calendar # URL: https://github.com/usingsky/korean_lunar_calendar_py/ from korean_lunar_calendar import KoreanLunarCalendar -from holidays.constants import ( - SAT, - SUN, - JAN, - MAR, - APR, - MAY, - JUN, - JUL, - AUG, - OCT, - DEC, -) +from holidays.constants import JAN, MAR, APR, MAY, JUN, JUL, AUG, OCT, DEC from holidays.holiday_base import HolidayBase @@ -272,9 +261,9 @@ def get_next_first_non_holiday( """ start_value = cur - target_weekday = [SUN] + target_weekday = [SU.weekday] if include_sat: - target_weekday.append(SAT) + target_weekday.append(SA.weekday) check_1 = cur.weekday() in target_weekday # Exclude weekends check_2 = ( cur in self and name != self[cur] diff --git a/holidays/countries/malawi.py b/holidays/countries/malawi.py index f7d67bf70..e74d9f1cf 100644 --- a/holidays/countries/malawi.py +++ b/holidays/countries/malawi.py @@ -13,8 +13,9 @@ from dateutil.easter import easter from dateutil.relativedelta import relativedelta as rd +from dateutil.relativedelta import SA, SU -from holidays.constants import SAT, SUN, JAN, MAR, MAY, JUL, OCT, DEC +from holidays.constants import JAN, MAR, MAY, JUL, OCT, DEC from holidays.holiday_base import HolidayBase @@ -48,9 +49,9 @@ def _populate(self, year): for k, v in list(self.items()): if self.observed and year > 1994: - if k.weekday() == SUN: + if k.weekday() == SU.weekday: self[k + rd(days=1)] = v + " (Observed)" - elif k.weekday() == SAT: + elif k.weekday() == SA.weekday: self[k + rd(days=2)] = v + " (Observed)" diff --git a/holidays/countries/malaysia.py b/holidays/countries/malaysia.py index 6902a5c25..8716dc169 100644 --- a/holidays/countries/malaysia.py +++ b/holidays/countries/malaysia.py @@ -17,21 +17,8 @@ from dateutil.relativedelta import MO, FR, SA, SU from dateutil.rrule import MONTHLY, rrule -from holidays.constants import ( - SUN, - JAN, - FEB, - MAR, - APR, - MAY, - JUN, - JUL, - AUG, - SEP, - OCT, - NOV, - DEC, -) +from holidays.constants import JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP +from holidays.constants import OCT, NOV, DEC from holidays.holiday_base import HolidayBase from holidays.utils import _ChineseLuniSolar, _islamic_to_gre @@ -350,7 +337,7 @@ def _populate(self, year): # holiday and if such day is already a public holiday, # then the day following shall be a public holiday" for (hol_date, hol_name) in list(self.items()): - if hol_date.year == year and hol_date.weekday() == SUN: + if hol_date.year == year and hol_date.weekday() == SU.weekday: self[hol_date] += " [Sunday]" in_lieu_date = hol_date + rd(days=+1) while in_lieu_date in self: @@ -409,7 +396,7 @@ def _populate(self, year): ): hol_date = date(year, JAN, 1) self[hol_date] = "New Year's Day" - if hol_date.weekday() == SUN: + if hol_date.weekday() == SU.weekday: self[hol_date] += " [Sunday]" self[date(year, JAN, 2)] = "New Year's Day [In lieu]" diff --git a/holidays/countries/mexico.py b/holidays/countries/mexico.py index 545b3374d..7066d8a75 100644 --- a/holidays/countries/mexico.py +++ b/holidays/countries/mexico.py @@ -12,9 +12,9 @@ from datetime import date from dateutil.relativedelta import relativedelta as rd -from dateutil.relativedelta import MO +from dateutil.relativedelta import MO, FR, SA, SU -from holidays.constants import FRI, SAT, SUN, JAN, FEB, MAR, MAY, SEP, NOV, DEC +from holidays.constants import JAN, FEB, MAR, MAY, SEP, NOV, DEC from holidays.holiday_base import HolidayBase @@ -28,11 +28,11 @@ def _populate(self, year): # New Year's Day name = "Año Nuevo [New Year's Day]" self[date(year, JAN, 1)] = name - if self.observed and date(year, JAN, 1).weekday() == SUN: + if self.observed and date(year, JAN, 1).weekday() == SU.weekday: self[date(year, JAN, 1) + rd(days=+1)] = name + " (Observed)" # The next year's observed New Year's Day can be in this year # when it falls on a Friday (Jan 1st is a Saturday) - if self.observed and date(year, DEC, 31).weekday() == FRI: + if self.observed and date(year, DEC, 31).weekday() == FR.weekday: self[date(year, DEC, 31)] = name + " (Observed)" # Constitution Day @@ -59,17 +59,17 @@ def _populate(self, year): if year >= 1923: name = "Día del Trabajo [Labour Day]" self[date(year, MAY, 1)] = name - if self.observed and date(year, MAY, 1).weekday() == SAT: + if self.observed and date(year, MAY, 1).weekday() == SA.weekday: self[date(year, MAY, 1) + rd(days=-1)] = name + " (Observed)" - elif self.observed and date(year, MAY, 1).weekday() == SUN: + elif self.observed and date(year, MAY, 1).weekday() == SU.weekday: self[date(year, MAY, 1) + rd(days=+1)] = name + " (Observed)" # Independence Day name = "Día de la Independencia [Independence Day]" self[date(year, SEP, 16)] = name - if self.observed and date(year, SEP, 16).weekday() == SAT: + if self.observed and date(year, SEP, 16).weekday() == SA.weekday: self[date(year, SEP, 16) + rd(days=-1)] = name + " (Observed)" - elif self.observed and date(year, SEP, 16).weekday() == SUN: + elif self.observed and date(year, SEP, 16).weekday() == SU.weekday: self[date(year, SEP, 16) + rd(days=+1)] = name + " (Observed)" # Revolution Day @@ -88,16 +88,16 @@ def _populate(self, year): name += " [Change of Federal Government]" if year >= 1970 and (2096 - year) % 6 == 0: self[date(year, DEC, 1)] = name - if self.observed and date(year, DEC, 1).weekday() == SAT: + if self.observed and date(year, DEC, 1).weekday() == SA.weekday: self[date(year, DEC, 1) + rd(days=-1)] = name + " (Observed)" - elif self.observed and date(year, DEC, 1).weekday() == SUN: + elif self.observed and date(year, DEC, 1).weekday() == SU.weekday: self[date(year, DEC, 1) + rd(days=+1)] = name + " (Observed)" # Christmas self[date(year, DEC, 25)] = "Navidad [Christmas]" - if self.observed and date(year, DEC, 25).weekday() == SAT: + if self.observed and date(year, DEC, 25).weekday() == SA.weekday: self[date(year, DEC, 25) + rd(days=-1)] = name + " (Observed)" - elif self.observed and date(year, DEC, 25).weekday() == SUN: + elif self.observed and date(year, DEC, 25).weekday() == SU.weekday: self[date(year, DEC, 25) + rd(days=+1)] = name + " (Observed)" diff --git a/holidays/countries/morocco.py b/holidays/countries/morocco.py index 6724c5c90..3684964dc 100644 --- a/holidays/countries/morocco.py +++ b/holidays/countries/morocco.py @@ -44,19 +44,6 @@ def __init__(self, **kwargs): HolidayBase.__init__(self, **kwargs) def _populate(self, year): - """ - # Function to store the holiday name in the appropriate - # date and to shift the Public holiday in case it happens - # on a Saturday(Weekend) - # (NOT USED) - def is_weekend(self, hol_date, hol_name): - if hol_date.weekday() == FRI: - self[hol_date] = hol_name + " [Friday]" - self[hol_date + rd(days=+2)] = "Sunday following " + hol_name - else: - self[hol_date] = hol_name - """ - def _add_holiday(dt: date, hol: str) -> None: """Only add if in current year; prevents adding holidays across years (handles multi-day Islamic holidays that straddle Gregorian diff --git a/holidays/countries/mozambique.py b/holidays/countries/mozambique.py index 37da215b4..7a663828b 100644 --- a/holidays/countries/mozambique.py +++ b/holidays/countries/mozambique.py @@ -13,8 +13,9 @@ from dateutil.easter import easter from dateutil.relativedelta import relativedelta as rd +from dateutil.relativedelta import TU, SU -from holidays.constants import TUE, SUN, FEB, APR, MAY, JUN, SEP, OCT, DEC +from holidays.constants import FEB, APR, MAY, JUN, SEP, OCT, DEC from holidays.holiday_base import HolidayBase @@ -35,7 +36,7 @@ def _populate(self, year): # carnival is the Tuesday before Ash Wednesday # which is 40 days before easter excluding sundays carnival = e - rd(days=46) - while carnival.weekday() != TUE: + while carnival.weekday() != TU.weekday: carnival = carnival - rd(days=1) self[carnival] = "Carnaval" @@ -52,7 +53,7 @@ def _populate(self, year): # it rolls over to the following Monday for k, v in list(self.items()): if self.observed: - if k.weekday() == SUN: + if k.weekday() == SU.weekday: self[k + rd(days=1)] = v + " (PONTE)" diff --git a/holidays/countries/namibia.py b/holidays/countries/namibia.py index 535bd092a..0a610dda6 100644 --- a/holidays/countries/namibia.py +++ b/holidays/countries/namibia.py @@ -13,8 +13,9 @@ from dateutil.easter import easter from dateutil.relativedelta import relativedelta as rd +from dateutil.relativedelta import SU -from holidays.constants import SUN, JAN, MAR, MAY, AUG, SEP, DEC +from holidays.constants import JAN, MAR, MAY, AUG, SEP, DEC from holidays.holiday_base import HolidayBase @@ -74,7 +75,11 @@ def _populate(self, year): # a public holiday. for k, v in list(self.items()): - if self.observed and k.weekday() == SUN and k.year == year: + if ( + self.observed + and k.weekday() == SU.weekday + and k.year == year + ): self[k + rd(days=1)] = v + " (Observed)" diff --git a/holidays/countries/netherlands.py b/holidays/countries/netherlands.py index 80e90ea26..35db60ea1 100644 --- a/holidays/countries/netherlands.py +++ b/holidays/countries/netherlands.py @@ -13,9 +13,9 @@ from dateutil.easter import easter from dateutil.relativedelta import relativedelta as rd -from dateutil.relativedelta import FR +from dateutil.relativedelta import FR, SU -from holidays.constants import SUN, JAN, APR, MAY, AUG, DEC +from holidays.constants import JAN, APR, MAY, AUG, DEC from holidays.holiday_base import HolidayBase @@ -63,7 +63,7 @@ def _populate(self, year): # Kingsday if year >= 2014: kings_day = date(year, APR, 27) - if kings_day.weekday() == SUN: + if kings_day.weekday() == SU.weekday: kings_day = kings_day - rd(days=1) self[kings_day] = "Koningsdag" @@ -74,7 +74,7 @@ def _populate(self, year): if year <= 1948: queens_day = date(year, AUG, 31) - if queens_day.weekday() == SUN: + if queens_day.weekday() == SU.weekday: if year < 1980: queens_day = queens_day + rd(days=1) else: diff --git a/holidays/countries/new_zealand.py b/holidays/countries/new_zealand.py index b1e52d34d..a038685ef 100644 --- a/holidays/countries/new_zealand.py +++ b/holidays/countries/new_zealand.py @@ -13,24 +13,9 @@ from dateutil.easter import easter from dateutil.relativedelta import relativedelta as rd -from dateutil.relativedelta import MO, TU, WE, FR - -from holidays.constants import ( - TUE, - WED, - THU, - WEEKEND, - JAN, - FEB, - MAR, - APR, - JUN, - JUL, - SEP, - OCT, - NOV, - DEC, -) +from dateutil.relativedelta import MO, TU, WE, TH, FR + +from holidays.constants import JAN, FEB, MAR, APR, JUN, JUL, SEP, OCT, NOV, DEC from holidays.holiday_base import HolidayBase @@ -97,13 +82,13 @@ def _populate(self, year): name = "New Year's Day" jan1 = date(year, JAN, 1) self[jan1] = name - if self.observed and jan1.weekday() in WEEKEND: + if self.observed and self._is_weekend(jan1): self[date(year, JAN, 3)] = name + " (Observed)" name = "Day after New Year's Day" jan2 = date(year, JAN, 2) self[jan2] = name - if self.observed and jan2.weekday() in WEEKEND: + if self.observed and self._is_weekend(jan2): self[date(year, JAN, 4)] = name + " (Observed)" # Waitangi Day @@ -113,7 +98,7 @@ def _populate(self, year): name = "Waitangi Day" feb6 = date(year, FEB, 6) self[feb6] = name - if self.observed and year >= 2014 and feb6.weekday() in WEEKEND: + if self.observed and year >= 2014 and self._is_weekend(feb6): self[feb6 + rd(weekday=MO)] = name + " (Observed)" # Easter @@ -125,7 +110,7 @@ def _populate(self, year): name = "Anzac Day" apr25 = date(year, APR, 25) self[apr25] = name - if self.observed and year >= 2014 and apr25.weekday() in WEEKEND: + if self.observed and year >= 2014 and self._is_weekend(apr25): self[apr25 + rd(weekday=MO)] = name + " (Observed)" # Sovereign's Birthday @@ -227,14 +212,14 @@ def _populate(self, year): name = "Christmas Day" dec25 = date(year, DEC, 25) self[dec25] = name - if self.observed and dec25.weekday() in WEEKEND: + if self.observed and self._is_weekend(dec25): self[date(year, DEC, 27)] = name + " (Observed)" # Boxing Day name = "Boxing Day" dec26 = date(year, DEC, 26) self[dec26] = name - if self.observed and dec26.weekday() in WEEKEND: + if self.observed and self._is_weekend(dec26): self[date(year, DEC, 28)] = name + " (Observed)" # Province Anniversary Day @@ -245,7 +230,7 @@ def _populate(self, year): else: name = "Auckland Anniversary Day" dt = date(year, JAN, 29) - if dt.weekday() in (TUE, WED, THU): + if dt.weekday() in (TU.weekday, WE.weekday, TH.weekday): self[dt + rd(weekday=MO(-1))] = name else: self[dt + rd(weekday=MO)] = name @@ -262,7 +247,7 @@ def _populate(self, year): elif self.subdiv in ("WGN", "Wellington"): name = "Wellington Anniversary Day" jan22 = date(year, JAN, 22) - if jan22.weekday() in (TUE, WED, THU): + if jan22.weekday() in (TU.weekday, WE.weekday, TH.weekday): self[jan22 + rd(weekday=MO(-1))] = name else: self[jan22 + rd(weekday=MO)] = name @@ -275,7 +260,7 @@ def _populate(self, year): elif self.subdiv in ("NSN", "Nelson"): name = "Nelson Anniversary Day" feb1 = date(year, FEB, 1) - if feb1.weekday() in (TUE, WED, THU): + if feb1.weekday() in (TU.weekday, WE.weekday, TH.weekday): self[feb1 + rd(weekday=MO(-1))] = name else: self[feb1 + rd(weekday=MO)] = name @@ -296,7 +281,7 @@ def _populate(self, year): # Observance varies?!?! if year == 2005: # special case?!?! self[date(year, DEC, 5)] = name - elif dec1.weekday() in (TUE, WED, THU): + elif dec1.weekday() in (TU.weekday, WE.weekday, TH.weekday): self[dec1 + rd(weekday=MO(-1))] = name else: self[dec1 + rd(weekday=MO)] = name @@ -305,7 +290,7 @@ def _populate(self, year): name = "Otago Anniversary Day" mar23 = date(year, MAR, 23) # there is no easily determined single day of local observance?!?! - if mar23.weekday() in (TUE, WED, THU): + if mar23.weekday() in (TU.weekday, WE.weekday, TH.weekday): dt = mar23 + rd(weekday=MO(-1)) else: dt = mar23 + rd(weekday=MO) @@ -319,7 +304,7 @@ def _populate(self, year): if year > 2011: self[easter(year) + rd(weekday=TU)] = name else: - if jan17.weekday() in (TUE, WED, THU): + if jan17.weekday() in (TU.weekday, WE.weekday, TH.weekday): self[jan17 + rd(weekday=MO(-1))] = name else: self[jan17 + rd(weekday=MO)] = name @@ -327,7 +312,7 @@ def _populate(self, year): elif self.subdiv in ("CIT", "Chatham Islands"): name = "Chatham Islands Anniversary Day" nov30 = date(year, NOV, 30) - if nov30.weekday() in (TUE, WED, THU): + if nov30.weekday() in (TU.weekday, WE.weekday, TH.weekday): self[nov30 + rd(weekday=MO(-1))] = name else: self[nov30 + rd(weekday=MO)] = name diff --git a/holidays/countries/nigeria.py b/holidays/countries/nigeria.py index befc504e5..bfe1555f7 100644 --- a/holidays/countries/nigeria.py +++ b/holidays/countries/nigeria.py @@ -13,8 +13,9 @@ from dateutil.easter import easter from dateutil.relativedelta import relativedelta as rd +from dateutil.relativedelta import SA -from holidays.constants import SAT, JAN, MAY, JUN, OCT, DEC +from holidays.constants import JAN, MAY, JUN, OCT, DEC from holidays.holiday_base import HolidayBase from holidays.utils import _islamic_to_gre @@ -96,7 +97,7 @@ def _add_holiday(dt: date, hol: str) -> None: if ( self.observed and year > 2015 - and k.weekday() == SAT + and k.weekday() == SA.weekday and k.year == year and v.upper() in ("WORKER'S DAY", "DEMOCRACY DAY") ): diff --git a/holidays/countries/norway.py b/holidays/countries/norway.py index 31009c179..e2944445a 100644 --- a/holidays/countries/norway.py +++ b/holidays/countries/norway.py @@ -13,8 +13,9 @@ from dateutil.easter import easter from dateutil.relativedelta import relativedelta as rd +from dateutil.relativedelta import MO, TH, FR, SU -from holidays.constants import MON, THU, FRI, SUN, JAN, MAY, DEC +from holidays.constants import JAN, MAY, DEC from holidays.holiday_base import HolidayBase @@ -51,12 +52,12 @@ def _populate(self, year): if self.include_sundays: first_day_of_year = date(year, JAN, 1) first_sunday_of_year = first_day_of_year + rd( - days=SUN - first_day_of_year.weekday() + days=SU.weekday - first_day_of_year.weekday() ) cur_date = first_sunday_of_year while cur_date < date(year + 1, 1, 1): - assert cur_date.weekday() == SUN + assert cur_date.weekday() == SU.weekday self[cur_date] = "Søndag" cur_date += rd(days=7) @@ -91,13 +92,13 @@ def _populate(self, year): pentecost = e + rd(days=49) pentecost_day_two = e + rd(days=50) - assert maundy_thursday.weekday() == THU - assert good_friday.weekday() == FRI - assert resurrection_sunday.weekday() == SUN - assert easter_monday.weekday() == MON - assert ascension_thursday.weekday() == THU - assert pentecost.weekday() == SUN - assert pentecost_day_two.weekday() == MON + assert maundy_thursday.weekday() == TH.weekday + assert good_friday.weekday() == FR.weekday + assert resurrection_sunday.weekday() == SU.weekday + assert easter_monday.weekday() == MO.weekday + assert ascension_thursday.weekday() == TH.weekday + assert pentecost.weekday() == SU.weekday + assert pentecost_day_two.weekday() == MO.weekday self[maundy_thursday] = "Skjærtorsdag" self[good_friday] = "Langfredag" diff --git a/holidays/countries/paraguay.py b/holidays/countries/paraguay.py index 2c6a051ae..287ad39a6 100644 --- a/holidays/countries/paraguay.py +++ b/holidays/countries/paraguay.py @@ -13,9 +13,9 @@ from dateutil.easter import easter from dateutil.relativedelta import relativedelta as rd -from dateutil.relativedelta import MO, TH, FR +from dateutil.relativedelta import MO, WE, TH, FR -from holidays.constants import WED, WEEKEND, JAN, MAR, MAY, JUN, AUG, SEP, DEC +from holidays.constants import JAN, MAR, MAY, JUN, AUG, SEP, DEC from holidays.holiday_base import HolidayBase @@ -31,7 +31,7 @@ def __init__(self, **kwargs): def _populate(self, year): # New Year's Day - if not self.observed and date(year, JAN, 1).weekday() in WEEKEND: + if not self.observed and self._is_weekend(date(year, JAN, 1)): pass else: self[date(year, JAN, 1)] = "Año Nuevo [New Year's Day]" @@ -39,9 +39,9 @@ def _populate(self, year): # Patriots day name = "Día de los Héroes de la Patria" "[Patriots Day]" - if not self.observed and date(year, MAR, 1).weekday() in WEEKEND: + if not self.observed and self._is_weekend(date(year, MAR, 1)): pass - elif date(year, MAR, 1).weekday() >= WED: + elif date(year, MAR, 1).weekday() >= WE.weekday: self[date(year, MAR, 1) + rd(weekday=MO(+1))] = name else: self[date(year, MAR, 1)] = name @@ -54,51 +54,51 @@ def _populate(self, year): self[easter(year) + rd(weekday=TH(-1))] = name_thu self[easter(year) + rd(weekday=FR(-1))] = name_fri - if not self.observed and easter(year).weekday() in WEEKEND: + if not self.observed and self._is_weekend(easter(year)): pass else: self[easter(year)] = name_easter # Labor Day name = "Día de los Trabajadores [Labour Day]" - if not self.observed and date(year, MAY, 1).weekday() in WEEKEND: + if not self.observed and self._is_weekend(date(year, MAY, 1)): pass else: self[date(year, MAY, 1)] = name # Independence Day name = "Día de la Independencia Nacional [Independence Day]" - if not self.observed and date(year, MAY, 15).weekday() in WEEKEND: + if not self.observed and self._is_weekend(date(year, MAY, 15)): pass else: self[date(year, MAY, 15)] = name # Peace in Chaco Day. name = "Día de la Paz del Chaco [Peace in Chaco Day]" - if not self.observed and date(year, JUN, 12).weekday() in WEEKEND: + if not self.observed and self._is_weekend(date(year, JUN, 12)): pass - elif date(year, JUN, 12).weekday() >= WED: + elif date(year, JUN, 12).weekday() >= WE.weekday: self[date(year, JUN, 12) + rd(weekday=MO(+1))] = name else: self[date(year, JUN, 12)] = name # Asuncion Fundation's Day name = "Día de la Fundación de Asunción [Asuncion Fundation's Day]" - if not self.observed and date(year, AUG, 15).weekday() in WEEKEND: + if not self.observed and self._is_weekend(date(year, AUG, 15)): pass else: self[date(year, AUG, 15)] = name # Boqueron's Battle name = "Batalla de Boquerón [Boqueron's Battle]" - if not self.observed and date(year, SEP, 29).weekday() in WEEKEND: + if not self.observed and self._is_weekend(date(year, SEP, 29)): pass else: self[date(year, SEP, 29)] = name # Caacupe Virgin Day name = "Día de la Virgen de Caacupé [Caacupe Virgin Day]" - if not self.observed and date(year, DEC, 8).weekday() in WEEKEND: + if not self.observed and self._is_weekend(date(year, DEC, 8)): pass else: self[date(year, DEC, 8)] = name diff --git a/holidays/countries/poland.py b/holidays/countries/poland.py index 1635baf14..c4c0f8832 100644 --- a/holidays/countries/poland.py +++ b/holidays/countries/poland.py @@ -9,7 +9,6 @@ # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) -import warnings from datetime import date from dateutil.easter import easter diff --git a/holidays/countries/portugal.py b/holidays/countries/portugal.py index 65e46e9f5..d19ddf2e6 100644 --- a/holidays/countries/portugal.py +++ b/holidays/countries/portugal.py @@ -14,19 +14,8 @@ from dateutil.easter import easter from dateutil.relativedelta import relativedelta as rd -from holidays.constants import ( - JAN, - MAR, - APR, - MAY, - JUN, - JUL, - AUG, - SEP, - OCT, - NOV, - DEC, -) +from holidays.constants import JAN, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT +from holidays.constants import NOV, DEC from holidays.holiday_base import HolidayBase diff --git a/holidays/countries/saudi_arabia.py b/holidays/countries/saudi_arabia.py index 6a31eb002..e75c77c42 100644 --- a/holidays/countries/saudi_arabia.py +++ b/holidays/countries/saudi_arabia.py @@ -12,8 +12,10 @@ from datetime import date from dateutil.relativedelta import relativedelta as rd +from dateutil.relativedelta import TH, FR +from dateutil.relativedelta import SA as SAT # Conflicts with SA Alpha-2 code. -from holidays.constants import THU, FRI, SAT, FEB, SEP +from holidays.constants import FEB, SEP from holidays.holiday_base import HolidayBase from holidays.utils import _islamic_to_gre @@ -47,9 +49,9 @@ def _populate(self, year): # Weekend used to be THU, FRI before June 28th, 2013 # On that year both Eids were after that date, and foudning # day holiday started at 2022; so what below works, - WEEKEND = (THU, FRI) + self.weekend = (TH.weekday, FR.weekday) else: - WEEKEND = (FRI, SAT) + self.weekend = (FR.weekday, SAT.weekday) observed_str = " (observed)" @@ -76,7 +78,7 @@ def _add_holiday(dt: date, hol: str) -> None: _add_holiday((hijri_date + rd(days=dys)), holiday_name) if self.observed: weekend_days = sum( - (hijri_date + rd(days=dys)).weekday() in WEEKEND + (hijri_date + rd(days=dys)).weekday() in self.weekend for dys in range(4) ) for dys in range(weekend_days): @@ -100,7 +102,7 @@ def _add_holiday(dt: date, hol: str) -> None: _add_holiday((hijri_date + rd(days=dys)), holiday_name) if self.observed: weekend_days = sum( - (hijri_date + rd(days=dys)).weekday() in WEEKEND + (hijri_date + rd(days=dys)).weekday() in self.weekend for dys in range(4) ) for dys in range(weekend_days): @@ -118,11 +120,13 @@ def _add_holiday(dt: date, hol: str) -> None: if national_day not in self: self[national_day] = holiday_name # First weekend day(Thursaday before 2013 and Friday otherwise) - if self.observed and national_day.weekday() == WEEKEND[0]: + if self.observed and national_day.weekday() == self.weekend[0]: national_day -= rd(days=1) self[national_day] = holiday_name + observed_str # Second weekend day(Friday before 2013 and Saturday otherwise) - elif self.observed and national_day.weekday() == WEEKEND[1]: + elif ( + self.observed and national_day.weekday() == self.weekend[1] + ): national_day += rd(days=1) self[national_day] = holiday_name + observed_str @@ -135,11 +139,13 @@ def _add_holiday(dt: date, hol: str) -> None: if founding_day not in self: self[founding_day] = holiday_name # First weekend day(Thursaday before 2013 and Friday otherwise) - if self.observed and founding_day.weekday() == WEEKEND[0]: + if self.observed and founding_day.weekday() == self.weekend[0]: founding_day -= rd(days=1) self[founding_day] = holiday_name + observed_str # Second weekend day(Friday before 2013 and Saturday otherwise) - elif self.observed and founding_day.weekday() == WEEKEND[1]: + elif ( + self.observed and founding_day.weekday() == self.weekend[1] + ): founding_day += rd(days=1) self[founding_day] = holiday_name + observed_str diff --git a/holidays/countries/serbia.py b/holidays/countries/serbia.py index f8ec3cdb0..2b27ec33b 100644 --- a/holidays/countries/serbia.py +++ b/holidays/countries/serbia.py @@ -13,8 +13,9 @@ from dateutil.easter import EASTER_ORTHODOX, easter from dateutil.relativedelta import relativedelta as rd +from dateutil.relativedelta import SU -from holidays.constants import SUN, WEEKEND, JAN, FEB, MAY, NOV +from holidays.constants import JAN, FEB, MAY, NOV from holidays.holiday_base import HolidayBase @@ -31,7 +32,7 @@ def _populate(self, year): name = "Нова година" self[date(year, JAN, 1)] = name self[date(year, JAN, 2)] = name - if self.observed and date(year, JAN, 1).weekday() in WEEKEND: + if self.observed and self._is_weekend(date(year, JAN, 1)): self[date(year, JAN, 3)] = name + " (Observed)" # Orthodox Christmas name = "Божић" @@ -40,13 +41,13 @@ def _populate(self, year): name = "Дан државности Србије" self[date(year, FEB, 15)] = name self[date(year, FEB, 16)] = name - if self.observed and date(year, FEB, 15).weekday() in WEEKEND: + if self.observed and self._is_weekend(date(year, FEB, 15)): self[date(year, FEB, 17)] = name + " (Observed)" # International Workers' Day name = "Празник рада" self[date(year, MAY, 1)] = name self[date(year, MAY, 2)] = name - if self.observed and date(year, MAY, 1).weekday() in WEEKEND: + if self.observed and self._is_weekend(date(year, MAY, 1)): if date(year, MAY, 2) == easter(year, method=EASTER_ORTHODOX): self[date(year, MAY, 4)] = name + " (Observed)" else: @@ -54,7 +55,7 @@ def _populate(self, year): # Armistice day name = "Дан примирја у Првом светском рату" self[date(year, NOV, 11)] = name - if self.observed and date(year, NOV, 11).weekday() == SUN: + if self.observed and date(year, NOV, 11).weekday() == SU.weekday: self[date(year, NOV, 12)] = name + " (Observed)" # Easter self[ diff --git a/holidays/countries/singapore.py b/holidays/countries/singapore.py index 919f0ecef..b956ef5b5 100644 --- a/holidays/countries/singapore.py +++ b/holidays/countries/singapore.py @@ -10,27 +10,14 @@ # License: MIT (see LICENSE file) from datetime import date -from typing import Dict, Iterable, List, Optional, Tuple, Union +from typing import Dict, Iterable, Optional, Tuple, Union from dateutil.easter import easter from dateutil.relativedelta import relativedelta as rd -from dateutil.relativedelta import MO, FR, SA - -from holidays.constants import ( - SUN, - JAN, - FEB, - MAR, - APR, - MAY, - JUN, - JUL, - SEP, - AUG, - OCT, - NOV, - DEC, -) +from dateutil.relativedelta import MO, FR, SA, SU + +from holidays.constants import JAN, FEB, MAR, APR, MAY, JUN, JUL, SEP, AUG +from holidays.constants import OCT, NOV, DEC from holidays.holiday_base import HolidayBase from holidays.utils import _ChineseLuniSolar, _islamic_to_gre @@ -300,7 +287,7 @@ def _populate(self, year: int) -> None: # a Sunday, the day next following not being itself a public holiday # is declared a public holiday in Singapore." for (hol_date, hol_name) in list(self.items()): - if hol_date.year == year and hol_date.weekday() == SUN: + if hol_date.year == year and hol_date.weekday() == SU.weekday: self[hol_date] += " [Sunday]" in_lieu_date = hol_date + rd(days=+1) while in_lieu_date in self: diff --git a/holidays/countries/slovakia.py b/holidays/countries/slovakia.py index 8b1395670..4760b802c 100644 --- a/holidays/countries/slovakia.py +++ b/holidays/countries/slovakia.py @@ -9,7 +9,6 @@ # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) -import warnings from datetime import date from dateutil.easter import easter diff --git a/holidays/countries/south_africa.py b/holidays/countries/south_africa.py index f2fa4ffb2..8daa5b7b9 100644 --- a/holidays/countries/south_africa.py +++ b/holidays/countries/south_africa.py @@ -13,22 +13,10 @@ from dateutil.easter import easter from dateutil.relativedelta import relativedelta as rd +from dateutil.relativedelta import MO, FR, SU -from holidays.constants import ( - FRI, - SUN, - JAN, - MAR, - APR, - MAY, - JUN, - JUL, - AUG, - SEP, - OCT, - NOV, - DEC, -) +from holidays.constants import JAN, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT +from holidays.constants import NOV, DEC from holidays.holiday_base import HolidayBase @@ -118,7 +106,7 @@ def _populate(self, year): if ( self.observed and year > 1994 - and k.weekday() == SUN + and k.weekday() == SU.weekday and k.year == year ): add_days = 1 @@ -135,7 +123,7 @@ def _populate(self, year): if 1986 < year < 1990: historic_workers_day = datetime(year, MAY, 1) # observed on first Friday in May - while historic_workers_day.weekday() != FRI: + while historic_workers_day.weekday() != FR.weekday: historic_workers_day += rd(days=1) self[historic_workers_day] = "Workers' Day" @@ -155,7 +143,7 @@ def _populate(self, year): if 1951 < year < 1961: queens_birthday = datetime(year, JUN, 7) # observed on second Monday in June - while queens_birthday.weekday() != 0: + while queens_birthday.weekday() != MO.weekday: queens_birthday += rd(days=1) self[queens_birthday] = "Queen's Birthday" @@ -166,14 +154,14 @@ def _populate(self, year): if 1909 < year < 1952: kings_birthday = datetime(year, AUG, 1) # observed on first Monday in August - while kings_birthday.weekday() != 0: + while kings_birthday.weekday() != MO.weekday: kings_birthday += rd(days=1) self[kings_birthday] = "King's Birthday" if 1951 < year < 1980: settlers_day = datetime(year, SEP, 1) - while settlers_day.weekday() != 0: + while settlers_day.weekday() != MO.weekday: settlers_day += rd(days=1) self[settlers_day] = "Settlers' Day" diff --git a/holidays/countries/spain.py b/holidays/countries/spain.py index 08b8a5140..70270fde5 100644 --- a/holidays/countries/spain.py +++ b/holidays/countries/spain.py @@ -13,23 +13,10 @@ from dateutil.easter import easter from dateutil.relativedelta import relativedelta as rd -from dateutil.relativedelta import TH, FR, MO +from dateutil.relativedelta import MO, TH, FR, SU -from holidays.constants import ( - SUN, - JAN, - FEB, - MAR, - APR, - MAY, - JUN, - JUL, - AUG, - SEP, - OCT, - NOV, - DEC, -) +from holidays.constants import JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP +from holidays.constants import OCT, NOV, DEC from holidays.holiday_base import HolidayBase from holidays.utils import _islamic_to_gre @@ -62,7 +49,7 @@ def __init__(self, **kwargs): HolidayBase.__init__(self, **kwargs) def _is_observed(self, date_holiday, name_holiday): - if self.observed and date_holiday.weekday() == SUN: + if self.observed and date_holiday.weekday() == SU.weekday: self[date_holiday + rd(days=+1)] = name_holiday + " (Trasladado)" else: self[date_holiday] = name_holiday diff --git a/holidays/countries/sweden.py b/holidays/countries/sweden.py index 67ffcec2a..612bc67d9 100644 --- a/holidays/countries/sweden.py +++ b/holidays/countries/sweden.py @@ -13,21 +13,9 @@ from dateutil.easter import easter from dateutil.relativedelta import relativedelta as rd -from dateutil.relativedelta import FR, SA - -from holidays.constants import ( - MON, - THU, - FRI, - SAT, - SUN, - JAN, - MAR, - MAY, - JUN, - OCT, - DEC, -) +from dateutil.relativedelta import MO, TH, FR, SA, SU + +from holidays.constants import JAN, MAR, MAY, JUN, OCT, DEC from holidays.holiday_base import HolidayBase @@ -61,12 +49,12 @@ def _populate(self, year): if self.include_sundays: first_day_of_year = date(year, JAN, 1) first_sunday_of_year = first_day_of_year + rd( - days=SUN - first_day_of_year.weekday() + days=SU.weekday - first_day_of_year.weekday() ) cur_date = first_sunday_of_year while cur_date < date(year + 1, 1, 1): - assert cur_date.weekday() == SUN + assert cur_date.weekday() == SU.weekday self[cur_date] = "Söndag" cur_date += rd(days=7) @@ -100,14 +88,14 @@ def _populate(self, year): pentecost = e + rd(days=49) pentecost_day_two = e + rd(days=50) - assert maundy_thursday.weekday() == THU - assert good_friday.weekday() == FRI - assert easter_saturday.weekday() == SAT - assert resurrection_sunday.weekday() == SUN - assert easter_monday.weekday() == MON - assert ascension_thursday.weekday() == THU - assert pentecost.weekday() == SUN - assert pentecost_day_two.weekday() == MON + assert maundy_thursday.weekday() == TH.weekday + assert good_friday.weekday() == FR.weekday + assert easter_saturday.weekday() == SA.weekday + assert resurrection_sunday.weekday() == SU.weekday + assert easter_monday.weekday() == MO.weekday + assert ascension_thursday.weekday() == TH.weekday + assert pentecost.weekday() == SU.weekday + assert pentecost_day_two.weekday() == MO.weekday self[good_friday] = "Långfredagen" self[resurrection_sunday] = "Påskdagen" diff --git a/holidays/countries/tunisia.py b/holidays/countries/tunisia.py index b5291723a..009c33cdb 100644 --- a/holidays/countries/tunisia.py +++ b/holidays/countries/tunisia.py @@ -11,15 +11,12 @@ from datetime import date -from dateutil.easter import easter from dateutil.relativedelta import relativedelta as rd -from holidays.constants import SAT, SUN, JAN, MAR, APR, MAY, JUL, AUG, OCT +from holidays.constants import JAN, MAR, APR, MAY, JUL, AUG, OCT from holidays.holiday_base import HolidayBase from holidays.utils import _islamic_to_gre -WEEKEND = (SAT, SUN) - class Tunisia(HolidayBase): country = "TN" @@ -41,20 +38,6 @@ def __init__(self, **kwargs): HolidayBase.__init__(self, **kwargs) def _populate(self, year): - - """ - # Function to store the holiday name in the appropriate - # date and to shift the Public holiday in case it happens - # on a Saturday(Weekend) - # (NOT USED) - def is_weekend(self, hol_date, hol_name): - if hol_date.weekday() == FRI: - self[hol_date] = hol_name + " [Friday]" - self[hol_date + rd(days=+2)] = "Sunday following " + hol_name - else: - self[hol_date] = hol_name - """ - def _add_holiday(dt: date, hol: str) -> None: """Only add if in current year; prevents adding holidays across years (handles multi-day Islamic holidays that straddle Gregorian diff --git a/holidays/countries/ukraine.py b/holidays/countries/ukraine.py index 8fdcb2148..d0e698d11 100644 --- a/holidays/countries/ukraine.py +++ b/holidays/countries/ukraine.py @@ -12,26 +12,11 @@ from datetime import date from dateutil.easter import EASTER_ORTHODOX, easter -from dateutil.relativedelta import MO +from dateutil.relativedelta import MO, FR, SA from dateutil.relativedelta import relativedelta as rd -from holidays.constants import ( - JAN, - APR, - MAR, - MAY, - JUN, - JUL, - AUG, - SEP, - OCT, - NOV, - DEC, - FRI, - SAT, - SUN, - WEEKEND, -) +from holidays.constants import JAN, APR, MAR, MAY, JUN, JUL, AUG, SEP, OCT +from holidays.constants import NOV, DEC from holidays.holiday_base import HolidayBase @@ -68,7 +53,7 @@ def _populate(self, year): if ( self.observed and (1996 <= year <= 1998 or year >= 2000) - and dt.weekday() in WEEKEND + and self._is_weekend(dt) ): self[dt + rd(weekday=MO(+1))] = "Вихідний за 1 січня" @@ -79,7 +64,7 @@ def _populate(self, year): if ( self.observed and (1996 <= year <= 1998 or year >= 2000) - and dt.weekday() in WEEKEND + and self._is_weekend(dt) ): self[dt + rd(weekday=MO(+1))] = "Вихідний за 7 січня" @@ -90,7 +75,7 @@ def _populate(self, year): if ( self.observed and (1995 <= year <= 1997 or year >= 2000) - and dt.weekday() in WEEKEND + and self._is_weekend(dt) ): self[dt + rd(weekday=MO(+1))] = "Вихідний за 8 березня" @@ -130,7 +115,7 @@ def _populate(self, year): if ( self.observed and (1995 <= year <= 1997 or year >= 1999) - and dt.weekday() in WEEKEND + and self._is_weekend(dt) ): name = "Вихідний за 1 травня" if year <= 2017: @@ -145,7 +130,7 @@ def _populate(self, year): if ( self.observed and (1995 <= year <= 1997 or year >= 1999) - and dt.weekday() in WEEKEND + and self._is_weekend(dt) ): self[dt + rd(days=+2)] = "Вихідний за 2 травня" @@ -165,7 +150,7 @@ def _populate(self, year): if ( self.observed and (1995 <= year <= 1997 or year >= 1999) - and dt.weekday() in WEEKEND + and self._is_weekend(dt) ): self[dt + rd(weekday=MO(+1))] = "Вихідний за 9 травня" @@ -176,7 +161,7 @@ def _populate(self, year): if ( self.observed and (year == 1997 or year >= 1999) - and dt.weekday() in WEEKEND + and self._is_weekend(dt) ): self[dt + rd(weekday=MO(+1))] = "Вихідний за 28 червня" @@ -184,7 +169,7 @@ def _populate(self, year): if year >= 2022: dt = date(year, JUL, 28) self[dt] = "День Української Державності" - if self.observed and dt.weekday() in WEEKEND: + if self.observed and self._is_weekend(dt): self[dt + rd(weekday=MO(+1))] = "Вихідний за 28 липня" # Independence Day @@ -195,7 +180,7 @@ def _populate(self, year): if ( self.observed and (1995 <= year <= 1997 or year >= 1999) - and dt.weekday() in WEEKEND + and self._is_weekend(dt) ): self[dt + rd(weekday=MO(+1))] = "Вихідний за 24 серпня" elif year == 1991: @@ -208,7 +193,7 @@ def _populate(self, year): if year >= 2021: name = "День захисників і захисниць України" self[dt] = name - if self.observed and dt.weekday() in WEEKEND: + if self.observed and self._is_weekend(dt): self[dt + rd(weekday=MO(+1))] = "Вихідний за 14 жовтня" # October Revolution @@ -218,16 +203,16 @@ def _populate(self, year): self[dt] = name self[dt + rd(days=+1)] = name if self.observed and (1995 <= year <= 1997 or year >= 1999): - if dt.weekday() in (SAT, SUN): + if self._is_weekend(dt): self[dt + rd(days=+2)] = "Вихідний за 7 листопада" - if dt.weekday() in (FRI, SAT): + if dt.weekday() in (FR.weekday, SA.weekday): self[dt + rd(days=+3)] = "Вихідний за 8 листопада" # Christmas Day (Gregorian calendar) if year >= 2017: dt = date(year, DEC, 25) self[dt] = "Різдво Христове (за григоріанським календарем)" - if self.observed and dt.weekday() in WEEKEND: + if self.observed and self._is_weekend(dt): self[dt + rd(weekday=MO(+1))] = "Вихідний за 25 грудня" # USSR holidays diff --git a/holidays/countries/united_arab_emirates.py b/holidays/countries/united_arab_emirates.py index bceeacde9..0e5e757d1 100644 --- a/holidays/countries/united_arab_emirates.py +++ b/holidays/countries/united_arab_emirates.py @@ -12,25 +12,12 @@ from datetime import date from dateutil.relativedelta import relativedelta as rd +from dateutil.relativedelta import FR, SA -from holidays.constants import ( - FRI, - SAT, - JAN, - APR, - MAY, - JUN, - JUL, - AUG, - SEP, - NOV, - DEC, -) +from holidays.constants import JAN, APR, MAY, JUN, JUL, AUG, SEP, NOV, DEC from holidays.holiday_base import HolidayBase from holidays.utils import _islamic_to_gre -WEEKEND = (FRI, SAT) - class UnitedArabEmirates(HolidayBase): @@ -57,6 +44,7 @@ class UnitedArabEmirates(HolidayBase): # raised that this holiday is missing. hijri-converter requires # Python >= 3.6 country = "AE" + weekend = (FR.weekday, SA.weekday) def __init__(self, **kwargs): HolidayBase.__init__(self, **kwargs) diff --git a/holidays/countries/united_kingdom.py b/holidays/countries/united_kingdom.py index 9e9821c06..fe539b205 100644 --- a/holidays/countries/united_kingdom.py +++ b/holidays/countries/united_kingdom.py @@ -8,34 +8,14 @@ # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) -import warnings from datetime import date from typing import Any from dateutil.easter import easter from dateutil.relativedelta import relativedelta as rd -from dateutil.relativedelta import MO, FR - -from holidays.constants import ( - MON, - TUE, - WED, - THU, - FRI, - SAT, - SUN, - WEEKEND, - JAN, - MAR, - APR, - MAY, - JUN, - JUL, - AUG, - SEP, - NOV, - DEC, -) +from dateutil.relativedelta import MO, TU, WE, TH, FR, SA, SU + +from holidays.constants import JAN, MAR, APR, MAY, JUN, JUL, AUG, SEP, NOV, DEC from holidays.holiday_base import HolidayBase @@ -60,9 +40,9 @@ def _populate(self, year: int) -> None: if year >= 1974: name = "New Year's Day" self[date(year, JAN, 1)] = name - if self.observed and date(year, JAN, 1).weekday() == SUN: + if self.observed and date(year, JAN, 1).weekday() == SU.weekday: self[date(year, JAN, 1) + rd(days=+1)] = name + " (Observed)" - elif self.observed and date(year, JAN, 1).weekday() == SAT: + elif self.observed and date(year, JAN, 1).weekday() == SA.weekday: self[date(year, JAN, 1) + rd(days=+2)] = name + " (Observed)" # New Year Holiday @@ -71,9 +51,9 @@ def _populate(self, year: int) -> None: if self.subdiv == "UK": name += " [Scotland]" self[date(year, JAN, 2)] = name - if self.observed and date(year, JAN, 2).weekday() in WEEKEND: + if self.observed and self._is_weekend(date(year, JAN, 2)): self[date(year, JAN, 2) + rd(days=+2)] = name + " (Observed)" - elif self.observed and date(year, JAN, 2).weekday() == MON: + elif self.observed and date(year, JAN, 2).weekday() == MO.weekday: self[date(year, JAN, 2) + rd(days=+1)] = name + " (Observed)" # St. Patrick's Day @@ -82,7 +62,7 @@ def _populate(self, year: int) -> None: if self.subdiv == "UK": name += " [Northern Ireland]" self[date(year, MAR, 17)] = name - if self.observed and date(year, MAR, 17).weekday() in WEEKEND: + if self.observed and self._is_weekend(date(year, MAR, 17)): self[date(year, MAR, 17) + rd(weekday=MO)] = ( name + " (Observed)" ) @@ -111,9 +91,9 @@ def _populate(self, year: int) -> None: # Christmas Day name = "Christmas Day" self[date(year, DEC, 25)] = name - if self.observed and date(year, DEC, 25).weekday() == SAT: + if self.observed and date(year, DEC, 25).weekday() == SA.weekday: self[date(year, DEC, 27)] = name + " (Observed)" - elif self.observed and date(year, DEC, 25).weekday() == SUN: + elif self.observed and date(year, DEC, 25).weekday() == SU.weekday: self[date(year, DEC, 27)] = name + " (Observed)" # Overwrite to modify country specific holidays @@ -145,19 +125,19 @@ def _country_specific(self, year: int) -> None: dt = date(year, MAY, 8) else: dt = date(year, MAY, 1) - if dt.weekday() == MON: + if dt.weekday() == MO.weekday: self[dt] = name - if dt.weekday() == TUE: + if dt.weekday() == TU.weekday: self[dt + rd(days=+6)] = name - if dt.weekday() == WED: + if dt.weekday() == WE.weekday: self[dt + rd(days=+5)] = name - if dt.weekday() == THU: + if dt.weekday() == TH.weekday: self[dt + rd(days=+4)] = name - if dt.weekday() == FRI: + if dt.weekday() == FR.weekday: self[dt + rd(days=+3)] = name - if dt.weekday() == SAT: + if dt.weekday() == SA.weekday: self[dt + rd(days=+2)] = name - if dt.weekday() == SUN: + if dt.weekday() == SU.weekday: self[dt + rd(days=+1)] = name # Spring bank holiday (last Monday in May) @@ -179,9 +159,9 @@ def _country_specific(self, year: int) -> None: # Boxing Day name = "Boxing Day" self[date(year, DEC, 26)] = name - if self.observed and date(year, DEC, 26).weekday() == SAT: + if self.observed and date(year, DEC, 26).weekday() == SA.weekday: self[date(year, DEC, 28)] = name + " (Observed)" - elif self.observed and date(year, DEC, 26).weekday() == SUN: + elif self.observed and date(year, DEC, 26).weekday() == SU.weekday: self[date(year, DEC, 28)] = name + " (Observed)" # Special holidays diff --git a/holidays/countries/united_states.py b/holidays/countries/united_states.py index 2e11e35ee..55256ea7b 100644 --- a/holidays/countries/united_states.py +++ b/holidays/countries/united_states.py @@ -12,29 +12,11 @@ from datetime import date from dateutil.easter import easter -from dateutil.relativedelta import FR, MO, TH, TU +from dateutil.relativedelta import MO, TH, TU, WE, FR, SA, SU from dateutil.relativedelta import relativedelta as rd -from holidays.constants import ( - MON, - WED, - FRI, - SAT, - SUN, - WEEKEND, - JAN, - FEB, - MAR, - APR, - MAY, - JUN, - JUL, - AUG, - SEP, - OCT, - NOV, - DEC, -) +from holidays.constants import JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP +from holidays.constants import OCT, NOV, DEC from holidays.holiday_base import HolidayBase @@ -112,11 +94,11 @@ def _populate(self, year): if year > 1870: name = "New Year's Day" self[date(year, JAN, 1)] = name - if self.observed and date(year, JAN, 1).weekday() == SUN: + if self.observed and date(year, JAN, 1).weekday() == SU.weekday: self[date(year, JAN, 1) + rd(days=+1)] = name + " (Observed)" # The following year's observed New Year's Day can be in this year # when it falls on a Friday (Jan 1st is a Saturday). - if self.observed and date(year, DEC, 31).weekday() == FRI: + if self.observed and date(year, DEC, 31).weekday() == FR.weekday: self[date(year, DEC, 31)] = name + " (Observed)" # Epiphany @@ -147,11 +129,11 @@ def _populate(self, year): name = "Inauguration Day" if (year - 1789) % 4 == 0 and year >= 1937: self[date(year, JAN, 20)] = name - if date(year, JAN, 20).weekday() == SUN: + if date(year, JAN, 20).weekday() == SU.weekday: self[date(year, JAN, 21)] = name + " (Observed)" elif (year - 1789) % 4 == 0: self[date(year, MAR, 4)] = name - if date(year, MAR, 4).weekday() == SUN: + if date(year, MAR, 4).weekday() == SU.weekday: self[date(year, MAR, 5)] = name + " (Observed)" # Martin Luther King Jr. Day @@ -180,9 +162,9 @@ def _populate(self, year): self.subdiv in ("CT", "IL", "IA", "NJ", "NY") and year >= 1971 ) or (self.subdiv == "CA" and 1971 <= year <= 2009): self[date(year, FEB, 12)] = name - if self.observed and date(year, FEB, 12).weekday() == SAT: + if self.observed and date(year, FEB, 12).weekday() == SA.weekday: self[date(year, FEB, 11)] = name + " (Observed)" - elif self.observed and date(year, FEB, 12).weekday() == SUN: + elif self.observed and date(year, FEB, 12).weekday() == SU.weekday: self[date(year, FEB, 13)] = name + " (Observed)" # Susan B. Anthony Day @@ -208,7 +190,7 @@ def _populate(self, year): elif year >= 1879: self[date(year, FEB, 22)] = name elif self.subdiv == "GA": - if date(year, DEC, 24).weekday() != WED: + if date(year, DEC, 24).weekday() != WE.weekday: self[date(year, DEC, 24)] = name else: self[date(year, DEC, 26)] = name @@ -239,7 +221,7 @@ def _populate(self, year): if self.subdiv == "MA" and year >= 1901: name = "Evacuation Day" self[date(year, MAR, 17)] = name - if date(year, MAR, 17).weekday() in WEEKEND: + if self._is_weekend(date(year, MAR, 17)): self[date(year, MAR, 17) + rd(weekday=MO)] = ( name + " (Observed)" ) @@ -247,16 +229,16 @@ def _populate(self, year): # Emancipation Day if self.subdiv == "PR": self[date(year, MAR, 22)] = "Emancipation Day" - if self.observed and date(year, MAR, 22).weekday() == SUN: + if self.observed and date(year, MAR, 22).weekday() == SU.weekday: self[date(year, MAR, 23)] = "Emancipation Day (Observed)" # Prince Jonah Kuhio Kalanianaole Day if self.subdiv == "HI" and year >= 1949: name = "Prince Jonah Kuhio Kalanianaole Day" self[date(year, MAR, 26)] = name - if self.observed and date(year, MAR, 26).weekday() == SAT: + if self.observed and date(year, MAR, 26).weekday() == SA.weekday: self[date(year, MAR, 25)] = name + " (Observed)" - elif self.observed and date(year, MAR, 26).weekday() == SUN: + elif self.observed and date(year, MAR, 26).weekday() == SU.weekday: self[date(year, MAR, 27)] = name + " (Observed)" # Seward's Day @@ -270,7 +252,7 @@ def _populate(self, year): name = "César Chávez Day" if self.subdiv == "CA" and year >= 1995: self[date(year, MAR, 31)] = name - if self.observed and date(year, MAR, 31).weekday() == SUN: + if self.observed and date(year, MAR, 31).weekday() == SU.weekday: self[date(year, APR, 1)] = name + " (Observed)" elif self.subdiv == "TX" and year >= 2000: self[date(year, MAR, 31)] = name @@ -283,9 +265,9 @@ def _populate(self, year): if self.subdiv == "DC" and year >= 2005: name = "Emancipation Day" self[date(year, APR, 16)] = name - if self.observed and date(year, APR, 16).weekday() == SAT: + if self.observed and date(year, APR, 16).weekday() == SA.weekday: self[date(year, APR, 15)] = name + " (Observed)" - elif self.observed and date(year, APR, 16).weekday() == SUN: + elif self.observed and date(year, APR, 16).weekday() == SU.weekday: self[date(year, APR, 17)] = name + " (Observed)" # Patriots' Day @@ -352,9 +334,9 @@ def _populate(self, year): if self.subdiv == "MO" and year >= 1949: name = "Truman Day" self[date(year, MAY, 8)] = name - if self.observed and date(year, MAY, 8).weekday() == SAT: + if self.observed and date(year, MAY, 8).weekday() == SA.weekday: self[date(year, MAY, 7)] = name + " (Observed)" - elif self.observed and date(year, MAY, 8).weekday() == SUN: + elif self.observed and date(year, MAY, 8).weekday() == SU.weekday: self[date(year, MAY, 10)] = name + " (Observed)" # Memorial Day @@ -367,9 +349,9 @@ def _populate(self, year): if year > 2020: name = "Juneteenth National Independence Day" self[date(year, JUN, 19)] = name - if self.observed and date(year, JUN, 19).weekday() == SAT: + if self.observed and date(year, JUN, 19).weekday() == SA.weekday: self[date(year, JUN, 18)] = name + " (Observed)" - elif self.observed and date(year, JUN, 19).weekday() == SUN: + elif self.observed and date(year, JUN, 19).weekday() == SU.weekday: self[date(year, JUN, 20)] = name + " (Observed)" # Jefferson Davis Birthday @@ -382,9 +364,9 @@ def _populate(self, year): name = "Kamehameha Day" self[date(year, JUN, 11)] = name if self.observed and year >= 2011: - if date(year, JUN, 11).weekday() == SAT: + if date(year, JUN, 11).weekday() == SA.weekday: self[date(year, JUN, 10)] = name + " (Observed)" - elif date(year, JUN, 11).weekday() == SUN: + elif date(year, JUN, 11).weekday() == SU.weekday: self[date(year, JUN, 12)] = name + " (Observed)" # Emancipation Day In Texas if self.subdiv == "TX" and year >= 1980: @@ -394,9 +376,9 @@ def _populate(self, year): name = "West Virginia Day" if self.subdiv == "WV" and year >= 1927: self[date(year, JUN, 20)] = name - if self.observed and date(year, JUN, 20).weekday() == SAT: + if self.observed and date(year, JUN, 20).weekday() == SA.weekday: self[date(year, JUN, 19)] = name + " (Observed)" - elif self.observed and date(year, JUN, 20).weekday() == SUN: + elif self.observed and date(year, JUN, 20).weekday() == SU.weekday: self[date(year, JUN, 21)] = name + " (Observed)" # Emancipation Day in US Virgin Islands @@ -407,9 +389,9 @@ def _populate(self, year): if year > 1870: name = "Independence Day" self[date(year, JUL, 4)] = name - if self.observed and date(year, JUL, 4).weekday() == SAT: + if self.observed and date(year, JUL, 4).weekday() == SA.weekday: self[date(year, JUL, 4) + rd(days=-1)] = name + " (Observed)" - elif self.observed and date(year, JUL, 4).weekday() == SUN: + elif self.observed and date(year, JUL, 4).weekday() == SU.weekday: self[date(year, JUL, 4) + rd(days=+1)] = name + " (Observed)" # Liberation Day (Guam) @@ -420,15 +402,15 @@ def _populate(self, year): if self.subdiv == "UT" and year >= 1849: name = "Pioneer Day" self[date(year, JUL, 24)] = name - if self.observed and date(year, JUL, 24).weekday() == SAT: + if self.observed and date(year, JUL, 24).weekday() == SA.weekday: self[date(year, JUL, 24) + rd(days=-1)] = name + " (Observed)" - elif self.observed and date(year, JUL, 24).weekday() == SUN: + elif self.observed and date(year, JUL, 24).weekday() == SU.weekday: self[date(year, JUL, 24) + rd(days=+1)] = name + " (Observed)" # Constitution Day if self.subdiv == "PR": self[date(year, JUL, 25)] = "Constitution Day" - if self.observed and date(year, JUL, 25).weekday() == SUN: + if self.observed and date(year, JUL, 25).weekday() == SU.weekday: self[date(year, JUL, 26)] = "Constitution Day (Observed)" # Victory Day @@ -443,9 +425,9 @@ def _populate(self, year): if self.subdiv == "VT" and year >= 1778: name = "Bennington Battle Day" self[date(year, AUG, 16)] = name - if self.observed and date(year, AUG, 16).weekday() == SAT: + if self.observed and date(year, AUG, 16).weekday() == SA.weekday: self[date(year, AUG, 15)] = name + " (Observed)" - elif self.observed and date(year, AUG, 16).weekday() == SUN: + elif self.observed and date(year, AUG, 16).weekday() == SU.weekday: self[date(year, AUG, 17)] = name + " (Observed)" # Lyndon Baines Johnson Day @@ -473,9 +455,9 @@ def _populate(self, year): if self.subdiv == "AK" and year >= 1867: name = "Alaska Day" self[date(year, OCT, 18)] = name - if self.observed and date(year, OCT, 18).weekday() == SAT: + if self.observed and date(year, OCT, 18).weekday() == SA.weekday: self[date(year, OCT, 18) + rd(days=-1)] = name + " (Observed)" - elif self.observed and date(year, OCT, 18).weekday() == SUN: + elif self.observed and date(year, OCT, 18).weekday() == SU.weekday: self[date(year, OCT, 18) + rd(days=+1)] = name + " (Observed)" # Nevada Day @@ -484,9 +466,9 @@ def _populate(self, year): if year >= 2000: dt += rd(weekday=FR(-1)) self[dt] = "Nevada Day" - if self.observed and dt.weekday() == SAT: + if self.observed and dt.weekday() == SA.weekday: self[dt + rd(days=-1)] = "Nevada Day (Observed)" - elif self.observed and dt.weekday() == SUN: + elif self.observed and dt.weekday() == SU.weekday: self[dt + rd(days=+1)] = "Nevada Day (Observed)" # Liberty Day @@ -516,15 +498,15 @@ def _populate(self, year): self[date(year, OCT, 1) + rd(weekday=MO(+4))] = name elif year >= 1938: self[date(year, NOV, 11)] = name - if self.observed and date(year, NOV, 11).weekday() == SAT: + if self.observed and date(year, NOV, 11).weekday() == SA.weekday: self[date(year, NOV, 11) + rd(days=-1)] = name + " (Observed)" - elif self.observed and date(year, NOV, 11).weekday() == SUN: + elif self.observed and date(year, NOV, 11).weekday() == SU.weekday: self[date(year, NOV, 11) + rd(days=+1)] = name + " (Observed)" # Discovery Day if self.subdiv == "PR": self[date(year, NOV, 19)] = "Discovery Day" - if self.observed and date(year, NOV, 19).weekday() == SUN: + if self.observed and date(year, NOV, 19).weekday() == SU.weekday: self[date(year, NOV, 20)] = "Discovery Day (Observed)" # Thanksgiving @@ -584,19 +566,19 @@ def _populate(self, year): self[date(year, DEC, 24)] = name name = name + " (Observed)" # If on Friday, observed on Thursday - if self.observed and date(year, DEC, 24).weekday() == FRI: + if self.observed and date(year, DEC, 24).weekday() == FR.weekday: self[date(year, DEC, 24) + rd(days=-1)] = name # If on Saturday or Sunday, observed on Friday - elif self.observed and date(year, DEC, 24).weekday() in WEEKEND: + elif self.observed and self._is_weekend(date(year, DEC, 24)): self[date(year, DEC, 24) + rd(weekday=FR(-1))] = name # Christmas Day if year > 1870: name = "Christmas Day" self[date(year, DEC, 25)] = "Christmas Day" - if self.observed and date(year, DEC, 25).weekday() == SAT: + if self.observed and date(year, DEC, 25).weekday() == SA.weekday: self[date(year, DEC, 25) + rd(days=-1)] = name + " (Observed)" - elif self.observed and date(year, DEC, 25).weekday() == SUN: + elif self.observed and date(year, DEC, 25).weekday() == SU.weekday: self[date(year, DEC, 25) + rd(days=+1)] = name + " (Observed)" # Day After Christmas @@ -605,10 +587,10 @@ def _populate(self, year): self[date(year, DEC, 26)] = name name = name + " (Observed)" # If on Saturday or Sunday, observed on Monday - if self.observed and date(year, DEC, 26).weekday() in WEEKEND: + if self.observed and self._is_weekend(date(year, DEC, 26)): self[date(year, DEC, 26) + rd(weekday=MO)] = name # If on Monday, observed on Tuesday - elif self.observed and date(year, DEC, 26).weekday() == MON: + elif self.observed and date(year, DEC, 26).weekday() == MO.weekday: self[date(year, DEC, 26) + rd(days=+1)] = name elif self.subdiv == "TX" and year >= 1981: self[date(year, DEC, 26)] = "Day After Christmas" @@ -621,7 +603,7 @@ def _populate(self, year): ): name = "New Year's Eve" self[date(year, DEC, 31)] = name - if self.observed and date(year, DEC, 31).weekday() == SAT: + if self.observed and date(year, DEC, 31).weekday() == SA.weekday: self[date(year, DEC, 30)] = name + " (Observed)" diff --git a/holidays/countries/uruguay.py b/holidays/countries/uruguay.py index 9154963f6..ba61603b7 100644 --- a/holidays/countries/uruguay.py +++ b/holidays/countries/uruguay.py @@ -15,18 +15,7 @@ from dateutil.relativedelta import relativedelta as rd from dateutil.relativedelta import TH, FR -from holidays.constants import ( - WEEKEND, - JAN, - APR, - MAY, - JUN, - JUL, - AUG, - OCT, - NOV, - DEC, -) +from holidays.constants import JAN, APR, MAY, JUN, JUL, AUG, OCT, NOV, DEC from holidays.holiday_base import HolidayBase @@ -40,7 +29,7 @@ def __init__(self, **kwargs): def _populate(self, year): # New Year's Day - if not self.observed and date(year, JAN, 1).weekday() in WEEKEND: + if not self.observed and self._is_weekend(date(year, JAN, 1)): pass else: self[date(year, JAN, 1)] = "Año Nuevo [New Year's Day]" @@ -53,7 +42,7 @@ def _populate(self, year): # Día de Reyes - Feriado en el cual se conmemora la llegada de # los reyes magos a Jesus - if not self.observed and date(year, JAN, 6).weekday() in WEEKEND: + if not self.observed and self._is_weekend(date(year, JAN, 6)): pass else: self[date(year, JAN, 6)] = "Día de Reyes" @@ -66,13 +55,13 @@ def _populate(self, year): self[easter(year) + rd(weekday=TH(-1))] = name_thu self[easter(year) + rd(weekday=FR(-1))] = name_fri - if not self.observed and easter(year).weekday() in WEEKEND: + if not self.observed and self._is_weekend(easter(year)): pass else: self[easter(year)] = name_easter # Desembarco de los 33 Orientales en la playa de la Agraciada - if not self.observed and date(year, APR, 19).weekday() in WEEKEND: + if not self.observed and self._is_weekend(date(year, APR, 19)): pass else: self[date(year, APR, 19)] = ( @@ -84,41 +73,41 @@ def _populate(self, year): # Día de los Trabajadores name = "Día del Trabajo [Labour Day]" - if not self.observed and date(year, MAY, 1).weekday() in WEEKEND: + if not self.observed and self._is_weekend(date(year, MAY, 1)): pass else: self[date(year, MAY, 1)] = name # Batalla de las piedras name = "Batalla de las Piedras [Battle of the stones]" - if not self.observed and date(year, MAY, 17).weekday() in WEEKEND: + if not self.observed and self._is_weekend(date(year, MAY, 17)): pass else: self[date(year, MAY, 17)] = name # Natalicio de José Gervacio Artigas name = "Natalicio de José Gervacio Artigas " - if not self.observed and date(year, JUN, 19).weekday() in WEEKEND: + if not self.observed and self._is_weekend(date(year, JUN, 19)): pass else: self[date(year, JUN, 19)] = name # Jura de la Constitución name = "Jura de la constitución " - if not self.observed and date(year, JUL, 18).weekday() in WEEKEND: + if not self.observed and self._is_weekend(date(year, JUL, 18)): pass else: self[date(year, JUL, 18)] = name # Declaratoria de la Independencia name = "Día de la Independencia [Independence Day]" - if not self.observed and date(year, AUG, 25).weekday() in WEEKEND: + if not self.observed and self._is_weekend(date(year, AUG, 25)): pass else: self[date(year, AUG, 25)] = name # Respect for Cultural Diversity Day or Columbus day - if not self.observed and date(year, OCT, 11).weekday() in WEEKEND: + if not self.observed and self._is_weekend(date(year, OCT, 11)): pass elif year < 2010: self[date(year, OCT, 11)] = "Día de la Raza [Columbus day]" @@ -130,7 +119,7 @@ def _populate(self, year): ) # Día de los difuntos name = "Día de los difuntos" - if not self.observed and date(year, NOV, 2).weekday() in WEEKEND: + if not self.observed and self._is_weekend(date(year, NOV, 2)): pass else: self[date(year, NOV, 2)] = name diff --git a/holidays/countries/vietnam.py b/holidays/countries/vietnam.py index 83427cfff..fa9623d00 100644 --- a/holidays/countries/vietnam.py +++ b/holidays/countries/vietnam.py @@ -9,15 +9,16 @@ # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) -from datetime import date, datetime, timedelta +from datetime import date from dateutil.relativedelta import relativedelta as rd +from dateutil.relativedelta import SA, SU # Installation: pip install korean_lunar_calendar # URL: https://github.com/usingsky/korean_lunar_calendar_py/ from korean_lunar_calendar import KoreanLunarCalendar -from holidays.constants import JAN, APR, MAY, SEP, SAT, SUN +from holidays.constants import JAN, APR, MAY, SEP from holidays.holiday_base import HolidayBase @@ -41,9 +42,9 @@ def _populate(self, year): self[first_date] = name if self.observed: self[first_date] = name - if first_date.weekday() == SAT: + if first_date.weekday() == SA.weekday: self[first_date + rd(days=+2)] = name + " observed" - elif first_date.weekday() == SUN: + elif first_date.weekday() == SU.weekday: self[first_date + rd(days=+1)] = name + " observed" # Lunar New Year diff --git a/holidays/countries/zambia.py b/holidays/countries/zambia.py index 73479dad9..01796815b 100644 --- a/holidays/countries/zambia.py +++ b/holidays/countries/zambia.py @@ -13,8 +13,9 @@ from dateutil.easter import easter from dateutil.relativedelta import relativedelta as rd +from dateutil.relativedelta import SU -from holidays.constants import SUN, JAN, MAR, APR, MAY, JUL, AUG, OCT, DEC +from holidays.constants import JAN, MAR, APR, MAY, JUL, AUG, OCT, DEC from holidays.holiday_base import HolidayBase @@ -81,7 +82,7 @@ def _populate(self, year): # it rolls over to the following Monday for k, v in list(self.items()): if self.observed and year > 1964: - if k.weekday() == SUN: + if k.weekday() == SU.weekday: self[k + rd(days=1)] = v + " (Observed)" # Once-off public holidays diff --git a/holidays/countries/zimbabwe.py b/holidays/countries/zimbabwe.py index fd0fe5aa4..954711053 100644 --- a/holidays/countries/zimbabwe.py +++ b/holidays/countries/zimbabwe.py @@ -13,8 +13,9 @@ from dateutil.easter import easter from dateutil.relativedelta import relativedelta as rd +from dateutil.relativedelta import MO, TU, SU -from holidays.constants import MON, TUE, SUN, JAN, FEB, APR, MAY, AUG, DEC +from holidays.constants import JAN, FEB, APR, MAY, AUG, DEC from holidays.holiday_base import HolidayBase @@ -53,7 +54,7 @@ def _populate(self, year): # Find the date of the 2nd Monday # for the given year zimbabwe_heroes_day = date(year, AUG, 8) - while zimbabwe_heroes_day.isoweekday() != MON and ( + while zimbabwe_heroes_day.weekday() != MO.weekday and ( 8 <= zimbabwe_heroes_day.day <= 14 ): zimbabwe_heroes_day = zimbabwe_heroes_day + rd(days=1) @@ -64,7 +65,7 @@ def _populate(self, year): # Find the date of the 2nd Tuesday # for the given year defence_forces_day = datetime(year, AUG, 8) - while defence_forces_day.isoweekday() != TUE and ( + while defence_forces_day.weekday() != TU.weekday and ( 8 <= defence_forces_day.day <= 14 ): defence_forces_day = defence_forces_day + rd(days=1) @@ -76,7 +77,11 @@ def _populate(self, year): self[date(year, DEC, 26)] = "Boxing Day" for k, v in list(self.items()): - if self.observed and k.weekday() == SUN and k.year == year: + if ( + self.observed + and k.weekday() == SU.weekday + and k.year == year + ): add_days = 1 while self.get(k + rd(days=add_days)) is not None: add_days += 1 diff --git a/holidays/financial/ny_stock_exchange.py b/holidays/financial/ny_stock_exchange.py index b3a947b30..21aaf3ea9 100644 --- a/holidays/financial/ny_stock_exchange.py +++ b/holidays/financial/ny_stock_exchange.py @@ -12,23 +12,11 @@ from datetime import date, timedelta from dateutil.easter import easter -from dateutil.relativedelta import FR, MO, TH, TU +from dateutil.relativedelta import MO, TU, WE, TH, FR from dateutil.relativedelta import relativedelta as rd -from holidays.constants import ( - APR, - AUG, - DEC, - FEB, - JAN, - JUL, - JUN, - MAR, - MAY, - NOV, - OCT, - SEP, -) +from holidays.constants import JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP +from holidays.constants import OCT, NOV, DEC from holidays.holiday_base import HolidayBase @@ -72,7 +60,7 @@ def _populate(self, year): # As per Rule 7.2.: check if next year's NYD falls on Saturday and # needs to be observed on Friday (Dec 31 of previous year). dec_31 = date(year, DEC, 31) - if dec_31.isoweekday() == 5: + if dec_31.weekday() == FR.weekday: self._set_observed_date(dec_31 + rd(days=+1), "New Year's Day") # MLK - observed 1998 - 3rd Monday of Jan @@ -191,7 +179,7 @@ def _populate(self, year): begin + timedelta(days=n) for n in range((end - begin).days + 1) ): - if d.isoweekday() in [6, 7]: + if self._is_weekend(d): continue self[d] = "World War I" elif year == 1917: @@ -223,7 +211,7 @@ def _populate(self, year): begin + timedelta(days=n) for n in range((end - begin).days + 1) ): - if d.isoweekday() in [6, 7]: + if self._is_weekend(d): continue self[d] = "Special Bank Holiday" elif year == 1945: @@ -253,7 +241,7 @@ def _populate(self, year): begin + timedelta(days=n) for n in range((end - begin).days + 1) ): - if d.isoweekday() != 3: # Wednesday special holiday + if d.weekday() != WE.weekday: # Wednesday special holiday continue self[d] = "Paper Crisis" elif year == 1969: diff --git a/holidays/holiday_base.py b/holidays/holiday_base.py index b1a2e49c0..2692e92aa 100644 --- a/holidays/holiday_base.py +++ b/holidays/holiday_base.py @@ -13,21 +13,11 @@ import warnings from datetime import date, datetime, timedelta -from typing import ( - TYPE_CHECKING, - Any, - Dict, - Iterable, - List, - Mapping, - Optional, - Set, - Tuple, - Union, - cast, -) +from typing import Any, Dict, Iterable, List, Mapping, Optional, Set, Tuple +from typing import Union, cast from dateutil.parser import parse +from dateutil.relativedelta import SA, SU DateLike = Union[date, datetime, str, float, int] @@ -181,6 +171,8 @@ class HolidayBase(Dict[date, str]): _deprecated_subdivisions: List[str] = [] """Other subdivisions whose names are deprecated or aliases of the official ones.""" + weekend: Tuple[int, int] = (SA.weekday, SU.weekday) + """Country weekend days.""" def __init__( self, @@ -555,6 +547,13 @@ def _populate(self, year: int) -> None: """meta: public""" pass + def _is_weekend(self, dt): + """ + Returns True if date's week day is a weekend day. + Returns False otherwise. + """ + return dt.weekday() in self.weekend + def __reduce__(self) -> Union[str, Tuple[Any, ...]]: return super().__reduce__() diff --git a/pyproject.toml b/pyproject.toml index 0c96268f0..9a8913c78 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -50,5 +50,6 @@ exclude_lines = [ [tool.isort] line_length = 79 +multi_line_output = 9 no_inline_sort = true profile = "black" diff --git a/setup.cfg b/setup.cfg index cafeb29ce..b4f5a4a20 100644 --- a/setup.cfg +++ b/setup.cfg @@ -43,14 +43,11 @@ holidays = py.typed current_version = 0.17 [flake8] -extend-ignore = E203,F401,W503,W504 -exclude = __init__.py,*.pyc,tests.py,build,dist -paths = ./holidays/ ./tests/ - -[isort] -line_length = 79 -no_inline_sort = true -profile = black +per-file-ignores = + holidays/__init__.py:F401,F403 + holidays/countries/__init__.py:F401 + holidays/financial/__init__.py:F401 + test/test_holiday_base.py:E203 [rstcheck] ignore_language = python diff --git a/test/__init__.py b/test/__init__.py index 373691c9d..e69de29bb 100644 --- a/test/__init__.py +++ b/test/__init__.py @@ -1,12 +0,0 @@ -# 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 (c) 2017-2022 -# ryanss (c) 2014-2017 -# Website: https://github.com/dr-prodigy/python-holidays -# License: MIT (see LICENSE file) -from test.countries import * -from test.financial import * diff --git a/test/countries/test_czechia.py b/test/countries/test_czechia.py index 78d18b48a..e56feb93f 100644 --- a/test/countries/test_czechia.py +++ b/test/countries/test_czechia.py @@ -10,7 +10,6 @@ # License: MIT (see LICENSE file) import unittest -import warnings from datetime import date import holidays diff --git a/test/countries/test_india.py b/test/countries/test_india.py index b8fb12256..bf25d3c2c 100644 --- a/test/countries/test_india.py +++ b/test/countries/test_india.py @@ -14,7 +14,7 @@ from datetime import date import holidays -from holidays.constants import APR, AUG, DEC, FEB, JAN, JUN, MAR, MAY, NOV, OCT +from holidays.constants import FEB, MAR, OCT, NOV, DEC class TestIND(unittest.TestCase): diff --git a/test/countries/test_malaysia.py b/test/countries/test_malaysia.py index 89253ea09..d06974e16 100644 --- a/test/countries/test_malaysia.py +++ b/test/countries/test_malaysia.py @@ -13,20 +13,8 @@ from datetime import date import holidays -from holidays.constants import ( - APR, - AUG, - DEC, - FEB, - JAN, - JUL, - JUN, - MAR, - MAY, - NOV, - OCT, - SEP, -) +from holidays.constants import APR, AUG, DEC, FEB, JAN, JUL, JUN, MAR, MAY +from holidays.constants import NOV, OCT, SEP class TestMalaysia(unittest.TestCase): diff --git a/test/countries/test_malta.py b/test/countries/test_malta.py index 15bfdc6fa..343c57082 100644 --- a/test/countries/test_malta.py +++ b/test/countries/test_malta.py @@ -10,7 +10,6 @@ # License: MIT (see LICENSE file) import unittest -import warnings from datetime import date import holidays diff --git a/test/countries/test_poland.py b/test/countries/test_poland.py index f944a00cd..81084a87c 100644 --- a/test/countries/test_poland.py +++ b/test/countries/test_poland.py @@ -10,7 +10,6 @@ # License: MIT (see LICENSE file) import unittest -import warnings from datetime import date import holidays diff --git a/test/countries/test_slovakia.py b/test/countries/test_slovakia.py index 721210be8..320da75bb 100644 --- a/test/countries/test_slovakia.py +++ b/test/countries/test_slovakia.py @@ -10,7 +10,6 @@ # License: MIT (see LICENSE file) import unittest -import warnings from datetime import date import holidays diff --git a/test/countries/test_spain.py b/test/countries/test_spain.py index 996d83c5f..266341004 100644 --- a/test/countries/test_spain.py +++ b/test/countries/test_spain.py @@ -14,9 +14,6 @@ from datetime import date from itertools import product -from dateutil.easter import easter -from dateutil.relativedelta import relativedelta as rd - import holidays from holidays.utils import _islamic_to_gre diff --git a/test/countries/test_united_kingdom.py b/test/countries/test_united_kingdom.py index 9152108eb..cb54b9be9 100644 --- a/test/countries/test_united_kingdom.py +++ b/test/countries/test_united_kingdom.py @@ -10,7 +10,6 @@ # License: MIT (see LICENSE file) import unittest -import warnings from datetime import date from dateutil.relativedelta import relativedelta diff --git a/test/countries/test_united_states.py b/test/countries/test_united_states.py index 397f2fb5a..7d2c31779 100644 --- a/test/countries/test_united_states.py +++ b/test/countries/test_united_states.py @@ -12,7 +12,7 @@ import unittest from datetime import date -from dateutil.relativedelta import relativedelta +from dateutil.relativedelta import SA, SU, relativedelta import holidays @@ -175,7 +175,7 @@ def test_lincolns_birthday(self): self.assertIn(date(year, 2, 12), ia_holidays) self.assertIn(date(year, 2, 12), nj_holidays) self.assertIn(date(year, 2, 12), ny_holidays) - if date(year, 2, 12).weekday() == 5: + if date(year, 2, 12).weekday() == SA.weekday: self.assertNotIn(date(year, 2, 11), self.holidays) self.assertIn(date(year, 2, 11), ca_holidays) self.assertIn(date(year, 2, 11), ct_holidays) @@ -190,7 +190,7 @@ def test_lincolns_birthday(self): self.assertNotIn(date(year, 2, 11), ia_holidays) self.assertNotIn(date(year, 2, 11), nj_holidays) self.assertNotIn(date(year, 2, 11), ny_holidays) - if date(year, 2, 12).weekday() == 6: + if date(year, 2, 12).weekday() == SU.weekday: self.assertNotIn(date(year, 2, 13), self.holidays) self.assertIn(date(year, 2, 13), ca_holidays) self.assertIn(date(year, 2, 13), ct_holidays) @@ -213,7 +213,7 @@ def test_lincolns_birthday(self): self.assertIn(date(year, 2, 12), ia_holidays) self.assertIn(date(year, 2, 12), nj_holidays) self.assertIn(date(year, 2, 12), ny_holidays) - if date(year, 2, 12).weekday() == 5: + if date(year, 2, 12).weekday() == SA.weekday: self.assertNotIn(date(year, 2, 11), self.holidays) self.assertNotIn(date(year, 2, 11), ca_holidays) self.assertIn(date(year, 2, 11), ct_holidays) @@ -228,7 +228,7 @@ def test_lincolns_birthday(self): self.assertNotIn(date(year, 2, 11), ia_holidays) self.assertNotIn(date(year, 2, 11), nj_holidays) self.assertNotIn(date(year, 2, 11), ny_holidays) - if date(year, 2, 12).weekday() == 6: + if date(year, 2, 12).weekday() == SU.weekday: self.assertNotIn(date(year, 2, 13), self.holidays) self.assertNotIn(date(year, 2, 13), ca_holidays) self.assertIn(date(year, 2, 13), ct_holidays) diff --git a/test/financial/test_ny_stock_exchange.py b/test/financial/test_ny_stock_exchange.py index addd7049b..d1b0490aa 100644 --- a/test/financial/test_ny_stock_exchange.py +++ b/test/financial/test_ny_stock_exchange.py @@ -15,20 +15,8 @@ from dateutil.relativedelta import relativedelta, WE import holidays -from holidays.constants import ( - APR, - AUG, - DEC, - FEB, - JAN, - JUL, - JUN, - MAR, - MAY, - NOV, - OCT, - SEP, -) +from holidays.constants import APR, AUG, DEC, FEB, JAN, JUL, JUN, MAR, MAY +from holidays.constants import NOV, OCT, SEP class TestNewYorkStockExchange(unittest.TestCase): @@ -428,7 +416,7 @@ def _make_special_holiday_list(begin, end, days=None, weekends=False): begin + timedelta(days=n) for n in range((end - begin).days + 1) ): - if not weekends and d.isoweekday() in [6, 7]: + if not weekends and d.weekday() in holidays.NYSE.weekend: continue if days is None or d.isoweekday() in days: _list.append(d) diff --git a/test/test_holiday_base.py b/test/test_holiday_base.py index aee65fa3b..1aea09eb2 100644 --- a/test/test_holiday_base.py +++ b/test/test_holiday_base.py @@ -10,12 +10,11 @@ # License: MIT (see LICENSE file) import pickle -import sys import unittest import warnings from datetime import date, datetime, timedelta -from dateutil.relativedelta import relativedelta, MO +from dateutil.relativedelta import relativedelta, MO, TU, SA, SU import holidays @@ -168,6 +167,24 @@ def test_update(self): self.assertIn("2015-01-01", h) self.assertIn(date(2015, 12, 25), h) + def test_is_weekend(self): + h = holidays.HolidayBase() + + h.weekend = (MO.weekday, TU.weekday) + for dt in (date(2022, 10, 3), date(2022, 10, 4)): + self.assertTrue(h._is_weekend(dt)) + + h.weekend = () + for dt in (date(2022, 10, 3), date(2022, 10, 4)): + self.assertFalse(h._is_weekend(dt)) + + h.weekend = (SA.weekday, SU.weekday) + for dt in (date(2022, 10, 1), date(2022, 10, 2)): + self.assertTrue(h._is_weekend(dt)) + + for dt in (date(2022, 10, 3), date(2022, 10, 4)): + self.assertFalse(h._is_weekend(dt)) + def test_append(self): h = holidays.HolidayBase() h.update( From 3532409b7591c7fe68bc71b9ba4fe42857b92870 Mon Sep 17 00:00:00 2001 From: Arkadii Yakovets Date: Tue, 15 Nov 2022 09:15:01 -0800 Subject: [PATCH 002/138] Migrate special holidays for all countries. Move logic from `_populate` to `special_holidays` for: - Botswana - Eswatini - Hongkong - Ireland - Japan - South Korea - Lesotho - Namibia - Poland - Singapore - Slovakia - South Africa - Zambia --- holidays/countries/botswana.py | 5 +-- holidays/countries/eswatini.py | 14 +++----- holidays/countries/hongkong.py | 22 +++++++----- holidays/countries/ireland.py | 7 ++-- holidays/countries/japan.py | 13 +++---- holidays/countries/korea.py | 12 +++---- holidays/countries/lesotho.py | 9 +++-- holidays/countries/namibia.py | 13 +++---- holidays/countries/poland.py | 6 ++-- holidays/countries/singapore.py | 12 +++---- holidays/countries/slovakia.py | 10 +++--- holidays/countries/south_africa.py | 54 ++++++++++++----------------- holidays/countries/zambia.py | 11 +++--- test/countries/test_botswana.py | 2 +- test/countries/test_eswatini.py | 2 +- test/countries/test_hongkong.py | 6 ++-- test/countries/test_ireland.py | 3 ++ test/countries/test_korea.py | 3 ++ test/countries/test_lesotho.py | 2 +- test/countries/test_namibia.py | 3 +- test/countries/test_poland.py | 2 +- test/countries/test_singapore.py | 5 +-- test/countries/test_slovakia.py | 10 +++--- test/countries/test_south_africa.py | 15 ++++++-- 24 files changed, 118 insertions(+), 123 deletions(-) diff --git a/holidays/countries/botswana.py b/holidays/countries/botswana.py index 910181698..3060c0795 100644 --- a/holidays/countries/botswana.py +++ b/holidays/countries/botswana.py @@ -28,6 +28,7 @@ class Botswana(HolidayBase): """ country = "BW" + special_holidays = {2019: ((JUL, 2, "Public Holiday"),)} def _populate(self, year: int): super()._populate(year) @@ -97,10 +98,6 @@ def _populate(self, year: int): if " (Observed)" not in i: self[k + rd(days=1)] = i.lstrip() + " (Observed)" - # Once off ad-hoc holiday. - if year == 2019: - self[date(year, JUL, 2)] = "Public Holiday" - class BW(Botswana): pass diff --git a/holidays/countries/eswatini.py b/holidays/countries/eswatini.py index 00ca75bf5..34ab7fa92 100644 --- a/holidays/countries/eswatini.py +++ b/holidays/countries/eswatini.py @@ -26,6 +26,11 @@ class Eswatini(HolidayBase): """ country = "SZ" + special_holidays = { + # https://mg.co.za/article/1999-12-09-swaziland-declares-bank-holidays/ + 1999: ((DEC, 31, "Y2K changeover"),), + 2000: ((JAN, 3, "Y2K changeover"),), + } def _populate(self, year): super()._populate(year) @@ -58,15 +63,6 @@ def _populate(self, year): self[date(year, DEC, 25)] = "Christmas Day" self[date(year, DEC, 26)] = "Boxing Day" - # Once-off public holidays - y2k = "Y2K changeover" - - if year == 1999: - # https://mg.co.za/article/1999-12-09-swaziland-declares-bank-holidays/ - self[date(1999, DEC, 31)] = y2k - if year == 2000: - self[date(2000, JAN, 3)] = y2k - # As of 2021/1/1, whenever a public holiday falls on a # Sunday # it rolls over to the following Monday diff --git a/holidays/countries/hongkong.py b/holidays/countries/hongkong.py index 15dd9c976..d7f16ad27 100644 --- a/holidays/countries/hongkong.py +++ b/holidays/countries/hongkong.py @@ -42,6 +42,19 @@ class HongKong(HolidayBase): """ country = "HK" + special_holidays = { + # Special holiday on 2015 - The 70th anniversary day of the victory + # of the Chinese people's war of resistance against Japanese + # aggression. + 2015: ( + ( + SEP, + 3, + "The 70th anniversary day of the victory of the Chinese " + "people's war of resistance against Japanese aggression", + ), + ), + } def __init__(self, **kwargs): self.cnls = _ChineseLuniSolar() @@ -186,15 +199,6 @@ def _populate(self, year): else: self[hksar_date] = name - # Special holiday on 2015 - The 70th anniversary day of the victory - # of the Chinese people's war of resistance against Japanese aggression - name = ( - "The 70th anniversary day of the victory of the Chinese " - + "people's war of resistance against Japanese aggression" - ) - if year == 2015: - self[date(year, SEP, 3)] = name - # Chinese Mid-Autumn Festival name = "Chinese Mid-Autumn Festival" dt = self.cnls.lunar_to_gre(year, 8, 15) diff --git a/holidays/countries/ireland.py b/holidays/countries/ireland.py index bbc3b0a38..d7a7a5a42 100644 --- a/holidays/countries/ireland.py +++ b/holidays/countries/ireland.py @@ -37,6 +37,9 @@ class Ireland(HolidayBase): """ country = "IE" + special_holidays = { + 2022: ((MAR, 18, "Day of Remembrance and Recognition"),) + } def _populate(self, year): super()._populate(year) @@ -51,10 +54,6 @@ def _populate(self, year): if self.observed and dt.weekday() != FRI: self[dt + rd(weekday=MO)] = name + " (Observed)" - # One-off day of rememberance and recognition - if year == 2022: - self[date(year, MAR, 18)] = "Day of Rememberance and Recognition" - # St. Patrick's Day name = "St. Patrick's Day" dt = date(year, MAR, 17) diff --git a/holidays/countries/japan.py b/holidays/countries/japan.py index 0ba439907..f4924f77d 100644 --- a/holidays/countries/japan.py +++ b/holidays/countries/japan.py @@ -37,6 +37,9 @@ class Japan(HolidayBase): """ country = "JP" + special_holidays = { + 1989: ((FEB, 24, "大喪の礼"),), # State Funeral of Emperor Shōwa. + } def _populate(self, year): super()._populate(year) @@ -72,10 +75,6 @@ def _populate(self, year): else: self[date(year, APR, 29)] = "昭和の日" - # State Funeral of Emperor Shōwa - if year == 1989: - self[date(year, FEB, 24)] = "大喪の礼" - # Constitution Memorial Day self[date(year, MAY, 3)] = "憲法記念日" @@ -212,11 +211,9 @@ def _add_national_holidays(self, year): if year in (2032, 2049, 2060, 2077, 2088, 2094): self[date(year, SEP, 21)] = "国民の休日" - - if year in (2009, 2015, 2026, 2037, 2043, 2054, 2065, 2071, 2099): + elif year in (2009, 2015, 2026, 2037, 2043, 2054, 2065, 2071, 2099): self[date(year, SEP, 22)] = "国民の休日" - - if year == 2019: + elif year == 2019: self[date(year, APR, 30)] = "国民の休日" self[date(year, MAY, 2)] = "国民の休日" diff --git a/holidays/countries/korea.py b/holidays/countries/korea.py index 47577e30c..ee664f3b7 100644 --- a/holidays/countries/korea.py +++ b/holidays/countries/korea.py @@ -50,6 +50,11 @@ class Korea(HolidayBase): """ country = "KR" + special_holidays = { + # Just for year 2020 - since 2020.08.15 is Sat, the government + # decided to make 2020.08.17 holiday, yay + 2020: ((AUG, 17, "Alternative public holiday"),) + } def __init__(self, **kwargs): self.korean_cal = KoreanLunarCalendar() @@ -219,13 +224,6 @@ def _populate(self, year): christmas_date = date(year, DEC, 25) self[christmas_date] = name - # Just for year 2020 - since 2020.08.15 is Sat, the government - # decided to make 2020.08.17 holiday, yay - if year == 2020: - name = "Alternative public holiday" - alt_date = date(2020, AUG, 17) - self[alt_date] = name - # convert lunar calendar date to solar def get_solar_date(self, year: int, month: int, day: int) -> date: """Return the Gregorian calendar date of a Korean lunar calendar date. diff --git a/holidays/countries/lesotho.py b/holidays/countries/lesotho.py index 8c9161822..5020dfd89 100644 --- a/holidays/countries/lesotho.py +++ b/holidays/countries/lesotho.py @@ -24,6 +24,10 @@ class Lesotho(HolidayBase): """ country = "LS" + special_holidays = { + # https://tinyurl.com/lesothourl + 2002: ((APR, 4, "Heroes Day"), (MAY, 25, "Africa Day")) + } def _populate(self, year): super()._populate(year) @@ -33,11 +37,6 @@ def _populate(self, year): self[date(year, JAN, 1)] = "New Year's Day" self[date(year, MAR, 11)] = "Moshoeshoe's Day" - if year == 2002: - # https://tinyurl.com/lesothourl - self[date(year, APR, 4)] = "Heroes Day" - self[date(year, MAY, 25)] = "Africa Day" - if year < 2002: self[date(year, APR, 4)] = "Heroes Day" diff --git a/holidays/countries/namibia.py b/holidays/countries/namibia.py index 196a4766b..f6e40dec9 100644 --- a/holidays/countries/namibia.py +++ b/holidays/countries/namibia.py @@ -26,6 +26,11 @@ class Namibia(HolidayBase): """ country = "NA" + special_holidays = { + # https://gazettes.africa/archive/na/1999/na-government-gazette-dated-1999-11-22-no-2234.pdf + 1999: ((DEC, 31, "Y2K changeover"),), + 2000: ((JAN, 3, "Y2K changeover"),), + } def _populate(self, year): super()._populate(year) @@ -50,14 +55,6 @@ def _populate(self, year): self[date(year, MAY, 25)] = "Africa Day" self[date(year, AUG, 26)] = "Heroes' Day" - # Once-off public holidays - y2k = "Y2K changeover" - if year == 1999: - # https://gazettes.africa/archive/na/1999/na-government-gazette-dated-1999-11-22-no-2234.pdf - self[date(1999, DEC, 31)] = y2k - if year == 2000: - self[date(2000, JAN, 3)] = y2k - if year > 2004: # http://www.lac.org.na/laws/2004/3348.pdf self[ diff --git a/holidays/countries/poland.py b/holidays/countries/poland.py index b5cc62e31..c9c3530dd 100644 --- a/holidays/countries/poland.py +++ b/holidays/countries/poland.py @@ -25,6 +25,9 @@ class Poland(HolidayBase): """ country = "PL" + special_holidays = { + 2018: ((NOV, 12, "Narodowe Święto Niepodległości - 100-lecie"),) + } def _populate(self, year): super()._populate(year) @@ -50,9 +53,6 @@ def _populate(self, year): self[date(year, NOV, 1)] = "Uroczystość Wszystkich Świętych" if (1937 <= year <= 1945) or year >= 1989: self[date(year, NOV, 11)] = "Narodowe Święto Niepodległości" - if year == 2018: - name = "Narodowe Święto Niepodległości - 100-lecie" - self[date(year, NOV, 12)] = name self[date(year, DEC, 25)] = "Boże Narodzenie (pierwszy dzień)" self[date(year, DEC, 26)] = "Boże Narodzenie (drugi dzień)" diff --git a/holidays/countries/singapore.py b/holidays/countries/singapore.py index e0bde43fb..43df09244 100644 --- a/holidays/countries/singapore.py +++ b/holidays/countries/singapore.py @@ -37,6 +37,12 @@ class Singapore(HolidayBase): country = "SG" + special_holidays = { + # SG50 Public holiday + # Announced on 14 March 2015 + # https://www.mom.gov.sg/newsroom/press-releases/2015/sg50-public-holiday-on-7-august-2015 + 2015: ((AUG, 7, "SG50 Public Holiday"),) + } def __init__( self, @@ -290,12 +296,6 @@ def _populate(self, year) -> None: if year in dates_fixed_obs: self[date(year, *dates_fixed_obs[year])] = "Polling Day" - # SG50 Public holiday - # Announced on 14 March 2015 - # https://www.mom.gov.sg/newsroom/press-releases/2015/sg50-public-holiday-on-7-august-2015 - if year == 2015: - self[date(2015, AUG, 7)] = "SG50 Public Holiday" - # Check for holidays that fall on a Sunday and implement Section 4(2) # of the Holidays Act: "if any day specified in the Schedule falls on # a Sunday, the day next following not being itself a public holiday diff --git a/holidays/countries/slovakia.py b/holidays/countries/slovakia.py index 2a6ffbaeb..5186d38b2 100644 --- a/holidays/countries/slovakia.py +++ b/holidays/countries/slovakia.py @@ -26,6 +26,11 @@ class Slovakia(HolidayBase): """ country = "SK" + special_holidays = { + 2018: ( + (OCT, 30, "100. výročie prijatia Deklarácie slovenského národa"), + ) + } def _populate(self, year): super()._populate(year) @@ -55,10 +60,7 @@ def _populate(self, year): self[date(year, SEP, 1)] = "Deň Ústavy Slovenskej republiky" self[date(year, SEP, 15)] = "Sedembolestná Panna Mária" - if year == 2018: - self[date(year, OCT, 30)] = ( - "100. výročie prijatia" " Deklarácie slovenského národa" - ) + self[date(year, NOV, 1)] = "Sviatok Všetkých svätých" if year >= 2001: diff --git a/holidays/countries/south_africa.py b/holidays/countries/south_africa.py index 712d536e4..dc3736868 100644 --- a/holidays/countries/south_africa.py +++ b/holidays/countries/south_africa.py @@ -39,6 +39,28 @@ class SouthAfrica(HolidayBase): """ country = "ZA" + special_holidays = { + 1999: ( + (JUN, 2, "National and provincial government elections"), + (DEC, 31, "Y2K changeover"), + ), + 2000: ((JAN, 2, "Y2K changeover"),), + 2004: ((APR, 14, "National and provincial government elections"),), + 2006: ((MAR, 1, "Local government elections"),), + 2008: ((MAY, 2, "By presidential decree"),), + 2009: ((APR, 22, "National and provincial government elections"),), + 2011: ( + (MAY, 18, "Local government elections"), + (DEC, 27, "By presidential decree"), + ), + 2014: ((MAY, 7, "National and provincial government elections"),), + 2016: ( + (AUG, 3, "Local government elections"), + (DEC, 27, "By presidential decree"), + ), + 2019: ((MAY, 8, "National and provincial government elections"),), + 2021: ((NOV, 1, "Municipal elections"),), + } def _populate(self, year): super()._populate(year) @@ -83,38 +105,6 @@ def _populate(self, year): self[date(year, AUG, 9)] = "National Women's Day" self[date(year, SEP, 24)] = "Heritage Day" - # Once-off public holidays - national_election = "National and provincial government elections" - y2k = "Y2K changeover" - local_election = "Local government elections" - presidential = "By presidential decree" - municipal_election = "Municipal elections" - if year == 1999: - self[date(1999, JUN, 2)] = national_election - self[date(1999, DEC, 31)] = y2k - if year == 2000: - self[date(2000, JAN, 2)] = y2k - if year == 2004: - self[date(2004, APR, 14)] = national_election - if year == 2006: - self[date(2006, MAR, 1)] = local_election - if year == 2008: - self[date(2008, MAY, 2)] = presidential - if year == 2009: - self[date(2009, APR, 22)] = national_election - if year == 2011: - self[date(2011, MAY, 18)] = local_election - self[date(2011, DEC, 27)] = presidential - if year == 2014: - self[date(2014, MAY, 7)] = national_election - if year == 2016: - self[date(2016, AUG, 3)] = local_election - self[date(2016, DEC, 27)] = presidential - if year == 2019: - self[date(2019, MAY, 8)] = national_election - if year == 2021: - self[date(2021, NOV, 1)] = municipal_election - # As of 1995/1/1, whenever a public holiday falls on a Sunday, # it rolls over to the following Monday for k, v in list(self.items()): diff --git a/holidays/countries/zambia.py b/holidays/countries/zambia.py index ea3b78269..d770aef3d 100644 --- a/holidays/countries/zambia.py +++ b/holidays/countries/zambia.py @@ -27,6 +27,12 @@ class Zambia(HolidayBase): """ country = "ZM" + special_holidays = { + 2021: ( + (JUL, 2, "Memorial service for Kenneth Kaunda"), + (JUL, 7, "Funeral of Kenneth Kaunda"), + ) + } def _populate(self, year): super()._populate(year) @@ -86,11 +92,6 @@ def _populate(self, year): if k.weekday() == SUN: self[k + rd(days=1)] = v + " (Observed)" - # Once-off public holidays - if year == 2021: - self[date(2021, JUL, 2)] = "Memorial service for Kenneth Kaunda" - self[date(2021, JUL, 7)] = "Funeral of Kenneth Kaunda" - class ZM(Zambia): pass diff --git a/test/countries/test_botswana.py b/test/countries/test_botswana.py index 2a968ca5c..d428e2689 100644 --- a/test/countries/test_botswana.py +++ b/test/countries/test_botswana.py @@ -49,7 +49,7 @@ def test_not_holiday(self): self.assertNotIn(date(2015, 3, 2), self.holidays) self.assertNotIn(date(1964, 4, 16), self.holidays) - def test_onceoff(self): + def test_special_holidays(self): self.assertIn(date(2019, 7, 2), self.holidays) def test_saturday_and_monday(self): diff --git a/test/countries/test_eswatini.py b/test/countries/test_eswatini.py index 29d3d34e2..7d01ea5e4 100644 --- a/test/countries/test_eswatini.py +++ b/test/countries/test_eswatini.py @@ -34,7 +34,7 @@ def test_easter(self): self.assertIn(date(2017, 5, 25), self.holidays) self.assertNotIn(date(2017, 5, 26), self.holidays) - def test_once_off(self): + def test_special_holidays(self): self.assertIn(date(1999, 12, 31), self.holidays) # y2k self.assertIn(date(2000, 1, 3), self.holidays) # y2k diff --git a/test/countries/test_hongkong.py b/test/countries/test_hongkong.py index f604c57e4..34f387a54 100644 --- a/test/countries/test_hongkong.py +++ b/test/countries/test_hongkong.py @@ -28,10 +28,8 @@ def test_common(self): ) self.assertEqual( self.holidays[date(2015, 9, 3)], - "The 70th " - + "anniversary day of the victory of the Chinese " - + "people's war of resistance against Japanese " - + "aggression", + "The 70th anniversary day of the victory of the Chinese " + "people's war of resistance against Japanese aggression", ) def test_first_day_of_january(self): diff --git a/test/countries/test_ireland.py b/test/countries/test_ireland.py index d6b01965c..067c08863 100644 --- a/test/countries/test_ireland.py +++ b/test/countries/test_ireland.py @@ -102,3 +102,6 @@ def test_st_stephens_day(self): "St. Stephen's Day, Christmas Day (Observed)", ], ) + + def test_special_holidays(self): + self.assertIn("2022-03-18", self.holidays) diff --git a/test/countries/test_korea.py b/test/countries/test_korea.py index f77d3d0a6..33c1c85bd 100644 --- a/test/countries/test_korea.py +++ b/test/countries/test_korea.py @@ -404,3 +404,6 @@ def test_years_range(self): self.holidays = holidays.KR(years=range(2006, 2021)) for year in range(2006, 2021): self.assertIn(self.holidays[date(year, 1, 1)], "New Year's Day") + + def test_special_holidays(self): + self.assertIn("2020-08-17", self.holidays) diff --git a/test/countries/test_lesotho.py b/test/countries/test_lesotho.py index 418a23e68..7e5ad10b3 100644 --- a/test/countries/test_lesotho.py +++ b/test/countries/test_lesotho.py @@ -33,7 +33,7 @@ def test_easter(self): self.assertIn(date(2017, 5, 25), self.holidays) self.assertIn(date(2021, 5, 13), self.holidays) - def test_once_off(self): + def test_special_holidays(self): self.assertIn(date(2002, 4, 4), self.holidays) self.assertIn(date(2002, 5, 25), self.holidays) diff --git a/test/countries/test_namibia.py b/test/countries/test_namibia.py index e147b0776..9eeb2b9f3 100644 --- a/test/countries/test_namibia.py +++ b/test/countries/test_namibia.py @@ -33,10 +33,9 @@ def test_easter(self): self.assertIn(date(2017, 5, 25), self.holidays) self.assertIn(date(1994, 4, 1), self.holidays) - def test_onceoff(self): + def test_special_holidays(self): self.assertIn(date(1999, 12, 31), self.holidays) # Y2K self.assertIn(date(2000, 1, 3), self.holidays) # Y2K - self.assertNotIn(date(2010, 1, 10), self.holidays) # notinY2k def test_namibian_women_int_rights(self): self.assertIn(date(2004, 9, 10), self.holidays) diff --git a/test/countries/test_poland.py b/test/countries/test_poland.py index f944a00cd..999b883d1 100644 --- a/test/countries/test_poland.py +++ b/test/countries/test_poland.py @@ -43,7 +43,7 @@ def test_2017(self): self.assertNotIn(date(2017, 11, 12), self.holidays) - def test_2018(self): + def test_special_holidays(self): self.assertIn(date(2018, 11, 12), self.holidays) def test_swieto_trzech_kroli(self): diff --git a/test/countries/test_singapore.py b/test/countries/test_singapore.py index 6e25c3465..8678e1bd1 100644 --- a/test/countries/test_singapore.py +++ b/test/countries/test_singapore.py @@ -28,8 +28,6 @@ def test_Singapore(self): self.assertIn(date(1968, 12, 26), self.holidays) # latest polling day self.assertIn(date(2015, 9, 11), self.holidays) - # SG50 - self.assertIn(date(2015, 8, 7), self.holidays) # Year with lunar leap month self.assertIn(date(2015, 8, 7), self.holidays) # Latest holidays @@ -100,3 +98,6 @@ def test_aliases(self): self.assertIsInstance(h, holidays.Singapore) h = holidays.SGP() self.assertIsInstance(h, holidays.Singapore) + + def test_special_holidays(self): + self.assertIn(date(2015, 8, 7), self.holidays) diff --git a/test/countries/test_slovakia.py b/test/countries/test_slovakia.py index 721210be8..416177c08 100644 --- a/test/countries/test_slovakia.py +++ b/test/countries/test_slovakia.py @@ -43,9 +43,11 @@ def test_special_dates(self): self.assertNotIn(date(1996, 5, 8), self.holidays) self.assertIn(date(1997, 5, 8), self.holidays) - self.assertNotIn(date(2017, 10, 30), self.holidays) - self.assertIn(date(2018, 10, 30), self.holidays) - self.assertNotIn(date(2019, 10, 30), self.holidays) - self.assertNotIn(date(2000, 11, 17), self.holidays) self.assertIn(date(2001, 11, 17), self.holidays) + + def test_special_holidays(self): + self.assertIn(date(2018, 10, 30), self.holidays) + + self.assertNotIn(date(2017, 10, 30), self.holidays) + self.assertNotIn(date(2019, 10, 30), self.holidays) diff --git a/test/countries/test_south_africa.py b/test/countries/test_south_africa.py index c99f56896..3d01140f2 100644 --- a/test/countries/test_south_africa.py +++ b/test/countries/test_south_africa.py @@ -37,11 +37,20 @@ def test_not_holiday(self): self.assertNotIn("2016-12-28", self.holidays) self.assertNotIn("2015-03-02", self.holidays) - def test_onceoff(self): + def test_special_holidays(self): + self.assertIn("1999-06-02", self.holidays) self.assertIn("1999-12-31", self.holidays) # Y2K - self.assertIn("2008-05-02", self.holidays) # Y2K self.assertIn("2000-01-02", self.holidays) # Y2K - self.assertNotIn("2017-08-03", self.holidays) + self.assertIn("2004-04-14", self.holidays) + self.assertIn("2006-03-01", self.holidays) + self.assertIn("2008-05-02", self.holidays) + self.assertIn("2009-04-22", self.holidays) + self.assertIn("2011-05-18", self.holidays) + self.assertIn("2011-12-27", self.holidays) + self.assertIn("2014-05-07", self.holidays) + self.assertIn("2016-08-03", self.holidays) + self.assertIn("2019-05-08", self.holidays) + self.assertIn("2021-11-01", self.holidays) def test_presidential(self): self.assertIn("2008-05-02", self.holidays) From b584d645a051c9acf3ee8e66079ae256733c85c4 Mon Sep 17 00:00:00 2001 From: Arkadii Yakovets Date: Tue, 15 Nov 2022 09:34:28 -0800 Subject: [PATCH 003/138] Rename Korea to South Korea. Update tests and documentation. --- README.rst | 6 +++--- holidays/countries/__init__.py | 2 +- holidays/countries/{korea.py => south_korea.py} | 14 +++++++++++++- .../{test_korea.py => test_south_korea.py} | 12 +++++++++++- 4 files changed, 28 insertions(+), 6 deletions(-) rename holidays/countries/{korea.py => south_korea.py} (96%) rename test/countries/{test_korea.py => test_south_korea.py} (97%) diff --git a/README.rst b/README.rst index 3a26d244d..462601d9a 100644 --- a/README.rst +++ b/README.rst @@ -262,9 +262,6 @@ following countries and their subdivisions are available: * - Kenya - KE - None - * - Korea - - KR - - None * - Latvia - LV - None @@ -361,6 +358,9 @@ following countries and their subdivisions are available: * - South Africa - ZA - None + * - South Korea + - KR + - None * - Spain - ES - Autonomous communities: AN (Andalucía), AR (Aragón), AS (Asturias), CB (Cantabria), CE (Ceuta), CL (Castilla y León), CM (Castilla La Mancha), CN (Canarias), CT (Cataluña), EX (Extremadura), GA (Galicia), IB (Islas Baleares), MC (Murcia), MD (Madrid), NC (Navarra), PV (País Vasco), RI (La Rioja), VC (Comunidad Valenciana) diff --git a/holidays/countries/__init__.py b/holidays/countries/__init__.py index 9e6a43c72..e8b62bbb8 100644 --- a/holidays/countries/__init__.py +++ b/holidays/countries/__init__.py @@ -58,7 +58,6 @@ from .japan import JP, JPN, Japan from .kazakhstan import KAZ, KZ, Kazakhstan from .kenya import KE, KEN, Kenya -from .korea import KOR, KR, Korea from .latvia import LV, LVA, Latvia from .lesotho import LS, LSO, Lesotho from .liechtenstein import LI, LIE, Liechtenstein @@ -91,6 +90,7 @@ from .slovakia import SK, SVK, Slovakia from .slovenia import SI, SVN, Slovenia from .south_africa import ZA, ZAF, SouthAfrica +from .south_korea import KOR, KR, Korea, SouthKorea from .spain import ES, ESP, Spain from .sweden import SE, SWE, Sweden from .switzerland import CH, CHE, Switzerland diff --git a/holidays/countries/korea.py b/holidays/countries/south_korea.py similarity index 96% rename from holidays/countries/korea.py rename to holidays/countries/south_korea.py index 47577e30c..ee9fdbea7 100644 --- a/holidays/countries/korea.py +++ b/holidays/countries/south_korea.py @@ -9,6 +9,8 @@ # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) + +import warnings from datetime import date from typing import Tuple @@ -34,7 +36,7 @@ from holidays.holiday_base import HolidayBase -class Korea(HolidayBase): +class SouthKorea(HolidayBase): """ 1. https://publicholidays.co.kr/ko/2020-dates/ 2. https://en.wikipedia.org/wiki/Public_holidays_in_South_Korea @@ -287,6 +289,16 @@ def get_next_first_non_holiday( return start_value != cur, cur +class Korea(SouthKorea): + def __init__(self, *args, **kwargs) -> None: + warnings.warn( + "Korea is deprecated, use SouthKorea instead.", + DeprecationWarning, + ) + + super().__init__(*args, **kwargs) + + class KR(Korea): pass diff --git a/test/countries/test_korea.py b/test/countries/test_south_korea.py similarity index 97% rename from test/countries/test_korea.py rename to test/countries/test_south_korea.py index f77d3d0a6..3f2d2aa79 100644 --- a/test/countries/test_korea.py +++ b/test/countries/test_south_korea.py @@ -10,12 +10,13 @@ # License: MIT (see LICENSE file) import unittest +import warnings from datetime import date import holidays -class TestKorea(unittest.TestCase): +class TestSouthKorea(unittest.TestCase): def setUp(self): self.holidays = holidays.KR() @@ -404,3 +405,12 @@ def test_years_range(self): self.holidays = holidays.KR(years=range(2006, 2021)) for year in range(2006, 2021): self.assertIn(self.holidays[date(year, 1, 1)], "New Year's Day") + + def test_korea_deprecation_warning(self): + warnings.simplefilter("default") + with self.assertWarns(Warning): + holidays.Korea() + + warnings.simplefilter("error") + with self.assertRaises(Warning): + holidays.Korea() From a7d3e7b5d9bf54d98817e6a46965aaea2048cfdc Mon Sep 17 00:00:00 2001 From: Arkadii Yakovets Date: Tue, 15 Nov 2022 17:39:56 -0800 Subject: [PATCH 004/138] Fix pre-commit. --- .pre-commit-config.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b22a46271..039ac6eca 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -17,8 +17,8 @@ repos: - id: black language_version: python3 - - repo: https://gitlab.com/pycqa/flake8 - rev: 3.9.2 + - repo: https://github.com/pycqa/flake8 + rev: 5.0.4 hooks: - id: flake8 args: [--max-line-length=79] @@ -30,7 +30,7 @@ repos: exclude: ^docs/ - repo: https://github.com/pre-commit/mirrors-mypy - rev: 'v0.990' + rev: 'v0.991' hooks: - id: mypy additional_dependencies: [types-all] From 592653c5f1e5c84cf48f2196e1f638dfa1cd68ab Mon Sep 17 00:00:00 2001 From: Arkadii Yakovets Date: Tue, 15 Nov 2022 18:09:09 -0800 Subject: [PATCH 005/138] Fix pre-comit and sphinx. --- .pre-commit-config.yaml | 6 +++--- README.rst | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b22a46271..039ac6eca 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -17,8 +17,8 @@ repos: - id: black language_version: python3 - - repo: https://gitlab.com/pycqa/flake8 - rev: 3.9.2 + - repo: https://github.com/pycqa/flake8 + rev: 5.0.4 hooks: - id: flake8 args: [--max-line-length=79] @@ -30,7 +30,7 @@ repos: exclude: ^docs/ - repo: https://github.com/pre-commit/mirrors-mypy - rev: 'v0.990' + rev: 'v0.991' hooks: - id: mypy additional_dependencies: [types-all] diff --git a/README.rst b/README.rst index 462601d9a..648f1f41e 100644 --- a/README.rst +++ b/README.rst @@ -358,7 +358,7 @@ following countries and their subdivisions are available: * - South Africa - ZA - None - * - South Korea + * - South Korea - KR - None * - Spain From 720f1efa37faf03b75863bba03e0ff4b5dbb79df Mon Sep 17 00:00:00 2001 From: Arkadii Yakovets Date: Wed, 16 Nov 2022 09:35:16 -0800 Subject: [PATCH 006/138] Address review comments. --- holidays/countries/japan.py | 28 +++++++++------------------- holidays/countries/malaysia.py | 18 +++++------------- 2 files changed, 14 insertions(+), 32 deletions(-) diff --git a/holidays/countries/japan.py b/holidays/countries/japan.py index f4924f77d..232e42fdd 100644 --- a/holidays/countries/japan.py +++ b/holidays/countries/japan.py @@ -38,15 +38,22 @@ class Japan(HolidayBase): country = "JP" special_holidays = { + 1959: ((APR, 10, "結婚の儀"),), # The Crown Prince marriage ceremony. 1989: ((FEB, 24, "大喪の礼"),), # State Funeral of Emperor Shōwa. + 1990: ((NOV, 12, "即位礼正殿の儀"),), # Enthronement ceremony. + 1993: ((JUN, 9, "結婚の儀"),), # The Crown Prince marriage ceremony. + 2019: ( + (MAY, 1, "天皇の即位の日"), # Enthronement day. + (OCT, 22, "即位礼正殿の儀が行われる日"), # Enthronement ceremony. + ), } def _populate(self, year): - super()._populate(year) - if year < 1949 or year > 2099: raise NotImplementedError + super()._populate(year) + # New Year's Day self[date(year, JAN, 1)] = "元日" @@ -131,27 +138,10 @@ def _populate(self, year): self[date(year, NOV, 23)] = "勤労感謝の日" # Regarding the Emperor of Heisei - if year == 1959: - # Marriage ceremony - self[date(year, APR, 10)] = "結婚の儀" if 1989 <= year <= 2018: # Heisei Emperor's Birthday self[date(year, DEC, 23)] = "天皇誕生日" - if year == 1990: - # Enthronement ceremony - self[date(year, NOV, 12)] = "即位礼正殿の儀" - - # Regarding the Emperor of Reiwa - if year == 1993: - # Marriage ceremony - self[date(year, JUN, 9)] = "結婚の儀" - elif year == 2019: - # Enthronement Day - self[date(year, MAY, 1)] = "天皇の即位の日" - # Enthronement ceremony - self[date(year, OCT, 22)] = "即位礼正殿の儀が行われる日" - # A weekday between national holidays becomes a holiday too (国民の休日) self._add_national_holidays(year) diff --git a/holidays/countries/malaysia.py b/holidays/countries/malaysia.py index e379a6c7c..0dcc5dee0 100644 --- a/holidays/countries/malaysia.py +++ b/holidays/countries/malaysia.py @@ -38,6 +38,11 @@ class Malaysia(HolidayBase): country = "MY" + special_holidays = { + 1999: ((NOV, 29, "Malaysia General Election Holiday"),), + 2018: ((MAY, 9, "Malaysia General Election Holiday"),), + } + subdivisions = [ "JHR", "KDH", @@ -369,19 +374,6 @@ def _populate(self, year): # Other holidays (decrees etc.) # # ------------------------------# - # Malaysia General Election Holiday. - dates_obs = { - # The years 1955 1959 1995 seems to have the elections - # one weekday but I am not sure if they were marked as - # holidays. - 1999: (NOV, 29), - 2018: (MAY, 9), - } - if year in dates_obs: - self[ - date(year, *dates_obs[year]) - ] = "Malaysia General Election Holiday" - # Awal Muharram. for hol_date in self.my_islamic_to_gre(year, 1, 1): self[hol_date] = "Awal Muharram (Hijri New Year)" From 01ec7524be585a0dfbe3b30590647d0764b2cc3d Mon Sep 17 00:00:00 2001 From: ~Jhellico Date: Mon, 7 Nov 2022 16:36:08 +0200 Subject: [PATCH 007/138] Hong Kong: - holidays establishing years specified - historical holidays added - Lunar New Year and Christmas calculation fix - Ching Ming Festival and Easter Monday overlapping fix - optimizations - tests added --- .pre-commit-config.yaml | 4 +- holidays/countries/hongkong.py | 219 ++++++++++++++------------------ test/countries/test_hongkong.py | 212 +++++++++++++++++++++++-------- 3 files changed, 253 insertions(+), 182 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b22a46271..f48dd37b4 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -17,8 +17,8 @@ repos: - id: black language_version: python3 - - repo: https://gitlab.com/pycqa/flake8 - rev: 3.9.2 + - repo: https://github.com/pycqa/flake8 + rev: 5.0.4 hooks: - id: flake8 args: [--max-line-length=79] diff --git a/holidays/countries/hongkong.py b/holidays/countries/hongkong.py index 15dd9c976..36f042b89 100644 --- a/holidays/countries/hongkong.py +++ b/holidays/countries/hongkong.py @@ -9,24 +9,22 @@ # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) -from datetime import date, datetime, timedelta +from datetime import date from dateutil.easter import easter from dateutil.relativedelta import relativedelta as rd -from dateutil.relativedelta import MO, FR, SA +from dateutil.relativedelta import MO from holidays.constants import ( - MON, - TUE, - WED, - THU, FRI, SAT, SUN, JAN, APR, MAY, + JUN, JUL, + AUG, SEP, OCT, DEC, @@ -37,34 +35,43 @@ class HongKong(HolidayBase): """ - https://www.gov.hk/en/about/abouthk/holiday/2020.htm https://en.wikipedia.org/wiki/Public_holidays_in_Hong_Kong + Holidays for 2007–2023 (government source): + https://www.gov.hk/en/about/abouthk/holiday/index.htm """ country = "HK" + special_holidays = { + 2015: ( + ( + SEP, + 3, + "The 70th anniversary day of the victory of the Chinese " + "people's war of resistance against Japanese aggression", + ), + ), + } def __init__(self, **kwargs): self.cnls = _ChineseLuniSolar() HolidayBase.__init__(self, **kwargs) def _populate(self, year): + # Current set of holidays actually valid since 1946 + if year <= 1945: + return super()._populate(year) day_following = "The day following " # The first day of January - name = "The first day of January" first_date = date(year, JAN, 1) - if self.observed: - if first_date.weekday() == SUN: - self[ - first_date + rd(days=+1) - ] = day_following + self.first_lower(name) - first_date = first_date + rd(days=+1) - else: - self[first_date] = name + if self.observed and first_date.weekday() == SUN: + self[first_date + rd(days=+1)] = ( + day_following + "the first day of January" + ) else: - self[first_date] = name + self[first_date] = "The first day of January" # Lunar New Year name = "Lunar New Year's Day" @@ -72,133 +79,96 @@ def _populate(self, year): second_day_lunar = "The second day of Lunar New Year" third_day_lunar = "The third day of Lunar New Year" fourth_day_lunar = "The fourth day of Lunar New Year" - dt = self.cnls.lunar_n_y_date(year) - new_year_date = date(dt.year, dt.month, dt.day) + new_year_date = self.cnls.lunar_n_y_date(year) if self.observed: - self[new_year_date] = name - if new_year_date.weekday() in [MON, TUE, WED, THU]: + if new_year_date.weekday() == SUN: + if year in {2006, 2007, 2010}: + self[new_year_date + rd(days=-1)] = preceding_day_lunar + else: + self[new_year_date + rd(days=+3)] = fourth_day_lunar + else: self[new_year_date] = name + if new_year_date.weekday() == SAT: + self[new_year_date + rd(days=+3)] = fourth_day_lunar + else: self[new_year_date + rd(days=+1)] = second_day_lunar - self[new_year_date + rd(days=+2)] = third_day_lunar if new_year_date.weekday() == FRI: - self[new_year_date] = name - self[new_year_date + rd(days=+1)] = second_day_lunar self[new_year_date + rd(days=+3)] = fourth_day_lunar - if new_year_date.weekday() == SAT: - self[new_year_date] = name + else: self[new_year_date + rd(days=+2)] = third_day_lunar - self[new_year_date + rd(days=+3)] = fourth_day_lunar - if new_year_date.weekday() == SUN: - if year in [2006, 2007, 2010]: - self[new_year_date + rd(days=-1)] = preceding_day_lunar - self[new_year_date + rd(days=+1)] = second_day_lunar - self[new_year_date + rd(days=+2)] = third_day_lunar - else: - self[new_year_date + rd(days=+1)] = second_day_lunar - self[new_year_date + rd(days=+2)] = third_day_lunar - self[new_year_date + rd(days=+3)] = fourth_day_lunar else: self[new_year_date] = name self[new_year_date + rd(days=+1)] = second_day_lunar self[new_year_date + rd(days=+2)] = third_day_lunar + easter_date = easter(year) + easter_monday_date = easter_date + rd(days=+1) # Ching Ming Festival name = "Ching Ming Festival" if self.is_leap_year(year) or ( - self.is_leap_year(year - 1) and year > 2008 + year > 2008 and self.is_leap_year(year - 1) ): ching_ming_date = date(year, APR, 4) else: ching_ming_date = date(year, APR, 5) - if self.observed: - if ching_ming_date.weekday() == SUN: - self[ching_ming_date + rd(days=+1)] = day_following + name - ching_ming_date = ching_ming_date + rd(days=+1) - else: - self[ching_ming_date] = name + if self.observed and ( + ching_ming_date.weekday() == SUN + or ching_ming_date == easter_monday_date + ): + self[ching_ming_date + rd(days=+1)] = day_following + name else: self[ching_ming_date] = name # Easter Holiday good_friday = "Good Friday" easter_monday = "Easter Monday" - if self.observed: - self[easter(year) + rd(weekday=FR(-1))] = good_friday - self[easter(year) + rd(weekday=SA(-1))] = ( - day_following + good_friday + self[easter_date + rd(days=-2)] = good_friday + self[easter_date + rd(days=-1)] = day_following + good_friday + if self.observed and self.get(easter_monday_date): + self[easter_monday_date + rd(days=+1)] = ( + day_following + easter_monday ) - if ching_ming_date == easter(year) + rd(weekday=MO): - self[easter(year) + rd(weekday=MO) + rd(days=+1)] = ( - day_following + easter_monday - ) - else: - self[easter(year) + rd(weekday=MO)] = easter_monday else: - self[easter(year) + rd(weekday=FR(-1))] = good_friday - self[easter(year) + rd(weekday=SA(-1))] = ( - day_following + good_friday - ) - self[easter(year) + rd(weekday=MO)] = easter_monday + self[easter_monday_date] = easter_monday - # Birthday of the Buddha - name = "Birthday of the Buddha" - dt = self.cnls.lunar_to_gre(year, 4, 8) - buddha_date = date(dt.year, dt.month, dt.day) - if self.observed: - if buddha_date.weekday() == SUN: + # The Birthday of the Buddha + if year >= 1998: + name = "The Birthday of the Buddha" + buddha_date = self.cnls.lunar_to_gre(year, 4, 8) + if self.observed and buddha_date.weekday() == SUN: self[buddha_date + rd(days=+1)] = day_following + name else: self[buddha_date] = name - else: - self[buddha_date] = name # Labour Day - name = "Labour Day" - labour_date = date(year, MAY, 1) - if self.observed: - if labour_date.weekday() == SUN: + if year >= 1998: + name = "Labour Day" + labour_date = date(year, MAY, 1) + if self.observed and labour_date.weekday() == SUN: self[labour_date + rd(days=+1)] = day_following + name else: self[labour_date] = name - else: - self[labour_date] = name # Tuen Ng Festival name = "Tuen Ng Festival" - dt = self.cnls.lunar_to_gre(year, 5, 5) - tuen_ng_date = date(dt.year, dt.month, dt.day) - if self.observed: - if tuen_ng_date.weekday() == SUN: - self[tuen_ng_date + rd(days=+1)] = day_following + name - else: - self[tuen_ng_date] = name + tuen_ng_date = self.cnls.lunar_to_gre(year, 5, 5) + if self.observed and tuen_ng_date.weekday() == SUN: + self[tuen_ng_date + rd(days=+1)] = day_following + name else: self[tuen_ng_date] = name # Hong Kong Special Administrative Region Establishment Day - name = "Hong Kong Special Administrative Region Establishment Day" - hksar_date = date(year, JUL, 1) - if self.observed: - if hksar_date.weekday() == SUN: + if year >= 1997: + name = "Hong Kong Special Administrative Region Establishment Day" + hksar_date = date(year, JUL, 1) + if self.observed and hksar_date.weekday() == SUN: self[hksar_date + rd(days=+1)] = day_following + name else: self[hksar_date] = name - else: - self[hksar_date] = name - - # Special holiday on 2015 - The 70th anniversary day of the victory - # of the Chinese people's war of resistance against Japanese aggression - name = ( - "The 70th anniversary day of the victory of the Chinese " - + "people's war of resistance against Japanese aggression" - ) - if year == 2015: - self[date(year, SEP, 3)] = name # Chinese Mid-Autumn Festival name = "Chinese Mid-Autumn Festival" - dt = self.cnls.lunar_to_gre(year, 8, 15) - mid_autumn_date = date(dt.year, dt.month, dt.day) + mid_autumn_date = self.cnls.lunar_to_gre(year, 8, 15) if self.observed: # if Chinese Mid-Autumn Festival lies on Saturday # before 1983 public holiday lies on Monday @@ -211,38 +181,29 @@ def _populate(self, year): self[mid_autumn_date + rd(days=+2)] = ( "The second day of the " + name + " (Monday)" ) - mid_autumn_date = mid_autumn_date + rd(days=+2) else: self[mid_autumn_date + rd(days=+1)] = ( day_following + "the " + name ) - mid_autumn_date = mid_autumn_date + rd(days=+1) else: self[mid_autumn_date] = name # National Day - name = "National Day" - national_date = date(year, OCT, 1) - if self.observed: - if ( - national_date.weekday() == SUN - or national_date == mid_autumn_date + if year >= 1997: + name = "National Day" + national_date = date(year, OCT, 1) + if self.observed and ( + national_date.weekday() == SUN or self.get(national_date) ): self[national_date + rd(days=+1)] = day_following + name else: self[national_date] = name - else: - self[national_date] = name # Chung Yeung Festival name = "Chung Yeung Festival" - dt = self.cnls.lunar_to_gre(year, 9, 9) - chung_yeung_date = date(dt.year, dt.month, dt.day) - if self.observed: - if chung_yeung_date.weekday() == SUN: - self[chung_yeung_date + rd(days=+1)] = day_following + name - else: - self[chung_yeung_date] = name + chung_yeung_date = self.cnls.lunar_to_gre(year, 9, 9) + if self.observed and chung_yeung_date.weekday() == SUN: + self[chung_yeung_date + rd(days=+1)] = day_following + name else: self[chung_yeung_date] = name @@ -253,7 +214,6 @@ def _populate(self, year): christmas_date = date(year, DEC, 25) if self.observed: if christmas_date.weekday() == SUN: - self[christmas_date] = name self[christmas_date + rd(days=+1)] = first_after_christmas self[christmas_date + rd(days=+2)] = second_after_christmas elif christmas_date.weekday() == SAT: @@ -266,18 +226,25 @@ def _populate(self, year): self[christmas_date] = name self[christmas_date + rd(days=+1)] = day_following + name - def is_leap_year(self, year): - if year % 4 != 0: - return False - elif year % 100 != 0: - return True - elif year % 400 != 0: - return False - else: - return True - - def first_lower(self, s): - return s[0].lower() + s[1:] + # Previous holidays + if 1952 <= year <= 1997: + # Queen's Birthday (June 2nd Monday) + dt = date(year, JUN, 1) + rd(weekday=MO(+2)) + self[dt] = "Queen's Birthday" + + if year <= 1996: + # Anniversary of the liberation of Hong Kong (August last Monday) + dt = date(year, AUG, 31) + rd(weekday=MO(-1)) + self[dt] = "Anniversary of the liberation of Hong Kong" + + # Anniversary of the victory in the Second Sino-Japanese War + self[ + dt + rd(days=-1) + ] = "Anniversary of the victory in the Second Sino-Japanese War" + + @staticmethod + def is_leap_year(year): + return year % 4 == 0 and (year % 100 != 0 or year % 400 == 0) class HK(HongKong): diff --git a/test/countries/test_hongkong.py b/test/countries/test_hongkong.py index f604c57e4..f4ac459af 100644 --- a/test/countries/test_hongkong.py +++ b/test/countries/test_hongkong.py @@ -22,9 +22,9 @@ def setUp(self): def test_common(self): self.assertTrue(self.holidays.is_leap_year(2000)) self.assertFalse(self.holidays.is_leap_year(2100)) - holidaysNoObserved = holidays.HK(observed=False) + holidays_no_observed = holidays.HK(observed=False) self.assertEqual( - holidaysNoObserved[date(2019, 1, 1)], "The first day of January" + holidays_no_observed[date(2019, 1, 1)], "The first day of January" ) self.assertEqual( self.holidays[date(2015, 9, 3)], @@ -33,10 +33,11 @@ def test_common(self): + "people's war of resistance against Japanese " + "aggression", ) + self.assertEqual(len(holidays.HK(years=1945)), 0) def test_first_day_of_january(self): - exception_years = [2006, 2012, 2017] - for year in range(2006, 2021): + exception_years = (2006, 2012, 2017, 2023) + for year in range(2006, 2024): if year in exception_years: self.assertEqual( self.holidays[date(year, 1, 2)], @@ -66,6 +67,8 @@ def test_lunar_new_year(self): (2018, 2, 16), (2019, 2, 5), (2020, 1, 25), + (2021, 2, 12), + (2022, 2, 1), ]: self.assertEqual( self.holidays[date(year, month, day)], "Lunar New Year's Day" @@ -85,6 +88,9 @@ def test_lunar_new_year(self): (2016, 2, 9), (2018, 2, 17), (2019, 2, 6), + (2021, 2, 13), + (2022, 2, 2), + (2023, 1, 23), ]: self.assertEqual( self.holidays[date(year, month, day)], @@ -105,6 +111,8 @@ def test_lunar_new_year(self): (2017, 1, 30), (2019, 2, 7), (2020, 1, 27), + (2022, 2, 3), + (2023, 1, 24), ]: self.assertEqual( self.holidays[date(year, month, day)], @@ -115,8 +123,10 @@ def test_lunar_new_year(self): (2013, 2, 13), (2014, 2, 3), (2017, 1, 31), - (2020, 1, 28), (2018, 2, 19), + (2020, 1, 28), + (2021, 2, 15), + (2023, 1, 25), ]: self.assertEqual( self.holidays[date(year, month, day)], @@ -129,7 +139,6 @@ def test_ching_ming_festival(self): (2007, 4, 5), (2008, 4, 4), (2009, 4, 4), - (2010, 4, 5), (2011, 4, 5), (2012, 4, 4), (2013, 4, 4), @@ -139,15 +148,18 @@ def test_ching_ming_festival(self): (2018, 4, 5), (2019, 4, 5), (2020, 4, 4), + (2022, 4, 5), + (2023, 4, 5), ]: self.assertEqual( self.holidays[date(year, month, day)], "Ching Ming Festival" ) - self.assertEqual( - self.holidays[date(2015, 4, 6)], - "The day " + "following Ching Ming Festival", - ) + for year, month, day in [(2010, 4, 6), (2015, 4, 6), (2021, 4, 5)]: + self.assertEqual( + self.holidays[date(year, month, day)], + "The day following Ching Ming Festival", + ) def test_easter(self): for year, month, day in [ @@ -166,27 +178,33 @@ def test_easter(self): (2018, 3, 30), (2019, 4, 19), (2020, 4, 10), + (2021, 4, 2), + (2022, 4, 15), + (2023, 4, 7), ]: self.assertEqual( self.holidays[date(year, month, day)], "Good Friday" ) for year, month, day in [ - (2019, 4, 20), - (2013, 3, 30), - (2020, 4, 11), - (2009, 4, 11), - (2018, 3, 31), + (2006, 4, 15), + (2007, 4, 7), (2008, 3, 22), - (2011, 4, 23), + (2009, 4, 11), (2010, 4, 3), - (2015, 4, 4), - (2006, 4, 15), - (2017, 4, 15), - (2016, 3, 26), + (2011, 4, 23), (2012, 4, 7), - (2007, 4, 7), + (2013, 3, 30), (2014, 4, 19), + (2015, 4, 4), + (2016, 3, 26), + (2017, 4, 15), + (2018, 3, 31), + (2019, 4, 20), + (2020, 4, 11), + (2021, 4, 3), + (2022, 4, 16), + (2023, 4, 8), ]: self.assertEqual( self.holidays[date(year, month, day)], @@ -196,8 +214,9 @@ def test_easter(self): for year, month, day in [ (2006, 4, 17), (2007, 4, 9), - (2009, 4, 13), (2008, 3, 24), + (2009, 4, 13), + (2010, 4, 5), (2011, 4, 25), (2012, 4, 9), (2013, 4, 1), @@ -212,12 +231,48 @@ def test_easter(self): self.holidays[date(year, month, day)], "Easter Monday" ) - name = "The day following Easter Monday" - self.assertEqual(self.holidays[date(2010, 4, 6)], name) - self.assertEqual(self.holidays[date(2015, 4, 7)], name) + for year, month, day in [(2015, 4, 7), (2021, 4, 6)]: + self.assertEqual( + self.holidays[date(year, month, day)], + "The day following Easter Monday", + ) + + def test_birthday_of_buddha(self): + for year, month, day in [ + (2006, 5, 5), + (2007, 5, 24), + (2008, 5, 12), + (2009, 5, 2), + (2010, 5, 21), + (2011, 5, 10), + (2012, 4, 28), + (2013, 5, 17), + (2014, 5, 6), + (2015, 5, 25), + (2016, 5, 14), + (2017, 5, 3), + (2018, 5, 22), + (2020, 4, 30), + (2021, 5, 19), + (2023, 5, 26), + ]: + self.assertEqual( + self.holidays[date(year, month, day)], + "The Birthday of the Buddha", + ) + + for year, month, day in [ + (2019, 5, 13), + (2022, 5, 9), + ]: + self.assertEqual( + self.holidays[date(year, month, day)], + "The day following The Birthday of the Buddha", + ) def test_labour_day(self): for year in [ + 1998, 2006, 2007, 2008, @@ -231,12 +286,18 @@ def test_labour_day(self): 2018, 2019, 2020, + 2021, + 2023, ]: self.assertEqual(self.holidays[date(year, 5, 1)], "Labour Day") - name = "The day following Labour Day" - self.assertEqual(self.holidays[date(2011, 5, 2)], name) - self.assertEqual(self.holidays[date(2016, 5, 2)], name) + for year in (2011, 2016, 2022): + self.assertEqual( + self.holidays[date(year, 5, 2)], "The day following Labour Day" + ) + + self.assertNotIn(date(1997, 5, 1), self.holidays) + self.assertNotIn(date(1997, 5, 2), self.holidays) def test_tuen_ng_festival(self): for year, month, day in [ @@ -254,18 +315,22 @@ def test_tuen_ng_festival(self): (2018, 6, 18), (2019, 6, 7), (2020, 6, 25), + (2021, 6, 14), + (2022, 6, 3), + (2023, 6, 22), ]: self.assertEqual( - self.holidays[date(year, month, day)], "Tuen " + "Ng Festival" + self.holidays[date(year, month, day)], "Tuen Ng Festival" ) self.assertEqual( self.holidays[date(2008, 6, 9)], - "The day " + "following Tuen Ng Festival", + "The day following Tuen Ng Festival", ) def test_hksar_day(self): for year in [ + 1997, 2006, 2008, 2009, @@ -281,18 +346,20 @@ def test_hksar_day(self): ]: self.assertEqual( self.holidays[date(year, 7, 1)], - "Hong Kong " - + "Special Administrative Region Establishment " - + "Day", + "Hong Kong Special Administrative Region Establishment Day", ) - name = ( - "The day following Hong Kong Special Administrative Region " - + "Establishment Day" - ) - self.assertEqual(self.holidays[date(2007, 7, 2)], name) - self.assertEqual(self.holidays[date(2012, 7, 2)], name) - self.assertEqual(self.holidays[date(2018, 7, 2)], name) + for year in (2007, 2012, 2018): + self.assertEqual( + self.holidays[date(year, 7, 2)], + ( + "The day following Hong Kong Special Administrative " + "Region Establishment Day" + ), + ) + + self.assertNotIn(date(1996, 7, 1), self.holidays) + self.assertNotIn(date(1996, 7, 2), self.holidays) def test_mid_autumn_festival(self): for year, month, day in [ @@ -321,20 +388,19 @@ def test_mid_autumn_festival(self): ]: self.assertEqual( self.holidays[date(year, month, day)], - "The " + "day following the Chinese Mid-Autumn Festival", + "The day following the Chinese Mid-Autumn Festival", ) for year, month, day in [(2002, 9, 21), (2009, 10, 3)]: self.assertEqual( self.holidays[date(year, month, day)], - "Chinese " + "Mid-Autumn Festival", + "Chinese Mid-Autumn Festival", ) for year, month, day in [(2022, 9, 12)]: self.assertEqual( self.holidays[date(year, month, day)], - "The second day of the " - + "Chinese Mid-Autumn Festival (Monday)", + "The second day of the Chinese Mid-Autumn Festival (Monday)", ) def test_national_day(self): @@ -351,13 +417,16 @@ def test_national_day(self): 2018, 2019, 2020, + 2021, + 2022, ]: self.assertEqual(self.holidays[date(year, 10, 1)], "National Day") - name = "The day following National Day" - self.assertEqual(self.holidays[date(2006, 10, 2)], name) - self.assertEqual(self.holidays[date(2012, 10, 2)], name) - self.assertEqual(self.holidays[date(2017, 10, 2)], name) + for year in (2006, 2012, 2017, 2023): + self.assertEqual( + self.holidays[date(year, 10, 2)], + "The day following National Day", + ) def test_chung_yeung_festival(self): for year, month, day in [ @@ -373,16 +442,24 @@ def test_chung_yeung_festival(self): (2017, 10, 28), (2018, 10, 17), (2019, 10, 7), + (2021, 10, 14), + (2022, 10, 4), + (2023, 10, 23), ]: self.assertEqual( self.holidays[date(year, month, day)], - "Chung " + "Yeung Festival", + "Chung Yeung Festival", ) - name = "The day following Chung Yeung Festival" - self.assertEqual(self.holidays[date(2013, 10, 14)], name) - self.assertEqual(self.holidays[date(2016, 10, 10)], name) - self.assertEqual(self.holidays[date(2020, 10, 26)], name) + for year, month, day in [ + (2013, 10, 14), + (2016, 10, 10), + (2020, 10, 26), + ]: + self.assertEqual( + self.holidays[date(year, month, day)], + "The day following Chung Yeung Festival", + ) def test_christmas_day(self): for year in [ @@ -399,18 +476,45 @@ def test_christmas_day(self): 2018, 2019, 2020, + 2021, + 2023, ]: self.assertEqual( - self.holidays[date(year, 12, 25)], "Christmas " + "Day" + self.holidays[date(year, 12, 25)], "Christmas Day" ) + for year in (2005, 2011, 2016, 2022): + self.assertNotIn(date(year, 12, 25), self.holidays) + name = "The first weekday after Christmas Day" for year in range(2006, 2010): self.assertEqual(self.holidays[date(year, 12, 26)], name) self.assertEqual(self.holidays[date(2010, 12, 27)], name) for year in range(2011, 2021): self.assertEqual(self.holidays[date(year, 12, 26)], name) + self.assertEqual(self.holidays[date(2021, 12, 27)], name) + for year in range(2022, 2024): + self.assertEqual(self.holidays[date(year, 12, 26)], name) name = "The second weekday after Christmas Day" self.assertEqual(self.holidays[date(2011, 12, 27)], name) self.assertEqual(self.holidays[date(2016, 12, 27)], name) + self.assertEqual(self.holidays[date(2022, 12, 27)], name) + + def test_old_holidays(self): + for year, month, day in [ + # Queen's Birthday + (1952, 6, 9), + (1987, 6, 8), + (1990, 6, 11), + (1997, 6, 9), + # Anniversary of the liberation of Hong Kong + # and Anniversary of the victory in the Second Sino-Japanese War + (1980, 8, 24), + (1980, 8, 25), + (1990, 8, 26), + (1990, 8, 27), + (1996, 8, 25), + (1996, 8, 26), + ]: + self.assertIn(date(year, month, day), self.holidays) From bb73c99577aa91a5419c372c082fb4695259ab47 Mon Sep 17 00:00:00 2001 From: Arkadii Yakovets Date: Fri, 18 Nov 2022 11:32:58 -0800 Subject: [PATCH 008/138] Optimize `if var in iterable:` statements. Replace a tuple/list with a set in order to achieve O(n) -> ~O(1) complexity improvement. --- .pre-commit-config.yaml | 6 +- holidays/countries/australia.py | 16 ++-- holidays/countries/azerbaijan.py | 2 +- holidays/countries/botswana.py | 2 +- holidays/countries/canada.py | 30 +++--- holidays/countries/dominican_republic.py | 4 +- holidays/countries/france.py | 8 +- holidays/countries/germany.py | 12 +-- holidays/countries/hongkong.py | 4 +- holidays/countries/hungary.py | 2 +- holidays/countries/india.py | 4 +- holidays/countries/israel.py | 3 +- holidays/countries/italy.py | 14 +-- holidays/countries/japan.py | 56 +++++------ holidays/countries/malaysia.py | 34 +++---- holidays/countries/new_zealand.py | 40 ++++---- holidays/countries/nigeria.py | 2 +- holidays/countries/portugal.py | 4 +- holidays/countries/spain.py | 44 ++++----- holidays/countries/switzerland.py | 34 +++---- holidays/countries/united_kingdom.py | 10 +- holidays/countries/united_states.py | 42 ++++----- holidays/countries/uruguay.py | 4 +- holidays/financial/ny_stock_exchange.py | 12 +-- test/countries/test_canada.py | 10 +- test/countries/test_colombia.py | 48 +++++----- test/countries/test_cuba.py | 72 +++++++------- test/countries/test_honduras.py | 20 ++-- test/countries/test_hongkong.py | 3 +- test/countries/test_korea.py | 4 +- test/countries/test_spain.py | 114 +++++++++++------------ test/countries/test_venezuela.py | 32 +++---- test/financial/test_ny_stock_exchange.py | 4 +- 33 files changed, 354 insertions(+), 342 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b22a46271..039ac6eca 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -17,8 +17,8 @@ repos: - id: black language_version: python3 - - repo: https://gitlab.com/pycqa/flake8 - rev: 3.9.2 + - repo: https://github.com/pycqa/flake8 + rev: 5.0.4 hooks: - id: flake8 args: [--max-line-length=79] @@ -30,7 +30,7 @@ repos: exclude: ^docs/ - repo: https://github.com/pre-commit/mirrors-mypy - rev: 'v0.990' + rev: 'v0.991' hooks: - id: mypy additional_dependencies: [types-all] diff --git a/holidays/countries/australia.py b/holidays/countries/australia.py index 7570d997b..762ff4ee3 100644 --- a/holidays/countries/australia.py +++ b/holidays/countries/australia.py @@ -107,9 +107,9 @@ def _populate(self, year): # Easter self[easter(year) + rd(weekday=FR(-1))] = "Good Friday" - if self.subdiv in ("ACT", "NSW", "NT", "QLD", "SA", "VIC"): + if self.subdiv in {"ACT", "NSW", "NT", "QLD", "SA", "VIC"}: self[easter(year) + rd(weekday=SA(-1))] = "Easter Saturday" - if self.subdiv in ("ACT", "NSW", "QLD", "VIC"): + if self.subdiv in {"ACT", "NSW", "QLD", "VIC"}: self[easter(year)] = "Easter Sunday" self[easter(year) + rd(weekday=MO)] = "Easter Monday" @@ -119,15 +119,15 @@ def _populate(self, year): apr25 = date(year, APR, 25) self[apr25] = name if self.observed: - if apr25.weekday() == SAT and self.subdiv in ("WA", "NT"): + if apr25.weekday() == SAT and self.subdiv in {"WA", "NT"}: self[apr25 + rd(weekday=MO)] = name + " (Observed)" - elif apr25.weekday() == SUN and self.subdiv in ( + elif apr25.weekday() == SUN and self.subdiv in { "ACT", + "NT", "QLD", "SA", "WA", - "NT", - ): + }: self[apr25 + rd(weekday=MO)] = name + " (Observed)" # Western Australia Day @@ -156,7 +156,7 @@ def _populate(self, year): elif self.subdiv == "WA": # by proclamation ?!?! self[date(year, OCT, 1) + rd(weekday=MO(-1))] = name - elif self.subdiv in ("NSW", "VIC", "ACT", "SA", "NT", "TAS"): + elif self.subdiv in {"ACT", "NSW", "NT", "SA", "TAS", "VIC"}: dt = date(year, JUN, 1) + rd(weekday=MO(+2)) self[dt] = name elif year > 1911: @@ -177,7 +177,7 @@ def _populate(self, year): # Labour Day name = "Labour Day" - if self.subdiv in ("NSW", "ACT", "SA"): + if self.subdiv in {"ACT", "NSW", "SA"}: self[date(year, OCT, 1) + rd(weekday=MO)] = name elif self.subdiv == "WA": self[date(year, MAR, 1) + rd(weekday=MO)] = name diff --git a/holidays/countries/azerbaijan.py b/holidays/countries/azerbaijan.py index 94102930f..6a062eca9 100644 --- a/holidays/countries/azerbaijan.py +++ b/holidays/countries/azerbaijan.py @@ -28,7 +28,7 @@ class Azerbaijan(HolidayBase): country = "AZ" def _add_observed(self, holiday: date) -> None: - if self.observed and holiday.weekday() in (SAT, SUN): + if self.observed and holiday.weekday() in {SAT, SUN}: next_monday = holiday + rd(days=7 - holiday.weekday()) if next_monday.year == holiday.year and not self.get( next_monday, None diff --git a/holidays/countries/botswana.py b/holidays/countries/botswana.py index 910181698..237849894 100644 --- a/holidays/countries/botswana.py +++ b/holidays/countries/botswana.py @@ -71,7 +71,7 @@ def _populate(self, year: int): and year > 2015 and k.weekday() == SAT and k.year == year - and v.upper() in ("BOXING DAY", "LABOUR DAY") + and v.upper() in {"BOXING DAY", "LABOUR DAY"} ): # Add the (Observed) holiday self[k + rd(days=2)] = v + " Holiday" diff --git a/holidays/countries/canada.py b/holidays/countries/canada.py index 11461aab4..04d601591 100644 --- a/holidays/countries/canada.py +++ b/holidays/countries/canada.py @@ -147,7 +147,7 @@ def _populate(self, year): # Victoria Day / National Patriots' Day (QC) if year >= 1953: dt = date(year, MAY, 24) + rd(weekday=MO(-1)) - if self.subdiv not in ("NB", "NS", "PE", "NL", "QC"): + if self.subdiv not in {"NB", "NS", "PE", "NL", "QC"}: self[dt] = "Victoria Day" elif self.subdiv == "QC": self[dt] = "National Patriots' Day" @@ -194,18 +194,18 @@ def _populate(self, year): self[date(2000, APR, 1)] = name # Civic Holiday - if self.subdiv in ("ON", "MB", "NT") and year >= 1900: + if year >= 1900 and self.subdiv in {"MB", "NT", "ON"}: self[date(year, AUG, 1) + rd(weekday=MO)] = "Civic Holiday" - elif self.subdiv == "AB" and year >= 1974: + elif year >= 1974 and self.subdiv == "AB": # https://en.wikipedia.org/wiki/Civic_Holiday#Alberta self[date(year, AUG, 1) + rd(weekday=MO)] = "Heritage Day" - elif self.subdiv == "BC" and year >= 1974: + elif year >= 1974 and self.subdiv == "BC": # https://en.wikipedia.org/wiki/Civic_Holiday self[date(year, AUG, 1) + rd(weekday=MO)] = "British Columbia Day" - elif self.subdiv == "NB" and year >= 1900: + elif year >= 1900 and self.subdiv == "NB": # https://en.wikipedia.org/wiki/Civic_Holiday self[date(year, AUG, 1) + rd(weekday=MO)] = "New Brunswick Day" - elif self.subdiv == "SK" and year >= 1900: + elif year >= 1900 and self.subdiv == "SK": # https://en.wikipedia.org/wiki/Civic_Holiday self[date(year, AUG, 1) + rd(weekday=MO)] = "Saskatchewan Day" @@ -216,20 +216,26 @@ def _populate(self, year): # Funeral of Queen Elizabeth II # https://www.narcity.com/provinces-territories-will-have-a-day-off-monday-mourn-queen # TODO: the territories holiday status (NT, NU, YT) is still tentative - queen_funeral_observers = ("BC", "NB", "NL", "NS", "PE", "YT") - if self.subdiv in queen_funeral_observers and year == 2022: + if year == 2022 and self.subdiv in { + "BC", + "NB", + "NL", + "NS", + "PE", + "YT", + }: self[ date(2022, SEP, 19) ] = "Funeral of Her Majesty the Queen Elizabeth II" # National Day for Truth and Reconciliation - if self.subdiv in ("MB", "NS") and year >= 2021: + if year >= 2021 and self.subdiv in {"MB", "NS"}: self[ date(year, SEP, 30) ] = "National Day for Truth and Reconciliation" # Thanksgiving - if self.subdiv not in ("NB", "NS", "PE", "NL") and year >= 1931: + if year >= 1931 and self.subdiv not in {"NB", "NL", "NS", "PE"}: if year == 1935: # in 1935, Canadian Thanksgiving was moved due to the General # Election falling on the second Monday of October @@ -239,14 +245,14 @@ def _populate(self, year): self[date(year, OCT, 1) + rd(weekday=MO(+2))] = "Thanksgiving" # Remembrance Day - if self.subdiv not in ("ON", "QC") and year >= 1931: + if year >= 1931 and self.subdiv not in {"ON", "QC"}: name = "Remembrance Day" dt = date(year, NOV, 11) self[dt] = name if ( self.observed - and self.subdiv in ("NS", "NL", "NT", "PE", "SK") and dt.weekday() == SUN + and self.subdiv in {"NS", "NL", "NT", "PE", "SK"} ): self[dt + rd(weekday=MO)] = name + " (Observed)" diff --git a/holidays/countries/dominican_republic.py b/holidays/countries/dominican_republic.py index addd0b293..e592a1042 100644 --- a/holidays/countries/dominican_republic.py +++ b/holidays/countries/dominican_republic.py @@ -15,7 +15,7 @@ from dateutil.relativedelta import relativedelta as rd from dateutil.relativedelta import MO, FR -from holidays.constants import JAN, FEB, MAY, JUN, AUG, SEP, NOV, DEC +from holidays.constants import TUE, WED, JAN, FEB, MAY, JUN, AUG, SEP, NOV, DEC from holidays.holiday_base import HolidayBase @@ -31,7 +31,7 @@ class DominicanRepublic(HolidayBase): def __change_day_by_law(holiday, latest_days=(3, 4)): # Law No. 139-97 - Holidays Dominican Republic - Jun 27, 1997 if holiday >= date(1997, 6, 27): - if holiday.weekday() in [1, 2]: + if holiday.weekday() in {TUE, WED}: holiday -= rd(weekday=MO(-1)) elif holiday.weekday() in latest_days: holiday += rd(weekday=MO(1)) diff --git a/holidays/countries/france.py b/holidays/countries/france.py index dfb5a0c3f..199a0a575 100644 --- a/holidays/countries/france.py +++ b/holidays/countries/france.py @@ -78,13 +78,13 @@ def _populate(self, year): self[date(year, NOV, 11)] = "Armistice 1918" # Religious holidays - if self.subdiv in [ + if self.subdiv in { "Alsace-Moselle", "Guadeloupe", "Guyane", "Martinique", "Polynésie Française", - ]: + }: self[easter(year) - rd(days=2)] = "Vendredi saint" if self.subdiv == "Alsace-Moselle": @@ -114,7 +114,7 @@ def _populate(self, year): if self.subdiv == "Martinique": self[date(year, MAY, 22)] = "Abolition de l'esclavage" - if self.subdiv in ["Guadeloupe", "Saint-Martin"]: + if self.subdiv in {"Guadeloupe", "Saint-Martin"}: self[date(year, MAY, 27)] = "Abolition de l'esclavage" if self.subdiv == "Guyane": @@ -123,7 +123,7 @@ def _populate(self, year): if self.subdiv == "Polynésie Française": self[date(year, JUN, 29)] = "Fête de l'autonomie" - if self.subdiv in ["Guadeloupe", "Martinique"]: + if self.subdiv in {"Guadeloupe", "Martinique"}: self[date(year, JUL, 21)] = "Fête Victor Schoelcher" if self.subdiv == "Wallis-et-Futuna": diff --git a/holidays/countries/germany.py b/holidays/countries/germany.py index 803b8d13e..0617be453 100644 --- a/holidays/countries/germany.py +++ b/holidays/countries/germany.py @@ -85,7 +85,7 @@ def _populate(self, year): self[date(year, JAN, 1)] = "Neujahr" - if self.subdiv in ("BW", "BY", "BYP", "ST"): + if self.subdiv in {"BW", "BY", "BYP", "ST"}: self[date(year, JAN, 6)] = "Heilige Drei Könige" self[easter(year) - rd(days=2)] = "Karfreitag" @@ -116,22 +116,22 @@ def _populate(self, year): self[easter(year) + rd(days=50)] = "Pfingstmontag" - if self.subdiv in ("BW", "BY", "BYP", "HE", "NW", "RP", "SL"): + if self.subdiv in {"BW", "BY", "BYP", "HE", "NW", "RP", "SL"}: self[easter(year) + rd(days=60)] = "Fronleichnam" - if self.subdiv in ("BY", "SL"): + if self.subdiv in {"BY", "SL"}: self[date(year, AUG, 15)] = "Mariä Himmelfahrt" self[date(year, OCT, 3)] = "Tag der Deutschen Einheit" if ( - self.subdiv in ("BB", "MV", "SN", "ST", "TH") - or (self.subdiv in ("HB", "SH", "NI", "HH") and year >= 2018) + self.subdiv in {"BB", "MV", "SN", "ST", "TH"} + or (self.subdiv in {"HB", "HH", "NI", "SH"} and year >= 2018) or year == 2017 ): self[date(year, OCT, 31)] = "Reformationstag" - if self.subdiv in ("BW", "BY", "BYP", "NW", "RP", "SL"): + if self.subdiv in {"BW", "BY", "BYP", "NW", "RP", "SL"}: self[date(year, NOV, 1)] = "Allerheiligen" if year <= 1994 or self.subdiv == "SN": diff --git a/holidays/countries/hongkong.py b/holidays/countries/hongkong.py index 15dd9c976..9d4baef43 100644 --- a/holidays/countries/hongkong.py +++ b/holidays/countries/hongkong.py @@ -76,7 +76,7 @@ def _populate(self, year): new_year_date = date(dt.year, dt.month, dt.day) if self.observed: self[new_year_date] = name - if new_year_date.weekday() in [MON, TUE, WED, THU]: + if new_year_date.weekday() in {MON, TUE, WED, THU}: self[new_year_date] = name self[new_year_date + rd(days=+1)] = second_day_lunar self[new_year_date + rd(days=+2)] = third_day_lunar @@ -89,7 +89,7 @@ def _populate(self, year): self[new_year_date + rd(days=+2)] = third_day_lunar self[new_year_date + rd(days=+3)] = fourth_day_lunar if new_year_date.weekday() == SUN: - if year in [2006, 2007, 2010]: + if year in {2006, 2007, 2010}: self[new_year_date + rd(days=-1)] = preceding_day_lunar self[new_year_date + rd(days=+1)] = second_day_lunar self[new_year_date + rd(days=+2)] = third_day_lunar diff --git a/holidays/countries/hungary.py b/holidays/countries/hungary.py index f75f61d66..1b045dc74 100644 --- a/holidays/countries/hungary.py +++ b/holidays/countries/hungary.py @@ -68,7 +68,7 @@ def _populate(self, year: int) -> None: # Liberation Day self[date(year, APR, 4)] = "A felszabadulás ünnepe" # Memorial day of The Great October Soviet Socialist Revolution - if year not in (1956, 1989): + if year not in {1956, 1989}: self[ date(year, NOV, 7) ] = "A nagy októberi szocialista forradalom ünnepe" diff --git a/holidays/countries/india.py b/holidays/countries/india.py index 3cda293cc..cf21400cc 100644 --- a/holidays/countries/india.py +++ b/holidays/countries/india.py @@ -110,7 +110,7 @@ def _populate(self, year): "Maha Vishuva Sankranti / Pana" " Sankranti" ) - if self.subdiv in ( + if self.subdiv in { "OR", "AP", "BR", @@ -121,7 +121,7 @@ def _populate(self, year): "UP", "UK", "TN", - ): + }: self[date(year, APR, 14)] = "Dr. B. R. Ambedkar's Jayanti" if self.subdiv == "TN": diff --git a/holidays/countries/israel.py b/holidays/countries/israel.py index b757f0c8a..3c70441fc 100644 --- a/holidays/countries/israel.py +++ b/holidays/countries/israel.py @@ -24,6 +24,7 @@ yom_kippur, ) from dateutil.relativedelta import relativedelta as rd +from dateutil.relativedelta import TU, WE from holidays.holiday_base import HolidayBase @@ -61,7 +62,7 @@ def _populate(self, year): observed_delta = 0 if self.observed: day_in_week = memorial_day_dt.weekday() - if day_in_week in (2, 3): + if day_in_week in {TU.weekday, WE.weekday}: observed_delta = -(day_in_week - 1) elif 2004 <= year and day_in_week == 5: observed_delta = 1 diff --git a/holidays/countries/italy.py b/holidays/countries/italy.py index f6cb2a0af..d5d287873 100644 --- a/holidays/countries/italy.py +++ b/holidays/countries/italy.py @@ -223,13 +223,13 @@ def _populate(self, year): ] = "San Teodoro d'Amasea e San Lorenzo da Brindisi" elif self.subdiv == "BS": self[date(year, FEB, 15)] = "Santi Faustino e Giovita" - elif self.subdiv in ("BT", "Barletta"): + elif self.subdiv in {"BT", "Barletta"}: self[date(year, DEC, 30)] = "San Ruggero" - if self.subdiv in ("BT", "Andria"): + if self.subdiv in {"BT", "Andria"}: self[ date(year, SEP, 1) + rd(weekday=SU(+3)) ] = "San Riccardo di Andria" # <--- Third sunday in September - if self.subdiv in ("BT", "Trani"): + if self.subdiv in {"BT", "Trani"}: self[date(year, MAY, 3)] = "San Nicola Pellegrino" elif self.subdiv == "BZ": self[easter(year) + rd(days=50)] = "Lunedì di Pentecoste" @@ -258,9 +258,9 @@ def _populate(self, year): self[date(year, JUL, 16)] = "San Vitaliano" elif self.subdiv == "EN": self[date(year, JUL, 2)] = "Madonna della Visitazione" - elif self.subdiv in ("FC", "Cesena"): + elif self.subdiv in {"FC", "Cesena"}: self[date(year, JUN, 24)] = "San Giovanni Battista" - if self.subdiv in ("FC", "Forlì"): + if self.subdiv in {"FC", "Forlì"}: self[date(year, FEB, 4)] = "Madonna del Fuoco" elif self.subdiv == "FE": self[date(year, APR, 23)] = "San Giorgio" @@ -342,9 +342,9 @@ def _populate(self, year): self[date(year, JAN, 13)] = "Sant'Ilario di Poitiers" elif self.subdiv == "PT": self[date(year, JUL, 25)] = "San Jacopo" - elif self.subdiv in ("PU", "Pesaro"): + elif self.subdiv in {"PU", "Pesaro"}: self[date(year, SEP, 24)] = "San Terenzio di Pesaro" - if self.subdiv in ("PU", "Urbino"): + if self.subdiv in {"PU", "Urbino"}: self[date(year, JUN, 1)] = "San Crescentino" elif self.subdiv == "PV": self[date(year, DEC, 9)] = "San Siro" diff --git a/holidays/countries/japan.py b/holidays/countries/japan.py index 0ba439907..a8083fdf4 100644 --- a/holidays/countries/japan.py +++ b/holidays/countries/japan.py @@ -191,7 +191,7 @@ def _autumnal_equinox_day(self, year): return date(year, SEP, day) def _add_national_holidays(self, year): - if year in ( + if year in { 1988, 1989, 1990, @@ -207,13 +207,13 @@ def _add_national_holidays(self, year): 2004, 2005, 2006, - ): + }: self[date(year, MAY, 4)] = "国民の休日" - if year in (2032, 2049, 2060, 2077, 2088, 2094): + if year in {2032, 2049, 2060, 2077, 2088, 2094}: self[date(year, SEP, 21)] = "国民の休日" - if year in (2009, 2015, 2026, 2037, 2043, 2054, 2065, 2071, 2099): + if year in {2009, 2015, 2026, 2037, 2043, 2054, 2065, 2071, 2099}: self[date(year, SEP, 22)] = "国民の休日" if year == 2019: @@ -225,7 +225,7 @@ def _add_substitute_holidays(self, year): ( 1, 2, - ( + { 1978, 1984, 1989, @@ -237,21 +237,21 @@ def _add_substitute_holidays(self, year): 2034, 2040, 2045, - ), + }, ), - (1, 16, (1978, 1984, 1989, 1995)), + (1, 16, {1978, 1984, 1989, 1995}), ( 2, 12, - (1979, 1990, 1996, 2001, 2007, 2018, 2024, 2029, 2035, 2046), + {1979, 1990, 1996, 2001, 2007, 2018, 2024, 2029, 2035, 2046}, ), - (2, 24, (2020, 2025, 2031, 2042, 2048)), - (3, 21, (1988, 2005, 2016, 2033, 2044, 2050)), - (3, 22, (1982, 1999, 2010, 2027)), + (2, 24, {2020, 2025, 2031, 2042, 2048}), + (3, 21, {1988, 2005, 2016, 2033, 2044, 2050}), + (3, 22, {1982, 1999, 2010, 2027}), ( 4, 30, - ( + { 1973, 1979, 1984, @@ -264,13 +264,13 @@ def _add_substitute_holidays(self, year): 2035, 2040, 2046, - ), + }, ), - (5, 4, (1981, 1987, 1992, 1998)), + (5, 4, {1981, 1987, 1992, 1998}), ( 5, 6, - ( + { 1974, 1985, 1991, @@ -295,19 +295,19 @@ def _add_substitute_holidays(self, year): 2037, 2043, 2048, - ), + }, ), - (7, 21, (1997,)), - (8, 9, (2021,)), - (8, 12, (2019, 2024, 2030, 2041, 2047)), - (9, 16, (1974, 1985, 1991, 1996, 2002)), - (9, 23, (2024,)), - (9, 24, (1973, 1984, 1990, 2001, 2007, 2018, 2029, 2035, 2046)), - (10, 11, (1976, 1982, 1993, 1999)), + (7, 21, {1997}), + (8, 9, {2021}), + (8, 12, {2019, 2024, 2030, 2041, 2047}), + (9, 16, {1974, 1985, 1991, 1996, 2002}), + (9, 23, {2024}), + (9, 24, {1973, 1984, 1990, 2001, 2007, 2018, 2029, 2035, 2046}), + (10, 11, {1976, 1982, 1993, 1999}), ( 11, 4, - ( + { 1974, 1985, 1991, @@ -319,12 +319,12 @@ def _add_substitute_holidays(self, year): 2030, 2041, 2047, - ), + }, ), ( 11, 24, - ( + { 1975, 1980, 1986, @@ -336,9 +336,9 @@ def _add_substitute_holidays(self, year): 2031, 2036, 2042, - ), + }, ), - (12, 24, (1990, 2001, 2007, 2012, 2018)), + (12, 24, {1990, 2001, 2007, 2012, 2018}), ) for holiday in table: month = holiday[0] diff --git a/holidays/countries/malaysia.py b/holidays/countries/malaysia.py index e379a6c7c..6477172c0 100644 --- a/holidays/countries/malaysia.py +++ b/holidays/countries/malaysia.py @@ -112,7 +112,7 @@ def _populate(self, year): super()._populate(year) # New Year's Day - if self.subdiv not in ("JHR", "KDH", "KTN", "PLS", "TRG"): + if self.subdiv not in {"JHR", "KDH", "KTN", "PLS", "TRG"}: self[date(year, JAN, 1)] = "New Year's Day" # Birthday of the Prophet Muhammad (s.a.w.). @@ -262,7 +262,7 @@ def _populate(self, year): if self.subdiv == "TRG": # Arafat Day is one day before Eid al-Adha self[hol_date - rd(days=1)] = "Arafat Day" - if self.subdiv in ("KDH", "KTN", "PLS", "TRG"): + if self.subdiv in {"KDH", "KTN", "PLS", "TRG"}: # Second day self[hol_date + rd(days=1)] = "Hari Raya Haji Holiday" else: @@ -272,7 +272,7 @@ def _populate(self, year): if self.subdiv == "TRG": # Arafat Day is one day before Eid al-Adha self[hol_date - rd(days=1)] = "Arafat Day* (*estimated)" - if self.subdiv in ("KDH", "KTN", "PLS", "TRG"): + if self.subdiv in {"KDH", "KTN", "PLS", "TRG"}: # Second day self[ hol_date + rd(days=1) @@ -361,7 +361,7 @@ def _populate(self, year): # The last two days in May (Pesta Kaamatan). # (Sarawak Act) # Day following a Sunday is not a holiday - if self.subdiv in ("LBN", "SBH"): + if self.subdiv in {"LBN", "SBH"}: self[date(year, MAY, 30)] = "Pesta Kaamatan" self[date(year, MAY, 31)] = "Pesta Kaamatan (Second day)" @@ -395,19 +395,19 @@ def _populate(self, year): # 1 January (or the following day if the 1 January should fall on a # weekly holiday in any State or in the Federal Territory). - if self.subdiv in ( + if self.subdiv in { "KUL", "LBN", "MLK", "NSN", "PHG", + "PJY", "PNG", "PRK", - "PJY", "SBH", - "SWK", "SGR", - ): + "SWK", + }: hol_date = date(year, JAN, 1) self[hol_date] = "New Year's Day" if hol_date.weekday() == SUN: @@ -415,24 +415,24 @@ def _populate(self, year): self[date(year, JAN, 2)] = "New Year's Day [In lieu]" # Isra and Mi'raj. - if self.subdiv in ("KDH", "NSN", "PLS", "TRG"): + if self.subdiv in {"KDH", "NSN", "PLS", "TRG"}: for hol_date in _islamic_to_gre(year, 7, 27): self[hol_date] = "Isra and Mi'raj" # Beginning of Ramadan. - if self.subdiv in ("JHR", "KDH", "MLK"): + if self.subdiv in {"JHR", "KDH", "MLK"}: for hol_date in _islamic_to_gre(year, 9, 1): self[hol_date] = "Begining of Ramadan" # Nuzul Al-Quran Day. - if self.subdiv not in ( + if self.subdiv not in { "JHR", "KDH", "MLK", "NSN", "SBH", "SWK", - ): + }: for hol_date in _islamic_to_gre(year, 9, 17): self[hol_date] = "Nuzul Al-Quran Day" @@ -477,13 +477,13 @@ def _populate(self, year): self[hol_date] = "Hari Raya Aidilfitri Holiday* (*estimated)" # Good Friday. - if self.subdiv in ("SBH", "SWK"): + if self.subdiv in {"SBH", "SWK"}: self[easter(year) + rd(weekday=FR(-1))] = "Good Friday" # Thaipusam. # An annual Hindu festival observed on the day of the first full moon # during the Tamil month of Thai - if self.subdiv in ("JHR", "KUL", "NSN", "PJY", "PNG", "PRK", "SGR"): + if self.subdiv in {"JHR", "KUL", "NSN", "PJY", "PNG", "PRK", "SGR"}: dates_obs = { 2018: [(JAN, 31)], 2019: [(JAN, 21)], @@ -505,7 +505,7 @@ def _populate(self, year): self[hol_date] = "Thaipusam* (*estimated)" # Federal Territory Day. - if self.subdiv in ("KUL", "LBN", "PJY"): + if self.subdiv in {"KUL", "LBN", "PJY"}: if year > 1973: self[date(year, FEB, 1)] = "Federal Territory Day" @@ -615,7 +615,7 @@ def my_islamic_to_gre(self, year: int, month: int, day: int): month, adjusted for Malaysia. """ hol_dates = _islamic_to_gre(year, month, day) - if year in ( + if year in { 2003, 2004, 2010, @@ -627,7 +627,7 @@ def my_islamic_to_gre(self, year: int, month: int, day: int): 2024, 2025, 2027, - ): + }: hol_dates = [ hol_date + timedelta(days=1) for hol_date in hol_dates ] diff --git a/holidays/countries/new_zealand.py b/holidays/countries/new_zealand.py index 240c37e39..37ffaed9d 100644 --- a/holidays/countries/new_zealand.py +++ b/holidays/countries/new_zealand.py @@ -235,74 +235,74 @@ def _populate(self, year): self[date(year, DEC, 28)] = name + " (Observed)" # Province Anniversary Day - if self.subdiv in ("NTL", "Northland", "AUK", "Auckland"): - if 1963 < year <= 1973 and self.subdiv in ("NTL", "Northland"): + if self.subdiv in {"Auckland", "AUK", "Northland", "NTL"}: + if 1963 < year <= 1973 and self.subdiv in {"Northland", "NTL"}: name = "Waitangi Day" dt = date(year, FEB, 6) else: name = "Auckland Anniversary Day" dt = date(year, JAN, 29) - if dt.weekday() in (TUE, WED, THU): + if dt.weekday() in {TUE, WED, THU}: self[dt + rd(weekday=MO(-1))] = name else: self[dt + rd(weekday=MO)] = name - elif self.subdiv in ("TKI", "Taranaki", "New Plymouth"): + elif self.subdiv in {"New Plymouth", "Taranaki", "TKI"}: name = "Taranaki Anniversary Day" self[date(year, MAR, 1) + rd(weekday=MO(+2))] = name - elif self.subdiv in ("HKB", "Hawke's Bay"): + elif self.subdiv in {"Hawke's Bay", "HKB"}: name = "Hawke's Bay Anniversary Day" labour_day = date(year, OCT, 1) + rd(weekday=MO(+4)) self[labour_day + rd(weekday=FR(-1))] = name - elif self.subdiv in ("WGN", "Wellington"): + elif self.subdiv in {"WGN", "Wellington"}: name = "Wellington Anniversary Day" jan22 = date(year, JAN, 22) - if jan22.weekday() in (TUE, WED, THU): + if jan22.weekday() in {TUE, WED, THU}: self[jan22 + rd(weekday=MO(-1))] = name else: self[jan22 + rd(weekday=MO)] = name - elif self.subdiv in ("MBH", "Marlborough"): + elif self.subdiv in {"Marlborough", "MBH"}: name = "Marlborough Anniversary Day" labour_day = date(year, OCT, 1) + rd(weekday=MO(+4)) self[labour_day + rd(weeks=1)] = name - elif self.subdiv in ("NSN", "Nelson"): + elif self.subdiv in {"Nelson", "NSN"}: name = "Nelson Anniversary Day" feb1 = date(year, FEB, 1) - if feb1.weekday() in (TUE, WED, THU): + if feb1.weekday() in {TUE, WED, THU}: self[feb1 + rd(weekday=MO(-1))] = name else: self[feb1 + rd(weekday=MO)] = name - elif self.subdiv in ("CAN", "Canterbury"): + elif self.subdiv in {"CAN", "Canterbury"}: name = "Canterbury Anniversary Day" showday = date(year, NOV, 1) + rd(weekday=TU) + rd(weekday=FR(+2)) self[showday] = name - elif self.subdiv in ("STC", "South Canterbury"): + elif self.subdiv in {"South Canterbury", "STC"}: name = "South Canterbury Anniversary Day" dominion_day = date(year, SEP, 1) + rd(weekday=MO(4)) self[dominion_day] = name - elif self.subdiv in ("WTC", "West Coast", "WTL", "Westland"): + elif self.subdiv in {"WTC", "West Coast", "WTL", "Westland"}: name = "West Coast Anniversary Day" dec1 = date(year, DEC, 1) # Observance varies?!?! if year == 2005: # special case?!?! self[date(year, DEC, 5)] = name - elif dec1.weekday() in (TUE, WED, THU): + elif dec1.weekday() in {TUE, WED, THU}: self[dec1 + rd(weekday=MO(-1))] = name else: self[dec1 + rd(weekday=MO)] = name - elif self.subdiv in ("OTA", "Otago"): + elif self.subdiv in {"OTA", "Otago"}: name = "Otago Anniversary Day" mar23 = date(year, MAR, 23) # there is no easily determined single day of local observance?!?! - if mar23.weekday() in (TUE, WED, THU): + if mar23.weekday() in {TUE, WED, THU}: dt = mar23 + rd(weekday=MO(-1)) else: dt = mar23 + rd(weekday=MO) @@ -310,21 +310,21 @@ def _populate(self, year): dt += rd(days=1) self[dt] = name - elif self.subdiv in ("STL", "Southland"): + elif self.subdiv in {"STL", "Southland"}: name = "Southland Anniversary Day" jan17 = date(year, JAN, 17) if year > 2011: self[easter(year) + rd(weekday=TU)] = name else: - if jan17.weekday() in (TUE, WED, THU): + if jan17.weekday() in {TUE, WED, THU}: self[jan17 + rd(weekday=MO(-1))] = name else: self[jan17 + rd(weekday=MO)] = name - elif self.subdiv in ("CIT", "Chatham Islands"): + elif self.subdiv in {"CIT", "Chatham Islands"}: name = "Chatham Islands Anniversary Day" nov30 = date(year, NOV, 30) - if nov30.weekday() in (TUE, WED, THU): + if nov30.weekday() in {TUE, WED, THU}: self[nov30 + rd(weekday=MO(-1))] = name else: self[nov30 + rd(weekday=MO)] = name diff --git a/holidays/countries/nigeria.py b/holidays/countries/nigeria.py index 62045152e..17827453e 100644 --- a/holidays/countries/nigeria.py +++ b/holidays/countries/nigeria.py @@ -100,7 +100,7 @@ def _add_holiday(dt: date, hol: str) -> None: and year > 2015 and k.weekday() == SAT and k.year == year - and v.upper() in ("WORKER'S DAY", "DEMOCRACY DAY") + and v.upper() in {"DEMOCRACY DAY", "WORKER'S DAY"} ): # Add the (Observed) holiday self[k + rd(days=2)] = v + " (Observed)" diff --git a/holidays/countries/portugal.py b/holidays/countries/portugal.py index 87b517e1b..38a8b08df 100644 --- a/holidays/countries/portugal.py +++ b/holidays/countries/portugal.py @@ -115,7 +115,7 @@ def _populate(self, year): self[date(year, MAY, 12)] = "Dia de Santa Joana" if self.subdiv == "02": self[e + rd(days=4) + rd(weeks=5)] = "Quinta-feira da Ascensão" - if self.subdiv in ("03", "13"): + if self.subdiv in {"03", "13"}: self[date(year, JUN, 24)] = "Dia de São João" if self.subdiv == "04": self[date(year, AUG, 22)] = "Dia de Nossa Senhora das Graças" @@ -133,7 +133,7 @@ def _populate(self, year): self[date(year, NOV, 27)] = "Dia do Município da Guarda" if self.subdiv == "10": self[date(year, MAY, 22)] = "Dia do Município de Leiria" - if self.subdiv in ("11", "17"): + if self.subdiv in {"11", "17"}: self[date(year, JUN, 13)] = "Dia de Santo António" if self.subdiv == "12": self[date(year, MAY, 23)] = "Dia do Município de Portalegre" diff --git a/holidays/countries/spain.py b/holidays/countries/spain.py index ce26762cb..3a6e73442 100644 --- a/holidays/countries/spain.py +++ b/holidays/countries/spain.py @@ -74,82 +74,82 @@ def _populate(self, year): year < 2015 and self.subdiv and self.subdiv - in [ + in { "AR", "CL", "CM", "EX", "GA", + "MC", "MD", "ML", - "MC", "NC", "PV", "VC", - ] + } ): self._is_observed(date(year, MAR, 19), "San José") elif ( year == 2015 and self.subdiv - and self.subdiv in ["CM", "MD", "ML", "MC", "NC", "PV", "VC"] + and self.subdiv in {"CM", "MC", "MD", "ML", "NC", "PV", "VC"} ): self._is_observed(date(year, MAR, 19), "San José") elif ( year == 2016 and self.subdiv - and self.subdiv in ["ML", "MC", "PV", "VC"] + and self.subdiv in {"MC", "ML", "PV", "VC"} ): self._is_observed(date(year, MAR, 19), "San José") - elif year == 2017 and self.subdiv in ["PV"]: + elif year == 2017 and self.subdiv in {"PV"}: self._is_observed(date(year, MAR, 19), "San José") elif ( 2018 <= year <= 2019 and self.subdiv - and self.subdiv in ["GA", "MC", "NC", "PV", "VC"] + and self.subdiv in {"GA", "MC", "NC", "PV", "VC"} ): self._is_observed(date(year, MAR, 19), "San José") elif ( 2020 <= year <= 2021 and self.subdiv - and self.subdiv in ["CM", "GA", "MC", "NC", "PV", "VC"] + and self.subdiv in {"CM", "GA", "MC", "NC", "PV", "VC"} ): self._is_observed(date(year, MAR, 19), "San José") elif year >= 2022 and self.subdiv and self.subdiv == "VC": self._is_observed(date(year, MAR, 19), "San José") - if year != 2022 and self.subdiv not in ["CT", "VC"]: + if year != 2022 and self.subdiv not in {"CT", "VC"}: self[easter(year) + rd(weeks=-1, weekday=TH)] = "Jueves Santo" - elif year == 2022 and self.subdiv and self.subdiv not in ["CT"]: + elif year == 2022 and self.subdiv and self.subdiv not in {"CT"}: self[easter(year) + rd(weeks=-1, weekday=TH)] = "Jueves Santo" self[easter(year) + rd(weeks=-1, weekday=FR)] = "Viernes Santo" if ( 2022 == year and self.subdiv - and self.subdiv in ["CT", "IB", "PV", "NC", "RI", "VC"] + and self.subdiv in {"CT", "IB", "NC", "PV", "RI", "VC"} ): self[easter(year) + rd(weekday=MO)] = "Lunes de Pascua" - elif 2022 > year and self.subdiv in [ + elif 2022 > year and self.subdiv in { + "CM", "CT", - "PV", + "IB", "NC", + "PV", "VC", - "IB", - "CM", - ]: + }: self[easter(year) + rd(weekday=MO)] = "Lunes de Pascua" if 2022 != year: self._is_observed(date(year, MAY, 1), "Día del Trabajador") - elif 2022 == year and self.subdiv in [ + elif 2022 == year and self.subdiv in { "AN", + "AR", "AS", "CL", "EX", "MC", - "AR", - ]: + }: self._is_observed(date(year, MAY, 1), "Día del Trabajador") - if self.subdiv in ["CT", "GA", "VC"]: + if self.subdiv in {"CT", "GA", "VC"}: self._is_observed(date(year, JUN, 24), "San Juan") self._is_observed(date(year, AUG, 15), "Asunción de la Virgen") self._is_observed(date(year, OCT, 12), "Día de la Hispanidad") @@ -160,9 +160,9 @@ def _populate(self, year): self._is_observed(date(year, DEC, 8), "La Inmaculada Concepción") if year != 2022: self._is_observed(date(year, DEC, 25), "Navidad") - elif year == 2022 and self.subdiv not in ["CE", "GA", "PV", "VC"]: + elif year == 2022 and self.subdiv not in {"CE", "GA", "PV", "VC"}: self._is_observed(date(year, DEC, 26), "Navidad (Trasladado)") - if self.subdiv in ["CT", "IB"]: + if self.subdiv in {"CT", "IB"}: self._is_observed(date(year, DEC, 26), "San Esteban") # Provinces festive day diff --git a/holidays/countries/switzerland.py b/holidays/countries/switzerland.py index 2676a9900..c3ac07ec7 100644 --- a/holidays/countries/switzerland.py +++ b/holidays/countries/switzerland.py @@ -75,13 +75,13 @@ def _populate(self, year): ): self[date(year, JAN, 2)] = "Berchtoldstag" - if self.subdiv in ("SZ", "TI", "UR"): + if self.subdiv in {"SZ", "TI", "UR"}: self[date(year, JAN, 6)] = "Heilige Drei Könige" if self.subdiv == "NE": self[date(year, MAR, 1)] = "Jahrestag der Ausrufung der Republik" - if self.subdiv in ("NW", "SZ", "TI", "UR", "VS"): + if self.subdiv in {"NW", "SZ", "TI", "UR", "VS"}: self[date(year, MAR, 19)] = "Josefstag" # Näfelser Fahrt (first Thursday in April but not in Holy Week) @@ -101,7 +101,7 @@ def _populate(self, year): self[easter(year) - rd(days=2)] = "Karfreitag" self[easter(year) + rd(weekday=MO)] = "Ostermontag" - if self.subdiv in ( + if self.subdiv in { "BL", "BS", "JU", @@ -111,7 +111,7 @@ def _populate(self, year): "TG", "TI", "ZH", - ): + }: self[date(year, MAY, 1)] = "Tag der Arbeit" self[easter(year) + rd(days=39)] = "Auffahrt" @@ -121,7 +121,7 @@ def _populate(self, year): self[easter(year) + rd(days=50)] = "Pfingstmontag" - if self.subdiv in ( + if self.subdiv in { "AI", "JU", "LU", @@ -132,7 +132,7 @@ def _populate(self, year): "UR", "VS", "ZG", - ): + }: self[easter(year) + rd(days=60)] = "Fronleichnam" if self.subdiv == "JU": @@ -144,7 +144,7 @@ def _populate(self, year): if year >= 1291: self[date(year, AUG, 1)] = "Nationalfeiertag" - if self.subdiv in ( + if self.subdiv in { "AI", "JU", "LU", @@ -155,7 +155,7 @@ def _populate(self, year): "UR", "VS", "ZG", - ): + }: self[date(year, AUG, 15)] = "Mariä Himmelfahrt" if self.subdiv == "VD": @@ -171,7 +171,7 @@ def _populate(self, year): if self.subdiv == "OW": self[date(year, SEP, 25)] = "Bruder Klaus" - if self.subdiv in ( + if self.subdiv in { "AI", "GL", "JU", @@ -184,10 +184,10 @@ def _populate(self, year): "UR", "VS", "ZG", - ): + }: self[date(year, NOV, 1)] = "Allerheiligen" - if self.subdiv in ( + if self.subdiv in { "AI", "LU", "NW", @@ -197,18 +197,18 @@ def _populate(self, year): "UR", "VS", "ZG", - ): + }: self[date(year, DEC, 8)] = "Mariä Empfängnis" self[date(year, DEC, 25)] = "Weihnachten" - if self.subdiv in ( + if self.subdiv in { "AG", - "AR", "AI", + "AR", + "BE", "BL", "BS", - "BE", "FR", "GL", "GR", @@ -218,14 +218,14 @@ def _populate(self, year): "OW", "SG", "SH", - "SZ", "SO", + "SZ", "TG", "TI", "UR", "ZG", "ZH", - ): + }: self[date(year, DEC, 26)] = "Stephanstag" if self.subdiv == "GE": diff --git a/holidays/countries/united_kingdom.py b/holidays/countries/united_kingdom.py index bd9c30761..cdce57cf8 100644 --- a/holidays/countries/united_kingdom.py +++ b/holidays/countries/united_kingdom.py @@ -73,7 +73,7 @@ def _populate(self, year: int) -> None: self[dt + rd(weekday=MO)] = name + " (Observed)" # New Year Holiday - if self.subdiv in ("UK", "Scotland"): + if self.subdiv in {"Scotland", "UK"}: name = "New Year Holiday" dt = date(year, JAN, 2) if self.subdiv == "UK": @@ -85,7 +85,7 @@ def _populate(self, year: int) -> None: self[dt + rd(days=+1)] = name + " (Observed)" # St. Patrick's Day - if self.subdiv in ("UK", "Northern Ireland"): + if self.subdiv in {"Northern Ireland", "UK"}: name = "St. Patrick's Day" dt = date(year, MAR, 17) if self.subdiv == "UK": @@ -95,21 +95,21 @@ def _populate(self, year: int) -> None: self[dt + rd(weekday=MO)] = name + " (Observed)" # Battle of the Boyne - if self.subdiv in ("UK", "Northern Ireland"): + if self.subdiv in {"Northern Ireland", "UK"}: name = "Battle of the Boyne" if self.subdiv == "UK": name += " [Northern Ireland]" self[date(year, JUL, 12)] = name # Summer bank holiday (first Monday in August) - if self.subdiv in ("UK", "Scotland"): + if self.subdiv in {"Scotland", "UK"}: name = "Summer Bank Holiday" if self.subdiv == "UK": name += " [Scotland]" self[date(year, AUG, 1) + rd(weekday=MO)] = name # St. Andrew's Day - if self.subdiv in ("UK", "Scotland"): + if self.subdiv in {"Scotland", "UK"}: name = "St. Andrew's Day" if self.subdiv == "UK": name += " [Scotland]" diff --git a/holidays/countries/united_states.py b/holidays/countries/united_states.py index c39a6c30b..0d78ee73e 100644 --- a/holidays/countries/united_states.py +++ b/holidays/countries/united_states.py @@ -144,7 +144,7 @@ def _populate(self, year): self[date(year, JAN, 19)] = name # Inauguration Day - if self.subdiv in ("DC", "LA", "MD", "VA") and year >= 1789: + if self.subdiv in {"DC", "LA", "MD", "VA"} and year >= 1789: name = "Inauguration Day" if (year - 1789) % 4 == 0 and year >= 1937: self[date(year, JAN, 20)] = name @@ -167,7 +167,7 @@ def _populate(self, year): "Dr. Martin Luther King Jr. " "and Robert E. Lee's Birthdays" ) - elif self.subdiv in ("AZ", "NH"): + elif self.subdiv in {"AZ", "NH"}: name = "Dr. Martin Luther King Jr./Civil Rights Day" elif self.subdiv == "GA" and year < 2012: name = "Robert E. Lee's Birthday" @@ -178,7 +178,7 @@ def _populate(self, year): # Lincoln's Birthday name = "Lincoln's Birthday" if ( - self.subdiv in ("CT", "IL", "IA", "NJ", "NY") and year >= 1971 + self.subdiv in {"CT", "IA", "IL", "NJ", "NY"} and year >= 1971 ) or (self.subdiv == "CA" and 1971 <= year <= 2009): self[date(year, FEB, 12)] = name if self.observed and date(year, FEB, 12).weekday() == SAT: @@ -201,9 +201,9 @@ def _populate(self, year): name = "George Washington/Thomas Jefferson Birthday" elif self.subdiv == "AR": name = "George Washington's Birthday and Daisy Gatson Bates Day" - elif self.subdiv in ("PR", "VI"): + elif self.subdiv in {"PR", "VI"}: name = "Presidents' Day" - if self.subdiv not in ("DE", "FL", "GA", "NM", "PR"): + if self.subdiv not in {"DE", "FL", "GA", "NM", "PR"}: if year > 1970: self[date(year, FEB, 1) + rd(weekday=MO(+3))] = name elif year >= 1879: @@ -213,7 +213,7 @@ def _populate(self, year): self[date(year, DEC, 24)] = name else: self[date(year, DEC, 26)] = name - elif self.subdiv in ("PR", "VI"): + elif self.subdiv in {"PR", "VI"}: self[date(year, FEB, 1) + rd(weekday=MO(+3))] = name # Mardi Gras @@ -290,9 +290,9 @@ def _populate(self, year): self[date(year, APR, 17)] = name + " (Observed)" # Patriots' Day - if self.subdiv in ("ME", "MA") and year >= 1969: + if self.subdiv in {"MA", "ME"} and year >= 1969: self[date(year, APR, 1) + rd(weekday=MO(+3))] = "Patriots' Day" - elif self.subdiv in ("ME", "MA") and year >= 1894: + elif self.subdiv in {"MA", "ME"} and year >= 1894: self[date(year, APR, 19)] = "Patriots' Day" # Holy Thursday @@ -300,20 +300,20 @@ def _populate(self, year): self[easter(year) + rd(weekday=TH(-1))] = "Holy Thursday" # Good Friday - if self.subdiv in ( + if self.subdiv in { "CT", "DE", "GU", "IN", "KY", "LA", - "NJ", "NC", + "NJ", "PR", "TN", "TX", "VI", - ): + }: self[easter(year) + rd(weekday=FR(-1))] = "Good Friday" # Easter Monday @@ -322,7 +322,7 @@ def _populate(self, year): # Confederate Memorial Day name = "Confederate Memorial Day" - if self.subdiv in ("AL", "GA", "MS", "SC") and year >= 1866: + if self.subdiv in {"AL", "GA", "MS", "SC"} and year >= 1866: if self.subdiv == "GA" and year >= 2016: name = "State Holiday" if self.subdiv == "GA" and year == 2020: @@ -458,7 +458,7 @@ def _populate(self, year): self[date(year, SEP, 1) + rd(weekday=MO)] = "Labor Day" # Columbus Day - if self.subdiv not in ("AK", "AR", "DE", "FL", "HI", "NV"): + if self.subdiv not in {"AK", "AR", "DE", "FL", "HI", "NV"}: if self.subdiv == "SD": name = "Native American Day" elif self.subdiv == "VI": @@ -497,10 +497,10 @@ def _populate(self, year): # Election Day if ( self.subdiv - in ("DE", "HI", "IL", "IN", "LA", "MT", "NH", "NJ", "NY", "WV") + in {"DE", "HI", "IL", "IN", "LA", "MT", "NH", "NJ", "NY", "WV"} and year >= 2008 and year % 2 == 0 - ) or (self.subdiv in ("IN", "NY") and year >= 2015): + ) or (self.subdiv in {"IN", "NY"} and year >= 2015): dt = date(year, NOV, 1) + rd(weekday=MO) self[dt + rd(days=+1)] = "Election Day" @@ -540,16 +540,16 @@ def _populate(self, year): # New Mexico Presidents' Day if ( ( - self.subdiv in ("CA", "DE", "FL", "NH", "NC", "OK", "TX", "WV") + self.subdiv in {"CA", "DE", "FL", "NC", "NH", "OK", "TX", "WV"} and year >= 1975 ) or (self.subdiv == "IN" and year >= 2010) or (self.subdiv == "MD" and year >= 2008) - or self.subdiv in ("NM", "NV", "PA") + or self.subdiv in {"NM", "NV", "PA"} ): - if self.subdiv in ("CA", "DE", "NH", "NC", "OK", "PA", "WV"): + if self.subdiv in {"CA", "DE", "NC", "NH", "OK", "PA", "WV"}: name = "Day After Thanksgiving" - if self.subdiv in ("FL", "TX"): + if self.subdiv in {"FL", "TX"}: name = "Friday After Thanksgiving" if self.subdiv == "IN": name = "Lincoln's Birthday" @@ -577,7 +577,7 @@ def _populate(self, year): # Christmas Eve if ( self.subdiv == "AS" - or (self.subdiv in ("KS", "MI", "NC") and year >= 2013) + or (self.subdiv in {"KS", "MI", "NC"} and year >= 2013) or (self.subdiv == "TX" and year >= 1981) or (self.subdiv == "WI" and year >= 2012) ): @@ -617,7 +617,7 @@ def _populate(self, year): self[date(year, DEC, 26)] = "Christmas Second Day" # New Year's Eve - if (self.subdiv in ("KY", "MI") and year >= 2013) or ( + if (self.subdiv in {"KY", "MI"} and year >= 2013) or ( self.subdiv == "WI" and year >= 2012 ): name = "New Year's Eve" diff --git a/holidays/countries/uruguay.py b/holidays/countries/uruguay.py index cc9904bc9..940fdc3da 100644 --- a/holidays/countries/uruguay.py +++ b/holidays/countries/uruguay.py @@ -101,9 +101,9 @@ def _populate(self, year): ) for dt, name in holiday_pairs: - if dt.weekday() in (TU.weekday, WE.weekday): + if dt.weekday() in {TU.weekday, WE.weekday}: self[dt + rd(weekday=MO(-1))] = name - elif dt.weekday() in (TH.weekday, FR.weekday): + elif dt.weekday() in {TH.weekday, FR.weekday}: self[dt + rd(weekday=MO(+1))] = name else: self[dt] = name diff --git a/holidays/financial/ny_stock_exchange.py b/holidays/financial/ny_stock_exchange.py index d872f5a2c..1158bce0a 100644 --- a/holidays/financial/ny_stock_exchange.py +++ b/holidays/financial/ny_stock_exchange.py @@ -12,7 +12,7 @@ from datetime import date, timedelta from dateutil.easter import easter -from dateutil.relativedelta import FR, MO, TH, TU +from dateutil.relativedelta import MO, TU, TH, FR, SA, SU from dateutil.relativedelta import relativedelta as rd from holidays.constants import ( @@ -99,7 +99,7 @@ def _populate(self, year): # GOOD FRIDAY - closed every year except 1898, 1906, and 1907 e = easter(year) - if year not in [1898, 1906, 1907]: + if year not in {1898, 1906, 1907}: self[e - rd(days=2)] = "Good Friday" # MEM DAY (May 30) - closed every year since 1873 @@ -139,11 +139,11 @@ def _populate(self, year): # closed until 1969, then closed pres years 1972-80 if year <= 1968: self[date(year, NOV, 1) + rd(weekday=TU(1))] = "Election Day" - elif year in [1972, 1976, 1980]: + elif year in {1972, 1976, 1980}: self[date(year, NOV, 1) + rd(weekday=TU(1))] = "Election Day" # VETERAN'S DAY: Nov 11 - closed 1918, 1921, 1934-1953 - if year in [1918, 1921] or (1934 <= year <= 1953): + if year in {1918, 1921} or (1934 <= year <= 1953): vetday = date(year, NOV, 11) self._set_observed_date(vetday, "Veteran's Day") @@ -193,7 +193,7 @@ def _populate(self, year): begin + timedelta(days=n) for n in range((end - begin).days + 1) ): - if d.isoweekday() in [6, 7]: + if d.weekday() in {SA.weekday, SU.weekday}: continue self[d] = "World War I" elif year == 1917: @@ -225,7 +225,7 @@ def _populate(self, year): begin + timedelta(days=n) for n in range((end - begin).days + 1) ): - if d.isoweekday() in [6, 7]: + if d.weekday() in {SA.weekday, SU.weekday}: continue self[d] = "Special Bank Holiday" elif year == 1945: diff --git a/test/countries/test_canada.py b/test/countries/test_canada.py index 49b4387f4..d70744508 100644 --- a/test/countries/test_canada.py +++ b/test/countries/test_canada.py @@ -384,11 +384,17 @@ def test_boxing_day(self): self.assertIn(date(2010, 12, 27), self.holidays) def test_queens_funeral(self): - observers = ("BC", "NB", "NL", "NS", "PE", "YT") for subdiv in holidays.CA.subdivisions: holidays_canada = holidays.CA(subdiv=subdiv) for year in range(1900, 2100): - if year == 2022 and subdiv in observers: + if year == 2022 and subdiv in { + "BC", + "NB", + "NL", + "NS", + "PE", + "YT", + }: self.assertIn(date(year, 9, 19), holidays_canada) else: self.assertNotIn(date(year, 9, 19), holidays_canada) diff --git a/test/countries/test_colombia.py b/test/countries/test_colombia.py index 5e72ce80b..b16c98daf 100644 --- a/test/countries/test_colombia.py +++ b/test/countries/test_colombia.py @@ -35,7 +35,7 @@ def _check_all_dates(self, year, expected_holidays): def test_2016(self): # https://www.officeholidays.com/countries/colombia/2016 year = 2016 - expected_holidays = [ + expected_holidays = { date(year, JAN, 1), date(year, JAN, 11), date(year, MAR, 21), @@ -54,13 +54,13 @@ def test_2016(self): date(year, NOV, 14), date(year, DEC, 8), date(year, DEC, 25), - ] + } self._check_all_dates(year, expected_holidays) def test_2017(self): # https://www.officeholidays.com/countries/colombia/2017 year = 2017 - expected_holidays = [ + expected_holidays = { date(year, JAN, 1), date(year, JAN, 9), date(year, MAR, 20), @@ -79,13 +79,13 @@ def test_2017(self): date(year, NOV, 13), date(year, DEC, 8), date(year, DEC, 25), - ] + } self._check_all_dates(year, expected_holidays) def test_2018(self): # https://publicholidays.co/2018-dates/ year = 2018 - expected_holidays = [ + expected_holidays = { date(year, JAN, 1), date(year, JAN, 8), date(year, MAR, 19), @@ -104,13 +104,13 @@ def test_2018(self): date(year, NOV, 12), date(year, DEC, 8), date(year, DEC, 25), - ] + } self._check_all_dates(year, expected_holidays) def test_2019(self): # https://www.officeholidays.com/countries/colombia/2019 year = 2019 - expected_holidays = [ + expected_holidays = { date(year, JAN, 1), date(year, JAN, 7), date(year, MAR, 25), @@ -129,13 +129,13 @@ def test_2019(self): date(year, NOV, 11), date(year, DEC, 8), date(year, DEC, 25), - ] + } self._check_all_dates(year, expected_holidays) def test_2020(self): # https://www.officeholidays.com/countries/colombia/2020 year = 2020 - expected_holidays = [ + expected_holidays = { date(year, JAN, 1), date(year, JAN, 6), date(year, MAR, 23), @@ -154,13 +154,13 @@ def test_2020(self): date(year, NOV, 16), date(year, DEC, 8), date(year, DEC, 25), - ] + } self._check_all_dates(year, expected_holidays) def test_2021(self): # https://www.officeholidays.com/countries/colombia/2021 year = 2021 - expected_holidays = [ + expected_holidays = { date(year, JAN, 1), date(year, JAN, 11), date(year, MAR, 22), @@ -179,13 +179,13 @@ def test_2021(self): date(year, NOV, 15), date(year, DEC, 8), date(year, DEC, 25), - ] + } self._check_all_dates(year, expected_holidays) def test_2022(self): # https://www.officeholidays.com/countries/colombia/2022 year = 2022 - expected_holidays = [ + expected_holidays = { date(year, JAN, 1), date(year, JAN, 10), date(year, MAR, 21), @@ -204,13 +204,13 @@ def test_2022(self): date(year, NOV, 14), date(year, DEC, 8), date(year, DEC, 25), - ] + } self._check_all_dates(year, expected_holidays) def test_2023(self): # https://publicholidays.co/2023-dates/ year = 2023 - expected_holidays = [ + expected_holidays = { date(year, JAN, 1), date(year, JAN, 9), date(year, MAR, 20), @@ -229,12 +229,12 @@ def test_2023(self): date(year, NOV, 13), date(year, DEC, 8), date(year, DEC, 25), - ] + } self._check_all_dates(year, expected_holidays) def test_1984(self): year = 1984 - expected_holidays = [ + expected_holidays = { date(year, JAN, 1), date(year, JAN, 9), date(year, MAR, 19), @@ -253,12 +253,12 @@ def test_1984(self): date(year, NOV, 12), date(year, DEC, 8), date(year, DEC, 25), - ] + } self._check_all_dates(year, expected_holidays) def test_1983(self): year = 1983 - expected_holidays = [ + expected_holidays = { date(year, JAN, 1), date(year, JAN, 6), date(year, MAR, 19), @@ -276,12 +276,12 @@ def test_1983(self): date(year, NOV, 11), date(year, DEC, 8), date(year, DEC, 25), - ] + } self._check_all_dates(year, expected_holidays) def test_1951(self): year = 1951 - expected_holidays = [ + expected_holidays = { date(year, JAN, 1), date(year, JAN, 6), date(year, MAR, 19), @@ -299,12 +299,12 @@ def test_1951(self): date(year, NOV, 11), date(year, DEC, 8), date(year, DEC, 25), - ] + } self._check_all_dates(year, expected_holidays) def test_1950(self): year = 1950 - expected_holidays = [ + expected_holidays = { date(year, JAN, 1), date(year, MAY, 1), date(year, JUL, 20), @@ -312,5 +312,5 @@ def test_1950(self): date(year, OCT, 12), date(year, NOV, 11), date(year, DEC, 25), - ] + } self._check_all_dates(year, expected_holidays) diff --git a/test/countries/test_cuba.py b/test/countries/test_cuba.py index b4708add1..37f0810e6 100644 --- a/test/countries/test_cuba.py +++ b/test/countries/test_cuba.py @@ -34,7 +34,7 @@ def _check_all_dates(self, year, expected_holidays): def test_1968(self): year = 1968 - expected = [ + expected = { date(year, JAN, 1), date(year, MAY, 1), date(year, JUL, 25), @@ -42,48 +42,48 @@ def test_1968(self): date(year, JUL, 27), date(year, OCT, 10), date(year, DEC, 25), - ] + } self._check_all_dates(year, expected) def test_1969(self): year = 1969 - expected = [ + expected = { date(year, JAN, 1), date(year, MAY, 1), date(year, JUL, 25), date(year, JUL, 26), date(year, JUL, 27), date(year, OCT, 10), - ] + } self._check_all_dates(year, expected) def test_1970(self): year = 1970 - expected = [ + expected = { date(year, JAN, 1), date(year, MAY, 1), date(year, JUL, 25), date(year, JUL, 26), date(year, JUL, 27), date(year, OCT, 10), - ] + } self._check_all_dates(year, expected) def test_1996(self): year = 1996 - expected = [ + expected = { date(year, JAN, 1), date(year, MAY, 1), date(year, JUL, 25), date(year, JUL, 26), date(year, JUL, 27), date(year, OCT, 10), - ] + } self._check_all_dates(year, expected) def test_1997(self): year = 1997 - expected = [ + expected = { date(year, JAN, 1), date(year, MAY, 1), date(year, JUL, 25), @@ -91,12 +91,12 @@ def test_1997(self): date(year, JUL, 27), date(year, OCT, 10), date(year, DEC, 25), - ] + } self._check_all_dates(year, expected) def test_1998(self): year = 1998 - expected = [ + expected = { date(year, JAN, 1), date(year, MAY, 1), date(year, JUL, 25), @@ -104,12 +104,12 @@ def test_1998(self): date(year, JUL, 27), date(year, OCT, 10), date(year, DEC, 25), - ] + } self._check_all_dates(year, expected) def test_2006(self): year = 2006 - expected = [ + expected = { date(year, JAN, 1), date(year, JAN, 2), date(year, MAY, 1), @@ -118,12 +118,12 @@ def test_2006(self): date(year, JUL, 27), date(year, OCT, 10), date(year, DEC, 25), - ] + } self._check_all_dates(year, expected) def test_2007(self): year = 2007 - expected = [ + expected = { date(year, JAN, 1), date(year, MAY, 1), date(year, JUL, 25), @@ -132,12 +132,12 @@ def test_2007(self): date(year, OCT, 10), date(year, DEC, 25), date(year, DEC, 31), - ] + } self._check_all_dates(year, expected) def test_2008(self): year = 2008 - expected = [ + expected = { date(year, JAN, 1), date(year, JAN, 2), date(year, MAY, 1), @@ -147,12 +147,12 @@ def test_2008(self): date(year, OCT, 10), date(year, DEC, 25), date(year, DEC, 31), - ] + } self._check_all_dates(year, expected) def test_2011(self): year = 2011 - expected = [ + expected = { date(year, JAN, 1), date(year, JAN, 2), date(year, MAY, 1), @@ -163,12 +163,12 @@ def test_2011(self): date(year, OCT, 10), date(year, DEC, 25), date(year, DEC, 31), - ] + } self._check_all_dates(year, expected) def test_2012(self): year = 2012 - expected = [ + expected = { date(year, JAN, 1), date(year, JAN, 2), date(year, JAN, 2), @@ -180,12 +180,12 @@ def test_2012(self): date(year, OCT, 10), date(year, DEC, 25), date(year, DEC, 31), - ] + } self._check_all_dates(year, expected) def test_2013(self): year = 2013 - expected = [ + expected = { date(year, JAN, 1), date(year, JAN, 2), date(year, MAR, 29), @@ -196,13 +196,13 @@ def test_2013(self): date(year, OCT, 10), date(year, DEC, 25), date(year, DEC, 31), - ] + } self._check_all_dates(year, expected) def test_2018(self): # https://www.officeholidays.com/countries/cuba/2018 year = 2018 - expected = [ + expected = { date(year, JAN, 1), date(year, JAN, 2), date(year, MAR, 30), @@ -213,13 +213,13 @@ def test_2018(self): date(year, OCT, 10), date(year, DEC, 25), date(year, DEC, 31), - ] + } self._check_all_dates(year, expected) def test_2019(self): # https://www.officeholidays.com/countries/cuba/2019 year = 2019 - expected = [ + expected = { date(year, JAN, 1), date(year, JAN, 2), date(year, APR, 19), @@ -230,13 +230,13 @@ def test_2019(self): date(year, OCT, 10), date(year, DEC, 25), date(year, DEC, 31), - ] + } self._check_all_dates(year, expected) def test_2020(self): # https://www.officeholidays.com/countries/cuba/2020 year = 2020 - expected = [ + expected = { date(year, JAN, 1), date(year, JAN, 2), date(year, APR, 10), @@ -247,13 +247,13 @@ def test_2020(self): date(year, OCT, 10), date(year, DEC, 25), date(year, DEC, 31), - ] + } self._check_all_dates(year, expected) def test_2021(self): # https://www.officeholidays.com/countries/cuba/2021 year = 2021 - expected = [ + expected = { date(year, JAN, 1), date(year, JAN, 2), date(year, APR, 2), @@ -265,13 +265,13 @@ def test_2021(self): date(year, OCT, 11), date(year, DEC, 25), date(year, DEC, 31), - ] + } self._check_all_dates(year, expected) def test_2022(self): # https://www.officeholidays.com/countries/cuba/2022 year = 2022 - expected = [ + expected = { date(year, JAN, 1), date(year, JAN, 2), date(year, APR, 15), @@ -283,13 +283,13 @@ def test_2022(self): date(year, OCT, 10), date(year, DEC, 25), date(year, DEC, 31), - ] + } self._check_all_dates(year, expected) def test_2023(self): # https://www.officeholidays.com/countries/cuba/2023 year = 2023 - expected = [ + expected = { date(year, JAN, 1), date(year, JAN, 2), date(year, APR, 7), @@ -300,5 +300,5 @@ def test_2023(self): date(year, OCT, 10), date(year, DEC, 25), date(year, DEC, 31), - ] + } self._check_all_dates(year, expected) diff --git a/test/countries/test_honduras.py b/test/countries/test_honduras.py index d3b236337..61950e56b 100644 --- a/test/countries/test_honduras.py +++ b/test/countries/test_honduras.py @@ -34,7 +34,7 @@ def _check_all_dates(self, year, expected_holidays): def test_2014(self): year = 2014 - expected_holidays = [ + expected_holidays = { date(year, JAN, 1), date(year, APR, 14), date(year, APR, 17), @@ -46,13 +46,13 @@ def test_2014(self): date(year, OCT, 12), date(year, OCT, 21), date(year, DEC, 25), - ] + } self._check_all_dates(year, expected_holidays) def test_2016(self): # https://www.officeholidays.com/countries/honduras/2016 year = 2016 - expected_holidays = [ + expected_holidays = { date(year, JAN, 1), date(year, MAR, 24), date(year, MAR, 25), @@ -64,13 +64,13 @@ def test_2016(self): date(year, OCT, 6), date(year, OCT, 7), date(year, DEC, 25), - ] + } self._check_all_dates(year, expected_holidays) def test_2021(self): # https://www.officeholidays.com/countries/honduras/2021 year = 2021 - expected_holidays = [ + expected_holidays = { date(year, JAN, 1), date(year, APR, 1), date(year, APR, 2), @@ -82,13 +82,13 @@ def test_2021(self): date(year, OCT, 7), date(year, OCT, 8), date(year, DEC, 25), - ] + } self._check_all_dates(year, expected_holidays) def test_2022(self): # https://www.officeholidays.com/countries/honduras/2022 year = 2022 - expected_holidays = [ + expected_holidays = { date(year, JAN, 1), date(year, APR, 14), date(year, APR, 15), @@ -99,12 +99,12 @@ def test_2022(self): date(year, OCT, 6), date(year, OCT, 7), date(year, DEC, 25), - ] + } self._check_all_dates(year, expected_holidays) def test_2025(self): year = 2025 - expected_holidays = [ + expected_holidays = { date(year, JAN, 1), date(year, APR, 14), date(year, APR, 17), @@ -116,5 +116,5 @@ def test_2025(self): date(year, OCT, 2), date(year, OCT, 3), date(year, DEC, 25), - ] + } self._check_all_dates(year, expected_holidays) diff --git a/test/countries/test_hongkong.py b/test/countries/test_hongkong.py index f604c57e4..965b3b0c6 100644 --- a/test/countries/test_hongkong.py +++ b/test/countries/test_hongkong.py @@ -35,9 +35,8 @@ def test_common(self): ) def test_first_day_of_january(self): - exception_years = [2006, 2012, 2017] for year in range(2006, 2021): - if year in exception_years: + if year in {2006, 2012, 2017}: self.assertEqual( self.holidays[date(year, 1, 2)], "The day following the first day of January", diff --git a/test/countries/test_korea.py b/test/countries/test_korea.py index f77d3d0a6..72694c6c8 100644 --- a/test/countries/test_korea.py +++ b/test/countries/test_korea.py @@ -358,7 +358,7 @@ def test_chuseok(self): def test_national_foundation_day(self): for year in range(1948, 2050): - if year in [ + if year in { 1952, 1963, 1971, @@ -369,7 +369,7 @@ def test_national_foundation_day(self): 2036, 2039, 2047, - ]: + }: self.assertIn( "National Foundation Day", self.holidays[date(year, 10, 3)] ) diff --git a/test/countries/test_spain.py b/test/countries/test_spain.py index 57a521fb0..71e26ed93 100644 --- a/test/countries/test_spain.py +++ b/test/countries/test_spain.py @@ -65,12 +65,12 @@ def test_fixed_holidays_observed(self): def test_variable_days_in_2016(self): for prov, prov_holidays in self.prov_holidays.items(): self.assertEqual( - date(2016, 3, 24) in prov_holidays, prov not in ["CT", "VC"] + date(2016, 3, 24) in prov_holidays, prov not in {"CT", "VC"} ) self.assertIn(date(2016, 3, 25), prov_holidays) self.assertEqual( date(2016, 3, 28) in prov_holidays, - prov in ["CT", "PV", "NC", "VC", "IB", "CM"], + prov in {"CM", "CT", "IB", "NC", "PV", "VC"}, ) def test_fix_days_in_2022(self): @@ -89,78 +89,78 @@ def test_fix_days_in_2022(self): def test_province_specific_days(self): province_days = { - (2, 28): ["AN"], - (3, 1): ["IB"], - (4, 23): ["AR", "CL"], - (5, 30): ["CN"], - (5, 31): ["CM"], - (5, 2): ["MD"], - (6, 9): ["MC", "RI"], - (7, 25): ["GA"], - (7, 28): ["CB"], - (8, 5): ["CE"], - (9, 2): ["CE"], - (9, 8): ["AS", "EX", "ML"], - (9, 11): ["CT"], - (9, 15): ["CB"], - (9, 17): ["ML"], - (9, 27): ["NC"], - (10, 9): ["VC"], + (2, 28): {"AN"}, + (3, 1): {"IB"}, + (4, 23): {"AR", "CL"}, + (5, 30): {"CN"}, + (5, 31): {"CM"}, + (5, 2): {"MD"}, + (6, 9): {"MC", "RI"}, + (7, 25): {"GA"}, + (7, 28): {"CB"}, + (8, 5): {"CE"}, + (9, 2): {"CE"}, + (9, 8): {"AS", "EX", "ML"}, + (9, 11): {"CT"}, + (9, 15): {"CB"}, + (9, 17): {"ML"}, + (9, 27): {"NC"}, + (10, 9): {"VC"}, } for prov, prov_holidays in self.prov_holidays.items(): for year in range(2010, 2021): self.assertEqual( - date(year, 12, 26) in prov_holidays, prov in ["CT", "IB"] + date(year, 12, 26) in prov_holidays, prov in {"CT", "IB"} ) if year < 2015: self.assertEqual( date(year, 3, 19) in prov_holidays, prov - in [ + in { "AR", "CL", "CM", "EX", "GA", + "MC", "MD", "ML", - "MC", "NC", "PV", "VC", - ], + }, ) elif year == 2015: self.assertEqual( date(year, 3, 19) in prov_holidays, - prov in ["CM", "MD", "ML", "MC", "NC", "PV", "VC"], + prov in {"CM", "MC", "MD", "ML", "NC", "PV", "VC"}, ) elif year == 2016: self.assertEqual( date(year, 3, 19) in prov_holidays, - prov in ["ML", "MC", "PV", "VC"], + prov in {"MC", "ML", "PV", "VC"}, ) elif year == 2017: self.assertEqual( - date(year, 3, 19) in prov_holidays, prov in ["PV"] + date(year, 3, 19) in prov_holidays, prov in {"PV"} ) elif 2018 <= year <= 2019: self.assertEqual( date(year, 3, 19) in prov_holidays, - prov in ["GA", "MC", "NC", "PV", "VC"], + prov in {"GA", "MC", "NC", "PV", "VC"}, ) elif year == 2020: self.assertEqual( date(year, 3, 19) in prov_holidays, - prov in ["CM", "GA", "MC", "NC", "PV", "VC"], + prov in {"CM", "GA", "MC", "NC", "PV", "VC"}, ) self.assertEqual( date(year, 6, 24) in prov_holidays, - prov in ["CT", "GA", "VC"], + prov in {"CT", "GA", "VC"}, ) year_province_days = deepcopy(province_days) - if prov in ["ML"]: + if prov in {"ML"}: eid_al_fitr_current_year = _islamic_to_gre(year, 10, 1)[0] eid_al_adha_current_year = _islamic_to_gre(year, 12, 10)[0] year_province_days.update( @@ -168,17 +168,17 @@ def test_province_specific_days(self): ( eid_al_fitr_current_year.month, eid_al_fitr_current_year.day, - ): ["ML"], + ): {"ML"}, ( eid_al_adha_current_year.month, eid_al_adha_current_year.day, - ): ["ML"], + ): {"ML"}, } ) if year == 2022: year_province_days.update( - {(7, 25): ["GA", "MD", "NC", "PV"]} + {(7, 25): {"GA", "MD", "NC", "PV"}} ) for fest_day, fest_prov in year_province_days.items(): @@ -191,9 +191,9 @@ def test_province_specific_days(self): def test_variable_days_in_2022(self): province_days = { - (2, 28): ["AN"], - (3, 1): ["IB"], - (3, 19): ["VC"], + (2, 28): {"AN"}, + (3, 1): {"IB"}, + (3, 19): {"VC"}, (4, 14): [ "AN", "AR", @@ -214,27 +214,27 @@ def test_variable_days_in_2022(self): "RI", "VC", ], - (4, 18): ["CT", "IB", "NC", "PV", "RI", "VC"], - (4, 23): ["AR", "CL"], - (5, 2): ["AN", "AS", "CL", "EX", "MC", "MD", "AR"], - (5, 3): ["ML"], - (5, 17): ["GA"], - (5, 30): ["CN"], - (5, 31): ["CM"], - (6, 6): ["CT"], - (6, 9): ["MC", "RI"], - (6, 16): ["CM"], - (6, 24): ["CT", "GA", "VC"], - (7, 9): ["CE"], - (7, 11): ["ML"], - (7, 25): ["GA", "NC", "MD", "PV"], - (7, 28): ["CB"], - (8, 5): ["CE"], - (9, 2): ["CE"], - (9, 6): ["PV"], - (9, 8): ["AS", "EX", "ML"], - (9, 15): ["CB"], - (9, 17): ["ML"], + (4, 18): {"CT", "IB", "NC", "PV", "RI", "VC"}, + (4, 23): {"AR", "CL"}, + (5, 2): {"AN", "AS", "CL", "EX", "MC", "MD", "AR"}, + (5, 3): {"ML"}, + (5, 17): {"GA"}, + (5, 30): {"CN"}, + (5, 31): {"CM"}, + (6, 6): {"CT"}, + (6, 9): {"MC", "RI"}, + (6, 16): {"CM"}, + (6, 24): {"CT", "GA", "VC"}, + (7, 9): {"CE"}, + (7, 11): {"ML"}, + (7, 25): {"GA", "NC", "MD", "PV"}, + (7, 28): {"CB"}, + (8, 5): {"CE"}, + (9, 2): {"CE"}, + (9, 6): {"PV"}, + (9, 8): {"AS", "EX", "ML"}, + (9, 15): {"CB"}, + (9, 17): {"ML"}, (12, 26): [ "AN", "AR", diff --git a/test/countries/test_venezuela.py b/test/countries/test_venezuela.py index 30dbb0c5a..515840dea 100644 --- a/test/countries/test_venezuela.py +++ b/test/countries/test_venezuela.py @@ -35,7 +35,7 @@ def _check_all_dates(self, year, expected_holidays): def test_2016(self): # https://www.officeholidays.com/countries/venezuela/2016 year = 2016 - expected_holidays = [ + expected_holidays = { date(year, JAN, 1), date(year, FEB, 8), date(year, FEB, 9), @@ -50,13 +50,13 @@ def test_2016(self): date(year, DEC, 24), date(year, DEC, 25), date(year, DEC, 31), - ] + } self._check_all_dates(year, expected_holidays) def test_2017(self): # https://www.officeholidays.com/countries/venezuela/2017 year = 2017 - expected_holidays = [ + expected_holidays = { date(year, JAN, 1), date(year, FEB, 27), date(year, FEB, 28), @@ -71,13 +71,13 @@ def test_2017(self): date(year, DEC, 24), date(year, DEC, 25), date(year, DEC, 31), - ] + } self._check_all_dates(year, expected_holidays) def test_2018(self): # https://www.officeholidays.com/countries/venezuela/2018 year = 2018 - expected_holidays = [ + expected_holidays = { date(year, JAN, 1), date(year, FEB, 12), date(year, FEB, 13), @@ -92,13 +92,13 @@ def test_2018(self): date(year, DEC, 24), date(year, DEC, 25), date(year, DEC, 31), - ] + } self._check_all_dates(year, expected_holidays) def test_2019(self): # https://www.officeholidays.com/countries/venezuela/2019 year = 2019 - expected_holidays = [ + expected_holidays = { date(year, JAN, 1), date(year, MAR, 4), date(year, MAR, 5), @@ -113,13 +113,13 @@ def test_2019(self): date(year, DEC, 24), date(year, DEC, 25), date(year, DEC, 31), - ] + } self._check_all_dates(year, expected_holidays) def test_2020(self): # https://www.officeholidays.com/countries/venezuela/2020 year = 2020 - expected_holidays = [ + expected_holidays = { date(year, JAN, 1), date(year, FEB, 24), date(year, FEB, 25), @@ -134,13 +134,13 @@ def test_2020(self): date(year, DEC, 24), date(year, DEC, 25), date(year, DEC, 31), - ] + } self._check_all_dates(year, expected_holidays) def test_2021(self): # https://www.officeholidays.com/countries/venezuela/2021 year = 2021 - expected_holidays = [ + expected_holidays = { date(year, JAN, 1), date(year, FEB, 15), date(year, FEB, 16), @@ -155,13 +155,13 @@ def test_2021(self): date(year, DEC, 24), date(year, DEC, 25), date(year, DEC, 31), - ] + } self._check_all_dates(year, expected_holidays) def test_2022(self): # https://www.officeholidays.com/countries/venezuela/2022 year = 2022 - expected_holidays = [ + expected_holidays = { date(year, JAN, 1), date(year, FEB, 28), date(year, MAR, 1), @@ -176,13 +176,13 @@ def test_2022(self): date(year, DEC, 24), date(year, DEC, 25), date(year, DEC, 31), - ] + } self._check_all_dates(year, expected_holidays) def test_2023(self): # https://www.officeholidays.com/countries/venezuela/2023 year = 2023 - expected_holidays = [ + expected_holidays = { date(year, JAN, 1), date(year, FEB, 20), date(year, FEB, 21), @@ -197,7 +197,7 @@ def test_2023(self): date(year, DEC, 24), date(year, DEC, 25), date(year, DEC, 31), - ] + } self._check_all_dates(year, expected_holidays) def test_independence(self): diff --git a/test/financial/test_ny_stock_exchange.py b/test/financial/test_ny_stock_exchange.py index addd7049b..cc13f810f 100644 --- a/test/financial/test_ny_stock_exchange.py +++ b/test/financial/test_ny_stock_exchange.py @@ -12,7 +12,7 @@ import unittest from datetime import date, timedelta -from dateutil.relativedelta import relativedelta, WE +from dateutil.relativedelta import relativedelta, WE, SA, SU import holidays from holidays.constants import ( @@ -428,7 +428,7 @@ def _make_special_holiday_list(begin, end, days=None, weekends=False): begin + timedelta(days=n) for n in range((end - begin).days + 1) ): - if not weekends and d.isoweekday() in [6, 7]: + if not weekends and d.weekday() in {SA.weekday, SU.weekday}: continue if days is None or d.isoweekday() in days: _list.append(d) From 30e294a01e354f1bb974e255c57babac1a99f060 Mon Sep 17 00:00:00 2001 From: Arkadii Yakovets Date: Sun, 20 Nov 2022 10:51:23 -0800 Subject: [PATCH 009/138] Change `weekend` data type to set. --- holidays/countries/argentina.py | 24 +++++++++++----------- holidays/countries/canada.py | 8 ++++---- holidays/countries/djibouti.py | 2 +- holidays/countries/greece.py | 2 +- holidays/countries/hungary.py | 2 +- holidays/countries/ireland.py | 6 +++--- holidays/countries/paraguay.py | 16 +++++++-------- holidays/countries/serbia.py | 6 +++--- holidays/countries/united_arab_emirates.py | 2 +- holidays/countries/united_kingdom.py | 4 ++-- holidays/countries/united_states.py | 6 +++--- holidays/countries/uruguay.py | 20 +++++++++--------- holidays/holiday_base.py | 9 ++++++-- test/test_holiday_base.py | 4 ++-- 14 files changed, 58 insertions(+), 53 deletions(-) diff --git a/holidays/countries/argentina.py b/holidays/countries/argentina.py index 6f8e0e372..c8f5b91b4 100644 --- a/holidays/countries/argentina.py +++ b/holidays/countries/argentina.py @@ -34,7 +34,7 @@ def __init__(self, **kwargs): def _populate(self, year): # New Year's Day - if not self.observed and self._is_weekend(date(year, JAN, 1)): + if not self.observed and self._is_weekend(year, JAN, 1): pass else: self[date(year, JAN, 1)] = "Año Nuevo [New Year's Day]" @@ -50,7 +50,7 @@ def _populate(self, year): "[Memory's National Day for the Truth and Justice]" ) - if not self.observed and self._is_weekend(date(year, MAR, 24)): + if not self.observed and self._is_weekend(year, MAR, 24): pass else: self[date(year, MAR, 24)] = name @@ -69,7 +69,7 @@ def _populate(self, year): self[easter(year)] = name_easter # Veterans Day and the Fallen in the Malvinas War - if not self.observed and self._is_weekend(date(year, APR, 2)): + if not self.observed and self._is_weekend(year, APR, 2): pass else: self[date(year, APR, 2)] = ( @@ -81,14 +81,14 @@ def _populate(self, year): # Labor Day name = "Día del Trabajo [Labour Day]" - if not self.observed and self._is_weekend(date(year, MAY, 1)): + if not self.observed and self._is_weekend(year, MAY, 1): pass else: self[date(year, MAY, 1)] = name # May Revolution Day name = "Día de la Revolucion de Mayo [May Revolution Day]" - if not self.observed and self._is_weekend(date(year, MAY, 25)): + if not self.observed and self._is_weekend(year, MAY, 25): pass else: self[date(year, MAY, 25)] = name @@ -99,7 +99,7 @@ def _populate(self, year): "del General Martín Miguel de Güemes [Day Pass " "to the Immortality of General Martín Miguel de Güemes]" ) - if not self.observed and self._is_weekend(date(year, JUN, 17)): + if not self.observed and self._is_weekend(year, JUN, 17): pass else: self[date(year, JUN, 17)] = name @@ -110,14 +110,14 @@ def _populate(self, year): "del General D. Manuel Belgrano [Day Pass " "to the Immortality of General D. Manuel Belgrano]" ) - if not self.observed and self._is_weekend(date(year, JUN, 20)): + if not self.observed and self._is_weekend(year, JUN, 20): pass else: self[date(year, JUN, 20)] = name # Independence Day name = "Día de la Independencia [Independence Day]" - if not self.observed and self._is_weekend(date(year, JUL, 9)): + if not self.observed and self._is_weekend(year, JUL, 9): pass else: self[date(year, JUL, 9)] = name @@ -128,13 +128,13 @@ def _populate(self, year): "del General D. José de San Martin [Day Pass " "to the Immortality of General D. José de San Martin]" ) - if not self.observed and self._is_weekend(date(year, AUG, 17)): + if not self.observed and self._is_weekend(year, AUG, 17): pass else: self[date(year, AUG, 17)] = name # Respect for Cultural Diversity Day or Columbus day - if not self.observed and self._is_weekend(date(year, OCT, 12)): + if not self.observed and self._is_weekend(year, OCT, 12): pass elif year < 2010: self[date(year, OCT, 12)] = "Día de la Raza [Columbus day]" @@ -146,13 +146,13 @@ def _populate(self, year): ) # National Sovereignty Day name = "Día Nacional de la Soberanía [National Sovereignty Day]" - if not self.observed and self._is_weekend(date(year, NOV, 20)): + if not self.observed and self._is_weekend(year, NOV, 20): pass elif year >= 2010: self[date(year, NOV, 20)] = name # Immaculate Conception - if not self.observed and self._is_weekend(date(year, DEC, 8)): + if not self.observed and self._is_weekend(year, DEC, 8): pass else: self[date(year, DEC, 8)] = ( diff --git a/holidays/countries/canada.py b/holidays/countries/canada.py index eaf9e58d6..42d0b23c6 100644 --- a/holidays/countries/canada.py +++ b/holidays/countries/canada.py @@ -160,7 +160,7 @@ def _populate(self, year): if ( year >= 1879 and self.observed - and self._is_weekend(date(year, JUL, 1)) + and self._is_weekend(year, JUL, 1) ): self[date(year, JUL, 1) + rd(weekday=MO)] = ( name + " (Observed)" @@ -174,7 +174,7 @@ def _populate(self, year): if ( year >= 1879 and self.observed - and self._is_weekend(date(year, JUL, 1)) + and self._is_weekend(year, JUL, 1) ): self[date(year, JUL, 1) + rd(weekday=MO)] = ( name + " (Observed)" @@ -250,14 +250,14 @@ def _populate(self, year): if year >= 1867: name = "Christmas Day" self[date(year, DEC, 25)] = name - if self.observed and self._is_weekend(date(year, DEC, 25)): + if self.observed and self._is_weekend(year, DEC, 25): self[date(year, DEC, 27)] = name + " (Observed)" # Boxing Day if year >= 1867: name = "Boxing Day" self[date(year, DEC, 26)] = name - if self.observed and self._is_weekend(date(year, DEC, 26)): + if self.observed and self._is_weekend(year, DEC, 26): self[date(year, DEC, 28)] = name + " (Observed)" diff --git a/holidays/countries/djibouti.py b/holidays/countries/djibouti.py index 6518fd4d4..846ed742a 100644 --- a/holidays/countries/djibouti.py +++ b/holidays/countries/djibouti.py @@ -39,7 +39,7 @@ class Djibouti(HolidayBase): # is_weekend function is there, however not activated for accuracy. country = "DJ" - weekend = (FR.weekday, SA.weekday) + weekend = {FR.weekday, SA.weekday} def __init__(self, **kwargs): HolidayBase.__init__(self, **kwargs) diff --git a/holidays/countries/greece.py b/holidays/countries/greece.py index 83b2084ce..963beb075 100644 --- a/holidays/countries/greece.py +++ b/holidays/countries/greece.py @@ -55,7 +55,7 @@ def _populate(self, year): name_observed = name + " (Observed)" self[date(year, MAY, 1)] = name - if self.observed and self._is_weekend(date(year, MAY, 1)): + if self.observed and self._is_weekend(year, MAY, 1): # https://en.wikipedia.org/wiki/Public_holidays_in_Greece labour_day_observed_date = date(year, MAY, 1) + rd(weekday=MO) # In 2016 and 2021, Labour Day coincided with other holidays diff --git a/holidays/countries/hungary.py b/holidays/countries/hungary.py index 685b28318..6503ebb25 100644 --- a/holidays/countries/hungary.py +++ b/holidays/countries/hungary.py @@ -117,7 +117,7 @@ def _populate(self, year: int) -> None: if ( self.observed and 2010 <= year - and not self._is_weekend(date(year, DEC, 24)) + and not self._is_weekend(year, DEC, 24) ): self[date(year, DEC, 24)] = "Szenteste" diff --git a/holidays/countries/ireland.py b/holidays/countries/ireland.py index fab5c0dad..2e1ecabbc 100644 --- a/holidays/countries/ireland.py +++ b/holidays/countries/ireland.py @@ -52,7 +52,7 @@ def _populate(self, year): # St. Patrick's Day name = "St. Patrick's Day" self[date(year, MAR, 17)] = name - if self.observed and self._is_weekend(date(year, MAR, 17)): + if self.observed and self._is_weekend(year, MAR, 17): self[date(year, MAR, 17) + rd(weekday=MO)] = name + " (Observed)" # Easter Monday @@ -92,7 +92,7 @@ def _populate(self, year): # Christmas Day name = "Christmas Day" self[date(year, DEC, 25)] = "Christmas Day" - if self.observed and self._is_weekend(date(year, DEC, 25)): + if self.observed and self._is_weekend(year, DEC, 25): self[date(year, DEC, 25) + rd(weekday=MO.weekday)] = ( name + " (Observed)" ) @@ -100,7 +100,7 @@ def _populate(self, year): # St. Stephen's Day name = "St. Stephen's Day" self[date(year, DEC, 26)] = name - if self.observed and self._is_weekend(date(year, DEC, 26)): + if self.observed and self._is_weekend(year, DEC, 26): self[date(year, DEC, 26) + rd(days=2)] = name + " (Observed)" diff --git a/holidays/countries/paraguay.py b/holidays/countries/paraguay.py index 287ad39a6..54afc7791 100644 --- a/holidays/countries/paraguay.py +++ b/holidays/countries/paraguay.py @@ -31,7 +31,7 @@ def __init__(self, **kwargs): def _populate(self, year): # New Year's Day - if not self.observed and self._is_weekend(date(year, JAN, 1)): + if not self.observed and self._is_weekend(year, JAN, 1): pass else: self[date(year, JAN, 1)] = "Año Nuevo [New Year's Day]" @@ -39,7 +39,7 @@ def _populate(self, year): # Patriots day name = "Día de los Héroes de la Patria" "[Patriots Day]" - if not self.observed and self._is_weekend(date(year, MAR, 1)): + if not self.observed and self._is_weekend(year, MAR, 1): pass elif date(year, MAR, 1).weekday() >= WE.weekday: self[date(year, MAR, 1) + rd(weekday=MO(+1))] = name @@ -61,21 +61,21 @@ def _populate(self, year): # Labor Day name = "Día de los Trabajadores [Labour Day]" - if not self.observed and self._is_weekend(date(year, MAY, 1)): + if not self.observed and self._is_weekend(year, MAY, 1): pass else: self[date(year, MAY, 1)] = name # Independence Day name = "Día de la Independencia Nacional [Independence Day]" - if not self.observed and self._is_weekend(date(year, MAY, 15)): + if not self.observed and self._is_weekend(year, MAY, 15): pass else: self[date(year, MAY, 15)] = name # Peace in Chaco Day. name = "Día de la Paz del Chaco [Peace in Chaco Day]" - if not self.observed and self._is_weekend(date(year, JUN, 12)): + if not self.observed and self._is_weekend(year, JUN, 12): pass elif date(year, JUN, 12).weekday() >= WE.weekday: self[date(year, JUN, 12) + rd(weekday=MO(+1))] = name @@ -84,21 +84,21 @@ def _populate(self, year): # Asuncion Fundation's Day name = "Día de la Fundación de Asunción [Asuncion Fundation's Day]" - if not self.observed and self._is_weekend(date(year, AUG, 15)): + if not self.observed and self._is_weekend(year, AUG, 15): pass else: self[date(year, AUG, 15)] = name # Boqueron's Battle name = "Batalla de Boquerón [Boqueron's Battle]" - if not self.observed and self._is_weekend(date(year, SEP, 29)): + if not self.observed and self._is_weekend(year, SEP, 29): pass else: self[date(year, SEP, 29)] = name # Caacupe Virgin Day name = "Día de la Virgen de Caacupé [Caacupe Virgin Day]" - if not self.observed and self._is_weekend(date(year, DEC, 8)): + if not self.observed and self._is_weekend(year, DEC, 8): pass else: self[date(year, DEC, 8)] = name diff --git a/holidays/countries/serbia.py b/holidays/countries/serbia.py index 2b27ec33b..0632570b4 100644 --- a/holidays/countries/serbia.py +++ b/holidays/countries/serbia.py @@ -32,7 +32,7 @@ def _populate(self, year): name = "Нова година" self[date(year, JAN, 1)] = name self[date(year, JAN, 2)] = name - if self.observed and self._is_weekend(date(year, JAN, 1)): + if self.observed and self._is_weekend(year, JAN, 1): self[date(year, JAN, 3)] = name + " (Observed)" # Orthodox Christmas name = "Божић" @@ -41,13 +41,13 @@ def _populate(self, year): name = "Дан државности Србије" self[date(year, FEB, 15)] = name self[date(year, FEB, 16)] = name - if self.observed and self._is_weekend(date(year, FEB, 15)): + if self.observed and self._is_weekend(year, FEB, 15): self[date(year, FEB, 17)] = name + " (Observed)" # International Workers' Day name = "Празник рада" self[date(year, MAY, 1)] = name self[date(year, MAY, 2)] = name - if self.observed and self._is_weekend(date(year, MAY, 1)): + if self.observed and self._is_weekend(year, MAY, 1): if date(year, MAY, 2) == easter(year, method=EASTER_ORTHODOX): self[date(year, MAY, 4)] = name + " (Observed)" else: diff --git a/holidays/countries/united_arab_emirates.py b/holidays/countries/united_arab_emirates.py index 0e5e757d1..e9c2a71cc 100644 --- a/holidays/countries/united_arab_emirates.py +++ b/holidays/countries/united_arab_emirates.py @@ -44,7 +44,7 @@ class UnitedArabEmirates(HolidayBase): # raised that this holiday is missing. hijri-converter requires # Python >= 3.6 country = "AE" - weekend = (FR.weekday, SA.weekday) + weekend = {FR.weekday, SA.weekday} def __init__(self, **kwargs): HolidayBase.__init__(self, **kwargs) diff --git a/holidays/countries/united_kingdom.py b/holidays/countries/united_kingdom.py index fe539b205..2535599bd 100644 --- a/holidays/countries/united_kingdom.py +++ b/holidays/countries/united_kingdom.py @@ -51,7 +51,7 @@ def _populate(self, year: int) -> None: if self.subdiv == "UK": name += " [Scotland]" self[date(year, JAN, 2)] = name - if self.observed and self._is_weekend(date(year, JAN, 2)): + if self.observed and self._is_weekend(year, JAN, 2): self[date(year, JAN, 2) + rd(days=+2)] = name + " (Observed)" elif self.observed and date(year, JAN, 2).weekday() == MO.weekday: self[date(year, JAN, 2) + rd(days=+1)] = name + " (Observed)" @@ -62,7 +62,7 @@ def _populate(self, year: int) -> None: if self.subdiv == "UK": name += " [Northern Ireland]" self[date(year, MAR, 17)] = name - if self.observed and self._is_weekend(date(year, MAR, 17)): + if self.observed and self._is_weekend(year, MAR, 17): self[date(year, MAR, 17) + rd(weekday=MO)] = ( name + " (Observed)" ) diff --git a/holidays/countries/united_states.py b/holidays/countries/united_states.py index 55256ea7b..ef0e54a19 100644 --- a/holidays/countries/united_states.py +++ b/holidays/countries/united_states.py @@ -221,7 +221,7 @@ def _populate(self, year): if self.subdiv == "MA" and year >= 1901: name = "Evacuation Day" self[date(year, MAR, 17)] = name - if self._is_weekend(date(year, MAR, 17)): + if self._is_weekend(year, MAR, 17): self[date(year, MAR, 17) + rd(weekday=MO)] = ( name + " (Observed)" ) @@ -569,7 +569,7 @@ def _populate(self, year): if self.observed and date(year, DEC, 24).weekday() == FR.weekday: self[date(year, DEC, 24) + rd(days=-1)] = name # If on Saturday or Sunday, observed on Friday - elif self.observed and self._is_weekend(date(year, DEC, 24)): + elif self.observed and self._is_weekend(year, DEC, 24): self[date(year, DEC, 24) + rd(weekday=FR(-1))] = name # Christmas Day @@ -587,7 +587,7 @@ def _populate(self, year): self[date(year, DEC, 26)] = name name = name + " (Observed)" # If on Saturday or Sunday, observed on Monday - if self.observed and self._is_weekend(date(year, DEC, 26)): + if self.observed and self._is_weekend(year, DEC, 26): self[date(year, DEC, 26) + rd(weekday=MO)] = name # If on Monday, observed on Tuesday elif self.observed and date(year, DEC, 26).weekday() == MO.weekday: diff --git a/holidays/countries/uruguay.py b/holidays/countries/uruguay.py index ba61603b7..4818ebe9e 100644 --- a/holidays/countries/uruguay.py +++ b/holidays/countries/uruguay.py @@ -29,7 +29,7 @@ def __init__(self, **kwargs): def _populate(self, year): # New Year's Day - if not self.observed and self._is_weekend(date(year, JAN, 1)): + if not self.observed and self._is_weekend(year, JAN, 1): pass else: self[date(year, JAN, 1)] = "Año Nuevo [New Year's Day]" @@ -42,7 +42,7 @@ def _populate(self, year): # Día de Reyes - Feriado en el cual se conmemora la llegada de # los reyes magos a Jesus - if not self.observed and self._is_weekend(date(year, JAN, 6)): + if not self.observed and self._is_weekend(year, JAN, 6): pass else: self[date(year, JAN, 6)] = "Día de Reyes" @@ -61,7 +61,7 @@ def _populate(self, year): self[easter(year)] = name_easter # Desembarco de los 33 Orientales en la playa de la Agraciada - if not self.observed and self._is_weekend(date(year, APR, 19)): + if not self.observed and self._is_weekend(year, APR, 19): pass else: self[date(year, APR, 19)] = ( @@ -73,41 +73,41 @@ def _populate(self, year): # Día de los Trabajadores name = "Día del Trabajo [Labour Day]" - if not self.observed and self._is_weekend(date(year, MAY, 1)): + if not self.observed and self._is_weekend(year, MAY, 1): pass else: self[date(year, MAY, 1)] = name # Batalla de las piedras name = "Batalla de las Piedras [Battle of the stones]" - if not self.observed and self._is_weekend(date(year, MAY, 17)): + if not self.observed and self._is_weekend(year, MAY, 17): pass else: self[date(year, MAY, 17)] = name # Natalicio de José Gervacio Artigas name = "Natalicio de José Gervacio Artigas " - if not self.observed and self._is_weekend(date(year, JUN, 19)): + if not self.observed and self._is_weekend(year, JUN, 19): pass else: self[date(year, JUN, 19)] = name # Jura de la Constitución name = "Jura de la constitución " - if not self.observed and self._is_weekend(date(year, JUL, 18)): + if not self.observed and self._is_weekend(year, JUL, 18): pass else: self[date(year, JUL, 18)] = name # Declaratoria de la Independencia name = "Día de la Independencia [Independence Day]" - if not self.observed and self._is_weekend(date(year, AUG, 25)): + if not self.observed and self._is_weekend(year, AUG, 25): pass else: self[date(year, AUG, 25)] = name # Respect for Cultural Diversity Day or Columbus day - if not self.observed and self._is_weekend(date(year, OCT, 11)): + if not self.observed and self._is_weekend(year, OCT, 11): pass elif year < 2010: self[date(year, OCT, 11)] = "Día de la Raza [Columbus day]" @@ -119,7 +119,7 @@ def _populate(self, year): ) # Día de los difuntos name = "Día de los difuntos" - if not self.observed and self._is_weekend(date(year, NOV, 2)): + if not self.observed and self._is_weekend(year, NOV, 2): pass else: self[date(year, NOV, 2)] = name diff --git a/holidays/holiday_base.py b/holidays/holiday_base.py index 2692e92aa..a4cc0e6d8 100644 --- a/holidays/holiday_base.py +++ b/holidays/holiday_base.py @@ -171,7 +171,7 @@ class HolidayBase(Dict[date, str]): _deprecated_subdivisions: List[str] = [] """Other subdivisions whose names are deprecated or aliases of the official ones.""" - weekend: Tuple[int, int] = (SA.weekday, SU.weekday) + weekend: Set[int] = {SA.weekday, SU.weekday} """Country weekend days.""" def __init__( @@ -547,11 +547,16 @@ def _populate(self, year: int) -> None: """meta: public""" pass - def _is_weekend(self, dt): + def _is_weekend(self, *args): """ Returns True if date's week day is a weekend day. Returns False otherwise. """ + if len(args) == 1: + dt = args[0] + else: + dt = date(*args) + return dt.weekday() in self.weekend def __reduce__(self) -> Union[str, Tuple[Any, ...]]: diff --git a/test/test_holiday_base.py b/test/test_holiday_base.py index 1aea09eb2..e083a6be3 100644 --- a/test/test_holiday_base.py +++ b/test/test_holiday_base.py @@ -170,7 +170,7 @@ def test_update(self): def test_is_weekend(self): h = holidays.HolidayBase() - h.weekend = (MO.weekday, TU.weekday) + h.weekend = {MO.weekday, TU.weekday} for dt in (date(2022, 10, 3), date(2022, 10, 4)): self.assertTrue(h._is_weekend(dt)) @@ -178,7 +178,7 @@ def test_is_weekend(self): for dt in (date(2022, 10, 3), date(2022, 10, 4)): self.assertFalse(h._is_weekend(dt)) - h.weekend = (SA.weekday, SU.weekday) + h.weekend = {SA.weekday, SU.weekday} for dt in (date(2022, 10, 1), date(2022, 10, 2)): self.assertTrue(h._is_weekend(dt)) From 3a0d590cb5c05c947de7cbb05146584e0e35eea5 Mon Sep 17 00:00:00 2001 From: Arkadii Yakovets Date: Sun, 20 Nov 2022 11:28:27 -0800 Subject: [PATCH 010/138] Fix pre-commit config. --- .pre-commit-config.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b22a46271..039ac6eca 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -17,8 +17,8 @@ repos: - id: black language_version: python3 - - repo: https://gitlab.com/pycqa/flake8 - rev: 3.9.2 + - repo: https://github.com/pycqa/flake8 + rev: 5.0.4 hooks: - id: flake8 args: [--max-line-length=79] @@ -30,7 +30,7 @@ repos: exclude: ^docs/ - repo: https://github.com/pre-commit/mirrors-mypy - rev: 'v0.990' + rev: 'v0.991' hooks: - id: mypy additional_dependencies: [types-all] From 5227b527cf53ee6a7b24c0ebadcefea345de04af Mon Sep 17 00:00:00 2001 From: ark Date: Mon, 21 Nov 2022 14:31:39 -0800 Subject: [PATCH 011/138] Update holidays/countries/israel.py Co-authored-by: ~Jhellico --- holidays/countries/israel.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/holidays/countries/israel.py b/holidays/countries/israel.py index 3c70441fc..e0323aed9 100644 --- a/holidays/countries/israel.py +++ b/holidays/countries/israel.py @@ -62,7 +62,7 @@ def _populate(self, year): observed_delta = 0 if self.observed: day_in_week = memorial_day_dt.weekday() - if day_in_week in {TU.weekday, WE.weekday}: + if day_in_week in {WE.weekday, TH.weekday}: observed_delta = -(day_in_week - 1) elif 2004 <= year and day_in_week == 5: observed_delta = 1 From c0dec88060919167da7961d7bed291c31f7a822a Mon Sep 17 00:00:00 2001 From: Arkadii Yakovets Date: Sun, 20 Nov 2022 10:40:15 -0800 Subject: [PATCH 012/138] Fix Israel holidays. --- holidays/countries/israel.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/holidays/countries/israel.py b/holidays/countries/israel.py index e0323aed9..d116976ac 100644 --- a/holidays/countries/israel.py +++ b/holidays/countries/israel.py @@ -24,7 +24,7 @@ yom_kippur, ) from dateutil.relativedelta import relativedelta as rd -from dateutil.relativedelta import TU, WE +from dateutil.relativedelta import WE, TH from holidays.holiday_base import HolidayBase From f7e40478dc5222c1b4fdb94dbf19c4342c4c952f Mon Sep 17 00:00:00 2001 From: Arkadii Yakovets Date: Mon, 21 Nov 2022 18:14:50 -0800 Subject: [PATCH 013/138] Migrate Singapore polling days. --- holidays/countries/singapore.py | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/holidays/countries/singapore.py b/holidays/countries/singapore.py index 43df09244..a4ab45f14 100644 --- a/holidays/countries/singapore.py +++ b/holidays/countries/singapore.py @@ -38,10 +38,17 @@ class Singapore(HolidayBase): country = "SG" special_holidays = { - # SG50 Public holiday - # Announced on 14 March 2015 - # https://www.mom.gov.sg/newsroom/press-releases/2015/sg50-public-holiday-on-7-august-2015 - 2015: ((AUG, 7, "SG50 Public Holiday"),) + 2001: ((NOV, 3, "Polling Day"),), + 2006: ((MAY, 6, "Polling Day"),), + 2011: ((MAY, 7, "Polling Day"),), + 2015: ( + # SG50 Public holiday + # Announced on 14 March 2015 + # https://www.mom.gov.sg/newsroom/press-releases/2015/sg50-public-holiday-on-7-august-2015 + (AUG, 7, "SG50 Public Holiday"), + (SEP, 11, "Polling Day"), + ), + 2020: ((JUL, 10, "Polling Day"),), } def __init__( @@ -285,17 +292,6 @@ def _populate(self, year) -> None: if year <= 1968: self[date(year, DEC, 26)] = "Boxing Day" - # Polling Day - dates_fixed_obs = { - 2001: (NOV, 3), - 2006: (MAY, 6), - 2011: (MAY, 7), - 2015: (SEP, 11), - 2020: (JUL, 10), - } - if year in dates_fixed_obs: - self[date(year, *dates_fixed_obs[year])] = "Polling Day" - # Check for holidays that fall on a Sunday and implement Section 4(2) # of the Holidays Act: "if any day specified in the Schedule falls on # a Sunday, the day next following not being itself a public holiday From ba30e398f69b9278a5855bad46d4834e4dd8da23 Mon Sep 17 00:00:00 2001 From: dr-prodigy Date: Thu, 24 Nov 2022 13:50:49 +0100 Subject: [PATCH 014/138] v.0.18 beta init --- CHANGES | 6 ++++++ holidays/__init__.py | 2 +- setup.cfg | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGES b/CHANGES index 012d04fc9..388564c0f 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,9 @@ +Version 0.18 +============ + +Released ???????? ??, ???? + + Version 0.17.2 ============== diff --git a/holidays/__init__.py b/holidays/__init__.py index 8413eb4a7..c2fa7e629 100644 --- a/holidays/__init__.py +++ b/holidays/__init__.py @@ -41,4 +41,4 @@ list_supported_financial, ) -__version__ = "0.17.2" +__version__ = "0.18" diff --git a/setup.cfg b/setup.cfg index b1d7a5b4f..541754681 100644 --- a/setup.cfg +++ b/setup.cfg @@ -40,7 +40,7 @@ python_requires = >=3.7 holidays = py.typed [bumpversion] -current_version = 0.17.2 +current_version = 0.18 [flake8] extend-ignore = E203,F401,W503,W504 From 446d9395d437743ab5fdfaa02a07abb9d8714bbd Mon Sep 17 00:00:00 2001 From: ~Jhellico Date: Sat, 26 Nov 2022 18:48:41 +0200 Subject: [PATCH 015/138] Added Indonesian holidays (#787) --- README.rst | 3 + holidays/countries/__init__.py | 1 + holidays/countries/indonesia.py | 315 +++++++++++++++++++++++++++++++ test/countries/test_indonesia.py | 182 ++++++++++++++++++ 4 files changed, 501 insertions(+) create mode 100644 holidays/countries/indonesia.py create mode 100644 test/countries/test_indonesia.py diff --git a/README.rst b/README.rst index 3a26d244d..c82bb0ab1 100644 --- a/README.rst +++ b/README.rst @@ -238,6 +238,9 @@ following countries and their subdivisions are available: * - India - IN - States: AN, AP, AR, AS, BR, CG, CH, DD, DH, DL, GA, GJ, HP, HR, JH, JK, KA, KL, LA, LD, MH, ML, MN, MP, MZ, NL, OR, PB, PY, RJ, SK, TN, TR, TS, UK, UP, WB + * - Indonesia + - ID + - None * - Ireland - IE - None diff --git a/holidays/countries/__init__.py b/holidays/countries/__init__.py index 9e6a43c72..7b70bc7b2 100644 --- a/holidays/countries/__init__.py +++ b/holidays/countries/__init__.py @@ -50,6 +50,7 @@ from .hungary import HU, HUN, Hungary from .iceland import IS, ISL, Iceland from .india import IN, IND, India +from .indonesia import ID, IDN, Indonesia from .ireland import IE, IRL, Ireland from .isle_of_man import IM, IMN, IsleOfMan from .israel import IL, ISR, Israel diff --git a/holidays/countries/indonesia.py b/holidays/countries/indonesia.py new file mode 100644 index 000000000..f5597b10a --- /dev/null +++ b/holidays/countries/indonesia.py @@ -0,0 +1,315 @@ +# 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 (c) 2017-2022 +# ryanss (c) 2014-2017 +# Website: https://github.com/dr-prodigy/python-holidays +# License: MIT (see LICENSE file) + +from datetime import date + +from dateutil.easter import easter +from dateutil.relativedelta import relativedelta as rd + +from holidays.constants import ( + JAN, + FEB, + MAR, + APR, + MAY, + JUN, + JUL, + AUG, + SEP, + OCT, + NOV, + DEC, +) +from holidays.holiday_base import HolidayBase +from holidays.utils import _islamic_to_gre, _ChineseLuniSolar + + +class Indonesia(HolidayBase): + country = "ID" + special_holidays = { + # Election Day + 2018: ((JUN, 27, "Hari Pemilihan"),), + 2019: ((APR, 17, "Hari Pemilihan"),), + 2020: ((DEC, 9, "Hari Pemilihan"),), + } + + # https://en.wikipedia.org/wiki/Public_holidays_in_Indonesia + # https://www.timeanddate.com/holidays/indonesia + # https://www.officeholidays.com/countries/indonesia + def __init__(self, **kwargs): + self.cnls = _ChineseLuniSolar() + HolidayBase.__init__(self, **kwargs) + + def _populate(self, year): + super()._populate(year) + + # New Year's Day + self[date(year, JAN, 1)] = "Tahun Baru Masehi" + + # Chinese New Year + if year >= 2003: + hol_date = self.cnls.lunar_n_y_date(year) + self[hol_date] = "Tahun Baru Imlek" + + # Day of Silence + # https://en.wikipedia.org/wiki/Nyepi + dates_obs = { + 2009: (MAR, 26), + 2010: (MAR, 16), + 2011: (MAR, 5), + 2012: (MAR, 23), + 2013: (MAR, 12), + 2014: (MAR, 31), + 2015: (MAR, 21), + 2016: (MAR, 9), + 2017: (MAR, 28), + 2018: (MAR, 17), + 2019: (MAR, 7), + 2020: (MAR, 25), + 2021: (MAR, 14), + 2022: (MAR, 3), + 2023: (MAR, 22), + 2024: (MAR, 11), + 2025: (MAR, 29), + 2026: (MAR, 19), + } + if year in dates_obs: + hol_date = date(year, *dates_obs[year]) + self[hol_date] = "Hari Suci Nyepi" + + # Eid al-Fitr + dates_obs = { + 2001: ((DEC, 16),), + 2002: ((DEC, 6),), + 2003: ((NOV, 25),), + 2004: ((NOV, 14),), + 2005: ((NOV, 3),), + 2006: ((OCT, 24),), + 2007: ((OCT, 13),), + 2008: ((OCT, 1),), + 2009: ((SEP, 20),), + 2010: ((SEP, 10),), + 2011: ((AUG, 30),), + 2012: ((AUG, 19),), + 2013: ((AUG, 8),), + 2014: ((JUL, 28),), + 2015: ((JUL, 17),), + 2016: ((JUL, 6),), + 2017: ((JUN, 25),), + 2018: ((JUN, 15),), + 2019: ((JUN, 5),), + 2020: ((MAY, 24),), + 2021: ((MAY, 13),), + 2022: ((MAY, 2),), + 2023: ((APR, 22),), + } + if year in dates_obs: + for date_obs in dates_obs[year]: + hol_date = date(year, *date_obs) + self[hol_date] = "Hari Raya Idul Fitri" + self[ + hol_date + rd(days=+1) + ] = "Hari kedua dari Hari Raya Idul Fitri" + else: + for date_obs in _islamic_to_gre(year, 10, 1): + hol_date = date_obs + self[hol_date] = "Hari Raya Idul Fitri* (*estimated)" + self[ + hol_date + rd(days=+1) + ] = "Hari kedua dari Hari Raya Idul Fitri* (*estimated)" + + # Eid al-Adha + dates_obs = { + 2001: ((MAR, 6),), + 2002: ((FEB, 23),), + 2003: ((FEB, 12),), + 2004: ((FEB, 2),), + 2005: ((JAN, 21),), + 2006: ((JAN, 10), (DEC, 31)), + 2007: ((DEC, 20),), + 2008: ((DEC, 8),), + 2009: ((NOV, 27),), + 2010: ((NOV, 17),), + 2011: ((NOV, 6),), + 2012: ((OCT, 26),), + 2013: ((OCT, 15),), + 2014: ((OCT, 5),), + 2015: ((SEP, 24),), + 2016: ((SEP, 12),), + 2017: ((SEP, 1),), + 2018: ((AUG, 22),), + 2019: ((AUG, 11),), + 2020: ((JUL, 31),), + 2021: ((JUL, 20),), + 2022: ((JUL, 10),), + 2023: ((JUN, 29),), + } + if year in dates_obs: + for date_obs in dates_obs[year]: + hol_date = date(year, *date_obs) + self[hol_date] = "Hari Raya Idul Adha" + else: + for date_obs in _islamic_to_gre(year, 12, 10): + hol_date = date_obs + self[hol_date] = "Hari Raya Idul Adha* (*estimated)" + + # Islamic New Year + dates_obs = { + 2001: ((MAR, 26),), + 2002: ((MAR, 15),), + 2003: ((MAR, 5),), + 2004: ((FEB, 22),), + 2005: ((FEB, 10),), + 2006: ((JAN, 31),), + 2007: ((JAN, 20),), + 2008: ((JAN, 10), (DEC, 29)), + 2009: ((DEC, 18),), + 2010: ((DEC, 7),), + 2011: ((NOV, 27),), + 2012: ((NOV, 15),), + 2013: ((NOV, 5),), + 2014: ((OCT, 25),), + 2015: ((OCT, 14),), + 2016: ((OCT, 2),), + 2017: ((SEP, 21),), + 2018: ((SEP, 11),), + 2019: ((SEP, 1),), + 2020: ((AUG, 20),), + 2021: ((AUG, 11),), + 2022: ((JUL, 30),), + } + if year in dates_obs: + for date_obs in dates_obs[year]: + hol_date = date(year, *date_obs) + self[hol_date] = "Tahun Baru Islam" + else: + for date_obs in _islamic_to_gre(year, 1, 1): + hol_date = date_obs + self[hol_date] = "Tahun Baru Islam* (*estimated)" + + # The Prophet's Birthday + dates_obs = { + 2006: ((APR, 10),), + 2007: ((MAR, 31),), + 2008: ((MAR, 20),), + 2009: ((MAR, 9),), + 2010: ((FEB, 26),), + 2011: ((FEB, 15),), + 2012: ((FEB, 5),), + 2013: ((JAN, 24),), + 2014: ((JAN, 14),), + 2015: ((JAN, 3), (DEC, 24)), + 2016: ((DEC, 12),), + 2017: ((DEC, 1),), + 2018: ((NOV, 20),), + 2019: ((NOV, 9),), + 2020: ((OCT, 29),), + 2021: ((OCT, 19),), + 2022: ((OCT, 8),), + } + if year in dates_obs: + for date_obs in dates_obs[year]: + hol_date = date(year, *date_obs) + self[hol_date] = "Maulid Nabi Muhammad" + else: + for date_obs in _islamic_to_gre(year, 3, 12): + hol_date = date_obs + self[hol_date] = "Maulid Nabi Muhammad* (*estimated)" + + # The Prophet's Ascension + dates_obs = { + 2001: ((OCT, 15),), + 2002: ((OCT, 4),), + 2003: ((SEP, 24),), + 2004: ((SEP, 12),), + 2005: ((SEP, 1),), + 2006: ((AUG, 22),), + 2007: ((AUG, 11),), + 2008: ((JUL, 31),), + 2009: ((JUL, 20),), + 2010: ((JUL, 9),), + 2011: ((JUN, 29),), + 2012: ((JUN, 17),), + 2013: ((JUN, 6),), + 2014: ((MAY, 27),), + 2015: ((MAY, 16),), + 2016: ((MAY, 6),), + 2017: ((APR, 24),), + 2018: ((APR, 14),), + 2019: ((APR, 3),), + 2020: ((MAR, 22),), + 2021: ((MAR, 11),), + 2022: ((FEB, 28),), + } + if year in dates_obs: + for date_obs in dates_obs[year]: + hol_date = date(year, *date_obs) + self[hol_date] = "Isra' Mi'raj Nabi Muhammad" + else: + for date_obs in _islamic_to_gre(year, 7, 27): + hol_date = date_obs + self[hol_date] = "Isra' Mi'raj Nabi Muhammad* (*estimated)" + + # Good Friday + self[easter(year) + rd(days=-2)] = "Wafat Yesus Kristus" + + # Buddha's Birthday + if year >= 1983: + date_obs = { + 2007: (JUN, 1), + 2008: (MAY, 20), + 2009: (MAY, 9), + 2010: (MAY, 28), + 2011: (MAY, 17), + 2012: (MAY, 6), + 2013: (MAY, 25), + 2014: (MAY, 15), + 2015: (JUN, 2), + 2016: (MAY, 22), + 2017: (MAY, 11), + 2018: (MAY, 29), + 2019: (MAY, 19), + 2020: (MAY, 7), + 2021: (MAY, 26), + 2022: (MAY, 16), + 2023: (JUN, 4), + } + if year in date_obs: + buddha_date = date(year, *date_obs[year]) + self[buddha_date] = "Hari Raya Waisak" + else: + buddha_date = self.cnls.vesak_date(year) + self[buddha_date] = "Hari Raya Waisak* (*estimated)" + + # Labour Day + if 1953 <= year <= 1968 or year >= 2014: + self[date(year, MAY, 1)] = "Hari Buruh Internasional" + + # Ascension Day + self[easter(year) + rd(days=+39)] = "Kenaikan Yesus Kristus" + + # Pancasila Day + if year >= 2017: + self[date(year, JUN, 1)] = "Hari Lahir Pancasila" + + # National Day + self[date(year, AUG, 17)] = "Hari Kemerdekaan Republik Indonesia" + + # Christmas Day + self[date(year, DEC, 25)] = "Hari Raya Natal" + + +class ID(Indonesia): + pass + + +class IDN(Indonesia): + pass diff --git a/test/countries/test_indonesia.py b/test/countries/test_indonesia.py new file mode 100644 index 000000000..774ce5454 --- /dev/null +++ b/test/countries/test_indonesia.py @@ -0,0 +1,182 @@ +# 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 (c) 2017-2022 +# ryanss (c) 2014-2017 +# Website: https://github.com/dr-prodigy/python-holidays +# License: MIT (see LICENSE file) + +import unittest +from datetime import date + +import holidays + + +class TestIndonesia(unittest.TestCase): + def setUp(self): + self.holidays = holidays.ID() + + def test_lunar_new_year(self): + for year, month, day in ( + (2005, 2, 9), + (2006, 1, 29), + (2007, 2, 18), + (2008, 2, 7), + (2009, 1, 26), + (2010, 2, 14), + (2011, 2, 3), + (2012, 1, 23), + (2013, 2, 10), + (2014, 1, 31), + (2015, 2, 19), + (2016, 2, 8), + (2017, 1, 28), + (2018, 2, 16), + (2019, 2, 5), + (2020, 1, 25), + (2021, 2, 12), + (2022, 2, 1), + ): + self.assertEqual( + self.holidays[date(year, month, day)], "Tahun Baru Imlek" + ) + + def test_day_of_silence(self): + for year, month, day in ( + (2009, 3, 26), + (2014, 3, 31), + (2018, 3, 17), + (2020, 3, 25), + (2021, 3, 14), + (2022, 3, 3), + ): + self.assertEqual( + self.holidays[date(year, month, day)], "Hari Suci Nyepi" + ) + + def test_islamic_holidays(self): + for year, month, day in ( + # Eid al-Fitr + (2001, 12, 16), + (2001, 12, 17), + (2011, 8, 30), + (2011, 8, 31), + (2018, 6, 15), + (2018, 6, 16), + (1991, 4, 15), + (1991, 4, 16), + (1996, 2, 19), + (1996, 2, 20), + (1999, 1, 18), + (1999, 1, 19), + # Eid al-Adha + (2001, 3, 6), + (2011, 11, 6), + (2018, 8, 22), + (1991, 6, 22), + (1996, 4, 27), + (1999, 3, 27), + # Islamic New Year + (2001, 3, 26), + (2011, 11, 27), + (2018, 9, 11), + (1991, 7, 12), + (1996, 5, 18), + (1999, 4, 17), + # The Prophet's Birthday + (2006, 4, 10), + (2011, 2, 15), + (2018, 11, 20), + (1991, 9, 20), + (1996, 7, 27), + (1999, 6, 26), + # The Prophet's Ascension + (2001, 10, 15), + (2011, 6, 29), + (2018, 4, 14), + (1991, 2, 11), + (1996, 12, 8), + (1999, 11, 5), + ): + self.assertIn(date(year, month, day), self.holidays) + + def test_vesak(self): + for year, month, day in ( + (2007, 6, 1), + (2011, 5, 17), + (2018, 5, 29), + (1991, 5, 28), + (1996, 5, 31), + (1999, 5, 29), + ): + self.assertIn(date(year, month, day), self.holidays) + + def test_common(self): + self.assertIn(date(2018, 1, 1), self.holidays) # New Year's Day + + # Labour Day + self.assertIn(date(1965, 5, 1), self.holidays) + self.assertIn(date(1968, 5, 1), self.holidays) + self.assertIn(date(2014, 5, 1), self.holidays) + self.assertNotIn(date(1969, 5, 1), self.holidays) + self.assertNotIn(date(2013, 5, 1), self.holidays) + + # Pancasila Day + self.assertIn(date(2017, 6, 1), self.holidays) + self.assertIn(date(2020, 6, 1), self.holidays) + self.assertNotIn(date(2016, 6, 1), self.holidays) + + self.assertIn(date(2006, 4, 14), self.holidays) # Good Friday + self.assertIn(date(2013, 5, 9), self.holidays) # Ascension Day + + self.assertIn(date(2007, 8, 17), self.holidays) # National Day + self.assertIn(date(2014, 12, 25), self.holidays) # Christmas Day + + def test_special(self): + self.assertIn(date(2018, 6, 27), self.holidays) + self.assertIn(date(2019, 4, 17), self.holidays) + self.assertIn(date(2020, 12, 9), self.holidays) + + def test_2021(self): + for month, day in ( + (1, 1), + (2, 12), + (3, 11), + (3, 14), + (4, 2), + (5, 1), + (5, 13), + (5, 14), + (5, 26), + (6, 1), + (7, 20), + (8, 11), + (8, 17), + (10, 19), + (12, 25), + ): + self.assertIn(date(2021, month, day), self.holidays) + + def test_2022(self): + for month, day in ( + (1, 1), + (2, 1), + (2, 28), + (3, 3), + (4, 15), + (5, 1), + (5, 2), + (5, 3), + (5, 16), + (5, 26), + (6, 1), + (7, 10), + (7, 30), + (8, 17), + (10, 8), + (12, 25), + ): + self.assertIn(date(2022, month, day), self.holidays) From fd5465b7a73b9e69b3833f2806e099050e6b26a9 Mon Sep 17 00:00:00 2001 From: Maurizio Montel Date: Sat, 26 Nov 2022 17:49:50 +0100 Subject: [PATCH 016/138] CHANGES sync --- CHANGES | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES b/CHANGES index 6f762607f..053dd45c8 100644 --- a/CHANGES +++ b/CHANGES @@ -4,6 +4,7 @@ Version 0.18 Released ???????? ??, ???? - Pre-commit upgrades #786 (KJhellico, dr-p) +- Support for Indonesia #787 (KJhellico) - Hong Kong optimizations #786 (KJhellico) Version 0.17.2 From 125f713ca844e3bc09de029a4ac11bfb65c17224 Mon Sep 17 00:00:00 2001 From: ~Jhellico Date: Sat, 26 Nov 2022 18:53:20 +0200 Subject: [PATCH 017/138] Korea: fixed holidays relevance period (#791) --- holidays/countries/korea.py | 32 +++++++++++++------------- test/countries/test_korea.py | 44 ++++++++++++++++++++---------------- 2 files changed, 40 insertions(+), 36 deletions(-) diff --git a/holidays/countries/korea.py b/holidays/countries/korea.py index 47577e30c..eb04ef6fc 100644 --- a/holidays/countries/korea.py +++ b/holidays/countries/korea.py @@ -103,13 +103,11 @@ def _populate(self, year): self[alt_date] = alt_holiday + name # Tree Planting Day + # removed from holiday since 2006 name = "Tree Planting Day" planting_date = date(year, APR, 5) - if self.observed and 1949 <= year <= 2007 and year != 1960: + if self.observed and 1949 <= year <= 2005 and year != 1960: self[planting_date] = name - else: - # removed from holiday since 2007 - pass # Birthday of the Buddha name = "Birthday of the Buddha" @@ -134,7 +132,10 @@ def _populate(self, year): # Labour Day name = "Labour Day" - labour_date = date(year, MAY, 1) + if year >= 1994: + labour_date = date(year, MAY, 1) + else: + labour_date = date(year, MAR, 10) self[labour_date] = name # Memorial Day @@ -143,13 +144,11 @@ def _populate(self, year): self[memorial_date] = name # Constitution Day + # removed from holiday since 2008 name = "Constitution Day" constitution_date = date(year, JUL, 17) if self.observed and 1948 <= year <= 2007: self[constitution_date] = name - else: - # removed from holiday since 2008 - pass # Liberation Day name = "Liberation Day" @@ -204,15 +203,16 @@ def _populate(self, year): # Hangul Day name = "Hangeul Day" - hangeul_date = date(year, OCT, 9) - self[hangeul_date] = name + if year <= 1990 or year >= 2013: + hangeul_date = date(year, OCT, 9) + self[hangeul_date] = name - if self.observed and year >= 2021: - is_alt, alt_date = self.get_next_first_non_holiday( - name, hangeul_date, include_sat=True - ) - if is_alt: - self[alt_date] = alt_holiday + name + if self.observed and year >= 2021: + is_alt, alt_date = self.get_next_first_non_holiday( + name, hangeul_date, include_sat=True + ) + if is_alt: + self[alt_date] = alt_holiday + name # Christmas Day name = "Christmas Day" diff --git a/test/countries/test_korea.py b/test/countries/test_korea.py index f77d3d0a6..1795e4ca2 100644 --- a/test/countries/test_korea.py +++ b/test/countries/test_korea.py @@ -136,12 +136,18 @@ def test_tree_planting_day(self): (1995, 4, 5), (1998, 4, 5), (2000, 4, 5), - (2007, 4, 5), + (2005, 4, 5), ]: self.assertEqual( self.holidays[date(year, month, day)], "Tree Planting Day" ) + for year, month, day in [ + (1960, 4, 5), + (2006, 4, 5), + ]: + self.assertNotIn(date(year, month, day), self.holidays) + def test_childrens_day(self): for year, month, day in [ (2015, 5, 5), @@ -198,22 +204,14 @@ def test_birthday_of_buddha(self): ) def test_labour_day(self): - for year in [ - 2006, - 2007, - 2008, - 2009, - 2010, - 2012, - 2013, - 2014, - 2015, - 2017, - 2018, - 2019, - 2020, - ]: - self.assertEqual(self.holidays[date(year, 5, 1)], "Labour Day") + for year in range(1948, 1994): + self.assertIn("Labour Day", self.holidays[date(year, 3, 10)]) + + for year in range(1994, 2023): + self.assertIn("Labour Day", self.holidays[date(year, 5, 1)]) + + self.assertNotIn(date(1993, 5, 1), self.holidays) + self.assertNotIn(date(1994, 3, 10), self.holidays) def test_memorial_day(self): for year in [ @@ -234,12 +232,12 @@ def test_memorial_day(self): self.assertEqual(self.holidays[date(year, 6, 6)], "Memorial Day") def test_constitution_day(self): - for year in range(1948, 2007): + for year in range(1948, 2008): self.assertEqual( self.holidays[date(year, 7, 17)], "Constitution Day" ) - self.assertNotIn(date(2008, 7, 17), self.holidays) self.assertNotIn(date(1947, 7, 17), self.holidays) + self.assertNotIn(date(2008, 7, 17), self.holidays) def test_liberation_day(self): for year in range(1945, 2020): @@ -385,9 +383,15 @@ def test_national_foundation_day(self): ) def test_hangeul_day(self): - for year in range(1948, 2007): + for year in range(1948, 1991): self.assertEqual(self.holidays[date(year, 10, 9)], "Hangeul Day") + for year in range(2013, 2023): + self.assertEqual(self.holidays[date(year, 10, 9)], "Hangeul Day") + + for year in range(1991, 2013): + self.assertNotIn(date(year, 10, 9), self.holidays) + for year, month, day in [(2021, 10, 11)]: self.assertEqual( self.holidays[date(year, month, day)], From a31c8ecfa1183c8e3047843ca9ea6d86e79c240f Mon Sep 17 00:00:00 2001 From: Maurizio Montel Date: Sat, 26 Nov 2022 17:55:27 +0100 Subject: [PATCH 018/138] CHANGES sync --- CHANGES | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES b/CHANGES index 053dd45c8..77af61d0d 100644 --- a/CHANGES +++ b/CHANGES @@ -6,6 +6,7 @@ Released ???????? ??, ???? - Pre-commit upgrades #786 (KJhellico, dr-p) - Support for Indonesia #787 (KJhellico) - Hong Kong optimizations #786 (KJhellico) +- Korea fixes #791 (KJhellico) Version 0.17.2 ============== From bc6d33e43c19dab472f3942fa042c461576198b1 Mon Sep 17 00:00:00 2001 From: Maurizio Montel Date: Sat, 26 Nov 2022 18:31:19 +0100 Subject: [PATCH 019/138] Korea quicker tests --- test/countries/test_korea.py | 82 +++++++----------------------------- 1 file changed, 16 insertions(+), 66 deletions(-) diff --git a/test/countries/test_korea.py b/test/countries/test_korea.py index 1795e4ca2..377d015e6 100644 --- a/test/countries/test_korea.py +++ b/test/countries/test_korea.py @@ -102,19 +102,7 @@ def test_lunar_new_year(self): def test_independence_movement_day(self): for year, month, day in [ (2006, 3, 1), - (2007, 3, 1), - (2008, 3, 1), - (2009, 3, 1), - (2010, 3, 1), - (2011, 3, 1), - (2012, 3, 1), - (2013, 3, 1), - (2014, 3, 1), - (2016, 3, 1), - (2017, 3, 1), - (2018, 3, 1), - (2019, 3, 1), - (2020, 3, 1), + (2022, 3, 1), ]: self.assertEqual( self.holidays[date(year, month, day)], @@ -130,12 +118,6 @@ def test_independence_movement_day(self): def test_tree_planting_day(self): for year, month, day in [ (1949, 4, 5), - (1962, 4, 5), - (1982, 4, 5), - (1990, 4, 5), - (1995, 4, 5), - (1998, 4, 5), - (2000, 4, 5), (2005, 4, 5), ]: self.assertEqual( @@ -151,8 +133,6 @@ def test_tree_planting_day(self): def test_childrens_day(self): for year, month, day in [ (2015, 5, 5), - (2016, 5, 5), - (2017, 5, 5), (2018, 5, 5), ]: self.assertEqual( @@ -204,35 +184,21 @@ def test_birthday_of_buddha(self): ) def test_labour_day(self): - for year in range(1948, 1994): + for year in [1948, 1993]: self.assertIn("Labour Day", self.holidays[date(year, 3, 10)]) - for year in range(1994, 2023): + for year in [1994, 2023]: self.assertIn("Labour Day", self.holidays[date(year, 5, 1)]) self.assertNotIn(date(1993, 5, 1), self.holidays) self.assertNotIn(date(1994, 3, 10), self.holidays) def test_memorial_day(self): - for year in [ - 2006, - 2007, - 2008, - 2009, - 2010, - 2012, - 2013, - 2014, - 2015, - 2017, - 2018, - 2019, - 2020, - ]: + for year in [2006, 2022]: self.assertEqual(self.holidays[date(year, 6, 6)], "Memorial Day") def test_constitution_day(self): - for year in range(1948, 2008): + for year in [1948, 2007]: self.assertEqual( self.holidays[date(year, 7, 17)], "Constitution Day" ) @@ -240,7 +206,7 @@ def test_constitution_day(self): self.assertNotIn(date(2008, 7, 17), self.holidays) def test_liberation_day(self): - for year in range(1945, 2020): + for year in [1945, 2020]: self.assertEqual( self.holidays[date(year, 8, 15)], "Liberation Day" ) @@ -355,26 +321,10 @@ def test_chuseok(self): ) def test_national_foundation_day(self): - for year in range(1948, 2050): - if year in [ - 1952, - 1963, - 1971, - 1990, - 2009, - 2017, - 2028, - 2036, - 2039, - 2047, - ]: - self.assertIn( - "National Foundation Day", self.holidays[date(year, 10, 3)] - ) - else: - self.assertEqual( - self.holidays[date(year, 10, 3)], "National Foundation Day" - ) + for year in [1951, 2049]: + self.assertIn( + "National Foundation Day", self.holidays[date(year, 10, 3)] + ) for year, month, day in [(2021, 10, 4)]: self.assertEqual( @@ -383,13 +333,13 @@ def test_national_foundation_day(self): ) def test_hangeul_day(self): - for year in range(1948, 1991): + for year in [1948, 1990]: self.assertEqual(self.holidays[date(year, 10, 9)], "Hangeul Day") - for year in range(2013, 2023): + for year in [2013, 2023]: self.assertEqual(self.holidays[date(year, 10, 9)], "Hangeul Day") - for year in range(1991, 2013): + for year in [1991, 2012]: self.assertNotIn(date(year, 10, 9), self.holidays) for year, month, day in [(2021, 10, 11)]: @@ -399,12 +349,12 @@ def test_hangeul_day(self): ) def test_christmas_day(self): - for year in range(1948, 2050): + for year in [1948, 2050]: self.assertEqual( self.holidays[date(year, 12, 25)], "Christmas Day" ) def test_years_range(self): - self.holidays = holidays.KR(years=range(2006, 2021)) - for year in range(2006, 2021): + self.holidays = holidays.KR(years=[2006, 2021]) + for year in [2006, 2021]: self.assertIn(self.holidays[date(year, 1, 1)], "New Year's Day") From 44c0c97271f74b18cbd5a35f16e4543d6c24f31c Mon Sep 17 00:00:00 2001 From: Maurizio Montel Date: Sat, 26 Nov 2022 18:40:55 +0100 Subject: [PATCH 020/138] CHANGES sync --- CHANGES | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index 77af61d0d..5390c5cb0 100644 --- a/CHANGES +++ b/CHANGES @@ -6,7 +6,7 @@ Released ???????? ??, ???? - Pre-commit upgrades #786 (KJhellico, dr-p) - Support for Indonesia #787 (KJhellico) - Hong Kong optimizations #786 (KJhellico) -- Korea fixes #791 (KJhellico) +- Korea fixes #791 (KJhellico) + test optimizations (dr-p) Version 0.17.2 ============== From a277919c1262aa97da60e00a1d8f644ed97db6b5 Mon Sep 17 00:00:00 2001 From: ark Date: Sat, 26 Nov 2022 09:49:51 -0800 Subject: [PATCH 021/138] Clean up unused imports. (#792) * Implement flake8 suggested fixes. - Fine tune flake8 setup.cfg config. - Remove unused imports. - Add __init__.py to test/financial Reconfigure flake8 to use per file ignores. * Fix pre-commit. * Add flake8-print. --- .pre-commit-config.yaml | 2 ++ holidays/countries/bulgaria.py | 2 +- holidays/countries/czechia.py | 1 - holidays/countries/djibouti.py | 1 - holidays/countries/norway.py | 2 +- holidays/countries/poland.py | 1 - holidays/countries/singapore.py | 2 +- holidays/countries/slovakia.py | 1 - holidays/countries/tunisia.py | 1 - holidays/countries/vietnam.py | 2 +- holidays/holiday_base.py | 1 - setup.cfg | 9 ++++++--- test/countries/test_czechia.py | 1 - test/countries/test_india.py | 2 +- test/countries/test_malta.py | 1 - test/countries/test_poland.py | 1 - test/countries/test_slovakia.py | 1 - test/countries/test_spain.py | 3 --- test/financial/__init__.py | 0 19 files changed, 13 insertions(+), 21 deletions(-) create mode 100644 test/financial/__init__.py diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 426e9f7fa..1eda505f4 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -21,6 +21,8 @@ repos: rev: 5.0.4 hooks: - id: flake8 + additional_dependencies: + - flake8-print args: [--max-line-length=79] - repo: https://github.com/pre-commit/mirrors-isort diff --git a/holidays/countries/bulgaria.py b/holidays/countries/bulgaria.py index 197887365..85e2e522d 100644 --- a/holidays/countries/bulgaria.py +++ b/holidays/countries/bulgaria.py @@ -14,7 +14,7 @@ from dateutil.easter import EASTER_ORTHODOX, easter from dateutil.relativedelta import relativedelta as rd -from holidays.constants import JAN, MAR, APR, MAY, SEP, NOV, DEC +from holidays.constants import JAN, MAR, MAY, SEP, NOV, DEC from holidays.holiday_base import HolidayBase diff --git a/holidays/countries/czechia.py b/holidays/countries/czechia.py index 805f6705f..aabcc7b83 100644 --- a/holidays/countries/czechia.py +++ b/holidays/countries/czechia.py @@ -9,7 +9,6 @@ # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) -import warnings from datetime import date from dateutil.easter import easter diff --git a/holidays/countries/djibouti.py b/holidays/countries/djibouti.py index a703d3225..660117073 100644 --- a/holidays/countries/djibouti.py +++ b/holidays/countries/djibouti.py @@ -11,7 +11,6 @@ from datetime import date -from dateutil.easter import easter from dateutil.relativedelta import relativedelta as rd from holidays.constants import FRI, SAT, JAN, MAY, JUN diff --git a/holidays/countries/norway.py b/holidays/countries/norway.py index 4e93ab499..256e77c38 100644 --- a/holidays/countries/norway.py +++ b/holidays/countries/norway.py @@ -16,7 +16,7 @@ from dateutil.relativedelta import relativedelta as rd from dateutil.relativedelta import SU -from holidays.constants import MON, THU, FRI, SUN, JAN, MAY, DEC +from holidays.constants import JAN, MAY, DEC from holidays.holiday_base import HolidayBase diff --git a/holidays/countries/poland.py b/holidays/countries/poland.py index b5cc62e31..a125da345 100644 --- a/holidays/countries/poland.py +++ b/holidays/countries/poland.py @@ -9,7 +9,6 @@ # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) -import warnings from datetime import date from dateutil.easter import easter diff --git a/holidays/countries/singapore.py b/holidays/countries/singapore.py index e0bde43fb..11f0923bc 100644 --- a/holidays/countries/singapore.py +++ b/holidays/countries/singapore.py @@ -10,7 +10,7 @@ # License: MIT (see LICENSE file) from datetime import date -from typing import Dict, Iterable, List, Optional, Tuple, Union +from typing import Dict, Iterable, Optional, Tuple, Union from dateutil.easter import easter from dateutil.relativedelta import relativedelta as rd diff --git a/holidays/countries/slovakia.py b/holidays/countries/slovakia.py index 2a6ffbaeb..a42da0fd6 100644 --- a/holidays/countries/slovakia.py +++ b/holidays/countries/slovakia.py @@ -9,7 +9,6 @@ # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) -import warnings from datetime import date from dateutil.easter import easter diff --git a/holidays/countries/tunisia.py b/holidays/countries/tunisia.py index 14418addd..baf87bde5 100644 --- a/holidays/countries/tunisia.py +++ b/holidays/countries/tunisia.py @@ -11,7 +11,6 @@ from datetime import date -from dateutil.easter import easter from dateutil.relativedelta import relativedelta as rd from holidays.constants import SAT, SUN, JAN, MAR, APR, MAY, JUL, AUG, OCT diff --git a/holidays/countries/vietnam.py b/holidays/countries/vietnam.py index a35b715f1..2d7dddaa8 100644 --- a/holidays/countries/vietnam.py +++ b/holidays/countries/vietnam.py @@ -9,7 +9,7 @@ # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) -from datetime import date, datetime, timedelta +from datetime import date from dateutil.relativedelta import relativedelta as rd diff --git a/holidays/holiday_base.py b/holidays/holiday_base.py index 98c065920..d6360e83f 100644 --- a/holidays/holiday_base.py +++ b/holidays/holiday_base.py @@ -14,7 +14,6 @@ import warnings from datetime import date, datetime, timedelta from typing import ( - TYPE_CHECKING, Any, Dict, Iterable, diff --git a/setup.cfg b/setup.cfg index 541754681..207910b7e 100644 --- a/setup.cfg +++ b/setup.cfg @@ -43,9 +43,12 @@ holidays = py.typed current_version = 0.18 [flake8] -extend-ignore = E203,F401,W503,W504 -exclude = __init__.py,*.pyc,tests.py,build,dist -paths = ./holidays/ ./tests/ +per-file-ignores = + holidays/__init__.py:F401,F403 + holidays/countries/__init__.py:F401 + holidays/financial/__init__.py:F401 + test/__init__.py:F401,F403 + test/test_holiday_base.py:E203,T201 [isort] line_length = 79 diff --git a/test/countries/test_czechia.py b/test/countries/test_czechia.py index 78d18b48a..e56feb93f 100644 --- a/test/countries/test_czechia.py +++ b/test/countries/test_czechia.py @@ -10,7 +10,6 @@ # License: MIT (see LICENSE file) import unittest -import warnings from datetime import date import holidays diff --git a/test/countries/test_india.py b/test/countries/test_india.py index b8fb12256..bf25d3c2c 100644 --- a/test/countries/test_india.py +++ b/test/countries/test_india.py @@ -14,7 +14,7 @@ from datetime import date import holidays -from holidays.constants import APR, AUG, DEC, FEB, JAN, JUN, MAR, MAY, NOV, OCT +from holidays.constants import FEB, MAR, OCT, NOV, DEC class TestIND(unittest.TestCase): diff --git a/test/countries/test_malta.py b/test/countries/test_malta.py index 15bfdc6fa..343c57082 100644 --- a/test/countries/test_malta.py +++ b/test/countries/test_malta.py @@ -10,7 +10,6 @@ # License: MIT (see LICENSE file) import unittest -import warnings from datetime import date import holidays diff --git a/test/countries/test_poland.py b/test/countries/test_poland.py index f944a00cd..81084a87c 100644 --- a/test/countries/test_poland.py +++ b/test/countries/test_poland.py @@ -10,7 +10,6 @@ # License: MIT (see LICENSE file) import unittest -import warnings from datetime import date import holidays diff --git a/test/countries/test_slovakia.py b/test/countries/test_slovakia.py index 721210be8..320da75bb 100644 --- a/test/countries/test_slovakia.py +++ b/test/countries/test_slovakia.py @@ -10,7 +10,6 @@ # License: MIT (see LICENSE file) import unittest -import warnings from datetime import date import holidays diff --git a/test/countries/test_spain.py b/test/countries/test_spain.py index 57a521fb0..77b9e365d 100644 --- a/test/countries/test_spain.py +++ b/test/countries/test_spain.py @@ -14,9 +14,6 @@ from datetime import date from itertools import product -from dateutil.easter import easter -from dateutil.relativedelta import relativedelta as rd - import holidays from holidays.utils import _islamic_to_gre diff --git a/test/financial/__init__.py b/test/financial/__init__.py new file mode 100644 index 000000000..e69de29bb From f8156bba6a9c9bbebd9579af6178b0f658c5e3de Mon Sep 17 00:00:00 2001 From: Maurizio Montel Date: Sat, 26 Nov 2022 21:58:32 +0100 Subject: [PATCH 022/138] flake8 settings review --- CHANGES | 3 ++- setup.cfg | 9 ++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/CHANGES b/CHANGES index 5390c5cb0..fca91ff77 100644 --- a/CHANGES +++ b/CHANGES @@ -3,7 +3,8 @@ Version 0.18 Released ???????? ??, ???? -- Pre-commit upgrades #786 (KJhellico, dr-p) +- Pre-commit reviews #786 (KJhellico, dr-p) +- Import cleanup, flake8 settings review #792 (arkid15r, dr-p) - Support for Indonesia #787 (KJhellico) - Hong Kong optimizations #786 (KJhellico) - Korea fixes #791 (KJhellico) + test optimizations (dr-p) diff --git a/setup.cfg b/setup.cfg index 207910b7e..6f245bbc5 100644 --- a/setup.cfg +++ b/setup.cfg @@ -43,12 +43,11 @@ holidays = py.typed current_version = 0.18 [flake8] +paths = ./holidays/, ./tests/ +ignore = E203, W503 +exclude = *.pyc, *.txt, .tox, build/, dist/, venv/ per-file-ignores = - holidays/__init__.py:F401,F403 - holidays/countries/__init__.py:F401 - holidays/financial/__init__.py:F401 - test/__init__.py:F401,F403 - test/test_holiday_base.py:E203,T201 + __init__.py:F401, F403 [isort] line_length = 79 From dedc9e7b5547156b264ec6cdf67cee247083a28f Mon Sep 17 00:00:00 2001 From: dr-prodigy Date: Sat, 26 Nov 2022 22:30:15 +0100 Subject: [PATCH 023/138] flake8 settings, print removal --- setup.cfg | 1 + test/test_holiday_base.py | 6 ++---- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/setup.cfg b/setup.cfg index 6f245bbc5..7688eaa04 100644 --- a/setup.cfg +++ b/setup.cfg @@ -56,3 +56,4 @@ profile = black [rstcheck] ignore_language = python +ignore_directives = automodule diff --git a/test/test_holiday_base.py b/test/test_holiday_base.py index 3d1a0d916..9aa4bdfa6 100644 --- a/test/test_holiday_base.py +++ b/test/test_holiday_base.py @@ -674,12 +674,10 @@ def list2reason(exc_list): failure = list2reason(result.failures) text = error if error else failure if text: - print( + warnings.warn( f"{text.splitlines()[-1]} in country {self.country}: " f"holiday {self.hol} returned for year {self.year}" - ) - print( - holidays.country_holidays( + + holidays.country_holidays( self.country, subdiv=None, years=[self.year] ).get_list(self.hol) ) From 5dc711b93f120eff5e8fefbc47fd727fe6366353 Mon Sep 17 00:00:00 2001 From: ark Date: Sat, 26 Nov 2022 13:37:29 -0800 Subject: [PATCH 024/138] Clean up .pre-commit-config.yaml. (#795) * Clean up .pre-commit-config.yaml. Re-enable rstcheck hook. * Change flake8 source URL. Co-authored-by: dr-prodigy --- .pre-commit-config.yaml | 15 ++++++--------- README.rst | 6 +++--- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1eda505f4..5ce1a4e83 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -32,7 +32,7 @@ repos: exclude: ^docs/ - repo: https://github.com/pre-commit/mirrors-mypy - rev: 'v0.991' + rev: v0.991 hooks: - id: mypy additional_dependencies: [types-all] @@ -46,14 +46,11 @@ repos: hooks: - id: rst-backticks -# Temporarily disabled due to unable to suppress -# [WinError 2] The system cannot find the file specified -# - repo: https://github.com/myint/rstcheck -# rev: 3f92957478422df87bd730abde66f089cc1ee19b -# hooks: -# - id: rstcheck -# additional_dependencies: [rstcheck] -# args: [--ignore-directives=automodule] + - repo: https://github.com/myint/rstcheck + rev: v6.1.1 + hooks: + - id: rstcheck + additional_dependencies: [rstcheck, sphinx] - repo: https://github.com/asottile/setup-cfg-fmt rev: v2.2.0 diff --git a/README.rst b/README.rst index c82bb0ab1..ac3a6ad09 100644 --- a/README.rst +++ b/README.rst @@ -95,10 +95,10 @@ Some holidays may be only present in parts of a country: '2018-01-06' in us_holidays # False '2018-01-06' in us_pr_holidays # True -.. _documentation: https://python-holidays.readthedocs.io/ +.. _python-holidays documentation: https://python-holidays.readthedocs.io/ -Please see the `documentation`_ for additional examples and detailed -information. +Please see the `python-holidays documentation`_ for additional examples and +detailed information. Available Countries From afc823fdf54e7a590d2d50330a17945a050db4ec Mon Sep 17 00:00:00 2001 From: dr-prodigy Date: Sat, 26 Nov 2022 22:38:25 +0100 Subject: [PATCH 025/138] CHANGES sync --- CHANGES | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index fca91ff77..eb0608a00 100644 --- a/CHANGES +++ b/CHANGES @@ -3,7 +3,7 @@ Version 0.18 Released ???????? ??, ???? -- Pre-commit reviews #786 (KJhellico, dr-p) +- Pre-commit reviews #786, #795 (KJhellico, arkid15r, dr-p) - Import cleanup, flake8 settings review #792 (arkid15r, dr-p) - Support for Indonesia #787 (KJhellico) - Hong Kong optimizations #786 (KJhellico) From c6c240dc8eb180aee2dbce6e285d5af978a80907 Mon Sep 17 00:00:00 2001 From: dr-prodigy Date: Sat, 26 Nov 2022 22:59:29 +0100 Subject: [PATCH 026/138] Hong Kong fix --- CHANGES | 3 ++- holidays/countries/hongkong.py | 2 -- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/CHANGES b/CHANGES index eb0608a00..a58c343ea 100644 --- a/CHANGES +++ b/CHANGES @@ -4,7 +4,8 @@ Version 0.18 Released ???????? ??, ???? - Pre-commit reviews #786, #795 (KJhellico, arkid15r, dr-p) -- Import cleanup, flake8 settings review #792 (arkid15r, dr-p) +- Import cleanup, flake8 settings review #792 (arkid15r, KJhellico, dr-p) +- Special holidays refactoring for 13 countries #796 (arkid15r, KJhellico) - Support for Indonesia #787 (KJhellico) - Hong Kong optimizations #786 (KJhellico) - Korea fixes #791 (KJhellico) + test optimizations (dr-p) diff --git a/holidays/countries/hongkong.py b/holidays/countries/hongkong.py index e4b623dd0..15dcd3aff 100644 --- a/holidays/countries/hongkong.py +++ b/holidays/countries/hongkong.py @@ -168,8 +168,6 @@ def _populate(self, year): self[hksar_date + rd(days=+1)] = day_following + name else: self[hksar_date] = name - else: - self[hksar_date] = name # Chinese Mid-Autumn Festival name = "Chinese Mid-Autumn Festival" From 6d0d16c86fd96e00abcf0b343a846bf47fa5d20b Mon Sep 17 00:00:00 2001 From: dr-prodigy Date: Sat, 26 Nov 2022 23:17:36 +0100 Subject: [PATCH 027/138] CHANGES sync --- CHANGES | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES b/CHANGES index a58c343ea..2ff44a8c6 100644 --- a/CHANGES +++ b/CHANGES @@ -7,6 +7,7 @@ Released ???????? ??, ???? - Import cleanup, flake8 settings review #792 (arkid15r, KJhellico, dr-p) - Special holidays refactoring for 13 countries #796 (arkid15r, KJhellico) - Support for Indonesia #787 (KJhellico) +- Korea renamed to South Korea #797 (arkid15r) - Hong Kong optimizations #786 (KJhellico) - Korea fixes #791 (KJhellico) + test optimizations (dr-p) From 53bbf05c1e484b9efd50d10339192c79743ae6fd Mon Sep 17 00:00:00 2001 From: ~Jhellico Date: Sun, 27 Nov 2022 00:22:42 +0200 Subject: [PATCH 028/138] Zambia: optimizations, added special holidays (#798) Co-authored-by: dr-prodigy <28216945+dr-prodigy@users.noreply.github.com> --- holidays/countries/zambia.py | 104 ++++++++++++++++++---------------- test/countries/test_zambia.py | 15 ++++- 2 files changed, 68 insertions(+), 51 deletions(-) diff --git a/holidays/countries/zambia.py b/holidays/countries/zambia.py index d770aef3d..55bf04e59 100644 --- a/holidays/countries/zambia.py +++ b/holidays/countries/zambia.py @@ -13,8 +13,9 @@ from dateutil.easter import easter from dateutil.relativedelta import relativedelta as rd +from dateutil.relativedelta import MO -from holidays.constants import SUN, JAN, MAR, APR, MAY, JUL, AUG, OCT, DEC +from holidays.constants import SUN, JAN, MAR, APR, MAY, JUL, AUG, SEP, OCT, DEC from holidays.holiday_base import HolidayBase @@ -28,68 +29,75 @@ class Zambia(HolidayBase): country = "ZM" special_holidays = { + 2016: ( + (AUG, 11, "General elections and referendum"), + ( + SEP, + 13, + "Inauguration ceremony of President-elect " + "and Vice President-elect", + ), + ), + 2018: ( + (MAR, 9, "Public holiday"), + (JUL, 26, "Lusaka mayoral and other local government elections"), + ), 2021: ( (JUL, 2, "Memorial service for Kenneth Kaunda"), (JUL, 7, "Funeral of Kenneth Kaunda"), - ) + (AUG, 12, "General elections"), + (AUG, 13, "Counting in general elections"), + (AUG, 24, "Presidential inauguration"), + ), + 2022: ((MAR, 18, "Funeral of Rupiah Banda"),), } def _populate(self, year): - super()._populate(year) # Observed since 1965 - if year > 1964: - self[date(year, JAN, 1)] = "New Year's Day" - self[date(year, MAR, 12)] = "Youth Day" - - e = easter(year) - good_friday = e - rd(days=2) - holy_saturday = e - rd(days=1) - easter_monday = e + rd(days=1) - self[good_friday] = "Good Friday" - self[holy_saturday] = "Holy Saturday" - self[easter_monday] = "Easter Monday" - - self[date(year, MAY, 1)] = "Labour Day" - self[date(year, MAY, 25)] = "Africa Freedom Day" - - # 1st Monday of July = "Heroes' Day" - # Find the date of the 1st Monday - # for the given year and month - d1 = date(year, JUL, 7) - offset = -d1.weekday() # weekday = 0 means monday - d1 = d1 + rd(days=offset) - - self[d1] = "Heroes' Day" - self[d1 + rd(days=1)] = "Unity Day" - - # 1st Monday of Aug = "Farmers' Day" - d2 = date(year, AUG, 7) - offset = -d2.weekday() - d2 = d2 + rd(days=offset) - - self[d2] = "Farmers' Day" - - self[date(year, OCT, 24)] = "Independence Day" - self[date(year, DEC, 25)] = "Christmas Day" - - # Observed since 1991 - if year > 1990: + if year <= 1964: + return + + super()._populate(year) + + self[date(year, JAN, 1)] = "New Year's Day" + + if year >= 1991: self[date(year, MAR, 8)] = "International Women's Day" - # Observed since 2015 - if year > 2014: - self[date(year, OCT, 18)] = "National Prayer Day" + self[date(year, MAR, 12)] = "Youth Day" + + easter_date = easter(year) + self[easter_date + rd(days=-2)] = "Good Friday" + self[easter_date + rd(days=-1)] = "Holy Saturday" + self[easter_date + rd(days=1)] = "Easter Monday" - # Observed since 2022 - if year > 2021: + if year >= 2022: self[date(year, APR, 28)] = "Kenneth Kaunda Day" + self[date(year, MAY, 1)] = "Labour Day" + self[date(year, MAY, 25)] = "Africa Freedom Day" + + # 1st Monday of July = "Heroes' Day" + dt = date(year, JUL, 1) + rd(weekday=MO) + self[dt] = "Heroes' Day" + self[dt + rd(days=1)] = "Unity Day" + + # 1st Monday of Aug = "Farmers' Day" + dt = date(year, AUG, 1) + rd(weekday=MO) + self[dt] = "Farmers' Day" + + if year >= 2015: + self[date(year, OCT, 18)] = "National Prayer Day" + + self[date(year, OCT, 24)] = "Independence Day" + self[date(year, DEC, 25)] = "Christmas Day" + # whenever a public holiday falls on a Sunday, # it rolls over to the following Monday - for k, v in list(self.items()): - if self.observed and year > 1964: - if k.weekday() == SUN: + if self.observed: + for k, v in list(self.items()): + if k.year == year and k.weekday() == SUN: self[k + rd(days=1)] = v + " (Observed)" diff --git a/test/countries/test_zambia.py b/test/countries/test_zambia.py index aecc142d0..eace9c023 100644 --- a/test/countries/test_zambia.py +++ b/test/countries/test_zambia.py @@ -54,9 +54,6 @@ def test_static(self): self.assertIn("1969-05-26", self.holidays) # Youth Day self.assertIn("2004-03-12", self.holidays) - # Two holidays declared in 2021 - self.assertIn("2021-07-02", self.holidays) - self.assertIn("2021-07-07", self.holidays) # Kenneth Kaunda Day self.assertIn("2032-04-28", self.holidays) @@ -70,3 +67,15 @@ def test_observed(self): self.holidays = holidays.ZM(observed=False) # African Freedom Day (on Sunday) self.assertNotIn("1969-05-26", self.holidays) + + def test_special_holidays(self): + self.assertIn(date(2016, 8, 11), self.holidays) + self.assertIn(date(2016, 9, 13), self.holidays) + self.assertIn(date(2018, 3, 9), self.holidays) + self.assertIn(date(2018, 7, 26), self.holidays) + self.assertIn(date(2021, 7, 2), self.holidays) + self.assertIn(date(2021, 7, 7), self.holidays) + self.assertIn(date(2021, 8, 12), self.holidays) + self.assertIn(date(2021, 8, 13), self.holidays) + self.assertIn(date(2021, 8, 24), self.holidays) + self.assertIn(date(2022, 3, 18), self.holidays) From 8b98269e50cdc82b3c2956f782cbcc6b895a8ace Mon Sep 17 00:00:00 2001 From: dr-prodigy Date: Sat, 26 Nov 2022 23:24:08 +0100 Subject: [PATCH 029/138] CHANGES sync --- CHANGES | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES b/CHANGES index 2ff44a8c6..333993b40 100644 --- a/CHANGES +++ b/CHANGES @@ -10,6 +10,7 @@ Released ???????? ??, ???? - Korea renamed to South Korea #797 (arkid15r) - Hong Kong optimizations #786 (KJhellico) - Korea fixes #791 (KJhellico) + test optimizations (dr-p) +- Zambia: optimizations and refactoring #798 (KJhellico) Version 0.17.2 ============== From b5ae9ab4cbbdbd0da2729427de2492ebf5d3049f Mon Sep 17 00:00:00 2001 From: ~Jhellico Date: Sun, 27 Nov 2022 00:26:26 +0200 Subject: [PATCH 030/138] Vietnam: optimizations, observed holidays calculation (#799) --- holidays/countries/vietnam.py | 73 +++++++++++++++------------------- test/countries/test_vietnam.py | 38 ++++++++++++++++-- 2 files changed, 66 insertions(+), 45 deletions(-) diff --git a/holidays/countries/vietnam.py b/holidays/countries/vietnam.py index 2d7dddaa8..9d5650b40 100644 --- a/holidays/countries/vietnam.py +++ b/holidays/countries/vietnam.py @@ -17,7 +17,7 @@ # URL: https://github.com/usingsky/korean_lunar_calendar_py/ from korean_lunar_calendar import KoreanLunarCalendar -from holidays.constants import JAN, APR, MAY, SEP, SAT, SUN +from holidays.constants import JAN, APR, MAY, SEP, WEEKEND from holidays.holiday_base import HolidayBase @@ -34,60 +34,51 @@ def __init__(self, **kwargs): self.korean_cal = KoreanLunarCalendar() HolidayBase.__init__(self, **kwargs) + def _add_observed(self, holiday: date) -> None: + if holiday.weekday() in WEEKEND: + next_workday = holiday + rd(days=+1) + while next_workday.weekday() in WEEKEND or self.get(next_workday): + next_workday += rd(days=+1) + self[next_workday] = self[holiday] + " observed" + def _populate(self, year): super()._populate(year) # New Year's Day - name = "International New Year's Day" - first_date = date(year, JAN, 1) - self[first_date] = name - if self.observed: - self[first_date] = name - if first_date.weekday() == SAT: - self[first_date + rd(days=+2)] = name + " observed" - elif first_date.weekday() == SUN: - self[first_date + rd(days=+1)] = name + " observed" - - # Lunar New Year - name = [ - "Vietnamese New Year", # index: 0 - "The second day of Tet Holiday", # index: 1 - "The third day of Tet Holiday", # index: 2 - "The forth day of Tet Holiday", # index: 3 - "The fifth day of Tet Holiday", # index: 4 - "Vietnamese New Year's Eve", # index: -1 - ] - dt = self.get_solar_date(year, 1, 1) - new_year_date = date(dt.year, dt.month, dt.day) - if self.observed: - for i in range(-1, 5, 1): - tet_day = new_year_date + rd(days=+i) - self[tet_day] = name[i] + self[date(year, JAN, 1)] = "International New Year's Day" # Vietnamese Kings' Commemoration Day # https://en.wikipedia.org/wiki/H%C3%B9ng_Kings%27_Festival if year >= 2007: - name = "Hung Kings Commemoration Day" - dt = self.get_solar_date(year, 3, 10) - king_hung_date = date(dt.year, dt.month, dt.day) - self[king_hung_date] = name - else: - pass + hol_date = self.get_solar_date(year, 3, 10) + self[hol_date] = "Hung Kings Commemoration Day" # Liberation Day/Reunification Day - name = "Liberation Day/Reunification Day" - libration_date = date(year, APR, 30) - self[libration_date] = name + self[date(year, APR, 30)] = "Liberation Day/Reunification Day" # International Labor Day - name = "International Labor Day" - labor_date = date(year, MAY, 1) - self[labor_date] = name + self[date(year, MAY, 1)] = "International Labor Day" # Independence Day - name = "Independence Day" - independence_date = date(year, SEP, 2) - self[independence_date] = name + self[date(year, SEP, 2)] = "Independence Day" + + if self.observed: + for dt in sorted(list(self.keys())): + if dt.year == year: + self._add_observed(dt) + + # Lunar New Year + names = ( + (-1, "Vietnamese New Year's Eve"), + (0, "Vietnamese New Year"), + (1, "The second day of Tet Holiday"), + (2, "The third day of Tet Holiday"), + (3, "The forth day of Tet Holiday"), + (4, "The fifth day of Tet Holiday"), + ) + hol_date = self.get_solar_date(year, 1, 1) + for d, name in names: + self[(hol_date + rd(days=+d))] = name # convert lunar calendar date to solar def get_solar_date(self, year, month, day): diff --git a/test/countries/test_vietnam.py b/test/countries/test_vietnam.py index 5c4e88f75..66612c194 100644 --- a/test/countries/test_vietnam.py +++ b/test/countries/test_vietnam.py @@ -33,7 +33,7 @@ def test_first_day_of_january(self): ) def test_lunar_new_year(self): - lunar_new_year_list = [ + for year, month, day in ( (2008, 2, 7), (2009, 1, 26), (2010, 2, 14), @@ -49,8 +49,7 @@ def test_lunar_new_year(self): (2020, 1, 25), (2021, 2, 12), (2022, 2, 1), - ] - for year, month, day in lunar_new_year_list: + ): self.assertEqual( self.holidays[date(year, month, day) + relativedelta(days=-1)], "Vietnamese New Year's Eve", @@ -77,7 +76,7 @@ def test_lunar_new_year(self): ) def test_king_hung_day(self): - for year, month, day in [(2020, 4, 2), (2021, 4, 21), (2022, 4, 10)]: + for year, month, day in ((2020, 4, 2), (2021, 4, 21), (2022, 4, 10)): self.assertEqual( self.holidays[date(year, month, day)], "Hung Kings Commemoration Day", @@ -107,6 +106,37 @@ def test_years_range(self): "International New Year's Day", self.holidays[date(year, 1, 1)] ) + def test_observed(self): + for year, month, day in ( + # International New Year's Day + (2012, 1, 2), + (2017, 1, 2), + (2022, 1, 3), + # Hung Kings Commemoration Day + (2012, 4, 2), + (2016, 4, 18), + (2019, 4, 15), + (2022, 4, 11), + (2023, 5, 2), + # Liberation Day/Reunification Day + (2011, 5, 2), + (2016, 5, 2), + (2017, 5, 2), + (2022, 5, 2), + (2023, 5, 3), + # International Labor Day + (2011, 5, 3), + (2016, 5, 3), + (2021, 5, 3), + (2022, 5, 3), + # Independence Day + (2012, 9, 3), + (2017, 9, 4), + (2018, 9, 3), + (2023, 9, 4), + ): + self.assertIn(date(year, month, day), self.holidays) + def test_not_observed(self): self.holidays = holidays.VN(observed=False) # New Years Day From 1f68db78acd4dba4a9361fb8511067bd1691b60b Mon Sep 17 00:00:00 2001 From: dr-prodigy Date: Sat, 26 Nov 2022 23:27:11 +0100 Subject: [PATCH 031/138] CHANGES sync --- CHANGES | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES b/CHANGES index 333993b40..1024246c9 100644 --- a/CHANGES +++ b/CHANGES @@ -11,6 +11,7 @@ Released ???????? ??, ???? - Hong Kong optimizations #786 (KJhellico) - Korea fixes #791 (KJhellico) + test optimizations (dr-p) - Zambia: optimizations and refactoring #798 (KJhellico) +- Vietnam: optimizations and refactoring #799 (KJhellico) Version 0.17.2 ============== From 2cc3151877b59a0344f7d241ea63515d60ed6d04 Mon Sep 17 00:00:00 2001 From: dr-prodigy Date: Sat, 26 Nov 2022 23:52:22 +0100 Subject: [PATCH 032/138] CHANGES sync --- CHANGES | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES b/CHANGES index 1024246c9..5614e0629 100644 --- a/CHANGES +++ b/CHANGES @@ -3,6 +3,7 @@ Version 0.18 Released ???????? ??, ???? +- Code refactoring #801 (arkid15r) - Pre-commit reviews #786, #795 (KJhellico, arkid15r, dr-p) - Import cleanup, flake8 settings review #792 (arkid15r, KJhellico, dr-p) - Special holidays refactoring for 13 countries #796 (arkid15r, KJhellico) From 2e0c84f53347c36f792b1b57a8915dd91567f7bd Mon Sep 17 00:00:00 2001 From: ~Jhellico Date: Sun, 4 Dec 2022 16:04:09 +0200 Subject: [PATCH 033/138] Uruguay: update holiday names (#809) --- holidays/countries/uruguay.py | 52 ++++++++++++++++++---------------- test/countries/test_uruguay.py | 33 ++++++++++++++------- 2 files changed, 49 insertions(+), 36 deletions(-) diff --git a/holidays/countries/uruguay.py b/holidays/countries/uruguay.py index 940fdc3da..491968a6d 100644 --- a/holidays/countries/uruguay.py +++ b/holidays/countries/uruguay.py @@ -12,16 +12,15 @@ from datetime import date from dateutil.easter import easter -from dateutil.relativedelta import FR, MO, TH, TU, WE +from dateutil.relativedelta import MO, TU, WE, TH, FR from dateutil.relativedelta import relativedelta as rd -from holidays.constants import APR, AUG, DEC, JAN, JUL, JUN, MAY, NOV, OCT +from holidays.constants import JAN, APR, MAY, JUN, JUL, AUG, OCT, NOV, DEC from holidays.holiday_base import HolidayBase class Uruguay(HolidayBase): """ - https://www.ute.com.uy/clientes/tramites-y-servicios/potencia-contratada https://en.wikipedia.org/wiki/Public_holidays_in_Uruguay """ @@ -36,10 +35,14 @@ def _populate(self, year): self[date(year, JAN, 1)] = "Año Nuevo [New Year's Day]" # Día de los Trabajadores. - self[date(year, MAY, 1)] = "Día del Trabajo [Labour Day]" + self[ + date(year, MAY, 1) + ] = "Día de los Trabajadores [International Workers' Day]" # Jura de la Constitución. - self[date(year, JUL, 18)] = "Jura de la constitución" + self[ + date(year, JUL, 18) + ] = "Jura de la Constitución [Constitution Day]" # Declaratoria de la Independencia. self[ @@ -47,49 +50,48 @@ def _populate(self, year): ] = "Día de la Independencia [Independence Day]" # Christmas. - self[date(year, DEC, 25)] = "Navidad [Christmas]" + self[date(year, DEC, 25)] = "Día de la Familia [Day of the Family]" # Partially paid holidays: - # Día de Reyes - Feriado en el cual se conmemora la llegada de - # los reyes magos a Jesus. - self[date(year, JAN, 6)] = "Día de Reyes" + # Día de los Niños. + self[date(year, JAN, 6)] = "Día de los Niños [Children's Day]" - # Natalicio de José Gervacio Artigas. - self[date(year, JUN, 19)] = "Natalicio de José Gervacio Artigas" + # Natalicio de José Gervasio Artigas. + self[date(year, JUN, 19)] = ( + "Natalicio de José Gervasio Artigas " + "[Birthday of José Gervasio Artigas]" + ) # Día de los difuntos. - self[date(year, NOV, 2)] = "Día de los difuntos" + self[date(year, NOV, 2)] = "Día de los Difuntos [All Souls' Day]" # Moveable holidays: + easter_date = easter(year) + # Carnival days # revisar este día para futuros casos name = "Día de Carnaval [Carnival's Day]" - self[easter(year) - rd(days=48)] = name - self[easter(year) - rd(days=47)] = name + self[easter_date + rd(days=-48)] = name + self[easter_date + rd(days=-47)] = name # Holy Week. - self[ - easter(year) + rd(weekday=TH(-1)) - ] = "Semana Santa (Jueves Santo) [Holy day (Holy Thursday)]" - self[ - easter(year) + rd(weekday=FR(-1)) - ] = "Semana Santa (Viernes Santo) [Holy day (Holy Friday)]" + self[easter_date + rd(days=-3)] = "Jueves Santo [Holy Thursday]" + self[easter_date + rd(days=-2)] = "Viernes Santo [Holy Friday]" - self[easter(year)] = "Día de Pascuas [Easter Day]" + self[easter_date] = "Día de Pascuas [Easter Day]" holiday_pairs = ( ( # Desembarco de los 33 Orientales en la playa de la Agraciada. date(year, APR, 19), - "Desembarco de los 33 Orientales Landing of the 33 Orientals " - "Aterrissagem dos 33 Orientais Sbarco dei 33 orientali", + "Desembarco de los 33 Orientales [Landing of the 33 Patriots]", ), ( - # Batalla de las Piedras [Battle of the stones]. + # Batalla de Las Piedras [Battle of Las Piedras]. date(year, MAY, 18), - "Batalla de las Piedras [Battle of the stones]", + "Batalla de Las Piedras [Battle of Las Piedras]", ), ( # "Día del Respeto a la Diversidad Cultural diff --git a/test/countries/test_uruguay.py b/test/countries/test_uruguay.py index 80635edc2..6a01f8e30 100644 --- a/test/countries/test_uruguay.py +++ b/test/countries/test_uruguay.py @@ -47,7 +47,10 @@ def test_labor_day(self): self.assertIn(dt, self.holidays) self.assertNotIn(dt + relativedelta(days=-1), self.holidays) self.assertNotIn(dt + relativedelta(days=+1), self.holidays) - self.assertEqual(self.holidays[dt], "Día del Trabajo [Labour Day]") + self.assertEqual( + self.holidays[dt], + "Día de los Trabajadores [International Workers' Day]", + ) def test_jura_de_la_constitucion_day(self): for year in range(1900, 2100): @@ -55,7 +58,9 @@ def test_jura_de_la_constitucion_day(self): self.assertIn(dt, self.holidays) self.assertNotIn(dt + relativedelta(days=-1), self.holidays) self.assertNotIn(dt + relativedelta(days=+1), self.holidays) - self.assertEqual(self.holidays[dt], "Jura de la constitución") + self.assertEqual( + self.holidays[dt], "Jura de la Constitución [Constitution Day]" + ) def test_declaratoria_de_la_independencia_day(self): for year in range(1900, 2100): @@ -73,7 +78,9 @@ def test_christmas(self): self.assertIn(dt, self.holidays) self.assertNotIn(dt + relativedelta(days=-1), self.holidays) self.assertNotIn(dt + relativedelta(days=+1), self.holidays) - self.assertEqual(self.holidays[dt], "Navidad [Christmas]") + self.assertEqual( + self.holidays[dt], "Día de la Familia [Day of the Family]" + ) # Partially paid holidays. @@ -82,7 +89,9 @@ def test_dia_de_reyes(self): for year in range(1900, 2100): dt = date(year, 1, 6) self.assertIn(dt, self.holidays) - self.assertEqual(self.holidays[dt], "Día de Reyes") + self.assertEqual( + self.holidays[dt], "Día de los Niños [Children's Day]" + ) def test_natalicio_artigas_day(self): for year in range(1900, 2100): @@ -92,7 +101,8 @@ def test_natalicio_artigas_day(self): self.assertNotIn(dt + relativedelta(days=+1), self.holidays) self.assertEqual( self.holidays[dt], - "Natalicio de José Gervacio Artigas", + "Natalicio de José Gervasio Artigas " + "[Birthday of José Gervasio Artigas]", ) def test_dia_de_los_difuntos_day(self): @@ -101,7 +111,9 @@ def test_dia_de_los_difuntos_day(self): self.assertIn(dt, self.holidays) self.assertNotIn(dt + relativedelta(days=-1), self.holidays) self.assertNotIn(dt + relativedelta(days=+1), self.holidays) - self.assertEqual(self.holidays[dt], "Día de los difuntos") + self.assertEqual( + self.holidays[dt], "Día de los Difuntos [All Souls' Day]" + ) # Moveable holidays. @@ -125,11 +137,11 @@ def test_holy_week_day(self): for dt in ( ( date(2021, 4, 1), - "Semana Santa (Jueves Santo) [Holy day (Holy Thursday)]", + "Jueves Santo [Holy Thursday]", ), ( date(2021, 4, 2), - "Semana Santa (Viernes Santo) [Holy day (Holy Friday)]", + "Viernes Santo [Holy Friday]", ), (date(2021, 4, 4), "Día de Pascuas [Easter Day]"), ): @@ -147,8 +159,7 @@ def test_desembarco_de_los_33_orientales(self): self.assertIn(dt, self.holidays) self.assertEqual( self.holidays[dt], - "Desembarco de los 33 Orientales Landing of the 33 Orientals " - "Aterrissagem dos 33 Orientais Sbarco dei 33 orientali", + "Desembarco de los 33 Orientales [Landing of the 33 Patriots]", ) def test_batalla_de_las_piedras_day(self): @@ -162,7 +173,7 @@ def test_batalla_de_las_piedras_day(self): self.assertIn(dt, self.holidays) self.assertEqual( self.holidays[dt], - "Batalla de las Piedras [Battle of the stones]", + "Batalla de Las Piedras [Battle of Las Piedras]", ) def test_dia_del_respeto_a_la_diversidad_cultural(self): From 333c63756b220690fba4d04ba92f0978d148691a Mon Sep 17 00:00:00 2001 From: ~Jhellico Date: Sun, 4 Dec 2022 16:08:07 +0200 Subject: [PATCH 034/138] Easter related holidays refactoring and unification (#803) --- holidays/countries/argentina.py | 14 +++++------ holidays/countries/aruba.py | 10 ++++---- holidays/countries/australia.py | 11 +++++---- holidays/countries/austria.py | 10 ++++---- holidays/countries/belgium.py | 8 +++---- holidays/countries/bolivia.py | 12 +++++----- holidays/countries/bosnia_and_herzegovina.py | 25 ++++++++------------ holidays/countries/botswana.py | 15 ++++-------- holidays/countries/brazil.py | 13 +++++----- holidays/countries/bulgaria.py | 12 +++++----- holidays/countries/canada.py | 7 +++--- holidays/countries/chile.py | 9 +++---- holidays/countries/colombia.py | 8 +++---- holidays/countries/croatia.py | 7 +++--- holidays/countries/cuba.py | 2 +- holidays/countries/curacao.py | 10 ++++---- holidays/countries/cyprus.py | 14 +++++------ holidays/countries/czechia.py | 6 ++--- holidays/countries/denmark.py | 20 ++++++++-------- holidays/countries/dominican_republic.py | 4 ++-- holidays/countries/egypt.py | 7 +++--- holidays/countries/estonia.py | 8 +++---- holidays/countries/eswatini.py | 11 ++++----- holidays/countries/ethiopia.py | 7 +++--- holidays/countries/finland.py | 12 +++++----- holidays/countries/france.py | 10 ++++---- holidays/countries/georgia.py | 11 +++++---- holidays/countries/germany.py | 16 +++++++------ holidays/countries/greece.py | 10 ++++---- holidays/countries/honduras.py | 13 ++++------ holidays/countries/hungary.py | 9 ++++--- holidays/countries/iceland.py | 17 ++++++------- holidays/countries/ireland.py | 2 +- holidays/countries/italy.py | 9 +++---- holidays/countries/jamaica.py | 11 +++++---- holidays/countries/kenya.py | 6 ++--- holidays/countries/latvia.py | 5 ++-- holidays/countries/lesotho.py | 12 ++++------ holidays/countries/liechtenstein.py | 17 ++++++------- holidays/countries/lithuania.py | 2 +- holidays/countries/luxembourg.py | 8 +++---- holidays/countries/madagascar.py | 13 +++++----- holidays/countries/malawi.py | 10 ++++---- holidays/countries/malaysia.py | 2 +- holidays/countries/malta.py | 4 +--- holidays/countries/moldova.py | 8 +++---- holidays/countries/mozambique.py | 8 +++---- holidays/countries/namibia.py | 12 ++++------ holidays/countries/netherlands.py | 11 ++++----- holidays/countries/new_zealand.py | 9 +++---- holidays/countries/nicaragua.py | 8 +++---- holidays/countries/nigeria.py | 10 +++----- holidays/countries/north_macedonia.py | 6 ++--- holidays/countries/norway.py | 16 ++++++------- holidays/countries/paraguay.py | 12 +++++----- holidays/countries/peru.py | 16 ++++--------- holidays/countries/poland.py | 10 ++++---- holidays/countries/portugal.py | 15 ++++++------ holidays/countries/romania.py | 14 +++++------ holidays/countries/serbia.py | 19 ++++++--------- holidays/countries/singapore.py | 15 ++++++------ holidays/countries/slovakia.py | 6 ++--- holidays/countries/slovenia.py | 3 +-- holidays/countries/south_africa.py | 14 +++++------ holidays/countries/spain.py | 13 +++++----- holidays/countries/sweden.py | 14 +++++------ holidays/countries/switzerland.py | 17 ++++++------- holidays/countries/ukraine.py | 8 +++---- holidays/countries/united_kingdom.py | 7 +++--- holidays/countries/united_states.py | 9 +++---- holidays/countries/venezuela.py | 9 +++---- holidays/countries/zambia.py | 2 +- holidays/countries/zimbabwe.py | 11 ++++----- test/countries/test_uruguay.py | 6 ++--- 74 files changed, 360 insertions(+), 397 deletions(-) diff --git a/holidays/countries/argentina.py b/holidays/countries/argentina.py index b050cb9c8..4eb617000 100644 --- a/holidays/countries/argentina.py +++ b/holidays/countries/argentina.py @@ -13,7 +13,6 @@ from dateutil.easter import easter from dateutil.relativedelta import relativedelta as rd -from dateutil.relativedelta import TH, FR from holidays.constants import ( WEEKEND, @@ -50,10 +49,11 @@ def _populate(self, year): else: self[date(year, JAN, 1)] = "Año Nuevo [New Year's Day]" + easter_date = easter(year) # Carnival days name = "Día de Carnaval [Carnival's Day]" - self[easter(year) - rd(days=48)] = name - self[easter(year) - rd(days=47)] = name + self[easter_date + rd(days=-48)] = name + self[easter_date + rd(days=-47)] = name # Memory's National Day for the Truth and Justice name = ( @@ -71,13 +71,13 @@ def _populate(self, year): name_fri = "Semana Santa (Viernes Santo) [Holy day (Holy Friday)]" name_easter = "Día de Pascuas [Easter Day]" - self[easter(year) + rd(weekday=TH(-1))] = name_thu - self[easter(year) + rd(weekday=FR(-1))] = name_fri + self[easter_date + rd(days=-3)] = name_thu + self[easter_date + rd(days=-2)] = name_fri - if not self.observed and easter(year).weekday() in WEEKEND: + if not self.observed and easter_date.weekday() in WEEKEND: pass else: - self[easter(year)] = name_easter + self[easter_date] = name_easter # Veterans Day and the Fallen in the Malvinas War if not self.observed and date(year, APR, 2).weekday() in WEEKEND: diff --git a/holidays/countries/aruba.py b/holidays/countries/aruba.py index ae75822ba..86cb80b5f 100644 --- a/holidays/countries/aruba.py +++ b/holidays/countries/aruba.py @@ -13,7 +13,6 @@ from dateutil.easter import easter from dateutil.relativedelta import relativedelta as rd -from dateutil.relativedelta import FR from holidays.constants import JAN, MAR, APR, MAY, AUG, DEC from holidays.holiday_base import HolidayBase @@ -36,9 +35,10 @@ def _populate(self, year): # Dia di Betico self[date(year, JAN, 25)] = "Dia Di Betico [Betico Day]" + easter_date = easter(year) # Carnaval Monday self[ - easter(year) + rd(days=-48) + easter_date + rd(days=-48) ] = "Dialuna di Carnaval [Carnaval Monday]" # Dia di Himno y Bandera @@ -47,11 +47,11 @@ def _populate(self, year): ] = "Dia di Himno y Bandera [National Anthem & Flag Day]" # Good Friday - self[easter(year) + rd(weekday=FR(-1))] = "Bierna Santo [Good Friday]" + self[easter_date + rd(days=-2)] = "Bierna Santo [Good Friday]" # Easter Monday self[ - easter(year) + rd(days=1) + easter_date + rd(days=+1) ] = "Di Dos Dia di Pasco di Resureccion [Easter Monday]" # King's Day @@ -80,7 +80,7 @@ def _populate(self, year): self[date(year, MAY, 1)] = "Dia di Obrero [Labour Day]" # Ascension Day - self[easter(year) + rd(days=39)] = "Dia di Asuncion [Ascension Day]" + self[easter_date + rd(days=+39)] = "Dia di Asuncion [Ascension Day]" # Christmas Day self[date(year, DEC, 25)] = "Pasco di Nacemento [Christmas]" diff --git a/holidays/countries/australia.py b/holidays/countries/australia.py index 762ff4ee3..eb4a600e5 100644 --- a/holidays/countries/australia.py +++ b/holidays/countries/australia.py @@ -13,7 +13,7 @@ from dateutil.easter import easter from dateutil.relativedelta import relativedelta as rd -from dateutil.relativedelta import MO, TU, WE, FR, SA +from dateutil.relativedelta import MO, TU, WE, FR from holidays.constants import ( SAT, @@ -106,12 +106,13 @@ def _populate(self, year): self[date(year, MAR, 12)] = name # Easter - self[easter(year) + rd(weekday=FR(-1))] = "Good Friday" + easter_date = easter(year) + self[easter_date + rd(days=-2)] = "Good Friday" if self.subdiv in {"ACT", "NSW", "NT", "QLD", "SA", "VIC"}: - self[easter(year) + rd(weekday=SA(-1))] = "Easter Saturday" + self[easter_date + rd(days=-1)] = "Easter Saturday" if self.subdiv in {"ACT", "NSW", "QLD", "VIC"}: - self[easter(year)] = "Easter Sunday" - self[easter(year) + rd(weekday=MO)] = "Easter Monday" + self[easter_date] = "Easter Sunday" + self[easter_date + rd(days=+1)] = "Easter Monday" # Anzac Day if year > 1920: diff --git a/holidays/countries/austria.py b/holidays/countries/austria.py index 7b2d320b2..8fb2bcfe7 100644 --- a/holidays/countries/austria.py +++ b/holidays/countries/austria.py @@ -13,7 +13,6 @@ from dateutil.easter import easter from dateutil.relativedelta import relativedelta as rd -from dateutil.relativedelta import MO from holidays.constants import JAN, MAY, AUG, OCT, NOV, DEC from holidays.holiday_base import HolidayBase @@ -37,11 +36,12 @@ def _populate(self, year): # public holidays self[date(year, JAN, 1)] = "Neujahr" self[date(year, JAN, 6)] = "Heilige Drei Könige" - self[easter(year) + rd(weekday=MO)] = "Ostermontag" + easter_date = easter(year) + self[easter_date + rd(days=+1)] = "Ostermontag" self[date(year, MAY, 1)] = "Staatsfeiertag" - self[easter(year) + rd(days=39)] = "Christi Himmelfahrt" - self[easter(year) + rd(days=50)] = "Pfingstmontag" - self[easter(year) + rd(days=60)] = "Fronleichnam" + self[easter_date + rd(days=+39)] = "Christi Himmelfahrt" + self[easter_date + rd(days=+50)] = "Pfingstmontag" + self[easter_date + rd(days=+60)] = "Fronleichnam" self[date(year, AUG, 15)] = "Mariä Himmelfahrt" if 1919 <= year <= 1934: self[date(year, NOV, 12)] = "Nationalfeiertag" diff --git a/holidays/countries/belgium.py b/holidays/countries/belgium.py index 57254427e..bfcb0efb9 100644 --- a/holidays/countries/belgium.py +++ b/holidays/countries/belgium.py @@ -38,16 +38,16 @@ def _populate(self, year): self[easter_date] = "Pasen" # Second easter day - self[easter_date + rd(days=1)] = "Paasmaandag" + self[easter_date + rd(days=+1)] = "Paasmaandag" # Ascension day - self[easter_date + rd(days=39)] = "O.L.H. Hemelvaart" + self[easter_date + rd(days=+39)] = "O.L.H. Hemelvaart" # Pentecost - self[easter_date + rd(days=49)] = "Pinksteren" + self[easter_date + rd(days=+49)] = "Pinksteren" # Pentecost monday - self[easter_date + rd(days=50)] = "Pinkstermaandag" + self[easter_date + rd(days=+50)] = "Pinkstermaandag" # International Workers' Day self[date(year, MAY, 1)] = "Dag van de Arbeid" diff --git a/holidays/countries/bolivia.py b/holidays/countries/bolivia.py index 79fb4bd00..034f04bef 100644 --- a/holidays/countries/bolivia.py +++ b/holidays/countries/bolivia.py @@ -13,7 +13,6 @@ from datetime import date from dateutil.easter import easter -from dateutil.relativedelta import FR from dateutil.relativedelta import relativedelta as rd from holidays.constants import ( @@ -69,7 +68,8 @@ def _populate(self, year): ] = "Nacimiento del Estado Plurinacional de Bolivia" # Good Friday. - self[easter(year) + rd(weekday=FR(-1))] = "Viernes Santo" + easter_date = easter(year) + self[easter_date + rd(days=-2)] = "Viernes Santo" # La Tablada. if self.subdiv == "T": @@ -77,12 +77,12 @@ def _populate(self, year): # Carnival in Oruro. if self.subdiv == "O": - self[easter(year) + rd(days=-51)] = "Carnaval de Oruro" + self[easter_date + rd(days=-51)] = "Carnaval de Oruro" # Carnival Monday (Observed on Tuesday). name = "Feriado por Carnaval" - self[easter(year) + rd(days=-48)] = name - self[easter(year) + rd(days=-47)] = f"{name} (Observed)" + self[easter_date + rd(days=-48)] = name + self[easter_date + rd(days=-47)] = f"{name} (Observed)" # Labor Day. name = "Dia del trabajo" @@ -96,7 +96,7 @@ def _populate(self, year): self[date(year, MAY, 25)] = "Día del departamento de Chuquisaca" # Corpus Christi. - self[easter(year) + rd(days=+60)] = "Corpus Christi" + self[easter_date + rd(days=+60)] = "Corpus Christi" # Andean New Year. name = "Año Nuevo Andino" diff --git a/holidays/countries/bosnia_and_herzegovina.py b/holidays/countries/bosnia_and_herzegovina.py index 31062236e..c7a418e07 100644 --- a/holidays/countries/bosnia_and_herzegovina.py +++ b/holidays/countries/bosnia_and_herzegovina.py @@ -12,8 +12,7 @@ from datetime import date -from dateutil.easter import easter -from dateutil.relativedelta import FR, MO +from dateutil.easter import easter, EASTER_ORTHODOX from dateutil.relativedelta import relativedelta as rd from holidays.constants import DEC, JAN, JUN, MAR, MAY, NOV, SUN @@ -56,20 +55,17 @@ def _populate(self, year): # Independence Day. self[date(year, MAR, 1)] = "Dan nezavisnosti" + easter_date = easter(year) # Catholic Good Friday. - self[ - easter(year) + rd(weekday=FR(-1)) - ] = "Veliki Petak (Katolički)" + self[easter_date + rd(days=-2)] = "Veliki Petak (Katolički)" # Catholic Easter. - self[easter(year)] = "Uskrs (Katolički)" - self[ - easter(year) + rd(weekday=MO(+1)) - ] = "Uskrsni ponedjeljak (Katolički)" + self[easter_date] = "Uskrs (Katolički)" + self[easter_date + rd(days=+1)] = "Uskrsni ponedjeljak (Katolički)" # Corpus Cristi. self[ - easter(year) + rd(days=+60) + easter_date + rd(days=+60) ] = "Tijelovo (Tijelo i Krv Kristova)" # Eid al-Fitr. @@ -118,15 +114,14 @@ def _populate(self, year): # Orthodox New Year. self[date(year, JAN, 14)] = "Pravoslavna Nova Godina" + easter_date = easter(year, method=EASTER_ORTHODOX) # Orthodox Good Friday. - self[ - easter(year, method=2) + rd(weekday=FR(-1)) - ] = "Veliki Petak (Pravoslavni)" + self[easter_date + rd(days=-2)] = "Veliki Petak (Pravoslavni)" # Orthodox Easter. - self[easter(year, method=2)] = "Vaskrs (Pravoslavni)" + self[easter_date] = "Vaskrs (Pravoslavni)" self[ - easter(year, method=2) + rd(weekday=MO(+1)) + easter_date + rd(days=+1) ] = "Uskrsni ponedjeljak (Pravoslavni)" # Victory Day. diff --git a/holidays/countries/botswana.py b/holidays/countries/botswana.py index c852062c3..807813c67 100644 --- a/holidays/countries/botswana.py +++ b/holidays/countries/botswana.py @@ -38,18 +38,13 @@ def _populate(self, year: int): self[date(year, JAN, 2)] = "New Year's Day Holiday" # Easter and easter related calculations - e = easter(year) - good_friday = e - rd(days=2) - easter_saturday = e - rd(days=1) - easter_monday = e + rd(days=1) - - self[good_friday] = "Good Friday" - self[easter_saturday] = "Holy Saturday" - self[easter_monday] = "Easter Monday" + easter_date = easter(year) + self[easter_date + rd(days=-2)] = "Good Friday" + self[easter_date + rd(days=-1)] = "Holy Saturday" + self[easter_date + rd(days=+1)] = "Easter Monday" self[date(year, MAY, 1)] = "Labour Day" - ascension_day = e + rd(days=39) - self[ascension_day] = "Ascension Day" + self[easter_date + rd(days=+39)] = "Ascension Day" self[date(year, JUL, 1)] = "Sir Seretse Khama Day" diff --git a/holidays/countries/brazil.py b/holidays/countries/brazil.py index 2fac479f8..646ed06d9 100644 --- a/holidays/countries/brazil.py +++ b/holidays/countries/brazil.py @@ -12,7 +12,7 @@ from datetime import date from dateutil.easter import easter -from dateutil.relativedelta import SU, TU +from dateutil.relativedelta import SU from dateutil.relativedelta import relativedelta as rd from holidays.constants import ( @@ -89,16 +89,17 @@ def _populate(self, year): # Christmas Day self[date(year, DEC, 25)] = "Natal" - self[easter(year) - rd(days=2)] = "Sexta-feira Santa" + easter_date = easter(year) + self[easter_date + rd(days=-2)] = "Sexta-feira Santa" - self[easter(year)] = "Páscoa" + self[easter_date] = "Páscoa" - self[easter(year) + rd(days=60)] = "Corpus Christi" + self[easter_date + rd(days=+60)] = "Corpus Christi" - quaresma = easter(year) - rd(days=46) + quaresma = easter_date + rd(days=-46) self[quaresma] = "Quarta-feira de cinzas (Início da Quaresma)" - self[quaresma - rd(weekday=TU(-1))] = "Carnaval" + self[quaresma + rd(days=-1)] = "Carnaval" if self.subdiv == "AC": self[date(year, JAN, 23)] = "Dia do evangélico" diff --git a/holidays/countries/bulgaria.py b/holidays/countries/bulgaria.py index 85e2e522d..bfa0cf006 100644 --- a/holidays/countries/bulgaria.py +++ b/holidays/countries/bulgaria.py @@ -11,7 +11,7 @@ from datetime import date -from dateutil.easter import EASTER_ORTHODOX, easter +from dateutil.easter import easter, EASTER_ORTHODOX from dateutil.relativedelta import relativedelta as rd from holidays.constants import JAN, MAR, MAY, SEP, NOV, DEC @@ -86,11 +86,11 @@ def _populate(self, year): self[date(year, DEC, 26)] = "Рождество Христово" # Easter - dt = easter(year, method=EASTER_ORTHODOX) - self[dt - rd(days=2)] = "Велики петък" - self[dt - rd(days=1)] = "Велика събота" - self[dt] = "Великден" - self[dt + rd(days=1)] = " Великден" + easter_date = easter(year, method=EASTER_ORTHODOX) + self[easter_date + rd(days=-2)] = "Велики петък" + self[easter_date + rd(days=-1)] = "Велика събота" + self[easter_date] = "Великден" + self[easter_date + rd(days=+1)] = "Великден" class BG(Bulgaria): diff --git a/holidays/countries/canada.py b/holidays/countries/canada.py index 04d601591..9c4102aac 100644 --- a/holidays/countries/canada.py +++ b/holidays/countries/canada.py @@ -13,7 +13,7 @@ from dateutil.easter import easter from dateutil.relativedelta import relativedelta as rd -from dateutil.relativedelta import MO, FR, SU +from dateutil.relativedelta import MO, SU from holidays.constants import ( FRI, @@ -128,10 +128,11 @@ def _populate(self, year): dt = self._get_nearest_monday(date(year, MAR, 17)) self[dt] = "St. Patrick's Day" + easter_date = easter(year) # Good Friday - self[easter(year) + rd(weekday=FR(-1))] = "Good Friday" + self[easter_date + rd(days=-2)] = "Good Friday" # Easter Monday - self[easter(year) + rd(weekday=MO)] = "Easter Monday" + self[easter_date + rd(days=+1)] = "Easter Monday" # St. George's Day if self.subdiv == "NL" and year >= 1990: diff --git a/holidays/countries/chile.py b/holidays/countries/chile.py index d52ea7735..d4eecb98f 100644 --- a/holidays/countries/chile.py +++ b/holidays/countries/chile.py @@ -13,7 +13,7 @@ from dateutil.easter import easter from dateutil.relativedelta import relativedelta as rd -from dateutil.relativedelta import MO, FR, SA +from dateutil.relativedelta import MO from holidays.constants import ( TUE, @@ -77,9 +77,10 @@ def _populate(self, year): name_sat = "Semana Santa (Sábado Santo) [Good Saturday)]" name_easter = "Día de Pascuas [Easter Day]" - self[easter(year) + rd(weekday=FR(-1))] = name_fri - self[easter(year) + rd(weekday=SA(-1))] = name_sat - self[easter(year)] = name_easter + easter_date = easter(year) + self[easter_date + rd(days=-2)] = name_fri + self[easter_date + rd(days=-1)] = name_sat + self[easter_date] = name_easter # Labor Day (Law 2.200, renamed with Law 18.018) name = "Día Nacional del Trabajo [Labour Day]" diff --git a/holidays/countries/colombia.py b/holidays/countries/colombia.py index 5f1397c17..e830a76e3 100644 --- a/holidays/countries/colombia.py +++ b/holidays/countries/colombia.py @@ -13,7 +13,7 @@ from dateutil.easter import easter from dateutil.relativedelta import relativedelta as rd -from dateutil.relativedelta import MO, TH, FR +from dateutil.relativedelta import MO from holidays.constants import MON, JAN, MAR, MAY, JUN, JUL, AUG, OCT, NOV, DEC from holidays.holiday_base import HolidayBase @@ -149,12 +149,10 @@ def _add_easter_based_holidays(self, year): def _add_fixed_easter_based_holidays(self, _easter): if _easter.year > 1950: # Maundy Thursday - self[ - _easter + rd(weekday=TH(-1)) - ] = "Jueves Santo [Maundy Thursday]" + self[_easter + rd(days=-3)] = "Jueves Santo [Maundy Thursday]" # Good Friday - self[_easter + rd(weekday=FR(-1))] = "Viernes Santo [Good Friday]" + self[_easter + rd(days=-2)] = "Viernes Santo [Good Friday]" def _add_flexible_easter_based_holidays(self, _easter): if _easter.year > 1950: diff --git a/holidays/countries/croatia.py b/holidays/countries/croatia.py index fbb93150d..137f0c139 100644 --- a/holidays/countries/croatia.py +++ b/holidays/countries/croatia.py @@ -9,9 +9,10 @@ # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) -from datetime import date, timedelta +from datetime import date from dateutil.easter import easter +from dateutil.relativedelta import relativedelta as rd from holidays.constants import JAN, MAY, JUN, AUG, OCT, NOV, DEC from holidays.holiday_base import HolidayBase @@ -39,10 +40,10 @@ def _populate(self, year): # Easter self[easter_date] = "Uskrs" # Easter Monday - self[easter_date + timedelta(days=1)] = "Uskrsni ponedjeljak" + self[easter_date + rd(days=+1)] = "Uskrsni ponedjeljak" # Corpus Christi - self[easter_date + timedelta(days=60)] = "Tijelovo" + self[easter_date + rd(days=+60)] = "Tijelovo" # International Workers' Day self[date(year, MAY, 1)] = "Međunarodni praznik rada" diff --git a/holidays/countries/cuba.py b/holidays/countries/cuba.py index dc66eba78..5bbe999fb 100644 --- a/holidays/countries/cuba.py +++ b/holidays/countries/cuba.py @@ -57,7 +57,7 @@ def _populate(self, year): # https://bit.ly/3v6bM18 # Permanently granted in 2013 decree for 2014 and onwards. if year >= 2012: - self[easter(year) - rd(days=2)] = "Viernes Santo [Good Friday]" + self[easter(year) + rd(days=-2)] = "Viernes Santo [Good Friday]" name = "Día Internacional de los Trabajadores [Labour Day]" self[date(year, MAY, 1)] = name diff --git a/holidays/countries/curacao.py b/holidays/countries/curacao.py index 159935d09..cf155a820 100644 --- a/holidays/countries/curacao.py +++ b/holidays/countries/curacao.py @@ -13,7 +13,6 @@ from dateutil.easter import easter from dateutil.relativedelta import relativedelta as rd -from dateutil.relativedelta import FR from holidays.constants import JAN, APR, MAY, JUL, AUG, OCT, DEC from holidays.holiday_base import HolidayBase @@ -32,17 +31,18 @@ def _populate(self, year): # New Year's Day self[date(year, JAN, 1)] = "Nieuwjaarsdag [New Year's Day]" + easter_date = easter(year) # Carnaval Monday self[ - easter(year) + rd(days=-48) + easter_date + rd(days=-48) ] = "Maandag na de Grote Karnaval [Carnaval Monday]" # Good Friday - self[easter(year) + rd(weekday=FR(-1))] = "Goede Vrijdag [Good Friday]" + self[easter_date + rd(days=-2)] = "Goede Vrijdag [Good Friday]" # Easter Monday self[ - easter(year) + rd(days=1) + easter_date + rd(days=+1) ] = "Di Dos Dia di Pasku di Resureccion [Easter Monday]" # King's Day @@ -74,7 +74,7 @@ def _populate(self, year): self[labour_day] = "Dia di Obrero [Labour Day]" # Ascension Day - self[easter(year) + rd(days=39)] = "Hemelvaartsdag [Ascension Day]" + self[easter_date + rd(days=+39)] = "Hemelvaartsdag [Ascension Day]" # Dia di Himno y Bandera self[ diff --git a/holidays/countries/cyprus.py b/holidays/countries/cyprus.py index 1aa173c81..0c3412e4b 100644 --- a/holidays/countries/cyprus.py +++ b/holidays/countries/cyprus.py @@ -11,7 +11,7 @@ from datetime import date -from dateutil.easter import EASTER_ORTHODOX, easter +from dateutil.easter import easter, EASTER_ORTHODOX from dateutil.relativedelta import relativedelta as rd from holidays.constants import JAN, MAR, APR, MAY, AUG, OCT, DEC @@ -28,7 +28,7 @@ class Cyprus(HolidayBase): def _populate(self, year): super()._populate(year) - eday = easter(year, method=EASTER_ORTHODOX) + easter_date = easter(year, method=EASTER_ORTHODOX) # New Years self[date(year, JAN, 1)] = "Πρωτοχρονιά [New Year's Day]" @@ -37,7 +37,7 @@ def _populate(self, year): self[date(year, JAN, 6)] = "Θεοφάνεια [Epiphany]" # Clean Monday - self[eday - rd(days=48)] = "Καθαρά Δευτέρα [Clean Monday]" + self[easter_date + rd(days=-48)] = "Καθαρά Δευτέρα [Clean Monday]" # Greek Independence Day self[ @@ -48,20 +48,20 @@ def _populate(self, year): self[date(year, APR, 1)] = "1η Απριλίου [Cyprus National Day]" # Good Friday - self[eday - rd(days=2)] = "Μεγάλη Παρασκευή [Good Friday]" + self[easter_date + rd(days=-2)] = "Μεγάλη Παρασκευή [Good Friday]" # Easter Sunday - self[eday] = "Κυριακή του Πάσχα [Easter Sunday]" + self[easter_date] = "Κυριακή του Πάσχα [Easter Sunday]" # Easter Monday - self[eday + rd(days=1)] = "Δευτέρα του Πάσχα [Easter Monday]" + self[easter_date + rd(days=+1)] = "Δευτέρα του Πάσχα [Easter Monday]" # Labour Day self[date(year, MAY, 1)] = "Εργατική Πρωτομαγιά [Labour day]" # Monday of the Holy Spirit self[ - eday + rd(days=50) + easter_date + rd(days=+50) ] = "Δευτέρα του Αγίου Πνεύματος [Monday of the Holy Spirit]" # Assumption of Mary diff --git a/holidays/countries/czechia.py b/holidays/countries/czechia.py index aabcc7b83..90ee108ad 100644 --- a/holidays/countries/czechia.py +++ b/holidays/countries/czechia.py @@ -34,10 +34,10 @@ def _populate(self, year): else "Nový rok" ) - e = easter(year) + easter_date = easter(year) if year <= 1951 or year >= 2016: - self[e - rd(days=2)] = "Velký pátek" - self[e + rd(days=1)] = "Velikonoční pondělí" + self[easter_date + rd(days=-2)] = "Velký pátek" + self[easter_date + rd(days=+1)] = "Velikonoční pondělí" if year >= 1951: self[date(year, MAY, 1)] = "Svátek práce" diff --git a/holidays/countries/denmark.py b/holidays/countries/denmark.py index b1a224ef5..df0ebcac8 100644 --- a/holidays/countries/denmark.py +++ b/holidays/countries/denmark.py @@ -13,7 +13,6 @@ from dateutil.easter import easter from dateutil.relativedelta import relativedelta as rd -from dateutil.relativedelta import MO, TH, FR, SU from holidays.constants import JAN, DEC from holidays.holiday_base import HolidayBase @@ -29,17 +28,18 @@ class Denmark(HolidayBase): def _populate(self, year): super()._populate(year) + easter_date = easter(year) # Public holidays self[date(year, JAN, 1)] = "Nytårsdag" - self[easter(year) + rd(weekday=SU(-2))] = "Palmesøndag" - self[easter(year) + rd(weekday=TH(-1))] = "Skærtorsdag" - self[easter(year) + rd(weekday=FR(-1))] = "Langfredag" - self[easter(year)] = "Påskedag" - self[easter(year) + rd(weekday=MO)] = "Anden påskedag" - self[easter(year) + rd(weekday=FR(+4))] = "Store bededag" - self[easter(year) + rd(days=39)] = "Kristi himmelfartsdag" - self[easter(year) + rd(days=49)] = "Pinsedag" - self[easter(year) + rd(days=50)] = "Anden pinsedag" + self[easter_date + rd(days=-7)] = "Palmesøndag" + self[easter_date + rd(days=-3)] = "Skærtorsdag" + self[easter_date + rd(days=-2)] = "Langfredag" + self[easter_date] = "Påskedag" + self[easter_date + rd(days=+1)] = "Anden påskedag" + self[easter_date + rd(days=+26)] = "Store bededag" + self[easter_date + rd(days=+39)] = "Kristi himmelfartsdag" + self[easter_date + rd(days=+49)] = "Pinsedag" + self[easter_date + rd(days=+50)] = "Anden pinsedag" self[date(year, DEC, 25)] = "Juledag" self[date(year, DEC, 26)] = "Anden juledag" diff --git a/holidays/countries/dominican_republic.py b/holidays/countries/dominican_republic.py index e592a1042..3d63a0dc3 100644 --- a/holidays/countries/dominican_republic.py +++ b/holidays/countries/dominican_republic.py @@ -13,7 +13,7 @@ from dateutil.easter import easter from dateutil.relativedelta import relativedelta as rd -from dateutil.relativedelta import MO, FR +from dateutil.relativedelta import MO from holidays.constants import TUE, WED, JAN, FEB, MAY, JUN, AUG, SEP, NOV, DEC from holidays.holiday_base import HolidayBase @@ -58,7 +58,7 @@ def _populate(self, year): self[date(year, FEB, 27)] = "Día de Independencia [Independence Day]" # Good Friday - self[easter(year) + rd(weekday=FR(-1))] = "Viernes Santo [Good Friday]" + self[easter(year) + rd(days=-2)] = "Viernes Santo [Good Friday]" # Labor Day labor_day = self.__change_day_by_law(date(year, MAY, 1), (3, 4, 6)) diff --git a/holidays/countries/egypt.py b/holidays/countries/egypt.py index 572bea602..1d4689311 100644 --- a/holidays/countries/egypt.py +++ b/holidays/countries/egypt.py @@ -11,7 +11,7 @@ from datetime import date -from dateutil.easter import easter +from dateutil.easter import easter, EASTER_ORTHODOX from dateutil.relativedelta import relativedelta as rd from holidays.constants import FRI, SAT, JAN, APR, MAY, JUN, JUL, OCT @@ -77,10 +77,11 @@ def _add_holiday(dt: date, hol: str) -> None: pass # Coptic Easter - Orthodox Easter - self[easter(year, 2)] = "Coptic Easter Sunday" + easter_date = easter(year, EASTER_ORTHODOX) + self[easter_date] = "Coptic Easter Sunday" # Sham El Nessim - Spring Festival - self[easter(year, 2) + rd(days=1)] = "Sham El Nessim" + self[easter_date + rd(days=+1)] = "Sham El Nessim" # Sinai Libration Day if year > 1982: diff --git a/holidays/countries/estonia.py b/holidays/countries/estonia.py index 47bfe1338..af04edb91 100644 --- a/holidays/countries/estonia.py +++ b/holidays/countries/estonia.py @@ -25,7 +25,7 @@ class Estonia(HolidayBase): def _populate(self, year): super()._populate(year) - e = easter(year) + easter_date = easter(year) # New Year's Day self[date(year, JAN, 1)] = "uusaasta" @@ -34,16 +34,16 @@ def _populate(self, year): self[date(year, FEB, 24)] = "iseseisvuspäev" # Good Friday - self[e - rd(days=2)] = "suur reede" + self[easter_date + rd(days=-2)] = "suur reede" # Easter Sunday - self[e] = "ülestõusmispühade 1. püha" + self[easter_date] = "ülestõusmispühade 1. püha" # Spring Day self[date(year, MAY, 1)] = "kevadpüha" # Pentecost - self[e + rd(days=49)] = "nelipühade 1. püha" + self[easter_date + rd(days=+49)] = "nelipühade 1. püha" # Victory Day self[date(year, JUN, 23)] = "võidupüha" diff --git a/holidays/countries/eswatini.py b/holidays/countries/eswatini.py index 87a8e82b5..28c4e4f6c 100644 --- a/holidays/countries/eswatini.py +++ b/holidays/countries/eswatini.py @@ -39,13 +39,10 @@ def _populate(self, year): if year > 1938: self[date(year, JAN, 1)] = "New Year's Day" - e = easter(year) - good_friday = e - rd(days=2) - easter_monday = e + rd(days=1) - ascension_day = e + rd(days=39) - self[good_friday] = "Good Friday" - self[easter_monday] = "Easter Monday" - self[ascension_day] = "Ascension Day" + easter_date = easter(year) + self[easter_date + rd(days=-2)] = "Good Friday" + self[easter_date + rd(days=+1)] = "Easter Monday" + self[easter_date + rd(days=+39)] = "Ascension Day" if year > 1968: self[date(year, APR, 25)] = "National Flag Day" diff --git a/holidays/countries/ethiopia.py b/holidays/countries/ethiopia.py index ebc212de4..3ed5f9dc7 100644 --- a/holidays/countries/ethiopia.py +++ b/holidays/countries/ethiopia.py @@ -12,7 +12,7 @@ from calendar import isleap from datetime import date -from dateutil.easter import easter +from dateutil.easter import easter, EASTER_ORTHODOX from dateutil.relativedelta import relativedelta as rd from holidays.constants import SAT, SUN, JAN, MAR, MAY, SEP @@ -67,10 +67,11 @@ def _populate(self, year): self[date(year, JAN, 19)] = "ጥምቀት/Ephiphany" # Ethiopian Good Friday - self[easter(year, 2) - rd(days=2)] = "ስቅለት/Ethiopian Good Friday" + easter_date = easter(year, EASTER_ORTHODOX) + self[easter_date + rd(days=-2)] = "ስቅለት/Ethiopian Good Friday" # Ethiopian Easter - Orthodox Easter - self[easter(year, 2)] = "ፋሲካ/Ethiopian Easter" + self[easter_date] = "ፋሲካ/Ethiopian Easter" # Adwa Victory Day if year > 1896: diff --git a/holidays/countries/finland.py b/holidays/countries/finland.py index ed1539790..c4698aead 100644 --- a/holidays/countries/finland.py +++ b/holidays/countries/finland.py @@ -29,16 +29,16 @@ class Finland(HolidayBase): def _populate(self, year): super()._populate(year) - e = easter(year) + easter_date = easter(year) self[date(year, JAN, 1)] = "Uudenvuodenpäivä" self[date(year, JAN, 6)] = "Loppiainen" - self[e - rd(days=2)] = "Pitkäperjantai" - self[e] = "Pääsiäispäivä" - self[e + rd(days=1)] = "2. pääsiäispäivä" + self[easter_date + rd(days=-2)] = "Pitkäperjantai" + self[easter_date] = "Pääsiäispäivä" + self[easter_date + rd(days=+1)] = "2. pääsiäispäivä" self[date(year, MAY, 1)] = "Vappu" - self[e + rd(days=39)] = "Helatorstai" - self[e + rd(days=49)] = "Helluntaipäivä" + self[easter_date + rd(days=+39)] = "Helatorstai" + self[easter_date + rd(days=+49)] = "Helluntaipäivä" self[date(year, JUN, 20) + rd(weekday=SA)] = "Juhannuspäivä" self[date(year, OCT, 31) + rd(weekday=SA)] = "Pyhäinpäivä" self[date(year, DEC, 6)] = "Itsenäisyyspäivä" diff --git a/holidays/countries/france.py b/holidays/countries/france.py index 199a0a575..057b9db04 100644 --- a/holidays/countries/france.py +++ b/holidays/countries/france.py @@ -78,6 +78,8 @@ def _populate(self, year): self[date(year, NOV, 11)] = "Armistice 1918" # Religious holidays + easter_date = easter(year) + if self.subdiv in { "Alsace-Moselle", "Guadeloupe", @@ -85,17 +87,17 @@ def _populate(self, year): "Martinique", "Polynésie Française", }: - self[easter(year) - rd(days=2)] = "Vendredi saint" + self[easter_date + rd(days=-2)] = "Vendredi saint" if self.subdiv == "Alsace-Moselle": self[date(year, DEC, 26)] = "Deuxième jour de Noël" if year >= 1886: - self[easter(year) + rd(days=1)] = "Lundi de Pâques" - self[easter(year) + rd(days=50)] = "Lundi de Pentecôte" + self[easter_date + rd(days=+1)] = "Lundi de Pâques" + self[easter_date + rd(days=+50)] = "Lundi de Pentecôte" if year >= 1802: - self[easter(year) + rd(days=39)] = "Ascension" + self[easter_date + rd(days=+39)] = "Ascension" self[date(year, AUG, 15)] = "Assomption" self[date(year, NOV, 1)] = "Toussaint" diff --git a/holidays/countries/georgia.py b/holidays/countries/georgia.py index 26959a5bd..52ef9c799 100644 --- a/holidays/countries/georgia.py +++ b/holidays/countries/georgia.py @@ -11,7 +11,7 @@ from datetime import date -from dateutil.easter import EASTER_ORTHODOX, easter +from dateutil.easter import easter, EASTER_ORTHODOX from dateutil.relativedelta import relativedelta as rd from holidays.constants import JAN, MAR, APR, MAY, AUG, OCT, NOV @@ -52,21 +52,22 @@ def _populate(self, year): name = "ქალთა საერთაშორისო დღე" self[date(year, MAR, 8)] = name + easter_date = easter(year, method=EASTER_ORTHODOX) # Orthodox Good Friday name = "წითელი პარასკევი" - self[easter(year, method=EASTER_ORTHODOX) - rd(days=2)] = name + self[easter_date + rd(days=-2)] = name # Orthodox Holy Saturday name = "დიდი შაბათი" - self[easter(year, method=EASTER_ORTHODOX) - rd(days=1)] = name + self[easter_date + rd(days=-1)] = name # Orthodox Easter Sunday name = "აღდგომა" - self[easter(year, method=EASTER_ORTHODOX)] = name + self[easter_date] = name # Orthodox Easter Monday name = "შავი ორშაბათი" - self[easter(year, method=EASTER_ORTHODOX) + rd(days=1)] = name + self[easter_date + rd(days=+1)] = name # National Unity Day name = "ეროვნული ერთიანობის დღე" diff --git a/holidays/countries/germany.py b/holidays/countries/germany.py index 0617be453..3e1ec7dce 100644 --- a/holidays/countries/germany.py +++ b/holidays/countries/germany.py @@ -88,15 +88,17 @@ def _populate(self, year): if self.subdiv in {"BW", "BY", "BYP", "ST"}: self[date(year, JAN, 6)] = "Heilige Drei Könige" - self[easter(year) - rd(days=2)] = "Karfreitag" + easter_date = easter(year) + + self[easter_date + rd(days=-2)] = "Karfreitag" if self.subdiv == "BB": # will always be a Sunday and we have no "observed" rule so # this is pretty pointless but it's nonetheless an official # holiday by law - self[easter(year)] = "Ostersonntag" + self[easter_date] = "Ostersonntag" - self[easter(year) + rd(days=1)] = "Ostermontag" + self[easter_date + rd(days=+1)] = "Ostermontag" self[date(year, MAY, 1)] = "Erster Mai" @@ -106,18 +108,18 @@ def _populate(self, year): "und der Beendigung des Zweiten Weltkriegs in Europa" ) - self[easter(year) + rd(days=39)] = "Christi Himmelfahrt" + self[easter_date + rd(days=+39)] = "Christi Himmelfahrt" if self.subdiv == "BB": # will always be a Sunday and we have no "observed" rule so # this is pretty pointless but it's nonetheless an official # holiday by law - self[easter(year) + rd(days=49)] = "Pfingstsonntag" + self[easter_date + rd(days=+49)] = "Pfingstsonntag" - self[easter(year) + rd(days=50)] = "Pfingstmontag" + self[easter_date + rd(days=+50)] = "Pfingstmontag" if self.subdiv in {"BW", "BY", "BYP", "HE", "NW", "RP", "SL"}: - self[easter(year) + rd(days=60)] = "Fronleichnam" + self[easter_date + rd(days=+60)] = "Fronleichnam" if self.subdiv in {"BY", "SL"}: self[date(year, AUG, 15)] = "Mariä Himmelfahrt" diff --git a/holidays/countries/greece.py b/holidays/countries/greece.py index d77465a4b..c6b987cc5 100644 --- a/holidays/countries/greece.py +++ b/holidays/countries/greece.py @@ -11,7 +11,7 @@ from datetime import date -from dateutil.easter import EASTER_ORTHODOX, easter +from dateutil.easter import easter, EASTER_ORTHODOX from dateutil.relativedelta import relativedelta as rd from dateutil.relativedelta import MO, TU @@ -29,7 +29,7 @@ class Greece(HolidayBase): def _populate(self, year): super()._populate(year) - eday = easter(year, method=EASTER_ORTHODOX) + easter_date = easter(year, method=EASTER_ORTHODOX) # New Years self[date(year, JAN, 1)] = "Πρωτοχρονιά [New Year's Day]" @@ -37,17 +37,17 @@ def _populate(self, year): self[date(year, JAN, 6)] = "Θεοφάνεια [Epiphany]" # Clean Monday - self[eday - rd(days=48)] = "Καθαρά Δευτέρα [Clean Monday]" + self[easter_date + rd(days=-48)] = "Καθαρά Δευτέρα [Clean Monday]" # Independence Day self[date(year, MAR, 25)] = "Εικοστή Πέμπτη Μαρτίου [Independence Day]" # Easter Monday - self[eday + rd(days=1)] = "Δευτέρα του Πάσχα [Easter Monday]" + self[easter_date + rd(days=+1)] = "Δευτέρα του Πάσχα [Easter Monday]" # Monday of the Holy Spirit self[ - eday + rd(days=50) + easter_date + rd(days=+50) ] = "Δευτέρα του Αγίου Πνεύματος [Monday of the Holy Spirit]" # Labour Day diff --git a/holidays/countries/honduras.py b/holidays/countries/honduras.py index ab4587cb8..594ca5224 100644 --- a/holidays/countries/honduras.py +++ b/holidays/countries/honduras.py @@ -13,7 +13,7 @@ from dateutil.easter import easter from dateutil.relativedelta import relativedelta as rd -from dateutil.relativedelta import WE, TH, FR, SA +from dateutil.relativedelta import WE from holidays.constants import JAN, APR, MAY, SEP, OCT, DEC from holidays.holiday_base import HolidayBase @@ -31,18 +31,15 @@ def _populate(self, year): # New Year's Day self[date(year, JAN, 1)] = "Año Nuevo [New Year's Day]" + easter_date = easter(year) # Maundy Thursday - self[ - easter(year) + rd(weekday=TH(-1)) - ] = "Jueves Santo [Maundy Thursday]" + self[easter_date + rd(days=-3)] = "Jueves Santo [Maundy Thursday]" # Good Friday - self[easter(year) + rd(weekday=FR(-1))] = "Viernes Santo [Good Friday]" + self[easter_date + rd(days=-2)] = "Viernes Santo [Good Friday]" # Holy Saturday - self[ - easter(year) + rd(weekday=SA(-1)) - ] = "Sábado de Gloria [Holy Saturday]" + self[easter_date + rd(days=-1)] = "Sábado de Gloria [Holy Saturday]" # Panamerican Day self[date(year, APR, 14)] = "Día de las Américas [Panamerican Day]" diff --git a/holidays/countries/hungary.py b/holidays/countries/hungary.py index 1b045dc74..d4d560f8b 100644 --- a/holidays/countries/hungary.py +++ b/holidays/countries/hungary.py @@ -13,7 +13,6 @@ from dateutil.easter import easter from dateutil.relativedelta import relativedelta as rd -from dateutil.relativedelta import FR from holidays.constants import ( MON, @@ -77,21 +76,21 @@ def _populate(self, year: int) -> None: # Good Friday if 2017 <= year: - self[easter_date + rd(weekday=FR(-1))] = "Nagypéntek" + self[easter_date + rd(days=-2)] = "Nagypéntek" # Easter self[easter_date] = "Húsvét" # Second easter day if 1955 != year: - self[easter_date + rd(days=1)] = "Húsvét Hétfő" + self[easter_date + rd(days=+1)] = "Húsvét Hétfő" # Pentecost - self[easter_date + rd(days=49)] = "Pünkösd" + self[easter_date + rd(days=+49)] = "Pünkösd" # Pentecost monday if year <= 1952 or 1992 <= year: - self[easter_date + rd(days=50)] = "Pünkösdhétfő" + self[easter_date + rd(days=+50)] = "Pünkösdhétfő" # International Workers' Day if 1946 <= year: diff --git a/holidays/countries/iceland.py b/holidays/countries/iceland.py index 94a12ee0e..fa5d8daa4 100644 --- a/holidays/countries/iceland.py +++ b/holidays/countries/iceland.py @@ -13,7 +13,7 @@ from dateutil.easter import easter from dateutil.relativedelta import relativedelta as rd -from dateutil.relativedelta import MO, TH, FR +from dateutil.relativedelta import MO, TH from holidays.constants import JAN, APR, MAY, JUN, AUG, DEC from holidays.holiday_base import HolidayBase @@ -32,15 +32,16 @@ def _populate(self, year): # Public holidays self[date(year, JAN, 1)] = "Nýársdagur" - self[easter(year) - rd(days=3)] = "Skírdagur" - self[easter(year) + rd(weekday=FR(-1))] = "Föstudagurinn langi" - self[easter(year)] = "Páskadagur" - self[easter(year) + rd(days=1)] = "Annar í páskum" + easter_date = easter(year) + self[easter_date + rd(days=-3)] = "Skírdagur" + self[easter_date + rd(days=-2)] = "Föstudagurinn langi" + self[easter_date] = "Páskadagur" + self[easter_date + rd(days=+1)] = "Annar í páskum" self[date(year, APR, 19) + rd(weekday=TH(+1))] = "Sumardagurinn fyrsti" self[date(year, MAY, 1)] = "Verkalýðsdagurinn" - self[easter(year) + rd(days=39)] = "Uppstigningardagur" - self[easter(year) + rd(days=49)] = "Hvítasunnudagur" - self[easter(year) + rd(days=50)] = "Annar í hvítasunnu" + self[easter_date + rd(days=+39)] = "Uppstigningardagur" + self[easter_date + rd(days=+49)] = "Hvítasunnudagur" + self[easter_date + rd(days=+50)] = "Annar í hvítasunnu" self[date(year, JUN, 17)] = "Þjóðhátíðardagurinn" # First Monday of August self[ diff --git a/holidays/countries/ireland.py b/holidays/countries/ireland.py index d7a7a5a42..cd2f3f210 100644 --- a/holidays/countries/ireland.py +++ b/holidays/countries/ireland.py @@ -62,7 +62,7 @@ def _populate(self, year): self[dt + rd(weekday=MO)] = name + " (Observed)" # Easter Monday - self[easter(year) + rd(weekday=MO)] = "Easter Monday" + self[easter(year) + rd(days=+1)] = "Easter Monday" # May bank holiday (first Monday in May) if year >= 1978: diff --git a/holidays/countries/italy.py b/holidays/countries/italy.py index d5d287873..de7c80513 100644 --- a/holidays/countries/italy.py +++ b/holidays/countries/italy.py @@ -14,7 +14,7 @@ from dateutil.easter import easter from dateutil.relativedelta import relativedelta as rd -from dateutil.relativedelta import MO, TU, TH, SU +from dateutil.relativedelta import TU, TH, SU from holidays.constants import ( JAN, @@ -166,8 +166,9 @@ def _populate(self, year): self[date(year, JAN, 1)] = "Capodanno" self[date(year, JAN, 6)] = "Epifania del Signore" - self[easter(year)] = "Pasqua di Resurrezione" - self[easter(year) + rd(weekday=MO)] = "Lunedì dell'Angelo" + easter_date = easter(year) + self[easter_date] = "Pasqua di Resurrezione" + self[easter_date + rd(days=+1)] = "Lunedì dell'Angelo" if year >= 1946: self[date(year, APR, 25)] = "Festa della Liberazione" self[date(year, MAY, 1)] = "Festa dei Lavoratori" @@ -232,7 +233,7 @@ def _populate(self, year): if self.subdiv in {"BT", "Trani"}: self[date(year, MAY, 3)] = "San Nicola Pellegrino" elif self.subdiv == "BZ": - self[easter(year) + rd(days=50)] = "Lunedì di Pentecoste" + self[easter_date + rd(days=+50)] = "Lunedì di Pentecoste" self[date(year, AUG, 15)] = "Maria Santissima Assunta" elif self.subdiv == "CA": self[date(year, OCT, 30)] = "San Saturnino di Cagliari" diff --git a/holidays/countries/jamaica.py b/holidays/countries/jamaica.py index 08fb44af7..519bf20dd 100644 --- a/holidays/countries/jamaica.py +++ b/holidays/countries/jamaica.py @@ -13,7 +13,7 @@ from dateutil.easter import easter from dateutil.relativedelta import relativedelta as rd -from dateutil.relativedelta import MO, WE, FR, SU +from dateutil.relativedelta import MO, SU from holidays.constants import SUN, WEEKEND, JAN, FEB, MAY, JUN, AUG, OCT, DEC from holidays.holiday_base import HolidayBase @@ -83,18 +83,19 @@ def _populate(self, year): # self[date(year, DEC, 31)] = "New Year Eve" # Holidays based on Easter + easter_date = easter(year) # Ash Wednesday - self[easter(year) + rd(days=-40, weekday=WE(-1))] = "Ash Wednesday" + self[easter_date + rd(days=-46)] = "Ash Wednesday" # Good Friday - self[easter(year) + rd(weekday=FR(-1))] = "Good Friday" + self[easter_date + rd(days=-2)] = "Good Friday" # Easter - self[easter(year)] = "Easter" + self[easter_date] = "Easter" # Easter - self[easter(year) + rd(weekday=MO(+1))] = "Easter Monday" + self[easter_date + rd(days=+1)] = "Easter Monday" class JM(Jamaica): diff --git a/holidays/countries/kenya.py b/holidays/countries/kenya.py index c805957f0..7e24c1ea2 100644 --- a/holidays/countries/kenya.py +++ b/holidays/countries/kenya.py @@ -13,7 +13,6 @@ from dateutil.easter import easter from dateutil.relativedelta import relativedelta as rd -from dateutil.relativedelta import MO, FR from holidays.constants import SUN, JAN, MAY, JUN, OCT, DEC from holidays.holiday_base import HolidayBase @@ -44,8 +43,9 @@ def _populate(self, year): if self.observed and k.weekday() == SUN: self[k + rd(days=1)] = v + " (Observed)" - self[easter(year) - rd(weekday=FR(-1))] = "Good Friday" - self[easter(year) + rd(weekday=MO(+1))] = "Easter Monday" + easter_date = easter(year) + self[easter_date + rd(days=-2)] = "Good Friday" + self[easter_date + rd(days=+1)] = "Easter Monday" class KE(Kenya): diff --git a/holidays/countries/latvia.py b/holidays/countries/latvia.py index 7934e22cd..f071f2347 100644 --- a/holidays/countries/latvia.py +++ b/holidays/countries/latvia.py @@ -33,14 +33,13 @@ def _populate(self, year): # Good Friday easter_date = easter(year) - self[easter_date - rd(days=2)] = "Lielā Piektdiena" + self[easter_date + rd(days=-2)] = "Lielā Piektdiena" # Easter - easter_date = easter(year) self[easter_date] = "Lieldienas" # Easter 2nd day - self[easter_date + rd(days=1)] = "Otrās Lieldienas" + self[easter_date + rd(days=+1)] = "Otrās Lieldienas" # International Workers' Day self[date(year, 5, 1)] = "Darba svētki" diff --git a/holidays/countries/lesotho.py b/holidays/countries/lesotho.py index 5020dfd89..1d0a84557 100644 --- a/holidays/countries/lesotho.py +++ b/holidays/countries/lesotho.py @@ -43,14 +43,10 @@ def _populate(self, year): if year > 2002: self[date(year, MAY, 25)] = "Africa/Heroes Day" - e = easter(year) - good_friday = e - rd(days=2) - easter_monday = e + rd(days=1) - ascension_day = e + rd(days=39) - - self[good_friday] = "Good Friday" - self[easter_monday] = "Easter Monday" - self[ascension_day] = "Ascension Day" + easter_date = easter(year) + self[easter_date + rd(days=-2)] = "Good Friday" + self[easter_date + rd(days=+1)] = "Easter Monday" + self[easter_date + rd(days=+39)] = "Ascension Day" self[date(year, MAY, 1)] = "Workers' Day" if year > 1997: diff --git a/holidays/countries/liechtenstein.py b/holidays/countries/liechtenstein.py index 73c57ccf3..96f0e9086 100644 --- a/holidays/countries/liechtenstein.py +++ b/holidays/countries/liechtenstein.py @@ -41,35 +41,36 @@ def _populate(self, year): # Candlemas. self[date(year, FEB, 2)] = "Mariä Lichtmess" + easter_date = easter(year) # Shrove Tuesday. - self[easter(year) + rd(days=-47)] = "Fasnachtsdienstag" + self[easter_date + rd(days=-47)] = "Fasnachtsdienstag" # Saint Joseph's Day. self[date(year, MAR, 19)] = "Josefstag" # Good Friday. - self[easter(year) + rd(days=-2)] = "Karfreitag" + self[easter_date + rd(days=-2)] = "Karfreitag" # Easter. - self[easter(year)] = "Ostersonntag" + self[easter_date] = "Ostersonntag" # Easter Monday. - self[easter(year) + rd(days=+1)] = "Ostermontag" + self[easter_date + rd(days=+1)] = "Ostermontag" # Labor Day. self[date(year, MAY, 1)] = "Tag der Arbeit" # Ascension Day. - self[easter(year) + rd(days=+39)] = "Auffahrt" + self[easter_date + rd(days=+39)] = "Auffahrt" # Pentecost. - self[easter(year) + rd(weeks=+7)] = "Pfingstsonntag" + self[easter_date + rd(days=+49)] = "Pfingstsonntag" # Whit Monday. - self[easter(year) + rd(days=+50)] = "Pfingstmontag" + self[easter_date + rd(days=+50)] = "Pfingstmontag" # Corpus Christi. - self[easter(year) + rd(days=+60)] = "Fronleichnam" + self[easter_date + rd(days=+60)] = "Fronleichnam" # National Day. self[date(year, AUG, 15)] = "Staatsfeiertag" diff --git a/holidays/countries/lithuania.py b/holidays/countries/lithuania.py index 32de11495..f53ce1b6d 100644 --- a/holidays/countries/lithuania.py +++ b/holidays/countries/lithuania.py @@ -48,7 +48,7 @@ def _populate(self, year): self[easter_date] = "Velykos" # Easter 2nd day - self[easter_date + rd(days=1)] = "Velykų antroji diena" + self[easter_date + rd(days=+1)] = "Velykų antroji diena" # International Workers' Day self[date(year, 5, 1)] = "Tarptautinė darbo diena" diff --git a/holidays/countries/luxembourg.py b/holidays/countries/luxembourg.py index 327564d18..3b76d942a 100644 --- a/holidays/countries/luxembourg.py +++ b/holidays/countries/luxembourg.py @@ -13,7 +13,6 @@ from dateutil.easter import easter from dateutil.relativedelta import relativedelta as rd -from dateutil.relativedelta import MO from holidays.constants import JAN, MAY, JUN, AUG, NOV, DEC from holidays.holiday_base import HolidayBase @@ -31,13 +30,14 @@ def _populate(self, year): # Public holidays self[date(year, JAN, 1)] = "Neijoerschdag" - self[easter(year) + rd(weekday=MO)] = "Ouschterméindeg" + easter_date = easter(year) + self[easter_date + rd(days=+1)] = "Ouschterméindeg" self[date(year, MAY, 1)] = "Dag vun der Aarbecht" if year >= 2019: # Europe Day: not in legislation yet, but introduced starting 2019 self[date(year, MAY, 9)] = "Europadag" - self[easter(year) + rd(days=39)] = "Christi Himmelfaart" - self[easter(year) + rd(days=50)] = "Péngschtméindeg" + self[easter_date + rd(days=+39)] = "Christi Himmelfaart" + self[easter_date + rd(days=+50)] = "Péngschtméindeg" self[date(year, JUN, 23)] = "Nationalfeierdag" self[date(year, AUG, 15)] = "Léiffrawëschdag" self[date(year, NOV, 1)] = "Allerhellgen" diff --git a/holidays/countries/madagascar.py b/holidays/countries/madagascar.py index d494a6b19..5ab47e550 100644 --- a/holidays/countries/madagascar.py +++ b/holidays/countries/madagascar.py @@ -38,17 +38,18 @@ def _populate(self, year): self[date(year, 3, 29)] = "Fetin'ny mahery fo" self[date(year, 11, 1)] = "Fetin'ny olo-masina" self[date(year, 12, 25)] = "Fetin'ny noely" - self[easter(year)] = "fetin'ny paska" - self[easter(year) + rd(days=1)] = "Alatsinain'ny paska" - self[easter(year) + rd(days=49)] = "Pentekosta" - self[easter(year) + rd(days=50)] = "Alatsinain'ny pentekosta" + easter_date = easter(year) + self[easter_date] = "fetin'ny paska" + self[easter_date + rd(days=+1)] = "Alatsinain'ny paska" + self[easter_date + rd(days=+49)] = "Pentekosta" + self[easter_date + rd(days=+50)] = "Alatsinain'ny pentekosta" self[date(year, 6, 1) + rd(day=1, weekday=SU(3))] = "Fetin'ny ray" self[ - easter(year) + rd(days=39) + easter_date + rd(days=+39) ] = "Fiakaran'ny Jesosy kristy tany an-danitra" self[date(year, 8, 15)] = "Fiakaran'ny Masina Maria tany an-danitra" - if easter(year) + rd(days=49) == date(year, 5, 1) + rd( + if easter_date + rd(days=+49) == date(year, 5, 1) + rd( day=31, weekday=SU(-1) ): self[ diff --git a/holidays/countries/malawi.py b/holidays/countries/malawi.py index 89dcb951e..6a6095849 100644 --- a/holidays/countries/malawi.py +++ b/holidays/countries/malawi.py @@ -31,13 +31,11 @@ def _populate(self, year): # Observed since 2000 if year > 1999: - self[date(year, 1, 1)] = "New Year's Day" + self[date(year, JAN, 1)] = "New Year's Day" - e = easter(year) - good_friday = e - rd(days=2) - easter_monday = e + rd(days=1) - self[good_friday] = "Good Friday" - self[easter_monday] = "Easter Monday" + easter_date = easter(year) + self[easter_date + rd(days=-2)] = "Good Friday" + self[easter_date + rd(days=+1)] = "Easter Monday" self[date(year, JAN, 15)] = "John Chilembwe Day" self[date(year, MAR, 3)] = "Martyrs Day" diff --git a/holidays/countries/malaysia.py b/holidays/countries/malaysia.py index 7c6a93491..cee4f64cf 100644 --- a/holidays/countries/malaysia.py +++ b/holidays/countries/malaysia.py @@ -470,7 +470,7 @@ def _populate(self, year): # Good Friday. if self.subdiv in {"SBH", "SWK"}: - self[easter(year) + rd(weekday=FR(-1))] = "Good Friday" + self[easter(year) + rd(days=-2)] = "Good Friday" # Thaipusam. # An annual Hindu festival observed on the day of the first full moon diff --git a/holidays/countries/malta.py b/holidays/countries/malta.py index a3af5c403..3ff0be886 100644 --- a/holidays/countries/malta.py +++ b/holidays/countries/malta.py @@ -34,9 +34,7 @@ def _populate(self, year): self[date(year, MAR, 31)] = "Freedom Day" # Easter and easter related calculations - e = easter(year) - good_friday = e - rd(days=2) - + good_friday = easter(year) + rd(days=-2) self[good_friday] = "Good Friday" self[date(year, MAY, 1)] = "Worker's Day" diff --git a/holidays/countries/moldova.py b/holidays/countries/moldova.py index b4f72442c..8b9d3b84f 100644 --- a/holidays/countries/moldova.py +++ b/holidays/countries/moldova.py @@ -11,7 +11,7 @@ from datetime import date -from dateutil.easter import EASTER_ORTHODOX, easter +from dateutil.easter import easter, EASTER_ORTHODOX from dateutil.relativedelta import relativedelta as rd from holidays.constants import JAN, MAR, MAY, JUN, AUG, OCT, DEC @@ -28,7 +28,7 @@ class Moldova(HolidayBase): def _populate(self, year): super()._populate(year) - eday = easter(year, method=EASTER_ORTHODOX) + easter_date = easter(year, method=EASTER_ORTHODOX) # New Year self[date(year, JAN, 1)] = "Anul Nou" @@ -42,10 +42,10 @@ def _populate(self, year): # Orthodox Easter for day_after_easter in [-2, 0, 1]: - self[eday + rd(days=day_after_easter)] = "Paştele" + self[easter_date + rd(days=day_after_easter)] = "Paştele" # Paştele Blajinilor - self[eday + rd(days=9)] = "Paştele Blajinilor" + self[easter_date + rd(days=+9)] = "Paştele Blajinilor" # Labour Day self[date(year, MAY, 1)] = "Ziua Internatională a Muncii" diff --git a/holidays/countries/mozambique.py b/holidays/countries/mozambique.py index b4ee351c7..49bed30d6 100644 --- a/holidays/countries/mozambique.py +++ b/holidays/countries/mozambique.py @@ -26,14 +26,12 @@ def _populate(self, year): if year > 1974: self[date(year, 1, 1)] = "Ano novo" - e = easter(year) - good_friday = e - rd(days=2) - self[good_friday] = "Sexta-feira Santa" + easter_date = easter(year) + self[easter_date + rd(days=-2)] = "Sexta-feira Santa" # carnival is the Tuesday before Ash Wednesday # which is 40 days before easter excluding sundays - carnival = e + rd(days=-47) - self[carnival] = "Carnaval" + self[easter_date + rd(days=-47)] = "Carnaval" self[date(year, FEB, 3)] = "Dia dos Heróis Moçambicanos" self[date(year, APR, 7)] = "Dia da Mulher Moçambicana" diff --git a/holidays/countries/namibia.py b/holidays/countries/namibia.py index f6e40dec9..d9d607220 100644 --- a/holidays/countries/namibia.py +++ b/holidays/countries/namibia.py @@ -40,14 +40,10 @@ def _populate(self, year): self[date(year, MAR, 21)] = "Independence Day" # Easter Calculation - e = easter(year) - good_friday = e - rd(days=2) - easter_monday = e + rd(days=1) - ascension_day = e + rd(days=39) - - self[easter_monday] = "Easter Monday" - self[good_friday] = "Good Friday" - self[ascension_day] = "Ascension Day" + easter_date = easter(year) + self[easter_date + rd(days=-2)] = "Good Friday" + self[easter_date + rd(days=+1)] = "Easter Monday" + self[easter_date + rd(days=+39)] = "Ascension Day" # --------END OF EASTER------------# self[date(year, MAY, 1)] = "Workers' Day" diff --git a/holidays/countries/netherlands.py b/holidays/countries/netherlands.py index 64ff96549..06979d453 100644 --- a/holidays/countries/netherlands.py +++ b/holidays/countries/netherlands.py @@ -13,7 +13,6 @@ from dateutil.easter import easter from dateutil.relativedelta import relativedelta as rd -from dateutil.relativedelta import FR from holidays.constants import SUN, JAN, APR, MAY, AUG, DEC from holidays.holiday_base import HolidayBase @@ -38,19 +37,19 @@ def _populate(self, year): self[easter_date] = "Eerste paasdag" # Good friday - self[easter_date + rd(weekday=FR(-1))] = "Goede Vrijdag" + self[easter_date + rd(days=-2)] = "Goede Vrijdag" # Second easter day - self[easter_date + rd(days=1)] = "Tweede paasdag" + self[easter_date + rd(days=+1)] = "Tweede paasdag" # Ascension day - self[easter_date + rd(days=39)] = "Hemelvaart" + self[easter_date + rd(days=+39)] = "Hemelvaart" # Pentecost - self[easter_date + rd(days=49)] = "Eerste Pinksterdag" + self[easter_date + rd(days=+49)] = "Eerste Pinksterdag" # Pentecost monday - self[easter_date + rd(days=50)] = "Tweede Pinksterdag" + self[easter_date + rd(days=+50)] = "Tweede Pinksterdag" # First christmas self[date(year, DEC, 25)] = "Eerste Kerstdag" diff --git a/holidays/countries/new_zealand.py b/holidays/countries/new_zealand.py index 37ffaed9d..036112fdf 100644 --- a/holidays/countries/new_zealand.py +++ b/holidays/countries/new_zealand.py @@ -118,8 +118,9 @@ def _populate(self, year): self[feb6 + rd(weekday=MO)] = name + " (Observed)" # Easter - self[easter(year) + rd(weekday=FR(-1))] = "Good Friday" - self[easter(year) + rd(weekday=MO)] = "Easter Monday" + easter_date = easter(year) + self[easter_date + rd(days=-2)] = "Good Friday" + self[easter_date + rd(days=+1)] = "Easter Monday" # Anzac Day if year > 1920: @@ -306,7 +307,7 @@ def _populate(self, year): dt = mar23 + rd(weekday=MO(-1)) else: dt = mar23 + rd(weekday=MO) - if dt == easter(year) + rd(weekday=MO): # Avoid Easter Monday + if dt == easter_date + rd(days=+1): # Avoid Easter Monday dt += rd(days=1) self[dt] = name @@ -314,7 +315,7 @@ def _populate(self, year): name = "Southland Anniversary Day" jan17 = date(year, JAN, 17) if year > 2011: - self[easter(year) + rd(weekday=TU)] = name + self[easter_date + rd(days=+2)] = name else: if jan17.weekday() in {TUE, WED, THU}: self[jan17 + rd(weekday=MO(-1))] = name diff --git a/holidays/countries/nicaragua.py b/holidays/countries/nicaragua.py index 3acd89ae3..72b396f1a 100644 --- a/holidays/countries/nicaragua.py +++ b/holidays/countries/nicaragua.py @@ -13,7 +13,6 @@ from dateutil.easter import easter from dateutil.relativedelta import relativedelta as rd -from dateutil.relativedelta import TH, FR from holidays.constants import JAN, MAY, JUL, AUG, SEP, DEC from holidays.holiday_base import HolidayBase @@ -35,11 +34,10 @@ def _populate(self, year): # New Years self[date(year, JAN, 1)] = "Año Nuevo [New Year's Day]" # Maundy Thursday - self[ - easter(year) + rd(weekday=TH(-1)) - ] = "Jueves Santo [Maundy Thursday]" + easter_date = easter(year) + self[easter_date + rd(days=-3)] = "Jueves Santo [Maundy Thursday]" # Good Friday - self[easter(year) + rd(weekday=FR(-1))] = "Viernes Santo [Good Friday]" + self[easter_date + rd(days=-2)] = "Viernes Santo [Good Friday]" # Labor Day self[date(year, MAY, 1)] = "Día del Trabajo [Labour Day]" # Revolution Day diff --git a/holidays/countries/nigeria.py b/holidays/countries/nigeria.py index 17827453e..891c8a798 100644 --- a/holidays/countries/nigeria.py +++ b/holidays/countries/nigeria.py @@ -44,13 +44,9 @@ def _add_holiday(dt: date, hol: str) -> None: # Calculate Easter for given year # followed by easter related holidays - e = easter(year) - - good_friday = e - rd(days=2) - self[good_friday] = "Good Friday" - - easter_monday = e + rd(days=1) - self[easter_monday] = "Easter Monday" + easter_date = easter(year) + self[easter_date + rd(days=-2)] = "Good Friday" + self[easter_date + rd(days=+1)] = "Easter Monday" # Worker's day self[date(year, MAY, 1)] = "Workers' day" diff --git a/holidays/countries/north_macedonia.py b/holidays/countries/north_macedonia.py index f028518b9..d8e1fffda 100644 --- a/holidays/countries/north_macedonia.py +++ b/holidays/countries/north_macedonia.py @@ -11,7 +11,7 @@ from datetime import date -from dateutil.easter import EASTER_ORTHODOX, easter +from dateutil.easter import easter, EASTER_ORTHODOX from dateutil.relativedelta import relativedelta as rd from holidays.constants import JAN, MAY, SEP, AUG, OCT, DEC @@ -32,8 +32,8 @@ def _populate(self, year): self[date(year, JAN, 1)] = "New Year's Day" self[date(year, JAN, 7)] = "Christmas Day (Orthodox)" - eater_day = easter(year, method=EASTER_ORTHODOX) - self[eater_day + rd(days=1)] = "Easter Monday(Orthodox)" + easter_date = easter(year, method=EASTER_ORTHODOX) + self[easter_date + rd(days=+1)] = "Easter Monday(Orthodox)" self[date(year, MAY, 1)] = "Labour Day" self[date(year, MAY, 24)] = "Saints Cyril and Methodius Day" self[date(year, AUG, 2)] = "Republic Day" diff --git a/holidays/countries/norway.py b/holidays/countries/norway.py index 256e77c38..169cfa865 100644 --- a/holidays/countries/norway.py +++ b/holidays/countries/norway.py @@ -84,14 +84,14 @@ def _populate(self, year): # which says # "(...) has been celebrated for over 1000 years (...)" (in Norway) - easter_day = easter(year) - self[easter_day + rd(days=-3)] = "Skjærtorsdag" - self[easter_day + rd(days=-2)] = "Langfredag" - self[easter_day] = "Første påskedag" - self[easter_day + rd(days=+1)] = "Andre påskedag" - self[easter_day + rd(days=+39)] = "Kristi himmelfartsdag" - self[easter_day + rd(days=+49)] = "Første pinsedag" - self[easter_day + rd(days=+50)] = "Andre pinsedag" + easter_date = easter(year) + self[easter_date + rd(days=-3)] = "Skjærtorsdag" + self[easter_date + rd(days=-2)] = "Langfredag" + self[easter_date] = "Første påskedag" + self[easter_date + rd(days=+1)] = "Andre påskedag" + self[easter_date + rd(days=+39)] = "Kristi himmelfartsdag" + self[easter_date + rd(days=+49)] = "Første pinsedag" + self[easter_date + rd(days=+50)] = "Andre pinsedag" class NO(Norway): diff --git a/holidays/countries/paraguay.py b/holidays/countries/paraguay.py index 545082e3f..e0293028a 100644 --- a/holidays/countries/paraguay.py +++ b/holidays/countries/paraguay.py @@ -13,7 +13,7 @@ from dateutil.easter import easter from dateutil.relativedelta import relativedelta as rd -from dateutil.relativedelta import MO, TH, FR +from dateutil.relativedelta import MO from holidays.constants import WED, WEEKEND, JAN, MAR, MAY, JUN, AUG, SEP, DEC from holidays.holiday_base import HolidayBase @@ -51,14 +51,14 @@ def _populate(self, year): name_thu = "Semana Santa (Jueves Santo) [Holy day (Holy Thursday)]" name_fri = "Semana Santa (Viernes Santo) [Holy day (Holy Friday)]" name_easter = "Día de Pascuas [Easter Day]" + easter_date = easter(year) + self[easter_date + rd(days=-3)] = name_thu + self[easter_date + rd(days=-2)] = name_fri - self[easter(year) + rd(weekday=TH(-1))] = name_thu - self[easter(year) + rd(weekday=FR(-1))] = name_fri - - if not self.observed and easter(year).weekday() in WEEKEND: + if not self.observed and easter_date.weekday() in WEEKEND: pass else: - self[easter(year)] = name_easter + self[easter_date] = name_easter # Labor Day name = "Día de los Trabajadores [Labour Day]" diff --git a/holidays/countries/peru.py b/holidays/countries/peru.py index 695f2886d..dfd8f1de6 100644 --- a/holidays/countries/peru.py +++ b/holidays/countries/peru.py @@ -13,7 +13,6 @@ from dateutil.easter import easter from dateutil.relativedelta import relativedelta as rd -from dateutil.relativedelta import TH, FR, SA, SU from holidays.constants import JAN, MAY, JUN, JUL, AUG, OCT, NOV, DEC from holidays.holiday_base import HolidayBase @@ -52,23 +51,18 @@ def _populate(self, year): name = "Combate Naval de Angamos [Battle of Angamos]" self[date(year, OCT, 8)] = name + easter_date = easter(year) # Holy Thursday - self[ - easter(year) + rd(weekday=TH(-1)) - ] = "Jueves Santo [Maundy Thursday]" + self[easter_date + rd(days=-3)] = "Jueves Santo [Maundy Thursday]" # Good Friday - self[easter(year) + rd(weekday=FR(-1))] = "Viernes Santo [Good Friday]" + self[easter_date + rd(days=-2)] = "Viernes Santo [Good Friday]" # Holy Saturday - self[ - easter(year) + rd(weekday=SA(-1)) - ] = "Sábado de Gloria [Holy Saturday]" + self[easter_date + rd(days=-1)] = "Sábado de Gloria [Holy Saturday]" # Easter Sunday - self[ - easter(year) + rd(weekday=SU(-1)) - ] = "Domingo de Resurrección [Easter Sunday]" + self[easter_date] = "Domingo de Resurrección [Easter Sunday]" # Labor Day self[date(year, MAY, 1)] = "Día del Trabajo [Labour Day]" diff --git a/holidays/countries/poland.py b/holidays/countries/poland.py index 89ad6e053..02c0095b1 100644 --- a/holidays/countries/poland.py +++ b/holidays/countries/poland.py @@ -35,17 +35,17 @@ def _populate(self, year): if year >= 2011: self[date(year, JAN, 6)] = "Święto Trzech Króli" - e = easter(year) - self[e] = "Niedziela Wielkanocna" - self[e + rd(days=1)] = "Poniedziałek Wielkanocny" + easter_date = easter(year) + self[easter_date] = "Niedziela Wielkanocna" + self[easter_date + rd(days=+1)] = "Poniedziałek Wielkanocny" if year >= 1950: self[date(year, MAY, 1)] = "Święto Państwowe" if year >= 1919: self[date(year, MAY, 3)] = "Święto Narodowe Trzeciego Maja" - self[e + rd(days=49)] = "Zielone Świątki" - self[e + rd(days=60)] = "Dzień Bożego Ciała" + self[easter_date + rd(days=+49)] = "Zielone Świątki" + self[easter_date + rd(days=+60)] = "Dzień Bożego Ciała" self[date(year, AUG, 15)] = "Wniebowzięcie Najświętszej Marii Panny" diff --git a/holidays/countries/portugal.py b/holidays/countries/portugal.py index 38a8b08df..db94f250a 100644 --- a/holidays/countries/portugal.py +++ b/holidays/countries/portugal.py @@ -66,17 +66,17 @@ def _populate(self, year): self[date(year, JAN, 1)] = "Ano Novo" - e = easter(year) + easter_date = easter(year) # carnival is no longer a holiday, but some companies let workers off. # @todo recollect the years in which it was a public holiday # self[e - rd(days=47)] = "Carnaval" - self[e - rd(days=2)] = "Sexta-feira Santa" - self[e] = "Páscoa" + self[easter_date + rd(days=-2)] = "Sexta-feira Santa" + self[easter_date] = "Páscoa" # Revoked holidays in 2013–2015 if year < 2013 or year > 2015: - self[e + rd(days=60)] = "Corpo de Deus" + self[easter_date + rd(days=+60)] = "Corpo de Deus" self[date(year, OCT, 5)] = "Implantação da República" self[date(year, NOV, 1)] = "Dia de Todos os Santos" self[date(year, DEC, 1)] = "Restauração da Independência" @@ -99,8 +99,7 @@ def _populate(self, year): - Lisbon's city holiday """ - e = easter(year) - self[e - rd(days=47)] = "Carnaval" + self[easter_date + rd(days=-47)] = "Carnaval" self[date(year, DEC, 24)] = "Véspera de Natal" self[date(year, DEC, 26)] = "26 de Dezembro" self[date(year, DEC, 31)] = "Véspera de Ano Novo" @@ -114,14 +113,14 @@ def _populate(self, year): if self.subdiv == "01": self[date(year, MAY, 12)] = "Dia de Santa Joana" if self.subdiv == "02": - self[e + rd(days=4) + rd(weeks=5)] = "Quinta-feira da Ascensão" + self[easter_date + rd(days=+39)] = "Quinta-feira da Ascensão" if self.subdiv in {"03", "13"}: self[date(year, JUN, 24)] = "Dia de São João" if self.subdiv == "04": self[date(year, AUG, 22)] = "Dia de Nossa Senhora das Graças" if self.subdiv == "05": self[ - e + rd(days=2) + rd(weeks=2) + easter_date + rd(days=+16) ] = "Dia de Nossa Senhora de Mércoles" if self.subdiv == "06": self[date(year, JUL, 4)] = "Dia de Santa Isabel" diff --git a/holidays/countries/romania.py b/holidays/countries/romania.py index 24becc442..9058bf495 100644 --- a/holidays/countries/romania.py +++ b/holidays/countries/romania.py @@ -11,7 +11,7 @@ from datetime import date -from dateutil.easter import EASTER_ORTHODOX, easter +from dateutil.easter import easter, EASTER_ORTHODOX from dateutil.relativedelta import relativedelta as rd from holidays.constants import JAN, MAY, JUN, AUG, NOV, DEC @@ -28,18 +28,18 @@ class Romania(HolidayBase): def _populate(self, year): super()._populate(year) - eday = easter(year, method=EASTER_ORTHODOX) + easter_date = easter(year, method=EASTER_ORTHODOX) # New Year - for day in [1, 2]: + for day in (1, 2): self[date(year, JAN, day)] = "Anul Nou" # Anniversary of the formation of the United Principalities self[date(year, JAN, 24)] = "Unirea Principatelor Române" # Easter (Friday, Sunday and Monday) - for day_after_easter in [-2, 0, 1]: - self[eday + rd(days=day_after_easter)] = "Paștele" + for day_after_easter in (-2, 0, 1): + self[easter_date + rd(days=day_after_easter)] = "Paștele" # Labour Day self[date(year, MAY, 1)] = "Ziua Muncii" @@ -49,8 +49,8 @@ def _populate(self, year): self[date(year, JUN, 1)] = "Ziua Copilului" # Whit Monday - for day_after_easter in [49, 50]: - self[eday + rd(days=day_after_easter)] = "Rusaliile" + for day_after_easter in (49, 50): + self[easter_date + rd(days=day_after_easter)] = "Rusaliile" # Assumption of Mary self[date(year, AUG, 15)] = "Adormirea Maicii Domnului" diff --git a/holidays/countries/serbia.py b/holidays/countries/serbia.py index 6ac664eb6..e9aefba95 100644 --- a/holidays/countries/serbia.py +++ b/holidays/countries/serbia.py @@ -11,7 +11,7 @@ from datetime import date -from dateutil.easter import EASTER_ORTHODOX, easter +from dateutil.easter import easter, EASTER_ORTHODOX from dateutil.relativedelta import relativedelta as rd from holidays.constants import SUN, WEEKEND, JAN, FEB, MAY, NOV @@ -47,8 +47,9 @@ def _populate(self, year): name = "Празник рада" self[date(year, MAY, 1)] = name self[date(year, MAY, 2)] = name + easter_date = easter(year, method=EASTER_ORTHODOX) if self.observed and date(year, MAY, 1).weekday() in WEEKEND: - if date(year, MAY, 2) == easter(year, method=EASTER_ORTHODOX): + if date(year, MAY, 2) == easter_date: self[date(year, MAY, 4)] = name + " (Observed)" else: self[date(year, MAY, 3)] = name + " (Observed)" @@ -58,16 +59,10 @@ def _populate(self, year): if self.observed and date(year, NOV, 11).weekday() == SUN: self[date(year, NOV, 12)] = name + " (Observed)" # Easter - self[ - easter(year, method=EASTER_ORTHODOX) - rd(days=2) - ] = "Велики петак" - self[ - easter(year, method=EASTER_ORTHODOX) - rd(days=1) - ] = "Велика субота" - self[easter(year, method=EASTER_ORTHODOX)] = "Васкрс" - self[ - easter(year, method=EASTER_ORTHODOX) + rd(days=1) - ] = "Други дан Васкрса" + self[easter_date + rd(days=-2)] = "Велики петак" + self[easter_date + rd(days=-1)] = "Велика субота" + self[easter_date] = "Васкрс" + self[easter_date + rd(days=+1)] = "Други дан Васкрса" class RS(Serbia): diff --git a/holidays/countries/singapore.py b/holidays/countries/singapore.py index 5e2817168..a744b23d4 100644 --- a/holidays/countries/singapore.py +++ b/holidays/countries/singapore.py @@ -14,7 +14,6 @@ from dateutil.easter import easter from dateutil.relativedelta import relativedelta as rd -from dateutil.relativedelta import MO, FR, SA from holidays.constants import ( SUN, @@ -196,16 +195,16 @@ def _populate(self, year) -> None: hol_date = date_obs self[hol_date] = "Hari Raya Haji* (*estimated)" - # Holy Saturday (up to and including 1968) - if year <= 1968: - self[easter(year) + rd(weekday=SA(-1))] = "Holy Saturday" - + easter_date = easter(year) # Good Friday - self[easter(year) + rd(weekday=FR(-1))] = "Good Friday" + self[easter_date + rd(days=-2)] = "Good Friday" - # Easter Monday if year <= 1968: - self[easter(year) + rd(weekday=MO(1))] = "Easter Monday" + # Holy Saturday + self[easter_date + rd(days=-1)] = "Holy Saturday" + + # Easter Monday + self[easter_date + rd(days=+1)] = "Easter Monday" # Labour Day self[date(year, MAY, 1)] = "Labour Day" diff --git a/holidays/countries/slovakia.py b/holidays/countries/slovakia.py index 871a970d2..426cadfcd 100644 --- a/holidays/countries/slovakia.py +++ b/holidays/countries/slovakia.py @@ -41,9 +41,9 @@ def _populate(self, year): " kresťanov)" ) - e = easter(year) - self[e - rd(days=2)] = "Veľký piatok" - self[e + rd(days=1)] = "Veľkonočný pondelok" + easter_date = easter(year) + self[easter_date + rd(days=-2)] = "Veľký piatok" + self[easter_date + rd(days=+1)] = "Veľkonočný pondelok" self[date(year, MAY, 1)] = "Sviatok práce" diff --git a/holidays/countries/slovenia.py b/holidays/countries/slovenia.py index d86a17b3e..93c3f9c65 100644 --- a/holidays/countries/slovenia.py +++ b/holidays/countries/slovenia.py @@ -48,8 +48,7 @@ def _populate(self, year): self[date(year, FEB, 8)] = "Prešernov dan" # Easter monday is the only easter related work-free day - easter_day = easter(year) - self[easter_day + rd(days=1)] = "Velikonočni ponedeljek" + self[easter(year) + rd(days=+1)] = "Velikonočni ponedeljek" # Day of uprising against occupation self[date(year, APR, 27)] = "dan upora proti okupatorju" diff --git a/holidays/countries/south_africa.py b/holidays/countries/south_africa.py index dc3736868..858d71af9 100644 --- a/holidays/countries/south_africa.py +++ b/holidays/countries/south_africa.py @@ -69,14 +69,13 @@ def _populate(self, year): if year > 1909: self[date(year, JAN, 1)] = "New Year's Day" - e = easter(year) - good_friday = e - rd(days=2) - easter_monday = e + rd(days=1) - self[good_friday] = "Good Friday" + easter_date = easter(year) + self[easter_date + rd(days=-2)] = "Good Friday" if year > 1979: - self[easter_monday] = "Family Day" + name = "Family Day" else: - self[easter_monday] = "Easter Monday" + name = "Easter Monday" + self[easter_date + rd(days=+1)] = name if 1909 < year < 1952: dec_16_name = "Dingaan's Day" @@ -129,8 +128,7 @@ def _populate(self, year): self[historic_workers_day] = "Workers' Day" if 1909 < year < 1994: - ascension_day = e + rd(days=40) - self[ascension_day] = "Ascension Day" + self[easter_date + rd(days=+40)] = "Ascension Day" if 1909 < year < 1952: self[date(year, MAY, 24)] = "Empire Day" diff --git a/holidays/countries/spain.py b/holidays/countries/spain.py index 3a6e73442..13470d413 100644 --- a/holidays/countries/spain.py +++ b/holidays/countries/spain.py @@ -13,7 +13,6 @@ from dateutil.easter import easter from dateutil.relativedelta import relativedelta as rd -from dateutil.relativedelta import TH, FR, MO from holidays.constants import ( SUN, @@ -70,6 +69,8 @@ def _populate(self, year): self._is_observed(date(year, JAN, 1), "Año nuevo") self._is_observed(date(year, JAN, 6), "Epifanía del Señor") + easter_date = easter(year) + if ( year < 2015 and self.subdiv @@ -118,16 +119,16 @@ def _populate(self, year): elif year >= 2022 and self.subdiv and self.subdiv == "VC": self._is_observed(date(year, MAR, 19), "San José") if year != 2022 and self.subdiv not in {"CT", "VC"}: - self[easter(year) + rd(weeks=-1, weekday=TH)] = "Jueves Santo" + self[easter_date + rd(days=-3)] = "Jueves Santo" elif year == 2022 and self.subdiv and self.subdiv not in {"CT"}: - self[easter(year) + rd(weeks=-1, weekday=TH)] = "Jueves Santo" - self[easter(year) + rd(weeks=-1, weekday=FR)] = "Viernes Santo" + self[easter_date + rd(days=-3)] = "Jueves Santo" + self[easter_date + rd(days=-2)] = "Viernes Santo" if ( 2022 == year and self.subdiv and self.subdiv in {"CT", "IB", "NC", "PV", "RI", "VC"} ): - self[easter(year) + rd(weekday=MO)] = "Lunes de Pascua" + self[easter_date + rd(days=+1)] = "Lunes de Pascua" elif 2022 > year and self.subdiv in { "CM", "CT", @@ -136,7 +137,7 @@ def _populate(self, year): "PV", "VC", }: - self[easter(year) + rd(weekday=MO)] = "Lunes de Pascua" + self[easter(year) + rd(days=+1)] = "Lunes de Pascua" if 2022 != year: self._is_observed(date(year, MAY, 1), "Día del Trabajador") diff --git a/holidays/countries/sweden.py b/holidays/countries/sweden.py index a2eac819f..450708216 100644 --- a/holidays/countries/sweden.py +++ b/holidays/countries/sweden.py @@ -78,14 +78,14 @@ def _populate(self, year): self[date(year, DEC, 31)] = "Nyårsafton" # ========= Moving holidays ========= - easter_day = easter(year) - self[easter_day + rd(days=-2)] = "Långfredagen" - self[easter_day] = "Påskdagen" - self[easter_day + rd(days=+1)] = "Annandag påsk" - self[easter_day + rd(days=+39)] = "Kristi himmelsfärdsdag" - self[easter_day + rd(days=+49)] = "Pingstdagen" + easter_date = easter(year) + self[easter_date + rd(days=-2)] = "Långfredagen" + self[easter_date] = "Påskdagen" + self[easter_date + rd(days=+1)] = "Annandag påsk" + self[easter_date + rd(days=+39)] = "Kristi himmelsfärdsdag" + self[easter_date + rd(days=+49)] = "Pingstdagen" if year <= 2004: - self[easter_day + rd(days=+50)] = "Annandag pingst" + self[easter_date + rd(days=+50)] = "Annandag pingst" # Source: # https://sv.wikipedia.org/wiki/Midsommarafton diff --git a/holidays/countries/switzerland.py b/holidays/countries/switzerland.py index c3ac07ec7..17961e8b5 100644 --- a/holidays/countries/switzerland.py +++ b/holidays/countries/switzerland.py @@ -84,22 +84,23 @@ def _populate(self, year): if self.subdiv in {"NW", "SZ", "TI", "UR", "VS"}: self[date(year, MAR, 19)] = "Josefstag" + easter_date = easter(year) # Näfelser Fahrt (first Thursday in April but not in Holy Week) if self.subdiv == "GL" and year >= 1835: if (date(year, APR, 1) + rd(weekday=FR)) != ( - easter(year) - rd(days=2) + easter_date + rd(days=-2) ): self[date(year, APR, 1) + rd(weekday=TH)] = "Näfelser Fahrt" else: self[date(year, APR, 8) + rd(weekday=TH)] = "Näfelser Fahrt" # it's a Holiday on a Sunday - self[easter(year)] = "Ostern" + self[easter_date] = "Ostern" # VS don't have easter if self.subdiv != "VS": - self[easter(year) - rd(days=2)] = "Karfreitag" - self[easter(year) + rd(weekday=MO)] = "Ostermontag" + self[easter_date + rd(days=-2)] = "Karfreitag" + self[easter_date + rd(days=+1)] = "Ostermontag" if self.subdiv in { "BL", @@ -114,12 +115,12 @@ def _populate(self, year): }: self[date(year, MAY, 1)] = "Tag der Arbeit" - self[easter(year) + rd(days=39)] = "Auffahrt" + self[easter_date + rd(days=+39)] = "Auffahrt" # it's a Holiday on a Sunday - self[easter(year) + rd(days=49)] = "Pfingsten" + self[easter_date + rd(days=+49)] = "Pfingsten" - self[easter(year) + rd(days=50)] = "Pfingstmontag" + self[easter_date + rd(days=+50)] = "Pfingstmontag" if self.subdiv in { "AI", @@ -133,7 +134,7 @@ def _populate(self, year): "VS", "ZG", }: - self[easter(year) + rd(days=60)] = "Fronleichnam" + self[easter_date + rd(days=+60)] = "Fronleichnam" if self.subdiv == "JU": self[date(year, JUN, 23)] = "Fest der Unabhängigkeit" diff --git a/holidays/countries/ukraine.py b/holidays/countries/ukraine.py index f56a0e746..ebc773860 100644 --- a/holidays/countries/ukraine.py +++ b/holidays/countries/ukraine.py @@ -11,7 +11,7 @@ from datetime import date -from dateutil.easter import EASTER_ORTHODOX, easter +from dateutil.easter import easter, EASTER_ORTHODOX from dateutil.relativedelta import relativedelta as rd from holidays.constants import ( @@ -89,11 +89,11 @@ def _populate(self, year): if year >= 1991: # Easter - dt = easter(year, method=EASTER_ORTHODOX) - self[dt] = "Великдень (Пасха)" + easter_date = easter(year, method=EASTER_ORTHODOX) + self[easter_date] = "Великдень (Пасха)" # Holy trinity - self[dt + rd(days=49)] = "Трійця" + self[easter_date + rd(days=+49)] = "Трійця" # Labour Day name = "День міжнародної солідарності трудящих" diff --git a/holidays/countries/united_kingdom.py b/holidays/countries/united_kingdom.py index cdce57cf8..798e09908 100644 --- a/holidays/countries/united_kingdom.py +++ b/holidays/countries/united_kingdom.py @@ -13,7 +13,7 @@ from dateutil.easter import easter from dateutil.relativedelta import relativedelta as rd -from dateutil.relativedelta import MO, FR +from dateutil.relativedelta import MO from holidays.constants import ( MON, @@ -130,15 +130,16 @@ def _country_specific(self, year: int) -> None: # UnitedKingdom exclusive holidays + easter_date = easter(year) # Good Friday - self[easter(year) + rd(weekday=FR(-1))] = "Good Friday" + self[easter_date + rd(days=-2)] = "Good Friday" # Easter Monday if self.subdiv != "Scotland": name = "Easter Monday" if self.subdiv == "UK": name += " [England/Wales/Northern Ireland]" - self[easter(year) + rd(weekday=MO)] = name + self[easter_date + rd(days=+1)] = name # May Day bank holiday (first Monday in May) if year >= 1978: diff --git a/holidays/countries/united_states.py b/holidays/countries/united_states.py index 0d78ee73e..5ca324b25 100644 --- a/holidays/countries/united_states.py +++ b/holidays/countries/united_states.py @@ -216,9 +216,10 @@ def _populate(self, year): elif self.subdiv in {"PR", "VI"}: self[date(year, FEB, 1) + rd(weekday=MO(+3))] = name + easter_date = easter(year) # Mardi Gras if self.subdiv == "LA" and year >= 1857: - self[easter(year) + rd(days=-47)] = "Mardi Gras" + self[easter_date + rd(days=-47)] = "Mardi Gras" # Guam Discovery Day if self.subdiv == "GU" and year >= 1970: @@ -297,7 +298,7 @@ def _populate(self, year): # Holy Thursday if self.subdiv == "VI": - self[easter(year) + rd(weekday=TH(-1))] = "Holy Thursday" + self[easter_date + rd(days=-3)] = "Holy Thursday" # Good Friday if self.subdiv in { @@ -314,11 +315,11 @@ def _populate(self, year): "TX", "VI", }: - self[easter(year) + rd(weekday=FR(-1))] = "Good Friday" + self[easter_date + rd(days=-2)] = "Good Friday" # Easter Monday if self.subdiv == "VI": - self[easter(year) + rd(weekday=MO)] = "Easter Monday" + self[easter_date + rd(days=+1)] = "Easter Monday" # Confederate Memorial Day name = "Confederate Memorial Day" diff --git a/holidays/countries/venezuela.py b/holidays/countries/venezuela.py index 69e058485..198b2acea 100644 --- a/holidays/countries/venezuela.py +++ b/holidays/countries/venezuela.py @@ -41,17 +41,18 @@ def _populate(self, year): self[date(year, JAN, 1)] = "Año Nuevo [New Year's]" + easter_date = easter(year) self[ - easter(year) - rd(days=48) + easter_date + rd(days=-48) ] = "Lunes de Carnaval [Monday of Carnival]" self[ - easter(year) - rd(days=47) + easter_date + rd(days=-47) ] = "Martes de Carnaval [Tuesday of Carnival]" - self[easter(year) - rd(days=3)] = "Jueves Santo [Maundy Thursday]" + self[easter_date + rd(days=-3)] = "Jueves Santo [Maundy Thursday]" - self[easter(year) - rd(days=2)] = "Viernes Santo [Good Friday]" + self[easter_date + rd(days=-2)] = "Viernes Santo [Good Friday]" # Note: not sure about the start year, but this event happened in 1811 if year >= 1811: diff --git a/holidays/countries/zambia.py b/holidays/countries/zambia.py index 55bf04e59..d603f9afd 100644 --- a/holidays/countries/zambia.py +++ b/holidays/countries/zambia.py @@ -70,7 +70,7 @@ def _populate(self, year): easter_date = easter(year) self[easter_date + rd(days=-2)] = "Good Friday" self[easter_date + rd(days=-1)] = "Holy Saturday" - self[easter_date + rd(days=1)] = "Easter Monday" + self[easter_date + rd(days=+1)] = "Easter Monday" if year >= 2022: self[date(year, APR, 28)] = "Kenneth Kaunda Day" diff --git a/holidays/countries/zimbabwe.py b/holidays/countries/zimbabwe.py index a9b0b85d4..e53f68d2b 100644 --- a/holidays/countries/zimbabwe.py +++ b/holidays/countries/zimbabwe.py @@ -39,13 +39,10 @@ def _populate(self, year): date(year, FEB, 21) ] = "Robert Gabriel Mugabe National Youth Day" - e = easter(year) - good_friday = e - rd(days=2) - easter_saturday = e - rd(days=1) - easter_monday = e + rd(days=1) - self[good_friday] = "Good Friday" - self[easter_saturday] = "Easter Saturday" - self[easter_monday] = "Easter Monday" + easter_date = easter(year) + self[easter_date + rd(days=-2)] = "Good Friday" + self[easter_date + rd(days=-1)] = "Easter Saturday" + self[easter_date + rd(days=+1)] = "Easter Monday" self[date(year, APR, 18)] = "Independence Day" diff --git a/test/countries/test_uruguay.py b/test/countries/test_uruguay.py index 6a01f8e30..825c36267 100644 --- a/test/countries/test_uruguay.py +++ b/test/countries/test_uruguay.py @@ -134,7 +134,7 @@ def test_carnival_day(self): ) def test_holy_week_day(self): - for dt in ( + for dt, name in ( ( date(2021, 4, 1), "Jueves Santo [Holy Thursday]", @@ -145,8 +145,8 @@ def test_holy_week_day(self): ), (date(2021, 4, 4), "Día de Pascuas [Easter Day]"), ): - self.assertIn(dt[0], self.holidays) - self.assertEqual(self.holidays[dt[0]], dt[1]) + self.assertIn(dt, self.holidays) + self.assertEqual(self.holidays[dt], name) def test_desembarco_de_los_33_orientales(self): for dt in ( From 7a883c3bbd3d32384b2937200d8d0b7a3e50679f Mon Sep 17 00:00:00 2001 From: Jason Jensen Date: Sun, 4 Dec 2022 09:21:54 -0500 Subject: [PATCH 035/138] Canada: make observed New Year's Day fall on or after the holiday (#811) --- holidays/countries/canada.py | 8 ++------ test/countries/test_canada.py | 4 +++- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/holidays/countries/canada.py b/holidays/countries/canada.py index 9c4102aac..7a3e70544 100644 --- a/holidays/countries/canada.py +++ b/holidays/countries/canada.py @@ -75,12 +75,8 @@ def _populate(self, year): # New Year's Day name = "New Year's Day" self[date(year, JAN, 1)] = name - if self.observed and date(year, JAN, 1).weekday() == SUN: - self[date(year, JAN, 1) + rd(days=+1)] = name + " (Observed)" - # The following year's observed New Year's Day can be in this year - # when it falls on a Friday (Jan 1st is a Saturday). - if self.observed and date(year, DEC, 31).weekday() == FRI: - self[date(year, DEC, 31)] = name + " (Observed)" + if self.observed and date(year, JAN, 1).weekday() in WEEKEND: + self[date(year, JAN, 1) + rd(weekday=MO)] = name + " (Observed)" # Family Day / Louis Riel Day (MB) / Islander Day (PE) # / Heritage Day (NS, YT) diff --git a/test/countries/test_canada.py b/test/countries/test_canada.py index d70744508..12253a6a1 100644 --- a/test/countries/test_canada.py +++ b/test/countries/test_canada.py @@ -24,9 +24,11 @@ def setUp(self): def test_new_years(self): self.assertNotIn(date(1866, 12, 31), self.holidays) self.assertNotIn(date(2010, 12, 31), self.holidays) + self.assertNotIn(date(2011, 1, 3), self.holidays) self.assertNotIn(date(2017, 1, 2), self.holidays) self.holidays.observed = True - self.assertIn(date(2010, 12, 31), self.holidays) + self.assertNotIn(date(2010, 12, 31), self.holidays) + self.assertIn(date(2011, 1, 3), self.holidays) self.assertIn(date(2017, 1, 2), self.holidays) self.holidays.observed = False for year in range(1900, 2100): From 9503fcfa1cb6aba81ef6c10669c78e0995c3ef2d Mon Sep 17 00:00:00 2001 From: dr-prodigy Date: Sun, 4 Dec 2022 15:23:03 +0100 Subject: [PATCH 036/138] CHANGES sync --- CHANGES | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGES b/CHANGES index 5614e0629..a16aa0894 100644 --- a/CHANGES +++ b/CHANGES @@ -6,6 +6,7 @@ Released ???????? ??, ???? - Code refactoring #801 (arkid15r) - Pre-commit reviews #786, #795 (KJhellico, arkid15r, dr-p) - Import cleanup, flake8 settings review #792 (arkid15r, KJhellico, dr-p) +- Easter holidays refactoring and unification #803 (KJhellico) - Special holidays refactoring for 13 countries #796 (arkid15r, KJhellico) - Support for Indonesia #787 (KJhellico) - Korea renamed to South Korea #797 (arkid15r) @@ -13,6 +14,8 @@ Released ???????? ??, ???? - Korea fixes #791 (KJhellico) + test optimizations (dr-p) - Zambia: optimizations and refactoring #798 (KJhellico) - Vietnam: optimizations and refactoring #799 (KJhellico) +- Uruguay updates #809 (KJhellico) +- Canada fixes #811 (jasonjensen) Version 0.17.2 ============== From 755401177bcb6bc3d0b80469ddaebbdd017fa147 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 4 Dec 2022 15:23:51 +0100 Subject: [PATCH 037/138] Bump pypa/gh-action-pypi-publish from 1.5.1 to 1.5.2 (#816) --- .github/workflows/ci-cd.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml index 110d6361c..65435abd2 100644 --- a/.github/workflows/ci-cd.yml +++ b/.github/workflows/ci-cd.yml @@ -80,7 +80,7 @@ jobs: python setup.py sdist bdist_wheel - name: Publish package - uses: pypa/gh-action-pypi-publish@v1.5.1 + uses: pypa/gh-action-pypi-publish@v1.5.2 with: user: __token__ password: ${{ secrets.pypi_password }} From cdcd4a506060af07ff70923dc22e5339df0cf8bb Mon Sep 17 00:00:00 2001 From: Arkadii Yakovets Date: Mon, 5 Dec 2022 17:12:25 -0800 Subject: [PATCH 038/138] Address comments (use `self._is_weekend()`). --- holidays/financial/ny_stock_exchange.py | 6 +++--- holidays/holiday_base.py | 5 +---- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/holidays/financial/ny_stock_exchange.py b/holidays/financial/ny_stock_exchange.py index e33ca1b79..bc0ae88d7 100644 --- a/holidays/financial/ny_stock_exchange.py +++ b/holidays/financial/ny_stock_exchange.py @@ -12,7 +12,7 @@ from datetime import date, timedelta from dateutil.easter import easter -from dateutil.relativedelta import MO, TU, WE, TH, FR, SA, SU +from dateutil.relativedelta import MO, TU, WE, TH, FR from dateutil.relativedelta import relativedelta as rd from holidays.constants import JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP @@ -181,7 +181,7 @@ def _populate(self, year): begin + timedelta(days=n) for n in range((end - begin).days + 1) ): - if d.weekday() in {SA.weekday, SU.weekday}: + if self._is_weekend(d): continue self[d] = "World War I" elif year == 1917: @@ -213,7 +213,7 @@ def _populate(self, year): begin + timedelta(days=n) for n in range((end - begin).days + 1) ): - if d.weekday() in {SA.weekday, SU.weekday}: + if self._is_weekend(d): continue self[d] = "Special Bank Holiday" elif year == 1945: diff --git a/holidays/holiday_base.py b/holidays/holiday_base.py index c4b7b8856..54b156695 100644 --- a/holidays/holiday_base.py +++ b/holidays/holiday_base.py @@ -595,10 +595,7 @@ def _is_weekend(self, *args): Returns True if date's week day is a weekend day. Returns False otherwise. """ - if len(args) == 1: - dt = args[0] - else: - dt = date(*args) + dt = args[0] if len(args) == 1 else date(*args) return dt.weekday() in self.weekend From e9714ee706bcf20d8139d97b3baabf62a53a82b7 Mon Sep 17 00:00:00 2001 From: Arkadii Yakovets Date: Thu, 8 Dec 2022 00:41:45 -0800 Subject: [PATCH 039/138] Refactor tests. Introduce `common.TestCase`. (#800) * Refactor tests. Introduce `common.TestCase`. The `TestCase` class simplifies country holiday tests by providing ready to use testing methods. It also reduces code clutter, improves tests readability. * Add instance eq. assertion. Merged by: dr-prodigy <28216945+dr-prodigy@users.noreply.github.com> --- test/common.py | 172 +++++++++++++++++++ test/countries/base.py | 36 ---- test/countries/test_angola.py | 114 +++++++----- test/countries/test_argentina.py | 286 +++++++++++++++++++++---------- test/countries/test_honduras.py | 171 +++++++++--------- test/countries/test_norway.py | 168 ++++++++++-------- test/countries/test_sweden.py | 192 ++++++++++++--------- 7 files changed, 721 insertions(+), 418 deletions(-) create mode 100644 test/common.py delete mode 100644 test/countries/base.py diff --git a/test/common.py b/test/common.py new file mode 100644 index 000000000..20d021d0e --- /dev/null +++ b/test/common.py @@ -0,0 +1,172 @@ +# 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 (c) 2017-2022 +# ryanss (c) 2014-2017 +# Website: https://github.com/dr-prodigy/python-holidays +# License: MIT (see LICENSE file) +# Copyright: Arkadii Yakovets , 2022 + +import unittest + +from dateutil.parser import parse +from dateutil.relativedelta import SU + +from holidays import HolidayBase + + +class TestCase(unittest.TestCase): + """Base class for python-holiday test cases.""" + + def parse_arguments(self, args): + if issubclass(args[0].__class__, HolidayBase): + return args[0], args[1:] + + if not hasattr(self, "holidays"): + raise ValueError( + "Either pass country holidays object (`HolidayBase` subclass) " + "as a first argument or initialize `self.holidays` in the " + "`setUp()` method." + ) + + return self.holidays, args + + def verify_type(self, holidays): + self.assertTrue( + issubclass(holidays.__class__, HolidayBase), + "`holidays` object must be a subclass of `HolidayBase`", + ) + + def assertCountryAliases(self, cls, *aliases): + """Asserts country aliases match.""" + + self.assertTrue( + issubclass(cls, HolidayBase), + "Country holidays object must be a subclass of `HolidayBase`", + ) + + has_alpha_2 = False + has_alpha_3 = False + for alias in aliases: + self.assertTrue( + issubclass(alias, cls), + "Country alias object must be a subclass of the " + "main country class.", + ) + self.assertEqual(alias(), cls()) + + class_name = alias.__name__ + if len(class_name) == 2: + has_alpha_2 = True + elif len(class_name) == 3: + has_alpha_3 = True + else: + raise ValueError( + "Alias class name must match either alpha-2 or alpha-3 " + f"country code. Got: `{class_name}`." + ) + + self.assertTrue( + has_alpha_2, "Country alpha-2 code must also be included." + ) + self.assertTrue( + has_alpha_3, "Country alpha-3 code must also be included." + ) + self.assertEqual( + 2, + len(aliases), + "Please include alpha-2 and alpha-3 country code aliases.", + ) + + def assertNoHolidays(self, holidays): + """Asserts holidays dict is empty.""" + + self.verify_type(holidays) + + self.assertEqual(0, len(holidays)) + self.assertFalse(holidays) + + def assertHolidaysEqual(self, holidays, *expected_holidays): + """Asserts holidays exactly match expected holidays.""" + + self.verify_type(holidays) + + self.assertEqual(len(holidays), len(expected_holidays)) + # Check one by one for descriptive error messages. + for dt, name in expected_holidays: + self.assertIn(dt, holidays) + self.assertEqual(name, holidays[dt]) + + def assertHolidayDatesEqual(self, holidays, *dates): + """Asserts holiday dates exactly match expected dates.""" + + self.verify_type(holidays) + + self.assertEqual(len(dates), len(holidays.keys())) + for date in dates: # Check one by one for descriptive error messages. + self.assertIn(date, holidays) + + def assertHoliday(self, *args): + """Asserts each date is a holiday.""" + + holidays, dates = self.parse_arguments(args) + for dt in dates: + self.assertIn(dt, holidays) + + def assertNoHoliday(self, *args): + """Asserts each date is not a holiday.""" + + holidays, dates = self.parse_arguments(args) + for dt in dates: + self.assertNotIn(dt, holidays) + + +class SundayHolidays(TestCase): + """Common class to test countries with Sundays as a holidays.""" + + def assertSundays(self, cls): + holidays = cls(years=1989, include_sundays=True) + self.assertHoliday( + holidays, + "1989-12-31", + ) + self.assertEqual( + 53, len([s for s in holidays if s.weekday() == SU.weekday]) + ) + + holidays = cls(years=2032, include_sundays=True) + self.assertHoliday( + holidays, + "2032-01-04", + ) + self.assertEqual( + 52, len([s for s in holidays if s.weekday() == SU.weekday]) + ) + + self.assertNoHolidays(cls(include_sundays=True)) + + for sunday in ( + "1989-12-31", + "2017-02-05", + "2017-02-12", + "2032-02-29", + ): + self.assertEqual(parse(sunday).weekday(), SU.weekday) + self.assertHoliday(holidays, sunday) + + for non_sunday in ( + "2001-05-16", + "2001-05-18", + "2016-12-27", + "2016-12-28", + "2017-02-06", + "2017-02-07", + "2017-02-08", + "2017-02-09", + "2017-02-10", + ): + self.assertNotEqual(parse(non_sunday).weekday(), SU.weekday) + self.assertNoHoliday(holidays, non_sunday) diff --git a/test/countries/base.py b/test/countries/base.py deleted file mode 100644 index 47a230a0c..000000000 --- a/test/countries/base.py +++ /dev/null @@ -1,36 +0,0 @@ -from dateutil.parser import parse -from dateutil.relativedelta import SU - - -class SundayHolidays: - """Common class to test countries with Sundays as a holidays.""" - - def test_sundays(self, cls): - h = cls(years=1989, include_sundays=True) - self.assertIn("1989-12-31", h) - self.assertEqual(53, len([s for s in h if s.weekday() == SU.weekday])) - - h = cls(years=2032, include_sundays=True) - self.assertIn("2032-01-04", h) - self.assertEqual(52, len([s for s in h if s.weekday() == SU.weekday])) - - h = cls(include_sundays=True) - self.assertEqual(0, len(h)) - - for sunday in ("1989-12-31", "2017-02-05", "2017-02-12", "2032-02-29"): - self.assertEqual(parse(sunday).weekday(), SU.weekday) - self.assertIn(sunday, h) - - for non_sunday in ( - "2001-05-16", - "2001-05-18", - "2016-12-27", - "2016-12-28", - "2017-02-06", - "2017-02-07", - "2017-02-08", - "2017-02-09", - "2017-02-10", - ): - self.assertNotEqual(parse(non_sunday).weekday(), SU.weekday) - self.assertNotIn(non_sunday, h) diff --git a/test/countries/test_angola.py b/test/countries/test_angola.py index 88e21c503..489cbbbc9 100644 --- a/test/countries/test_angola.py +++ b/test/countries/test_angola.py @@ -9,69 +9,91 @@ # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) -import unittest -from datetime import date +from test.common import TestCase -import holidays +from holidays.countries.angola import Angola, AO, AGO -class TestAngola(unittest.TestCase): +class TestAngola(TestCase): def setUp(self): - self.holidays = holidays.AO() + self.holidays = Angola() - def test_new_years(self): - self.assertIn("1975-01-01", self.holidays) - self.assertIn("2017-01-01", self.holidays) - self.assertIn("2999-01-01", self.holidays) - self.assertIn("2017-01-02", self.holidays) # sunday + def test_country_aliases(self): + self.assertCountryAliases(Angola, AO, AGO) def test_carnival(self): - self.assertIn("1994-02-15", self.holidays) - self.assertIn("2002-02-12", self.holidays) - self.assertIn("2010-02-16", self.holidays) - self.assertIn("2017-02-28", self.holidays) - self.assertIn("2018-02-13", self.holidays) - self.assertIn("2019-03-05", self.holidays) - self.assertIn("2020-02-25", self.holidays) - self.assertIn("2021-02-16", self.holidays) - self.assertIn("2022-03-01", self.holidays) + self.assertHoliday( + "1994-02-15", + "2002-02-12", + "2010-02-16", + "2017-02-28", + "2018-02-13", + "2019-03-05", + "2020-02-25", + "2021-02-16", + "2022-03-01", + ) def test_easter(self): - self.assertIn(date(2017, 4, 14), self.holidays) - self.assertIn(date(2020, 4, 10), self.holidays) - self.assertIn(date(1994, 4, 1), self.holidays) - - def test_static(self): - self.assertIn("2004-03-08", self.holidays) - self.assertIn("2020-03-23", self.holidays) + self.assertHoliday( + "1994-04-01", + "2017-04-14", + "2020-04-10", + ) def test_long_weekend(self): - self.assertIn("2020-02-03", self.holidays) - self.assertIn("2019-04-05", self.holidays) - self.assertIn("2050-03-07", self.holidays) - - def test_not_holiday(self): - self.assertNotIn("2016-12-28", self.holidays) - self.assertNotIn("2015-03-02", self.holidays) - self.assertNotIn("2018-03-23", self.holidays) + self.assertHoliday( + "2019-04-05", + "2020-02-03", + "2050-03-07", + ) def test_national_hero_day(self): - for year in range(1980, 1979): - self.assertNotIn(date(year, 9, 17), self.holidays) - for year in range(1980, 2030): - self.assertIn(date(year, 9, 17), self.holidays) + self.assertHoliday(*[f"{year}-09-17" for year in range(1980, 2030)]) + + self.assertNoHoliday(*[f"{year}-09-17" for year in range(1975, 1980)]) def test_national_liberation_day(self): - for year in range(1990, 2018): - self.assertNotIn(date(year, 3, 23), self.holidays) - for year in range(2019, 2030): - self.assertIn(date(year, 3, 23), self.holidays) + self.assertHoliday(*[f"{year}-03-23" for year in range(2019, 2030)]) + + # Not a holiday before 2019. + self.assertNoHoliday(*[f"{year}-03-23" for year in range(1990, 2019)]) + + def test_new_years_day(self): + self.assertHoliday( + "1975-01-01", + "2017-01-01", + "2017-01-02", # Sunday. + "2999-01-01", + ) + + def test_not_holidays(self): + self.assertNoHoliday( + "2015-03-02", + "2016-12-28", + "2018-03-23", + ) def test_pre_1975(self): - # Holidays are defined since 1975. - self.assertNotIn("1974-01-01", self.holidays) - self.assertEqual(0, len(holidays.AO(years=1974))) + self.assertNoHolidays(Angola(years=1974)) + + def test_2022(self): + self.assertHolidaysEqual( + Angola(observed=False, years=2022), + ("2022-01-01", "Ano novo"), + ("2022-02-04", "Dia do Início da Luta Armada"), + ("2022-03-01", "Carnaval"), + ("2022-03-08", "Dia Internacional da Mulher"), + ("2022-03-23", "Dia da Libertação da África Austral"), + ("2022-04-04", "Dia da Paz e Reconciliação"), + ("2022-04-15", "Sexta-feira Santa"), + ("2022-05-01", "Dia Mundial do Trabalho"), + ("2022-09-17", "Dia do Herói Nacional"), + ("2022-11-02", "Dia dos Finados"), + ("2022-11-11", "Dia da Independência"), + ("2022-12-25", "Dia de Natal e da Família"), + ) def test_observed(self): - for _, name in holidays.AO(observed=False, years=2020).items(): + for _, name in Angola(observed=False, years=2020).items(): self.assertNotIn("Observed", name) diff --git a/test/countries/test_argentina.py b/test/countries/test_argentina.py index 8aacad71f..b715cbcf9 100644 --- a/test/countries/test_argentina.py +++ b/test/countries/test_argentina.py @@ -9,161 +9,267 @@ # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) -import unittest from datetime import date +from test.common import TestCase from dateutil.relativedelta import relativedelta -import holidays +from holidays.constants import MAY, JUN, JUL, AUG, OCT +from holidays.countries.argentina import Argentina, AR, ARG -class TestAR(unittest.TestCase): +class TestArgentina(TestCase): def setUp(self): - self.holidays = holidays.AR(observed=True) + self.holidays = Argentina() - def test_new_years(self): + def test_country_aliases(self): + self.assertCountryAliases(Argentina, AR, ARG) + + def test_new_years_day(self): self.holidays.observed = False - self.assertNotIn(date(2010, 12, 31), self.holidays) - self.assertNotIn(date(2017, 1, 2), self.holidays) + self.assertNoHoliday( + "2010-12-31", + "2017-01-02", + ) + self.holidays.observed = True - self.assertIn(date(2017, 1, 1), self.holidays) + self.assertHoliday( + "2017-01-01", + ) + for year in range(1900, 2100): dt = date(year, 1, 1) - self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertHoliday(dt) + self.assertNoHoliday( + dt + relativedelta(days=-1), + dt + relativedelta(days=+1), + ) def test_carnival_day(self): - for dt in [ - date(2018, 2, 12), - date(2018, 2, 13), - date(2017, 2, 27), - date(2017, 2, 28), - date(2016, 2, 8), - date(2016, 2, 9), - ]: - self.assertIn(dt, self.holidays) + self.assertHoliday( + "2016-02-08", + "2016-02-09", + "2017-02-27", + "2017-02-28", + "2018-02-12", + "2018-02-13", + ) def test_memory_national_day(self): self.holidays.observed = False - self.assertNotIn(date(1907, 3, 24), self.holidays) - self.assertNotIn(date(2002, 3, 24), self.holidays) + self.assertNoHoliday( + "1907-03-24", + "2002-03-24", + ) + self.holidays.observed = True - for dt in [date(2018, 3, 24), date(2017, 3, 24), date(2016, 3, 24)]: - self.assertIn(dt, self.holidays) + self.assertHoliday( + "2018-03-24", + "2017-03-24", + "2016-03-24", + ) def test_holy_week_day(self): - for dt in [ - date(2018, 3, 29), - date(2018, 3, 30), - date(2017, 4, 13), - date(2017, 4, 14), - date(2016, 3, 24), - date(2016, 3, 25), - ]: - self.assertIn(dt, self.holidays) + self.assertHoliday( + "2016-03-24", + "2016-03-25", + "2017-04-13", + "2017-04-14", + "2018-03-29", + "2018-03-30", + ) def test_malvinas_war_day(self): - for year in range(1900, 2100): - dt = date(year, 4, 2) - self.assertIn(dt, self.holidays) + self.assertHoliday(*[f"{year}-04-02" for year in range(1900, 2100)]) def test_labor_day(self): self.holidays.observed = False - self.assertNotIn(date(2010, 4, 30), self.holidays) - self.assertNotIn(date(2011, 5, 2), self.holidays) + self.assertNoHoliday( + "2010-04-30", + "2011-05-02", + ) + self.holidays.observed = True - self.assertIn(date(1922, 5, 1), self.holidays) + self.assertHoliday( + "1922-05-01", + ) + for year in range(1900, 2100): - dt = date(year, 5, 1) - self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + dt = date(year, MAY, 1) + self.assertHoliday(dt) + self.assertNoHoliday( + dt + relativedelta(days=-1), + dt + relativedelta(days=+1), + ) def test_may_revolution_day(self): self.holidays.observed = False - self.assertNotIn(date(1930, 5, 25), self.holidays) - self.assertNotIn(date(2014, 5, 25), self.holidays) + self.assertNoHoliday( + "1930-05-25", + "2014-05-25", + ) + self.holidays.observed = True for year in range(1900, 2100): - dt = date(year, 5, 1) - self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + dt = date(year, MAY, 25) + self.assertHoliday(dt) + self.assertNoHoliday( + dt + relativedelta(days=-1), + dt + relativedelta(days=+1), + ) def test_guemes_day(self): for year in range(1900, 2100): - dt = date(year, 6, 17) - self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + dt = date(year, JUN, 17) + self.assertHoliday(dt) + self.assertNoHoliday( + dt + relativedelta(days=-1), + dt + relativedelta(days=+1), + ) def test_belgrano_day(self): for year in range(1900, 2100): - dt = date(year, 6, 20) - self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + dt = date(year, JUN, 20) + self.assertHoliday(dt) + self.assertNoHoliday( + dt + relativedelta(days=-1), + dt + relativedelta(days=+1), + ) def test_independence_day(self): self.holidays.observed = False - self.assertNotIn(date(2017, 7, 9), self.holidays) - self.assertNotIn(date(2011, 7, 9), self.holidays) + self.assertNoHoliday( + "2011-07-09", + "2017-07-09", + ) + self.holidays.observed = True - self.assertIn(date(2017, 7, 9), self.holidays) - self.assertIn(date(2011, 7, 9), self.holidays) + self.assertHoliday( + "2011-07-09", + "2017-07-09", + ) + for year in range(1900, 2100): - dt = date(year, 7, 9) - self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + dt = date(year, JUL, 9) + self.assertHoliday(dt) + self.assertNoHoliday( + dt + relativedelta(days=-1), + dt + relativedelta(days=+1), + ) def test_san_martin_day(self): self.holidays.observed = False - self.assertNotIn(date(1930, 8, 10), self.holidays) - self.assertNotIn(date(2008, 8, 10), self.holidays) + self.assertNoHoliday( + "1930-08-10", + "2008-08-10", + ) + self.holidays.observed = True for year in range(1900, 2100): - dt = date(year, 8, 17) - self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + dt = date(year, AUG, 17) + self.assertHoliday(dt) + self.assertNoHoliday( + dt + relativedelta(days=-1), + dt + relativedelta(days=+1), + ) def test_cultural_day(self): self.holidays.observed = False - self.assertNotIn(date(2014, 10, 12), self.holidays) - self.assertNotIn(date(1913, 10, 12), self.holidays) + self.assertNoHoliday( + "1913-10-12", + "2014-10-12", + ) + self.holidays.observed = True for year in range(1900, 2100): - dt = date(year, 10, 12) - self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + dt = date(year, OCT, 12) + self.assertHoliday(dt) + self.assertNoHoliday( + dt + relativedelta(days=-1), + dt + relativedelta(days=+1), + ) def test_national_sovereignty_day(self): for year in range(1900, 2100): dt = date(year, 11, 20) if year < 2010: - self.assertNotIn(dt, self.holidays) + self.assertNoHoliday(dt) else: - self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertHoliday(dt) + self.assertNoHoliday( + dt + relativedelta(days=-1), + dt + relativedelta(days=+1), + ) - def test_inmaculate_conception_day(self): + def test_immaculate_conception_day(self): self.holidays.observed = False - self.assertNotIn(date(1940, 12, 8), self.holidays) - self.assertNotIn(date(2013, 12, 8), self.holidays) + self.assertNoHoliday( + "1940-12-08", + "2013-12-08", + ) + self.holidays.observed = True for year in range(1900, 2100): dt = date(year, 12, 8) - self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertHoliday(dt) + self.assertNoHoliday( + dt + relativedelta(days=-1), + dt + relativedelta(days=+1), + ) def test_christmas(self): for year in range(1900, 2100): dt = date(year, 12, 25) - self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertHoliday(dt) + self.assertNoHoliday( + dt + relativedelta(days=-1), + dt + relativedelta(days=+1), + ) + + def test_2022(self): + self.assertHolidaysEqual( + Argentina(observed=False, years=2022), + ("2022-02-28", "Día de Carnaval [Carnival's Day]"), + ("2022-03-01", "Día de Carnaval [Carnival's Day]"), + ( + "2022-03-24", + "Día Nacional de la Memoria por la Verdad y la Justicia " + "[Memory's National Day for the Truth and Justice]", + ), + ( + "2022-04-14", + "Semana Santa (Jueves Santo) [Holy day (Holy Thursday)]", + ), + ( + "2022-04-15", + "Semana Santa (Viernes Santo) [Holy day (Holy Friday)]", + ), + ( + "2022-05-25", + "Día de la Revolucion de Mayo [May Revolution Day]", + ), + ( + "2022-06-17", + "Día Pase a la Inmortalidad del General Martín Miguel de " + "Güemes [Day Pass to the Immortality of General Martín Miguel " + "de Güemes]", + ), + ( + "2022-06-20", + "Día Pase a la Inmortalidad del General D. Manuel Belgrano " + "[Day Pass to the Immortality of General D. Manuel Belgrano]", + ), + ( + "2022-08-17", + "Día Pase a la Inmortalidad del General D. José de San Martin " + "[Day Pass to the Immortality of General D. José de San " + "Martin]", + ), + ( + "2022-10-12", + "Día del Respeto a la Diversidad Cultural " + "[Respect for Cultural Diversity Day]", + ), + ("2022-12-08", "La Inmaculada Concepción [Immaculate Conception]"), + ("2022-12-25", "Navidad [Christmas]"), + ) diff --git a/test/countries/test_honduras.py b/test/countries/test_honduras.py index 61950e56b..d8a8cb5c6 100644 --- a/test/countries/test_honduras.py +++ b/test/countries/test_honduras.py @@ -9,112 +9,99 @@ # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) -import unittest -from datetime import date, timedelta +from test.common import TestCase -import holidays -from holidays.constants import APR, DEC, JAN, MAR, MAY, OCT, SEP +from holidays.countries.honduras import Honduras, HN, HND -class TestHonduras(unittest.TestCase): +class TestHonduras(TestCase): def setUp(self): - self.holidays = holidays.Honduras(observed=True) + self.holidays = Honduras() - def _check_all_dates(self, year, expected_holidays): - start_date = date(year, 1, 1) - end_date = date(year, 12, 31) - delta = timedelta(days=1) - - while start_date <= end_date: - if start_date in expected_holidays: - self.assertIn(start_date, self.holidays) - else: - self.assertNotIn(start_date, self.holidays) - start_date += delta + def test_aliases(self): + self.assertCountryAliases(Honduras, HN, HND) def test_2014(self): - year = 2014 - expected_holidays = { - date(year, JAN, 1), - date(year, APR, 14), - date(year, APR, 17), - date(year, APR, 18), - date(year, APR, 19), - date(year, MAY, 1), - date(year, SEP, 15), - date(year, OCT, 3), - date(year, OCT, 12), - date(year, OCT, 21), - date(year, DEC, 25), - } - self._check_all_dates(year, expected_holidays) + self.assertHolidayDatesEqual( + Honduras(years=2014), + "2014-01-01", + "2014-04-14", + "2014-04-17", + "2014-04-18", + "2014-04-19", + "2014-05-01", + "2014-09-15", + "2014-10-03", + "2014-10-12", + "2014-10-21", + "2014-12-25", + ) def test_2016(self): # https://www.officeholidays.com/countries/honduras/2016 - year = 2016 - expected_holidays = { - date(year, JAN, 1), - date(year, MAR, 24), - date(year, MAR, 25), - date(year, MAR, 26), - date(year, APR, 14), - date(year, MAY, 1), - date(year, SEP, 15), - date(year, OCT, 5), - date(year, OCT, 6), - date(year, OCT, 7), - date(year, DEC, 25), - } - self._check_all_dates(year, expected_holidays) + self.assertHolidayDatesEqual( + Honduras(years=2016), + "2016-01-01", + "2016-03-24", + "2016-03-25", + "2016-03-26", + "2016-04-14", + "2016-05-01", + "2016-09-15", + "2016-10-05", + "2016-10-06", + "2016-10-07", + "2016-12-25", + ) def test_2021(self): # https://www.officeholidays.com/countries/honduras/2021 - year = 2021 - expected_holidays = { - date(year, JAN, 1), - date(year, APR, 1), - date(year, APR, 2), - date(year, APR, 3), - date(year, APR, 14), - date(year, MAY, 1), - date(year, SEP, 15), - date(year, OCT, 6), - date(year, OCT, 7), - date(year, OCT, 8), - date(year, DEC, 25), - } - self._check_all_dates(year, expected_holidays) + self.assertHolidayDatesEqual( + Honduras(years=2021), + "2021-01-01", + "2021-04-01", + "2021-04-02", + "2021-04-03", + "2021-04-14", + "2021-05-01", + "2021-09-15", + "2021-10-06", + "2021-10-07", + "2021-10-08", + "2021-12-25", + ) def test_2022(self): - # https://www.officeholidays.com/countries/honduras/2022 - year = 2022 - expected_holidays = { - date(year, JAN, 1), - date(year, APR, 14), - date(year, APR, 15), - date(year, APR, 16), - date(year, MAY, 1), - date(year, SEP, 15), - date(year, OCT, 5), - date(year, OCT, 6), - date(year, OCT, 7), - date(year, DEC, 25), - } - self._check_all_dates(year, expected_holidays) + self.assertHolidaysEqual( + Honduras(observed=False, years=2022), + ("2022-01-01", "Año Nuevo [New Year's Day]"), + ( + "2022-04-14", + "Día de las Américas [Panamerican Day], " + "Jueves Santo [Maundy Thursday]", + ), + ("2022-04-15", "Viernes Santo [Good Friday]"), + ("2022-04-16", "Sábado de Gloria [Holy Saturday]"), + ("2022-05-01", "Día del Trabajo [Labor Day]"), + ("2022-09-15", "Día de la Independencia [Independence Day]"), + ("2022-10-05", "Semana Morazánica [Morazan Weekend]"), + ("2022-10-06", "Semana Morazánica [Morazan Weekend]"), + ("2022-10-07", "Semana Morazánica [Morazan Weekend]"), + ("2022-12-25", "Navidad [Christmas]"), + ) def test_2025(self): - year = 2025 - expected_holidays = { - date(year, JAN, 1), - date(year, APR, 14), - date(year, APR, 17), - date(year, APR, 18), - date(year, APR, 19), - date(year, MAY, 1), - date(year, SEP, 15), - date(year, OCT, 1), - date(year, OCT, 2), - date(year, OCT, 3), - date(year, DEC, 25), - } - self._check_all_dates(year, expected_holidays) + self.assertHolidayDatesEqual( + Honduras(years=2025), + "2025-01-01", + "2025-04-14", + "2025-04-17", + "2025-04-18", + "2025-04-19", + "2025-05-01", + "2025-09-15", + "2025-10-01", + "2025-10-02", + "2025-10-03", + "2025-12-25", + ) diff --git a/test/countries/test_norway.py b/test/countries/test_norway.py index b925a0083..f9dc66f73 100644 --- a/test/countries/test_norway.py +++ b/test/countries/test_norway.py @@ -9,58 +9,69 @@ # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) -import unittest -from test.countries.base import SundayHolidays +from test.common import SundayHolidays from dateutil.parser import parse from dateutil.relativedelta import MO, SU -import holidays +from holidays.countries.norway import Norway, NO, NOR -class TestNorway(unittest.TestCase, SundayHolidays): +class TestNorway(SundayHolidays): def setUp(self): - self.holidays = holidays.Norway() + self.holidays = Norway() + + def test_country_aliases(self): + self.assertCountryAliases(Norway, NO, NOR) def test_new_years(self): - self.assertIn("1900-01-01", self.holidays) - self.assertIn("2017-01-01", self.holidays) - self.assertIn("2999-01-01", self.holidays) + self.assertHoliday( + "1900-01-01", + "2017-01-01", + "2999-01-01", + ) def test_easter(self): - self.assertIn("2000-04-20", self.holidays) - self.assertIn("2000-04-21", self.holidays) - self.assertIn("2000-04-23", self.holidays) - self.assertIn("2000-04-24", self.holidays) - - self.assertIn("2010-04-01", self.holidays) - self.assertIn("2010-04-02", self.holidays) - self.assertIn("2010-04-04", self.holidays) - self.assertIn("2010-04-05", self.holidays) - - self.assertIn("2021-04-01", self.holidays) - self.assertIn("2021-04-02", self.holidays) - self.assertIn("2021-04-04", self.holidays) - self.assertIn("2021-04-05", self.holidays) - - self.assertIn("2024-03-28", self.holidays) - self.assertIn("2024-03-29", self.holidays) - self.assertIn("2024-03-31", self.holidays) - self.assertIn("2024-04-01", self.holidays) + self.assertHoliday( + "2000-04-20", + "2000-04-21", + "2000-04-23", + "2000-04-24", + "2010-04-01", + "2010-04-02", + "2010-04-04", + "2010-04-05", + "2021-04-01", + "2021-04-02", + "2021-04-04", + "2021-04-05", + "2024-03-28", + "2024-03-29", + "2024-03-31", + "2024-04-01", + ) def test_workers_day(self): - self.assertNotIn("1900-05-01", self.holidays) - self.assertNotIn("1946-05-01", self.holidays) - self.assertIn("1947-05-01", self.holidays) - self.assertIn("2017-05-01", self.holidays) - self.assertIn("2999-05-01", self.holidays) + self.assertHoliday( + "1947-05-01", + "2017-05-01", + "2999-05-01", + ) + self.assertNoHoliday( + "1900-05-01", + "1946-05-01", + ) def test_constitution_day(self): - self.assertNotIn("1900-05-17", self.holidays) - self.assertNotIn("1946-05-17", self.holidays) - self.assertIn("1947-05-17", self.holidays) - self.assertIn("2017-05-17", self.holidays) - self.assertIn("2999-05-17", self.holidays) + self.assertHoliday( + "1947-05-17", + "2017-05-17", + "2999-05-17", + ) + self.assertNoHoliday( + "1900-05-17", + "1946-05-17", + ) def test_pentecost(self): pentecost_days = ( @@ -70,47 +81,60 @@ def test_pentecost(self): ) for day1, day2 in pentecost_days: - self.assertIn(day1, self.holidays) + self.assertHoliday(day1) self.assertEqual(parse(day1).weekday(), SU.weekday) - self.assertIn(day2, self.holidays) + self.assertHoliday(day2) self.assertEqual(parse(day2).weekday(), MO.weekday) def test_christmas(self): - self.assertIn("1901-12-25", self.holidays) - self.assertIn("1901-12-26", self.holidays) - - self.assertIn("2016-12-25", self.holidays) - self.assertIn("2016-12-26", self.holidays) - - self.assertIn("2500-12-25", self.holidays) - self.assertIn("2500-12-26", self.holidays) + self.assertHoliday( + "1901-12-25", + "1901-12-26", + "2016-12-25", + "2016-12-26", + "2500-12-25", + "2500-12-26", + ) def test_sundays(self): - """ - Sundays are considered holidays in Norway. - """ - - super().test_sundays(holidays.Norway) + self.assertSundays( + Norway + ) # Sundays are considered holidays in Norway. def test_not_holiday(self): - """ - Note: Sundays in Norway are considered holidays, - so make sure none of these are actually Sundays - - TODO: Should add more dates that are often confused for being a holiday - :return: - """ - self.assertNotIn("2017-02-06", self.holidays) - self.assertNotIn("2017-02-07", self.holidays) - self.assertNotIn("2017-02-08", self.holidays) - self.assertNotIn("2017-02-09", self.holidays) - self.assertNotIn("2017-02-10", self.holidays) - - self.assertNotIn("2001-12-24", self.holidays) - self.assertNotIn("2001-05-16", self.holidays) - self.assertNotIn("2001-05-18", self.holidays) - self.assertNotIn("1999-12-31", self.holidays) - self.assertNotIn("2016-12-31", self.holidays) - self.assertNotIn("2016-12-27", self.holidays) - self.assertNotIn("2016-12-28", self.holidays) + # TODO: Add more dates that are often confused for being a holiday. + + # Sundays in Norway are considered holidays, + # so make sure none of these are actually Sundays. + self.assertNoHoliday( + "2017-02-06", + "2017-02-07", + "2017-02-08", + "2017-02-09", + "2017-02-10", + "2001-12-24", + "2001-05-16", + "2001-05-18", + "1999-12-31", + "2016-12-31", + "2016-12-27", + "2016-12-28", + ) + + def test_2022(self): + self.assertHolidaysEqual( + Norway(observed=False, years=2022), + ("2022-01-01", "Første nyttårsdag"), + ("2022-04-14", "Skjærtorsdag"), + ("2022-04-15", "Langfredag"), + ("2022-04-17", "Første påskedag"), + ("2022-04-18", "Andre påskedag"), + ("2022-05-01", "Arbeidernes dag"), + ("2022-05-17", "Grunnlovsdag"), + ("2022-05-26", "Kristi himmelfartsdag"), + ("2022-06-05", "Første pinsedag"), + ("2022-06-06", "Andre pinsedag"), + ("2022-12-25", "Første juledag"), + ("2022-12-26", "Andre juledag"), + ) diff --git a/test/countries/test_sweden.py b/test/countries/test_sweden.py index 17472e66a..1bb28502c 100644 --- a/test/countries/test_sweden.py +++ b/test/countries/test_sweden.py @@ -9,73 +9,86 @@ # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) -import unittest -from test.countries.base import SundayHolidays +from test.common import SundayHolidays -import holidays +from holidays.countries.sweden import Sweden, SE, SWE -class TestSweden(unittest.TestCase, SundayHolidays): +class TestSweden(SundayHolidays): def setUp(self): - self.holidays = holidays.Sweden(include_sundays=False) + self.holidays = Sweden(include_sundays=False) + + def test_country_aliases(self): + self.assertCountryAliases(Sweden, SE, SWE) def test_new_years(self): - self.assertIn("1900-01-01", self.holidays) - self.assertIn("2017-01-01", self.holidays) - self.assertIn("2999-01-01", self.holidays) + self.assertHoliday( + "1900-01-01", + "2017-01-01", + "2999-01-01", + ) def test_easter(self): - self.assertNotIn("2000-04-20", self.holidays) - self.assertIn("2000-04-21", self.holidays) - self.assertIn("2000-04-23", self.holidays) - self.assertIn("2000-04-24", self.holidays) - - self.assertNotIn("2010-04-01", self.holidays) - self.assertIn("2010-04-02", self.holidays) - self.assertIn("2010-04-04", self.holidays) - self.assertIn("2010-04-05", self.holidays) - - self.assertNotIn("2021-04-01", self.holidays) - self.assertIn("2021-04-02", self.holidays) - self.assertIn("2021-04-04", self.holidays) - self.assertIn("2021-04-05", self.holidays) - - self.assertNotIn("2024-03-28", self.holidays) - self.assertIn("2024-03-29", self.holidays) - self.assertIn("2024-03-31", self.holidays) - self.assertIn("2024-04-01", self.holidays) + self.assertHoliday( + "2000-04-21", + "2000-04-23", + "2000-04-24", + "2010-04-02", + "2010-04-04", + "2010-04-05", + "2021-04-02", + "2021-04-04", + "2021-04-05", + "2024-03-29", + "2024-03-31", + "2024-04-01", + ) + self.assertNoHoliday( + "2000-04-20", + "2010-04-01", + "2021-04-01", + "2024-03-28", + ) def test_workers_day(self): - self.assertNotIn("1800-05-01", self.holidays) - self.assertNotIn("1879-05-01", self.holidays) - self.assertIn("1939-05-01", self.holidays) - self.assertIn("2017-05-01", self.holidays) - self.assertIn("2999-05-01", self.holidays) + self.assertHoliday( + "1939-05-01", + "2017-05-01", + "2999-05-01", + ) + self.assertNoHoliday( + "1800-05-01", + "1879-05-01", + ) def test_constitution_day(self): - self.assertNotIn("1900-06-06", self.holidays) - self.assertNotIn("2004-06-06", self.holidays) - self.assertIn("2005-06-06", self.holidays) - self.assertIn("2017-06-06", self.holidays) - self.assertIn("2999-06-06", self.holidays) + self.assertHoliday( + "2005-06-06", + "2017-06-06", + "2999-06-06", + ) + self.assertNoHoliday( + "1900-06-06", + "2004-06-06", + ) def test_pentecost(self): - self.assertIn("2000-06-11", self.holidays) - self.assertIn("2000-06-12", self.holidays) - - self.assertIn("2010-05-23", self.holidays) - self.assertNotIn("2010-05-24", self.holidays) - - self.assertIn("2021-05-23", self.holidays) - self.assertNotIn("2021-05-24", self.holidays) - - self.assertIn("2003-06-09", self.holidays) - - self.assertIn("2024-05-19", self.holidays) - self.assertNotIn("2024-05-20", self.holidays) + self.assertHoliday( + "2000-06-11", + "2000-06-12", + "2010-05-23", + "2021-05-23", + "2003-06-09", + "2024-05-19", + ) + self.assertNoHoliday( + "2010-05-24", + "2021-05-24", + "2024-05-20", + ) def test_midsommar(self): - for dt in [ + self.assertHoliday( "1950-06-23", "1950-06-24", "1951-06-23", @@ -94,46 +107,61 @@ def test_midsommar(self): "2021-06-26", "2022-06-24", "2022-06-25", - ]: - self.assertIn(dt, self.holidays) - - for dt in [ + ) + self.assertNoHoliday( "1952-06-20", "1952-06-21", "1953-06-23", "1953-06-24", "1954-06-23", "1954-06-24", - ]: - self.assertNotIn(dt, self.holidays) + ) def test_christmas(self): - self.assertIn("1901-12-25", self.holidays) - self.assertIn("1901-12-26", self.holidays) - - self.assertIn("2016-12-25", self.holidays) - self.assertIn("2016-12-26", self.holidays) - - self.assertIn("2500-12-25", self.holidays) - self.assertIn("2500-12-26", self.holidays) + self.assertHoliday( + "1901-12-25", + "1901-12-26", + "2016-12-25", + "2016-12-26", + "2500-12-25", + "2500-12-26", + ) def test_sundays(self): - """ - Sundays are considered holidays in Sweden - """ - - super().test_sundays(holidays.Sweden) + self.assertSundays( + Sweden + ) # Sundays are considered holidays in Sweden. def test_not_holiday(self): - """ - Note: Sundays in Sweden are considered holidays, - so make sure none of these are actually Sundays - :return: - """ - self.assertNotIn("2017-02-06", self.holidays) - self.assertNotIn("2017-02-07", self.holidays) - self.assertNotIn("2017-02-08", self.holidays) - self.assertNotIn("2017-02-09", self.holidays) - self.assertNotIn("2017-02-10", self.holidays) - self.assertNotIn("2016-12-27", self.holidays) - self.assertNotIn("2016-12-28", self.holidays) + # Sundays in Sweden are considered holidays, + # so make sure none of these are actually Sundays. + self.assertNoHoliday( + "2017-02-06", + "2017-02-07", + "2017-02-08", + "2017-02-09", + "2017-02-10", + "2016-12-27", + "2016-12-28", + ) + + def test_2022(self): + self.assertHolidaysEqual( + Sweden(include_sundays=False, observed=False, years=2022), + ("2022-01-01", "Nyårsdagen"), + ("2022-01-06", "Trettondedag jul"), + ("2022-04-15", "Långfredagen"), + ("2022-04-17", "Påskdagen"), + ("2022-04-18", "Annandag påsk"), + ("2022-05-01", "Första maj"), + ("2022-05-26", "Kristi himmelsfärdsdag"), + ("2022-06-05", "Pingstdagen"), + ("2022-06-06", "Sveriges nationaldag"), + ("2022-06-24", "Midsommarafton"), + ("2022-06-25", "Midsommardagen"), + ("2022-11-05", "Alla helgons dag"), + ("2022-12-24", "Julafton"), + ("2022-12-25", "Juldagen"), + ("2022-12-26", "Annandag jul"), + ("2022-12-31", "Nyårsafton"), + ) From 9f992d56db59daeaf58d38d9e8e661af4707b82b Mon Sep 17 00:00:00 2001 From: dr-prodigy <28216945+dr-prodigy@users.noreply.github.com> Date: Thu, 8 Dec 2022 09:42:59 +0100 Subject: [PATCH 040/138] CHANGES sync --- CHANGES | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES b/CHANGES index a16aa0894..ab3dcef7b 100644 --- a/CHANGES +++ b/CHANGES @@ -4,6 +4,7 @@ Version 0.18 Released ???????? ??, ???? - Code refactoring #801 (arkid15r) +- Test refactoring / common functions #800 (arkid15r) - Pre-commit reviews #786, #795 (KJhellico, arkid15r, dr-p) - Import cleanup, flake8 settings review #792 (arkid15r, KJhellico, dr-p) - Easter holidays refactoring and unification #803 (KJhellico) From f270d7d5a849cda3e7b3782eabd6f0174f94d80c Mon Sep 17 00:00:00 2001 From: ~Jhellico Date: Thu, 8 Dec 2022 11:15:34 +0200 Subject: [PATCH 041/138] Malaysia: (#802) - fixed dates of some islamic and lunisolar calendar holidays - rewritten observed calculation (by states) - huge refactoring - rewritten tests --- holidays/countries/malaysia.py | 864 +++++++++++++++++++------------- test/countries/test_malaysia.py | 764 +++++++++++++++++++++++----- 2 files changed, 1140 insertions(+), 488 deletions(-) diff --git a/holidays/countries/malaysia.py b/holidays/countries/malaysia.py index cee4f64cf..e84946c83 100644 --- a/holidays/countries/malaysia.py +++ b/holidays/countries/malaysia.py @@ -9,15 +9,16 @@ # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) -from datetime import date, timedelta +from datetime import date from typing import Iterable, Optional, Union from dateutil.easter import easter from dateutil.relativedelta import relativedelta as rd from dateutil.relativedelta import MO, FR, SA, SU -from dateutil.rrule import MONTHLY, rrule from holidays.constants import ( + FRI, + SAT, SUN, JAN, FEB, @@ -39,10 +40,13 @@ class Malaysia(HolidayBase): country = "MY" special_holidays = { + # The years 1955 1959 1995 seems to have the elections + # one weekday but I am not sure if they were marked as + # holidays. 1999: ((NOV, 29, "Malaysia General Election Holiday"),), 2018: ((MAY, 9, "Malaysia General Election Holiday"),), + 2019: ((JUL, 30, "Installation of New King"),), } - subdivisions = [ "JHR", "KDH", @@ -116,19 +120,7 @@ def __init__( def _populate(self, year): super()._populate(year) - # New Year's Day - if self.subdiv not in {"JHR", "KDH", "KTN", "PLS", "TRG"}: - self[date(year, JAN, 1)] = "New Year's Day" - - # Birthday of the Prophet Muhammad (s.a.w.). - # a.k.a. Hari Keputeraan Nabi Muhammad (Sabah Act) - for hol_date in self.my_islamic_to_gre(year, 3, 12): - self[ - hol_date - ] = "Maulidur Rasul (Birthday of the Prophet Muhammad)" - - # Hari Kebangsaan or National Day. - self[date(year, AUG, 31)] = "National Day" + estimated_suffix = "* (*estimated)" # Chinese New Year (one day in the States of Kelantan and Terengganu, # two days in the other States). @@ -146,10 +138,10 @@ def _populate(self, year): 2001: (MAY, 7), 2002: (MAY, 27), 2003: (MAY, 15), - 2004: (JUN, 2), + 2004: (MAY, 3), 2005: (MAY, 23), 2006: (MAY, 12), - 2007: (MAY, 31), + 2007: (MAY, 1), 2008: (MAY, 19), 2009: (MAY, 9), 2010: (MAY, 28), @@ -157,8 +149,8 @@ def _populate(self, year): 2012: (MAY, 5), 2013: (MAY, 24), 2014: (MAY, 13), - 2015: (JUN, 1), - 2016: (MAY, 20), + 2015: (MAY, 3), + 2016: (MAY, 21), 2017: (MAY, 10), 2018: (MAY, 29), 2019: (MAY, 19), @@ -166,122 +158,35 @@ def _populate(self, year): 2021: (MAY, 26), 2022: (MAY, 15), } + name = "Vesak Day" if year in dates_obs: hol_date = date(year, *dates_obs[year]) - self[hol_date] = "Vesak Day" else: hol_date = self.cnls.vesak_may_date(year) - self[hol_date] = "Vesak Day* (*estimated; ~10% chance +/- 1 day)" + name += estimated_suffix + self[hol_date] = name + + # Labour Day. + self[date(year, MAY, 1)] = "Labour Day" # Birthday of [His Majesty] the Yang di-Pertuan Agong. if year <= 2017: - hol_date = rrule( - MONTHLY, - dtstart=date(year, JUN, 1), - count=1, - bysetpos=1, - byweekday=SA, - )[0] + hol_date = date(year, JUN, 1) + rd(weekday=SA) elif year == 2018: hol_date = date(2018, SEP, 9) + elif year == 2020: + # https://www.nst.com.my/news/nation/2020/03/571660/agongs-birthday-moved-june-6-june-8 + hol_date = date(2020, JUN, 8) else: - hol_date = rrule( - MONTHLY, - dtstart=date(year, JUN, 1), - count=1, - bysetpos=1, - byweekday=MO, - )[0] + hol_date = date(year, JUN, 1) + rd(weekday=MO) self[hol_date] = "Birthday of SPB Yang di-Pertuan Agong" - # Hari Raya Puasa (2 days). - # aka Eid al-Fitr; - # exact date of observance is announced yearly - dates_obs = { - 2001: [(DEC, 17)], - 2002: [(DEC, 6)], - 2003: [(NOV, 25)], - 2004: [(NOV, 14)], - 2005: [(NOV, 3)], - 2006: [(OCT, 24)], - 2007: [(OCT, 13)], - 2008: [(OCT, 1)], - 2009: [(SEP, 20)], - 2010: [(SEP, 10)], - 2011: [(AUG, 30)], - 2012: [(AUG, 19)], - 2013: [(AUG, 8)], - 2014: [(JUL, 28)], - 2015: [(JUL, 17)], - 2016: [(JUL, 6)], - 2017: [(JUN, 25)], - 2018: [(JUN, 15)], - 2019: [(JUN, 5)], - 2020: [(MAY, 24)], - 2021: [(MAY, 13)], - 2022: [(MAY, 2)], - } - if year in dates_obs: - for date_obs in dates_obs[year]: - hol_date = date(year, *date_obs) - self[hol_date] = "Hari Raya Puasa" - self[hol_date + rd(days=+1)] = "Second day of Hari Raya Puasa" - else: - for date_obs in _islamic_to_gre(year, 10, 1): - hol_date = date_obs - self[hol_date] = "Hari Raya Puasa* (*estimated)" - self[hol_date + rd(days=+1)] = ( - "Second day of Hari Raya Puasa*" " (*estimated)" - ) + # Hari Kebangsaan or National Day. + self[date(year, AUG, 31)] = "National Day" - # Hari Raya Haji and Arafat Day. - # Date of observance is announced yearly. - dates_obs = { - 2001: [(MAR, 6)], - 2002: [(FEB, 23)], - 2003: [(FEB, 12)], - 2004: [(FEB, 1)], - 2005: [(JAN, 21)], - 2006: [(JAN, 10)], - 2007: [(DEC, 20)], - 2008: [(DEC, 8)], - 2009: [(NOV, 27)], - 2010: [(NOV, 17)], - 2011: [(NOV, 6)], - 2012: [(OCT, 26)], - 2013: [(OCT, 15)], - 2014: [(OCT, 5)], - 2015: [(SEP, 24)], - 2016: [(SEP, 12)], - 2017: [(SEP, 1)], - 2018: [(AUG, 22)], - 2019: [(AUG, 11)], - 2020: [(JUL, 31)], - 2021: [(JUL, 20)], - 2022: [(JUL, 9)], - } - if year in dates_obs: - for date_obs in dates_obs[year]: - hol_date = date(year, *date_obs) - self[hol_date] = "Hari Raya Haji" - if self.subdiv == "TRG": - # Arafat Day is one day before Eid al-Adha - self[hol_date - rd(days=1)] = "Arafat Day" - if self.subdiv in {"KDH", "KTN", "PLS", "TRG"}: - # Second day - self[hol_date + rd(days=1)] = "Hari Raya Haji Holiday" - else: - for date_obs in _islamic_to_gre(year, 12, 10): - hol_date = date_obs - self[hol_date] = "Hari Raya Haji* (*estimated)" - if self.subdiv == "TRG": - # Arafat Day is one day before Eid al-Adha - self[hol_date - rd(days=1)] = "Arafat Day* (*estimated)" - if self.subdiv in {"KDH", "KTN", "PLS", "TRG"}: - # Second day - self[ - hol_date + rd(days=1) - ] = "Hari Raya Haji Holiday* (*estimated)" + # Malaysia Day. + if year >= 2010: + self[date(year, SEP, 16)] = "Malaysia Day" # Deepavali. # aka Diwali; @@ -311,18 +216,148 @@ def _populate(self, year): 2021: (NOV, 4), 2022: (OCT, 24), } + name = "Deepavali" if year in dates_obs: hol_date = date(year, *dates_obs[year]) - self[hol_date] = "Deepavali" else: hol_date = self.cnls.s_diwali_date(year) - self[hol_date] = "Deepavali* (*estimated; rarely on day after)" + name += estimated_suffix + self[hol_date] = name # Christmas day. self[date(year, DEC, 25)] = "Christmas Day" - # Malaysia Day. - self[date(year, SEP, 16)] = "Malaysia Day" + # Birthday of the Prophet Muhammad (s.a.w.). + # a.k.a. Hari Keputeraan Nabi Muhammad (Sabah Act) + dates_obs = { + 2001: ((JUN, 4),), + 2002: ((MAY, 24),), + 2003: ((MAY, 14),), + 2004: ((MAY, 2),), + 2005: ((APR, 21),), + 2006: ((APR, 11),), + 2007: ((MAR, 31),), + 2008: ((MAR, 20),), + 2009: ((MAR, 9),), + 2010: ((FEB, 26),), + 2011: ((FEB, 16),), + 2012: ((FEB, 5),), + 2013: ((JAN, 24),), + 2014: ((JAN, 14),), + 2015: ( + (JAN, 3), + (DEC, 24), + ), + 2016: ((DEC, 12),), + 2017: ((DEC, 1),), + 2018: ((NOV, 20),), + 2019: ((NOV, 9),), + 2020: ((OCT, 29),), + 2021: ((OCT, 19),), + 2022: ((OCT, 10),), + } + name = "Maulidur Rasul (Birthday of the Prophet Muhammad)" + if year in dates_obs: + hol_dates = [ + (date(year, *date_obs), "") for date_obs in dates_obs[year] + ] + else: + hol_dates = [ + (date_obs, estimated_suffix) + for date_obs in _islamic_to_gre(year, 3, 12) + ] + for hol_date, hol_suffix in hol_dates: + self[hol_date] = name + hol_suffix + + # Hari Raya Puasa (2 days). + # aka Eid al-Fitr; + # exact date of observance is announced yearly + dates_obs = { + 2001: ((DEC, 17),), + 2002: ((DEC, 6),), + 2003: ((NOV, 26),), + 2004: ((NOV, 14),), + 2005: ((NOV, 3),), + 2006: ((OCT, 24),), + 2007: ((OCT, 13),), + 2008: ((OCT, 1),), + 2009: ((SEP, 20),), + 2010: ((SEP, 10),), + 2011: ((AUG, 31),), + 2012: ((AUG, 19),), + 2013: ((AUG, 8),), + 2014: ((JUL, 28),), + 2015: ((JUL, 17),), + 2016: ((JUL, 6),), + 2017: ((JUN, 25),), + 2018: ((JUN, 15),), + 2019: ((JUN, 5),), + 2020: ((MAY, 24),), + 2021: ((MAY, 13),), + 2022: ((MAY, 2),), + } + name = "Hari Raya Puasa" + if year in dates_obs: + hol_dates = [ + (date(year, *date_obs), "") for date_obs in dates_obs[year] + ] + else: + hol_dates = [ + (date_obs, estimated_suffix) + for date_obs in _islamic_to_gre(year, 10, 1) + ] + for hol_date, hol_suffix in hol_dates: + self[hol_date] = name + hol_suffix + self[hol_date + rd(days=+1)] = "Second day of " + name + hol_suffix + + # Hari Raya Haji and Arafat Day. + # Date of observance is announced yearly. + dates_obs = { + 2001: ((MAR, 6),), + 2002: ((FEB, 23),), + 2003: ((FEB, 12),), + 2004: ((FEB, 2),), + 2005: ((JAN, 21),), + 2006: ( + (JAN, 10), + (DEC, 31), + ), + 2007: ((DEC, 20),), + 2008: ((DEC, 9),), + 2009: ((NOV, 28),), + 2010: ((NOV, 17),), + 2011: ((NOV, 7),), + 2012: ((OCT, 26),), + 2013: ((OCT, 15),), + 2014: ((OCT, 5),), + 2015: ((SEP, 24),), + 2016: ((SEP, 12),), + 2017: ((SEP, 1),), + 2018: ((AUG, 22),), + 2019: ((AUG, 11),), + 2020: ((JUL, 31),), + 2021: ((JUL, 20),), + 2022: ((JUL, 10),), + } + name = "Hari Raya Haji" + prev_day_name = "Arafat Day" + if year in dates_obs: + hol_dates = [ + (date(year, *date_obs), "") for date_obs in dates_obs[year] + ] + else: + hol_dates = [ + (date_obs, estimated_suffix) + for date_obs in _islamic_to_gre(year, 12, 10) + ] + for hol_date, hol_suffix in hol_dates: + self[hol_date] = name + hol_suffix + if self.subdiv == "TRG": + # Arafat Day is one day before Eid al-Adha + self[hol_date + rd(days=-1)] = prev_day_name + hol_suffix + if self.subdiv in {"KDH", "KTN", "PLS", "TRG"}: + # Second day + self[hol_date + rd(days=+1)] = name + " Holiday" + hol_suffix # ---------------------------------------------------------# # Holidays from the Sarawak Ordinance (not included above) # @@ -336,57 +371,14 @@ def _populate(self, year): # Birthday of Tuan Yang Terutama Yang di-Pertua Negeri Sarawak (the # second Saturday of September). - second_sat_oct = rrule( - MONTHLY, - dtstart=date(year, OCT, 1), - count=1, - bysetpos=2, - byweekday=SA, - )[0] + second_sat_oct = date(year, OCT, 1) + rd(weekday=SA(+2)) self[second_sat_oct] = "Birthday of the Governor of Sarawak" # Sarawak Independence Day - if year > 2016: + if year >= 2017: self[date(year, JUL, 22)] = "Sarawak Day" - # Check for holidays that fall on a Sunday and - # implement Section 3 of Malaysian Holidays Act: - # "if any day specified in the Schedule falls on - # Sunday then the day following shall be a public - # holiday and if such day is already a public holiday, - # then the day following shall be a public holiday" - for (hol_date, hol_name) in list(self.items()): - if hol_date.year == year and hol_date.weekday() == SUN: - self[hol_date] += " [Sunday]" - in_lieu_date = hol_date + rd(days=+1) - while in_lieu_date in self: - in_lieu_date += rd(days=+1) - self[in_lieu_date] = hol_name + " [In lieu]" - - # The last two days in May (Pesta Kaamatan). - # (Sarawak Act) - # Day following a Sunday is not a holiday - if self.subdiv in {"LBN", "SBH"}: - self[date(year, MAY, 30)] = "Pesta Kaamatan" - self[date(year, MAY, 31)] = "Pesta Kaamatan (Second day)" - - # ------------------------------# - # Other holidays (decrees etc.) # - # ------------------------------# - - # Awal Muharram. - for hol_date in self.my_islamic_to_gre(year, 1, 1): - self[hol_date] = "Awal Muharram (Hijri New Year)" - - # Labour Day. - self[date(year, MAY, 1)] = "Labour Day" - - # ---------------------------------# - # State holidays (multiple states) # - # ---------------------------------# - - # 1 January (or the following day if the 1 January should fall on a - # weekly holiday in any State or in the Federal Territory). + # New Year's Day if self.subdiv in { "KUL", "LBN", @@ -400,230 +392,392 @@ def _populate(self, year): "SGR", "SWK", }: - hol_date = date(year, JAN, 1) - self[hol_date] = "New Year's Day" - if hol_date.weekday() == SUN: - self[hol_date] += " [Sunday]" - self[date(year, JAN, 2)] = "New Year's Day [In lieu]" + self[date(year, JAN, 1)] = "New Year's Day" # Isra and Mi'raj. - if self.subdiv in {"KDH", "NSN", "PLS", "TRG"}: - for hol_date in _islamic_to_gre(year, 7, 27): - self[hol_date] = "Isra and Mi'raj" + if self.subdiv in {"KDH", "NSN", "PLS"} or ( + self.subdiv == "TRG" and year >= 2020 + ): + dates_obs = { + 2001: ((OCT, 15),), + 2002: ((OCT, 4),), + 2003: ((SEP, 24),), + 2004: ((SEP, 12),), + 2005: ((SEP, 1),), + 2006: ((AUG, 22),), + 2007: ((AUG, 11),), + 2008: ((JUL, 31),), + 2009: ((JUL, 20),), + 2010: ((JUL, 9),), + 2011: ((JUN, 29),), + 2012: ((JUN, 17),), + 2013: ((JUN, 6),), + 2014: ((MAY, 27),), + 2015: ((MAY, 16),), + 2016: ((MAY, 5),), + 2017: ((APR, 24),), + 2018: ((APR, 14),), + 2019: ((APR, 3),), + 2020: ((MAR, 22),), + 2021: ((MAR, 11),), + 2022: ((MAR, 1),), + } + name = "Isra and Mi'raj" + if year in dates_obs: + hol_dates = [ + (date(year, *date_obs), "") for date_obs in dates_obs[year] + ] + else: + hol_dates = [ + (date_obs, estimated_suffix) + for date_obs in _islamic_to_gre(year, 7, 27) + ] + for hol_date, hol_suffix in hol_dates: + self[hol_date] = name + hol_suffix # Beginning of Ramadan. if self.subdiv in {"JHR", "KDH", "MLK"}: - for hol_date in _islamic_to_gre(year, 9, 1): - self[hol_date] = "Begining of Ramadan" + dates_obs = { + 2001: ((NOV, 17),), + 2002: ((NOV, 6),), + 2003: ((OCT, 27),), + 2004: ((OCT, 16),), + 2005: ((OCT, 5),), + 2006: ((SEP, 24),), + 2007: ((SEP, 13),), + 2008: ((SEP, 2),), + 2009: ((AUG, 22),), + 2010: ((AUG, 11),), + 2011: ((AUG, 1),), + 2012: ((JUL, 20),), + 2013: ((JUL, 9),), + 2014: ((JUN, 29),), + 2015: ((JUN, 18),), + 2016: ((JUN, 7),), + 2017: ((MAY, 27),), + 2018: ((MAY, 17),), + 2019: ((MAY, 6),), + 2020: ((APR, 24),), + 2021: ((APR, 13),), + 2022: ((APR, 3),), + } + name = "Beginning of Ramadan" + if year in dates_obs: + hol_dates = [ + (date(year, *date_obs), "") for date_obs in dates_obs[year] + ] + else: + hol_dates = [ + (date_obs, estimated_suffix) + for date_obs in _islamic_to_gre(year, 9, 1) + ] + for hol_date, hol_suffix in hol_dates: + self[hol_date] = name + hol_suffix # Nuzul Al-Quran Day. - if self.subdiv not in { - "JHR", - "KDH", - "MLK", - "NSN", - "SBH", - "SWK", + if self.subdiv in { + "KTN", + "KUL", + "LBN", + "PHG", + "PNG", + "PRK", + "PLS", + "PJY", + "SGR", + "TRG", }: - for hol_date in _islamic_to_gre(year, 9, 17): - self[hol_date] = "Nuzul Al-Quran Day" - - # Hari Raya Aidilfitri. - # aka Eid al-Fitr; - # date of observance is announced yearly - dates_obs = { - 2001: [(DEC, 16)], - 2002: [(DEC, 6)], - 2003: [(NOV, 25)], - 2004: [(NOV, 14)], - 2005: [(NOV, 3)], - 2006: [(OCT, 24)], - 2007: [(OCT, 13)], - 2008: [(OCT, 1)], - 2009: [(SEP, 20)], - 2010: [(SEP, 10)], - 2011: [(AUG, 30)], - 2012: [(AUG, 19)], - 2013: [(AUG, 8)], - 2014: [(JUL, 28)], - 2015: [(JUL, 17)], - 2016: [(JUL, 6)], - 2017: [(JUN, 25)], - 2018: [(JUN, 15)], - 2019: [(JUN, 5)], - 2020: [(MAY, 24)], - 2021: [(MAY, 13)], - 2022: [(MAY, 2)], - } - if year in dates_obs: - for date_obs in dates_obs[year]: - hol_date = date(year, *date_obs) - self[hol_date] = "Hari Raya Aidilfitri" - hol_date += rd(days=+1) - self[hol_date] = "Hari Raya Aidilfitri Holiday" - else: - for date_obs in _islamic_to_gre(year, 10, 1): - hol_date = date_obs - self[hol_date] = "Hari Raya Aidilfitri* (*estimated)" - hol_date += rd(days=+1) - self[hol_date] = "Hari Raya Aidilfitri Holiday* (*estimated)" - - # Good Friday. - if self.subdiv in {"SBH", "SWK"}: - self[easter(year) + rd(days=-2)] = "Good Friday" + dates_obs = { + 2001: ((DEC, 3),), + 2002: ((NOV, 22),), + 2003: ((NOV, 12),), + 2004: ((NOV, 1),), + 2005: ((OCT, 21),), + 2006: ((OCT, 10),), + 2007: ((SEP, 29),), + 2008: ((SEP, 18),), + 2009: ((SEP, 7),), + 2010: ((AUG, 27),), + 2011: ((AUG, 17),), + 2012: ((AUG, 5),), + 2013: ((JUL, 25),), + 2014: ((JUL, 15),), + 2015: ((JUL, 4),), + 2016: ((JUN, 22),), + 2017: ((JUN, 12),), + 2018: ((JUN, 2),), + 2019: ((MAY, 22),), + 2020: ((MAY, 10),), + 2021: ((APR, 29),), + 2022: ((APR, 19),), + } + name = "Nuzul Al-Quran Day" + if year in dates_obs: + hol_dates = [ + (date(year, *date_obs), "") for date_obs in dates_obs[year] + ] + else: + hol_dates = [ + (date_obs, estimated_suffix) + for date_obs in _islamic_to_gre(year, 9, 17) + ] + for hol_date, hol_suffix in hol_dates: + self[hol_date] = name + hol_suffix # Thaipusam. # An annual Hindu festival observed on the day of the first full moon # during the Tamil month of Thai if self.subdiv in {"JHR", "KUL", "NSN", "PJY", "PNG", "PRK", "SGR"}: dates_obs = { - 2018: [(JAN, 31)], - 2019: [(JAN, 21)], - 2020: [(FEB, 8)], - 2021: [(JAN, 28)], - 2022: [(JAN, 18)], - 2023: [(FEB, 4)], - 2024: [(JAN, 25)], - 2025: [(FEB, 11)], - 2026: [(FEB, 1)], - 2027: [(JAN, 22)], + 2018: (JAN, 31), + 2019: (JAN, 21), + 2020: (FEB, 8), + 2021: (JAN, 28), + 2022: (JAN, 18), + 2023: (FEB, 5), + 2024: (JAN, 25), + 2025: (FEB, 11), + 2026: (FEB, 1), + 2027: (JAN, 22), } + name = "Thaipusam" if year in dates_obs: - for date_obs in dates_obs[year]: - hol_date = date(year, *date_obs) - self[hol_date] = "Thaipusam" + hol_date = date(year, *dates_obs[year]) else: hol_date = self.cnls.thaipusam_date(year) - self[hol_date] = "Thaipusam* (*estimated)" + name += estimated_suffix + self[hol_date] = name # Federal Territory Day. - if self.subdiv in {"KUL", "LBN", "PJY"}: - if year > 1973: - self[date(year, FEB, 1)] = "Federal Territory Day" + if self.subdiv in {"KUL", "LBN", "PJY"} and year >= 1974: + self[date(year, FEB, 1)] = "Federal Territory Day" # State holidays (single state) - # ----------------------------- - if self.subdiv == "JHR": - if year > 2014: - self[date(year, MAR, 23)] = "Birthday of the Sultan of Johor" - for date_obs in _islamic_to_gre(year, 2, 6): - self[date_obs] = "Hari Hol of Sultan Iskandar of Johor" - - elif self.subdiv == "KDH": - third_sun_jun = rrule( - MONTHLY, - dtstart=date(year, JUN, 1), - count=1, - bysetpos=3, - byweekday=SU, - )[0] - self[third_sun_jun] = "Birthday of The Sultan of Kedah" - - elif self.subdiv == "KTN": - self[date(year, NOV, 11)] = "Birthday of the Sultan of Kelantan" - self[ - date(year, NOV, 12) - ] = "Birthday of the Sultan of Kelantan Holiday" - - elif self.subdiv == "MLK": - self[ - date(year, APR, 15) - ] = "Declaration of Malacca as a Historical City in Melaka" - self[ - date(year, AUG, 24) - ] = "Birthday of the Governor of the State of Melaka" + if self.subdiv == "MLK": + if year >= 1989: + self[ + date(year, APR, 15) + ] = "Declaration of Malacca as a Historical City" + if year >= 2020: + hol_date = date(year, AUG, 24) + else: + hol_date = date(year, OCT, 1) + rd(weekday=FR(+2)) + self[hol_date] = "Birthday of the Governor of Malacca" elif self.subdiv == "NSN": - self[ - date(year, JAN, 14) - ] = "Birthday of the Sultan of Negeri Sembilan" + if year >= 2009: + self[ + date(year, JAN, 14) + ] = "Birthday of the Sultan of Negeri Sembilan" elif self.subdiv == "PHG": - self[date(year, MAY, 22)] = "Hari Hol of Pahang" - self[date(year, JUL, 30)] = "Birthday of the Sultan of Pahang" + if year >= 2020: + hol_date = date(year, MAY, 22) + else: + hol_date = date(year, MAY, 7) + self[hol_date] = "Hari Hol of Pahang" + + if year >= 2019: + hol_date = date(year, JUL, 30) + elif 1975 <= year <= 2018: + hol_date = date(year, OCT, 24) + self[hol_date] = "Birthday of the Sultan of Pahang" elif self.subdiv == "PNG": - self[date(year, JUL, 7)] = "George Town Heritage Day" - second_sat_jul = rrule( - MONTHLY, - dtstart=date(year, JUL, 1), - count=1, - bysetpos=2, - byweekday=SA, - )[0] + if year >= 2009: + self[date(year, JUL, 7)] = "George Town Heritage Day" + second_sat_jul = date(year, JUL, 1) + rd(weekday=SA(+2)) self[second_sat_jul] = "Birthday of the Governor of Penang" - elif self.subdiv == "PRK": - if year > 2016: - first_fri_nov = rrule( - MONTHLY, - dtstart=date(year, NOV, 1), - count=1, - bysetpos=1, - byweekday=FR, - )[0] - self[first_fri_nov] = "Birthday of the Sultan of Perak" - else: - # This Holiday used to be on 27th until 2017 - # https://www.officeholidays.com/holidays/malaysia/birthday-of-the-sultan-of-perak # noqa: E501 - self[date(year, NOV, 27)] = "Birthday of the Sultan of Perak" - elif self.subdiv == "PLS": - self[date(year, JUL, 17)] = "Birthday of The Raja of Perlis" + if year >= 2018: + hol_date = date(year, JUL, 17) + elif year >= 2000: + hol_date = date(year, MAY, 17) + self[hol_date] = "Birthday of The Raja of Perlis" elif self.subdiv == "SGR": self[date(year, DEC, 11)] = "Birthday of The Sultan of Selangor" - elif self.subdiv == "SBH": - first_sat_oct = rrule( - MONTHLY, - dtstart=date(year, OCT, 1), - count=1, - bysetpos=1, - byweekday=SA, - )[0] - self[first_sat_oct] = "Birthday of the Governor of Sabah" - if year > 2018: - self[date(year, DEC, 24)] = "Christmas Eve" - elif self.subdiv == "TRG": - self[ - date(year, MAR, 4) - ] = "Anniversary of the Installation of the Sultan of Terengganu" - self[date(year, APR, 26)] = "Birthday of the Sultan of Terengganu" + if year >= 2000: + self[date(year, MAR, 4)] = ( + "Anniversary of the Installation " + "of the Sultan of Terengganu" + ) + self[ + date(year, APR, 26) + ] = "Birthday of the Sultan of Terengganu" - def my_islamic_to_gre(self, year: int, month: int, day: int): - """ - Malaysia seems to have a slightly different Hijri calendar. This - function returns the adjusted date. + # Check for holidays that fall on a Sunday and + # implement Section 3 of Malaysian Holidays Act: + # "if any day specified in the Schedule falls on + # Sunday then the day following shall be a public + # holiday and if such day is already a public holiday, + # then the day following shall be a public holiday" + # In Johor and Kedah it's Friday -> Sunday, + # in Kelantan and Terengganu it's Saturday -> Sunday + for hol_date, hol_name in list(self.items()): + if hol_date.year != year: + continue + in_lieu_date = None + if hol_date.weekday() == FRI and self.subdiv in {"JHR", "KDH"}: + in_lieu_date = hol_date + rd(days=+2) + elif hol_date.weekday() == SAT and self.subdiv in { + "KTN", + "TRG", + }: + in_lieu_date = hol_date + rd(days=+1) + elif hol_date.weekday() == SUN and self.subdiv not in { + "JHR", + "KDH", + "KTN", + "TRG", + }: + in_lieu_date = hol_date + rd(days=+1) + if not in_lieu_date: + continue + while in_lieu_date in self: + in_lieu_date += rd(days=+1) + self[in_lieu_date] = hol_name + " [In lieu]" - Only knows years 2000 to 2030. + # The last two days in May (Pesta Kaamatan). + # (Sarawak Act) + # Day following a Sunday is not a holiday + if self.subdiv in {"LBN", "SBH"}: + self[date(year, MAY, 30)] = "Pesta Kaamatan" + self[date(year, MAY, 31)] = "Pesta Kaamatan (Second day)" - :param year: The Gregorian year. - :param Hmonth: The Hijri (Islamic) month. - :param Hday: The Hijri (Islamic) day. - :return: List of Gregorian dates within the year matching the hijri day - month, adjusted for Malaysia. - """ - hol_dates = _islamic_to_gre(year, month, day) - if year in { - 2003, - 2004, - 2010, - 2011, - 2013, - 2017, - 2019, - 2021, - 2024, - 2025, - 2027, - }: + # ------------------------------# + # Other holidays (decrees etc.) # + # ------------------------------# + + # Awal Muharram. + dates_obs = { + 2001: ((MAR, 26),), + 2002: ((MAR, 15),), + 2003: ((MAR, 5),), + 2004: ((FEB, 22),), + 2005: ((FEB, 10),), + 2006: ((JAN, 31),), + 2007: ((JAN, 20),), + 2008: ( + (JAN, 10), + (DEC, 29), + ), + 2009: ((DEC, 18),), + 2010: ((DEC, 8),), + 2011: ((NOV, 27),), + 2012: ((NOV, 15),), + 2013: ((NOV, 5),), + 2014: ((OCT, 25),), + 2015: ((OCT, 14),), + 2016: ((OCT, 2),), + 2017: ((SEP, 22),), + 2018: ((SEP, 11),), + 2019: ((SEP, 1),), + 2020: ((AUG, 20),), + 2021: ((AUG, 10),), + 2022: ((JUL, 30),), + } + name = "Awal Muharram (Hijri New Year)" + if year in dates_obs: hol_dates = [ - hol_date + timedelta(days=1) for hol_date in hol_dates + (date(year, *date_obs), "") for date_obs in dates_obs[year] ] - return hol_dates + else: + hol_dates = [ + (date_obs, estimated_suffix) + for date_obs in _islamic_to_gre(year, 1, 1) + ] + for hol_date, hol_suffix in hol_dates: + self[hol_date] = name + hol_suffix + + # Special holidays (states) + if year == 2021 and self.subdiv in {"KUL", "LBN", "PJY"}: + self[date(2021, DEC, 3)] = "Malaysia Cup Holiday" + + if year == 2022 and self.subdiv == "KDH": + self[date(2022, JAN, 18)] = "Thaipusam" + + if year == 2022 and self.subdiv in { + "JHR", + "KDH", + "KTN", + "TRG", + }: + self[date(2022, MAY, 4)] = "Labour Day Holiday" + + # ---------------------------------# + # State holidays (multiple states) # + # ---------------------------------# + + # Good Friday. + if self.subdiv in {"SBH", "SWK"}: + self[easter(year) + rd(days=-2)] = "Good Friday" + + # ----------------------------- + # State holidays (single state) + # ----------------------------- + + if self.subdiv == "JHR": + if year >= 2015: + self[date(year, MAR, 23)] = "Birthday of the Sultan of Johor" + if year >= 2011: + dates_obs = { + 2011: ((JAN, 12),), + 2012: ((JAN, 1), (DEC, 20)), + 2013: ((DEC, 10),), + 2014: ((NOV, 29),), + 2015: ((NOV, 19),), + 2016: ((NOV, 7),), + 2017: ((OCT, 27),), + 2018: ((OCT, 15),), + 2019: ((OCT, 5),), + 2020: ((SEP, 24),), + 2021: ((SEP, 13),), + 2022: ((SEP, 3),), + } + name = "Hari Hol of Sultan Iskandar of Johor" + if year in dates_obs: + hol_dates = [ + (date(year, *date_obs), "") + for date_obs in dates_obs[year] + ] + else: + hol_dates = [ + (date_obs, estimated_suffix) + for date_obs in _islamic_to_gre(year, 2, 6) + ] + for hol_date, hol_suffix in hol_dates: + self[hol_date] = name + hol_suffix + + elif self.subdiv == "KDH": + if year >= 2020: + third_sun_jun = date(year, JUN, 1) + rd(weekday=SU(+3)) + self[third_sun_jun] = "Birthday of The Sultan of Kedah" + + elif self.subdiv == "KTN": + if year >= 2010: + name = "Birthday of the Sultan of Kelantan" + self[date(year, NOV, 11)] = name + self[date(year, NOV, 12)] = name + + elif self.subdiv == "PRK": + # This Holiday used to be on 27th until 2017 + # https://www.officeholidays.com/holidays/malaysia/birthday-of-the-sultan-of-perak # noqa: E501 + if year >= 2018: + first_fri_nov = date(year, NOV, 1) + rd(weekday=FR) + self[first_fri_nov] = "Birthday of the Sultan of Perak" + else: + self[date(year, NOV, 27)] = "Birthday of the Sultan of Perak" + + elif self.subdiv == "SBH": + first_sat_oct = date(year, OCT, 1) + rd(weekday=SA) + self[first_sat_oct] = "Birthday of the Governor of Sabah" + if year >= 2019: + self[date(year, DEC, 24)] = "Christmas Eve" class MY(Malaysia): diff --git a/test/countries/test_malaysia.py b/test/countries/test_malaysia.py index 1d462c86b..62cf162a1 100644 --- a/test/countries/test_malaysia.py +++ b/test/countries/test_malaysia.py @@ -32,6 +32,42 @@ class TestMalaysia(unittest.TestCase): def setUp(self): self.holidays = holidays.Malaysia() + years = ( + 1970, + 1985, + 1990, + 2001, + 2010, + 2014, + 2015, + 2018, + 2019, + 2020, + 2021, + 2022, + 2023, + ) + self.johor_holidays = holidays.Malaysia(years=years, subdiv="JHR") + self.kedah_holidays = holidays.Malaysia(years=years, subdiv="KDH") + self.kelantan_holidays = holidays.Malaysia(years=years, subdiv="KTN") + self.malacca_holidays = holidays.Malaysia(years=years, subdiv="MLK") + self.negeri_sembilan_holidays = holidays.Malaysia( + years=years, + subdiv="NSN", + ) + self.pahang_holidays = holidays.Malaysia(years=years, subdiv="PHG") + self.perak_holidays = holidays.Malaysia(years=years, subdiv="PRK") + self.perlis_holidays = holidays.Malaysia(years=years, subdiv="PLS") + self.penang_holidays = holidays.Malaysia(years=years, subdiv="PNG") + self.sabah_holidays = holidays.Malaysia(years=years, subdiv="SBH") + self.sarawak_holidays = holidays.Malaysia(years=years, subdiv="SWK") + self.selangor_holidays = holidays.Malaysia(years=years, subdiv="SGR") + self.terengganu_holidays = holidays.Malaysia(years=years, subdiv="TRG") + self.kuala_lumpur_holidays = holidays.Malaysia( + years=years, subdiv="KUL" + ) + self.labuan_holidays = holidays.Malaysia(years=years, subdiv="LBN") + self.putrajaya_holidays = holidays.Malaysia(years=years, subdiv="PJY") def test_Malaysia_Wikipedia(self): # reproduce table at @@ -164,6 +200,24 @@ def test_Malaysia_Wikipedia(self): 1, 1, ], + date(2021, FEB, 14): [ + 1, + 1, + 1, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 1, + ], date(2021, MAR, 4): [ 0, 0, @@ -326,6 +380,24 @@ def test_Malaysia_Wikipedia(self): 1, 1, ], + date(2021, MAY, 2): [ + 0, + 0, + 1, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 1, + ], date(2021, MAY, 13): [ 1, 1, @@ -362,6 +434,24 @@ def test_Malaysia_Wikipedia(self): 1, 1, ], + date(2021, MAY, 16): [ + 1, + 1, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + ], date(2021, MAY, 22): [ 0, 0, @@ -866,6 +956,24 @@ def test_Malaysia_Wikipedia(self): 0, 0, ], + date(2021, DEC, 3): [ + 0, + 0, + 0, + 1, + 1, + 0, + 0, + 0, + 0, + 0, + 0, + 1, + 0, + 0, + 0, + 0, + ], date(2021, DEC, 11): [ 0, 0, @@ -920,18 +1028,34 @@ def test_Malaysia_Wikipedia(self): 1, 1, ], + date(2021, DEC, 26): [ + 0, + 0, + 1, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 1, + ], } for col, state in enumerate(columns): my_holidays = holidays.Malaysia(years=2021, subdiv=state) # check if all holidays are in here - tot_holidays = 0 for hol_date, is_holiday in rows.items(): if is_holiday[col]: self.assertIn(hol_date, my_holidays) - tot_holidays += 1 - # check that there are no extra ones - self.assertEqual(len(my_holidays), tot_holidays) + else: + self.assertNotIn(hol_date, my_holidays) def test_Malaysia(self): # Federal Public Holidays @@ -951,173 +1075,547 @@ def test_Malaysia(self): self.assertIn(date(2001, 12, 18), self.holidays) self.assertIn(date(2001, 12, 25), self.holidays) + def test_special_holidays(self): + self.assertIn(date(1999, 11, 29), self.holidays) + self.assertIn(date(2018, 5, 9), self.holidays) + self.assertIn(date(2019, 7, 30), self.holidays) + def test_JHR_holidays(self): - Johor_holidays = holidays.MY(years=2015, subdiv="JHR") + state_holidays = self.johor_holidays + # Birthday of the Sultan of Johor - self.assertIn(date(2015, 3, 23), Johor_holidays) - self.assertIn(date(2016, 3, 23), Johor_holidays) - self.assertIn(date(2020, 3, 23), Johor_holidays) - self.assertIn(date(2022, 3, 23), Johor_holidays) - self.assertNotIn(date(2001, 3, 23), Johor_holidays) - self.assertNotIn(date(1990, 3, 23), Johor_holidays) + self.assertIn(date(2015, 3, 23), state_holidays) + self.assertIn(date(2018, 3, 23), state_holidays) + self.assertIn(date(2020, 3, 23), state_holidays) + self.assertIn(date(2022, 3, 23), state_holidays) + self.assertNotIn(date(2014, 3, 23), state_holidays) + # Hari Hol of Sultan Iskandar of Johor + self.assertIn(date(2018, 10, 15), state_holidays) + self.assertIn(date(2019, 10, 5), state_holidays) + self.assertIn(date(2020, 9, 24), state_holidays) + self.assertIn(date(2021, 9, 13), state_holidays) + self.assertIn(date(2022, 9, 3), state_holidays) + self.assertIn(date(2023, 8, 22), state_holidays) + self.assertNotIn(date(2010, 1, 21), state_holidays) + # Thaipusam + self.assertIn(date(2018, 1, 31), state_holidays) + self.assertIn(date(2019, 1, 21), state_holidays) + self.assertIn(date(2020, 2, 8), state_holidays) + self.assertIn(date(2021, 1, 28), state_holidays) + self.assertIn(date(2022, 1, 18), state_holidays) + self.assertIn(date(2023, 2, 5), state_holidays) + # Beginning of Ramadan + self.assertIn(date(2018, 5, 17), state_holidays) + self.assertIn(date(2019, 5, 6), state_holidays) + self.assertIn(date(2020, 4, 24), state_holidays) + self.assertIn(date(2020, 4, 26), state_holidays) # In lieu + self.assertIn(date(2021, 4, 13), state_holidays) + self.assertIn(date(2022, 4, 3), state_holidays) + self.assertIn(date(2023, 3, 23), state_holidays) + # Labour Day Holiday + self.assertIn(date(2022, 5, 4), state_holidays) + # Malaysia Day [In lieu] + self.assertNotIn(date(2018, 9, 17), state_holidays) def test_KDH_holidays(self): - Kedah_holidays = holidays.MY( - years=[2018, 2019, 2020, 2021, 2022], subdiv="KDH" - ) - self.assertIn(date(2018, 8, 22), Kedah_holidays) - self.assertIn(date(2019, 8, 11), Kedah_holidays) - self.assertIn(date(2020, 7, 31), Kedah_holidays) - self.assertIn(date(2021, 7, 20), Kedah_holidays) - self.assertIn(date(2022, 7, 9), Kedah_holidays) + state_holidays = self.kedah_holidays + + # Hari Raya Haji + self.assertIn(date(2018, 8, 22), state_holidays) + self.assertIn(date(2019, 8, 11), state_holidays) + self.assertIn(date(2020, 7, 31), state_holidays) + self.assertIn(date(2021, 7, 20), state_holidays) + self.assertIn(date(2022, 7, 10), state_holidays) + self.assertIn(date(2023, 6, 28), state_holidays) + # Hari Raya Haji Holiday + self.assertIn(date(2018, 8, 23), state_holidays) + self.assertIn(date(2019, 8, 12), state_holidays) + self.assertIn(date(2020, 8, 1), state_holidays) + self.assertIn(date(2020, 8, 2), state_holidays) # In lieu + self.assertIn(date(2021, 7, 21), state_holidays) + self.assertIn(date(2022, 7, 11), state_holidays) + self.assertIn(date(2023, 6, 29), state_holidays) + # Isra and Mi'raj + self.assertIn(date(2018, 4, 14), state_holidays) + self.assertIn(date(2019, 4, 3), state_holidays) + self.assertIn(date(2020, 3, 22), state_holidays) + self.assertIn(date(2021, 3, 11), state_holidays) + self.assertIn(date(2022, 3, 1), state_holidays) + self.assertIn(date(2023, 2, 18), state_holidays) + # Beginning of Ramadan + self.assertIn(date(2018, 5, 17), state_holidays) + self.assertIn(date(2019, 5, 6), state_holidays) + self.assertIn(date(2020, 4, 24), state_holidays) + self.assertIn(date(2020, 4, 26), state_holidays) # In lieu + self.assertIn(date(2021, 4, 13), state_holidays) + self.assertIn(date(2022, 4, 3), state_holidays) + self.assertIn(date(2023, 3, 23), state_holidays) + # Thaipusam in 2022 + self.assertIn(date(2022, 1, 18), state_holidays) + # Malaysia Day [In lieu] + self.assertNotIn(date(2018, 9, 17), state_holidays) def test_KTN_holidays(self): - Kelantan_holidays = holidays.MY( - years=[2018, 2019, 2020, 2021, 2022], subdiv="KTN" - ) - self.assertIn(date(2018, 11, 11), Kelantan_holidays) - self.assertIn(date(2019, 11, 12), Kelantan_holidays) - self.assertIn(date(2020, 11, 11), Kelantan_holidays) - self.assertIn(date(2029, 11, 12), Kelantan_holidays) + state_holidays = self.kelantan_holidays + + # Birthday of the Sultan of Kelantan + self.assertIn(date(2018, 11, 11), state_holidays) + self.assertIn(date(2019, 11, 12), state_holidays) + self.assertIn(date(2020, 11, 11), state_holidays) + self.assertNotIn(date(2001, 11, 11), state_holidays) + # Hari Raya Haji + self.assertIn(date(2018, 8, 22), state_holidays) + self.assertIn(date(2019, 8, 11), state_holidays) + self.assertIn(date(2020, 7, 31), state_holidays) + self.assertIn(date(2021, 7, 20), state_holidays) + self.assertIn(date(2022, 7, 10), state_holidays) + self.assertIn(date(2023, 6, 28), state_holidays) + # Hari Raya Haji Holiday + self.assertIn(date(2018, 8, 23), state_holidays) + self.assertIn(date(2019, 8, 12), state_holidays) + self.assertIn(date(2020, 8, 1), state_holidays) + self.assertIn(date(2020, 8, 2), state_holidays) # In lieu + self.assertIn(date(2021, 7, 21), state_holidays) + self.assertIn(date(2022, 7, 11), state_holidays) + self.assertIn(date(2023, 6, 29), state_holidays) + # Nuzul Al-Quran Day + self.assertIn(date(2018, 6, 2), state_holidays) + self.assertIn(date(2018, 6, 3), state_holidays) # In lieu + self.assertIn(date(2019, 5, 22), state_holidays) + self.assertIn(date(2020, 5, 10), state_holidays) + self.assertIn(date(2021, 4, 29), state_holidays) + self.assertIn(date(2022, 4, 19), state_holidays) + self.assertIn(date(2023, 4, 8), state_holidays) + self.assertIn(date(2023, 4, 9), state_holidays) # In lieu + # Labour Day Holiday + self.assertIn(date(2022, 5, 4), state_holidays) + # Malaysia Day [In lieu] + self.assertNotIn(date(2018, 9, 17), state_holidays) def test_NSN_holidays(self): - Negeri_Sembilan_holidays = holidays.MY( - years=[2018, 2019, 2020, 2021, 2022], subdiv="NSN" - ) - self.assertIn(date(2018, 1, 14), Negeri_Sembilan_holidays) - self.assertIn(date(2023, 1, 14), Negeri_Sembilan_holidays) - self.assertNotIn(date(2020, 11, 11), Negeri_Sembilan_holidays) - self.assertNotIn(date(2029, 11, 12), Negeri_Sembilan_holidays) + state_holidays = self.negeri_sembilan_holidays + + # New Year's Day + self.assertIn(date(2018, 1, 1), state_holidays) + self.assertIn(date(2020, 1, 1), state_holidays) + self.assertIn(date(2022, 1, 1), state_holidays) + self.assertIn(date(2023, 1, 2), state_holidays) # In lieu + # Isra and Mi'raj + self.assertIn(date(2018, 4, 14), state_holidays) + self.assertIn(date(2019, 4, 3), state_holidays) + self.assertIn(date(2020, 3, 22), state_holidays) + self.assertIn(date(2021, 3, 11), state_holidays) + self.assertIn(date(2022, 3, 1), state_holidays) + self.assertIn(date(2023, 2, 18), state_holidays) + # Birthday of the Sultan of Negeri Sembilan + self.assertIn(date(2018, 1, 14), state_holidays) + self.assertIn(date(2023, 1, 14), state_holidays) + self.assertNotIn(date(2008, 1, 14), state_holidays) + # Thaipusam + self.assertIn(date(2018, 1, 31), state_holidays) + self.assertIn(date(2019, 1, 21), state_holidays) + self.assertIn(date(2020, 2, 8), state_holidays) + self.assertIn(date(2021, 1, 28), state_holidays) + self.assertIn(date(2022, 1, 18), state_holidays) + self.assertIn(date(2023, 2, 5), state_holidays) def test_PNG_holidays(self): - Penang_holidays = holidays.MY( - years=[2023, 2024, 2019, 2020, 2021, 2022], subdiv="PNG" - ) - self.assertIn(date(2020, 7, 7), Penang_holidays) - self.assertIn(date(2020, 7, 11), Penang_holidays) - self.assertIn(date(2019, 7, 13), Penang_holidays) - self.assertIn(date(2017, 7, 8), Penang_holidays) - self.assertIn(date(2024, 7, 13), Penang_holidays) - self.assertIn(date(2023, 7, 8), Penang_holidays) + state_holidays = self.penang_holidays + + # New Year's Day + self.assertIn(date(2018, 1, 1), state_holidays) + self.assertIn(date(2020, 1, 1), state_holidays) + self.assertIn(date(2022, 1, 1), state_holidays) + self.assertIn(date(2023, 1, 2), state_holidays) # In lieu + # Nuzul Al-Quran Day + self.assertIn(date(2018, 6, 2), state_holidays) + self.assertIn(date(2019, 5, 22), state_holidays) + self.assertIn(date(2020, 5, 10), state_holidays) + self.assertIn(date(2020, 5, 11), state_holidays) # In lieu + self.assertIn(date(2021, 4, 29), state_holidays) + self.assertIn(date(2022, 4, 19), state_holidays) + self.assertIn(date(2023, 4, 8), state_holidays) + # Thaipusam + self.assertIn(date(2018, 1, 31), state_holidays) + self.assertIn(date(2019, 1, 21), state_holidays) + self.assertIn(date(2020, 2, 8), state_holidays) + self.assertIn(date(2021, 1, 28), state_holidays) + self.assertIn(date(2022, 1, 18), state_holidays) + self.assertIn(date(2023, 2, 5), state_holidays) + self.assertIn(date(2023, 2, 6), state_holidays) # In lieu + # George Town Heritage Day + self.assertIn(date(2009, 7, 7), state_holidays) + self.assertIn(date(2020, 7, 7), state_holidays) + self.assertNotIn(date(2008, 7, 7), state_holidays) + # Birthday of the Governor of Penang + self.assertIn(date(2017, 7, 8), state_holidays) + self.assertIn(date(2019, 7, 13), state_holidays) + self.assertIn(date(2020, 7, 11), state_holidays) + self.assertIn(date(2022, 7, 9), state_holidays) + self.assertIn(date(2023, 7, 8), state_holidays) def test_PRK_holidays(self): - Perak_holidays = holidays.MY( - years=[2013, 2018, 2019, 2020, 2021, 2022], subdiv="PRK" - ) - self.assertIn(date(2018, 11, 2), Perak_holidays) - self.assertIn(date(2019, 11, 1), Perak_holidays) - self.assertIn(date(2020, 11, 6), Perak_holidays) - self.assertIn(date(2021, 11, 5), Perak_holidays) - self.assertIn(date(2022, 11, 4), Perak_holidays) - self.assertNotIn(date(2023, 11, 27), Perak_holidays) - self.assertIn(date(2013, 11, 27), Perak_holidays) + state_holidays = self.perak_holidays + + # New Year's Day + self.assertIn(date(2018, 1, 1), state_holidays) + self.assertIn(date(2020, 1, 1), state_holidays) + self.assertIn(date(2022, 1, 1), state_holidays) + self.assertIn(date(2023, 1, 2), state_holidays) # In lieu + # Nuzul Al-Quran Day + self.assertIn(date(2018, 6, 2), state_holidays) + self.assertIn(date(2019, 5, 22), state_holidays) + self.assertIn(date(2020, 5, 10), state_holidays) + self.assertIn(date(2020, 5, 11), state_holidays) # In lieu + self.assertIn(date(2021, 4, 29), state_holidays) + self.assertIn(date(2022, 4, 19), state_holidays) + self.assertIn(date(2023, 4, 8), state_holidays) + # Thaipusam + self.assertIn(date(2018, 1, 31), state_holidays) + self.assertIn(date(2019, 1, 21), state_holidays) + self.assertIn(date(2020, 2, 8), state_holidays) + self.assertIn(date(2021, 1, 28), state_holidays) + self.assertIn(date(2022, 1, 18), state_holidays) + self.assertIn(date(2023, 2, 5), state_holidays) + self.assertIn(date(2023, 2, 6), state_holidays) # In lieu + # Birthday of the Sultan of Perak + self.assertIn(date(2009, 11, 27), state_holidays) + self.assertIn(date(2017, 11, 27), state_holidays) + self.assertIn(date(2018, 11, 2), state_holidays) + self.assertIn(date(2019, 11, 1), state_holidays) + self.assertIn(date(2020, 11, 6), state_holidays) + self.assertIn(date(2021, 11, 5), state_holidays) + self.assertIn(date(2022, 11, 4), state_holidays) + self.assertNotIn(date(2018, 11, 27), state_holidays) def test_SBH_holidays(self): - Sabah_holidays = holidays.MY( - years=[2017, 2018, 2019, 2020, 2021, 2022], subdiv="SBH" - ) - self.assertIn(date(2018, 5, 30), Sabah_holidays) - self.assertIn(date(2018, 5, 31), Sabah_holidays) - self.assertIn(date(2020, 5, 31), Sabah_holidays) - self.assertIn(date(2020, 5, 30), Sabah_holidays) - self.assertIn(date(2017, 10, 7), Sabah_holidays) - self.assertIn(date(2018, 10, 6), Sabah_holidays) - self.assertIn(date(2019, 10, 5), Sabah_holidays) - self.assertIn(date(2020, 10, 3), Sabah_holidays) - self.assertIn(date(2020, 12, 24), Sabah_holidays) - self.assertNotIn(date(2010, 12, 24), Sabah_holidays) + state_holidays = self.sabah_holidays + + # New Year's Day + self.assertIn(date(2018, 1, 1), state_holidays) + self.assertIn(date(2020, 1, 1), state_holidays) + self.assertIn(date(2022, 1, 1), state_holidays) + self.assertIn(date(2023, 1, 2), state_holidays) # In lieu + # Pesta Kaamatan + self.assertIn(date(2018, 5, 30), state_holidays) + self.assertIn(date(2019, 5, 31), state_holidays) + # Good Friday + self.assertIn(date(2018, 3, 30), state_holidays) + self.assertIn(date(2020, 4, 10), state_holidays) + self.assertIn(date(2021, 4, 2), state_holidays) + self.assertIn(date(2022, 4, 15), state_holidays) + self.assertIn(date(2023, 4, 7), state_holidays) + # Birthday of the Governor of Sabah + self.assertIn(date(2017, 10, 7), state_holidays) + self.assertIn(date(2018, 10, 6), state_holidays) + self.assertIn(date(2019, 10, 5), state_holidays) + self.assertIn(date(2020, 10, 3), state_holidays) + # Christmas Eve + self.assertIn(date(2019, 12, 24), state_holidays) + self.assertIn(date(2020, 12, 24), state_holidays) + self.assertNotIn(date(2018, 12, 24), state_holidays) def test_SWK_holidays(self): - Sarawakholidays = holidays.MY( - years=[2018, 2019, 2020, 2021, 2022], subdiv="SWK" - ) + state_holidays = self.sarawak_holidays + + # New Year's Day + self.assertIn(date(2018, 1, 1), state_holidays) + self.assertIn(date(2020, 1, 1), state_holidays) + self.assertIn(date(2022, 1, 1), state_holidays) + self.assertIn(date(2023, 1, 2), state_holidays) # In lieu + # Good Friday + self.assertIn(date(2018, 3, 30), state_holidays) + self.assertIn(date(2020, 4, 10), state_holidays) + self.assertIn(date(2021, 4, 2), state_holidays) + self.assertIn(date(2022, 4, 15), state_holidays) + self.assertIn(date(2023, 4, 7), state_holidays) # Gawai Dayak - self.assertIn(date(2018, 6, 1), Sarawakholidays) - self.assertIn(date(2018, 6, 2), Sarawakholidays) - self.assertIn(date(2020, 6, 2), Sarawakholidays) - self.assertIn(date(2020, 6, 2), Sarawakholidays) + self.assertIn(date(2018, 6, 1), state_holidays) + self.assertIn(date(2018, 6, 2), state_holidays) + self.assertIn(date(2020, 6, 2), state_holidays) + self.assertIn(date(2020, 6, 2), state_holidays) # Birthday of the Governor of Sarawak - self.assertIn(date(2018, 10, 13), Sarawakholidays) - self.assertIn(date(2019, 10, 12), Sarawakholidays) - self.assertIn(date(2020, 10, 10), Sarawakholidays) - self.assertIn(date(2021, 10, 9), Sarawakholidays) - self.assertIn(date(2022, 10, 8), Sarawakholidays) + self.assertIn(date(2018, 10, 13), state_holidays) + self.assertIn(date(2019, 10, 12), state_holidays) + self.assertIn(date(2020, 10, 10), state_holidays) + self.assertIn(date(2021, 10, 9), state_holidays) + self.assertIn(date(2022, 10, 8), state_holidays) # Sarawak Day - self.assertIn(date(2022, 7, 22), Sarawakholidays) - self.assertNotIn(date(2014, 7, 22), Sarawakholidays) + self.assertIn(date(2017, 7, 22), state_holidays) + self.assertIn(date(2018, 7, 22), state_holidays) + self.assertIn(date(2018, 7, 23), state_holidays) # In lieu + self.assertIn(date(2022, 7, 22), state_holidays) + self.assertNotIn(date(2014, 7, 22), state_holidays) + # Deepavali + self.assertNotIn(date(2018, 11, 6), state_holidays) + self.assertNotIn(date(2022, 10, 24), state_holidays) def test_SGR_holidays(self): - Selangor_holidays = holidays.MY( - years=[2018, 2019, 2020, 2021, 2022], subdiv="SGR" - ) - # Birthday of The Sultan of Selangor - self.assertIn(date(2018, 12, 11), Selangor_holidays) - self.assertIn(date(2019, 12, 11), Selangor_holidays) + state_holidays = self.selangor_holidays + + # New Year's Day + self.assertIn(date(2018, 1, 1), state_holidays) + self.assertIn(date(2020, 1, 1), state_holidays) + self.assertIn(date(2022, 1, 1), state_holidays) + self.assertIn(date(2023, 1, 2), state_holidays) # In lieu + # Nuzul Al-Quran Day + self.assertIn(date(2018, 6, 2), state_holidays) + self.assertIn(date(2019, 5, 22), state_holidays) + self.assertIn(date(2020, 5, 10), state_holidays) + self.assertIn(date(2020, 5, 11), state_holidays) # In lieu + self.assertIn(date(2021, 4, 29), state_holidays) + self.assertIn(date(2022, 4, 19), state_holidays) + self.assertIn(date(2023, 4, 8), state_holidays) # Thaipusam - self.assertIn(date(2021, 1, 28), Selangor_holidays) - self.assertIn(date(2022, 1, 18), Selangor_holidays) + self.assertIn(date(2018, 1, 31), state_holidays) + self.assertIn(date(2019, 1, 21), state_holidays) + self.assertIn(date(2020, 2, 8), state_holidays) + self.assertIn(date(2021, 1, 28), state_holidays) + self.assertIn(date(2022, 1, 18), state_holidays) + self.assertIn(date(2023, 2, 5), state_holidays) + self.assertIn(date(2023, 2, 6), state_holidays) # In lieu + # Birthday of The Sultan of Selangor + self.assertIn(date(2018, 12, 11), state_holidays) + self.assertIn(date(2019, 12, 11), state_holidays) def test_TRG_holidays(self): - Terengganu_holidays = holidays.MY( - years=[2018, 2019, 2020, 2021, 2022], subdiv="TRG" - ) + state_holidays = self.terengganu_holidays + + # Arafat Day + self.assertIn(date(2018, 8, 21), state_holidays) + self.assertIn(date(2019, 8, 10), state_holidays) + self.assertIn(date(2019, 8, 13), state_holidays) # In lieu + self.assertIn(date(2020, 7, 30), state_holidays) + self.assertIn(date(2021, 7, 19), state_holidays) + self.assertIn(date(2022, 7, 9), state_holidays) + self.assertIn(date(2022, 7, 12), state_holidays) # In lieu + self.assertIn(date(2023, 6, 27), state_holidays) + # Hari Raya Haji + self.assertIn(date(2018, 8, 22), state_holidays) + self.assertIn(date(2019, 8, 11), state_holidays) + self.assertIn(date(2020, 7, 31), state_holidays) + self.assertIn(date(2021, 7, 20), state_holidays) + self.assertIn(date(2022, 7, 10), state_holidays) + self.assertIn(date(2023, 6, 28), state_holidays) + # Hari Raya Haji Holiday + self.assertIn(date(2018, 8, 23), state_holidays) + self.assertIn(date(2019, 8, 12), state_holidays) + self.assertIn(date(2020, 8, 1), state_holidays) + self.assertIn(date(2020, 8, 2), state_holidays) # In lieu + self.assertIn(date(2021, 7, 21), state_holidays) + self.assertIn(date(2022, 7, 11), state_holidays) + self.assertIn(date(2023, 6, 29), state_holidays) + # Isra and Mi'raj + self.assertIn(date(2020, 3, 22), state_holidays) + self.assertIn(date(2021, 3, 11), state_holidays) + self.assertIn(date(2022, 3, 1), state_holidays) + self.assertIn(date(2023, 2, 18), state_holidays) + self.assertIn(date(2023, 2, 19), state_holidays) # In lieu + self.assertNotIn(date(2018, 4, 14), state_holidays) + self.assertNotIn(date(2019, 4, 3), state_holidays) + # Nuzul Al-Quran Day + self.assertIn(date(2018, 6, 2), state_holidays) + self.assertIn(date(2018, 6, 3), state_holidays) # In lieu + self.assertIn(date(2019, 5, 22), state_holidays) + self.assertIn(date(2020, 5, 10), state_holidays) + self.assertIn(date(2021, 4, 29), state_holidays) + self.assertIn(date(2022, 4, 19), state_holidays) + self.assertIn(date(2023, 4, 8), state_holidays) + self.assertIn(date(2023, 4, 9), state_holidays) # In lieu # Anniversary of the Installation of the Sultan of Terengganu - self.assertIn(date(2018, 3, 4), Terengganu_holidays) - self.assertIn(date(2019, 3, 4), Terengganu_holidays) + self.assertIn(date(2000, 3, 4), state_holidays) + self.assertIn(date(2018, 3, 4), state_holidays) + self.assertIn(date(2019, 3, 4), state_holidays) + self.assertNotIn(date(1999, 3, 4), state_holidays) # Birthday of the Sultan of Terengganu - self.assertIn(date(2020, 4, 26), Terengganu_holidays) - self.assertIn(date(2029, 4, 26), Terengganu_holidays) - # The Arafat Day is one day before Eid al-Adha - self.assertIn(date(2021, 7, 20), Terengganu_holidays) - self.assertIn(date(2022, 7, 9), Terengganu_holidays) + self.assertIn(date(2020, 4, 26), state_holidays) + self.assertIn(date(2022, 4, 26), state_holidays) + self.assertNotIn(date(1999, 4, 26), state_holidays) + # Labour Day Holiday + self.assertIn(date(2022, 5, 4), state_holidays) + # Malaysia Day [In lieu] + self.assertNotIn(date(2018, 9, 17), state_holidays) def test_KUL_holidays(self): - Kuala_Lumpur_holidays = holidays.MY( - years=[1970, 2018, 2019, 2020, 2021, 2022, 2023], subdiv="KUL" - ) + state_holidays = self.kuala_lumpur_holidays + + # New Year's Day + self.assertIn(date(2018, 1, 1), state_holidays) + self.assertIn(date(2020, 1, 1), state_holidays) + self.assertIn(date(2022, 1, 1), state_holidays) + self.assertIn(date(2023, 1, 2), state_holidays) # In lieu # Federal Territory Day - self.assertIn(date(2018, 2, 1), Kuala_Lumpur_holidays) - self.assertIn(date(2019, 2, 1), Kuala_Lumpur_holidays) - self.assertNotIn(date(1970, 2, 1), Kuala_Lumpur_holidays) - self.assertEqual( - self.holidays[date(2023, 1, 2)], "New Year's Day [In lieu]" - ) + self.assertIn(date(2018, 2, 1), state_holidays) + self.assertIn(date(2019, 2, 1), state_holidays) + self.assertNotIn(date(1970, 2, 1), state_holidays) + # Thaipusam + self.assertIn(date(2018, 1, 31), state_holidays) + self.assertIn(date(2019, 1, 21), state_holidays) + self.assertIn(date(2020, 2, 8), state_holidays) + self.assertIn(date(2021, 1, 28), state_holidays) + self.assertIn(date(2022, 1, 18), state_holidays) + self.assertIn(date(2023, 2, 5), state_holidays) + # Malaysia Cup Holiday + self.assertIn(date(2021, 12, 3), state_holidays) def test_MLK_holidays(self): - Malacca_holidays = holidays.MY( - years=[2018, 2019, 2020, 2021, 2022], subdiv="MLK" - ) - # Declaration of Malacca as a Historical City in Melaka - self.assertIn(date(2018, 4, 15), Malacca_holidays) - self.assertIn(date(2019, 4, 15), Malacca_holidays) - # Birthday of the Governor of MelakaMelaka + state_holidays = self.malacca_holidays - # self.assertIn(date(2018, 10, 12), Malacca_holidays) - # self.assertIn(date(2019, 10, 11), Malacca_holidays) - # self.assertIn(date(2020, 10, 9), Malacca_holidays) - # self.assertIn(date(2021, 10, 8), Malacca_holidays) + # New Year's Day + self.assertIn(date(2018, 1, 1), state_holidays) + self.assertIn(date(2020, 1, 1), state_holidays) + self.assertIn(date(2022, 1, 1), state_holidays) + self.assertIn(date(2023, 1, 2), state_holidays) # In lieu + # Beginning of Ramadan + self.assertIn(date(2018, 5, 17), state_holidays) + self.assertIn(date(2019, 5, 6), state_holidays) + self.assertIn(date(2020, 4, 24), state_holidays) + self.assertIn(date(2021, 4, 13), state_holidays) + self.assertIn(date(2022, 4, 3), state_holidays) + self.assertIn(date(2022, 4, 4), state_holidays) # In lieu + self.assertIn(date(2023, 3, 23), state_holidays) + # Declaration of Malacca as a Historical City + self.assertIn(date(2018, 4, 15), state_holidays) + self.assertIn(date(2019, 4, 15), state_holidays) + self.assertNotIn(date(1985, 4, 15), state_holidays) + # Birthday of the Governor of Malacca + self.assertIn(date(2018, 10, 12), state_holidays) + self.assertIn(date(2019, 10, 11), state_holidays) + self.assertIn(date(2020, 8, 24), state_holidays) + self.assertIn(date(2021, 8, 24), state_holidays) + self.assertIn(date(2022, 8, 24), state_holidays) + self.assertNotIn(date(2019, 8, 24), state_holidays) + self.assertNotIn(date(2020, 10, 9), state_holidays) def test_LBN_holidays(self): - Labuan_holidays = holidays.MY( - years=[1972, 2018, 2019, 2020, 2021, 2022], subdiv="LBN" - ) - # Pesta Kaamatan - self.assertIn(date(2018, 5, 30), Labuan_holidays) - self.assertIn(date(2019, 5, 31), Labuan_holidays) + state_holidays = self.labuan_holidays + + # New Year's Day + self.assertIn(date(2018, 1, 1), state_holidays) + self.assertIn(date(2020, 1, 1), state_holidays) + self.assertIn(date(2022, 1, 1), state_holidays) + self.assertIn(date(2023, 1, 2), state_holidays) # In lieu # Federal Territory Day - self.assertIn(date(2020, 2, 1), Labuan_holidays) - self.assertIn(date(2022, 2, 1), Labuan_holidays) - self.assertNotIn(date(1972, 2, 1), Labuan_holidays) + self.assertIn(date(2020, 2, 1), state_holidays) + self.assertIn(date(2022, 2, 1), state_holidays) + self.assertNotIn(date(1970, 2, 1), state_holidays) + # Pesta Kaamatan + self.assertIn(date(2018, 5, 30), state_holidays) + self.assertIn(date(2019, 5, 31), state_holidays) + # Nuzul Al-Quran Day + self.assertIn(date(2018, 6, 2), state_holidays) + self.assertIn(date(2019, 5, 22), state_holidays) + self.assertIn(date(2020, 5, 10), state_holidays) + self.assertIn(date(2020, 5, 11), state_holidays) # In lieu + self.assertIn(date(2021, 4, 29), state_holidays) + self.assertIn(date(2022, 4, 19), state_holidays) + self.assertIn(date(2023, 4, 8), state_holidays) + # Malaysia Cup Holiday + self.assertIn(date(2021, 12, 3), state_holidays) - def test_PJY_holidays(self): - Putrajaya_holidays = holidays.MY( - years=[2018, 2019, 2020, 2021, 2022], subdiv="PJY" + def test_PHG_holidays(self): + state_holidays = self.pahang_holidays + + # New Year's Day + self.assertIn(date(2018, 1, 1), state_holidays) + self.assertIn(date(2020, 1, 1), state_holidays) + self.assertIn(date(2022, 1, 1), state_holidays) + self.assertIn(date(2023, 1, 2), state_holidays) # In lieu + # Nuzul Al-Quran Day + self.assertIn(date(2018, 6, 2), state_holidays) + self.assertIn(date(2019, 5, 22), state_holidays) + self.assertIn(date(2020, 5, 10), state_holidays) + self.assertIn(date(2020, 5, 11), state_holidays) # In lieu + self.assertIn(date(2021, 4, 29), state_holidays) + self.assertIn(date(2022, 4, 19), state_holidays) + self.assertIn(date(2023, 4, 8), state_holidays) + # Hari Hol of Pahang + self.assertIn(date(2001, 5, 7), state_holidays) + self.assertIn(date(2018, 5, 7), state_holidays) + self.assertIn(date(2019, 5, 7), state_holidays) + self.assertIn(date(2020, 5, 22), state_holidays) + self.assertIn(date(2021, 5, 22), state_holidays) + self.assertIn(date(2022, 5, 22), state_holidays) + self.assertNotIn(date(2010, 5, 22), state_holidays) + self.assertNotIn(date(2021, 5, 7), state_holidays) + self.assertNotEqual( + state_holidays[date(2020, 5, 7)], "Hari Hol of Pahang" ) + + def test_PLS_holidays(self): + state_holidays = self.perlis_holidays + + # Hari Raya Haji + self.assertIn(date(2018, 8, 22), state_holidays) + self.assertIn(date(2019, 8, 11), state_holidays) + self.assertIn(date(2020, 7, 31), state_holidays) + self.assertIn(date(2021, 7, 20), state_holidays) + self.assertIn(date(2022, 7, 10), state_holidays) + self.assertIn(date(2023, 6, 28), state_holidays) + # Hari Raya Haji Holiday + self.assertIn(date(2018, 8, 23), state_holidays) + self.assertIn(date(2019, 8, 12), state_holidays) + self.assertIn(date(2019, 8, 13), state_holidays) # In lieu + self.assertIn(date(2020, 8, 1), state_holidays) + self.assertIn(date(2021, 7, 21), state_holidays) + self.assertIn(date(2022, 7, 11), state_holidays) + self.assertIn(date(2022, 7, 12), state_holidays) # In lieu + self.assertIn(date(2023, 6, 29), state_holidays) + # Isra and Mi'raj + self.assertIn(date(2018, 4, 14), state_holidays) + self.assertIn(date(2019, 4, 3), state_holidays) + self.assertIn(date(2020, 3, 22), state_holidays) + self.assertIn(date(2020, 3, 23), state_holidays) # In lieu + self.assertIn(date(2021, 3, 11), state_holidays) + self.assertIn(date(2022, 3, 1), state_holidays) + self.assertIn(date(2023, 2, 18), state_holidays) + # Nuzul Al-Quran Day + self.assertIn(date(2018, 6, 2), state_holidays) + self.assertIn(date(2019, 5, 22), state_holidays) + self.assertIn(date(2020, 5, 10), state_holidays) + self.assertIn(date(2020, 5, 11), state_holidays) # In lieu + self.assertIn(date(2021, 4, 29), state_holidays) + self.assertIn(date(2022, 4, 19), state_holidays) + self.assertIn(date(2023, 4, 8), state_holidays) + # Birthday of The Raja of Perlis + self.assertIn(date(2000, 5, 17), state_holidays) + self.assertIn(date(2010, 5, 17), state_holidays) + self.assertIn(date(2017, 5, 17), state_holidays) + self.assertIn(date(2018, 7, 17), state_holidays) + self.assertIn(date(2022, 7, 17), state_holidays) + self.assertNotIn(date(2017, 7, 17), state_holidays) + self.assertNotIn(date(2018, 5, 17), state_holidays) + + def test_PJY_holidays(self): + state_holidays = self.putrajaya_holidays + + # New Year's Day + self.assertIn(date(2018, 1, 1), state_holidays) + self.assertIn(date(2020, 1, 1), state_holidays) + self.assertIn(date(2022, 1, 1), state_holidays) + self.assertIn(date(2023, 1, 2), state_holidays) # In lieu + # Nuzul Al-Quran Day + self.assertIn(date(2018, 6, 2), state_holidays) + self.assertIn(date(2019, 5, 22), state_holidays) + self.assertIn(date(2020, 5, 10), state_holidays) + self.assertIn(date(2020, 5, 11), state_holidays) # In lieu + self.assertIn(date(2021, 4, 29), state_holidays) + self.assertIn(date(2022, 4, 19), state_holidays) + self.assertIn(date(2023, 4, 8), state_holidays) + # Thaipusam + self.assertIn(date(2018, 1, 31), state_holidays) + self.assertIn(date(2019, 1, 21), state_holidays) + self.assertIn(date(2020, 2, 8), state_holidays) + self.assertIn(date(2021, 1, 28), state_holidays) + self.assertIn(date(2022, 1, 18), state_holidays) + self.assertIn(date(2023, 2, 5), state_holidays) + self.assertIn(date(2023, 2, 6), state_holidays) # In lieu # Federal Territory Day - self.assertIn(date(2020, 2, 1), Putrajaya_holidays) - self.assertIn(date(2022, 2, 1), Putrajaya_holidays) - self.assertNotIn(date(1972, 2, 1), Putrajaya_holidays) - self.assertIn(date(2022, 1, 18), Putrajaya_holidays) + self.assertIn(date(2018, 2, 1), state_holidays) + self.assertIn(date(2019, 2, 1), state_holidays) + self.assertNotIn(date(1970, 2, 1), state_holidays) + # Malaysia Cup Holiday + self.assertIn(date(2021, 12, 3), state_holidays) def test_aliases(self): holidays1 = holidays.MY() From 4df0056faf162d1b1d3ad80f545d99c0e90026cd Mon Sep 17 00:00:00 2001 From: dr-prodigy <28216945+dr-prodigy@users.noreply.github.com> Date: Thu, 8 Dec 2022 10:17:55 +0100 Subject: [PATCH 042/138] CHANGES sync --- CHANGES | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES b/CHANGES index ab3dcef7b..664be32fd 100644 --- a/CHANGES +++ b/CHANGES @@ -15,6 +15,7 @@ Released ???????? ??, ???? - Korea fixes #791 (KJhellico) + test optimizations (dr-p) - Zambia: optimizations and refactoring #798 (KJhellico) - Vietnam: optimizations and refactoring #799 (KJhellico) +- Malaysia: optimizations and refactoring #802 (KJhellico) - Uruguay updates #809 (KJhellico) - Canada fixes #811 (jasonjensen) From 1e95f623896b66067e4035455a7583d67579fb21 Mon Sep 17 00:00:00 2001 From: ~Jhellico Date: Fri, 9 Dec 2022 01:25:03 +0200 Subject: [PATCH 043/138] Nigeria holiday updates (#823) --- holidays/countries/nigeria.py | 134 ++++++++++++++++----------------- test/countries/test_nigeria.py | 12 +++ 2 files changed, 79 insertions(+), 67 deletions(-) diff --git a/holidays/countries/nigeria.py b/holidays/countries/nigeria.py index 891c8a798..72e42601f 100644 --- a/holidays/countries/nigeria.py +++ b/holidays/countries/nigeria.py @@ -14,7 +14,7 @@ from dateutil.easter import easter from dateutil.relativedelta import relativedelta as rd -from holidays.constants import SAT, JAN, MAY, JUN, OCT, DEC +from holidays.constants import WEEKEND, JAN, MAY, JUN, OCT, DEC from holidays.holiday_base import HolidayBase from holidays.utils import _islamic_to_gre @@ -27,79 +27,79 @@ class Nigeria(HolidayBase): country = "NG" def _populate(self, year): + def _add_holiday(dt: date, hol: str) -> None: + """Only add if in current year; prevents adding holidays across + years (handles multi-day Islamic holidays that straddle + Gregorian years). + """ + if dt.year == year: + self[dt] = hol + + if year <= 1978: + return super()._populate(year) - if year > 1978: + # New Year's Day + self[date(year, JAN, 1)] = "New Year's day" - def _add_holiday(dt: date, hol: str) -> None: - """Only add if in current year; prevents adding holidays across - years (handles multi-day Islamic holidays that straddle - Gregorian years). - """ - if dt.year == year: - self[dt] = hol + # Calculate Easter for given year + # followed by easter related holidays + easter_date = easter(year) + self[easter_date + rd(days=-2)] = "Good Friday" + self[easter_date + rd(days=+1)] = "Easter Monday" - # New Year's Day - self[date(year, JAN, 1)] = "New Year's day" - - # Calculate Easter for given year - # followed by easter related holidays - easter_date = easter(year) - self[easter_date + rd(days=-2)] = "Good Friday" - self[easter_date + rd(days=+1)] = "Easter Monday" - - # Worker's day + # Worker's day + if year >= 1981: self[date(year, MAY, 1)] = "Workers' day" - # Eid al-Fitr - Feast Festive - # This is an estimate - # date of observance is announced yearly - for yr in (year - 1, year): - for date_obs in _islamic_to_gre(yr, 10, 1): - hol_date = date_obs - _add_holiday(hol_date, "Eid al-Fitr") - _add_holiday(hol_date + rd(days=1), "Eid al-Fitr Holiday") - - # Arafat Day & Eid al-Adha - Scarfice Festive - # This is an estimate - # date of observance is announced yearly - for yr in (year - 1, year): - for date_obs in _islamic_to_gre(yr, 12, 10): - hol_date = date_obs - _add_holiday(hol_date, "Eid al-Adha") - _add_holiday(hol_date + rd(days=1), "Eid al-Adha Holiday") - - # Independence Day - self[date(year, OCT, 1)] = "National day" - - # Christmas day - self[date(year, DEC, 25)] = "Christmas day" - - # Boxing day - self[date(year, DEC, 26)] = "Boxing day" - - # Democracy day moved around after its inception in 2000 - # Initally it fell on May 29th - if 2019 > year > 1999: - self[date(year, MAY, 29)] = "Democracy day" - # In 2018 it was announced that the holiday - # will move to June 12th from 2019 - if year >= 2019: - self[date(year, JUN, 12)] = "Democracy day" - - # Observed holidays + # Eid al-Fitr - Feast Festive + # This is an estimate + # date of observance is announced yearly + for yr in (year - 1, year): + for hol_date in _islamic_to_gre(yr, 10, 1): + _add_holiday(hol_date, "Eid al-Fitr") + _add_holiday(hol_date + rd(days=1), "Eid al-Fitr Holiday") + + # Arafat Day & Eid al-Adha - Scarfice Festive + # This is an estimate + # date of observance is announced yearly + for yr in (year - 1, year): + for hol_date in _islamic_to_gre(yr, 12, 10): + _add_holiday(hol_date, "Eid al-Adha") + _add_holiday(hol_date + rd(days=1), "Eid al-Adha Holiday") + + # Birthday of Prophet Muhammad + for hol_date in _islamic_to_gre(year, 3, 12): + _add_holiday(hol_date, "Mawlid") + + # Independence Day + self[date(year, OCT, 1)] = "Independence day" + + # Christmas day + self[date(year, DEC, 25)] = "Christmas day" + + # Boxing day + self[date(year, DEC, 26)] = "Boxing day" + + # Democracy day moved around after its inception in 2000 + # Initally it fell on May 29th + # In 2018 it was announced that the holiday + # will move to June 12th from 2019 + if year >= 2019: + self[date(year, JUN, 12)] = "Democracy day" + elif year >= 2000: + self[date(year, MAY, 29)] = "Democracy day" + + # Observed holidays + if self.observed and year >= 2016: for k, v in list(self.items()): - # If a holiday falls on a Saturday the - # following Monday is Observed as a public holiday - if ( - self.observed - and year > 2015 - and k.weekday() == SAT - and k.year == year - and v.upper() in {"DEMOCRACY DAY", "WORKER'S DAY"} - ): - # Add the (Observed) holiday - self[k + rd(days=2)] = v + " (Observed)" + if k.weekday() in WEEKEND and k.year == year: + next_workday = k + rd(days=+1) + while next_workday.weekday() in WEEKEND or self.get( + next_workday + ): + next_workday += rd(days=+1) + self[next_workday] = v + " (Observed)" class NG(Nigeria): diff --git a/test/countries/test_nigeria.py b/test/countries/test_nigeria.py index 7a13dfbb2..d0420ef53 100644 --- a/test/countries/test_nigeria.py +++ b/test/countries/test_nigeria.py @@ -21,6 +21,10 @@ def setUp(self): def test_not_holiday(self): self.assertNotIn(date(1966, 1, 1), self.holidays) + self.assertNotIn(date(1980, 5, 1), self.holidays) + self.assertNotIn(date(2019, 5, 29), self.holidays) + self.assertNotIn(date(1999, 5, 29), self.holidays) + self.assertNotIn(date(1999, 6, 12), self.holidays) def test_fixed_holidays(self): self.assertIn(date(2015, 5, 29), self.holidays) @@ -32,3 +36,11 @@ def test_fixed_holidays(self): self.assertIn(date(2019, 12, 26), self.holidays) self.assertIn(date(2020, 6, 12), self.holidays) self.assertIn(date(2021, 6, 14), self.holidays) + + def test_not_observed(self): + self.holidays = holidays.Nigeria(observed=False) + self.assertNotIn(date(2017, 1, 2), self.holidays) + self.assertNotIn(date(2017, 10, 2), self.holidays) + self.assertNotIn(date(2019, 8, 13), self.holidays) + self.assertNotIn(date(2020, 12, 28), self.holidays) + self.assertNotIn(date(2021, 5, 3), self.holidays) From 69fb0a06cc29fad24436e84e3c0bb10dceffd7ab Mon Sep 17 00:00:00 2001 From: SnowX65 <39384983+SnowX65@users.noreply.github.com> Date: Fri, 9 Dec 2022 00:30:30 +0100 Subject: [PATCH 044/138] Financial holiday - Day of Mourning for President George H.W. Bush (#817) --- holidays/financial/ny_stock_exchange.py | 4 ++++ test/financial/test_ny_stock_exchange.py | 3 +++ 2 files changed, 7 insertions(+) diff --git a/holidays/financial/ny_stock_exchange.py b/holidays/financial/ny_stock_exchange.py index 1158bce0a..664919b94 100644 --- a/holidays/financial/ny_stock_exchange.py +++ b/holidays/financial/ny_stock_exchange.py @@ -291,6 +291,10 @@ def _populate(self, year): self[ date(year, JAN, 2) ] = "Day of Mourning for President Gerald R. Ford" + elif year == 2018: + self[ + date(year, DEC, 5) + ] = "Day of Mourning for President George H.W. Bush" class XNYS(NewYorkStockExchange): diff --git a/test/financial/test_ny_stock_exchange.py b/test/financial/test_ny_stock_exchange.py index cc13f810f..f036e830d 100644 --- a/test/financial/test_ny_stock_exchange.py +++ b/test/financial/test_ny_stock_exchange.py @@ -420,6 +420,9 @@ def test_special_holidays(self): 2004, JUN, 11 ), # Day of Mourning for President Ronald W. Reagan date(2007, JAN, 2), # Day of Mourning for President Gerald R. Ford + date( + 2018, DEC, 5 + ), # Day of Mourning for President George H.W. Bush ] def _make_special_holiday_list(begin, end, days=None, weekends=False): From 19a350beba90764394eba7b50c7dadfd1507b27d Mon Sep 17 00:00:00 2001 From: ~Jhellico Date: Fri, 9 Dec 2022 01:34:27 +0200 Subject: [PATCH 045/138] Madagascar: added holidays with tests (#818) --- holidays/countries/madagascar.py | 64 +++++++++++++++++++------------ test/countries/test_madagascar.py | 51 +++++++++++++++++++++++- 2 files changed, 88 insertions(+), 27 deletions(-) diff --git a/holidays/countries/madagascar.py b/holidays/countries/madagascar.py index 5ab47e550..916b43238 100644 --- a/holidays/countries/madagascar.py +++ b/holidays/countries/madagascar.py @@ -15,6 +15,7 @@ from dateutil.relativedelta import relativedelta as rd from dateutil.relativedelta import SU +from holidays.constants import JAN, MAR, MAY, JUN, AUG, NOV, DEC from holidays.holiday_base import HolidayBase @@ -27,38 +28,51 @@ class Madagascar(HolidayBase): country = "MG" def _populate(self, year): - super()._populate(year) - # Observed since 1947 if year <= 1946: return + super()._populate(year) + + self[date(year, JAN, 1)] = "Taom-baovao / New Year's Day" + self[date(year, MAR, 8)] = "Fetin'ny vehivavy / Women's Day" + self[date(year, MAR, 29)] = "Fetin'ny mahery fo / Martyrs' Day" + self[date(year, MAY, 1)] = "Labour Day" + self[ + date(year, JUN, 1) + rd(weekday=SU(+3)) + ] = "Fetin'ny ray / Father's Day" + + if year >= 1960: + self[date(year, JUN, 26)] = "Independence Day" + + self[ + date(year, AUG, 15) + ] = "Fiakaran'ny Masina Maria tany an-danitra / Assumption Day" + + self[date(year, NOV, 1)] = "Fetin'ny olo-masina / All Saints' Day" + + if year >= 2011: + self[date(year, DEC, 11)] = "Republic Day" + + self[date(year, DEC, 25)] = "Fetin'ny noely / Christmas Day" - self[date(year, 1, 1)] = "Taom-baovao" - self[date(year, 3, 8)] = "Fetin'ny vehivavy" - self[date(year, 3, 29)] = "Fetin'ny mahery fo" - self[date(year, 11, 1)] = "Fetin'ny olo-masina" - self[date(year, 12, 25)] = "Fetin'ny noely" easter_date = easter(year) - self[easter_date] = "fetin'ny paska" - self[easter_date + rd(days=+1)] = "Alatsinain'ny paska" - self[easter_date + rd(days=+49)] = "Pentekosta" - self[easter_date + rd(days=+50)] = "Alatsinain'ny pentekosta" - self[date(year, 6, 1) + rd(day=1, weekday=SU(3))] = "Fetin'ny ray" + self[easter_date] = "Fetin'ny paska / Easter Sunday" + self[easter_date + rd(days=+1)] = "Alatsinain'ny paska / Easter Monday" self[ easter_date + rd(days=+39) - ] = "Fiakaran'ny Jesosy kristy tany an-danitra" - self[date(year, 8, 15)] = "Fiakaran'ny Masina Maria tany an-danitra" - - if easter_date + rd(days=+49) == date(year, 5, 1) + rd( - day=31, weekday=SU(-1) - ): - self[ - date(year, 5, 1) + rd(day=31, weekday=SU(-1)) + rd(days=7) - ] = "Fetin'ny Reny" - else: - self[ - date(year, 5, 1) + rd(day=31, weekday=SU(-1)) - ] = "Fetin'ny Reny" + ] = "Fiakaran'ny Jesosy kristy tany an-danitra / Ascension Day" + + whit_sunday = easter_date + rd(days=+49) + self[whit_sunday] = "Pentekosta / Whit Sunday" + + self[ + easter_date + rd(days=+50) + ] = "Alatsinain'ny pentekosta / Whit Monday" + + dt = date(year, MAY, 31) + rd(weekday=SU(-1)) + if dt == whit_sunday: + dt += rd(days=+7) + self[dt] = "Fetin'ny Reny / Mother's Day" class MG(Madagascar): diff --git a/test/countries/test_madagascar.py b/test/countries/test_madagascar.py index 14ecf51dd..1559deec1 100644 --- a/test/countries/test_madagascar.py +++ b/test/countries/test_madagascar.py @@ -31,9 +31,56 @@ def test_mahery_fo(self): def test_paska(self): self.assertIn(date(2022, 4, 17), self.holidays) # Andron'ny paska self.assertIn(date(2022, 4, 18), self.holidays) # Alatsinain'ny Paska + self.assertIn(date(2022, 5, 26), self.holidays) + self.assertIn(date(2022, 6, 5), self.holidays) + self.assertIn(date(2022, 6, 6), self.holidays) - def test_not_holiday(self): - self.assertNotIn(date(2022, 4, 20), self.holidays) + def test_womens_day(self): + self.assertIn(date(2010, 3, 8), self.holidays) + self.assertIn(date(2020, 3, 8), self.holidays) + + def test_labour_day(self): + self.assertIn(date(2010, 5, 1), self.holidays) + self.assertIn(date(2020, 5, 1), self.holidays) + + def test_mother_day(self): + self.assertIn(date(2010, 5, 30), self.holidays) + self.assertIn(date(2018, 5, 27), self.holidays) + self.assertIn(date(2020, 6, 7), self.holidays) + self.assertIn(date(2022, 5, 29), self.holidays) + + def test_father_day(self): + self.assertIn(date(2010, 6, 20), self.holidays) + self.assertIn(date(2018, 6, 17), self.holidays) + self.assertIn(date(2020, 6, 21), self.holidays) + self.assertIn(date(2022, 6, 19), self.holidays) + + def test_independence_day(self): + self.assertIn(date(1960, 6, 26), self.holidays) + self.assertIn(date(2010, 6, 26), self.holidays) + self.assertIn(date(2020, 6, 26), self.holidays) + self.assertNotIn(date(1959, 6, 26), self.holidays) + + def test_assumption_day(self): + self.assertIn(date(2010, 8, 15), self.holidays) + self.assertIn(date(2020, 8, 15), self.holidays) + self.assertIn(date(2022, 8, 15), self.holidays) + + def test_all_saints_day(self): + self.assertIn(date(2010, 11, 1), self.holidays) + self.assertIn(date(2020, 11, 1), self.holidays) + self.assertIn(date(2022, 11, 1), self.holidays) + + def test_republic_day(self): + self.assertIn(date(2011, 12, 11), self.holidays) + self.assertIn(date(2020, 12, 11), self.holidays) + self.assertIn(date(2022, 12, 11), self.holidays) + self.assertNotIn(date(2010, 12, 11), self.holidays) + + def test_christmas_day(self): + self.assertIn(date(2010, 12, 25), self.holidays) + self.assertIn(date(2020, 12, 25), self.holidays) + self.assertIn(date(2022, 12, 25), self.holidays) def test_1946(self): mg_holidays = holidays.MG(years=1946) From 2aec3aea8d9c34ab1a26b7f4e68089af7e2c3d07 Mon Sep 17 00:00:00 2001 From: ~Jhellico Date: Fri, 9 Dec 2022 01:36:17 +0200 Subject: [PATCH 046/138] Paraguay updates (#819) - added special holidays - fixed observance calculation --- holidays/countries/paraguay.py | 232 ++++++++++++++++++++++++-------- test/countries/test_paraguay.py | 130 ++++++++++++++---- 2 files changed, 279 insertions(+), 83 deletions(-) diff --git a/holidays/countries/paraguay.py b/holidays/countries/paraguay.py index e0293028a..f34a45f35 100644 --- a/holidays/countries/paraguay.py +++ b/holidays/countries/paraguay.py @@ -13,9 +13,21 @@ from dateutil.easter import easter from dateutil.relativedelta import relativedelta as rd -from dateutil.relativedelta import MO -from holidays.constants import WED, WEEKEND, JAN, MAR, MAY, JUN, AUG, SEP, DEC +from holidays.constants import ( + WEEKEND, + JAN, + FEB, + MAR, + APR, + MAY, + JUN, + JUL, + AUG, + SEP, + OCT, + DEC, +) from holidays.holiday_base import HolidayBase @@ -27,82 +39,194 @@ class Paraguay(HolidayBase): """ country = "PY" + special_holidays = { + # public holiday for business purposes, in view of + # the recently increased risk of Dengue fever + 2007: ((JAN, 29, "Public Holiday"),), + # public sector holiday to celebrate Paraguay's + # football team's qualification for the 2010 World Cup + 2009: ((SEP, 10, "Public Holiday"),), + 2010: ( + # public holiday to coincide with the Paraguay-Italy + # game of the current World Cup + (JUN, 14, "Public Holiday"), + # 2 year-end public sector holidays + (DEC, 24, "Public sector Holiday"), + (DEC, 31, "Public sector Holiday"), + ), + 2011: ( + # public holiday to coincide with the current anti-Dengue drive + (APR, 19, "Public Holiday"), + # public sector holiday to let civil servants + # begin their Holy Week earlier + (APR, 20, "Public sector Holiday"), + # public holidays to commemorate the Bicentennial + # of Paraguay's independence + (MAY, 14, "Public Holiday"), + (MAY, 16, "Public Holiday"), + # 2 year-end public sector holidays + (DEC, 23, "Public sector Holiday"), + (DEC, 30, "Public sector Holiday"), + ), + 2012: ( + # public sector holiday to let civil servants + # begin their Holy Week earlier + (APR, 4, "Public sector Holiday"), + # 2 year-end public sector holidays + (DEC, 24, "Public sector Holiday"), + (DEC, 31, "Public sector Holiday"), + ), + 2013: ( + # public sector holiday to let civil servants + # begin their Holy Week earlier + (MAR, 27, "Public sector Holiday"), + # date of the inauguration of President-elect + # Horacio Cartes, as a one-off non-working public holiday + (AUG, 14, "Public Holiday"), + ), + 2014: ( + # public sector holiday to let civil servants + # begin their Holy Week earlier + (APR, 16, "Public sector Holiday"), + # 2 year-end public sector holidays + (DEC, 24, "Public sector Holiday"), + (DEC, 31, "Public sector Holiday"), + ), + 2015: ( + # public sector holiday to let civil servants + # begin their Holy Week earlier + (APR, 1, "Public sector Holiday"), + # public holidays in Paraguay on account + # of the upcoming visit of Pope Francis in Paraguay + (JUL, 10, "Public Holiday"), + (JUL, 11, "Public Holiday"), + # 2 year-end public sector holidays + (DEC, 24, "Public sector Holiday"), + (DEC, 31, "Public sector Holiday"), + ), + 2016: ( + # public sector holiday to let civil servants + # begin their Holy Week earlier + (MAR, 23, "Public sector Holiday"), + (DEC, 26, "Public Holiday"), + ), + 2017: ( + (JAN, 2, "Public Holiday"), + # public sector holiday to let civil servants + # begin their Holy Week earlier + (MAR, 28, "Public sector Holiday"), + ), + 2018: ( + # 2 year-end public sector holidays + (DEC, 24, "Public sector Holiday"), + (DEC, 31, "Public sector Holiday"), + ), + 2019: ( + # public sector holiday to let civil servants + # begin their Holy Week earlier + (APR, 17, "Public sector Holiday"), + # 2 year-end public sector holidays + (DEC, 24, "Public sector Holiday"), + (DEC, 31, "Public sector Holiday"), + ), + 2020: ( + # public sector holiday to let civil servants + # begin their Holy Week earlier + (APR, 8, "Public sector Holiday"), + ), + 2021: ( + # 2 year-end public sector holidays + (DEC, 24, "Public sector Holiday"), + (DEC, 31, "Public sector Holiday"), + ), + 2022: ( + # public sector holiday to let civil servants + # begin their Holy Week earlier + (APR, 13, "Public sector Holiday"), + # public sector holiday due to the annual May 1st + # public holiday falling on a Sunday + (MAY, 2, "Public Holiday"), + ), + } + + def _add_holiday(self, dt: date, name: str) -> None: + if self.observed or dt.weekday() not in WEEKEND: + self[dt] = name def _populate(self, year): super()._populate(year) # New Year's Day - if not self.observed and date(year, JAN, 1).weekday() in WEEKEND: - pass - else: - self[date(year, JAN, 1)] = "Año Nuevo [New Year's Day]" + self._add_holiday(date(year, JAN, 1), "Año Nuevo [New Year's Day]") # Patriots day - name = "Día de los Héroes de la Patria [Patriots Day]" - - if not self.observed and date(year, MAR, 1).weekday() in WEEKEND: - pass - elif date(year, MAR, 1).weekday() >= WED: - self[date(year, MAR, 1) + rd(weekday=MO(+1))] = name - else: - self[date(year, MAR, 1)] = name + dates_obs = { + 2013: (MAR, 4), + 2016: (FEB, 29), + 2018: (FEB, 26), + 2022: (FEB, 28), + } + self[ + date(year, *dates_obs.get(year, (MAR, 1))) + ] = "Día de los Héroes de la Patria [Patriots Day]" # Holy Week - name_thu = "Semana Santa (Jueves Santo) [Holy day (Holy Thursday)]" - name_fri = "Semana Santa (Viernes Santo) [Holy day (Holy Friday)]" - name_easter = "Día de Pascuas [Easter Day]" easter_date = easter(year) - self[easter_date + rd(days=-3)] = name_thu - self[easter_date + rd(days=-2)] = name_fri - - if not self.observed and easter_date.weekday() in WEEKEND: - pass - else: - self[easter_date] = name_easter + self[easter_date + rd(days=-3)] = "Jueves Santo [Maundy Thursday]" + self[easter_date + rd(days=-2)] = "Viernes Santo [Good Friday]" + self._add_holiday(easter_date, "Día de Pascuas [Easter Day]") # Labor Day - name = "Día de los Trabajadores [Labour Day]" - if not self.observed and date(year, MAY, 1).weekday() in WEEKEND: - pass - else: - self[date(year, MAY, 1)] = name + self._add_holiday( + date(year, MAY, 1), "Día del Trabajador [Labour Day]" + ) # Independence Day name = "Día de la Independencia Nacional [Independence Day]" - if not self.observed and date(year, MAY, 15).weekday() in WEEKEND: - pass - else: + if year == 2021: + self[date(year, MAY, 14)] = name self[date(year, MAY, 15)] = name + elif year >= 2012: + self._add_holiday(date(year, MAY, 14), name) + self._add_holiday(date(year, MAY, 15), name) + else: + self._add_holiday(date(year, MAY, 15), name) # Peace in Chaco Day. - name = "Día de la Paz del Chaco [Peace in Chaco Day]" - if not self.observed and date(year, JUN, 12).weekday() in WEEKEND: - pass - elif date(year, JUN, 12).weekday() >= WED: - self[date(year, JUN, 12) + rd(weekday=MO(+1))] = name - else: - self[date(year, JUN, 12)] = name + dates_obs = { + 2014: (JUN, 16), + 2018: (JUN, 11), + } + self._add_holiday( + date(year, *dates_obs.get(year, (JUN, 12))), + "Día de la Paz del Chaco [Chaco Armistice Day]", + ) # Asuncion Fundation's Day - name = "Día de la Fundación de Asunción [Asuncion Fundation's Day]" - if not self.observed and date(year, AUG, 15).weekday() in WEEKEND: - pass - else: - self[date(year, AUG, 15)] = name + self._add_holiday( + date(year, AUG, 15), + "Día de la Fundación de Asunción [Asuncion Foundation's Day]", + ) # Boqueron's Battle - name = "Batalla de Boquerón [Boqueron's Battle]" - if not self.observed and date(year, SEP, 29).weekday() in WEEKEND: - pass - else: - self[date(year, SEP, 29)] = name + if year >= 2000: + dates_obs = { + 2015: (SEP, 28), + 2016: (OCT, 3), + 2017: (OCT, 2), + 2021: (SEP, 27), + 2022: (OCT, 3), + } + self._add_holiday( + date(year, *dates_obs.get(year, (SEP, 29))), + "Día de la Batalla de Boquerón [Boqueron Battle Day]", + ) # Caacupe Virgin Day - name = "Día de la Virgen de Caacupé [Caacupe Virgin Day]" - if not self.observed and date(year, DEC, 8).weekday() in WEEKEND: - pass - else: - self[date(year, DEC, 8)] = name + self._add_holiday( + date(year, DEC, 8), + "Día de la Virgen de Caacupé [Caacupe Virgin Day]", + ) # Christmas self[date(year, DEC, 25)] = "Navidad [Christmas]" diff --git a/test/countries/test_paraguay.py b/test/countries/test_paraguay.py index 8167136a6..14eea4f12 100644 --- a/test/countries/test_paraguay.py +++ b/test/countries/test_paraguay.py @@ -20,40 +20,112 @@ def setUp(self): self.holidays = holidays.PY() def test_fixed_holidays(self): - checkdates = ( - date(2016, 1, 1), - date(2020, 1, 1), - date(2020, 3, 2), - date(2020, 4, 9), - date(2020, 5, 1), - date(2020, 5, 15), - date(2020, 6, 15), - date(2020, 8, 15), - date(2020, 9, 29), - date(2020, 12, 8), - date(2020, 12, 25), - ) - - for d in checkdates: - self.assertIn(d, self.holidays) + for year, month, day in ( + (2016, 1, 1), + (2020, 1, 1), + (2020, 3, 1), + (2020, 4, 8), + (2020, 4, 9), + (2020, 4, 10), + (2020, 4, 12), + (2020, 5, 1), + (2020, 5, 14), + (2020, 5, 15), + (2020, 6, 12), + (2020, 8, 15), + (2020, 9, 29), + (2020, 12, 8), + (2020, 12, 25), + ): + self.assertIn(date(year, month, day), self.holidays) def test_no_observed(self): # no observed dates self.holidays.observed = False - checkdates = ( - date(2017, 1, 1), - date(2014, 3, 2), - date(2020, 4, 12), - date(2016, 5, 1), - date(2016, 5, 15), - date(2016, 6, 12), - date(2015, 8, 15), - date(2018, 9, 29), - date(2018, 12, 8), - ) + for year, month, day in ( + (2017, 1, 1), + (2014, 3, 2), + (2020, 4, 12), + (2016, 5, 1), + (2016, 5, 15), + (2016, 6, 12), + (2015, 8, 15), + (2018, 9, 29), + (2018, 12, 8), + ): + self.assertNotIn(date(year, month, day), self.holidays) + + def test_moveable(self): + for year, month, day in ( + # Patriots day + (2013, 3, 4), + (2016, 2, 29), + (2018, 2, 26), + (2022, 2, 28), + (2014, 3, 1), + (2015, 3, 1), + (2017, 3, 1), + (2019, 3, 1), + (2020, 3, 1), + (2021, 3, 1), + # Peace in Chaco Day + (2014, 6, 16), + (2018, 6, 11), + (2013, 6, 12), + (2015, 6, 12), + (2016, 6, 12), + (2017, 6, 12), + (2019, 6, 12), + (2020, 6, 12), + (2021, 6, 12), + (2022, 6, 12), + # Boqueron's Battle + (2015, 9, 28), + (2016, 10, 3), + (2017, 10, 2), + (2021, 9, 27), + (2022, 10, 3), + (2013, 9, 29), + (2014, 9, 29), + (2018, 9, 29), + (2019, 9, 29), + (2020, 9, 29), + ): + self.assertIn(date(year, month, day), self.holidays) + + for year, month, day in ( + # Patriots day + (2013, 3, 1), + (2016, 3, 1), + (2018, 3, 1), + (2022, 3, 1), + # Peace in Chaco Day + (2014, 6, 12), + (2018, 6, 12), + # Boqueron's Battle + (1999, 9, 29), + (2015, 9, 29), + (2016, 9, 29), + (2017, 9, 29), + (2021, 9, 29), + (2022, 9, 29), + ): + self.assertNotIn(date(year, month, day), self.holidays) - for d in checkdates: - self.assertNotIn(d, self.holidays) + def test_independence_day(self): + for year, month, day in ( + (2010, 5, 15), + (2011, 5, 15), + (2012, 5, 14), + (2012, 5, 15), + (2013, 5, 14), + (2013, 5, 15), + (2018, 5, 14), + (2018, 5, 15), + (2021, 5, 14), + (2021, 5, 15), + ): + self.assertIn(date(year, month, day), self.holidays) def test_easter(self): for year, month, day in [ From 01c16abd890b6c6878fdf811921769928b51ecb3 Mon Sep 17 00:00:00 2001 From: ~Jhellico Date: Fri, 9 Dec 2022 01:37:22 +0200 Subject: [PATCH 047/138] South Africa: optimizations (#820) --- holidays/countries/south_africa.py | 116 ++++++++++++++--------------- 1 file changed, 57 insertions(+), 59 deletions(-) diff --git a/holidays/countries/south_africa.py b/holidays/countries/south_africa.py index 858d71af9..0a60f34a4 100644 --- a/holidays/countries/south_africa.py +++ b/holidays/countries/south_africa.py @@ -63,40 +63,41 @@ class SouthAfrica(HolidayBase): } def _populate(self, year): + # Observed since 1910, with a few name changes + if year <= 1909: + return super()._populate(year) - # Observed since 1910, with a few name changes - if year > 1909: - self[date(year, JAN, 1)] = "New Year's Day" - - easter_date = easter(year) - self[easter_date + rd(days=-2)] = "Good Friday" - if year > 1979: - name = "Family Day" - else: - name = "Easter Monday" - self[easter_date + rd(days=+1)] = name - - if 1909 < year < 1952: - dec_16_name = "Dingaan's Day" - elif 1951 < year < 1980: - dec_16_name = "Day of the Covenant" - elif 1979 < year < 1995: - dec_16_name = "Day of the Vow" - else: - dec_16_name = "Day of Reconciliation" - self[date(year, DEC, 16)] = dec_16_name - - self[date(year, DEC, 25)] = "Christmas Day" - - if year > 1979: - dec_26_name = "Day of Goodwill" - else: - dec_26_name = "Boxing Day" - self[date(year, DEC, 26)] = dec_26_name + self[date(year, JAN, 1)] = "New Year's Day" + + easter_date = easter(year) + self[easter_date + rd(days=-2)] = "Good Friday" + if year >= 1980: + name = "Family Day" + else: + name = "Easter Monday" + self[easter_date + rd(days=+1)] = name + + if year <= 1951: + name = "Dingaan's Day" + elif year <= 1979: + name = "Day of the Covenant" + elif year <= 1994: + name = "Day of the Vow" + else: + name = "Day of Reconciliation" + self[date(year, DEC, 16)] = name + + self[date(year, DEC, 25)] = "Christmas Day" + + if year >= 1980: + name = "Day of Goodwill" + else: + name = "Boxing Day" + self[date(year, DEC, 26)] = name # Observed since 1995/1/1 - if year > 1994: + if year >= 1995: self[date(year, MAR, 21)] = "Human Rights Day" self[date(year, APR, 27)] = "Freedom Day" self[date(year, MAY, 1)] = "Workers' Day" @@ -106,57 +107,54 @@ def _populate(self, year): # As of 1995/1/1, whenever a public holiday falls on a Sunday, # it rolls over to the following Monday - for k, v in list(self.items()): - if ( - self.observed - and year > 1994 - and k.weekday() == SUN - and k.year == year - ): - if not self.get(k + rd(days=1)): - self[k + rd(days=1)] = v + " (Observed)" + if self.observed and year >= 1995: + for k, v in list(self.items()): + if k.weekday() != SUN or k.year != year: + continue + dt = k + rd(days=+1) + if dt in self: + continue + self[dt] = v + " (Observed)" # Historic public holidays no longer observed - if 1951 < year < 1974: + if 1952 <= year <= 1973: self[date(year, APR, 6)] = "Van Riebeeck's Day" - elif 1979 < year < 1995: + elif 1980 <= year <= 1994: self[date(year, APR, 6)] = "Founder's Day" - if 1986 < year < 1990: + if 1987 <= year <= 1989: # observed on first Friday in May - historic_workers_day = date(year, MAY, 1) + rd(weekday=FR) - self[historic_workers_day] = "Workers' Day" + self[(date(year, MAY, 1) + rd(weekday=FR))] = "Workers' Day" - if 1909 < year < 1994: + if year <= 1993: self[easter_date + rd(days=+40)] = "Ascension Day" - if 1909 < year < 1952: + if year <= 1951: self[date(year, MAY, 24)] = "Empire Day" - if 1909 < year < 1961: + if year <= 1960: self[date(year, MAY, 31)] = "Union Day" - elif 1960 < year < 1994: + elif year <= 1993: self[date(year, MAY, 31)] = "Republic Day" - if 1951 < year < 1961: + if 1952 <= year <= 1960: # observed on second Monday in July - queens_birthday = date(year, JUL, 1) + rd(weekday=MO(+2)) - self[queens_birthday] = "Queen's Birthday" + self[ + (date(year, JUL, 1) + rd(weekday=MO(+2))) + ] = "Queen's Birthday" - if 1960 < year < 1974: + if 1961 <= year <= 1973: self[date(year, JUL, 10)] = "Family Day" - if 1909 < year < 1952: + if year <= 1951: # observed on first Monday in August - kings_birthday = date(year, AUG, 1) + rd(weekday=MO) - self[kings_birthday] = "King's Birthday" + self[(date(year, AUG, 1) + rd(weekday=MO))] = "King's Birthday" - if 1951 < year < 1980: + if 1952 <= year <= 1979: # observed on first Monday in September - settlers_day = date(year, SEP, 1) + rd(weekday=MO) - self[settlers_day] = "Settlers' Day" + self[(date(year, SEP, 1) + rd(weekday=MO))] = "Settlers' Day" - if 1951 < year < 1994: + if 1952 <= year <= 1993: self[date(year, OCT, 10)] = "Kruger Day" From ce2fb21e82561f180985f4e890479a796672831d Mon Sep 17 00:00:00 2001 From: ~Jhellico Date: Fri, 9 Dec 2022 01:38:29 +0200 Subject: [PATCH 048/138] =?UTF-8?q?Switzerland:=20optimizations,=20N=C3=A4?= =?UTF-8?q?felser=20Fahrt=20fix=20(#821)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- holidays/countries/switzerland.py | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/holidays/countries/switzerland.py b/holidays/countries/switzerland.py index 17961e8b5..9ce13b07e 100644 --- a/holidays/countries/switzerland.py +++ b/holidays/countries/switzerland.py @@ -13,7 +13,7 @@ from dateutil.easter import easter from dateutil.relativedelta import relativedelta as rd -from dateutil.relativedelta import MO, FR, TH, SU +from dateutil.relativedelta import TH, SU from holidays.constants import JAN, MAR, APR, MAY, JUN, AUG, SEP, NOV, DEC from holidays.holiday_base import HolidayBase @@ -56,7 +56,7 @@ def _populate(self, year): # public holidays self[date(year, JAN, 1)] = "Neujahrestag" - if self.subdiv in ( + if self.subdiv in { "AG", "BE", "FR", @@ -72,7 +72,7 @@ def _populate(self, year): "VD", "ZG", "ZH", - ): + }: self[date(year, JAN, 2)] = "Berchtoldstag" if self.subdiv in {"SZ", "TI", "UR"}: @@ -87,12 +87,10 @@ def _populate(self, year): easter_date = easter(year) # Näfelser Fahrt (first Thursday in April but not in Holy Week) if self.subdiv == "GL" and year >= 1835: - if (date(year, APR, 1) + rd(weekday=FR)) != ( - easter_date + rd(days=-2) - ): - self[date(year, APR, 1) + rd(weekday=TH)] = "Näfelser Fahrt" - else: - self[date(year, APR, 8) + rd(weekday=TH)] = "Näfelser Fahrt" + dt = date(year, APR, 1) + rd(weekday=TH) + if dt == easter_date + rd(days=-3): + dt += rd(days=+7) + self[dt] = "Näfelser Fahrt" # it's a Holiday on a Sunday self[easter_date] = "Ostern" @@ -161,12 +159,12 @@ def _populate(self, year): if self.subdiv == "VD": # Monday after the third Sunday of September - dt = date(year, SEP, 1) + rd(weekday=SU(+3)) + rd(weekday=MO) + dt = date(year, SEP, 1) + rd(weekday=SU(+3)) + rd(days=+1) self[dt] = "Lundi du Jeûne" if self.subdiv == "GE": # Thursday after the first Sunday of September - dt = date(year, SEP, 1) + rd(weekday=SU) + rd(weekday=TH) + dt = date(year, SEP, 1) + rd(weekday=SU) + rd(days=+4) self[dt] = "Jeûne genevois" if self.subdiv == "OW": From 5e28c3767d9b3bd0b789169b3a32e5d94cdd4888 Mon Sep 17 00:00:00 2001 From: ~Jhellico Date: Fri, 9 Dec 2022 01:39:21 +0200 Subject: [PATCH 049/138] Angola: optimizations, observance calculation fix (#822) --- holidays/countries/angola.py | 39 ++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/holidays/countries/angola.py b/holidays/countries/angola.py index cd1ba2b92..0ebeb929e 100644 --- a/holidays/countries/angola.py +++ b/holidays/countries/angola.py @@ -45,7 +45,7 @@ def _populate(self, year: int) -> None: # Observed since 1975 # TODO do more research on history of Angolan holidays - if year < 1975: + if year <= 1974: return self[date(year, JAN, 1)] = "Ano novo" @@ -55,25 +55,23 @@ def _populate(self, year: int) -> None: if self.observed and date(year, DEC, 31).weekday() == MON: self[date(year, DEC, 31)] = "Ano novo (Day off)" - e = easter(year) - good_friday = e - rd(days=2) - self[good_friday] = "Sexta-feira Santa" + easter_date = easter(year) + self[(easter_date + rd(days=-2))] = "Sexta-feira Santa" # carnival is the Tuesday before Ash Wednesday # which is 40 days before easter excluding sundays - carnival = e + rd(days=-47) - self[carnival] = "Carnaval" + self[(easter_date + rd(days=-47))] = "Carnaval" self[date(year, FEB, 4)] = "Dia do Início da Luta Armada" self[date(year, MAR, 8)] = "Dia Internacional da Mulher" - if year > 2018: + if year >= 2019: self[date(year, MAR, 23)] = "Dia da Libertação da África Austral" self[date(year, APR, 4)] = "Dia da Paz e Reconciliação" self[date(year, MAY, 1)] = "Dia Mundial do Trabalho" - if year > 1979: + if year >= 1980: self[date(year, SEP, 17)] = "Dia do Herói Nacional" self[date(year, NOV, 2)] = "Dia dos Finados" @@ -84,20 +82,17 @@ def _populate(self, year: int) -> None: # it rolls over to the following Monday # Since 2018 when a public holiday falls on the Tuesday or Thursday # the Monday or Friday is also a holiday - for k, v in list(self.items()): - if self.observed and year > 1974: - if k.weekday() == SUN: - self[k + rd(days=1)] = v + " (Observed)" - if self.observed and year > 2017: - if k.weekday() == SUN: - pass - if self.observed and year > 2017: - if k.weekday() == TUE and k != date(year, JAN, 1): - self[k - rd(days=1)] = v + " (Day off)" - elif k.weekday() == THU: - self[k + rd(days=1)] = v + " (Day off)" - if self.observed and year > 1994 and k.weekday() == SUN: - self[k + rd(days=1)] = v + " (Observed)" + if self.observed and year >= 1995: + for k, v in list(self.items()): + if k.year == year: + if year <= 2017: + if k.weekday() == SUN: + self[k + rd(days=+1)] = v + " (Observed)" + else: + if k.weekday() == TUE and k != date(year, JAN, 1): + self[k + rd(days=-1)] = v + " (Day off)" + elif k.weekday() == THU: + self[k + rd(days=+1)] = v + " (Day off)" class AO(Angola): From e5c6f1a8485c56777c6383d1d951cd8b6b875a80 Mon Sep 17 00:00:00 2001 From: ~Jhellico Date: Fri, 9 Dec 2022 01:40:29 +0200 Subject: [PATCH 050/138] India: Diwali and Holi holidays update (#825) --- holidays/countries/india.py | 148 ++++++++++++++++++----------------- test/countries/test_india.py | 87 ++++++++++---------- 2 files changed, 120 insertions(+), 115 deletions(-) diff --git a/holidays/countries/india.py b/holidays/countries/india.py index cf21400cc..004bb7754 100644 --- a/holidays/countries/india.py +++ b/holidays/countries/india.py @@ -12,7 +12,7 @@ import warnings from datetime import date -from holidays.constants import JAN, FEB, MAR, APR, MAY, JUN, AUG, OCT, NOV, DEC +from holidays.constants import JAN, MAR, APR, MAY, JUN, AUG, OCT, NOV, DEC from holidays.holiday_base import HolidayBase @@ -169,80 +169,86 @@ def _populate(self, year): # https://github.com/facebook/prophet/blob/main/python/prophet/hdays.py # Warnings kept in place so that users are aware - if year < 2010 or year > 2030: + if year < 2001 or year > 2030: warning_msg = ( - "Diwali and Holi holidays available from 2010 to 2030 only" + "Diwali and Holi holidays available from 2001 to 2030 only" ) warnings.warn(warning_msg, Warning) - name1 = "Diwali" - name2 = "Holi" - - if year == 2010: - self[date(year, DEC, 5)] = name1 - self[date(year, FEB, 28)] = name2 - elif year == 2011: - self[date(year, OCT, 26)] = name1 - self[date(year, MAR, 19)] = name2 - elif year == 2012: - self[date(year, NOV, 13)] = name1 - self[date(year, MAR, 8)] = name2 - elif year == 2013: - self[date(year, NOV, 3)] = name1 - self[date(year, MAR, 26)] = name2 - elif year == 2014: - self[date(year, OCT, 23)] = name1 - self[date(year, MAR, 17)] = name2 - elif year == 2015: - self[date(year, NOV, 11)] = name1 - self[date(year, MAR, 6)] = name2 - elif year == 2016: - self[date(year, OCT, 30)] = name1 - self[date(year, MAR, 24)] = name2 - elif year == 2017: - self[date(year, OCT, 19)] = name1 - self[date(year, MAR, 13)] = name2 - elif year == 2018: - self[date(year, NOV, 7)] = name1 - self[date(year, MAR, 2)] = name2 - elif year == 2019: - self[date(year, OCT, 27)] = name1 - self[date(year, MAR, 21)] = name2 - elif year == 2020: - self[date(year, NOV, 14)] = name1 - self[date(year, MAR, 9)] = name2 - elif year == 2021: - self[date(year, NOV, 4)] = name1 - self[date(year, MAR, 28)] = name2 - elif year == 2022: - self[date(year, OCT, 24)] = name1 - self[date(year, MAR, 18)] = name2 - elif year == 2023: - self[date(year, OCT, 12)] = name1 - self[date(year, MAR, 7)] = name2 - elif year == 2024: - self[date(year, NOV, 1)] = name1 - self[date(year, MAR, 25)] = name2 - elif year == 2025: - self[date(year, OCT, 21)] = name1 - self[date(year, MAR, 14)] = name2 - elif year == 2026: - self[date(year, NOV, 8)] = name1 - self[date(year, MAR, 3)] = name2 - elif year == 2027: - self[date(year, OCT, 29)] = name1 - self[date(year, MAR, 22)] = name2 - elif year == 2028: - self[date(year, OCT, 17)] = name1 - self[date(year, MAR, 11)] = name2 - elif year == 2029: - self[date(year, NOV, 5)] = name1 - self[date(year, FEB, 28)] = name2 - elif year == 2030: - self[date(year, OCT, 26)] = name1 - self[date(year, MAR, 19)] = name2 - else: - pass + # https://www.timeanddate.com/holidays/india/diwali + diwali_dates = { + 2001: (NOV, 14), + 2002: (NOV, 4), + 2003: (OCT, 25), + 2004: (NOV, 12), + 2005: (NOV, 1), + 2006: (OCT, 21), + 2007: (NOV, 9), + 2008: (OCT, 28), + 2009: (OCT, 17), + 2010: (NOV, 5), + 2011: (OCT, 26), + 2012: (NOV, 13), + 2013: (NOV, 3), + 2014: (OCT, 23), + 2015: (NOV, 11), + 2016: (OCT, 30), + 2017: (OCT, 19), + 2018: (NOV, 7), + 2019: (OCT, 27), + 2020: (NOV, 14), + 2021: (NOV, 4), + 2022: (OCT, 24), + 2023: (NOV, 12), + 2024: (NOV, 1), + 2025: (OCT, 20), + 2026: (NOV, 8), + 2027: (OCT, 29), + 2028: (OCT, 17), + 2029: (NOV, 5), + 2030: (OCT, 26), + } + + # https://www.timeanddate.com/holidays/india/holi + holi_dates = { + 2001: (MAR, 10), + 2002: (MAR, 29), + 2003: (MAR, 18), + 2004: (MAR, 7), + 2005: (MAR, 26), + 2006: (MAR, 15), + 2007: (MAR, 4), + 2008: (MAR, 22), + 2009: (MAR, 11), + 2010: (MAR, 1), + 2011: (MAR, 20), + 2012: (MAR, 8), + 2013: (MAR, 27), + 2014: (MAR, 17), + 2015: (MAR, 6), + 2016: (MAR, 24), + 2017: (MAR, 13), + 2018: (MAR, 2), + 2019: (MAR, 21), + 2020: (MAR, 10), + 2021: (MAR, 29), + 2022: (MAR, 18), + 2023: (MAR, 8), + 2024: (MAR, 25), + 2025: (MAR, 14), + 2026: (MAR, 4), + 2027: (MAR, 22), + 2028: (MAR, 11), + 2029: (MAR, 1), + 2030: (MAR, 20), + } + + if year in diwali_dates: + hol_date = date(year, *diwali_dates[year]) + self[hol_date] = "Diwali" + if year in holi_dates: + hol_date = date(year, *holi_dates[year]) + self[hol_date] = "Holi" class IN(India): diff --git a/test/countries/test_india.py b/test/countries/test_india.py index bf25d3c2c..ca2749e0e 100644 --- a/test/countries/test_india.py +++ b/test/countries/test_india.py @@ -14,7 +14,6 @@ from datetime import date import holidays -from holidays.constants import FEB, MAR, OCT, NOV, DEC class TestIND(unittest.TestCase): @@ -129,7 +128,7 @@ def test_diwali_and_holi(self): warnings.simplefilter("always") with self.assertWarns(Warning): # Diwali and Holi out of range - holidays.IN(years=2009) + holidays.IN(years=2000) with self.assertWarns(Warning): # Diwali and Holi out of range @@ -137,48 +136,48 @@ def test_diwali_and_holi(self): diwali_name = "Diwali" holi_name = "Holi" - self.assertEqual(self.holidays[date(2010, DEC, 5)], diwali_name) - self.assertEqual(self.holidays[date(2010, FEB, 28)], holi_name) - self.assertEqual(self.holidays[date(2011, MAR, 19)], holi_name) - self.assertEqual(self.holidays[date(2011, OCT, 26)], diwali_name) - self.assertEqual(self.holidays[date(2012, MAR, 8)], holi_name) - self.assertEqual(self.holidays[date(2012, NOV, 13)], diwali_name) - self.assertEqual(self.holidays[date(2013, MAR, 26)], holi_name) - self.assertEqual(self.holidays[date(2013, NOV, 3)], diwali_name) - self.assertEqual(self.holidays[date(2014, MAR, 17)], holi_name) - self.assertEqual(self.holidays[date(2014, OCT, 23)], diwali_name) - self.assertEqual(self.holidays[date(2015, MAR, 6)], holi_name) - self.assertEqual(self.holidays[date(2015, NOV, 11)], diwali_name) - self.assertEqual(self.holidays[date(2016, MAR, 24)], holi_name) - self.assertEqual(self.holidays[date(2016, OCT, 30)], diwali_name) - self.assertEqual(self.holidays[date(2017, MAR, 13)], holi_name) - self.assertEqual(self.holidays[date(2017, OCT, 19)], diwali_name) - self.assertEqual(self.holidays[date(2018, MAR, 2)], holi_name) - self.assertEqual(self.holidays[date(2018, NOV, 7)], diwali_name) - self.assertEqual(self.holidays[date(2019, MAR, 21)], holi_name) - self.assertEqual(self.holidays[date(2019, OCT, 27)], diwali_name) - self.assertEqual(self.holidays[date(2020, MAR, 9)], holi_name) - self.assertEqual(self.holidays[date(2020, NOV, 14)], diwali_name) - self.assertEqual(self.holidays[date(2021, MAR, 28)], holi_name) - self.assertEqual(self.holidays[date(2021, NOV, 4)], diwali_name) - self.assertEqual(self.holidays[date(2022, MAR, 18)], holi_name) - self.assertEqual(self.holidays[date(2022, OCT, 24)], diwali_name) - self.assertEqual(self.holidays[date(2023, MAR, 7)], holi_name) - self.assertEqual(self.holidays[date(2023, OCT, 12)], diwali_name) - self.assertEqual(self.holidays[date(2024, MAR, 25)], holi_name) - self.assertEqual(self.holidays[date(2024, NOV, 1)], diwali_name) - self.assertEqual(self.holidays[date(2025, MAR, 14)], holi_name) - self.assertEqual(self.holidays[date(2025, OCT, 21)], diwali_name) - self.assertEqual(self.holidays[date(2026, MAR, 3)], holi_name) - self.assertEqual(self.holidays[date(2026, NOV, 8)], diwali_name) - self.assertEqual(self.holidays[date(2027, MAR, 22)], holi_name) - self.assertEqual(self.holidays[date(2027, OCT, 29)], diwali_name) - self.assertEqual(self.holidays[date(2028, MAR, 11)], holi_name) - self.assertEqual(self.holidays[date(2028, OCT, 17)], diwali_name) - self.assertEqual(self.holidays[date(2029, FEB, 28)], holi_name) - self.assertEqual(self.holidays[date(2029, NOV, 5)], diwali_name) - self.assertEqual(self.holidays[date(2030, MAR, 19)], holi_name) - self.assertEqual(self.holidays[date(2030, OCT, 26)], diwali_name) + self.assertEqual(self.holidays[date(2010, 11, 5)], diwali_name) + self.assertEqual(self.holidays[date(2010, 3, 1)], holi_name) + self.assertEqual(self.holidays[date(2011, 3, 20)], holi_name) + self.assertEqual(self.holidays[date(2011, 10, 26)], diwali_name) + self.assertEqual(self.holidays[date(2012, 3, 8)], holi_name) + self.assertEqual(self.holidays[date(2012, 11, 13)], diwali_name) + self.assertEqual(self.holidays[date(2013, 3, 27)], holi_name) + self.assertEqual(self.holidays[date(2013, 11, 3)], diwali_name) + self.assertEqual(self.holidays[date(2014, 3, 17)], holi_name) + self.assertEqual(self.holidays[date(2014, 10, 23)], diwali_name) + self.assertEqual(self.holidays[date(2015, 3, 6)], holi_name) + self.assertEqual(self.holidays[date(2015, 11, 11)], diwali_name) + self.assertEqual(self.holidays[date(2016, 3, 24)], holi_name) + self.assertEqual(self.holidays[date(2016, 10, 30)], diwali_name) + self.assertEqual(self.holidays[date(2017, 3, 13)], holi_name) + self.assertEqual(self.holidays[date(2017, 10, 19)], diwali_name) + self.assertEqual(self.holidays[date(2018, 3, 2)], holi_name) + self.assertEqual(self.holidays[date(2018, 11, 7)], diwali_name) + self.assertEqual(self.holidays[date(2019, 3, 21)], holi_name) + self.assertEqual(self.holidays[date(2019, 10, 27)], diwali_name) + self.assertEqual(self.holidays[date(2020, 3, 10)], holi_name) + self.assertEqual(self.holidays[date(2020, 11, 14)], diwali_name) + self.assertEqual(self.holidays[date(2021, 3, 29)], holi_name) + self.assertEqual(self.holidays[date(2021, 11, 4)], diwali_name) + self.assertEqual(self.holidays[date(2022, 3, 18)], holi_name) + self.assertEqual(self.holidays[date(2022, 10, 24)], diwali_name) + self.assertEqual(self.holidays[date(2023, 3, 8)], holi_name) + self.assertEqual(self.holidays[date(2023, 11, 12)], diwali_name) + self.assertEqual(self.holidays[date(2024, 3, 25)], holi_name) + self.assertEqual(self.holidays[date(2024, 11, 1)], diwali_name) + self.assertEqual(self.holidays[date(2025, 3, 14)], holi_name) + self.assertEqual(self.holidays[date(2025, 10, 20)], diwali_name) + self.assertEqual(self.holidays[date(2026, 3, 4)], holi_name) + self.assertEqual(self.holidays[date(2026, 11, 8)], diwali_name) + self.assertEqual(self.holidays[date(2027, 3, 22)], holi_name) + self.assertEqual(self.holidays[date(2027, 10, 29)], diwali_name) + self.assertEqual(self.holidays[date(2028, 3, 11)], holi_name) + self.assertEqual(self.holidays[date(2028, 10, 17)], diwali_name) + self.assertEqual(self.holidays[date(2029, 3, 1)], holi_name) + self.assertEqual(self.holidays[date(2029, 11, 5)], diwali_name) + self.assertEqual(self.holidays[date(2030, 3, 20)], holi_name) + self.assertEqual(self.holidays[date(2030, 10, 26)], diwali_name) def test_pre_1947(self): self.assertNotIn(date(1946, 8, 15), self.holidays) From 82ff1bc5acb4986fc416b564e2091790cdaeb3b2 Mon Sep 17 00:00:00 2001 From: ~Jhellico Date: Fri, 9 Dec 2022 01:41:53 +0200 Subject: [PATCH 051/138] Hungary: removed double holiday Dec 31 (#826) --- holidays/countries/hungary.py | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/holidays/countries/hungary.py b/holidays/countries/hungary.py index d4d560f8b..1671cd611 100644 --- a/holidays/countries/hungary.py +++ b/holidays/countries/hungary.py @@ -44,13 +44,10 @@ class Hungary(HolidayBase): def _populate(self, year: int) -> None: super()._populate(year) - # New years - self._add_with_observed_day_off(date(year, JAN, 1), "Újév", since=2014) - # Since 2014, the last day of the year is an observed day off if New - # Year's Day falls on a Tuesday. - if year >= 2014: - if self.observed and date(year, DEC, 31).weekday() == MON: - self[date(year, DEC, 31)] = "Újév előtti pihenőnap" + # New year + self._add_with_observed_day_off( + date(year, JAN, 1), "Újév", before=False, since=2014 + ) # National Day if 1945 <= year <= 1950 or 1989 <= year: @@ -101,7 +98,7 @@ def _populate(self, year: int) -> None: self[date(year, MAY, 2)] = "A Munka ünnepe" # State Foundation Day (1771-????, 1891-) - if 1950 <= year < 1990: + if 1950 <= year <= 1989: self[date(year, AUG, 20)] = "A kenyér ünnepe" else: self._add_with_observed_day_off( @@ -139,10 +136,11 @@ def _populate(self, year: int) -> None: "Karácsony másnapja", since=2013, before=False, - after=True, ) # New Year's Eve + # Since 2014, the last day of the year is an observed day off if New + # Year's Day falls on a Tuesday. if ( self.observed and 2014 <= year @@ -163,14 +161,10 @@ def _add_with_observed_day_off( self[day] = desc # TODO: should it be a separate flag? if self.observed and since <= day.year: - if ( - day.weekday() == TUE - and before - and not (day.month == JAN and day.day == 1) - ): - self[day - rd(days=1)] = desc + " előtti pihenőnap" + if day.weekday() == TUE and before: + self[day + rd(days=-1)] = desc + " előtti pihenőnap" elif day.weekday() == THU and after: - self[day + rd(days=1)] = desc + " utáni pihenőnap" + self[day + rd(days=+1)] = desc + " utáni pihenőnap" class HU(Hungary): From d37b6650a87ab039d9f46d4536363266b94fdc46 Mon Sep 17 00:00:00 2001 From: ~Jhellico Date: Fri, 9 Dec 2022 01:46:08 +0200 Subject: [PATCH 052/138] Observed holidays calc optimizations (#824) --- holidays/countries/botswana.py | 118 +++++++++++++++---------------- holidays/countries/eswatini.py | 57 +++++++-------- holidays/countries/kenya.py | 8 ++- holidays/countries/malawi.py | 48 ++++++------- holidays/countries/mozambique.py | 49 ++++++------- holidays/countries/namibia.py | 69 +++++++++--------- holidays/countries/ukraine.py | 58 +++++++-------- holidays/countries/zimbabwe.py | 58 +++++++-------- test/countries/test_botswana.py | 8 +++ test/countries/test_kenya.py | 8 +++ test/countries/test_namibia.py | 8 +++ test/countries/test_zimbabwe.py | 8 +++ 12 files changed, 263 insertions(+), 234 deletions(-) diff --git a/holidays/countries/botswana.py b/holidays/countries/botswana.py index 807813c67..5d6cb46f9 100644 --- a/holidays/countries/botswana.py +++ b/holidays/countries/botswana.py @@ -31,67 +31,67 @@ class Botswana(HolidayBase): special_holidays = {2019: ((JUL, 2, "Public Holiday"),)} def _populate(self, year: int): + if year <= 1965: + return super()._populate(year) - if year > 1965: - self[date(year, JAN, 1)] = "New Year's Day" - self[date(year, JAN, 2)] = "New Year's Day Holiday" - - # Easter and easter related calculations - easter_date = easter(year) - self[easter_date + rd(days=-2)] = "Good Friday" - self[easter_date + rd(days=-1)] = "Holy Saturday" - self[easter_date + rd(days=+1)] = "Easter Monday" - - self[date(year, MAY, 1)] = "Labour Day" - self[easter_date + rd(days=+39)] = "Ascension Day" - - self[date(year, JUL, 1)] = "Sir Seretse Khama Day" - - # 3rd Monday of July = "President's Day" - d = date(year, JUL, 1) + rd(weekday=MO(+3)) - self[d] = "President's Day" - self[d + rd(days=1)] = "President's Day Holiday" - - self[date(year, SEP, 30)] = "Botswana Day" - self[date(year, OCT, 1)] = "Botswana Day Holiday" - - self[date(year, DEC, 25)] = "Christmas Day" - self[date(year, DEC, 26)] = "Boxing Day" - - for k, v in list(self.items()): - # Whenever Boxing Day falls on a Saturday, - # it rolls over to the following Monday - if ( - self.observed - and year > 2015 - and k.weekday() == SAT - and k.year == year - and v.upper() in {"BOXING DAY", "LABOUR DAY"} - ): - # Add the (Observed) holiday - self[k + rd(days=2)] = v + " Holiday" - if ( - self.observed - and year > 1994 - and k.weekday() == SUN - and k.year == year - and v.upper() != "NEW YEAR'S DAY HOLIDAY" - ): - # Add the (Observed) holiday - self[k + rd(days=1)] = v + " (Observed)" - - # If there is a holiday and an (Observed) holiday on the same day, - # add an (Observed) holiday for that holiday - if len(self.get(k).split(",")) > 1: - # self.get(date) returns a string containing holidays as a - # comma delimited string split on delimiter to determine if - # there are multiple on the same day - - # Add an (Observed) for the one that is not (Observed) - for i in self.get(k).split(","): - if " (Observed)" not in i: - self[k + rd(days=1)] = i.lstrip() + " (Observed)" + self[date(year, JAN, 1)] = "New Year's Day" + self[date(year, JAN, 2)] = "New Year's Day Holiday" + + # Easter and easter related calculations + easter_date = easter(year) + self[easter_date + rd(days=-2)] = "Good Friday" + self[easter_date + rd(days=-1)] = "Holy Saturday" + self[easter_date + rd(days=+1)] = "Easter Monday" + + self[date(year, MAY, 1)] = "Labour Day" + self[easter_date + rd(days=+39)] = "Ascension Day" + + self[date(year, JUL, 1)] = "Sir Seretse Khama Day" + + # 3rd Monday of July = "President's Day" + d = date(year, JUL, 1) + rd(weekday=MO(+3)) + self[d] = "President's Day" + self[d + rd(days=1)] = "President's Day Holiday" + + self[date(year, SEP, 30)] = "Botswana Day" + self[date(year, OCT, 1)] = "Botswana Day Holiday" + + self[date(year, DEC, 25)] = "Christmas Day" + self[date(year, DEC, 26)] = "Boxing Day" + + if self.observed: + for k, v in list(self.items()): + # Whenever Boxing Day falls on a Saturday, + # it rolls over to the following Monday + if ( + 2016 <= year == k.year + and k.weekday() == SAT + and v.upper() in {"BOXING DAY", "LABOUR DAY"} + ): + # Add the (Observed) holiday + self[k + rd(days=+2)] = v + " Holiday" + if ( + 1995 <= year == k.year + and k.weekday() == SUN + and v.upper() != "NEW YEAR'S DAY HOLIDAY" + ): + # Add the (Observed) holiday + self[k + rd(days=+1)] = v + " (Observed)" + + # If there is a holiday and an (Observed) holiday + # on the same day, add an (Observed) holiday for that holiday + hol_names = self.get(k).split(",") + if len(hol_names) > 1: + # self.get(date) returns a string containing holidays as a + # comma delimited string split on delimiter to determine if + # there are multiple on the same day + # Add an (Observed) for the one that is not (Observed) + for name in hol_names: + if " (Observed)" not in name: + self[k + rd(days=+1)] = ( + name.lstrip() + " (Observed)" + ) class BW(Botswana): diff --git a/holidays/countries/eswatini.py b/holidays/countries/eswatini.py index 28c4e4f6c..afac41fd9 100644 --- a/holidays/countries/eswatini.py +++ b/holidays/countries/eswatini.py @@ -33,43 +33,44 @@ class Eswatini(HolidayBase): } def _populate(self, year): + # Observed since 1939 + if year <= 1938: + return super()._populate(year) - # Observed since 1938 - if year > 1938: - self[date(year, JAN, 1)] = "New Year's Day" + self[date(year, JAN, 1)] = "New Year's Day" - easter_date = easter(year) - self[easter_date + rd(days=-2)] = "Good Friday" - self[easter_date + rd(days=+1)] = "Easter Monday" - self[easter_date + rd(days=+39)] = "Ascension Day" + easter_date = easter(year) + self[easter_date + rd(days=-2)] = "Good Friday" + self[easter_date + rd(days=+1)] = "Easter Monday" + self[easter_date + rd(days=+39)] = "Ascension Day" - if year > 1968: - self[date(year, APR, 25)] = "National Flag Day" + if year >= 1969: + self[date(year, APR, 25)] = "National Flag Day" - if year > 1982: - # https://www.officeholidays.com/holidays/swaziland/birthday-of-late-king-sobhuza - self[date(year, JUL, 22)] = "Birthday of Late King Sobhuza" + if year >= 1983: + # https://www.officeholidays.com/holidays/swaziland/birthday-of-late-king-sobhuza + self[date(year, JUL, 22)] = "Birthday of Late King Sobhuza" - if year > 1986: - # https://www.officeholidays.com/holidays/swaziland/birthday-of-king-mswati-iii - self[date(year, APR, 19)] = "King's Birthday" + if year >= 1987: + # https://www.officeholidays.com/holidays/swaziland/birthday-of-king-mswati-iii + self[date(year, APR, 19)] = "King's Birthday" - self[date(year, MAY, 1)] = "Worker's Day" - self[date(year, SEP, 6)] = "Independence Day" - self[date(year, DEC, 25)] = "Christmas Day" - self[date(year, DEC, 26)] = "Boxing Day" + self[date(year, MAY, 1)] = "Worker's Day" + self[date(year, SEP, 6)] = "Independence Day" + self[date(year, DEC, 25)] = "Christmas Day" + self[date(year, DEC, 26)] = "Boxing Day" - # As of 2021/1/1, whenever a public holiday falls on a - # Sunday - # it rolls over to the following Monday + # As of 2021/1/1, whenever a public holiday falls on a + # Sunday + # it rolls over to the following Monday + if self.observed and year >= 2021: for k, v in list(self.items()): - - if self.observed and k.weekday() == SUN and k.year == year: - add_days = 1 - while self.get(k + rd(days=add_days)) is not None: - add_days += 1 - self[k + rd(days=add_days)] = v + " (Day Off)" + if k.weekday() == SUN and k.year == year: + dt = k + rd(days=+1) + while self.get(dt): + dt += rd(days=+1) + self[dt] = v + " (Observed)" class Swaziland(Eswatini): diff --git a/holidays/countries/kenya.py b/holidays/countries/kenya.py index 7e24c1ea2..d1d09a319 100644 --- a/holidays/countries/kenya.py +++ b/holidays/countries/kenya.py @@ -39,9 +39,11 @@ def _populate(self, year): self[date(year, DEC, 12)] = "Jamhuri (Independence) Day" self[date(year, DEC, 25)] = "Christmas Day" self[date(year, DEC, 26)] = "Utamaduni Day" - for k, v in list(self.items()): - if self.observed and k.weekday() == SUN: - self[k + rd(days=1)] = v + " (Observed)" + + if self.observed: + for k, v in list(self.items()): + if k.weekday() == SUN and k.year == year: + self[k + rd(days=+1)] = v + " (Observed)" easter_date = easter(year) self[easter_date + rd(days=-2)] = "Good Friday" diff --git a/holidays/countries/malawi.py b/holidays/countries/malawi.py index 6a6095849..a52cdd102 100644 --- a/holidays/countries/malawi.py +++ b/holidays/countries/malawi.py @@ -13,8 +13,9 @@ from dateutil.easter import easter from dateutil.relativedelta import relativedelta as rd +from dateutil.relativedelta import MO -from holidays.constants import SAT, SUN, JAN, MAR, MAY, JUL, OCT, DEC +from holidays.constants import WEEKEND, JAN, MAR, MAY, JUL, OCT, DEC from holidays.holiday_base import HolidayBase @@ -27,31 +28,30 @@ class Malawi(HolidayBase): country = "MW" def _populate(self, year): + # Observed since 2000 + if year <= 1999: + return super()._populate(year) - # Observed since 2000 - if year > 1999: - self[date(year, JAN, 1)] = "New Year's Day" - - easter_date = easter(year) - self[easter_date + rd(days=-2)] = "Good Friday" - self[easter_date + rd(days=+1)] = "Easter Monday" - - self[date(year, JAN, 15)] = "John Chilembwe Day" - self[date(year, MAR, 3)] = "Martyrs Day" - self[date(year, MAY, 1)] = "Labour Day" - self[date(year, MAY, 14)] = "Kamuzu Day" - self[date(year, JUL, 6)] = "Independence Day" - self[date(year, OCT, 15)] = "Mother's Day" - self[date(year, DEC, 25)] = "Christmas Day" - self[date(year, DEC, 26)] = "Boxing Day" - - for k, v in list(self.items()): - if self.observed and year > 1994: - if k.weekday() == SUN: - self[k + rd(days=1)] = v + " (Observed)" - elif k.weekday() == SAT: - self[k + rd(days=2)] = v + " (Observed)" + self[date(year, JAN, 1)] = "New Year's Day" + + easter_date = easter(year) + self[easter_date + rd(days=-2)] = "Good Friday" + self[easter_date + rd(days=+1)] = "Easter Monday" + + self[date(year, JAN, 15)] = "John Chilembwe Day" + self[date(year, MAR, 3)] = "Martyrs Day" + self[date(year, MAY, 1)] = "Labour Day" + self[date(year, MAY, 14)] = "Kamuzu Day" + self[date(year, JUL, 6)] = "Independence Day" + self[date(year, OCT, 15)] = "Mother's Day" + self[date(year, DEC, 25)] = "Christmas Day" + self[date(year, DEC, 26)] = "Boxing Day" + + if self.observed: + for k, v in list(self.items()): + if k.weekday() in WEEKEND and k.year == year: + self[k + rd(weekday=MO)] = v + " (Observed)" class MW(Malawi): diff --git a/holidays/countries/mozambique.py b/holidays/countries/mozambique.py index 49bed30d6..86fad0ac8 100644 --- a/holidays/countries/mozambique.py +++ b/holidays/countries/mozambique.py @@ -14,7 +14,7 @@ from dateutil.easter import easter from dateutil.relativedelta import relativedelta as rd -from holidays.constants import SUN, FEB, APR, MAY, JUN, SEP, OCT, DEC +from holidays.constants import SUN, JAN, FEB, APR, MAY, JUN, SEP, OCT, DEC from holidays.holiday_base import HolidayBase @@ -22,32 +22,33 @@ class Mozambique(HolidayBase): country = "MZ" def _populate(self, year): + if year <= 1974: + return super()._populate(year) - if year > 1974: - self[date(year, 1, 1)] = "Ano novo" - easter_date = easter(year) - self[easter_date + rd(days=-2)] = "Sexta-feira Santa" - - # carnival is the Tuesday before Ash Wednesday - # which is 40 days before easter excluding sundays - self[easter_date + rd(days=-47)] = "Carnaval" - - self[date(year, FEB, 3)] = "Dia dos Heróis Moçambicanos" - self[date(year, APR, 7)] = "Dia da Mulher Moçambicana" - self[date(year, MAY, 1)] = "Dia Mundial do Trabalho" - self[date(year, JUN, 25)] = "Dia da Independência Nacional" - self[date(year, SEP, 7)] = "Dia da Vitória" - self[date(year, SEP, 25)] = "Dia das Forças Armadas" - self[date(year, OCT, 4)] = "Dia da Paz e Reconciliação" - self[date(year, DEC, 25)] = "Dia de Natal e da Família" - - # whenever a public holiday falls on a Sunday, - # it rolls over to the following Monday + self[date(year, JAN, 1)] = "Ano novo" + easter_date = easter(year) + self[easter_date + rd(days=-2)] = "Sexta-feira Santa" + + # carnival is the Tuesday before Ash Wednesday + # which is 40 days before easter excluding sundays + self[easter_date + rd(days=-47)] = "Carnaval" + + self[date(year, FEB, 3)] = "Dia dos Heróis Moçambicanos" + self[date(year, APR, 7)] = "Dia da Mulher Moçambicana" + self[date(year, MAY, 1)] = "Dia Mundial do Trabalho" + self[date(year, JUN, 25)] = "Dia da Independência Nacional" + self[date(year, SEP, 7)] = "Dia da Vitória" + self[date(year, SEP, 25)] = "Dia das Forças Armadas" + self[date(year, OCT, 4)] = "Dia da Paz e Reconciliação" + self[date(year, DEC, 25)] = "Dia de Natal e da Família" + + # whenever a public holiday falls on a Sunday, + # it rolls over to the following Monday + if self.observed: for k, v in list(self.items()): - if self.observed: - if k.weekday() == SUN: - self[k + rd(days=1)] = v + " (PONTE)" + if k.weekday() == SUN and k.year == year: + self[k + rd(days=+1)] = v + " (PONTE)" class MZ(Mozambique): diff --git a/holidays/countries/namibia.py b/holidays/countries/namibia.py index d9d607220..0ca6a4b93 100644 --- a/holidays/countries/namibia.py +++ b/holidays/countries/namibia.py @@ -33,44 +33,43 @@ class Namibia(HolidayBase): } def _populate(self, year): + if year <= 1989: + return super()._populate(year) - if year >= 1990: - self[date(year, JAN, 1)] = "New Year's Day" - self[date(year, MAR, 21)] = "Independence Day" - - # Easter Calculation - easter_date = easter(year) - self[easter_date + rd(days=-2)] = "Good Friday" - self[easter_date + rd(days=+1)] = "Easter Monday" - self[easter_date + rd(days=+39)] = "Ascension Day" - # --------END OF EASTER------------# - - self[date(year, MAY, 1)] = "Workers' Day" - self[date(year, MAY, 4)] = "Cassinga Day" - self[date(year, MAY, 25)] = "Africa Day" - self[date(year, AUG, 26)] = "Heroes' Day" - - if year > 2004: - # http://www.lac.org.na/laws/2004/3348.pdf - self[ - date(year, SEP, 10) - ] = "Day of the Namibian Women and Intr. Human Rights Day" - - if year <= 2004: - self[date(year, SEP, 10)] = "International Human Rights Day" - - self[date(year, DEC, 25)] = "Christmas Day" - self[date(year, DEC, 26)] = "Family Day" - - # https://tinyurl.com/lacorg5835 - # As of 1991/2/1, whenever a public holiday falls on a Sunday, - # it rolls over to the monday, unless that monday is already - # a public holiday. - + self[date(year, JAN, 1)] = "New Year's Day" + self[date(year, MAR, 21)] = "Independence Day" + + # Easter Calculation + easter_date = easter(year) + self[easter_date + rd(days=-2)] = "Good Friday" + self[easter_date + rd(days=+1)] = "Easter Monday" + self[easter_date + rd(days=+39)] = "Ascension Day" + # --------END OF EASTER------------# + + self[date(year, MAY, 1)] = "Workers' Day" + self[date(year, MAY, 4)] = "Cassinga Day" + self[date(year, MAY, 25)] = "Africa Day" + self[date(year, AUG, 26)] = "Heroes' Day" + + dt = date(year, SEP, 10) + if year >= 2005: + # http://www.lac.org.na/laws/2004/3348.pdf + self[dt] = "Day of the Namibian Women and Intr. Human Rights Day" + else: + self[dt] = "International Human Rights Day" + + self[date(year, DEC, 25)] = "Christmas Day" + self[date(year, DEC, 26)] = "Family Day" + + # https://tinyurl.com/lacorg5835 + # As of 1991/2/1, whenever a public holiday falls on a Sunday, + # it rolls over to the monday, unless that monday is already + # a public holiday. + if self.observed: for k, v in list(self.items()): - if self.observed and k.weekday() == SUN and k.year == year: - self[k + rd(days=1)] = v + " (Observed)" + if k.weekday() == SUN and k.year == year: + self[k + rd(days=+1)] = v + " (Observed)" class NA(Namibia): diff --git a/holidays/countries/ukraine.py b/holidays/countries/ukraine.py index ebc773860..ed9c22a92 100644 --- a/holidays/countries/ukraine.py +++ b/holidays/countries/ukraine.py @@ -39,39 +39,12 @@ class Ukraine(HolidayBase): country = "UA" - def _add_observed(self, holiday: date) -> None: - """ - 27.01.1995: holiday on weekend move to next workday - https://zakon.rada.gov.ua/laws/show/35/95-вр - - 10.01.1998: cancelled - https://zakon.rada.gov.ua/laws/show/785/97-вр - - 23.04.1999: holiday on weekend move to next workday - https://zakon.rada.gov.ua/laws/show/576-14 - """ - if ( - self.observed - and holiday.weekday() in WEEKEND - and ( - date(1995, JAN, 27) <= holiday <= date(1998, JAN, 9) - or holiday >= date(1999, APR, 23) - ) - ): - next_workday = holiday + rd(days=1) - while next_workday.weekday() in WEEKEND or self.get( - next_workday, None - ): - next_workday += rd(days=1) - self[next_workday] = "Вихідний за " + self[holiday] - def _populate(self, year): - super()._populate(year) - # The current set of holidays came into force in 1991 # But most holiday days were implemented in 1918 if year <= 1917: return + super()._populate(year) # New Year's Day if year <= 1929 or year >= 1948: @@ -109,11 +82,11 @@ def _populate(self, year): name = "День перемоги" dt = date(year, MAY, 9) if year >= 2016: - self[dt] = ( + name = ( "День перемоги над нацизмом у Другій світовій війні " "(День перемоги)" ) - elif 1965 <= year <= 2015: + if year >= 1965: self[dt] = name elif 1945 <= year <= 1946: self[dt] = name @@ -153,9 +126,28 @@ def _populate(self, year): date(year, DEC, 25) ] = "Різдво Христове (за григоріанським календарем)" - for dt in sorted(list(self.keys())): - if dt.year == year: - self._add_observed(dt) + # 27.01.1995: holiday on weekend move to next workday + # https://zakon.rada.gov.ua/laws/show/35/95-вр + # 10.01.1998: cancelled + # https://zakon.rada.gov.ua/laws/show/785/97-вр + # 23.04.1999: holiday on weekend move to next workday + # https://zakon.rada.gov.ua/laws/show/576-14 + if self.observed: + for k, v in list(self.items()): + if ( + k.weekday() in WEEKEND + and k.year == year + and ( + date(1995, JAN, 27) <= k <= date(1998, JAN, 9) + or k >= date(1999, APR, 23) + ) + ): + next_workday = k + rd(days=+1) + while next_workday.weekday() in WEEKEND or self.get( + next_workday + ): + next_workday += rd(days=+1) + self[next_workday] = "Вихідний за " + v # USSR holidays # Bloody_Sunday_(1905) diff --git a/holidays/countries/zimbabwe.py b/holidays/countries/zimbabwe.py index e53f68d2b..806f0a9c3 100644 --- a/holidays/countries/zimbabwe.py +++ b/holidays/countries/zimbabwe.py @@ -28,45 +28,47 @@ class Zimbabwe(HolidayBase): country = "ZW" def _populate(self, year): + if year <= 1987: + return super()._populate(year) - if year > 1987: - self[date(year, JAN, 1)] = "New Year's Day" + self[date(year, JAN, 1)] = "New Year's Day" - if year > 2017: - # https://en.wikipedia.org/wiki/Robert_Gabriel_Mugabe_National_Youth_Day - self[ - date(year, FEB, 21) - ] = "Robert Gabriel Mugabe National Youth Day" + # https://en.wikipedia.org/wiki/Robert_Gabriel_Mugabe_National_Youth_Day + if year >= 2018: + self[ + date(year, FEB, 21) + ] = "Robert Gabriel Mugabe National Youth Day" - easter_date = easter(year) - self[easter_date + rd(days=-2)] = "Good Friday" - self[easter_date + rd(days=-1)] = "Easter Saturday" - self[easter_date + rd(days=+1)] = "Easter Monday" + easter_date = easter(year) + self[easter_date + rd(days=-2)] = "Good Friday" + self[easter_date + rd(days=-1)] = "Easter Saturday" + self[easter_date + rd(days=+1)] = "Easter Monday" - self[date(year, APR, 18)] = "Independence Day" + self[date(year, APR, 18)] = "Independence Day" - self[date(year, MAY, 1)] = "Workers' Day" - self[date(year, MAY, 25)] = "Africa Day" + self[date(year, MAY, 1)] = "Workers' Day" + self[date(year, MAY, 25)] = "Africa Day" - # 2nd Monday of August - zimbabwe_heroes_day = date(year, AUG, 1) + rd(weekday=MO(+2)) - self[zimbabwe_heroes_day] = "Zimbabwe Heroes' Day" + # 2nd Monday of August + zimbabwe_heroes_day = date(year, AUG, 1) + rd(weekday=MO(+2)) + self[zimbabwe_heroes_day] = "Zimbabwe Heroes' Day" - # Tuesday after 2nd Monday of August - defence_forces_day = zimbabwe_heroes_day + rd(days=1) - self[defence_forces_day] = "Defense Forces Day" + # Tuesday after 2nd Monday of August + defence_forces_day = zimbabwe_heroes_day + rd(days=1) + self[defence_forces_day] = "Defense Forces Day" - self[date(year, DEC, 22)] = "Unity Day" - self[date(year, DEC, 25)] = "Christmas Day" - self[date(year, DEC, 26)] = "Boxing Day" + self[date(year, DEC, 22)] = "Unity Day" + self[date(year, DEC, 25)] = "Christmas Day" + self[date(year, DEC, 26)] = "Boxing Day" + if self.observed: for k, v in list(self.items()): - if self.observed and k.weekday() == SUN and k.year == year: - add_days = 1 - while self.get(k + rd(days=add_days)) is not None: - add_days += 1 - self[k + rd(days=add_days)] = v + " (Observed)" + if k.weekday() == SUN and k.year == year: + dt = k + rd(days=+1) + while self.get(dt): + dt += rd(days=+1) + self[dt] = v + " (Observed)" class ZW(Zimbabwe): diff --git a/test/countries/test_botswana.py b/test/countries/test_botswana.py index d428e2689..33fb5a298 100644 --- a/test/countries/test_botswana.py +++ b/test/countries/test_botswana.py @@ -54,3 +54,11 @@ def test_special_holidays(self): def test_saturday_and_monday(self): self.assertIn(date(2020, 12, 26), self.holidays) + + def test_not_observed(self): + self.holidays = holidays.BW(observed=False) + self.assertNotIn(date(2018, 7, 2), self.holidays) + self.assertNotIn(date(2018, 10, 2), self.holidays) + self.assertNotIn(date(2021, 12, 27), self.holidays) + self.assertNotIn(date(2022, 5, 2), self.holidays) + self.assertNotIn(date(2022, 12, 27), self.holidays) diff --git a/test/countries/test_kenya.py b/test/countries/test_kenya.py index cb5fd7e02..4885f7946 100644 --- a/test/countries/test_kenya.py +++ b/test/countries/test_kenya.py @@ -40,3 +40,11 @@ def test_2019(self): self.assertIn(date(2019, 12, 25), self.holidays) # Utamaduni Day self.assertIn(date(2018, 12, 26), self.holidays) + + def test_not_observed(self): + self.holidays = holidays.Kenya(observed=False) + self.assertNotIn(date(2017, 1, 2), self.holidays) + self.assertNotIn(date(2019, 10, 21), self.holidays) + self.assertNotIn(date(2021, 10, 11), self.holidays) + self.assertNotIn(date(2021, 12, 13), self.holidays) + self.assertNotIn(date(2022, 5, 2), self.holidays) diff --git a/test/countries/test_namibia.py b/test/countries/test_namibia.py index 9eeb2b9f3..5d43e4e01 100644 --- a/test/countries/test_namibia.py +++ b/test/countries/test_namibia.py @@ -53,3 +53,11 @@ def test_observed(self): self.assertIn(date(2021, 3, 22), self.holidays) self.assertIn(date(2021, 12, 27), self.holidays) self.assertIn(date(2022, 12, 26), self.holidays) + + def test_not_observed(self): + self.holidays = holidays.NA(observed=False) + self.assertNotIn(date(2017, 1, 2), self.holidays) + self.assertNotIn(date(2017, 9, 11), self.holidays) + self.assertNotIn(date(2018, 8, 27), self.holidays) + self.assertNotIn(date(2021, 3, 22), self.holidays) + self.assertNotIn(date(2021, 12, 27), self.holidays) diff --git a/test/countries/test_zimbabwe.py b/test/countries/test_zimbabwe.py index b138a32b9..55d60c411 100644 --- a/test/countries/test_zimbabwe.py +++ b/test/countries/test_zimbabwe.py @@ -53,3 +53,11 @@ def test_not_holiday(self): def test_youth_day(self): self.assertIn(date(2019, 2, 21), self.holidays) self.assertNotIn(date(2015, 2, 21), self.holidays) + + def test_not_observed(self): + self.holidays = holidays.ZW(observed=False) + self.assertNotIn(date(2017, 1, 2), self.holidays) + self.assertNotIn(date(2019, 12, 23), self.holidays) + self.assertNotIn(date(2021, 2, 22), self.holidays) + self.assertNotIn(date(2022, 5, 2), self.holidays) + self.assertNotIn(date(2022, 12, 27), self.holidays) From 904f58d5f106d2c4cf2a9d93e2211bbe7eec46c5 Mon Sep 17 00:00:00 2001 From: Arkadii Yakovets Date: Thu, 8 Dec 2022 16:52:59 -0800 Subject: [PATCH 053/138] Address review comments. Add isort first-parties. --- holidays/countries/angola.py | 16 +-- holidays/countries/aruba.py | 7 +- holidays/countries/australia.py | 9 +- holidays/countries/azerbaijan.py | 7 +- holidays/countries/belarus.py | 2 +- holidays/countries/bolivia.py | 16 +-- holidays/countries/bosnia_and_herzegovina.py | 2 +- holidays/countries/botswana.py | 8 +- holidays/countries/bulgaria.py | 2 +- holidays/countries/burundi.py | 17 ++- holidays/countries/canada.py | 12 +- holidays/countries/chile.py | 19 ++-- holidays/countries/colombia.py | 10 +- holidays/countries/cuba.py | 10 +- holidays/countries/curacao.py | 9 +- holidays/countries/cyprus.py | 2 +- holidays/countries/djibouti.py | 5 +- holidays/countries/dominican_republic.py | 9 +- holidays/countries/egypt.py | 2 +- holidays/countries/eswatini.py | 9 +- holidays/countries/finland.py | 4 +- holidays/countries/georgia.py | 2 +- holidays/countries/germany.py | 2 +- holidays/countries/greece.py | 4 +- holidays/countries/honduras.py | 2 +- holidays/countries/hongkong.py | 44 ++++---- holidays/countries/hungary.py | 12 +- holidays/countries/iceland.py | 2 +- holidays/countries/indonesia.py | 2 +- holidays/countries/ireland.py | 6 +- holidays/countries/isle_of_man.py | 2 +- holidays/countries/israel.py | 6 +- holidays/countries/jamaica.py | 10 +- holidays/countries/japan.py | 2 +- holidays/countries/kenya.py | 5 +- holidays/countries/lithuania.py | 2 +- holidays/countries/madagascar.py | 2 +- holidays/countries/malawi.py | 7 +- holidays/countries/malaysia.py | 23 +--- holidays/countries/mexico.py | 12 +- holidays/countries/moldova.py | 2 +- holidays/countries/mozambique.py | 5 +- holidays/countries/namibia.py | 9 +- holidays/countries/netherlands.py | 7 +- holidays/countries/new_zealand.py | 19 ++-- holidays/countries/nigeria.py | 5 +- holidays/countries/north_macedonia.py | 2 +- holidays/countries/norway.py | 2 +- holidays/countries/paraguay.py | 8 +- holidays/countries/romania.py | 2 +- holidays/countries/saudi_arabia.py | 8 +- holidays/countries/serbia.py | 7 +- holidays/countries/singapore.py | 5 +- holidays/countries/south_africa.py | 6 +- holidays/countries/south_korea.py | 6 +- holidays/countries/spain.py | 5 +- holidays/countries/sweden.py | 2 +- holidays/countries/switzerland.py | 2 +- holidays/countries/ukraine.py | 2 +- holidays/countries/united_arab_emirates.py | 4 +- holidays/countries/united_kingdom.py | 7 +- holidays/countries/united_states.py | 84 +++++++------- holidays/countries/uruguay.py | 7 +- holidays/countries/zambia.py | 6 +- holidays/countries/zimbabwe.py | 10 +- holidays/financial/ny_stock_exchange.py | 8 +- holidays/holiday_base.py | 5 +- pyproject.toml | 1 + test/common.py | 14 +-- test/countries/test_angola.py | 3 +- test/countries/test_argentina.py | 4 +- test/countries/test_honduras.py | 3 +- test/countries/test_norway.py | 11 +- test/countries/test_sweden.py | 3 +- test/countries/test_united_states.py | 11 +- test/financial/test_ny_stock_exchange.py | 113 ++++++++++--------- test/test_holiday_base.py | 11 +- 77 files changed, 344 insertions(+), 389 deletions(-) diff --git a/holidays/countries/angola.py b/holidays/countries/angola.py index 09b1e7815..d7e573551 100644 --- a/holidays/countries/angola.py +++ b/holidays/countries/angola.py @@ -13,9 +13,9 @@ from dateutil.easter import easter from dateutil.relativedelta import relativedelta as rd -from dateutil.relativedelta import MO, TU, TH, SU -from holidays.constants import JAN, FEB, MAR, APR, MAY, SEP, NOV, DEC +from holidays.constants import JAN, FEB, MAR, APR, MAY, SEP, NOV, DEC, MON +from holidays.constants import TUE, THU, SUN from holidays.holiday_base import HolidayBase @@ -40,7 +40,7 @@ def _populate(self, year: int) -> None: # Since 2018, if the following year's New Year's Day falls on a # Tuesday, the 31st of the current year is also a holiday. if year >= 2018: - if self.observed and date(year, DEC, 31).weekday() == MO.weekday: + if self.observed and date(year, DEC, 31).weekday() == MON: self[date(year, DEC, 31)] = "Ano novo (Day off)" e = easter(year) @@ -74,17 +74,17 @@ def _populate(self, year: int) -> None: # the Monday or Friday is also a holiday for k, v in list(self.items()): if self.observed and year > 1974: - if k.weekday() == SU.weekday: + if k.weekday() == SUN: self[k + rd(days=1)] = v + " (Observed)" if self.observed and year > 2017: - if k.weekday() == SU.weekday: + if k.weekday() == SUN: pass if self.observed and year > 2017: - if k.weekday() == TU.weekday and k != date(year, JAN, 1): + if k.weekday() == TUE and k != date(year, JAN, 1): self[k - rd(days=1)] = v + " (Day off)" - elif k.weekday() == TH.weekday: + elif k.weekday() == THU: self[k + rd(days=1)] = v + " (Day off)" - if self.observed and year > 1994 and k.weekday() == SU.weekday: + if self.observed and year > 1994 and k.weekday() == SUN: self[k + rd(days=1)] = v + " (Observed)" diff --git a/holidays/countries/aruba.py b/holidays/countries/aruba.py index cd743add7..731fdb1ad 100644 --- a/holidays/countries/aruba.py +++ b/holidays/countries/aruba.py @@ -13,9 +13,8 @@ from dateutil.easter import easter from dateutil.relativedelta import relativedelta as rd -from dateutil.relativedelta import SU -from holidays.constants import JAN, MAR, APR, MAY, AUG, DEC +from holidays.constants import JAN, MAR, APR, MAY, AUG, DEC, SUN from holidays.holiday_base import HolidayBase @@ -58,7 +57,7 @@ def _populate(self, year): # King's Day if year >= 2014: kings_day = date(year, APR, 27) - if kings_day.weekday() == SU.weekday: + if kings_day.weekday() == SUN: kings_day = kings_day - rd(days=1) self[kings_day] = "Aña di Rey [King's Day]" @@ -69,7 +68,7 @@ def _populate(self, year): if year <= 1948: queens_day = date(year, AUG, 31) - if queens_day.weekday() == SU.weekday: + if queens_day.weekday() == SUN: if year < 1980: queens_day = queens_day + rd(days=1) else: diff --git a/holidays/countries/australia.py b/holidays/countries/australia.py index 1688216b6..096565f87 100644 --- a/holidays/countries/australia.py +++ b/holidays/countries/australia.py @@ -12,10 +12,11 @@ from datetime import date from dateutil.easter import easter +from dateutil.relativedelta import MO, TU, WE, FR from dateutil.relativedelta import relativedelta as rd -from dateutil.relativedelta import MO, TU, WE, FR, SA, SU -from holidays.constants import JAN, MAR, APR, MAY, JUN, AUG, SEP, OCT, NOV, DEC +from holidays.constants import JAN, MAR, APR, MAY, JUN, AUG, SEP, OCT, NOV +from holidays.constants import DEC, SAT, SUN from holidays.holiday_base import HolidayBase @@ -106,12 +107,12 @@ def _populate(self, year): apr25 = date(year, APR, 25) self[apr25] = name if self.observed: - if apr25.weekday() == SA.weekday and self.subdiv in { + if apr25.weekday() == SAT and self.subdiv in { "WA", "NT", }: self[apr25 + rd(weekday=MO)] = name + " (Observed)" - elif apr25.weekday() == SU.weekday and self.subdiv in { + elif apr25.weekday() == SUN and self.subdiv in { "ACT", "NT", "QLD", diff --git a/holidays/countries/azerbaijan.py b/holidays/countries/azerbaijan.py index fa95fc416..66c0b7df5 100644 --- a/holidays/countries/azerbaijan.py +++ b/holidays/countries/azerbaijan.py @@ -12,9 +12,8 @@ from datetime import date from dateutil.relativedelta import relativedelta as rd -from dateutil.relativedelta import SA, SU -from holidays.constants import JAN, MAR, MAY, JUN, OCT, NOV, DEC +from holidays.constants import JAN, MAR, MAY, JUN, OCT, NOV, DEC, SAT, SUN from holidays.holiday_base import HolidayBase from holidays.utils import _islamic_to_gre @@ -90,12 +89,12 @@ def _populate(self, year: int) -> None: # If the prior year's International Solidarity Day of Azerbaijanis # falls on a Saturday or Monday, the 1st Monday of the current year is # also a holiday. - if self.observed and date(year - 1, DEC, 31).weekday() == SU.weekday: + if self.observed and date(year - 1, DEC, 31).weekday() == SUN: self[date(year, JAN, 1)] = ( "International Solidarity Day of Azerbaijanis" + OBSERVED_SUFFIX ) - elif self.observed and date(year - 1, DEC, 31).weekday() == SA.weekday: + elif self.observed and date(year - 1, DEC, 31).weekday() == SAT: self[date(year, JAN, 2)] = ( "International Solidarity Day of Azerbaijanis" + OBSERVED_SUFFIX diff --git a/holidays/countries/belarus.py b/holidays/countries/belarus.py index 5aee54cbf..348a7f2e0 100644 --- a/holidays/countries/belarus.py +++ b/holidays/countries/belarus.py @@ -14,7 +14,7 @@ from dateutil.easter import EASTER_ORTHODOX, easter from dateutil.relativedelta import relativedelta as rd -from holidays.constants import JAN, MAR, MAY, JUL, NOV, DEC +from holidays.constants import DEC, JAN, JUL, MAR, MAY, NOV from holidays.holiday_base import HolidayBase diff --git a/holidays/countries/bolivia.py b/holidays/countries/bolivia.py index c53ee88e8..0b18af564 100644 --- a/holidays/countries/bolivia.py +++ b/holidays/countries/bolivia.py @@ -13,10 +13,10 @@ from datetime import date from dateutil.easter import easter -from dateutil.relativedelta import FR, SU from dateutil.relativedelta import relativedelta as rd -from holidays.constants import JAN, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC +from holidays.constants import JAN, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV +from holidays.constants import DEC, FRI, SUN from holidays.holiday_base import HolidayBase @@ -47,7 +47,7 @@ def _populate(self, year): if year >= 1825: self[date(year, JAN, 1)] = name - if self.observed and date(year, JAN, 1).weekday() == SU.weekday: + if self.observed and date(year, JAN, 1).weekday() == SUN: self[date(year, JAN, 1) + rd(days=+1)] = f"{name} (Observed)" # Plurinational State Foundation Day. @@ -77,7 +77,7 @@ def _populate(self, year): name = "Dia del trabajo" self[date(year, MAY, 1)] = name - if self.observed and date(year, MAY, 1).weekday() == SU.weekday: + if self.observed and date(year, MAY, 1).weekday() == SUN: self[date(year, MAY, 1) + rd(days=+1)] = f"{name} (Observed)" # Chuquisaca Day. @@ -92,7 +92,7 @@ def _populate(self, year): if year >= 2010: self[date(year, JUN, 21)] = name - if self.observed and date(year, JUN, 21).weekday() == SU.weekday: + if self.observed and date(year, JUN, 21).weekday() == SUN: self[date(year, JUN, 21) + rd(days=+1)] = f"{name} (Observed)" # La Paz Day. @@ -108,7 +108,7 @@ def _populate(self, year): if year >= 1825: self[date(year, AUG, 6)] = name - if self.observed and date(year, AUG, 6).weekday() > FR.weekday: + if self.observed and date(year, AUG, 6).weekday() > FRI: self[date(year, AUG, 6) + rd(days=+1)] = f"{name} (Observed)" # Cochabamba Day. @@ -127,7 +127,7 @@ def _populate(self, year): name = "Todos Santos" self[date(year, NOV, 2)] = name - if self.observed and date(year, NOV, 2).weekday() == SU.weekday: + if self.observed and date(year, NOV, 2).weekday() == SUN: self[date(year, NOV, 2) + rd(days=+1)] = f"{name} (Observed)" # Potosí Day. @@ -142,7 +142,7 @@ def _populate(self, year): name = "Navidad" self[date(year, DEC, 25)] = name - if self.observed and date(year, DEC, 25).weekday() == SU.weekday: + if self.observed and date(year, DEC, 25).weekday() == SUN: self[date(year, DEC, 25) + rd(days=+1)] = f"{name} (Observed)" diff --git a/holidays/countries/bosnia_and_herzegovina.py b/holidays/countries/bosnia_and_herzegovina.py index c7a418e07..59abdcbbb 100644 --- a/holidays/countries/bosnia_and_herzegovina.py +++ b/holidays/countries/bosnia_and_herzegovina.py @@ -12,7 +12,7 @@ from datetime import date -from dateutil.easter import easter, EASTER_ORTHODOX +from dateutil.easter import EASTER_ORTHODOX, easter from dateutil.relativedelta import relativedelta as rd from holidays.constants import DEC, JAN, JUN, MAR, MAY, NOV, SUN diff --git a/holidays/countries/botswana.py b/holidays/countries/botswana.py index db6a7f178..64cbce3ea 100644 --- a/holidays/countries/botswana.py +++ b/holidays/countries/botswana.py @@ -12,10 +12,10 @@ from datetime import date from dateutil.easter import easter +from dateutil.relativedelta import MO from dateutil.relativedelta import relativedelta as rd -from dateutil.relativedelta import MO, SA, SU -from holidays.constants import JAN, MAY, JUL, SEP, OCT, DEC +from holidays.constants import JAN, MAY, JUL, SEP, OCT, DEC, SAT, SUN from holidays.holiday_base import HolidayBase @@ -65,7 +65,7 @@ def _populate(self, year: int): if ( self.observed and year > 2015 - and k.weekday() == SA.weekday + and k.weekday() == SAT and k.year == year and v.upper() in {"BOXING DAY", "LABOUR DAY"} ): @@ -74,7 +74,7 @@ def _populate(self, year: int): if ( self.observed and year > 1994 - and k.weekday() == SU.weekday + and k.weekday() == SUN and k.year == year and v.upper() != "NEW YEAR'S DAY HOLIDAY" ): diff --git a/holidays/countries/bulgaria.py b/holidays/countries/bulgaria.py index bfa0cf006..aee2ca563 100644 --- a/holidays/countries/bulgaria.py +++ b/holidays/countries/bulgaria.py @@ -11,7 +11,7 @@ from datetime import date -from dateutil.easter import easter, EASTER_ORTHODOX +from dateutil.easter import EASTER_ORTHODOX, easter from dateutil.relativedelta import relativedelta as rd from holidays.constants import JAN, MAR, MAY, SEP, NOV, DEC diff --git a/holidays/countries/burundi.py b/holidays/countries/burundi.py index c65b41588..b0d5cfd81 100644 --- a/holidays/countries/burundi.py +++ b/holidays/countries/burundi.py @@ -13,9 +13,8 @@ from dateutil.easter import easter from dateutil.relativedelta import relativedelta as rd -from dateutil.relativedelta import SU -from holidays.constants import JAN, FEB, APR, MAY, JUL, AUG, OCT, NOV, DEC +from holidays.constants import JAN, FEB, APR, MAY, JUL, AUG, OCT, NOV, DEC, SUN from holidays.holiday_base import HolidayBase from holidays.utils import _islamic_to_gre @@ -51,19 +50,19 @@ def _add_holiday(dt: date, hol: str) -> None: # Unity Day name = "Unity Day" self[date(year, FEB, 5)] = name - if date(year, FEB, 5).weekday() == SU.weekday: + if date(year, FEB, 5).weekday() == SUN: self[date(year, FEB, 6)] = name + " (Observed)" # President Ntaryamira Day name = "President Ntaryamira Day" self[date(year, APR, 6)] = "President Ntaryamira Day" - if date(year, APR, 6).weekday() == SU.weekday: + if date(year, APR, 6).weekday() == SUN: self[date(year, APR, 7)] = name + " (Observed)" # Labour Day name = "Labour Day" self[date(year, MAY, 1)] = name - if date(year, MAY, 1).weekday() == SU.weekday: + if date(year, MAY, 1).weekday() == SUN: self[date(year, MAY, 2)] = name + " (Observed)" # Ascension Day @@ -74,7 +73,7 @@ def _add_holiday(dt: date, hol: str) -> None: name = "Independence Day" if year > 1961: self[date(year, JUL, 1)] = name - if date(year, JUL, 1).weekday() == SU.weekday: + if date(year, JUL, 1).weekday() == SUN: self[date(year, JUL, 2)] = name + " (Observed)" # Eid Al Adha- Feast of the Sacrifice @@ -92,19 +91,19 @@ def _add_holiday(dt: date, hol: str) -> None: # Prince Louis Rwagasore Day name = "Prince Louis Rwagasore Day" self[date(year, OCT, 13)] = name - if date(year, OCT, 13).weekday() == SU.weekday: + if date(year, OCT, 13).weekday() == SUN: self[date(year, OCT, 14)] = name + " (Observed)" # President Ndadaye's Day name = "President Ndadaye's Day" self[date(year, OCT, 21)] = name - if date(year, OCT, 21).weekday() == SU.weekday: + if date(year, OCT, 21).weekday() == SUN: self[date(year, OCT, 22)] = name + " (Observed)" # All Saints' Day name = "All Saints' Day" self[date(year, NOV, 1)] = name - if date(year, NOV, 1).weekday() == SU.weekday: + if date(year, NOV, 1).weekday() == SUN: self[date(year, NOV, 2)] = name + " (Observed)" # Christmas Day diff --git a/holidays/countries/canada.py b/holidays/countries/canada.py index 0b6535693..f219620f9 100644 --- a/holidays/countries/canada.py +++ b/holidays/countries/canada.py @@ -12,11 +12,11 @@ from datetime import date from dateutil.easter import easter +from dateutil.relativedelta import MO, SU from dateutil.relativedelta import relativedelta as rd -from dateutil.relativedelta import MO, FR, SU from holidays.constants import JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP -from holidays.constants import OCT, NOV, DEC +from holidays.constants import OCT, NOV, DEC, FRI, SUN from holidays.holiday_base import HolidayBase @@ -46,7 +46,7 @@ def __init__(self, **kwargs): @staticmethod def _get_nearest_monday(d: date) -> date: - if d.weekday() < FR.weekday: + if d.weekday() < FRI: return d + rd(weekday=MO(-1)) else: return d + rd(weekday=MO) @@ -143,7 +143,7 @@ def _populate(self, year): name = "St. Jean Baptiste Day" dt = date(year, JUN, 24) self[dt] = name - if self.observed and dt.weekday() == SU.weekday: + if self.observed and dt.weekday() == SUN: self[dt + rd(days=1)] = name + " (Observed)" # Discovery Day @@ -170,7 +170,7 @@ def _populate(self, year): if year >= 2001: dt = date(year, JUL, 9) self[dt] = name - if self.observed and dt.weekday() == SU.weekday: + if self.observed and dt.weekday() == SUN: self[dt + rd(days=1)] = name + " (Observed)" elif year == 2000: self[date(2000, APR, 1)] = name @@ -233,7 +233,7 @@ def _populate(self, year): self[dt] = name if ( self.observed - and dt.weekday() == SU.weekday + and dt.weekday() == SUN and self.subdiv in {"NS", "NL", "NT", "PE", "SK"} ): self[dt + rd(weekday=MO)] = name + " (Observed)" diff --git a/holidays/countries/chile.py b/holidays/countries/chile.py index 8c92243ab..4a4b990fa 100644 --- a/holidays/countries/chile.py +++ b/holidays/countries/chile.py @@ -12,10 +12,11 @@ from datetime import date from dateutil.easter import easter +from dateutil.relativedelta import MO from dateutil.relativedelta import relativedelta as rd -from dateutil.relativedelta import MO, TU, TH, FR, SA, SU from holidays.constants import JAN, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC +from holidays.constants import TUE, THU, FRI, SAT, SUN from holidays.holiday_base import HolidayBase @@ -54,7 +55,7 @@ def _populate(self, year): # New Year's Day (Law 2.977) self[date(year, JAN, 1)] = "Año Nuevo [New Year's Day]" # Day after, if it's a Sunday (Law 20.983) - if year > 2016 and date(year, JAN, 1).weekday() == SU.weekday: + if year > 2016 and date(year, JAN, 1).weekday() == SUN: self[date(year, JAN, 2)] = "Fiestas Patrias [Holiday]" # Holy Week (Law 2.977) @@ -87,12 +88,12 @@ def _populate(self, year): self[date(year, JUN, 29)] = name else: # floating Monday holiday (Law 19.668) - if date(year, JUN, 29).weekday() <= TH.weekday: + if date(year, JUN, 29).weekday() <= THU: self[ date(year, JUN, 29) + rd(date(year, JUN, 29), weekday=MO(-1)) ] = name - elif date(year, JUN, 29).weekday() == FR.weekday: + elif date(year, JUN, 29).weekday() == FRI: self[date(year, JUN, 29) + rd(weekday=MO)] = name else: self[date(year, JUN, 29)] = name @@ -107,11 +108,11 @@ def _populate(self, year): self[date(year, AUG, 15)] = name # National Holiday Friday preceding Independence Day (Law 20.983) - if year > 2016 and date(year, SEP, 18).weekday() == SA.weekday: + if year > 2016 and date(year, SEP, 18).weekday() == SAT: self[date(year, SEP, 17)] = "Fiestas Patrias [Holiday]" # National Holiday Monday preceding Independence Day (Law 20.215) - if year > 2007 and date(year, SEP, 18).weekday() == TU.weekday: + if year > 2007 and date(year, SEP, 18).weekday() == TUE: self[date(year, SEP, 17)] = "Fiestas Patrias [Holiday]" # Independence Day (Law 2.977) @@ -123,7 +124,7 @@ def _populate(self, year): self[date(year, SEP, 19)] = name # National Holiday Friday following Army Day (Law 20.215) - if year > 2007 and date(year, SEP, 19).weekday() == TH.weekday: + if year > 2007 and date(year, SEP, 19).weekday() == THU: self[date(year, SEP, 20)] = "Fiestas Patrias [Holiday]" # Day of the Meeting of Two Worlds (Law 3.810) @@ -138,12 +139,12 @@ def _populate(self, year): else: # floating Monday holiday (Law 19.668) name = "Día del Descubrimiento de dos Mundos [Columbus Day]" - if date(year, OCT, 12).weekday() <= TH.weekday: + if date(year, OCT, 12).weekday() <= THU: self[ date(year, OCT, 12) + rd(date(year, OCT, 12), weekday=MO(-1)) ] = name - elif date(year, OCT, 12).weekday() == FR.weekday: + elif date(year, OCT, 12).weekday() == FRI: self[date(year, OCT, 12) + rd(weekday=MO)] = name else: self[date(year, OCT, 12)] = name diff --git a/holidays/countries/colombia.py b/holidays/countries/colombia.py index a8a1d97ea..e37ade1ca 100644 --- a/holidays/countries/colombia.py +++ b/holidays/countries/colombia.py @@ -12,10 +12,10 @@ from datetime import date from dateutil.easter import easter -from dateutil.relativedelta import relativedelta as rd from dateutil.relativedelta import MO +from dateutil.relativedelta import relativedelta as rd -from holidays.constants import JAN, MAR, MAY, JUN, JUL, AUG, OCT, NOV, DEC +from holidays.constants import JAN, MAR, MAY, JUN, JUL, AUG, OCT, NOV, DEC, MON from holidays.holiday_base import HolidayBase @@ -46,11 +46,7 @@ def _add_with_bridge(self, _date, name): 1984: https://bit.ly/3B7ogt8 """ - if ( - self.observed - and _date.weekday() != MO.weekday - and _date.year > 1983 - ): + if self.observed and _date.weekday() != MON and _date.year > 1983: self[_date + rd(weekday=MO)] = name + " (Observed)" else: self[_date] = name diff --git a/holidays/countries/cuba.py b/holidays/countries/cuba.py index 00d47d3ae..6c7f1da8a 100644 --- a/holidays/countries/cuba.py +++ b/holidays/countries/cuba.py @@ -12,10 +12,10 @@ from datetime import date from dateutil.easter import easter +from dateutil.relativedelta import MO from dateutil.relativedelta import relativedelta as rd -from dateutil.relativedelta import MO, SU -from holidays.constants import JAN, MAY, JUL, OCT, DEC +from holidays.constants import JAN, MAY, JUL, OCT, DEC, SUN from holidays.holiday_base import HolidayBase @@ -44,7 +44,7 @@ def _populate(self, year): if ( year <= 2013 and self.observed - and date(year, JAN, 1).weekday() == SU.weekday + and date(year, JAN, 1).weekday() == SUN ): self[date(year, JAN, 1) + rd(weekday=MO)] = name + " (Observed)" @@ -61,7 +61,7 @@ def _populate(self, year): name = "Día Internacional de los Trabajadores [Labour Day]" self[date(year, MAY, 1)] = name - if self.observed and date(year, MAY, 1).weekday() == SU.weekday: + if self.observed and date(year, MAY, 1).weekday() == SUN: self[date(year, MAY, 1) + rd(weekday=MO)] = name + " (Observed)" self[date(year, JUL, 25)] = ( @@ -80,7 +80,7 @@ def _populate(self, year): name = "Inicio de las Guerras de Independencia [Independence Day]" self[date(year, OCT, 10)] = name - if self.observed and date(year, OCT, 10).weekday() == SU.weekday: + if self.observed and date(year, OCT, 10).weekday() == SUN: self[date(year, OCT, 10) + rd(weekday=MO)] = name + " (Observed)" # In 1969, Christmas was cancelled for the sugar harvest but then was diff --git a/holidays/countries/curacao.py b/holidays/countries/curacao.py index fd31640ec..139e4a492 100644 --- a/holidays/countries/curacao.py +++ b/holidays/countries/curacao.py @@ -13,9 +13,8 @@ from dateutil.easter import easter from dateutil.relativedelta import relativedelta as rd -from dateutil.relativedelta import SU -from holidays.constants import JAN, APR, MAY, JUL, AUG, OCT, DEC +from holidays.constants import JAN, APR, MAY, JUL, AUG, OCT, DEC, SUN from holidays.holiday_base import HolidayBase @@ -49,7 +48,7 @@ def _populate(self, year): # King's Day if year >= 2014: kings_day = date(year, APR, 27) - if kings_day.weekday() == SU.weekday: + if kings_day.weekday() == SUN: kings_day = kings_day - rd(days=1) self[kings_day] = "Koningsdag [King's Day]" @@ -60,7 +59,7 @@ def _populate(self, year): if year <= 1948: queens_day = date(year, AUG, 31) - if queens_day.weekday() == SU.weekday: + if queens_day.weekday() == SUN: if year < 1980: queens_day = queens_day + rd(days=1) else: @@ -70,7 +69,7 @@ def _populate(self, year): # Labour Day labour_day = date(year, MAY, 1) - if labour_day.weekday() == SU.weekday: + if labour_day.weekday() == SUN: labour_day = labour_day + rd(days=1) self[labour_day] = "Dia di Obrero [Labour Day]" diff --git a/holidays/countries/cyprus.py b/holidays/countries/cyprus.py index 0c3412e4b..a0cc209e5 100644 --- a/holidays/countries/cyprus.py +++ b/holidays/countries/cyprus.py @@ -11,7 +11,7 @@ from datetime import date -from dateutil.easter import easter, EASTER_ORTHODOX +from dateutil.easter import EASTER_ORTHODOX, easter from dateutil.relativedelta import relativedelta as rd from holidays.constants import JAN, MAR, APR, MAY, AUG, OCT, DEC diff --git a/holidays/countries/djibouti.py b/holidays/countries/djibouti.py index e787587df..a299d5bd7 100644 --- a/holidays/countries/djibouti.py +++ b/holidays/countries/djibouti.py @@ -12,9 +12,8 @@ from datetime import date from dateutil.relativedelta import relativedelta as rd -from dateutil.relativedelta import FR, SA -from holidays.constants import JAN, MAY, JUN +from holidays.constants import JAN, MAY, JUN, FRI, SAT from holidays.holiday_base import HolidayBase from holidays.utils import _islamic_to_gre @@ -39,7 +38,7 @@ class Djibouti(HolidayBase): # is_weekend function is there, however not activated for accuracy. country = "DJ" - weekend = {FR.weekday, SA.weekday} + weekend = {FRI, SAT} def _populate(self, year): super()._populate(year) diff --git a/holidays/countries/dominican_republic.py b/holidays/countries/dominican_republic.py index ab5eaa917..64a314cd8 100644 --- a/holidays/countries/dominican_republic.py +++ b/holidays/countries/dominican_republic.py @@ -12,10 +12,11 @@ from datetime import date from dateutil.easter import easter +from dateutil.relativedelta import MO from dateutil.relativedelta import relativedelta as rd -from dateutil.relativedelta import MO, TU, WE, TH, FR -from holidays.constants import JAN, FEB, MAY, JUN, AUG, SEP, NOV, DEC +from holidays.constants import JAN, FEB, MAY, JUN, AUG, SEP, NOV, DEC, TUE +from holidays.constants import WED, THU, FRI from holidays.holiday_base import HolidayBase @@ -28,10 +29,10 @@ class DominicanRepublic(HolidayBase): country = "DO" @staticmethod - def __change_day_by_law(holiday, latest_days=(TH.weekday, FR.weekday)): + def __change_day_by_law(holiday, latest_days=(THU, FRI)): # Law No. 139-97 - Holidays Dominican Republic - Jun 27, 1997 if holiday >= date(1997, 6, 27): - if holiday.weekday() in {TU.weekday, WE.weekday}: + if holiday.weekday() in {TUE, WED}: holiday -= rd(weekday=MO(-1)) elif holiday.weekday() in latest_days: holiday += rd(weekday=MO(1)) diff --git a/holidays/countries/egypt.py b/holidays/countries/egypt.py index ca79fe27d..8ddc3990c 100644 --- a/holidays/countries/egypt.py +++ b/holidays/countries/egypt.py @@ -11,7 +11,7 @@ from datetime import date -from dateutil.easter import easter, EASTER_ORTHODOX +from dateutil.easter import EASTER_ORTHODOX, easter from dateutil.relativedelta import relativedelta as rd from holidays.constants import JAN, APR, MAY, JUN, JUL, OCT diff --git a/holidays/countries/eswatini.py b/holidays/countries/eswatini.py index 260316138..0224ab0e7 100644 --- a/holidays/countries/eswatini.py +++ b/holidays/countries/eswatini.py @@ -14,9 +14,8 @@ from dateutil.easter import easter from dateutil.relativedelta import relativedelta as rd -from dateutil.relativedelta import SU -from holidays.constants import JAN, APR, MAY, JUL, SEP, DEC +from holidays.constants import JAN, APR, MAY, JUL, SEP, DEC, SUN from holidays.holiday_base import HolidayBase @@ -66,11 +65,7 @@ def _populate(self, year): # it rolls over to the following Monday for k, v in list(self.items()): - if ( - self.observed - and k.weekday() == SU.weekday - and k.year == year - ): + if self.observed and k.weekday() == SUN and k.year == year: add_days = 1 while self.get(k + rd(days=add_days)) is not None: add_days += 1 diff --git a/holidays/countries/finland.py b/holidays/countries/finland.py index c4698aead..58dbd170d 100644 --- a/holidays/countries/finland.py +++ b/holidays/countries/finland.py @@ -12,10 +12,10 @@ from datetime import date from dateutil.easter import easter -from dateutil.relativedelta import relativedelta as rd from dateutil.relativedelta import FR, SA +from dateutil.relativedelta import relativedelta as rd -from holidays.constants import JAN, MAY, JUN, OCT, DEC +from holidays.constants import DEC, JAN, JUN, MAY, OCT from holidays.holiday_base import HolidayBase diff --git a/holidays/countries/georgia.py b/holidays/countries/georgia.py index 52ef9c799..f223ece7d 100644 --- a/holidays/countries/georgia.py +++ b/holidays/countries/georgia.py @@ -11,7 +11,7 @@ from datetime import date -from dateutil.easter import easter, EASTER_ORTHODOX +from dateutil.easter import EASTER_ORTHODOX, easter from dateutil.relativedelta import relativedelta as rd from holidays.constants import JAN, MAR, APR, MAY, AUG, OCT, NOV diff --git a/holidays/countries/germany.py b/holidays/countries/germany.py index 3e1ec7dce..75b1b608a 100644 --- a/holidays/countries/germany.py +++ b/holidays/countries/germany.py @@ -12,8 +12,8 @@ from datetime import date from dateutil.easter import easter -from dateutil.relativedelta import relativedelta as rd from dateutil.relativedelta import WE +from dateutil.relativedelta import relativedelta as rd from holidays.constants import JAN, MAR, MAY, AUG, SEP, OCT, NOV, DEC from holidays.holiday_base import HolidayBase diff --git a/holidays/countries/greece.py b/holidays/countries/greece.py index 45329e160..b85a2a61e 100644 --- a/holidays/countries/greece.py +++ b/holidays/countries/greece.py @@ -11,9 +11,9 @@ from datetime import date -from dateutil.easter import easter, EASTER_ORTHODOX -from dateutil.relativedelta import relativedelta as rd +from dateutil.easter import EASTER_ORTHODOX, easter from dateutil.relativedelta import MO, TU +from dateutil.relativedelta import relativedelta as rd from holidays.constants import JAN, MAR, MAY, AUG, OCT, DEC from holidays.holiday_base import HolidayBase diff --git a/holidays/countries/honduras.py b/holidays/countries/honduras.py index 594ca5224..a163baec9 100644 --- a/holidays/countries/honduras.py +++ b/holidays/countries/honduras.py @@ -12,8 +12,8 @@ from datetime import date from dateutil.easter import easter -from dateutil.relativedelta import relativedelta as rd from dateutil.relativedelta import WE +from dateutil.relativedelta import relativedelta as rd from holidays.constants import JAN, APR, MAY, SEP, OCT, DEC from holidays.holiday_base import HolidayBase diff --git a/holidays/countries/hongkong.py b/holidays/countries/hongkong.py index 21cf1b4dd..73a0300f1 100644 --- a/holidays/countries/hongkong.py +++ b/holidays/countries/hongkong.py @@ -12,10 +12,11 @@ from datetime import date from dateutil.easter import easter +from dateutil.relativedelta import MO from dateutil.relativedelta import relativedelta as rd -from dateutil.relativedelta import MO, TU, WE, TH, FR, SA, SU from holidays.constants import JAN, APR, MAY, JUN, JUL, AUG, SEP, OCT, DEC +from holidays.constants import MON, TUE, WED, THU, FRI, SAT, SUN from holidays.holiday_base import HolidayBase from holidays.utils import _ChineseLuniSolar @@ -56,7 +57,7 @@ def _populate(self, year): # The first day of January first_date = date(year, JAN, 1) - if self.observed and first_date.weekday() == SU.weekday: + if self.observed and first_date.weekday() == SUN: self[first_date + rd(days=+1)] = ( day_following + "the first day of January" ) @@ -73,34 +74,34 @@ def _populate(self, year): if self.observed: self[new_year_date] = name if new_year_date.weekday() in { - MO.weekday, - TU.weekday, - WE.weekday, - TH.weekday, + MON, + TUE, + WED, + THU, }: self[new_year_date] = name self[new_year_date + rd(days=+1)] = second_day_lunar self[new_year_date + rd(days=+2)] = third_day_lunar - if new_year_date.weekday() == FR.weekday: + if new_year_date.weekday() == FRI: self[new_year_date] = name self[new_year_date + rd(days=+1)] = second_day_lunar self[new_year_date + rd(days=+3)] = fourth_day_lunar - if new_year_date.weekday() == SA.weekday: + if new_year_date.weekday() == SAT: self[new_year_date] = name self[new_year_date + rd(days=+2)] = third_day_lunar self[new_year_date + rd(days=+3)] = fourth_day_lunar - if new_year_date.weekday() == SU.weekday: + if new_year_date.weekday() == SUN: if year in {2006, 2007, 2010}: self[new_year_date + rd(days=-1)] = preceding_day_lunar else: self[new_year_date + rd(days=+3)] = fourth_day_lunar else: self[new_year_date] = name - if new_year_date.weekday() == SA.weekday: + if new_year_date.weekday() == SAT: self[new_year_date + rd(days=+3)] = fourth_day_lunar else: self[new_year_date + rd(days=+1)] = second_day_lunar - if new_year_date.weekday() == FR.weekday: + if new_year_date.weekday() == FRI: self[new_year_date + rd(days=+3)] = fourth_day_lunar else: self[new_year_date + rd(days=+2)] = third_day_lunar @@ -120,7 +121,7 @@ def _populate(self, year): else: ching_ming_date = date(year, APR, 5) if self.observed and ( - ching_ming_date.weekday() == SU.weekday + ching_ming_date.weekday() == SUN or ching_ming_date == easter_monday_date ): self[ching_ming_date + rd(days=+1)] = day_following + name @@ -143,7 +144,7 @@ def _populate(self, year): if year >= 1998: name = "The Birthday of the Buddha" buddha_date = self.cnls.lunar_to_gre(year, 4, 8) - if self.observed and buddha_date.weekday() == SU.weekday: + if self.observed and buddha_date.weekday() == SUN: self[buddha_date + rd(days=+1)] = day_following + name else: self[buddha_date] = name @@ -152,7 +153,7 @@ def _populate(self, year): if year >= 1998: name = "Labour Day" labour_date = date(year, MAY, 1) - if self.observed and labour_date.weekday() == SU.weekday: + if self.observed and labour_date.weekday() == SUN: self[labour_date + rd(days=+1)] = day_following + name else: self[labour_date] = name @@ -160,7 +161,7 @@ def _populate(self, year): # Tuen Ng Festival name = "Tuen Ng Festival" tuen_ng_date = self.cnls.lunar_to_gre(year, 5, 5) - if self.observed and tuen_ng_date.weekday() == SU.weekday: + if self.observed and tuen_ng_date.weekday() == SUN: self[tuen_ng_date + rd(days=+1)] = day_following + name else: self[tuen_ng_date] = name @@ -169,7 +170,7 @@ def _populate(self, year): if year >= 1997: name = "Hong Kong Special Administrative Region Establishment Day" hksar_date = date(year, JUL, 1) - if self.observed and hksar_date.weekday() == SU.weekday: + if self.observed and hksar_date.weekday() == SUN: self[hksar_date + rd(days=+1)] = day_following + name else: self[hksar_date] = name @@ -182,7 +183,7 @@ def _populate(self, year): # before 1983 public holiday lies on Monday # from 1983 to 2010 public holiday lies on same day # since 2011 public holiday lies on Monday - if mid_autumn_date.weekday() == SA.weekday: + if mid_autumn_date.weekday() == SAT: if 1983 <= year <= 2010: self[mid_autumn_date] = name else: @@ -201,8 +202,7 @@ def _populate(self, year): name = "National Day" national_date = date(year, OCT, 1) if self.observed and ( - national_date.weekday() == SU.weekday - or self.get(national_date) + national_date.weekday() == SUN or self.get(national_date) ): self[national_date + rd(days=+1)] = day_following + name else: @@ -211,7 +211,7 @@ def _populate(self, year): # Chung Yeung Festival name = "Chung Yeung Festival" chung_yeung_date = self.cnls.lunar_to_gre(year, 9, 9) - if self.observed and chung_yeung_date.weekday() == SU.weekday: + if self.observed and chung_yeung_date.weekday() == SUN: self[chung_yeung_date + rd(days=+1)] = day_following + name else: self[chung_yeung_date] = name @@ -222,10 +222,10 @@ def _populate(self, year): second_after_christmas = "The second weekday after " + name christmas_date = date(year, DEC, 25) if self.observed: - if christmas_date.weekday() == SU.weekday: + if christmas_date.weekday() == SUN: self[christmas_date + rd(days=+1)] = first_after_christmas self[christmas_date + rd(days=+2)] = second_after_christmas - elif christmas_date.weekday() == SA.weekday: + elif christmas_date.weekday() == SAT: self[christmas_date] = name self[christmas_date + rd(days=+2)] = first_after_christmas else: diff --git a/holidays/countries/hungary.py b/holidays/countries/hungary.py index 0800e09e9..7be71b700 100644 --- a/holidays/countries/hungary.py +++ b/holidays/countries/hungary.py @@ -13,9 +13,9 @@ from dateutil.easter import easter from dateutil.relativedelta import relativedelta as rd -from dateutil.relativedelta import MO, TU, TH -from holidays.constants import JAN, MAR, APR, MAY, AUG, OCT, NOV, DEC +from holidays.constants import JAN, MAR, APR, MAY, AUG, OCT, NOV, DEC, MON +from holidays.constants import TUE, THU from holidays.holiday_base import HolidayBase @@ -37,7 +37,7 @@ def _populate(self, year: int) -> None: # Since 2014, the last day of the year is an observed day off if New # Year's Day falls on a Tuesday. if year >= 2014: - if self.observed and date(year, DEC, 31).weekday() == MO.weekday: + if self.observed and date(year, DEC, 31).weekday() == MON: self[date(year, DEC, 31)] = "Újév előtti pihenőnap" # National Day @@ -134,7 +134,7 @@ def _populate(self, year: int) -> None: if ( self.observed and 2014 <= year - and date(year, DEC, 31).weekday() == MO.weekday + and date(year, DEC, 31).weekday() == MON ): self[date(year, DEC, 31)] = "Szilveszter" @@ -152,12 +152,12 @@ def _add_with_observed_day_off( # TODO: should it be a separate flag? if self.observed and since <= day.year: if ( - day.weekday() == TU.weekday + day.weekday() == TUE and before and not (day.month == JAN and day.day == 1) ): self[day - rd(days=1)] = desc + " előtti pihenőnap" - elif day.weekday() == TH.weekday and after: + elif day.weekday() == THU and after: self[day + rd(days=1)] = desc + " utáni pihenőnap" diff --git a/holidays/countries/iceland.py b/holidays/countries/iceland.py index fa5d8daa4..c4f7019d1 100644 --- a/holidays/countries/iceland.py +++ b/holidays/countries/iceland.py @@ -12,8 +12,8 @@ from datetime import date from dateutil.easter import easter -from dateutil.relativedelta import relativedelta as rd from dateutil.relativedelta import MO, TH +from dateutil.relativedelta import relativedelta as rd from holidays.constants import JAN, APR, MAY, JUN, AUG, DEC from holidays.holiday_base import HolidayBase diff --git a/holidays/countries/indonesia.py b/holidays/countries/indonesia.py index 8ac898fb1..c5ee8e0d2 100644 --- a/holidays/countries/indonesia.py +++ b/holidays/countries/indonesia.py @@ -17,7 +17,7 @@ from holidays.constants import JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP from holidays.constants import OCT, NOV, DEC from holidays.holiday_base import HolidayBase -from holidays.utils import _islamic_to_gre, _ChineseLuniSolar +from holidays.utils import _ChineseLuniSolar, _islamic_to_gre class Indonesia(HolidayBase): diff --git a/holidays/countries/ireland.py b/holidays/countries/ireland.py index acd41cc9a..b8a330ebe 100644 --- a/holidays/countries/ireland.py +++ b/holidays/countries/ireland.py @@ -11,10 +11,10 @@ from datetime import date from dateutil.easter import easter +from dateutil.relativedelta import MO from dateutil.relativedelta import relativedelta as rd -from dateutil.relativedelta import MO, FR -from holidays.constants import JAN, FEB, MAR, MAY, JUN, AUG, OCT, DEC +from holidays.constants import JAN, FEB, MAR, MAY, JUN, AUG, OCT, DEC, FRI from holidays.holiday_base import HolidayBase @@ -40,7 +40,7 @@ def _populate(self, year): name = "St. Brigid's Day" dt = date(year, FEB, 1) self[dt] = name - if self.observed and dt.weekday() != FR.weekday: + if self.observed and dt.weekday() != FRI: self[dt + rd(weekday=MO)] = name + " (Observed)" # St. Patrick's Day diff --git a/holidays/countries/isle_of_man.py b/holidays/countries/isle_of_man.py index 26acbd874..30377dd6f 100644 --- a/holidays/countries/isle_of_man.py +++ b/holidays/countries/isle_of_man.py @@ -10,8 +10,8 @@ # License: MIT (see LICENSE file) from datetime import date -from dateutil.relativedelta import relativedelta as rd from dateutil.relativedelta import FR +from dateutil.relativedelta import relativedelta as rd from holidays.constants import JUN, JUL diff --git a/holidays/countries/israel.py b/holidays/countries/israel.py index 54f7bbe0b..7da13450c 100644 --- a/holidays/countries/israel.py +++ b/holidays/countries/israel.py @@ -16,8 +16,8 @@ from convertdate.holidays import hanukkah, lag_baomer, passover, purim from convertdate.holidays import rosh_hashanah, shavuot, sukkot, yom_kippur from dateutil.relativedelta import relativedelta as rd -from dateutil.relativedelta import WE, TH, SA +from holidays.constants import WED, THU, SAT from holidays.holiday_base import HolidayBase @@ -54,9 +54,9 @@ def _populate(self, year): observed_delta = 0 if self.observed: day_in_week = memorial_day_dt.weekday() - if day_in_week in {WE.weekday, TH.weekday}: + if day_in_week in {WED, THU}: observed_delta = -(day_in_week - 1) - elif 2004 <= year and day_in_week == SA.weekday: + elif 2004 <= year and day_in_week == SAT: observed_delta = 1 if observed_delta != 0: diff --git a/holidays/countries/jamaica.py b/holidays/countries/jamaica.py index 64b61a2e1..20ada9d50 100644 --- a/holidays/countries/jamaica.py +++ b/holidays/countries/jamaica.py @@ -12,10 +12,10 @@ from datetime import date from dateutil.easter import easter -from dateutil.relativedelta import relativedelta as rd from dateutil.relativedelta import MO, SU +from dateutil.relativedelta import relativedelta as rd -from holidays.constants import JAN, FEB, MAY, JUN, AUG, OCT, DEC +from holidays.constants import JAN, FEB, MAY, JUN, AUG, OCT, DEC, SUN from holidays.holiday_base import HolidayBase @@ -32,7 +32,7 @@ def _populate(self, year): # New Year's Day name = "New Year's Day" _date = date(year, JAN, 1) - if self.observed and _date.weekday() == SU.weekday: + if self.observed and _date.weekday() == SUN: self[_date + rd(weekday=MO(+1))] = name + " (Observed)" else: self[_date] = name @@ -46,7 +46,7 @@ def _populate(self, year): # Labour Day name = "Labour Day" _date = date(year, MAY, 23) - if self.observed and _date.weekday() == SU.weekday: + if self.observed and _date.weekday() == SUN: self[_date + rd(weekday=MO)] = name + " (Observed)" else: self[_date] = name @@ -57,7 +57,7 @@ def _populate(self, year): # Emancipation Day name = "Emancipation Day" _date = date(year, AUG, 1) - if self.observed and _date.weekday() == SU.weekday: + if self.observed and _date.weekday() == SUN: self[_date + rd(weekday=MO)] = name + " (Observed)" else: self[_date] = name diff --git a/holidays/countries/japan.py b/holidays/countries/japan.py index 1ce23d8f2..665013455 100644 --- a/holidays/countries/japan.py +++ b/holidays/countries/japan.py @@ -11,8 +11,8 @@ from datetime import date -from dateutil.relativedelta import relativedelta as rd from dateutil.relativedelta import MO +from dateutil.relativedelta import relativedelta as rd from holidays.constants import JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP from holidays.constants import OCT, NOV, DEC diff --git a/holidays/countries/kenya.py b/holidays/countries/kenya.py index b90dff368..b825235b1 100644 --- a/holidays/countries/kenya.py +++ b/holidays/countries/kenya.py @@ -13,9 +13,8 @@ from dateutil.easter import easter from dateutil.relativedelta import relativedelta as rd -from dateutil.relativedelta import SU -from holidays.constants import JAN, MAY, JUN, OCT, DEC +from holidays.constants import JAN, MAY, JUN, OCT, DEC, SUN from holidays.holiday_base import HolidayBase @@ -41,7 +40,7 @@ def _populate(self, year): self[date(year, DEC, 25)] = "Christmas Day" self[date(year, DEC, 26)] = "Utamaduni Day" for k, v in list(self.items()): - if self.observed and k.weekday() == SU.weekday: + if self.observed and k.weekday() == SUN: self[k + rd(days=1)] = v + " (Observed)" easter_date = easter(year) diff --git a/holidays/countries/lithuania.py b/holidays/countries/lithuania.py index f53ce1b6d..3eb67e7b4 100644 --- a/holidays/countries/lithuania.py +++ b/holidays/countries/lithuania.py @@ -12,8 +12,8 @@ from datetime import date from dateutil.easter import easter -from dateutil.relativedelta import relativedelta as rd from dateutil.relativedelta import SU +from dateutil.relativedelta import relativedelta as rd from holidays.holiday_base import HolidayBase diff --git a/holidays/countries/madagascar.py b/holidays/countries/madagascar.py index 5ab47e550..aaf5836e7 100644 --- a/holidays/countries/madagascar.py +++ b/holidays/countries/madagascar.py @@ -12,8 +12,8 @@ from datetime import date from dateutil.easter import easter -from dateutil.relativedelta import relativedelta as rd from dateutil.relativedelta import SU +from dateutil.relativedelta import relativedelta as rd from holidays.holiday_base import HolidayBase diff --git a/holidays/countries/malawi.py b/holidays/countries/malawi.py index f335a5901..bfff651ed 100644 --- a/holidays/countries/malawi.py +++ b/holidays/countries/malawi.py @@ -13,9 +13,8 @@ from dateutil.easter import easter from dateutil.relativedelta import relativedelta as rd -from dateutil.relativedelta import SA, SU -from holidays.constants import JAN, MAR, MAY, JUL, OCT, DEC +from holidays.constants import JAN, MAR, MAY, JUL, OCT, DEC, SAT, SUN from holidays.holiday_base import HolidayBase @@ -49,9 +48,9 @@ def _populate(self, year): for k, v in list(self.items()): if self.observed and year > 1994: - if k.weekday() == SU.weekday: + if k.weekday() == SUN: self[k + rd(days=1)] = v + " (Observed)" - elif k.weekday() == SA.weekday: + elif k.weekday() == SAT: self[k + rd(days=2)] = v + " (Observed)" diff --git a/holidays/countries/malaysia.py b/holidays/countries/malaysia.py index e84946c83..2a3150261 100644 --- a/holidays/countries/malaysia.py +++ b/holidays/countries/malaysia.py @@ -13,26 +13,11 @@ from typing import Iterable, Optional, Union from dateutil.easter import easter +from dateutil.relativedelta import FR, MO, SA, SU from dateutil.relativedelta import relativedelta as rd -from dateutil.relativedelta import MO, FR, SA, SU - -from holidays.constants import ( - FRI, - SAT, - SUN, - JAN, - FEB, - MAR, - APR, - MAY, - JUN, - JUL, - AUG, - SEP, - OCT, - NOV, - DEC, -) + +from holidays.constants import JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP +from holidays.constants import OCT, NOV, DEC, FRI, SAT, SUN from holidays.holiday_base import HolidayBase from holidays.utils import _ChineseLuniSolar, _islamic_to_gre diff --git a/holidays/countries/mexico.py b/holidays/countries/mexico.py index 90568fcc1..0bd4c1327 100644 --- a/holidays/countries/mexico.py +++ b/holidays/countries/mexico.py @@ -11,10 +11,10 @@ from datetime import date +from dateutil.relativedelta import MO from dateutil.relativedelta import relativedelta as rd -from dateutil.relativedelta import MO, FR, SA, SU -from holidays.constants import JAN, FEB, MAR, MAY, SEP, NOV, DEC +from holidays.constants import FRI, SAT, SUN, JAN, FEB, MAR, MAY, SEP, NOV, DEC from holidays.holiday_base import HolidayBase @@ -24,9 +24,9 @@ class Mexico(HolidayBase): def _add_with_observed(self, holiday: date, name: str): self[holiday] = name - if self.observed and holiday.weekday() == SA.weekday: + if self.observed and holiday.weekday() == SAT: self[holiday + rd(days=-1)] = name + " (Observed)" - elif self.observed and holiday.weekday() == SU.weekday: + elif self.observed and holiday.weekday() == SUN: self[holiday + rd(days=+1)] = name + " (Observed)" def _populate(self, year): @@ -36,11 +36,11 @@ def _populate(self, year): name = "Año Nuevo [New Year's Day]" dt = date(year, JAN, 1) self[dt] = name - if self.observed and dt.weekday() == SU.weekday: + if self.observed and dt.weekday() == SUN: self[dt + rd(days=+1)] = name + " (Observed)" # The next year's observed New Year's Day can be in this year # when it falls on a Friday (Jan 1st is a Saturday) - if self.observed and date(year, DEC, 31).weekday() == FR.weekday: + if self.observed and date(year, DEC, 31).weekday() == FRI: self[date(year, DEC, 31)] = name + " (Observed)" # Constitution Day diff --git a/holidays/countries/moldova.py b/holidays/countries/moldova.py index 8b9d3b84f..cd4f2a3f9 100644 --- a/holidays/countries/moldova.py +++ b/holidays/countries/moldova.py @@ -11,7 +11,7 @@ from datetime import date -from dateutil.easter import easter, EASTER_ORTHODOX +from dateutil.easter import EASTER_ORTHODOX, easter from dateutil.relativedelta import relativedelta as rd from holidays.constants import JAN, MAR, MAY, JUN, AUG, OCT, DEC diff --git a/holidays/countries/mozambique.py b/holidays/countries/mozambique.py index de9fd4625..b9d61ec87 100644 --- a/holidays/countries/mozambique.py +++ b/holidays/countries/mozambique.py @@ -13,9 +13,8 @@ from dateutil.easter import easter from dateutil.relativedelta import relativedelta as rd -from dateutil.relativedelta import SU -from holidays.constants import FEB, APR, MAY, JUN, SEP, OCT, DEC +from holidays.constants import FEB, APR, MAY, JUN, SEP, OCT, DEC, SUN from holidays.holiday_base import HolidayBase @@ -47,7 +46,7 @@ def _populate(self, year): # it rolls over to the following Monday for k, v in list(self.items()): if self.observed: - if k.weekday() == SU.weekday: + if k.weekday() == SUN: self[k + rd(days=1)] = v + " (PONTE)" diff --git a/holidays/countries/namibia.py b/holidays/countries/namibia.py index a2b85ae5d..89d35ce6e 100644 --- a/holidays/countries/namibia.py +++ b/holidays/countries/namibia.py @@ -13,9 +13,8 @@ from dateutil.easter import easter from dateutil.relativedelta import relativedelta as rd -from dateutil.relativedelta import SU -from holidays.constants import JAN, MAR, MAY, AUG, SEP, DEC +from holidays.constants import JAN, MAR, MAY, AUG, SEP, DEC, SUN from holidays.holiday_base import HolidayBase @@ -70,11 +69,7 @@ def _populate(self, year): # a public holiday. for k, v in list(self.items()): - if ( - self.observed - and k.weekday() == SU.weekday - and k.year == year - ): + if self.observed and k.weekday() == SUN and k.year == year: self[k + rd(days=1)] = v + " (Observed)" diff --git a/holidays/countries/netherlands.py b/holidays/countries/netherlands.py index 801fd16cc..a0c502745 100644 --- a/holidays/countries/netherlands.py +++ b/holidays/countries/netherlands.py @@ -13,9 +13,8 @@ from dateutil.easter import easter from dateutil.relativedelta import relativedelta as rd -from dateutil.relativedelta import SU -from holidays.constants import JAN, APR, MAY, AUG, DEC +from holidays.constants import JAN, APR, MAY, AUG, DEC, SUN from holidays.holiday_base import HolidayBase @@ -65,7 +64,7 @@ def _populate(self, year): # Kingsday if year >= 2014: kings_day = date(year, APR, 27) - if kings_day.weekday() == SU.weekday: + if kings_day.weekday() == SUN: kings_day = kings_day - rd(days=1) self[kings_day] = "Koningsdag" @@ -76,7 +75,7 @@ def _populate(self, year): if year <= 1948: queens_day = date(year, AUG, 31) - if queens_day.weekday() == SU.weekday: + if queens_day.weekday() == SUN: if year < 1980: queens_day = queens_day + rd(days=1) else: diff --git a/holidays/countries/new_zealand.py b/holidays/countries/new_zealand.py index a87d4b7df..1e7f7e394 100644 --- a/holidays/countries/new_zealand.py +++ b/holidays/countries/new_zealand.py @@ -12,10 +12,11 @@ from datetime import date from dateutil.easter import easter +from dateutil.relativedelta import MO, TU, WE, FR from dateutil.relativedelta import relativedelta as rd -from dateutil.relativedelta import MO, TU, WE, TH, FR -from holidays.constants import JAN, FEB, MAR, APR, JUN, JUL, SEP, OCT, NOV, DEC +from holidays.constants import JAN, FEB, MAR, APR, JUN, JUL, SEP, OCT, NOV +from holidays.constants import DEC, TUE, WED, THU from holidays.holiday_base import HolidayBase @@ -228,7 +229,7 @@ def _populate(self, year): else: name = "Auckland Anniversary Day" dt = date(year, JAN, 29) - if dt.weekday() in {TU.weekday, WE.weekday, TH.weekday}: + if dt.weekday() in {TUE, WED, THU}: self[dt + rd(weekday=MO(-1))] = name else: self[dt + rd(weekday=MO)] = name @@ -245,7 +246,7 @@ def _populate(self, year): elif self.subdiv in {"WGN", "Wellington"}: name = "Wellington Anniversary Day" jan22 = date(year, JAN, 22) - if jan22.weekday() in {TU.weekday, WE.weekday, TH.weekday}: + if jan22.weekday() in {TUE, WED, THU}: self[jan22 + rd(weekday=MO(-1))] = name else: self[jan22 + rd(weekday=MO)] = name @@ -258,7 +259,7 @@ def _populate(self, year): elif self.subdiv in {"Nelson", "NSN"}: name = "Nelson Anniversary Day" feb1 = date(year, FEB, 1) - if feb1.weekday() in {TU.weekday, WE.weekday, TH.weekday}: + if feb1.weekday() in {TUE, WED, THU}: self[feb1 + rd(weekday=MO(-1))] = name else: self[feb1 + rd(weekday=MO)] = name @@ -279,7 +280,7 @@ def _populate(self, year): # Observance varies?!?! if year == 2005: # special case?!?! self[date(year, DEC, 5)] = name - elif dec1.weekday() in {TU.weekday, WE.weekday, TH.weekday}: + elif dec1.weekday() in {TUE, WED, THU}: self[dec1 + rd(weekday=MO(-1))] = name else: self[dec1 + rd(weekday=MO)] = name @@ -288,7 +289,7 @@ def _populate(self, year): name = "Otago Anniversary Day" mar23 = date(year, MAR, 23) # there is no easily determined single day of local observance?!?! - if mar23.weekday() in {TU.weekday, WE.weekday, TH.weekday}: + if mar23.weekday() in {TUE, WED, THU}: dt = mar23 + rd(weekday=MO(-1)) else: dt = mar23 + rd(weekday=MO) @@ -302,7 +303,7 @@ def _populate(self, year): if year > 2011: self[easter_date + rd(days=+2)] = name else: - if jan17.weekday() in {TU.weekday, WE.weekday, TH.weekday}: + if jan17.weekday() in {TUE, WED, THU}: self[jan17 + rd(weekday=MO(-1))] = name else: self[jan17 + rd(weekday=MO)] = name @@ -310,7 +311,7 @@ def _populate(self, year): elif self.subdiv in {"CIT", "Chatham Islands"}: name = "Chatham Islands Anniversary Day" nov30 = date(year, NOV, 30) - if nov30.weekday() in {TU.weekday, WE.weekday, TH.weekday}: + if nov30.weekday() in {TUE, WED, THU}: self[nov30 + rd(weekday=MO(-1))] = name else: self[nov30 + rd(weekday=MO)] = name diff --git a/holidays/countries/nigeria.py b/holidays/countries/nigeria.py index 7985e5088..85939ac99 100644 --- a/holidays/countries/nigeria.py +++ b/holidays/countries/nigeria.py @@ -13,9 +13,8 @@ from dateutil.easter import easter from dateutil.relativedelta import relativedelta as rd -from dateutil.relativedelta import SA -from holidays.constants import JAN, MAY, JUN, OCT, DEC +from holidays.constants import JAN, MAY, JUN, OCT, DEC, SAT from holidays.holiday_base import HolidayBase from holidays.utils import _islamic_to_gre @@ -95,7 +94,7 @@ def _add_holiday(dt: date, hol: str) -> None: if ( self.observed and year > 2015 - and k.weekday() == SA.weekday + and k.weekday() == SAT and k.year == year and v.upper() in {"DEMOCRACY DAY", "WORKER'S DAY"} ): diff --git a/holidays/countries/north_macedonia.py b/holidays/countries/north_macedonia.py index d8e1fffda..748018bab 100644 --- a/holidays/countries/north_macedonia.py +++ b/holidays/countries/north_macedonia.py @@ -11,7 +11,7 @@ from datetime import date -from dateutil.easter import easter, EASTER_ORTHODOX +from dateutil.easter import EASTER_ORTHODOX, easter from dateutil.relativedelta import relativedelta as rd from holidays.constants import JAN, MAY, SEP, AUG, OCT, DEC diff --git a/holidays/countries/norway.py b/holidays/countries/norway.py index 169cfa865..b85fd15e4 100644 --- a/holidays/countries/norway.py +++ b/holidays/countries/norway.py @@ -13,8 +13,8 @@ from dateutil import rrule from dateutil.easter import easter -from dateutil.relativedelta import relativedelta as rd from dateutil.relativedelta import SU +from dateutil.relativedelta import relativedelta as rd from holidays.constants import JAN, MAY, DEC from holidays.holiday_base import HolidayBase diff --git a/holidays/countries/paraguay.py b/holidays/countries/paraguay.py index 1d7e7ecd6..e387d0260 100644 --- a/holidays/countries/paraguay.py +++ b/holidays/countries/paraguay.py @@ -12,10 +12,10 @@ from datetime import date from dateutil.easter import easter +from dateutil.relativedelta import MO from dateutil.relativedelta import relativedelta as rd -from dateutil.relativedelta import MO, WE -from holidays.constants import JAN, MAR, MAY, JUN, AUG, SEP, DEC +from holidays.constants import JAN, MAR, MAY, JUN, AUG, SEP, DEC, WED from holidays.holiday_base import HolidayBase @@ -42,7 +42,7 @@ def _populate(self, year): if not self.observed and self._is_weekend(year, MAR, 1): pass - elif date(year, MAR, 1).weekday() >= WE.weekday: + elif date(year, MAR, 1).weekday() >= WED: self[date(year, MAR, 1) + rd(weekday=MO(+1))] = name else: self[date(year, MAR, 1)] = name @@ -78,7 +78,7 @@ def _populate(self, year): name = "Día de la Paz del Chaco [Peace in Chaco Day]" if not self.observed and self._is_weekend(year, JUN, 12): pass - elif date(year, JUN, 12).weekday() >= WE.weekday: + elif date(year, JUN, 12).weekday() >= WED: self[date(year, JUN, 12) + rd(weekday=MO(+1))] = name else: self[date(year, JUN, 12)] = name diff --git a/holidays/countries/romania.py b/holidays/countries/romania.py index 9058bf495..0ed1804f5 100644 --- a/holidays/countries/romania.py +++ b/holidays/countries/romania.py @@ -11,7 +11,7 @@ from datetime import date -from dateutil.easter import easter, EASTER_ORTHODOX +from dateutil.easter import EASTER_ORTHODOX, easter from dateutil.relativedelta import relativedelta as rd from holidays.constants import JAN, MAY, JUN, AUG, NOV, DEC diff --git a/holidays/countries/saudi_arabia.py b/holidays/countries/saudi_arabia.py index a174b71e1..a07a53aeb 100644 --- a/holidays/countries/saudi_arabia.py +++ b/holidays/countries/saudi_arabia.py @@ -12,10 +12,8 @@ from datetime import date from dateutil.relativedelta import relativedelta as rd -from dateutil.relativedelta import TH, FR -from dateutil.relativedelta import SA as SAT # Conflicts with SA Alpha-2 code. -from holidays.constants import FEB, SEP +from holidays.constants import FEB, SEP, THU, FRI, SAT from holidays.holiday_base import HolidayBase from holidays.utils import _islamic_to_gre @@ -47,9 +45,9 @@ def _populate(self, year): # Weekend used to be THU, FRI before June 28th, 2013 # On that year both Eids were after that date, and foudning # day holiday started at 2022; so what below works, - self.weekend = (TH.weekday, FR.weekday) + self.weekend = (THU, FRI) else: - self.weekend = (FR.weekday, SAT.weekday) + self.weekend = (FRI, SAT) observed_str = " (observed)" diff --git a/holidays/countries/serbia.py b/holidays/countries/serbia.py index 70a9db4f0..2caeea4ce 100644 --- a/holidays/countries/serbia.py +++ b/holidays/countries/serbia.py @@ -11,11 +11,10 @@ from datetime import date -from dateutil.easter import easter, EASTER_ORTHODOX +from dateutil.easter import EASTER_ORTHODOX, easter from dateutil.relativedelta import relativedelta as rd -from dateutil.relativedelta import SU -from holidays.constants import JAN, FEB, MAY, NOV +from holidays.constants import JAN, FEB, MAY, NOV, SUN from holidays.holiday_base import HolidayBase @@ -57,7 +56,7 @@ def _populate(self, year): # Armistice day name = "Дан примирја у Првом светском рату" self[date(year, NOV, 11)] = name - if self.observed and date(year, NOV, 11).weekday() == SU.weekday: + if self.observed and date(year, NOV, 11).weekday() == SUN: self[date(year, NOV, 12)] = name + " (Observed)" # Easter self[easter_date + rd(days=-2)] = "Велики петак" diff --git a/holidays/countries/singapore.py b/holidays/countries/singapore.py index 741524965..f5df66a0f 100644 --- a/holidays/countries/singapore.py +++ b/holidays/countries/singapore.py @@ -14,10 +14,9 @@ from dateutil.easter import easter from dateutil.relativedelta import relativedelta as rd -from dateutil.relativedelta import SU from holidays.constants import JAN, FEB, MAR, APR, MAY, JUN, JUL, SEP, AUG -from holidays.constants import OCT, NOV, DEC +from holidays.constants import OCT, NOV, DEC, SUN from holidays.holiday_base import HolidayBase from holidays.utils import _ChineseLuniSolar, _islamic_to_gre @@ -284,7 +283,7 @@ def _populate(self, year) -> None: # a Sunday, the day next following not being itself a public holiday # is declared a public holiday in Singapore." for (hol_date, hol_name) in list(self.items()): - if hol_date.year == year and hol_date.weekday() == SU.weekday: + if hol_date.year == year and hol_date.weekday() == SUN: self[hol_date] += " [Sunday]" in_lieu_date = hol_date + rd(days=+1) while in_lieu_date in self: diff --git a/holidays/countries/south_africa.py b/holidays/countries/south_africa.py index 8d4d35114..d685177f5 100644 --- a/holidays/countries/south_africa.py +++ b/holidays/countries/south_africa.py @@ -12,11 +12,11 @@ from datetime import date from dateutil.easter import easter +from dateutil.relativedelta import MO, FR from dateutil.relativedelta import relativedelta as rd -from dateutil.relativedelta import MO, FR, SU from holidays.constants import JAN, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT -from holidays.constants import NOV, DEC +from holidays.constants import NOV, DEC, SUN from holidays.holiday_base import HolidayBase @@ -98,7 +98,7 @@ def _populate(self, year): if ( self.observed and year > 1994 - and k.weekday() == SU.weekday + and k.weekday() == SUN and k.year == year ): if not self.get(k + rd(days=1)): diff --git a/holidays/countries/south_korea.py b/holidays/countries/south_korea.py index 9251036c0..1e6d8fa96 100644 --- a/holidays/countries/south_korea.py +++ b/holidays/countries/south_korea.py @@ -15,13 +15,13 @@ from typing import Tuple from dateutil.relativedelta import relativedelta as rd -from dateutil.relativedelta import SA, SU # Installation: pip install korean_lunar_calendar # URL: https://github.com/usingsky/korean_lunar_calendar_py/ from korean_lunar_calendar import KoreanLunarCalendar from holidays.constants import JAN, MAR, APR, MAY, JUN, JUL, AUG, OCT, DEC +from holidays.constants import SAT, SUN from holidays.holiday_base import HolidayBase @@ -261,9 +261,9 @@ def get_next_first_non_holiday( """ start_value = cur - target_weekday = [SU.weekday] + target_weekday = [SUN] if include_sat: - target_weekday.append(SA.weekday) + target_weekday.append(SAT) check_1 = cur.weekday() in target_weekday # Exclude weekends check_2 = ( cur in self and name != self[cur] diff --git a/holidays/countries/spain.py b/holidays/countries/spain.py index 0f92a7b27..24ecd155f 100644 --- a/holidays/countries/spain.py +++ b/holidays/countries/spain.py @@ -13,10 +13,9 @@ from dateutil.easter import easter from dateutil.relativedelta import relativedelta as rd -from dateutil.relativedelta import SU from holidays.constants import JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP -from holidays.constants import OCT, NOV, DEC +from holidays.constants import OCT, NOV, DEC, SUN from holidays.holiday_base import HolidayBase from holidays.utils import _islamic_to_gre @@ -46,7 +45,7 @@ class Spain(HolidayBase): ] def _is_observed(self, date_holiday, name_holiday): - if self.observed and date_holiday.weekday() == SU.weekday: + if self.observed and date_holiday.weekday() == SUN: self[date_holiday + rd(days=+1)] = name_holiday + " (Trasladado)" else: self[date_holiday] = name_holiday diff --git a/holidays/countries/sweden.py b/holidays/countries/sweden.py index 450708216..3f16eca86 100644 --- a/holidays/countries/sweden.py +++ b/holidays/countries/sweden.py @@ -13,8 +13,8 @@ from dateutil import rrule from dateutil.easter import easter -from dateutil.relativedelta import relativedelta as rd from dateutil.relativedelta import FR, SA, SU +from dateutil.relativedelta import relativedelta as rd from holidays.constants import JAN, MAR, MAY, JUN, OCT, DEC from holidays.holiday_base import HolidayBase diff --git a/holidays/countries/switzerland.py b/holidays/countries/switzerland.py index 17961e8b5..cdb84fdc5 100644 --- a/holidays/countries/switzerland.py +++ b/holidays/countries/switzerland.py @@ -12,8 +12,8 @@ from datetime import date from dateutil.easter import easter +from dateutil.relativedelta import MO, SU, TH, FR from dateutil.relativedelta import relativedelta as rd -from dateutil.relativedelta import MO, FR, TH, SU from holidays.constants import JAN, MAR, APR, MAY, JUN, AUG, SEP, NOV, DEC from holidays.holiday_base import HolidayBase diff --git a/holidays/countries/ukraine.py b/holidays/countries/ukraine.py index 1430cefcb..db3784d1d 100644 --- a/holidays/countries/ukraine.py +++ b/holidays/countries/ukraine.py @@ -11,7 +11,7 @@ from datetime import date -from dateutil.easter import easter, EASTER_ORTHODOX +from dateutil.easter import EASTER_ORTHODOX, easter from dateutil.relativedelta import relativedelta as rd from holidays.constants import JAN, APR, MAR, MAY, JUN, JUL, AUG, SEP, OCT diff --git a/holidays/countries/united_arab_emirates.py b/holidays/countries/united_arab_emirates.py index 2800a3329..e79c7c38e 100644 --- a/holidays/countries/united_arab_emirates.py +++ b/holidays/countries/united_arab_emirates.py @@ -12,9 +12,9 @@ from datetime import date from dateutil.relativedelta import relativedelta as rd -from dateutil.relativedelta import FR, SA from holidays.constants import JAN, APR, MAY, JUN, JUL, AUG, SEP, NOV, DEC +from holidays.constants import FRI, SAT from holidays.holiday_base import HolidayBase from holidays.utils import _islamic_to_gre @@ -44,7 +44,7 @@ class UnitedArabEmirates(HolidayBase): # raised that this holiday is missing. hijri-converter requires # Python >= 3.6 country = "AE" - weekend = {FR.weekday, SA.weekday} + weekend = {FRI, SAT} def _populate(self, year): super()._populate(year) diff --git a/holidays/countries/united_kingdom.py b/holidays/countries/united_kingdom.py index 092f96394..cd526df49 100644 --- a/holidays/countries/united_kingdom.py +++ b/holidays/countries/united_kingdom.py @@ -12,10 +12,11 @@ from typing import Any from dateutil.easter import easter -from dateutil.relativedelta import relativedelta as rd from dateutil.relativedelta import MO +from dateutil.relativedelta import relativedelta as rd -from holidays.constants import JAN, MAR, APR, MAY, JUN, JUL, AUG, SEP, NOV, DEC +from holidays.constants import MON, JAN, MAR, APR, MAY, JUN, JUL, AUG, SEP +from holidays.constants import NOV, DEC from holidays.holiday_base import HolidayBase @@ -68,7 +69,7 @@ def _populate(self, year: int) -> None: self[dt] = name if self.observed and self._is_weekend(dt): self[dt + rd(days=+2)] = name + " (Observed)" - elif self.observed and dt.weekday() == MO.weekday: + elif self.observed and dt.weekday() == MON: self[dt + rd(days=+1)] = name + " (Observed)" # St. Patrick's Day diff --git a/holidays/countries/united_states.py b/holidays/countries/united_states.py index e56d36d4d..ba8fb7f00 100644 --- a/holidays/countries/united_states.py +++ b/holidays/countries/united_states.py @@ -12,11 +12,11 @@ from datetime import date from dateutil.easter import easter -from dateutil.relativedelta import MO, TH, TU, WE, FR, SA, SU +from dateutil.relativedelta import MO, TU, TH, FR from dateutil.relativedelta import relativedelta as rd from holidays.constants import JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP -from holidays.constants import OCT, NOV, DEC +from holidays.constants import OCT, NOV, DEC, MON, WED, FRI, SAT, SUN from holidays.holiday_base import HolidayBase @@ -95,11 +95,11 @@ def _populate(self, year): if year > 1870: name = "New Year's Day" self[date(year, JAN, 1)] = name - if self.observed and date(year, JAN, 1).weekday() == SU.weekday: + if self.observed and date(year, JAN, 1).weekday() == SUN: self[date(year, JAN, 1) + rd(days=+1)] = name + " (Observed)" # The following year's observed New Year's Day can be in this year # when it falls on a Friday (Jan 1st is a Saturday). - if self.observed and date(year, DEC, 31).weekday() == FR.weekday: + if self.observed and date(year, DEC, 31).weekday() == FRI: self[date(year, DEC, 31)] = name + " (Observed)" # Epiphany @@ -130,11 +130,11 @@ def _populate(self, year): name = "Inauguration Day" if (year - 1789) % 4 == 0 and year >= 1937: self[date(year, JAN, 20)] = name - if date(year, JAN, 20).weekday() == SU.weekday: + if date(year, JAN, 20).weekday() == SUN: self[date(year, JAN, 21)] = name + " (Observed)" elif (year - 1789) % 4 == 0: self[date(year, MAR, 4)] = name - if date(year, MAR, 4).weekday() == SU.weekday: + if date(year, MAR, 4).weekday() == SUN: self[date(year, MAR, 5)] = name + " (Observed)" # Martin Luther King Jr. Day @@ -163,9 +163,9 @@ def _populate(self, year): self.subdiv in {"CT", "IA", "IL", "NJ", "NY"} and year >= 1971 ) or (self.subdiv == "CA" and 1971 <= year <= 2009): self[date(year, FEB, 12)] = name - if self.observed and date(year, FEB, 12).weekday() == SA.weekday: + if self.observed and date(year, FEB, 12).weekday() == SAT: self[date(year, FEB, 11)] = name + " (Observed)" - elif self.observed and date(year, FEB, 12).weekday() == SU.weekday: + elif self.observed and date(year, FEB, 12).weekday() == SUN: self[date(year, FEB, 13)] = name + " (Observed)" # Susan B. Anthony Day @@ -191,7 +191,7 @@ def _populate(self, year): elif year >= 1879: self[date(year, FEB, 22)] = name elif self.subdiv == "GA": - if date(year, DEC, 24).weekday() != WE.weekday: + if date(year, DEC, 24).weekday() != WED: self[date(year, DEC, 24)] = name else: self[date(year, DEC, 26)] = name @@ -231,16 +231,16 @@ def _populate(self, year): # Emancipation Day if self.subdiv == "PR": self[date(year, MAR, 22)] = "Emancipation Day" - if self.observed and date(year, MAR, 22).weekday() == SU.weekday: + if self.observed and date(year, MAR, 22).weekday() == SUN: self[date(year, MAR, 23)] = "Emancipation Day (Observed)" # Prince Jonah Kuhio Kalanianaole Day if self.subdiv == "HI" and year >= 1949: name = "Prince Jonah Kuhio Kalanianaole Day" self[date(year, MAR, 26)] = name - if self.observed and date(year, MAR, 26).weekday() == SA.weekday: + if self.observed and date(year, MAR, 26).weekday() == SAT: self[date(year, MAR, 25)] = name + " (Observed)" - elif self.observed and date(year, MAR, 26).weekday() == SU.weekday: + elif self.observed and date(year, MAR, 26).weekday() == SUN: self[date(year, MAR, 27)] = name + " (Observed)" # Seward's Day @@ -254,7 +254,7 @@ def _populate(self, year): name = "César Chávez Day" if self.subdiv == "CA" and year >= 1995: self[date(year, MAR, 31)] = name - if self.observed and date(year, MAR, 31).weekday() == SU.weekday: + if self.observed and date(year, MAR, 31).weekday() == SUN: self[date(year, APR, 1)] = name + " (Observed)" elif self.subdiv == "TX" and year >= 2000: self[date(year, MAR, 31)] = name @@ -267,9 +267,9 @@ def _populate(self, year): if self.subdiv == "DC" and year >= 2005: name = "Emancipation Day" self[date(year, APR, 16)] = name - if self.observed and date(year, APR, 16).weekday() == SA.weekday: + if self.observed and date(year, APR, 16).weekday() == SAT: self[date(year, APR, 15)] = name + " (Observed)" - elif self.observed and date(year, APR, 16).weekday() == SU.weekday: + elif self.observed and date(year, APR, 16).weekday() == SUN: self[date(year, APR, 17)] = name + " (Observed)" # Patriots' Day @@ -336,9 +336,9 @@ def _populate(self, year): if self.subdiv == "MO" and year >= 1949: name = "Truman Day" self[date(year, MAY, 8)] = name - if self.observed and date(year, MAY, 8).weekday() == SA.weekday: + if self.observed and date(year, MAY, 8).weekday() == SAT: self[date(year, MAY, 7)] = name + " (Observed)" - elif self.observed and date(year, MAY, 8).weekday() == SU.weekday: + elif self.observed and date(year, MAY, 8).weekday() == SUN: self[date(year, MAY, 10)] = name + " (Observed)" # Memorial Day @@ -351,9 +351,9 @@ def _populate(self, year): if year > 2020: name = "Juneteenth National Independence Day" self[date(year, JUN, 19)] = name - if self.observed and date(year, JUN, 19).weekday() == SA.weekday: + if self.observed and date(year, JUN, 19).weekday() == SAT: self[date(year, JUN, 18)] = name + " (Observed)" - elif self.observed and date(year, JUN, 19).weekday() == SU.weekday: + elif self.observed and date(year, JUN, 19).weekday() == SUN: self[date(year, JUN, 20)] = name + " (Observed)" # Jefferson Davis Birthday @@ -366,9 +366,9 @@ def _populate(self, year): name = "Kamehameha Day" self[date(year, JUN, 11)] = name if self.observed and year >= 2011: - if date(year, JUN, 11).weekday() == SA.weekday: + if date(year, JUN, 11).weekday() == SAT: self[date(year, JUN, 10)] = name + " (Observed)" - elif date(year, JUN, 11).weekday() == SU.weekday: + elif date(year, JUN, 11).weekday() == SUN: self[date(year, JUN, 12)] = name + " (Observed)" # Emancipation Day In Texas if self.subdiv == "TX" and year >= 1980: @@ -378,9 +378,9 @@ def _populate(self, year): name = "West Virginia Day" if self.subdiv == "WV" and year >= 1927: self[date(year, JUN, 20)] = name - if self.observed and date(year, JUN, 20).weekday() == SA.weekday: + if self.observed and date(year, JUN, 20).weekday() == SAT: self[date(year, JUN, 19)] = name + " (Observed)" - elif self.observed and date(year, JUN, 20).weekday() == SU.weekday: + elif self.observed and date(year, JUN, 20).weekday() == SUN: self[date(year, JUN, 21)] = name + " (Observed)" # Emancipation Day in US Virgin Islands @@ -391,9 +391,9 @@ def _populate(self, year): if year > 1870: name = "Independence Day" self[date(year, JUL, 4)] = name - if self.observed and date(year, JUL, 4).weekday() == SA.weekday: + if self.observed and date(year, JUL, 4).weekday() == SAT: self[date(year, JUL, 4) + rd(days=-1)] = name + " (Observed)" - elif self.observed and date(year, JUL, 4).weekday() == SU.weekday: + elif self.observed and date(year, JUL, 4).weekday() == SUN: self[date(year, JUL, 4) + rd(days=+1)] = name + " (Observed)" # Liberation Day (Guam) @@ -404,15 +404,15 @@ def _populate(self, year): if self.subdiv == "UT" and year >= 1849: name = "Pioneer Day" self[date(year, JUL, 24)] = name - if self.observed and date(year, JUL, 24).weekday() == SA.weekday: + if self.observed and date(year, JUL, 24).weekday() == SAT: self[date(year, JUL, 24) + rd(days=-1)] = name + " (Observed)" - elif self.observed and date(year, JUL, 24).weekday() == SU.weekday: + elif self.observed and date(year, JUL, 24).weekday() == SUN: self[date(year, JUL, 24) + rd(days=+1)] = name + " (Observed)" # Constitution Day if self.subdiv == "PR": self[date(year, JUL, 25)] = "Constitution Day" - if self.observed and date(year, JUL, 25).weekday() == SU.weekday: + if self.observed and date(year, JUL, 25).weekday() == SUN: self[date(year, JUL, 26)] = "Constitution Day (Observed)" # Victory Day @@ -427,9 +427,9 @@ def _populate(self, year): if self.subdiv == "VT" and year >= 1778: name = "Bennington Battle Day" self[date(year, AUG, 16)] = name - if self.observed and date(year, AUG, 16).weekday() == SA.weekday: + if self.observed and date(year, AUG, 16).weekday() == SAT: self[date(year, AUG, 15)] = name + " (Observed)" - elif self.observed and date(year, AUG, 16).weekday() == SU.weekday: + elif self.observed and date(year, AUG, 16).weekday() == SUN: self[date(year, AUG, 17)] = name + " (Observed)" # Lyndon Baines Johnson Day @@ -457,9 +457,9 @@ def _populate(self, year): if self.subdiv == "AK" and year >= 1867: name = "Alaska Day" self[date(year, OCT, 18)] = name - if self.observed and date(year, OCT, 18).weekday() == SA.weekday: + if self.observed and date(year, OCT, 18).weekday() == SAT: self[date(year, OCT, 18) + rd(days=-1)] = name + " (Observed)" - elif self.observed and date(year, OCT, 18).weekday() == SU.weekday: + elif self.observed and date(year, OCT, 18).weekday() == SUN: self[date(year, OCT, 18) + rd(days=+1)] = name + " (Observed)" # Nevada Day @@ -468,9 +468,9 @@ def _populate(self, year): if year >= 2000: dt += rd(weekday=FR(-1)) self[dt] = "Nevada Day" - if self.observed and dt.weekday() == SA.weekday: + if self.observed and dt.weekday() == SAT: self[dt + rd(days=-1)] = "Nevada Day (Observed)" - elif self.observed and dt.weekday() == SU.weekday: + elif self.observed and dt.weekday() == SUN: self[dt + rd(days=+1)] = "Nevada Day (Observed)" # Liberty Day @@ -500,15 +500,15 @@ def _populate(self, year): self[date(year, OCT, 1) + rd(weekday=MO(+4))] = name elif year >= 1938: self[date(year, NOV, 11)] = name - if self.observed and date(year, NOV, 11).weekday() == SA.weekday: + if self.observed and date(year, NOV, 11).weekday() == SAT: self[date(year, NOV, 11) + rd(days=-1)] = name + " (Observed)" - elif self.observed and date(year, NOV, 11).weekday() == SU.weekday: + elif self.observed and date(year, NOV, 11).weekday() == SUN: self[date(year, NOV, 11) + rd(days=+1)] = name + " (Observed)" # Discovery Day if self.subdiv == "PR": self[date(year, NOV, 19)] = "Discovery Day" - if self.observed and date(year, NOV, 19).weekday() == SU.weekday: + if self.observed and date(year, NOV, 19).weekday() == SUN: self[date(year, NOV, 20)] = "Discovery Day (Observed)" # Thanksgiving @@ -568,7 +568,7 @@ def _populate(self, year): self[date(year, DEC, 24)] = name name = name + " (Observed)" # If on Friday, observed on Thursday - if self.observed and date(year, DEC, 24).weekday() == FR.weekday: + if self.observed and date(year, DEC, 24).weekday() == FRI: self[date(year, DEC, 24) + rd(days=-1)] = name # If on Saturday or Sunday, observed on Friday elif self.observed and self._is_weekend(year, DEC, 24): @@ -578,9 +578,9 @@ def _populate(self, year): if year > 1870: name = "Christmas Day" self[date(year, DEC, 25)] = "Christmas Day" - if self.observed and date(year, DEC, 25).weekday() == SA.weekday: + if self.observed and date(year, DEC, 25).weekday() == SAT: self[date(year, DEC, 25) + rd(days=-1)] = name + " (Observed)" - elif self.observed and date(year, DEC, 25).weekday() == SU.weekday: + elif self.observed and date(year, DEC, 25).weekday() == SUN: self[date(year, DEC, 25) + rd(days=+1)] = name + " (Observed)" # Day After Christmas @@ -592,7 +592,7 @@ def _populate(self, year): if self.observed and self._is_weekend(year, DEC, 26): self[date(year, DEC, 26) + rd(weekday=MO)] = name # If on Monday, observed on Tuesday - elif self.observed and date(year, DEC, 26).weekday() == MO.weekday: + elif self.observed and date(year, DEC, 26).weekday() == MON: self[date(year, DEC, 26) + rd(days=+1)] = name elif self.subdiv == "TX" and year >= 1981: self[date(year, DEC, 26)] = "Day After Christmas" @@ -605,7 +605,7 @@ def _populate(self, year): ): name = "New Year's Eve" self[date(year, DEC, 31)] = name - if self.observed and date(year, DEC, 31).weekday() == SA.weekday: + if self.observed and date(year, DEC, 31).weekday() == SAT: self[date(year, DEC, 30)] = name + " (Observed)" diff --git a/holidays/countries/uruguay.py b/holidays/countries/uruguay.py index 491968a6d..8b2dee8a7 100644 --- a/holidays/countries/uruguay.py +++ b/holidays/countries/uruguay.py @@ -12,10 +12,11 @@ from datetime import date from dateutil.easter import easter -from dateutil.relativedelta import MO, TU, WE, TH, FR +from dateutil.relativedelta import MO from dateutil.relativedelta import relativedelta as rd from holidays.constants import JAN, APR, MAY, JUN, JUL, AUG, OCT, NOV, DEC +from holidays.constants import TUE, WED, THU, FRI from holidays.holiday_base import HolidayBase @@ -103,9 +104,9 @@ def _populate(self, year): ) for dt, name in holiday_pairs: - if dt.weekday() in {TU.weekday, WE.weekday}: + if dt.weekday() in {TUE, WED}: self[dt + rd(weekday=MO(-1))] = name - elif dt.weekday() in {TH.weekday, FR.weekday}: + elif dt.weekday() in {THU, FRI}: self[dt + rd(weekday=MO(+1))] = name else: self[dt] = name diff --git a/holidays/countries/zambia.py b/holidays/countries/zambia.py index e7329e05f..88240170f 100644 --- a/holidays/countries/zambia.py +++ b/holidays/countries/zambia.py @@ -12,10 +12,10 @@ from datetime import date from dateutil.easter import easter +from dateutil.relativedelta import MO from dateutil.relativedelta import relativedelta as rd -from dateutil.relativedelta import MO, SU -from holidays.constants import JAN, MAR, APR, MAY, JUL, AUG, SEP, OCT, DEC +from holidays.constants import JAN, MAR, APR, MAY, JUL, AUG, SEP, OCT, DEC, SUN from holidays.holiday_base import HolidayBase @@ -97,7 +97,7 @@ def _populate(self, year): # it rolls over to the following Monday if self.observed: for k, v in list(self.items()): - if k.year == year and k.weekday() == SU.weekday: + if k.year == year and k.weekday() == SUN: self[k + rd(days=1)] = v + " (Observed)" diff --git a/holidays/countries/zimbabwe.py b/holidays/countries/zimbabwe.py index 4cee95749..803fdc168 100644 --- a/holidays/countries/zimbabwe.py +++ b/holidays/countries/zimbabwe.py @@ -12,10 +12,10 @@ from datetime import date from dateutil.easter import easter +from dateutil.relativedelta import MO from dateutil.relativedelta import relativedelta as rd -from dateutil.relativedelta import MO, SU -from holidays.constants import JAN, FEB, APR, MAY, AUG, DEC +from holidays.constants import JAN, FEB, APR, MAY, AUG, DEC, SUN from holidays.holiday_base import HolidayBase @@ -62,11 +62,7 @@ def _populate(self, year): self[date(year, DEC, 26)] = "Boxing Day" for k, v in list(self.items()): - if ( - self.observed - and k.weekday() == SU.weekday - and k.year == year - ): + if self.observed and k.weekday() == SUN and k.year == year: add_days = 1 while self.get(k + rd(days=add_days)) is not None: add_days += 1 diff --git a/holidays/financial/ny_stock_exchange.py b/holidays/financial/ny_stock_exchange.py index bc0ae88d7..d681acbc0 100644 --- a/holidays/financial/ny_stock_exchange.py +++ b/holidays/financial/ny_stock_exchange.py @@ -12,11 +12,11 @@ from datetime import date, timedelta from dateutil.easter import easter -from dateutil.relativedelta import MO, TU, WE, TH, FR +from dateutil.relativedelta import MO, TU, TH, FR from dateutil.relativedelta import relativedelta as rd from holidays.constants import JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP -from holidays.constants import OCT, NOV, DEC +from holidays.constants import OCT, NOV, DEC, WED, FRI from holidays.holiday_base import HolidayBase @@ -62,7 +62,7 @@ def _populate(self, year): # As per Rule 7.2.: check if next year's NYD falls on Saturday and # needs to be observed on Friday (Dec 31 of previous year). dec_31 = date(year, DEC, 31) - if dec_31.weekday() == FR.weekday: + if dec_31.weekday() == FRI: self._set_observed_date(dec_31 + rd(days=+1), "New Year's Day") # MLK - observed 1998 - 3rd Monday of Jan @@ -243,7 +243,7 @@ def _populate(self, year): begin + timedelta(days=n) for n in range((end - begin).days + 1) ): - if d.weekday() != WE.weekday: # Wednesday special holiday + if d.weekday() != WED: # Wednesday special holiday continue self[d] = "Paper Crisis" elif year == 1969: diff --git a/holidays/holiday_base.py b/holidays/holiday_base.py index 54b156695..08f3330d4 100644 --- a/holidays/holiday_base.py +++ b/holidays/holiday_base.py @@ -17,7 +17,8 @@ from typing import Union, cast from dateutil.parser import parse -from dateutil.relativedelta import SA, SU + +from holidays.constants import SAT, SUN DateLike = Union[date, datetime, str, float, int] @@ -197,7 +198,7 @@ def _populate(self, year): _deprecated_subdivisions: List[str] = [] """Other subdivisions whose names are deprecated or aliases of the official ones.""" - weekend: Set[int] = {SA.weekday, SU.weekday} + weekend: Set[int] = {SAT, SUN} """Country weekend days.""" def __init__( diff --git a/pyproject.toml b/pyproject.toml index 9a8913c78..473b9446b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -49,6 +49,7 @@ exclude_lines = [ ] [tool.isort] +known_first_party = ["holidays", "test"] line_length = 79 multi_line_output = 9 no_inline_sort = true diff --git a/test/common.py b/test/common.py index 20d021d0e..ad6e6a916 100644 --- a/test/common.py +++ b/test/common.py @@ -13,9 +13,9 @@ import unittest from dateutil.parser import parse -from dateutil.relativedelta import SU from holidays import HolidayBase +from holidays.constants import SUN class TestCase(unittest.TestCase): @@ -133,18 +133,14 @@ def assertSundays(self, cls): holidays, "1989-12-31", ) - self.assertEqual( - 53, len([s for s in holidays if s.weekday() == SU.weekday]) - ) + self.assertEqual(53, len([s for s in holidays if s.weekday() == SUN])) holidays = cls(years=2032, include_sundays=True) self.assertHoliday( holidays, "2032-01-04", ) - self.assertEqual( - 52, len([s for s in holidays if s.weekday() == SU.weekday]) - ) + self.assertEqual(52, len([s for s in holidays if s.weekday() == SUN])) self.assertNoHolidays(cls(include_sundays=True)) @@ -154,7 +150,7 @@ def assertSundays(self, cls): "2017-02-12", "2032-02-29", ): - self.assertEqual(parse(sunday).weekday(), SU.weekday) + self.assertEqual(parse(sunday).weekday(), SUN) self.assertHoliday(holidays, sunday) for non_sunday in ( @@ -168,5 +164,5 @@ def assertSundays(self, cls): "2017-02-09", "2017-02-10", ): - self.assertNotEqual(parse(non_sunday).weekday(), SU.weekday) + self.assertNotEqual(parse(non_sunday).weekday(), SUN) self.assertNoHoliday(holidays, non_sunday) diff --git a/test/countries/test_angola.py b/test/countries/test_angola.py index 489cbbbc9..e466f576b 100644 --- a/test/countries/test_angola.py +++ b/test/countries/test_angola.py @@ -9,10 +9,9 @@ # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) +from holidays.countries.angola import AGO, AO, Angola from test.common import TestCase -from holidays.countries.angola import Angola, AO, AGO - class TestAngola(TestCase): def setUp(self): diff --git a/test/countries/test_argentina.py b/test/countries/test_argentina.py index b715cbcf9..ea93271d9 100644 --- a/test/countries/test_argentina.py +++ b/test/countries/test_argentina.py @@ -10,12 +10,12 @@ # License: MIT (see LICENSE file) from datetime import date -from test.common import TestCase from dateutil.relativedelta import relativedelta from holidays.constants import MAY, JUN, JUL, AUG, OCT -from holidays.countries.argentina import Argentina, AR, ARG +from holidays.countries.argentina import AR, ARG, Argentina +from test.common import TestCase class TestArgentina(TestCase): diff --git a/test/countries/test_honduras.py b/test/countries/test_honduras.py index d8a8cb5c6..2e1d41fbb 100644 --- a/test/countries/test_honduras.py +++ b/test/countries/test_honduras.py @@ -9,10 +9,9 @@ # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) +from holidays.countries.honduras import HN, HND, Honduras from test.common import TestCase -from holidays.countries.honduras import Honduras, HN, HND - class TestHonduras(TestCase): def setUp(self): diff --git a/test/countries/test_norway.py b/test/countries/test_norway.py index f9dc66f73..2d6e308a8 100644 --- a/test/countries/test_norway.py +++ b/test/countries/test_norway.py @@ -9,12 +9,11 @@ # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) -from test.common import SundayHolidays - from dateutil.parser import parse -from dateutil.relativedelta import MO, SU -from holidays.countries.norway import Norway, NO, NOR +from holidays.constants import MON, SUN +from holidays.countries.norway import NO, NOR, Norway +from test.common import SundayHolidays class TestNorway(SundayHolidays): @@ -82,10 +81,10 @@ def test_pentecost(self): for day1, day2 in pentecost_days: self.assertHoliday(day1) - self.assertEqual(parse(day1).weekday(), SU.weekday) + self.assertEqual(parse(day1).weekday(), SUN) self.assertHoliday(day2) - self.assertEqual(parse(day2).weekday(), MO.weekday) + self.assertEqual(parse(day2).weekday(), MON) def test_christmas(self): self.assertHoliday( diff --git a/test/countries/test_sweden.py b/test/countries/test_sweden.py index 1bb28502c..a07608eb5 100644 --- a/test/countries/test_sweden.py +++ b/test/countries/test_sweden.py @@ -9,10 +9,9 @@ # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) +from holidays.countries.sweden import SE, SWE, Sweden from test.common import SundayHolidays -from holidays.countries.sweden import Sweden, SE, SWE - class TestSweden(SundayHolidays): def setUp(self): diff --git a/test/countries/test_united_states.py b/test/countries/test_united_states.py index 7d2c31779..1ef63c974 100644 --- a/test/countries/test_united_states.py +++ b/test/countries/test_united_states.py @@ -12,9 +12,10 @@ import unittest from datetime import date -from dateutil.relativedelta import SA, SU, relativedelta +from dateutil.relativedelta import relativedelta import holidays +from holidays.constants import SAT, SUN class TestUS(unittest.TestCase): @@ -175,7 +176,7 @@ def test_lincolns_birthday(self): self.assertIn(date(year, 2, 12), ia_holidays) self.assertIn(date(year, 2, 12), nj_holidays) self.assertIn(date(year, 2, 12), ny_holidays) - if date(year, 2, 12).weekday() == SA.weekday: + if date(year, 2, 12).weekday() == SAT: self.assertNotIn(date(year, 2, 11), self.holidays) self.assertIn(date(year, 2, 11), ca_holidays) self.assertIn(date(year, 2, 11), ct_holidays) @@ -190,7 +191,7 @@ def test_lincolns_birthday(self): self.assertNotIn(date(year, 2, 11), ia_holidays) self.assertNotIn(date(year, 2, 11), nj_holidays) self.assertNotIn(date(year, 2, 11), ny_holidays) - if date(year, 2, 12).weekday() == SU.weekday: + if date(year, 2, 12).weekday() == SUN: self.assertNotIn(date(year, 2, 13), self.holidays) self.assertIn(date(year, 2, 13), ca_holidays) self.assertIn(date(year, 2, 13), ct_holidays) @@ -213,7 +214,7 @@ def test_lincolns_birthday(self): self.assertIn(date(year, 2, 12), ia_holidays) self.assertIn(date(year, 2, 12), nj_holidays) self.assertIn(date(year, 2, 12), ny_holidays) - if date(year, 2, 12).weekday() == SA.weekday: + if date(year, 2, 12).weekday() == SAT: self.assertNotIn(date(year, 2, 11), self.holidays) self.assertNotIn(date(year, 2, 11), ca_holidays) self.assertIn(date(year, 2, 11), ct_holidays) @@ -228,7 +229,7 @@ def test_lincolns_birthday(self): self.assertNotIn(date(year, 2, 11), ia_holidays) self.assertNotIn(date(year, 2, 11), nj_holidays) self.assertNotIn(date(year, 2, 11), ny_holidays) - if date(year, 2, 12).weekday() == SU.weekday: + if date(year, 2, 12).weekday() == SUN: self.assertNotIn(date(year, 2, 13), self.holidays) self.assertNotIn(date(year, 2, 13), ca_holidays) self.assertIn(date(year, 2, 13), ct_holidays) diff --git a/test/financial/test_ny_stock_exchange.py b/test/financial/test_ny_stock_exchange.py index d97ebc42a..405fe1249 100644 --- a/test/financial/test_ny_stock_exchange.py +++ b/test/financial/test_ny_stock_exchange.py @@ -12,11 +12,12 @@ import unittest from datetime import date, timedelta -from dateutil.relativedelta import relativedelta, WE, SA, SU +from dateutil.relativedelta import WE +from dateutil.relativedelta import relativedelta as rd import holidays from holidays.constants import APR, AUG, DEC, FEB, JAN, JUL, JUN, MAR, MAY -from holidays.constants import NOV, OCT, SEP +from holidays.constants import NOV, OCT, SEP, SAT, SUN class TestNewYorkStockExchange(unittest.TestCase): @@ -39,9 +40,9 @@ def test_new_years(self): date(2027, DEC, 31), ]: self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+7), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=+7), self.holidays) def test_mlk(self): for dt in [ @@ -55,10 +56,10 @@ def test_mlk(self): date(2022, JAN, 17), ]: self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+7), self.holidays) - self.assertNotIn(dt + relativedelta(days=-7), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=+7), self.holidays) + self.assertNotIn(dt + rd(days=-7), self.holidays) for dt in [ date(1997, JAN, 20), @@ -74,10 +75,10 @@ def test_lincoln(self): date(1968, FEB, 12), ]: self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+7), self.holidays) - self.assertNotIn(dt + relativedelta(days=-7), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=+7), self.holidays) + self.assertNotIn(dt + rd(days=-7), self.holidays) for dt in [ date(1954, FEB, 12), @@ -109,10 +110,10 @@ def test_washington(self): date(2022, FEB, 21), ]: self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+7), self.holidays) - self.assertNotIn(dt + relativedelta(days=-7), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=+7), self.holidays) + self.assertNotIn(dt + rd(days=-7), self.holidays) def test_good_friday(self): for dt in [ @@ -129,10 +130,10 @@ def test_good_friday(self): date(2022, APR, 15), ]: self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+7), self.holidays) - self.assertNotIn(dt + relativedelta(days=-7), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=+7), self.holidays) + self.assertNotIn(dt + rd(days=-7), self.holidays) def test_memday(self): for dt in [ @@ -153,10 +154,10 @@ def test_memday(self): date(2022, MAY, 30), ]: self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+7), self.holidays) - self.assertNotIn(dt + relativedelta(days=-7), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=+7), self.holidays) + self.assertNotIn(dt + rd(days=-7), self.holidays) def test_flagday(self): for dt in [ @@ -168,10 +169,10 @@ def test_flagday(self): date(1953, JUN, 15), ]: self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+7), self.holidays) - self.assertNotIn(dt + relativedelta(days=-7), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=+7), self.holidays) + self.assertNotIn(dt + rd(days=-7), self.holidays) for dt in [ date(1954, JUN, 14), @@ -186,10 +187,10 @@ def test_juneteenth(self): date(2022, JUN, 20), ]: self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+7), self.holidays) - self.assertNotIn(dt + relativedelta(days=-7), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=+7), self.holidays) + self.assertNotIn(dt + rd(days=-7), self.holidays) for dt in [ date(1954, JUN, 18), @@ -213,10 +214,10 @@ def test_laborday(self): date(2022, SEP, 5), ]: self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+7), self.holidays) - self.assertNotIn(dt + relativedelta(days=-7), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=+7), self.holidays) + self.assertNotIn(dt + rd(days=-7), self.holidays) for dt in [ date(1886, SEP, 6), @@ -233,10 +234,10 @@ def test_columbusday(self): date(1953, OCT, 12), ]: self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+7), self.holidays) - self.assertNotIn(dt + relativedelta(days=-7), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=+7), self.holidays) + self.assertNotIn(dt + rd(days=-7), self.holidays) for dt in [ date(1908, OCT, 12), @@ -259,9 +260,9 @@ def test_electionday(self): date(1980, NOV, 4), ]: self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+7), self.holidays) - self.assertNotIn(dt + relativedelta(days=-7), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=+7), self.holidays) + self.assertNotIn(dt + rd(days=-7), self.holidays) for dt in [ date(1969, NOV, 4), @@ -291,10 +292,10 @@ def test_veteransday(self): date(1953, NOV, 11), ]: self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+7), self.holidays) - self.assertNotIn(dt + relativedelta(days=-7), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=+7), self.holidays) + self.assertNotIn(dt + rd(days=-7), self.holidays) for dt in [ date(1917, NOV, 12), @@ -323,10 +324,10 @@ def test_thxgiving(self): date(2022, NOV, 24), ]: self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+7), self.holidays) - self.assertNotIn(dt + relativedelta(days=-7), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=+7), self.holidays) + self.assertNotIn(dt + rd(days=-7), self.holidays) def test_christmas_day(self): for dt in [ @@ -343,9 +344,9 @@ def test_christmas_day(self): date(2022, DEC, 26), ]: self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) - self.assertNotIn(dt + relativedelta(days=-7), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=-7), self.holidays) def test_special_holidays(self): # add to this list as new historical holidays are added @@ -416,7 +417,7 @@ def _make_special_holiday_list(begin, end, days=None, weekends=False): begin + timedelta(days=n) for n in range((end - begin).days + 1) ): - if not weekends and d.weekday() in {SA.weekday, SU.weekday}: + if not weekends and d.weekday() in {SAT, SUN}: continue if days is None or d.isoweekday() in days: _list.append(d) diff --git a/test/test_holiday_base.py b/test/test_holiday_base.py index 600830ce7..3a06ff4f5 100644 --- a/test/test_holiday_base.py +++ b/test/test_holiday_base.py @@ -15,10 +15,11 @@ import warnings from datetime import date, datetime, timedelta -from dateutil.relativedelta import relativedelta, MO, TU, SA, SU +from dateutil.relativedelta import MO +from dateutil.relativedelta import relativedelta as rd import holidays -from holidays.constants import FEB, JAN +from holidays.constants import JAN, FEB, MON, TUE, SAT, SUN class TestBasics(unittest.TestCase): @@ -172,7 +173,7 @@ def test_update(self): def test_is_weekend(self): h = holidays.HolidayBase() - h.weekend = {MO.weekday, TU.weekday} + h.weekend = {MON, TUE} for dt in (date(2022, 10, 3), date(2022, 10, 4)): self.assertTrue(h._is_weekend(dt)) @@ -180,7 +181,7 @@ def test_is_weekend(self): for dt in (date(2022, 10, 3), date(2022, 10, 4)): self.assertFalse(h._is_weekend(dt)) - h.weekend = {SA.weekday, SU.weekday} + h.weekend = {SAT, SUN} for dt in (date(2022, 10, 1), date(2022, 10, 2)): self.assertTrue(h._is_weekend(dt)) @@ -390,7 +391,7 @@ def test_inheritance(self): class NoColumbusHolidays(holidays.US): def _populate(self, year): holidays.US._populate(self, year) - self.pop(date(year, 10, 1) + relativedelta(weekday=MO(+2))) + self.pop(date(year, 10, 1) + rd(weekday=MO(+2))) hdays = NoColumbusHolidays() self.assertIn(date(2014, 10, 13), self.holidays) From f7324db8ffab510112f4af9c27d9c4622531432c Mon Sep 17 00:00:00 2001 From: Arkadii Yakovets Date: Thu, 8 Dec 2022 17:19:18 -0800 Subject: [PATCH 054/138] Remove deprecation warnings. Fix minor issues. --- holidays/constants.py | 14 -------------- holidays/countries/finland.py | 2 +- holidays/countries/hongkong.py | 7 +------ test/financial/test_ny_stock_exchange.py | 4 ++-- test/test_holiday_base.py | 2 +- 5 files changed, 5 insertions(+), 24 deletions(-) diff --git a/holidays/constants.py b/holidays/constants.py index db4319cf9..795cbd306 100644 --- a/holidays/constants.py +++ b/holidays/constants.py @@ -9,21 +9,7 @@ # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) -import warnings - -warnings.warn( - "Weekday constants (MON, TUE, WED, THU, FRI, SAT, SUN) are deprecated " - "in favor of MO, TU, WE, TH, FR, SA, SU objects from " - "dateutil.relativedelta.", - DeprecationWarning, -) MON, TUE, WED, THU, FRI, SAT, SUN = range(7) - - -warnings.warn( - "WEEKEND is deprecated. Use HolidayBase.weekend instead.", - DeprecationWarning, -) WEEKEND = (SAT, SUN) JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC = range(1, 13) diff --git a/holidays/countries/finland.py b/holidays/countries/finland.py index 58dbd170d..0a9a8e650 100644 --- a/holidays/countries/finland.py +++ b/holidays/countries/finland.py @@ -15,7 +15,7 @@ from dateutil.relativedelta import FR, SA from dateutil.relativedelta import relativedelta as rd -from holidays.constants import DEC, JAN, JUN, MAY, OCT +from holidays.constants import JAN, MAY, JUN, OCT, DEC from holidays.holiday_base import HolidayBase diff --git a/holidays/countries/hongkong.py b/holidays/countries/hongkong.py index 73a0300f1..055e66cf8 100644 --- a/holidays/countries/hongkong.py +++ b/holidays/countries/hongkong.py @@ -73,12 +73,7 @@ def _populate(self, year): new_year_date = self.cnls.lunar_n_y_date(year) if self.observed: self[new_year_date] = name - if new_year_date.weekday() in { - MON, - TUE, - WED, - THU, - }: + if new_year_date.weekday() in {MON, TUE, WED, THU}: self[new_year_date] = name self[new_year_date + rd(days=+1)] = second_day_lunar self[new_year_date + rd(days=+2)] = third_day_lunar diff --git a/test/financial/test_ny_stock_exchange.py b/test/financial/test_ny_stock_exchange.py index b7cc08655..f7b382b5a 100644 --- a/test/financial/test_ny_stock_exchange.py +++ b/test/financial/test_ny_stock_exchange.py @@ -16,8 +16,8 @@ from dateutil.relativedelta import relativedelta as rd import holidays -from holidays.constants import APR, AUG, DEC, FEB, JAN, JUL, JUN, MAR, MAY -from holidays.constants import NOV, OCT, SEP, SAT, SUN +from holidays.constants import JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP +from holidays.constants import OCT, NOV, DEC, SAT, SUN class TestNewYorkStockExchange(unittest.TestCase): diff --git a/test/test_holiday_base.py b/test/test_holiday_base.py index 3a06ff4f5..9e8c16526 100644 --- a/test/test_holiday_base.py +++ b/test/test_holiday_base.py @@ -177,7 +177,7 @@ def test_is_weekend(self): for dt in (date(2022, 10, 3), date(2022, 10, 4)): self.assertTrue(h._is_weekend(dt)) - h.weekend = () + h.weekend = {} for dt in (date(2022, 10, 3), date(2022, 10, 4)): self.assertFalse(h._is_weekend(dt)) From 300d4a13cc11c6047014b8e5e40567ac0790df29 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 13 Dec 2022 22:48:31 +0100 Subject: [PATCH 055/138] Bump actions/setup-python from 4.3.0 to 4.3.1 (#831) --- .github/workflows/ci-cd.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml index 65435abd2..8289eda98 100644 --- a/.github/workflows/ci-cd.yml +++ b/.github/workflows/ci-cd.yml @@ -12,7 +12,7 @@ jobs: - name: Check out repo uses: actions/checkout@v3 - name: Set up Python - uses: actions/setup-python@v4.3.0 + uses: actions/setup-python@v4.3.1 - name: Run pre-commit uses: pre-commit/action@v3.0.0 @@ -28,7 +28,7 @@ jobs: steps: - uses: actions/checkout@v3 - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v4.3.0 + uses: actions/setup-python@v4.3.1 with: python-version: ${{ matrix.python-version }} cache: pip @@ -68,7 +68,7 @@ jobs: steps: - uses: actions/checkout@v3 - name: Set up Python 3.9 - uses: actions/setup-python@v4.3.0 + uses: actions/setup-python@v4.3.1 with: python-version: "3.10" - name: Install dependencies From 70fc335cb20815b16d0e846cbff84a64ac4c5660 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 13 Dec 2022 22:55:17 +0100 Subject: [PATCH 056/138] Bump pypa/gh-action-pypi-publish from 1.5.1 to 1.6.4 (#832) Co-authored-by: dr-prodigy <28216945+dr-prodigy@users.noreply.github.com> --- .github/workflows/ci-cd.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml index 8289eda98..014f0921f 100644 --- a/.github/workflows/ci-cd.yml +++ b/.github/workflows/ci-cd.yml @@ -80,7 +80,7 @@ jobs: python setup.py sdist bdist_wheel - name: Publish package - uses: pypa/gh-action-pypi-publish@v1.5.2 + uses: pypa/gh-action-pypi-publish@v1.6.4 with: user: __token__ password: ${{ secrets.pypi_password }} From d3fbe0a77d86dad8c1ada522cd2195772eb400ce Mon Sep 17 00:00:00 2001 From: Pedro Baptista <32106544+Nalguedo@users.noreply.github.com> Date: Tue, 13 Dec 2022 22:19:53 +0000 Subject: [PATCH 057/138] =?UTF-8?q?chile:=20D=C3=ADa=20Nacional=20de=20los?= =?UTF-8?q?=20Pueblos=20Ind=C3=ADgenas=20(#828)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix the holiday day when year > 2021 according to the calculated solstice datetime adjusted to Chile timezone UTC-3 Added necessary util Class _AstroMeeusAlgorithms Issue: 666 --- holidays/countries/chile.py | 9 +- holidays/utils.py | 170 ++++++++++++++++++++++++++++++++++- test/countries/test_chile.py | 12 ++- 3 files changed, 188 insertions(+), 3 deletions(-) diff --git a/holidays/countries/chile.py b/holidays/countries/chile.py index d4eecb98f..0c9df5a1e 100644 --- a/holidays/countries/chile.py +++ b/holidays/countries/chile.py @@ -32,6 +32,7 @@ DEC, ) from holidays.holiday_base import HolidayBase +from holidays.utils import _AstroMeeusAlgorithms class Chile(HolidayBase): @@ -94,7 +95,13 @@ def _populate(self, year): if year == 2021: self[date(year, JUN, 21)] = name if year > 2021: - self[date(year, JUN, 19)] = name + astro_alg = _AstroMeeusAlgorithms() + equinox = astro_alg.jd2date(astro_alg.summer(year)) + # Received date for UTC timezone needs to be adjusted + # to match Chile's timezone + # https://www.feriadoschilenos.cl/#DiaNacionalDeLosPueblosIndigenasII + adjusted_date = equinox + rd(hours=-4) + self[date(year, JUN, adjusted_date.day)] = name # Saint Peter and Saint Paul (Law 18.432) name = "San Pedro y San Pablo [Saint Peter and Saint Paul]" diff --git a/holidays/utils.py b/holidays/utils.py index 32e9db2d1..b8aa63ca8 100755 --- a/holidays/utils.py +++ b/holidays/utils.py @@ -12,8 +12,9 @@ # from __future__ import annotations # add in Python 3.7 import inspect +import math import warnings -from datetime import date, timedelta +from datetime import date, datetime, timedelta from functools import lru_cache from typing import Dict, Iterable, List, Optional, Union @@ -792,3 +793,170 @@ def thaipusam_date(self, year: int) -> date: span_days += self._lunar_month_days(year, m) span_days -= 15 return self.SOLAR_START_DATE + timedelta(span_days) + + +class _AstroMeeusAlgorithms: + def __init__(self) -> None: + """ + This class provides some of Jean Meeus' algorithms from the book + `Astronomical Algorithms` required for equinox and solstice + calculations. + The complete list of algorithm implementations is available here: + https://github.com/pavolgaj/AstroAlgorithms4Python + + Usage example: + + >>> from holidays.utils import _AstroMeeusAlgorithms + >>> astro_alg = _AstroMeeusAlgorithms() + >>> equinox = astro_alg.jd2date(astro_alg.summer(2026)) + >>> print(equinox) + 2026-06-21 05:26:04 + """ + + def _corrections(self, jd: float) -> float: + """ + Corrections to times of equinox/solstice + + :param jd: Julian day + :return: The Julian date of the next equinox or solstice. + """ + T = (jd - 2451545) / 36525.0 + + W = math.radians(35999.373 * T - 2.47) + dl = 1 + 0.0334 * math.cos(W) + 0.0007 * math.cos(2 * W) + + A = [ + 485, + 203, + 199, + 182, + 156, + 136, + 77, + 74, + 70, + 58, + 52, + 50, + 45, + 44, + 29, + 18, + 17, + 16, + 14, + 12, + 12, + 12, + 9, + 8, + ] + B = [ + 324.96, + 337.23, + 342.08, + 27.85, + 73.14, + 171.52, + 222.54, + 296.72, + 243.58, + 119.81, + 297.17, + 21.02, + 247.54, + 325.15, + 60.93, + 155.12, + 288.79, + 198.04, + 199.76, + 95.39, + 287.11, + 320.81, + 227.73, + 15.45, + ] + C = [ + 1934.136, + 32964.467, + 20.186, + 445267.112, + 45036.886, + 22518.443, + 65928.934, + 3034.906, + 9037.513, + 33718.147, + 150.678, + 2281.226, + 29929.562, + 31555.956, + 4443.417, + 67555.328, + 4562.452, + 62894.029, + 31436.921, + 14577.848, + 31931.756, + 34777.259, + 1222.114, + 16859.074, + ] + + S = 0.0 + for i in range(len(A)): + S += A[i] * math.cos(math.radians(B[i] + C[i] * T)) + return jd + 0.00001 * S / dl + + def summer(self, year: int) -> float: + """ + Calculates summer (June) solstice for given year + + :param year: The year for which you want to calculate the solstice + :return: The Julian date of the summer solstice. + """ + Y = (year - 2000) / 1000.0 + jd0 = ( + 2451716.56767 + + 365241.62603 * Y + + 0.00325 * Y**2 + + 0.00888 * Y**3 + - 0.00030 * Y**4 + ) + return self._corrections(jd0) + + def jd2date(self, jd: float) -> datetime: + """ + Convert a Julian date to a Gregorian date. + + :param jd: Julian date + :return: The datetime object of the Julian date. + """ + jd += 0.5 + z = int(jd) + f = jd % 1 + if z < 2299161: + a = z + else: + alp = int((z - 1867216.25) / 36524.25) + a = z + 1 + alp - int(alp / 4) + b = a + 1524 + c = int((b - 122.1) / 365.25) + d = int(365.25 * c) + e = int((b - d) / 30.6001) + + h = int(f * 24) + m = int((f - h / 24.0) * 1440) + s = round((f - h / 24.0 - m / 1440.0) * 86400.0, 2) + day = b - d - int(30.6001 * e) + if e < 14: + mon = e - 1 + else: + mon = e - 13 + if mon > 2: + year = c - 4716 + else: + year = c - 4715 + + return datetime(year, mon, day, h, m, int(s)) diff --git a/test/countries/test_chile.py b/test/countries/test_chile.py index 70d3aba09..de7591084 100644 --- a/test/countries/test_chile.py +++ b/test/countries/test_chile.py @@ -100,9 +100,19 @@ def test_2021(self): self.assertIn(date(2021, 8, 20), self.holidays_NB) def test_2024(self): - self.assertIn(date(2024, 6, 19), self.holidays) + self.assertIn(date(2024, 6, 20), self.holidays) self.assertIn(date(2024, 10, 12), self.holidays) + def test_2026(self): + self.assertIn(date(2026, 6, 21), self.holidays) + def test_2029(self): + self.assertIn(date(2029, 6, 20), self.holidays) self.assertIn(date(2029, 7, 2), self.holidays) self.assertIn(date(2029, 10, 15), self.holidays) + + def test_2050(self): + self.assertIn(date(2050, 6, 20), self.holidays) + + def test_2079(self): + self.assertIn(date(2079, 6, 20), self.holidays) From bfde36d1c9f4e6d766fe56798248e13d45a88050 Mon Sep 17 00:00:00 2001 From: ~Jhellico Date: Wed, 14 Dec 2022 00:26:22 +0200 Subject: [PATCH 058/138] Kazakhstan: (#829) - observed holidays - holidays relevance period --- holidays/countries/kazakhstan.py | 52 +++++++--- test/countries/test_kazakhstan.py | 165 +++++++++++++++++++++++++----- 2 files changed, 173 insertions(+), 44 deletions(-) diff --git a/holidays/countries/kazakhstan.py b/holidays/countries/kazakhstan.py index 0617be4da..3c352a747 100644 --- a/holidays/countries/kazakhstan.py +++ b/holidays/countries/kazakhstan.py @@ -11,7 +11,9 @@ from datetime import date -from holidays.constants import JAN, MAR, MAY, JUL, AUG, DEC +from dateutil.relativedelta import relativedelta as rd + +from holidays.constants import WEEKEND, JAN, MAR, MAY, JUL, AUG, DEC from holidays.holiday_base import HolidayBase from holidays.utils import _islamic_to_gre @@ -31,48 +33,64 @@ def _populate(self, year): All holidays get observed on weekdays if they fall on weekends, but this has not been implemented as yet. """ - # New Year's holiday (3 days) + # New Year's holiday (2 days) self[date(year, JAN, 1)] = "New Year" self[date(year, JAN, 2)] = "New Year Holiday" - self[date(year, JAN, 3)] = "New Year Holiday" # Orthodox Christmas - self[date(year, JAN, 7)] = "Orthodox Christmas" + if year >= 2007: + self[date(year, JAN, 7)] = "Orthodox Christmas" # Women's Day self[date(year, MAR, 8)] = "Women's Day" # Nauryz Holiday (3 days) - self[date(year, MAR, 21)] = "Nauryz" - self[date(year, MAR, 22)] = "Nauryz Holiday" - self[date(year, MAR, 23)] = "Nauryz Holiday" + if year >= 2009: + self[date(year, MAR, 21)] = "Nauryz" + self[date(year, MAR, 22)] = "Nauryz Holiday" + self[date(year, MAR, 23)] = "Nauryz Holiday" - # People Solidarity Holiday - self[date(year, MAY, 1)] = "People's Solidarity Day" + # Unity Day + self[date(year, MAY, 1)] = "Unity Day" # Defender's Day - self[date(year, MAY, 7)] = "Defender's Day" + if year >= 2013: + self[date(year, MAY, 7)] = "Defender's Day" # Victory Day self[date(year, MAY, 9)] = "Victory Day" # Capital City Day - self[date(year, JUL, 6)] = "Capital City Day" - - # Kurban Ait - for hol_date in _islamic_to_gre(year, 12, 10): - self[hol_date] = "Kurban Ait" + if year >= 2009: + self[date(year, JUL, 6)] = "Capital City Day" # Constitution Day - self[date(year, AUG, 30)] = "Constitution Day" + if year >= 1996: + self[date(year, AUG, 30)] = "Constitution Day" # First President Day - self[date(year, DEC, 1)] = "First President Day" + if year >= 2013: + self[date(year, DEC, 1)] = "First President Day" # Independence Day (2 days) self[date(year, DEC, 16)] = "Independence Day" self[date(year, DEC, 17)] = "Independence Day Holiday" + if self.observed: + for k, v in list(self.items()): + if k.weekday() in WEEKEND and k.year == year: + next_workday = k + rd(days=+1) + while next_workday.weekday() in WEEKEND or self.get( + next_workday + ): + next_workday += rd(days=+1) + self[next_workday] = v + " (Observed)" + + # Kurban Ait + if year >= 2007: + for hol_date in _islamic_to_gre(year, 12, 10): + self[hol_date] = "Kurban Ait" + class KZ(Kazakhstan): pass diff --git a/test/countries/test_kazakhstan.py b/test/countries/test_kazakhstan.py index 51748ca13..a347466e3 100644 --- a/test/countries/test_kazakhstan.py +++ b/test/countries/test_kazakhstan.py @@ -9,36 +9,147 @@ # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) -import unittest -from datetime import date +from test.common import TestCase -import holidays +from holidays.countries.kazakhstan import Kazakhstan, KZ, KAZ -class TestKazakhstan(unittest.TestCase): +class TestKazakhstan(TestCase): def setUp(self): - self.holidays = holidays.KZ() + self.holidays = Kazakhstan() + + def test_country_aliases(self): + self.assertCountryAliases(Kazakhstan, KZ, KAZ) def test2020(self): - _holidays = [ - date(2020, 1, 1), - date(2020, 1, 2), - date(2020, 1, 3), - date(2020, 1, 7), - date(2020, 3, 8), - date(2020, 3, 21), - date(2020, 3, 22), - date(2020, 3, 23), - date(2020, 5, 1), - date(2020, 5, 7), - date(2020, 5, 9), - date(2020, 7, 6), - date(2020, 7, 31), - date(2020, 8, 30), - date(2020, 12, 1), - date(2020, 12, 16), - date(2020, 12, 17), - ] - - for kaz_hol in _holidays: - self.assertIn(kaz_hol, self.holidays) + self.assertHolidayDatesEqual( + Kazakhstan(years=2020), + "2020-01-01", + "2020-01-02", + "2020-01-07", + "2020-03-08", + "2020-03-09", + "2020-03-21", + "2020-03-22", + "2020-03-23", + "2020-03-24", + "2020-03-25", + "2020-05-01", + "2020-05-07", + "2020-05-09", + "2020-05-11", + "2020-07-06", + "2020-07-31", + "2020-08-30", + "2020-08-31", + "2020-12-01", + "2020-12-16", + "2020-12-17", + ) + + def test_christmas(self): + self.assertHoliday(*[f"{year}-01-07" for year in range(2007, 2100)]) + self.assertNoHoliday(*[f"{year}-01-07" for year in range(1990, 2007)]) + + def test_nauryz(self): + for year in range(2009, 2100): + self.assertHoliday( + f"{year}-03-21", f"{year}-03-22", f"{year}-03-23" + ) + for year in range(1990, 2009): + self.assertNoHoliday( + f"{year}-03-21", f"{year}-03-22", f"{year}-03-23" + ) + + def test_defenders_day(self): + self.assertHoliday(*[f"{year}-05-07" for year in range(2013, 2100)]) + self.assertNoHoliday(*[f"{year}-05-07" for year in range(1990, 2013)]) + + def test_capital_city_day(self): + self.assertHoliday(*[f"{year}-07-06" for year in range(2009, 2100)]) + self.assertNoHoliday(*[f"{year}-07-06" for year in range(1990, 2009)]) + + def test_constitution_day(self): + self.assertHoliday(*[f"{year}-08-30" for year in range(1996, 2100)]) + self.assertNoHoliday(*[f"{year}-08-30" for year in range(1990, 1996)]) + + def test_first_president_day(self): + self.assertHoliday(*[f"{year}-12-01" for year in range(2013, 2100)]) + self.assertNoHoliday(*[f"{year}-12-01" for year in range(1990, 2013)]) + + def test_kurban_ait(self): + self.assertHoliday( + "2007-12-20", + "2008-12-08", + "2009-11-27", + "2010-11-16", + "2011-11-06", + "2012-10-26", + "2013-10-15", + "2014-10-04", + "2015-09-23", + "2016-09-11", + "2017-09-01", + "2018-08-21", + "2019-08-11", + "2020-07-31", + "2021-07-20", + "2022-07-09", + "2023-06-28", + ) + + self.assertNoHoliday( + "2005-01-21", + "2006-01-10", + "2006-12-31", + ) + + def test_observed(self): + observed_holidays = ( + "2012-01-03", + "2012-01-09", + "2012-12-18", + "2013-03-25", + "2013-07-08", + "2013-12-02", + "2014-03-10", + "2014-03-24", + "2014-03-25", + "2014-07-07", + "2014-09-01", + "2015-03-09", + "2015-03-24", + "2015-03-25", + "2015-05-11", + "2015-08-31", + "2016-01-04", + "2016-05-02", + "2016-05-10", + "2016-12-19", + "2017-01-03", + "2017-01-09", + "2017-05-08", + "2017-12-18", + "2017-12-19", + "2018-01-08", + "2018-12-03", + "2018-12-18", + "2019-03-25", + "2019-07-08", + "2019-12-02", + "2020-03-09", + "2020-03-24", + "2020-03-25", + "2020-05-11", + "2020-08-31", + "2021-01-04", + "2021-03-24", + "2021-05-03", + "2021-05-10", + "2022-01-04", + "2022-05-02", + "2022-05-10", + "2022-12-19", + ) + self.assertHoliday(Kazakhstan(observed=True), *observed_holidays) + self.assertNoHoliday(Kazakhstan(observed=False), *observed_holidays) From dd6e2c33460dbecaaa3544dee58d4fe54feae446 Mon Sep 17 00:00:00 2001 From: Arkadii Yakovets Date: Tue, 13 Dec 2022 15:24:44 -0800 Subject: [PATCH 059/138] Improve `common.TestCase` (#830) --- test/common.py | 76 +++++++++++++++++++---------------- test/countries/test_angola.py | 8 ++-- 2 files changed, 46 insertions(+), 38 deletions(-) diff --git a/test/common.py b/test/common.py index 20d021d0e..006e37f35 100644 --- a/test/common.py +++ b/test/common.py @@ -11,6 +11,7 @@ # Copyright: Arkadii Yakovets , 2022 import unittest +from typing import Generator from dateutil.parser import parse from dateutil.relativedelta import SU @@ -22,17 +23,31 @@ class TestCase(unittest.TestCase): """Base class for python-holiday test cases.""" def parse_arguments(self, args): + date_args = args + instance = None + if issubclass(args[0].__class__, HolidayBase): - return args[0], args[1:] + instance = args[0] + date_args = args[1:] - if not hasattr(self, "holidays"): + instance = instance or getattr(self, "holidays", None) + if instance is None: raise ValueError( - "Either pass country holidays object (`HolidayBase` subclass) " + "Either pass a holidays object (`HolidayBase` subclass) " "as a first argument or initialize `self.holidays` in the " "`setUp()` method." ) - return self.holidays, args + dates = [] + for date_arg in date_args: + if type(date_arg) in {list, tuple}: + dates.extend(date_arg) + elif isinstance(date_arg, Generator): + dates.extend(tuple(date_arg)) + else: + dates.append(date_arg) + + return instance, dates def verify_type(self, holidays): self.assertTrue( @@ -40,7 +55,7 @@ def verify_type(self, holidays): "`holidays` object must be a subclass of `HolidayBase`", ) - def assertCountryAliases(self, cls, *aliases): + def assertCountryAliases(self, cls, alpha_2, alpha_3): """Asserts country aliases match.""" self.assertTrue( @@ -48,38 +63,31 @@ def assertCountryAliases(self, cls, *aliases): "Country holidays object must be a subclass of `HolidayBase`", ) - has_alpha_2 = False - has_alpha_3 = False - for alias in aliases: - self.assertTrue( - issubclass(alias, cls), - "Country alias object must be a subclass of the " - "main country class.", - ) + type_error_message = ( + "Country alias object must be a subclass of the country class." + ) + for alias in (alpha_2, alpha_3): + self.assertIsNotNone(alias, type_error_message) + self.assertTrue(issubclass(alias, cls), type_error_message) self.assertEqual(alias(), cls()) - class_name = alias.__name__ - if len(class_name) == 2: - has_alpha_2 = True - elif len(class_name) == 3: - has_alpha_3 = True - else: - raise ValueError( - "Alias class name must match either alpha-2 or alpha-3 " - f"country code. Got: `{class_name}`." - ) - - self.assertTrue( - has_alpha_2, "Country alpha-2 code must also be included." - ) - self.assertTrue( - has_alpha_3, "Country alpha-3 code must also be included." - ) - self.assertEqual( - 2, - len(aliases), - "Please include alpha-2 and alpha-3 country code aliases.", + length_error_message = ( + "This method accepts exactly 3 arguments " + "in this specific order: country base class, country alpha-2 " + "alias, and country alpha-3 alias. For example: " + "`self.assertCountryAliases(UnitedStates, US, USA)`" ) + if len(alpha_2.__name__) != 2: + raise ValueError( + f"{length_error_message}. Alias `{alpha_2.__name__}` doesn't " + "look like alpha-2 country code." + ) + + if len(alpha_3.__name__) != 3: + raise ValueError( + f"{length_error_message}. Alias `{alpha_3.__name__}` doesn't " + "look like alpha-3 country code." + ) def assertNoHolidays(self, holidays): """Asserts holidays dict is empty.""" diff --git a/test/countries/test_angola.py b/test/countries/test_angola.py index 489cbbbc9..4be549b17 100644 --- a/test/countries/test_angola.py +++ b/test/countries/test_angola.py @@ -49,15 +49,15 @@ def test_long_weekend(self): ) def test_national_hero_day(self): - self.assertHoliday(*[f"{year}-09-17" for year in range(1980, 2030)]) + self.assertHoliday(f"{year}-09-17" for year in range(1980, 2030)) - self.assertNoHoliday(*[f"{year}-09-17" for year in range(1975, 1980)]) + self.assertNoHoliday(f"{year}-09-17" for year in range(1975, 1980)) def test_national_liberation_day(self): - self.assertHoliday(*[f"{year}-03-23" for year in range(2019, 2030)]) + self.assertHoliday(f"{year}-03-23" for year in range(2019, 2030)) # Not a holiday before 2019. - self.assertNoHoliday(*[f"{year}-03-23" for year in range(1990, 2019)]) + self.assertNoHoliday(f"{year}-03-23" for year in range(1990, 2019)) def test_new_years_day(self): self.assertHoliday( From c3e65ebeca16cf95e70033af31bd6c492d03730a Mon Sep 17 00:00:00 2001 From: Snow <39384983+SnowX65@users.noreply.github.com> Date: Wed, 14 Dec 2022 00:27:59 +0100 Subject: [PATCH 060/138] Adding financial holidays - Hurricane Gloria and Sandy (#833) Co-authored-by: Arkadii Yakovets --- holidays/financial/ny_stock_exchange.py | 5 +++++ test/financial/test_ny_stock_exchange.py | 3 +++ 2 files changed, 8 insertions(+) diff --git a/holidays/financial/ny_stock_exchange.py b/holidays/financial/ny_stock_exchange.py index 664919b94..61bf1b250 100644 --- a/holidays/financial/ny_stock_exchange.py +++ b/holidays/financial/ny_stock_exchange.py @@ -274,6 +274,8 @@ def _populate(self, year): ] = "Funeral for President Lyndon B. Johnson" elif year == 1977: self[date(year, JUL, 14)] = "Blackout in New Yor City" + elif year == 1985: + self[date(year, SEP, 27)] = "Hurricane Gloria" elif year == 1994: self[ date(year, APR, 27) @@ -291,6 +293,9 @@ def _populate(self, year): self[ date(year, JAN, 2) ] = "Day of Mourning for President Gerald R. Ford" + elif year == 2012: + self[date(year, OCT, 29)] = "Hurricane Sandy" + self[date(year, OCT, 30)] = "Hurricane Sandy" elif year == 2018: self[ date(year, DEC, 5) diff --git a/test/financial/test_ny_stock_exchange.py b/test/financial/test_ny_stock_exchange.py index f036e830d..a9be945ba 100644 --- a/test/financial/test_ny_stock_exchange.py +++ b/test/financial/test_ny_stock_exchange.py @@ -411,6 +411,7 @@ def test_special_holidays(self): date(1972, DEC, 28), # Funeral for President Harry S. Truman date(1973, JAN, 25), # Funeral for President Lyndon B. Johnson date(1977, JUL, 14), # Blackout in New Yor City + date(1985, SEP, 27), # Hurricane Gloria date(1994, APR, 27), # Funeral for President Richard M. Nixon date(2001, SEP, 11), # Closed for Sept 11, 2001 Attacks date(2001, SEP, 12), # Closed for Sept 11, 2001 Attacks @@ -420,6 +421,8 @@ def test_special_holidays(self): 2004, JUN, 11 ), # Day of Mourning for President Ronald W. Reagan date(2007, JAN, 2), # Day of Mourning for President Gerald R. Ford + date(2012, OCT, 29), # Hurricane Sandy + date(2012, OCT, 30), # Hurricane Sandy date( 2018, DEC, 5 ), # Day of Mourning for President George H.W. Bush From 3ec2f71cb3c1ec875ed56fa5a3fc43196efa05a7 Mon Sep 17 00:00:00 2001 From: ~Jhellico Date: Wed, 14 Dec 2022 01:32:31 +0200 Subject: [PATCH 061/138] Angola small refactoring (#835) --- holidays/countries/angola.py | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/holidays/countries/angola.py b/holidays/countries/angola.py index 0ebeb929e..c1f8b2227 100644 --- a/holidays/countries/angola.py +++ b/holidays/countries/angola.py @@ -40,13 +40,11 @@ class Angola(HolidayBase): country = "AO" def _populate(self, year: int) -> None: - super()._populate(year) - # Observed since 1975 # TODO do more research on history of Angolan holidays - if year <= 1974: return + super()._populate(year) self[date(year, JAN, 1)] = "Ano novo" # Since 2018, if the following year's New Year's Day falls on a @@ -84,15 +82,16 @@ def _populate(self, year: int) -> None: # the Monday or Friday is also a holiday if self.observed and year >= 1995: for k, v in list(self.items()): - if k.year == year: - if year <= 2017: - if k.weekday() == SUN: - self[k + rd(days=+1)] = v + " (Observed)" - else: - if k.weekday() == TUE and k != date(year, JAN, 1): - self[k + rd(days=-1)] = v + " (Day off)" - elif k.weekday() == THU: - self[k + rd(days=+1)] = v + " (Day off)" + if k.year != year: + continue + if year <= 2017: + if k.weekday() == SUN: + self[k + rd(days=+1)] = v + " (Observed)" + else: + if k.weekday() == TUE and k != date(year, JAN, 1): + self[k + rd(days=-1)] = v + " (Day off)" + elif k.weekday() == THU: + self[k + rd(days=+1)] = v + " (Day off)" class AO(Angola): From f5835280e4ae77df8c3dd9aa38e33a73c37a9460 Mon Sep 17 00:00:00 2001 From: ~Jhellico Date: Wed, 14 Dec 2022 01:33:22 +0200 Subject: [PATCH 062/138] New Zealand: optimizations (#836) --- holidays/countries/new_zealand.py | 221 ++++++++++++----------------- test/countries/test_new_zealand.py | 38 +++-- 2 files changed, 105 insertions(+), 154 deletions(-) diff --git a/holidays/countries/new_zealand.py b/holidays/countries/new_zealand.py index 036112fdf..a9409435c 100644 --- a/holidays/countries/new_zealand.py +++ b/holidays/countries/new_zealand.py @@ -13,12 +13,10 @@ from dateutil.easter import easter from dateutil.relativedelta import relativedelta as rd -from dateutil.relativedelta import MO, TU, WE, FR +from dateutil.relativedelta import MO, TU, WE from holidays.constants import ( - TUE, - WED, - THU, + FRI, WEEKEND, JAN, FEB, @@ -78,9 +76,14 @@ class NewZealand(HolidayBase): "WTL", # Correct code is WTC ] - def _populate(self, year): - super()._populate(year) + @staticmethod + def _get_nearest_monday(d: date) -> date: + if d.weekday() < FRI: + return d + rd(weekday=MO(-1)) + else: + return d + rd(weekday=MO) + def _populate(self, year): # Bank Holidays Act 1873 # The Employment of Females Act 1873 # Factories Act 1894 @@ -91,8 +94,9 @@ def _populate(self, year): # Waitangi Day Act 1960, 1976 # Sovereign's Birthday Observance Act 1937, 1952 # Holidays Act 1981, 2003 - if year < 1894: + if year <= 1893: return + super()._populate(year) # New Year's Day name = "New Year's Day" @@ -108,9 +112,9 @@ def _populate(self, year): self[date(year, JAN, 4)] = name + " (Observed)" # Waitangi Day - if year > 1973: + if year >= 1974: name = "New Zealand Day" - if year > 1976: + if year >= 1977: name = "Waitangi Day" feb6 = date(year, FEB, 6) self[feb6] = name @@ -123,7 +127,7 @@ def _populate(self, year): self[easter_date + rd(days=+1)] = "Easter Monday" # Anzac Day - if year > 1920: + if year >= 1921: name = "Anzac Day" apr25 = date(year, APR, 25) self[apr25] = name @@ -133,92 +137,64 @@ def _populate(self, year): # Sovereign's Birthday if 1952 <= year <= 2022: name = "Queen's Birthday" - elif year > 1901: + elif year >= 1902: name = "King's Birthday" if year == 1952: self[date(year, JUN, 2)] = name # Elizabeth II - elif year > 1937: - self[date(year, JUN, 1) + rd(weekday=MO(+1))] = name # EII & GVI + elif year >= 1938: + self[date(year, JUN, 1) + rd(weekday=MO)] = name # EII & GVI elif year == 1937: self[date(year, JUN, 9)] = name # George VI elif year == 1936: self[date(year, JUN, 23)] = name # Edward VIII - elif year > 1911: + elif year >= 1912: self[date(year, JUN, 3)] = name # George V - elif year > 1901: + elif year >= 1902: # http://paperspast.natlib.govt.nz/cgi-bin/paperspast?a=d&d=NZH19091110.2.67 self[date(year, NOV, 9)] = name # Edward VII # Matariki - name = "Matariki" - if year == 2022: - self[date(year, JUN, 24)] = name - elif year == 2023: - self[date(year, JUL, 14)] = name - elif year == 2024: - self[date(year, JUN, 28)] = name - elif year == 2025: - self[date(year, JUN, 20)] = name - elif year == 2026: - self[date(year, JUL, 10)] = name - elif year == 2027: - self[date(year, JUN, 25)] = name - elif year == 2028: - self[date(year, JUL, 14)] = name - elif year == 2029: - self[date(year, JUL, 6)] = name - elif year == 2030: - self[date(year, JUN, 21)] = name - elif year == 2031: - self[date(year, JUL, 11)] = name - elif year == 2032: - self[date(year, JUL, 2)] = name - elif year == 2033: - self[date(year, JUN, 24)] = name - elif year == 2034: - self[date(year, JUL, 7)] = name - elif year == 2035: - self[date(year, JUN, 29)] = name - elif year == 2036: - self[date(year, JUL, 18)] = name - elif year == 2037: - self[date(year, JUL, 10)] = name - elif year == 2038: - self[date(year, JUN, 25)] = name - elif year == 2039: - self[date(year, JUL, 15)] = name - elif year == 2040: - self[date(year, JUL, 6)] = name - elif year == 2041: - self[date(year, JUL, 19)] = name - elif year == 2042: - self[date(year, JUL, 11)] = name - elif year == 2043: - self[date(year, JUL, 3)] = name - elif year == 2044: - self[date(year, JUN, 24)] = name - elif year == 2045: - self[date(year, JUL, 7)] = name - elif year == 2046: - self[date(year, JUN, 29)] = name - elif year == 2047: - self[date(year, JUL, 19)] = name - elif year == 2048: - self[date(year, JUL, 3)] = name - elif year == 2049: - self[date(year, JUN, 25)] = name - elif year == 2050: - self[date(year, JUL, 15)] = name - elif year == 2051: - self[date(year, JUN, 30)] = name - elif year == 2052: - self[date(year, JUN, 21)] = name + dates_obs = { + 2022: (JUN, 24), + 2023: (JUL, 14), + 2024: (JUN, 28), + 2025: (JUN, 20), + 2026: (JUL, 10), + 2027: (JUN, 25), + 2028: (JUL, 14), + 2029: (JUL, 6), + 2030: (JUN, 21), + 2031: (JUL, 11), + 2032: (JUL, 2), + 2033: (JUN, 24), + 2034: (JUL, 7), + 2035: (JUN, 29), + 2036: (JUL, 18), + 2037: (JUL, 10), + 2038: (JUN, 25), + 2039: (JUL, 15), + 2040: (JUL, 6), + 2041: (JUL, 19), + 2042: (JUL, 11), + 2043: (JUL, 3), + 2044: (JUN, 24), + 2045: (JUL, 7), + 2046: (JUN, 29), + 2047: (JUL, 19), + 2048: (JUL, 3), + 2049: (JUN, 25), + 2050: (JUL, 15), + 2051: (JUN, 30), + 2052: (JUN, 21), + } + if year in dates_obs: + self[date(year, *dates_obs[year])] = "Matariki" # Labour Day name = "Labour Day" if year >= 1910: self[date(year, OCT, 1) + rd(weekday=MO(+4))] = name - elif year > 1899: + elif year >= 1900: self[date(year, OCT, 1) + rd(weekday=WE(+2))] = name # Christmas Day @@ -237,98 +213,75 @@ def _populate(self, year): # Province Anniversary Day if self.subdiv in {"Auckland", "AUK", "Northland", "NTL"}: - if 1963 < year <= 1973 and self.subdiv in {"Northland", "NTL"}: + if 1964 <= year <= 1973 and self.subdiv in {"Northland", "NTL"}: name = "Waitangi Day" dt = date(year, FEB, 6) else: name = "Auckland Anniversary Day" dt = date(year, JAN, 29) - if dt.weekday() in {TUE, WED, THU}: - self[dt + rd(weekday=MO(-1))] = name - else: - self[dt + rd(weekday=MO)] = name + self[self._get_nearest_monday(dt)] = name elif self.subdiv in {"New Plymouth", "Taranaki", "TKI"}: - name = "Taranaki Anniversary Day" - self[date(year, MAR, 1) + rd(weekday=MO(+2))] = name + self[ + date(year, MAR, 1) + rd(weekday=MO(+2)) + ] = "Taranaki Anniversary Day" elif self.subdiv in {"Hawke's Bay", "HKB"}: - name = "Hawke's Bay Anniversary Day" - labour_day = date(year, OCT, 1) + rd(weekday=MO(+4)) - self[labour_day + rd(weekday=FR(-1))] = name + self[ + (date(year, OCT, 1) + rd(weekday=MO(+4)) + rd(days=-3)) + ] = "Hawke's Bay Anniversary Day" elif self.subdiv in {"WGN", "Wellington"}: - name = "Wellington Anniversary Day" - jan22 = date(year, JAN, 22) - if jan22.weekday() in {TUE, WED, THU}: - self[jan22 + rd(weekday=MO(-1))] = name - else: - self[jan22 + rd(weekday=MO)] = name + self[ + self._get_nearest_monday(date(year, JAN, 22)) + ] = "Wellington Anniversary Day" elif self.subdiv in {"Marlborough", "MBH"}: - name = "Marlborough Anniversary Day" - labour_day = date(year, OCT, 1) + rd(weekday=MO(+4)) - self[labour_day + rd(weeks=1)] = name + self[ + (date(year, OCT, 1) + rd(weekday=MO(+4)) + rd(days=+7)) + ] = "Marlborough Anniversary Day" elif self.subdiv in {"Nelson", "NSN"}: - name = "Nelson Anniversary Day" - feb1 = date(year, FEB, 1) - if feb1.weekday() in {TUE, WED, THU}: - self[feb1 + rd(weekday=MO(-1))] = name - else: - self[feb1 + rd(weekday=MO)] = name + self[ + self._get_nearest_monday(date(year, FEB, 1)) + ] = "Nelson Anniversary Day" elif self.subdiv in {"CAN", "Canterbury"}: - name = "Canterbury Anniversary Day" - showday = date(year, NOV, 1) + rd(weekday=TU) + rd(weekday=FR(+2)) - self[showday] = name + self[ + (date(year, NOV, 1) + rd(weekday=TU) + rd(days=+10)) + ] = "Canterbury Anniversary Day" elif self.subdiv in {"South Canterbury", "STC"}: - name = "South Canterbury Anniversary Day" - dominion_day = date(year, SEP, 1) + rd(weekday=MO(4)) - self[dominion_day] = name + self[ + (date(year, SEP, 1) + rd(weekday=MO(+4))) + ] = "South Canterbury Anniversary Day" elif self.subdiv in {"WTC", "West Coast", "WTL", "Westland"}: name = "West Coast Anniversary Day" - dec1 = date(year, DEC, 1) # Observance varies?!?! if year == 2005: # special case?!?! self[date(year, DEC, 5)] = name - elif dec1.weekday() in {TUE, WED, THU}: - self[dec1 + rd(weekday=MO(-1))] = name else: - self[dec1 + rd(weekday=MO)] = name + self[self._get_nearest_monday(date(year, DEC, 1))] = name elif self.subdiv in {"OTA", "Otago"}: - name = "Otago Anniversary Day" - mar23 = date(year, MAR, 23) # there is no easily determined single day of local observance?!?! - if mar23.weekday() in {TUE, WED, THU}: - dt = mar23 + rd(weekday=MO(-1)) - else: - dt = mar23 + rd(weekday=MO) + dt = self._get_nearest_monday(date(year, MAR, 23)) if dt == easter_date + rd(days=+1): # Avoid Easter Monday - dt += rd(days=1) - self[dt] = name + dt += rd(days=+1) + self[dt] = "Otago Anniversary Day" elif self.subdiv in {"STL", "Southland"}: name = "Southland Anniversary Day" - jan17 = date(year, JAN, 17) - if year > 2011: + if year >= 2012: self[easter_date + rd(days=+2)] = name else: - if jan17.weekday() in {TUE, WED, THU}: - self[jan17 + rd(weekday=MO(-1))] = name - else: - self[jan17 + rd(weekday=MO)] = name + self[self._get_nearest_monday(date(year, JAN, 17))] = name elif self.subdiv in {"CIT", "Chatham Islands"}: - name = "Chatham Islands Anniversary Day" - nov30 = date(year, NOV, 30) - if nov30.weekday() in {TUE, WED, THU}: - self[nov30 + rd(weekday=MO(-1))] = name - else: - self[nov30 + rd(weekday=MO)] = name + self[ + self._get_nearest_monday(date(year, NOV, 30)) + ] = "Chatham Islands Anniversary Day" class NZ(NewZealand): diff --git a/test/countries/test_new_zealand.py b/test/countries/test_new_zealand.py index eba755e51..09281a266 100644 --- a/test/countries/test_new_zealand.py +++ b/test/countries/test_new_zealand.py @@ -742,26 +742,24 @@ def test_southland_anniversary_day(self): dt = date(year, 1, day) self.assertIn(dt, stl_holidays, dt) self.assertEqual(stl_holidays[dt], "Southland Anniversary Day", dt) - for year, (month, day) in enumerate( - [ - (4, 10), - (4, 2), - (4, 22), - (4, 7), - (3, 29), - (4, 18), - (4, 3), - (4, 23), - (4, 14), - (4, 6), - ], - 2012, - ): - dt = date(year, month, day) - self.assertIn(dt, stl_holidays, dt) - self.assertEqual( - stl_holidays[dt], "Southland Anniversary Day", dt - ) + for year, (month, day) in enumerate( + [ + (4, 10), + (4, 2), + (4, 22), + (4, 7), + (3, 29), + (4, 18), + (4, 3), + (4, 23), + (4, 14), + (4, 6), + ], + 2012, + ): + dt = date(year, month, day) + self.assertIn(dt, stl_holidays, dt) + self.assertEqual(stl_holidays[dt], "Southland Anniversary Day", dt) def test_chatham_islands_anniversary_day(self): cit_holidays = holidays.NZ(subdiv="Chatham Islands") From d279eda456ab676ce83e1010d0045237f31ab7cf Mon Sep 17 00:00:00 2001 From: ~Jhellico Date: Wed, 14 Dec 2022 01:38:10 +0200 Subject: [PATCH 063/138] =?UTF-8?q?UK=20King=E2=80=99s=20Coronation=20holi?= =?UTF-8?q?day=20in=202023=20(#840)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- holidays/countries/united_kingdom.py | 1 + test/countries/test_united_kingdom.py | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/holidays/countries/united_kingdom.py b/holidays/countries/united_kingdom.py index 798e09908..b525d49a1 100644 --- a/holidays/countries/united_kingdom.py +++ b/holidays/countries/united_kingdom.py @@ -52,6 +52,7 @@ class UnitedKingdom(HolidayBase): (JUN, 3, "Platinum Jubilee of Elizabeth II"), (SEP, 19, "State Funeral of Queen Elizabeth II"), ), + 2023: ((MAY, 8, "Coronation of Charles III"),), } subdivisions = ["UK", "England", "Northern Ireland", "Scotland", "Wales"] diff --git a/test/countries/test_united_kingdom.py b/test/countries/test_united_kingdom.py index cb54b9be9..b1e516958 100644 --- a/test/countries/test_united_kingdom.py +++ b/test/countries/test_united_kingdom.py @@ -25,6 +25,20 @@ def setUp(self): self.holidays_scotland = holidays.UK(subdiv="Scotland") self.holidays_northernireland = holidays.UK(subdiv="Northern Ireland") + def test_special_holidays(self): + for dt in ( + "1977-06-07", + "1981-07-29", + "1999-12-31", + "2002-06-03", + "2011-04-29", + "2012-06-05", + "2022-06-03", + "2022-09-19", + "2023-05-08", + ): + self.assertIn(dt, self.holidays) + def test_new_years(self): for year in range(1974, 2100): dt = date(year, 1, 1) From 9636d3e0d96b9fd95b397778be0b9c974a73a15d Mon Sep 17 00:00:00 2001 From: dr-prodigy <28216945+dr-prodigy@users.noreply.github.com> Date: Wed, 14 Dec 2022 00:40:51 +0100 Subject: [PATCH 064/138] CHANGES sync --- CHANGES | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index 664be32fd..bb1ad55f1 100644 --- a/CHANGES +++ b/CHANGES @@ -4,10 +4,12 @@ Version 0.18 Released ???????? ??, ???? - Code refactoring #801 (arkid15r) -- Test refactoring / common functions #800 (arkid15r) +- Test refactoring / common functions #800, #830 (arkid15r) - Pre-commit reviews #786, #795 (KJhellico, arkid15r, dr-p) - Import cleanup, flake8 settings review #792 (arkid15r, KJhellico, dr-p) +- Meeus algorithm for equinox and solstice calculation utils #828 (Nalguedo) - Easter holidays refactoring and unification #803 (KJhellico) +- Observed holidays calc optimizations #824 (KJhellico) - Special holidays refactoring for 13 countries #796 (arkid15r, KJhellico) - Support for Indonesia #787 (KJhellico) - Korea renamed to South Korea #797 (arkid15r) @@ -16,8 +18,22 @@ Released ???????? ??, ???? - Zambia: optimizations and refactoring #798 (KJhellico) - Vietnam: optimizations and refactoring #799 (KJhellico) - Malaysia: optimizations and refactoring #802 (KJhellico) +- New Zealand: optimizations and refactoring #836 (KJhellico) - Uruguay updates #809 (KJhellico) +- Kazakhstan updates #829 (KJhellico) - Canada fixes #811 (jasonjensen) +- Nigeria updates #823 (KJhellico) +- NY Stock Exchange update #817 (SnowX65) +- Madagascar updates #818 (KJhellico) +- Paraguay updates #819 (KJhellico) +- United Kingdom updates #840 (KJhellico) +- South Africa: optimizations #820 (KJhellico) +- Switzerland: optimizations, fix #821 (KJhellico) +- Angola: optimizations, fix #822, #835 (KJhellico) +- India updates #825 (KJhellico) +- NY Stock Exchange updates #833 (SnowX65, KJhellico) +- Hungary fixes #826 (KJhellico) +- Chile fixes #828 (Nalguedo) Version 0.17.2 ============== From 4008a7e3497d53fcb0dfa88a53998c1e3ff9dea9 Mon Sep 17 00:00:00 2001 From: Maurizio Montel <28216945+dr-prodigy@users.noreply.github.com> Date: Wed, 14 Dec 2022 01:03:17 +0100 Subject: [PATCH 065/138] Revert "Kazakhstan: (#829)" (#842) This reverts commit bfde36d1c9f4e6d766fe56798248e13d45a88050. --- holidays/countries/kazakhstan.py | 52 +++------- test/countries/test_kazakhstan.py | 165 +++++------------------------- 2 files changed, 44 insertions(+), 173 deletions(-) diff --git a/holidays/countries/kazakhstan.py b/holidays/countries/kazakhstan.py index 3c352a747..0617be4da 100644 --- a/holidays/countries/kazakhstan.py +++ b/holidays/countries/kazakhstan.py @@ -11,9 +11,7 @@ from datetime import date -from dateutil.relativedelta import relativedelta as rd - -from holidays.constants import WEEKEND, JAN, MAR, MAY, JUL, AUG, DEC +from holidays.constants import JAN, MAR, MAY, JUL, AUG, DEC from holidays.holiday_base import HolidayBase from holidays.utils import _islamic_to_gre @@ -33,64 +31,48 @@ def _populate(self, year): All holidays get observed on weekdays if they fall on weekends, but this has not been implemented as yet. """ - # New Year's holiday (2 days) + # New Year's holiday (3 days) self[date(year, JAN, 1)] = "New Year" self[date(year, JAN, 2)] = "New Year Holiday" + self[date(year, JAN, 3)] = "New Year Holiday" # Orthodox Christmas - if year >= 2007: - self[date(year, JAN, 7)] = "Orthodox Christmas" + self[date(year, JAN, 7)] = "Orthodox Christmas" # Women's Day self[date(year, MAR, 8)] = "Women's Day" # Nauryz Holiday (3 days) - if year >= 2009: - self[date(year, MAR, 21)] = "Nauryz" - self[date(year, MAR, 22)] = "Nauryz Holiday" - self[date(year, MAR, 23)] = "Nauryz Holiday" + self[date(year, MAR, 21)] = "Nauryz" + self[date(year, MAR, 22)] = "Nauryz Holiday" + self[date(year, MAR, 23)] = "Nauryz Holiday" - # Unity Day - self[date(year, MAY, 1)] = "Unity Day" + # People Solidarity Holiday + self[date(year, MAY, 1)] = "People's Solidarity Day" # Defender's Day - if year >= 2013: - self[date(year, MAY, 7)] = "Defender's Day" + self[date(year, MAY, 7)] = "Defender's Day" # Victory Day self[date(year, MAY, 9)] = "Victory Day" # Capital City Day - if year >= 2009: - self[date(year, JUL, 6)] = "Capital City Day" + self[date(year, JUL, 6)] = "Capital City Day" + + # Kurban Ait + for hol_date in _islamic_to_gre(year, 12, 10): + self[hol_date] = "Kurban Ait" # Constitution Day - if year >= 1996: - self[date(year, AUG, 30)] = "Constitution Day" + self[date(year, AUG, 30)] = "Constitution Day" # First President Day - if year >= 2013: - self[date(year, DEC, 1)] = "First President Day" + self[date(year, DEC, 1)] = "First President Day" # Independence Day (2 days) self[date(year, DEC, 16)] = "Independence Day" self[date(year, DEC, 17)] = "Independence Day Holiday" - if self.observed: - for k, v in list(self.items()): - if k.weekday() in WEEKEND and k.year == year: - next_workday = k + rd(days=+1) - while next_workday.weekday() in WEEKEND or self.get( - next_workday - ): - next_workday += rd(days=+1) - self[next_workday] = v + " (Observed)" - - # Kurban Ait - if year >= 2007: - for hol_date in _islamic_to_gre(year, 12, 10): - self[hol_date] = "Kurban Ait" - class KZ(Kazakhstan): pass diff --git a/test/countries/test_kazakhstan.py b/test/countries/test_kazakhstan.py index a347466e3..51748ca13 100644 --- a/test/countries/test_kazakhstan.py +++ b/test/countries/test_kazakhstan.py @@ -9,147 +9,36 @@ # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) -from test.common import TestCase +import unittest +from datetime import date -from holidays.countries.kazakhstan import Kazakhstan, KZ, KAZ +import holidays -class TestKazakhstan(TestCase): +class TestKazakhstan(unittest.TestCase): def setUp(self): - self.holidays = Kazakhstan() - - def test_country_aliases(self): - self.assertCountryAliases(Kazakhstan, KZ, KAZ) + self.holidays = holidays.KZ() def test2020(self): - self.assertHolidayDatesEqual( - Kazakhstan(years=2020), - "2020-01-01", - "2020-01-02", - "2020-01-07", - "2020-03-08", - "2020-03-09", - "2020-03-21", - "2020-03-22", - "2020-03-23", - "2020-03-24", - "2020-03-25", - "2020-05-01", - "2020-05-07", - "2020-05-09", - "2020-05-11", - "2020-07-06", - "2020-07-31", - "2020-08-30", - "2020-08-31", - "2020-12-01", - "2020-12-16", - "2020-12-17", - ) - - def test_christmas(self): - self.assertHoliday(*[f"{year}-01-07" for year in range(2007, 2100)]) - self.assertNoHoliday(*[f"{year}-01-07" for year in range(1990, 2007)]) - - def test_nauryz(self): - for year in range(2009, 2100): - self.assertHoliday( - f"{year}-03-21", f"{year}-03-22", f"{year}-03-23" - ) - for year in range(1990, 2009): - self.assertNoHoliday( - f"{year}-03-21", f"{year}-03-22", f"{year}-03-23" - ) - - def test_defenders_day(self): - self.assertHoliday(*[f"{year}-05-07" for year in range(2013, 2100)]) - self.assertNoHoliday(*[f"{year}-05-07" for year in range(1990, 2013)]) - - def test_capital_city_day(self): - self.assertHoliday(*[f"{year}-07-06" for year in range(2009, 2100)]) - self.assertNoHoliday(*[f"{year}-07-06" for year in range(1990, 2009)]) - - def test_constitution_day(self): - self.assertHoliday(*[f"{year}-08-30" for year in range(1996, 2100)]) - self.assertNoHoliday(*[f"{year}-08-30" for year in range(1990, 1996)]) - - def test_first_president_day(self): - self.assertHoliday(*[f"{year}-12-01" for year in range(2013, 2100)]) - self.assertNoHoliday(*[f"{year}-12-01" for year in range(1990, 2013)]) - - def test_kurban_ait(self): - self.assertHoliday( - "2007-12-20", - "2008-12-08", - "2009-11-27", - "2010-11-16", - "2011-11-06", - "2012-10-26", - "2013-10-15", - "2014-10-04", - "2015-09-23", - "2016-09-11", - "2017-09-01", - "2018-08-21", - "2019-08-11", - "2020-07-31", - "2021-07-20", - "2022-07-09", - "2023-06-28", - ) - - self.assertNoHoliday( - "2005-01-21", - "2006-01-10", - "2006-12-31", - ) - - def test_observed(self): - observed_holidays = ( - "2012-01-03", - "2012-01-09", - "2012-12-18", - "2013-03-25", - "2013-07-08", - "2013-12-02", - "2014-03-10", - "2014-03-24", - "2014-03-25", - "2014-07-07", - "2014-09-01", - "2015-03-09", - "2015-03-24", - "2015-03-25", - "2015-05-11", - "2015-08-31", - "2016-01-04", - "2016-05-02", - "2016-05-10", - "2016-12-19", - "2017-01-03", - "2017-01-09", - "2017-05-08", - "2017-12-18", - "2017-12-19", - "2018-01-08", - "2018-12-03", - "2018-12-18", - "2019-03-25", - "2019-07-08", - "2019-12-02", - "2020-03-09", - "2020-03-24", - "2020-03-25", - "2020-05-11", - "2020-08-31", - "2021-01-04", - "2021-03-24", - "2021-05-03", - "2021-05-10", - "2022-01-04", - "2022-05-02", - "2022-05-10", - "2022-12-19", - ) - self.assertHoliday(Kazakhstan(observed=True), *observed_holidays) - self.assertNoHoliday(Kazakhstan(observed=False), *observed_holidays) + _holidays = [ + date(2020, 1, 1), + date(2020, 1, 2), + date(2020, 1, 3), + date(2020, 1, 7), + date(2020, 3, 8), + date(2020, 3, 21), + date(2020, 3, 22), + date(2020, 3, 23), + date(2020, 5, 1), + date(2020, 5, 7), + date(2020, 5, 9), + date(2020, 7, 6), + date(2020, 7, 31), + date(2020, 8, 30), + date(2020, 12, 1), + date(2020, 12, 16), + date(2020, 12, 17), + ] + + for kaz_hol in _holidays: + self.assertIn(kaz_hol, self.holidays) From 6d48e329464ac170a7ba50b7f5e1c9699f3a5978 Mon Sep 17 00:00:00 2001 From: Arkadii Yakovets Date: Wed, 14 Dec 2022 01:38:30 -0800 Subject: [PATCH 066/138] Fix `TestCase::parse_arguments` instance determining logic. (#844) --- test/common.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/test/common.py b/test/common.py index 006e37f35..e45938004 100644 --- a/test/common.py +++ b/test/common.py @@ -29,14 +29,19 @@ def parse_arguments(self, args): if issubclass(args[0].__class__, HolidayBase): instance = args[0] date_args = args[1:] - - instance = instance or getattr(self, "holidays", None) - if instance is None: - raise ValueError( - "Either pass a holidays object (`HolidayBase` subclass) " - "as a first argument or initialize `self.holidays` in the " - "`setUp()` method." - ) + else: + try: + instance = getattr(self, "holidays") + self.assertTrue( + issubclass(instance.__class__, HolidayBase), + "The `self.holidays` must be a `HolidayBase` subclass.", + ) + except AttributeError: + raise ValueError( + "Either pass a holidays object (`HolidayBase` subclass) " + "as a first argument or initialize `self.holidays` in the " + "`setUp()` method." + ) dates = [] for date_arg in date_args: From 972046996404915eee9703cff957eb2ecd5fd05a Mon Sep 17 00:00:00 2001 From: ~Jhellico Date: Sat, 10 Dec 2022 12:17:04 +0200 Subject: [PATCH 067/138] Chile: - holidays relevance period fixes - historical holidays added - special holidays added - tests for all holidays --- holidays/countries/chile.py | 190 +++++++++------ test/countries/test_chile.py | 435 ++++++++++++++++++++++++++++------- 2 files changed, 471 insertions(+), 154 deletions(-) diff --git a/holidays/countries/chile.py b/holidays/countries/chile.py index 0c9df5a1e..72caf997a 100644 --- a/holidays/countries/chile.py +++ b/holidays/countries/chile.py @@ -17,6 +17,7 @@ from holidays.constants import ( TUE, + WED, THU, FRI, SAT, @@ -43,7 +44,9 @@ class Chile(HolidayBase): """ country = "CL" - + special_holidays = { + 2022: ((SEP, 16, "Feriado nacional [National Holiday]"),), + } # ISO 3166-2 codes for the principal subdivisions, called regions subdivisions = [ "AI", @@ -65,36 +68,58 @@ class Chile(HolidayBase): ] def _populate(self, year): + + # Law 2.977 established official holidays for Chile + # in its current form + if year <= 1914: + return super()._populate(year) # New Year's Day (Law 2.977) self[date(year, JAN, 1)] = "Año Nuevo [New Year's Day]" # Day after, if it's a Sunday (Law 20.983) - if year > 2016 and date(year, JAN, 1).weekday() == SUN: + if year >= 2017 and date(year, JAN, 1).weekday() == SUN: self[date(year, JAN, 2)] = "Fiestas Patrias [Holiday]" # Holy Week (Law 2.977) - name_fri = "Semana Santa (Viernes Santo) [Good Friday)]" - name_sat = "Semana Santa (Sábado Santo) [Good Saturday)]" - name_easter = "Día de Pascuas [Easter Day]" - easter_date = easter(year) - self[easter_date + rd(days=-2)] = name_fri - self[easter_date + rd(days=-1)] = name_sat - self[easter_date] = name_easter + self[ + easter_date + rd(days=-2) + ] = "Semana Santa (Viernes Santo) [Good Friday)]" + self[ + easter_date + rd(days=-1) + ] = "Semana Santa (Sábado Santo) [Good Saturday)]" + + # Ascension + if year <= 1967: + self[ + easter_date + rd(days=+39) + ] = "Ascensión del Señor [Ascension of Jesus]" + + # Corpus Christi + if year <= 1967 or 1987 <= year <= 2006: + # Law 19.668 + if year <= 1999: + dt = easter_date + rd(days=+60) + else: + dt = easter_date + rd(days=+57) + self[dt] = "Corpus Christi [Corpus Christi]" - # Labor Day (Law 2.200, renamed with Law 18.018) - name = "Día Nacional del Trabajo [Labour Day]" - self[date(year, MAY, 1)] = name + # Labour Day (Law 2.200, renamed with Law 18.018) + if year >= 1932: + self[date(year, MAY, 1)] = "Día Nacional del Trabajo [Labour Day]" # Naval Glories Day (Law 2.977) - name = "Día de las Glorias Navales [Navy Day]" - self[date(year, MAY, 21)] = name + self[date(year, MAY, 21)] = "Día de las Glorias Navales [Navy Day]" - name = "Día Nacional de los Pueblos Indígenas" + # National Day of Indigenous Peoples + name = ( + "Día Nacional de los Pueblos Indígenas " + "[National Day of Indigenous Peoples]" + ) if year == 2021: self[date(year, JUN, 21)] = name - if year > 2021: + elif year >= 2022: astro_alg = _AstroMeeusAlgorithms() equinox = astro_alg.jd2date(astro_alg.summer(year)) # Received date for UTC timezone needs to be adjusted @@ -103,95 +128,120 @@ def _populate(self, year): adjusted_date = equinox + rd(hours=-4) self[date(year, JUN, adjusted_date.day)] = name - # Saint Peter and Saint Paul (Law 18.432) - name = "San Pedro y San Pablo [Saint Peter and Saint Paul]" - if year < 2020: - self[date(year, JUN, 29)] = name - else: - # floating Monday holiday (Law 19.668) - if date(year, JUN, 29).weekday() <= THU: - self[ - date(year, JUN, 29) - + rd(date(year, JUN, 29), weekday=MO(-1)) - ] = name - elif date(year, JUN, 29).weekday() == FRI: - self[date(year, JUN, 29) + rd(weekday=MO)] = name - else: - self[date(year, JUN, 29)] = name + # Saint Peter and Saint Paul (Law 16.840, Law 18.432) + if year <= 1967 or year >= 1986: + dt = date(year, JUN, 29) + if year >= 2000: + # floating Monday holiday (Law 19.668) + if dt.weekday() < FRI: + dt += rd(weekday=MO(-1)) + elif dt.weekday() == FRI: + dt += rd(weekday=MO) + self[dt] = "San Pedro y San Pablo [Saint Peter and Saint Paul]" # Day of Virgin of Carmen (Law 20.148) - if year > 2006: - name = "Virgen del Carmen [Our Lady of Mount Carmel]" - self[date(year, JUL, 16)] = name + if year >= 2007: + self[ + date(year, JUL, 16) + ] = "Virgen del Carmen [Our Lady of Mount Carmel]" # Day of Assumption of the Virgin (Law 2.977) - name = "Asunción de la Virgen [Assumption of Mary]" - self[date(year, AUG, 15)] = name + self[ + date(year, AUG, 15) + ] = "Asunción de la Virgen [Assumption of Mary]" + + # Day of National Liberation (Law 18.026) + if 1981 <= year <= 1998: + self[ + date(year, SEP, 11) + ] = "Día de la Liberación Nacional [Day of National Liberation]" + # Day of National Unity (Law 19.588, Law 19.793) + elif 1999 <= year <= 2001: + self[ + date(year, SEP, 1) + rd(weekday=MO) + ] = "Día de la Unidad Nacional [Day of National Unity]" # National Holiday Friday preceding Independence Day (Law 20.983) - if year > 2016 and date(year, SEP, 18).weekday() == SAT: + # Monday, September 17, 2007, is declared a holiday. + if year >= 2017 and date(year, SEP, 18).weekday() == SAT: self[date(year, SEP, 17)] = "Fiestas Patrias [Holiday]" # National Holiday Monday preceding Independence Day (Law 20.215) - if year > 2007 and date(year, SEP, 18).weekday() == TUE: + if year >= 2007 and date(year, SEP, 18).weekday() == TUE: self[date(year, SEP, 17)] = "Fiestas Patrias [Holiday]" # Independence Day (Law 2.977) - name = "Día de la Independencia [Independence Day]" - self[date(year, SEP, 18)] = name + self[ + date(year, SEP, 18) + ] = "Día de la Independencia [Independence Day]" # Day of Glories of the Army of Chile (Law 2.977) - name = "Día de las Glorias del Ejército [Army Day]" - self[date(year, SEP, 19)] = name + self[ + date(year, SEP, 19) + ] = "Día de las Glorias del Ejército [Army Day]" # National Holiday Friday following Army Day (Law 20.215) - if year > 2007 and date(year, SEP, 19).weekday() == THU: + if year >= 2008 and date(year, SEP, 19).weekday() == THU: self[date(year, SEP, 20)] = "Fiestas Patrias [Holiday]" - # Day of the Meeting of Two Worlds (Law 3.810) - if year < 2010: - self[date(year, OCT, 12)] = "Día de la Raza [Columbus day]" - elif year < 2020: - self[date(year, OCT, 12)] = ( - "Día del Respeto a la Diversidad" - " [Day of the Meeting" - " of Two Worlds]" - ) - else: - # floating Monday holiday (Law 19.668) - name = "Día del Descubrimiento de dos Mundos [Columbus Day]" - if date(year, OCT, 12).weekday() <= THU: - self[ - date(year, OCT, 12) - + rd(date(year, OCT, 12), weekday=MO(-1)) - ] = name - elif date(year, OCT, 12).weekday() == FRI: - self[date(year, OCT, 12) + rd(weekday=MO)] = name - else: - self[date(year, OCT, 12)] = name + # Decree-law 636, Law 8.223 + if 1932 <= year <= 1944: + self[date(year, SEP, 20)] = "Fiestas Patrias [Holiday]" + + # Columbus day (Law 3.810) + if year >= 1922 and year != 1973: + dt = date(year, OCT, 12) + name = "Día de la Raza [Columbus day]" + if year >= 2000: + # floating Monday holiday (Law 19.668) + if dt.weekday() < FRI: + dt += rd(weekday=MO(-1)) + elif dt.weekday() == FRI: + dt += rd(weekday=MO) + if year <= 2019: + # Day of the Meeting of Two Worlds (Law 3.810) + name = ( + "Día del Respeto a la Diversidad " + "[Day of the Meeting of Two Worlds]" + ) + else: + name = ( + "Día del Descubrimiento de dos Mundos " + "[Discovery of Two Worlds' Day]" + ) + self[dt] = name # National Day of the Evangelical and Protestant Churches (Law 20.299) - if year > 2007: - name = ( + if year >= 2008: + dt = date(year, OCT, 31) + # This holiday is moved to the preceding Friday + # if it falls on a Tuesday, or to the following Friday + # if it falls on a Wednesday (Law 20.299) + if dt.weekday() == WED: + dt += rd(days=+2) + elif dt.weekday() == TUE: + dt += rd(days=-4) + self[dt] = ( "Día Nacional de las Iglesias Evangélicas y Protestantes" " [Reformation Day]" ) - self[date(year, OCT, 31)] = name # All Saints Day (Law 2.977) - name = "Día de Todos los Santos [All Saints Day]" - self[date(year, NOV, 1)] = name + self[date(year, NOV, 1)] = "Día de Todos los Santos [All Saints Day]" # Immaculate Conception (Law 2.977) self[ date(year, DEC, 8) ] = "La Inmaculada Concepción [Immaculate Conception]" + if 1944 <= year <= 1988: + self[date(year, DEC, 24)] = "Víspera de Navidad [Christmas Eve]" + # Christmas (Law 2.977) self[date(year, DEC, 25)] = "Navidad [Christmas]" # región de Arica y Parinacota - if self.subdiv == "AP" and year >= 2020: + if self.subdiv == "AP" and year >= 2013: # Law 20.663 self[date(year, JUN, 7)] = ( "Asalto y Toma del Morro de Arica" diff --git a/test/countries/test_chile.py b/test/countries/test_chile.py index de7591084..579502ae4 100644 --- a/test/countries/test_chile.py +++ b/test/countries/test_chile.py @@ -9,110 +9,377 @@ # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) -import unittest -from datetime import date +from test.common import TestCase -import holidays +from holidays.countries.chile import Chile, CL, CHL -class TestChile(unittest.TestCase): +class TestChile(TestCase): def setUp(self): - self.holidays = holidays.Chile() - self.holidays_AP = holidays.CL(subdiv="AP") - self.holidays_NB = holidays.CHL(subdiv="NB") + self.holidays = Chile() + self.holidays_AP = Chile(subdiv="AP") + self.holidays_NB = Chile(subdiv="NB") - def test_dia_del_carmen(self): + def test_country_aliases(self): + self.assertCountryAliases(Chile, CL, CHL) + + def test_special_holidays(self): + self.assertHoliday("2022-09-16") + + def test_no_holidays(self): + self.assertNoHolidays(Chile(years=1914)) + + def test_new_year(self): + self.assertHoliday(*[f"{year}-01-01" for year in range(1915, 2050)]) + self.assertHoliday( + "2017-01-02", + "2023-01-02", + ) + self.assertNoHoliday( + "1995-01-02", + "2006-01-02", + "2012-01-02", + ) + + def test_holy_week(self): + self.assertHoliday( + "1915-04-02", + "1940-03-22", + "1960-04-15", + "1980-04-04", + "2000-04-21", + "2015-04-03", + "2022-04-15", + "1915-04-03", + "1940-03-23", + "1960-04-16", + "1980-04-05", + "2000-04-22", + "2015-04-04", + "2022-04-16", + ) + + def test_ascension(self): + self.assertHoliday( + "1915-05-13", + "1930-05-29", + "1950-05-18", + "1967-05-04", + ) + for year in range(1915, 1968): + self.assertIn( + "Ascensión del Señor [Ascension of Jesus]", + ";".join(Chile(years=year).values()), + ) + for year in range(1968, 2050): + self.assertNotIn( + "Ascensión del Señor [Ascension of Jesus]", + ";".join(Chile(years=year).values()), + ) + + def test_corpus_christi(self): + self.assertHoliday( + "1915-06-03", + "1940-05-23", + "1950-06-08", + "1967-05-25", + "1987-06-18", + "1998-06-11", + "2000-06-19", + "2006-06-12", + ) + for year in range(1915, 1968): + self.assertIn( + "Corpus Christi [Corpus Christi]", + ";".join(Chile(years=year).values()), + ) + for year in range(1968, 1987): + self.assertNotIn( + "Corpus Christi [Corpus Christi]", + ";".join(Chile(years=year).values()), + ) + for year in range(1987, 2006): + self.assertIn( + "Corpus Christi [Corpus Christi]", + ";".join(Chile(years=year).values()), + ) + + def test_labour_day(self): + self.assertHoliday(*[f"{year}-05-01" for year in range(1932, 2050)]) + self.assertNoHoliday(*[f"{year}-05-01" for year in range(1915, 1932)]) + + def test_navy_day(self): + self.assertHoliday(*[f"{year}-05-21" for year in range(1915, 2050)]) + + def test_indigenous_peoples_day(self): + self.assertHoliday( + "2021-06-21", + "2022-06-21", + "2023-06-21", + "2024-06-20", + "2025-06-20", + "2026-06-21", + "2027-06-21", + "2028-06-20", + "2029-06-20", + "2030-06-21", + "2031-06-21", + "2032-06-20", + "2033-06-20", + "2034-06-21", + "2035-06-21", + "2036-06-20", + "2037-06-20", + "2038-06-21", + "2039-06-21", + "2040-06-20", + "2041-06-20", + "2042-06-21", + "2043-06-21", + "2044-06-20", + "2045-06-20", + "2046-06-21", + "2047-06-21", + "2048-06-20", + "2049-06-20", + "2050-06-20", + "2075-06-21", + "2076-06-20", + "2077-06-20", + "2078-06-20", + "2079-06-20", + ) + for year in range(1915, 2021): + self.assertNotIn( + "Día Nacional de los Pueblos Indígenas", + ";".join(Chile(years=year).values()), + ) + + def test_saint_peter_and_paul(self): + self.assertHoliday(*[f"{year}-06-29" for year in range(1915, 1967)]) + self.assertHoliday(*[f"{year}-06-29" for year in range(1986, 2000)]) + self.assertHoliday( + "2000-06-26", + "2001-07-02", + "2002-06-29", + "2003-06-29", + "2004-06-28", + "2005-06-27", + "2006-06-26", + "2007-07-02", + "2008-06-29", + "2009-06-29", + "2010-06-28", + "2011-06-27", + "2012-07-02", + "2013-06-29", + "2014-06-29", + "2015-06-29", + "2016-06-27", + "2017-06-26", + "2018-07-02", + "2019-06-29", + "2020-06-29", + "2021-06-28", + "2022-06-27", + "2023-06-26", + "2024-06-29", + ) + for year in range(1968, 1986): + self.assertNotIn( + "San Pedro y San Pablo", + ";".join(Chile(years=year).values()), + ) + + def test_virgin_of_carmen(self): # Day of Virgin of Carmen started after 2006 - self.assertNotIn(date(2006, 7, 16), self.holidays) - self.assertIn(date(2007, 7, 16), self.holidays) + self.assertHoliday(*[f"{year}-07-16" for year in range(2007, 2050)]) + self.assertNoHoliday(*[f"{year}-07-16" for year in range(1915, 2007)]) + + def test_assumption_of_mary(self): + self.assertHoliday(*[f"{year}-08-15" for year in range(1915, 2050)]) + + def test_national_liberation(self): + self.assertHoliday(*[f"{year}-09-11" for year in range(1981, 1999)]) + self.assertNoHoliday("1980-09-11", "1999-09-11") + for year in range(1915, 1981): + self.assertNotIn( + "Día de la Liberación Nacional", + ";".join(Chile(years=year).values()), + ) + for year in range(1999, 2050): + self.assertNotIn( + "Día de la Liberación Nacional", + ";".join(Chile(years=year).values()), + ) + + def test_national_unity(self): + self.assertHoliday( + "1999-09-06", + "2000-09-04", + "2001-09-03", + ) + self.assertNoHoliday("1998-09-07", "2002-09-02") + for year in range(1915, 2050): + if year not in {1999, 2000, 2001}: + self.assertNotIn( + "Día de la Unidad Nacional", + ";".join(Chile(years=year).values()), + ) + + def test_independence_holidays(self): + self.assertHoliday(*[f"{year}-09-18" for year in range(1915, 2050)]) + self.assertHoliday(*[f"{year}-09-19" for year in range(1915, 2050)]) + self.assertHoliday( + "2007-09-17", + "2012-09-17", + "2013-09-20", + "2018-09-17", + "2019-09-20", + "2021-09-17", + "2024-09-20", + ) + self.assertHoliday(*[f"{year}-09-20" for year in range(1932, 1945)]) + + def test_columbus_day(self): + for year in range(1922, 2000): + if year != 1973: + self.assertHoliday(f"{year}-10-12") + self.assertIn( + "Día de la Raza [Columbus day]", + ";".join(Chile(years=year).values()), + ) + else: + self.assertNotIn( + "Día de la Raza [Columbus day]", + ";".join(Chile(years=year).values()), + ) + self.assertHoliday( + "2000-10-09", + "2005-10-10", + "2010-10-11", + "2015-10-12", + "2019-10-12", + "2020-10-12", + "2021-10-11", + "2022-10-10", + "2023-10-09", + ) + for year in range(2000, 2020): + self.assertIn( + "Día del Respeto a la Diversidad", + ";".join(Chile(years=year).values()), + ) + for year in range(2020, 2050): + self.assertIn( + "Día del Descubrimiento de dos Mundos", + ";".join(Chile(years=year).values()), + ) - def test_2007(self): - # National Day started after 2007 - self.assertNotIn(date(2007, 10, 31), self.holidays) - self.assertIn(date(2008, 10, 31), self.holidays) + def test_reformation_day(self): + self.assertHoliday( + "2008-10-31", + "2009-10-31", + "2010-10-31", + "2011-10-31", + "2012-11-02", + "2013-10-31", + "2014-10-31", + "2015-10-31", + "2016-10-31", + "2017-10-27", + "2018-11-02", + "2019-10-31", + "2020-10-31", + "2021-10-31", + "2022-10-31", + "2023-10-27", + ) + for year in range(1915, 2008): + self.assertNotIn( + "Día Nacional de las Iglesias Evangélicas y Protestantes", + ";".join(Chile(years=year).values()), + ) - def test_2009(self): - self.assertIn(date(2009, 10, 12), self.holidays) + def test_all_saints(self): + self.assertHoliday(*[f"{year}-11-01" for year in range(1915, 2050)]) - def test_2017(self): - self.assertIn(date(2017, 1, 2), self.holidays) + def test_immaculate_conception(self): + self.assertHoliday(*[f"{year}-12-08" for year in range(1915, 2050)]) - def test_2018(self): - self.assertIn(date(2018, 9, 17), self.holidays) + def test_christmas(self): + self.assertHoliday(*[f"{year}-12-25" for year in range(1915, 2050)]) + self.assertHoliday(*[f"{year}-12-24" for year in range(1944, 1989)]) + self.assertNoHoliday(*[f"{year}-12-24" for year in range(1915, 1944)]) + self.assertNoHoliday(*[f"{year}-12-24" for year in range(1989, 2050)]) def test_2019(self): # No laborables (sector público) not included - self.assertIn(date(2019, 1, 1), self.holidays) - # self.assertIn(date(2019, 4, 18), self.holidays) - self.assertIn(date(2019, 4, 19), self.holidays) - self.assertIn(date(2019, 5, 1), self.holidays) - self.assertIn(date(2019, 5, 21), self.holidays) - self.assertIn(date(2019, 6, 29), self.holidays) - self.assertIn(date(2019, 7, 16), self.holidays) - self.assertIn(date(2019, 8, 15), self.holidays) - self.assertIn(date(2019, 9, 18), self.holidays) - self.assertIn(date(2019, 9, 19), self.holidays) - self.assertIn(date(2019, 9, 20), self.holidays) - self.assertIn(date(2019, 10, 12), self.holidays) - self.assertIn(date(2019, 11, 1), self.holidays) - self.assertIn(date(2019, 12, 8), self.holidays) - self.assertIn(date(2019, 12, 25), self.holidays) + self.assertHoliday( + "2019-01-01", + "2019-04-19", + "2019-05-01", + "2019-05-21", + "2019-06-29", + "2019-07-16", + "2019-08-15", + "2019-09-18", + "2019-09-19", + "2019-09-20", + "2019-10-12", + "2019-11-01", + "2019-12-08", + "2019-12-25", + ) def test_2020(self): # from https://feriados.cl/2020.htm - self.assertIn(date(2020, 1, 1), self.holidays) - self.assertIn(date(2020, 4, 10), self.holidays) - self.assertIn(date(2020, 4, 11), self.holidays) - self.assertIn(date(2020, 5, 1), self.holidays) - self.assertIn(date(2020, 5, 21), self.holidays) - self.assertIn(date(2020, 6, 29), self.holidays) - self.assertIn(date(2020, 7, 16), self.holidays) - self.assertIn(date(2020, 8, 15), self.holidays) - self.assertIn(date(2020, 9, 18), self.holidays) - self.assertIn(date(2020, 9, 19), self.holidays) - self.assertIn(date(2020, 10, 12), self.holidays) - self.assertIn(date(2020, 10, 31), self.holidays) - self.assertIn(date(2020, 11, 1), self.holidays) - self.assertIn(date(2020, 12, 8), self.holidays) - self.assertIn(date(2020, 12, 25), self.holidays) - self.assertIn(date(2020, 6, 7), self.holidays_AP) - self.assertIn(date(2020, 8, 20), self.holidays_NB) + self.assertHoliday( + "2020-01-01", + "2020-04-10", + "2020-04-11", + "2020-05-01", + "2020-05-21", + "2020-06-29", + "2020-07-16", + "2020-08-15", + "2020-09-18", + "2020-09-19", + "2020-10-12", + "2020-10-31", + "2020-11-01", + "2020-12-08", + "2020-12-25", + ) + self.assertHoliday(self.holidays_AP, "2020-06-07") + self.assertHoliday(self.holidays_NB, "2020-08-20") def test_2021(self): # from https://feriados.cl/2021.htm - self.assertIn(date(2021, 1, 1), self.holidays) - self.assertIn(date(2021, 4, 2), self.holidays) - self.assertIn(date(2021, 4, 3), self.holidays) - self.assertIn(date(2021, 5, 1), self.holidays) - self.assertIn(date(2021, 5, 21), self.holidays) - self.assertIn(date(2021, 6, 21), self.holidays) - self.assertIn(date(2021, 6, 28), self.holidays) - self.assertIn(date(2021, 7, 16), self.holidays) - self.assertIn(date(2021, 8, 15), self.holidays) - self.assertIn(date(2021, 9, 18), self.holidays) - self.assertIn(date(2021, 9, 19), self.holidays) - self.assertIn(date(2021, 10, 11), self.holidays) - self.assertIn(date(2021, 10, 31), self.holidays) - self.assertIn(date(2021, 11, 1), self.holidays) - self.assertIn(date(2021, 12, 8), self.holidays) - self.assertIn(date(2021, 12, 25), self.holidays) - self.assertIn(date(2021, 6, 7), self.holidays_AP) - self.assertIn(date(2021, 8, 20), self.holidays_NB) - - def test_2024(self): - self.assertIn(date(2024, 6, 20), self.holidays) - self.assertIn(date(2024, 10, 12), self.holidays) - - def test_2026(self): - self.assertIn(date(2026, 6, 21), self.holidays) - - def test_2029(self): - self.assertIn(date(2029, 6, 20), self.holidays) - self.assertIn(date(2029, 7, 2), self.holidays) - self.assertIn(date(2029, 10, 15), self.holidays) + self.assertHoliday( + "2021-01-01", + "2021-04-02", + "2021-04-03", + "2021-05-01", + "2021-05-21", + "2021-06-21", + "2021-06-28", + "2021-07-16", + "2021-08-15", + "2021-09-17", + "2021-09-18", + "2021-09-19", + "2021-10-11", + "2021-10-31", + "2021-11-01", + "2021-12-08", + "2021-12-25", + ) + self.assertHoliday(self.holidays_AP, "2021-06-07") + self.assertHoliday(self.holidays_NB, "2021-08-20") def test_2050(self): - self.assertIn(date(2050, 6, 20), self.holidays) + self.assertHoliday("2050-06-20") def test_2079(self): - self.assertIn(date(2079, 6, 20), self.holidays) + self.assertHoliday("2079-06-20") From 777a5c466dd00aac063d16eb1cf54ca60ae5f2cc Mon Sep 17 00:00:00 2001 From: Maurizio Montel <28216945+dr-prodigy@users.noreply.github.com> Date: Wed, 14 Dec 2022 11:44:01 +0100 Subject: [PATCH 068/138] Revert "Revert "Kazakhstan: (#829)" (#842)" (#845) This reverts commit 4008a7e3497d53fcb0dfa88a53998c1e3ff9dea9. --- holidays/countries/kazakhstan.py | 52 +++++++--- test/countries/test_kazakhstan.py | 165 +++++++++++++++++++++++++----- 2 files changed, 173 insertions(+), 44 deletions(-) diff --git a/holidays/countries/kazakhstan.py b/holidays/countries/kazakhstan.py index 0617be4da..3c352a747 100644 --- a/holidays/countries/kazakhstan.py +++ b/holidays/countries/kazakhstan.py @@ -11,7 +11,9 @@ from datetime import date -from holidays.constants import JAN, MAR, MAY, JUL, AUG, DEC +from dateutil.relativedelta import relativedelta as rd + +from holidays.constants import WEEKEND, JAN, MAR, MAY, JUL, AUG, DEC from holidays.holiday_base import HolidayBase from holidays.utils import _islamic_to_gre @@ -31,48 +33,64 @@ def _populate(self, year): All holidays get observed on weekdays if they fall on weekends, but this has not been implemented as yet. """ - # New Year's holiday (3 days) + # New Year's holiday (2 days) self[date(year, JAN, 1)] = "New Year" self[date(year, JAN, 2)] = "New Year Holiday" - self[date(year, JAN, 3)] = "New Year Holiday" # Orthodox Christmas - self[date(year, JAN, 7)] = "Orthodox Christmas" + if year >= 2007: + self[date(year, JAN, 7)] = "Orthodox Christmas" # Women's Day self[date(year, MAR, 8)] = "Women's Day" # Nauryz Holiday (3 days) - self[date(year, MAR, 21)] = "Nauryz" - self[date(year, MAR, 22)] = "Nauryz Holiday" - self[date(year, MAR, 23)] = "Nauryz Holiday" + if year >= 2009: + self[date(year, MAR, 21)] = "Nauryz" + self[date(year, MAR, 22)] = "Nauryz Holiday" + self[date(year, MAR, 23)] = "Nauryz Holiday" - # People Solidarity Holiday - self[date(year, MAY, 1)] = "People's Solidarity Day" + # Unity Day + self[date(year, MAY, 1)] = "Unity Day" # Defender's Day - self[date(year, MAY, 7)] = "Defender's Day" + if year >= 2013: + self[date(year, MAY, 7)] = "Defender's Day" # Victory Day self[date(year, MAY, 9)] = "Victory Day" # Capital City Day - self[date(year, JUL, 6)] = "Capital City Day" - - # Kurban Ait - for hol_date in _islamic_to_gre(year, 12, 10): - self[hol_date] = "Kurban Ait" + if year >= 2009: + self[date(year, JUL, 6)] = "Capital City Day" # Constitution Day - self[date(year, AUG, 30)] = "Constitution Day" + if year >= 1996: + self[date(year, AUG, 30)] = "Constitution Day" # First President Day - self[date(year, DEC, 1)] = "First President Day" + if year >= 2013: + self[date(year, DEC, 1)] = "First President Day" # Independence Day (2 days) self[date(year, DEC, 16)] = "Independence Day" self[date(year, DEC, 17)] = "Independence Day Holiday" + if self.observed: + for k, v in list(self.items()): + if k.weekday() in WEEKEND and k.year == year: + next_workday = k + rd(days=+1) + while next_workday.weekday() in WEEKEND or self.get( + next_workday + ): + next_workday += rd(days=+1) + self[next_workday] = v + " (Observed)" + + # Kurban Ait + if year >= 2007: + for hol_date in _islamic_to_gre(year, 12, 10): + self[hol_date] = "Kurban Ait" + class KZ(Kazakhstan): pass diff --git a/test/countries/test_kazakhstan.py b/test/countries/test_kazakhstan.py index 51748ca13..a347466e3 100644 --- a/test/countries/test_kazakhstan.py +++ b/test/countries/test_kazakhstan.py @@ -9,36 +9,147 @@ # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) -import unittest -from datetime import date +from test.common import TestCase -import holidays +from holidays.countries.kazakhstan import Kazakhstan, KZ, KAZ -class TestKazakhstan(unittest.TestCase): +class TestKazakhstan(TestCase): def setUp(self): - self.holidays = holidays.KZ() + self.holidays = Kazakhstan() + + def test_country_aliases(self): + self.assertCountryAliases(Kazakhstan, KZ, KAZ) def test2020(self): - _holidays = [ - date(2020, 1, 1), - date(2020, 1, 2), - date(2020, 1, 3), - date(2020, 1, 7), - date(2020, 3, 8), - date(2020, 3, 21), - date(2020, 3, 22), - date(2020, 3, 23), - date(2020, 5, 1), - date(2020, 5, 7), - date(2020, 5, 9), - date(2020, 7, 6), - date(2020, 7, 31), - date(2020, 8, 30), - date(2020, 12, 1), - date(2020, 12, 16), - date(2020, 12, 17), - ] - - for kaz_hol in _holidays: - self.assertIn(kaz_hol, self.holidays) + self.assertHolidayDatesEqual( + Kazakhstan(years=2020), + "2020-01-01", + "2020-01-02", + "2020-01-07", + "2020-03-08", + "2020-03-09", + "2020-03-21", + "2020-03-22", + "2020-03-23", + "2020-03-24", + "2020-03-25", + "2020-05-01", + "2020-05-07", + "2020-05-09", + "2020-05-11", + "2020-07-06", + "2020-07-31", + "2020-08-30", + "2020-08-31", + "2020-12-01", + "2020-12-16", + "2020-12-17", + ) + + def test_christmas(self): + self.assertHoliday(*[f"{year}-01-07" for year in range(2007, 2100)]) + self.assertNoHoliday(*[f"{year}-01-07" for year in range(1990, 2007)]) + + def test_nauryz(self): + for year in range(2009, 2100): + self.assertHoliday( + f"{year}-03-21", f"{year}-03-22", f"{year}-03-23" + ) + for year in range(1990, 2009): + self.assertNoHoliday( + f"{year}-03-21", f"{year}-03-22", f"{year}-03-23" + ) + + def test_defenders_day(self): + self.assertHoliday(*[f"{year}-05-07" for year in range(2013, 2100)]) + self.assertNoHoliday(*[f"{year}-05-07" for year in range(1990, 2013)]) + + def test_capital_city_day(self): + self.assertHoliday(*[f"{year}-07-06" for year in range(2009, 2100)]) + self.assertNoHoliday(*[f"{year}-07-06" for year in range(1990, 2009)]) + + def test_constitution_day(self): + self.assertHoliday(*[f"{year}-08-30" for year in range(1996, 2100)]) + self.assertNoHoliday(*[f"{year}-08-30" for year in range(1990, 1996)]) + + def test_first_president_day(self): + self.assertHoliday(*[f"{year}-12-01" for year in range(2013, 2100)]) + self.assertNoHoliday(*[f"{year}-12-01" for year in range(1990, 2013)]) + + def test_kurban_ait(self): + self.assertHoliday( + "2007-12-20", + "2008-12-08", + "2009-11-27", + "2010-11-16", + "2011-11-06", + "2012-10-26", + "2013-10-15", + "2014-10-04", + "2015-09-23", + "2016-09-11", + "2017-09-01", + "2018-08-21", + "2019-08-11", + "2020-07-31", + "2021-07-20", + "2022-07-09", + "2023-06-28", + ) + + self.assertNoHoliday( + "2005-01-21", + "2006-01-10", + "2006-12-31", + ) + + def test_observed(self): + observed_holidays = ( + "2012-01-03", + "2012-01-09", + "2012-12-18", + "2013-03-25", + "2013-07-08", + "2013-12-02", + "2014-03-10", + "2014-03-24", + "2014-03-25", + "2014-07-07", + "2014-09-01", + "2015-03-09", + "2015-03-24", + "2015-03-25", + "2015-05-11", + "2015-08-31", + "2016-01-04", + "2016-05-02", + "2016-05-10", + "2016-12-19", + "2017-01-03", + "2017-01-09", + "2017-05-08", + "2017-12-18", + "2017-12-19", + "2018-01-08", + "2018-12-03", + "2018-12-18", + "2019-03-25", + "2019-07-08", + "2019-12-02", + "2020-03-09", + "2020-03-24", + "2020-03-25", + "2020-05-11", + "2020-08-31", + "2021-01-04", + "2021-03-24", + "2021-05-03", + "2021-05-10", + "2022-01-04", + "2022-05-02", + "2022-05-10", + "2022-12-19", + ) + self.assertHoliday(Kazakhstan(observed=True), *observed_holidays) + self.assertNoHoliday(Kazakhstan(observed=False), *observed_holidays) From f1111696e5e3dce078fc1733c147b955681e0e0f Mon Sep 17 00:00:00 2001 From: dr-prodigy <28216945+dr-prodigy@users.noreply.github.com> Date: Wed, 14 Dec 2022 13:23:48 +0100 Subject: [PATCH 069/138] CHANGES sync --- CHANGES | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGES b/CHANGES index bb1ad55f1..f11d0da44 100644 --- a/CHANGES +++ b/CHANGES @@ -4,7 +4,7 @@ Version 0.18 Released ???????? ??, ???? - Code refactoring #801 (arkid15r) -- Test refactoring / common functions #800, #830 (arkid15r) +- Test refactoring / common functions #800, #830, #844 (arkid15r) - Pre-commit reviews #786, #795 (KJhellico, arkid15r, dr-p) - Import cleanup, flake8 settings review #792 (arkid15r, KJhellico, dr-p) - Meeus algorithm for equinox and solstice calculation utils #828 (Nalguedo) @@ -19,6 +19,7 @@ Released ???????? ??, ???? - Vietnam: optimizations and refactoring #799 (KJhellico) - Malaysia: optimizations and refactoring #802 (KJhellico) - New Zealand: optimizations and refactoring #836 (KJhellico) +- Chile: optimizations #834 (KJhellico) + fixes #828 (Nalguedo) - Uruguay updates #809 (KJhellico) - Kazakhstan updates #829 (KJhellico) - Canada fixes #811 (jasonjensen) @@ -33,7 +34,6 @@ Released ???????? ??, ???? - India updates #825 (KJhellico) - NY Stock Exchange updates #833 (SnowX65, KJhellico) - Hungary fixes #826 (KJhellico) -- Chile fixes #828 (Nalguedo) Version 0.17.2 ============== From a4dab537ca45fe9ae4132affd92733cb5e233061 Mon Sep 17 00:00:00 2001 From: dr-prodigy <28216945+dr-prodigy@users.noreply.github.com> Date: Wed, 14 Dec 2022 18:25:19 +0100 Subject: [PATCH 070/138] Fix conflict solving errors --- holidays/countries/chile.py | 2 +- holidays/countries/new_zealand.py | 4 ++-- test/countries/test_chile.py | 3 +-- test/countries/test_kazakhstan.py | 3 +-- 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/holidays/countries/chile.py b/holidays/countries/chile.py index 4c6a1da0a..191ce1415 100644 --- a/holidays/countries/chile.py +++ b/holidays/countries/chile.py @@ -16,7 +16,7 @@ from dateutil.relativedelta import relativedelta as rd from holidays.constants import JAN, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC -from holidays.constants import TUE, THU, FRI, SAT, SUN +from holidays.constants import TUE, WED, THU, FRI, SAT, SUN from holidays.holiday_base import HolidayBase from holidays.utils import _AstroMeeusAlgorithms diff --git a/holidays/countries/new_zealand.py b/holidays/countries/new_zealand.py index 2955dd70c..9364fc1fe 100644 --- a/holidays/countries/new_zealand.py +++ b/holidays/countries/new_zealand.py @@ -12,11 +12,11 @@ from datetime import date from dateutil.easter import easter -from dateutil.relativedelta import MO, TU, WE, FR +from dateutil.relativedelta import MO, TU, WE from dateutil.relativedelta import relativedelta as rd from holidays.constants import JAN, FEB, MAR, APR, JUN, JUL, SEP, OCT, NOV -from holidays.constants import DEC, TUE, WED, THU +from holidays.constants import DEC, FRI from holidays.holiday_base import HolidayBase diff --git a/test/countries/test_chile.py b/test/countries/test_chile.py index 579502ae4..fc82da92e 100644 --- a/test/countries/test_chile.py +++ b/test/countries/test_chile.py @@ -9,9 +9,8 @@ # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) -from test.common import TestCase - from holidays.countries.chile import Chile, CL, CHL +from test.common import TestCase class TestChile(TestCase): diff --git a/test/countries/test_kazakhstan.py b/test/countries/test_kazakhstan.py index a347466e3..bd4806f68 100644 --- a/test/countries/test_kazakhstan.py +++ b/test/countries/test_kazakhstan.py @@ -9,9 +9,8 @@ # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) -from test.common import TestCase - from holidays.countries.kazakhstan import Kazakhstan, KZ, KAZ +from test.common import TestCase class TestKazakhstan(TestCase): From b56e6e13934a8a4ec577968309a26df915f5fcd4 Mon Sep 17 00:00:00 2001 From: ~Jhellico Date: Thu, 15 Dec 2022 16:37:09 +0200 Subject: [PATCH 071/138] South Africa: added 27 Dec 2002 public holiday (#848) --- holidays/countries/south_africa.py | 7 ++++--- test/countries/test_south_africa.py | 1 + 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/holidays/countries/south_africa.py b/holidays/countries/south_africa.py index f8c01d55c..ac1b4ec27 100644 --- a/holidays/countries/south_africa.py +++ b/holidays/countries/south_africa.py @@ -35,19 +35,20 @@ class SouthAfrica(HolidayBase): 2000: ((JAN, 2, "Y2K changeover"),), 2004: ((APR, 14, "National and provincial government elections"),), 2006: ((MAR, 1, "Local government elections"),), - 2008: ((MAY, 2, "By presidential decree"),), + 2008: ((MAY, 2, "Public holiday by presidential decree"),), 2009: ((APR, 22, "National and provincial government elections"),), 2011: ( (MAY, 18, "Local government elections"), - (DEC, 27, "By presidential decree"), + (DEC, 27, "Public holiday by presidential decree"), ), 2014: ((MAY, 7, "National and provincial government elections"),), 2016: ( (AUG, 3, "Local government elections"), - (DEC, 27, "By presidential decree"), + (DEC, 27, "Public holiday by presidential decree"), ), 2019: ((MAY, 8, "National and provincial government elections"),), 2021: ((NOV, 1, "Municipal elections"),), + 2022: ((DEC, 27, "Public holiday by presidential decree"),), } def _populate(self, year): diff --git a/test/countries/test_south_africa.py b/test/countries/test_south_africa.py index 3d01140f2..8d407c93d 100644 --- a/test/countries/test_south_africa.py +++ b/test/countries/test_south_africa.py @@ -51,6 +51,7 @@ def test_special_holidays(self): self.assertIn("2016-08-03", self.holidays) self.assertIn("2019-05-08", self.holidays) self.assertIn("2021-11-01", self.holidays) + self.assertIn("2022-12-27", self.holidays) def test_presidential(self): self.assertIn("2008-05-02", self.holidays) From 0bfc37e339068256424c1abac1209b07388e39b1 Mon Sep 17 00:00:00 2001 From: dr-prodigy <28216945+dr-prodigy@users.noreply.github.com> Date: Thu, 15 Dec 2022 15:43:02 +0100 Subject: [PATCH 072/138] CHANGES sync --- CHANGES | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index f11d0da44..211da3917 100644 --- a/CHANGES +++ b/CHANGES @@ -28,7 +28,7 @@ Released ???????? ??, ???? - Madagascar updates #818 (KJhellico) - Paraguay updates #819 (KJhellico) - United Kingdom updates #840 (KJhellico) -- South Africa: optimizations #820 (KJhellico) +- South Africa: optimizations and updates #820, #848 (KJhellico) - Switzerland: optimizations, fix #821 (KJhellico) - Angola: optimizations, fix #822, #835 (KJhellico) - India updates #825 (KJhellico) From 109ee99fd784115cfa14a790587447d0eab86dd7 Mon Sep 17 00:00:00 2001 From: ~Jhellico Date: Thu, 15 Dec 2022 17:46:43 +0200 Subject: [PATCH 073/138] Add Pakistan holidays (#847) --- README.rst | 5 +- holidays/countries/__init__.py | 1 + holidays/countries/pakistan.py | 225 ++++++++++++++++++++++++++++++++ test/countries/test_pakistan.py | 157 ++++++++++++++++++++++ 4 files changed, 387 insertions(+), 1 deletion(-) create mode 100644 holidays/countries/pakistan.py create mode 100644 test/countries/test_pakistan.py diff --git a/README.rst b/README.rst index 4227683fb..013c04ea5 100644 --- a/README.rst +++ b/README.rst @@ -106,7 +106,7 @@ Available Countries .. _ISO 3166-1 alpha-2 code: https://en.wikipedia.org/wiki/List_of_ISO_3166_country_codes -We currently support 96 countries. The standard way to refer to a country is by +We currently support 100 countries. The standard way to refer to a country is by using its `ISO 3166-1 alpha-2 code`_, the same used for domain names. The following countries and their subdivisions are available: @@ -325,6 +325,9 @@ following countries and their subdivisions are available: * - Norway - NO - None + * - Pakistan + - PK + - None * - Paraguay - PY - None diff --git a/holidays/countries/__init__.py b/holidays/countries/__init__.py index bc98604b1..a70bdd2ca 100644 --- a/holidays/countries/__init__.py +++ b/holidays/countries/__init__.py @@ -79,6 +79,7 @@ from .nigeria import NG, NGA, Nigeria from .north_macedonia import MK, MKD, NorthMacedonia from .norway import NO, NOR, Norway +from .pakistan import PAK, PK, Pakistan from .paraguay import PRY, PY, Paraguay from .peru import PE, PER, Peru from .poland import PL, POL, Poland diff --git a/holidays/countries/pakistan.py b/holidays/countries/pakistan.py new file mode 100644 index 000000000..7d96d1c71 --- /dev/null +++ b/holidays/countries/pakistan.py @@ -0,0 +1,225 @@ +# 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 (c) 2017-2022 +# ryanss (c) 2014-2017 +# Website: https://github.com/dr-prodigy/python-holidays +# License: MIT (see LICENSE file) + +from datetime import date +from typing import Dict, Tuple, List + +from dateutil.relativedelta import relativedelta as rd + +from holidays.constants import JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP +from holidays.constants import OCT, NOV, DEC +from holidays.holiday_base import HolidayBase +from holidays.utils import _islamic_to_gre + + +class Pakistan(HolidayBase): + country = "PK" + + def _populate(self, year): + def _add_holiday(dt: date, hol: str) -> None: + if dt.year == year: + self[dt] = hol + + if year <= 1947: + return + super()._populate(year) + + # Kashmir Solidarity Day + if year >= 1990: + self[date(year, FEB, 5)] = "Kashmir Solidarity Day" + + # Pakistan Day + if year >= 1956: + self[date(year, MAR, 23)] = "Pakistan Day" + + # Labour Day + if year >= 1972: + self[date(year, MAY, 1)] = "Labour Day" + + # Independence Day + self[date(year, AUG, 14)] = "Independence Day" + + # Iqbal Day + if year <= 2014 or year >= 2022: + self[date(year, NOV, 9)] = "Iqbal Day" + + # Quaid-e-Azam Day + self[date(year, DEC, 25)] = "Quaid-e-Azam Day" + + # Eid-ul-Fitr + # https://www.timeanddate.com/holidays/pakistan/eid-ul-fitr-1 + dates_obs = { + 2005: ((NOV, 4),), + 2006: ((OCT, 24),), + 2007: ((OCT, 13),), + 2008: ((OCT, 2),), + 2009: ((SEP, 21),), + 2010: ((SEP, 10),), + 2011: ((AUG, 31),), + 2012: ((AUG, 19),), + 2013: ((AUG, 8),), + 2014: ((JUL, 29),), + 2015: ((JUL, 17),), + 2016: ((JUL, 6),), + 2017: ((JUN, 26),), + 2018: ((JUN, 16),), + 2019: ((JUN, 5),), + 2020: ((MAY, 24),), + 2021: ((MAY, 13),), + 2022: ((MAY, 3),), + } + name = "Eid-ul-Fitr" + hol_dates = self._get_islamic_holiday(name, year, 10, 1, dates_obs) + for hol_date, hol_name in hol_dates: + _add_holiday(hol_date, hol_name) + _add_holiday(hol_date + rd(days=+1), hol_name) + _add_holiday(hol_date + rd(days=+2), hol_name) + + # Eid-ul-Adha + # https://www.timeanddate.com/holidays/pakistan/eid-ul-azha + dates_obs = { + 2005: ((JAN, 21),), + 2006: ( + (JAN, 10), + (DEC, 31), + ), + 2007: ((DEC, 20),), + 2008: ((DEC, 9),), + 2009: ((NOV, 28),), + 2010: ((NOV, 17),), + 2011: ((NOV, 7),), + 2012: ((OCT, 26),), + 2013: ((OCT, 15),), + 2014: ((OCT, 6),), + 2015: ((SEP, 24),), + 2016: ((SEP, 12),), + 2017: ((SEP, 2),), + 2018: ((AUG, 22),), + 2019: ((AUG, 12),), + 2020: ((JUL, 31),), + 2021: ((JUL, 21),), + 2022: ((JUL, 10),), + } + name = "Eid-ul-Adha" + hol_dates = self._get_islamic_holiday(name, year, 12, 10, dates_obs) + for hol_date, hol_name in hol_dates: + _add_holiday(hol_date, hol_name) + _add_holiday(hol_date + rd(days=+1), hol_name) + _add_holiday(hol_date + rd(days=+2), hol_name) + + # Eid Milad-un-Nabi, Birth of the Prophet + # https://www.timeanddate.com/holidays/pakistan/eid-milad-un-nabi + dates_obs = { + 2005: ((APR, 22),), + 2006: ((APR, 11),), + 2007: ((MAR, 31),), + 2008: ((MAR, 21),), + 2009: ((MAR, 9),), + 2010: ((MAR, 1),), + 2011: ((FEB, 17),), + 2012: ((FEB, 5),), + 2013: ((JAN, 24),), + 2014: ((JAN, 14),), + 2015: ((JAN, 4),), + 2016: ((DEC, 12),), + 2017: ((DEC, 1),), + 2018: ((NOV, 21),), + 2019: ((NOV, 10),), + 2020: ((OCT, 30),), + 2021: ((OCT, 19),), + 2022: ((OCT, 9),), + } + name = "Eid Milad-un-Nabi" + hol_dates = self._get_islamic_holiday(name, year, 3, 12, dates_obs) + for hol_date, hol_name in hol_dates: + _add_holiday(hol_date, hol_name) + + # Ashura + # https://www.timeanddate.com/holidays/pakistan/first-day-ashura + dates_obs = { + 2005: ((FEB, 18),), + 2006: ((FEB, 8),), + 2007: ((JAN, 28),), + 2008: ((JAN, 18),), + 2009: ( + (JAN, 6), + (DEC, 26), + ), + 2010: ((DEC, 16),), + 2011: ((DEC, 5),), + 2012: ((NOV, 23),), + 2013: ((NOV, 13),), + 2014: ((NOV, 3),), + 2015: ((OCT, 23),), + 2016: ((OCT, 11),), + 2017: ((SEP, 30),), + 2018: ((SEP, 21),), + 2019: ((SEP, 9),), + 2020: ((AUG, 29),), + 2021: ((AUG, 18),), + 2022: ((AUG, 9),), + } + name = "Ashura" + hol_dates = self._get_islamic_holiday(name, year, 1, 10, dates_obs) + for hol_date, hol_name in hol_dates: + _add_holiday(hol_date, hol_name) + _add_holiday(hol_date + rd(days=+1), hol_name) + + @staticmethod + def _get_islamic_holiday( + name: str, + year: int, + hmonth: int, + hday: int, + known_dates: Dict[int, Tuple[Tuple[int, int]]], + ) -> List[Tuple[date, str]]: + """ + Return the Gregorian dates of all instances of Islamic holiday + falling within specified and previous Gregorian year + (used to multi-day Islamic holidays). + If specified year is in known dates list, known date used, + else calculated date. + + :param name: + Holiday name + + :param year: + Gregorian year + + :param hmonth: + Hijri month of holiday + + :param hday: + Hijri day of holiday + + :param known_dates: + Known holiday dates list + + :return: + List of date-name pairs + """ + hol_dates: List[Tuple[date, str]] = [] + for yr in (year - 1, year): + if yr in known_dates: + for date_obs in known_dates[yr]: + hol_dates.append((date(yr, *date_obs), name)) + else: + for dt in _islamic_to_gre(yr, hmonth, hday): + hol_dates.append((dt, f"{name}* (*estimated)")) + return hol_dates + + +class PK(Pakistan): + pass + + +class PAK(Pakistan): + pass diff --git a/test/countries/test_pakistan.py b/test/countries/test_pakistan.py new file mode 100644 index 000000000..47e2707cd --- /dev/null +++ b/test/countries/test_pakistan.py @@ -0,0 +1,157 @@ +# 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 (c) 2017-2022 +# ryanss (c) 2014-2017 +# Website: https://github.com/dr-prodigy/python-holidays +# License: MIT (see LICENSE file) + +from datetime import date + +from dateutil.relativedelta import relativedelta as rd + +from holidays.countries.pakistan import Pakistan, PK, PAK +from test.common import TestCase + + +class TestPakistan(TestCase): + def setUp(self): + self.holidays = Pakistan() + + def test_country_aliases(self): + self.assertCountryAliases(Pakistan, PK, PAK) + + def test_no_holidays(self): + self.assertNoHolidays(Pakistan(years=1947)) + + def test_kashmir_day(self): + name = "Kashmir Solidarity Day" + for year in range(1990, 2050): + self.assertIn(name, Pakistan(years=year).get(f"{year}-02-05")) + for year in range(1948, 1990): + self.assertEqual(Pakistan(years=year).get_named(name), []) + + def test_pakistan_day(self): + name = "Pakistan Day" + for year in range(1956, 2050): + self.assertIn(name, Pakistan(years=year).get(f"{year}-03-23")) + for year in range(1948, 1956): + self.assertEqual(Pakistan(years=year).get_named(name), []) + + def test_labour_day(self): + name = "Labour Day" + for year in range(1972, 2050): + self.assertIn(name, Pakistan(years=year).get(f"{year}-05-01")) + for year in range(1948, 1972): + self.assertEqual(Pakistan(years=year).get_named(name), []) + + def test_independence_day(self): + name = "Independence Day" + for year in range(1948, 2050): + self.assertIn(name, Pakistan(years=year).get(f"{year}-08-14")) + + def test_iqbal_day(self): + name = "Iqbal Day" + for year in range(1948, 2015): + self.assertIn(name, Pakistan(years=year).get(f"{year}-11-09")) + for year in range(2022, 2050): + self.assertIn(name, Pakistan(years=year).get(f"{year}-11-09")) + for year in range(2015, 2022): + self.assertEqual(Pakistan(years=year).get_named(name), []) + + def test_quaid_e_azam_day(self): + name = "Quaid-e-Azam Day" + for year in range(1948, 2050): + self.assertIn(name, Pakistan(years=year).get(f"{year}-12-25")) + + def test_eid_ul_fitr(self): + name = "Eid-ul-Fitr" + for dt in ( + date(2000, 1, 8), + date(2000, 12, 27), + date(2001, 12, 16), + date(2002, 12, 5), + date(2003, 11, 25), + date(2004, 11, 14), + date(2005, 11, 4), + date(2006, 10, 24), + date(2013, 8, 8), + date(2019, 6, 5), + date(2020, 5, 24), + date(2021, 5, 13), + date(2022, 5, 3), + date(2023, 4, 21), + ): + self.assertHoliday(dt) + self.assertHoliday(dt + rd(days=+1)) + self.assertHoliday(dt + rd(days=+2)) + self.assertIn(name, self.holidays.get(dt)) + + def test_eid_ul_adha(self): + name = "Eid-ul-Adha" + for dt in ( + date(2000, 3, 16), + date(2001, 3, 5), + date(2002, 2, 22), + date(2003, 2, 11), + date(2004, 2, 1), + date(2005, 1, 21), + date(2006, 1, 10), + date(2006, 12, 31), + date(2013, 10, 15), + date(2019, 8, 12), + date(2020, 7, 31), + date(2021, 7, 21), + date(2022, 7, 10), + date(2023, 6, 28), + ): + self.assertHoliday(dt) + self.assertHoliday(dt + rd(days=+1)) + self.assertHoliday(dt + rd(days=+2)) + self.assertIn(name, self.holidays.get(dt)) + + def test_eid_milad_un_nabi(self): + name = "Eid Milad-un-Nabi" + for dt in ( + date(2000, 6, 14), + date(2001, 6, 4), + date(2002, 5, 24), + date(2003, 5, 13), + date(2004, 5, 1), + date(2005, 4, 22), + date(2006, 4, 11), + date(2013, 1, 24), + date(2019, 11, 10), + date(2020, 10, 30), + date(2021, 10, 19), + date(2022, 10, 9), + date(2023, 9, 27), + ): + self.assertHoliday(dt) + self.assertIn(name, self.holidays.get(dt)) + + def test_ashura(self): + name = "Ashura" + for dt in ( + date(2000, 4, 15), + date(2001, 4, 4), + date(2002, 3, 24), + date(2003, 3, 13), + date(2004, 3, 1), + date(2005, 2, 18), + date(2006, 2, 8), + date(2009, 1, 6), + date(2009, 12, 26), + date(2013, 11, 13), + date(2019, 9, 9), + date(2020, 8, 29), + date(2021, 8, 18), + date(2022, 8, 9), + date(2023, 7, 28), + ): + self.assertHoliday(dt) + self.assertHoliday(dt + rd(days=+1)) + self.assertIn(name, self.holidays.get(dt)) From 6c2fba7e4b477f105a9474e9226c3907f4964347 Mon Sep 17 00:00:00 2001 From: dr-prodigy <28216945+dr-prodigy@users.noreply.github.com> Date: Thu, 15 Dec 2022 16:47:57 +0100 Subject: [PATCH 074/138] CHANGES --- CHANGES | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES b/CHANGES index 211da3917..7ee7df38f 100644 --- a/CHANGES +++ b/CHANGES @@ -12,6 +12,7 @@ Released ???????? ??, ???? - Observed holidays calc optimizations #824 (KJhellico) - Special holidays refactoring for 13 countries #796 (arkid15r, KJhellico) - Support for Indonesia #787 (KJhellico) +- Support for Pakistan #847 (KJhellico) - Korea renamed to South Korea #797 (arkid15r) - Hong Kong optimizations #786 (KJhellico) - Korea fixes #791 (KJhellico) + test optimizations (dr-p) From 6a04aab15fc9d4a0dc422acb1f65e5441bfb0642 Mon Sep 17 00:00:00 2001 From: ~Jhellico Date: Fri, 16 Dec 2022 00:23:39 +0200 Subject: [PATCH 075/138] Added tests for _AstroMeeusAlgorithms (#851) --- holidays/utils.py | 17 +++++++------- test/test_utils.py | 55 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 9 deletions(-) create mode 100644 test/test_utils.py diff --git a/holidays/utils.py b/holidays/utils.py index b8aa63ca8..6c11f2ce1 100755 --- a/holidays/utils.py +++ b/holidays/utils.py @@ -904,9 +904,10 @@ def _corrections(self, jd: float) -> float: 16859.074, ] - S = 0.0 - for i in range(len(A)): - S += A[i] * math.cos(math.radians(B[i] + C[i] * T)) + S = sum( + a * math.cos(math.radians(b + c * T)) for a, b, c in zip(A, B, C) + ) + return jd + 0.00001 * S / dl def summer(self, year: int) -> float: @@ -948,15 +949,13 @@ def jd2date(self, jd: float) -> datetime: h = int(f * 24) m = int((f - h / 24.0) * 1440) - s = round((f - h / 24.0 - m / 1440.0) * 86400.0, 2) + s = round((f - h / 24.0 - m / 1440.0) * 86400.0) day = b - d - int(30.6001 * e) + year = c - 4716 if e < 14: mon = e - 1 else: mon = e - 13 - if mon > 2: - year = c - 4716 - else: - year = c - 4715 + year += 1 - return datetime(year, mon, day, h, m, int(s)) + return datetime(year, mon, day, h, m, s) diff --git a/test/test_utils.py b/test/test_utils.py new file mode 100644 index 000000000..035ffc8bb --- /dev/null +++ b/test/test_utils.py @@ -0,0 +1,55 @@ +# 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 (c) 2017-2022 +# ryanss (c) 2014-2017 +# Website: https://github.com/dr-prodigy/python-holidays +# License: MIT (see LICENSE file) + +import unittest +from datetime import datetime + +from holidays.utils import _AstroMeeusAlgorithms + + +class TestMeeus(unittest.TestCase): + def setUp(self): + self.meeus = _AstroMeeusAlgorithms() + + def test_jd2date(self): + self.assertEqual(self.meeus.jd2date(2299161.5), datetime(1582, 10, 16)) + self.assertEqual(self.meeus.jd2date(2299159.5), datetime(1582, 10, 4)) + self.assertEqual( + self.meeus.jd2date(2459929.187962963), + datetime(2022, 12, 15, 16, 30, 40), + ) + for mon, jd in enumerate( + ( + 2459580.5, + 2459611.5, + 2459639.5, + 2459670.5, + 2459700.5, + 2459731.5, + 2459761.5, + 2459792.5, + 2459823.5, + 2459853.5, + 2459884.5, + 2459914.5, + ), + 1, + ): + self.assertEqual(self.meeus.jd2date(jd), datetime(2022, mon, 1)) + + def test_summer(self): + for year, jd in ( + (1900, 2415192.402799466), + (2000, 2451716.5755480495), + (2022, 2459751.885369888), + (2100, 2488240.732588952), + ): + self.assertEqual(self.meeus.summer(year), jd) From 24441b60faa14ced9ce57ccb86dfae38c2a50c0c Mon Sep 17 00:00:00 2001 From: Arkadii Yakovets Date: Tue, 20 Dec 2022 09:13:32 -0800 Subject: [PATCH 076/138] Pin `coverage` version. (#862) Add a temporary version pin in order to fix GH CI/CD. --- requirements_dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements_dev.txt b/requirements_dev.txt index c68a2defb..cdba6e51e 100644 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -7,7 +7,7 @@ hijri_converter # test requirements pytest pytest-cov -coverage[toml] +coverage[toml]<7.0.0 pre-commit flake8 sphinx From f2d496d8e1b9ecc7f46629afa2e1c2d06ec4d4df Mon Sep 17 00:00:00 2001 From: Nalguedo Date: Tue, 20 Dec 2022 22:24:09 +0000 Subject: [PATCH 077/138] japan: refactor japanese equinox holidays Refactored japanese holidays to make use of Meeus algorithms Include pymeeus in requirements_dev.txt which was already a transitive dependency associated with convertdate Sort dependencies alphabetically in requirements_dev.txt --- holidays/countries/japan.py | 50 ++++++++++++------------------------ requirements_dev.txt | 11 ++++---- test/countries/test_japan.py | 15 +++++++++++ 3 files changed, 37 insertions(+), 39 deletions(-) diff --git a/holidays/countries/japan.py b/holidays/countries/japan.py index 665013455..f44272b6f 100644 --- a/holidays/countries/japan.py +++ b/holidays/countries/japan.py @@ -9,10 +9,13 @@ # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) -from datetime import date +from datetime import date, datetime +from dateutil import tz from dateutil.relativedelta import MO from dateutil.relativedelta import relativedelta as rd +from pymeeus.Epoch import Epoch +from pymeeus.Sun import Sun from holidays.constants import JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP from holidays.constants import OCT, NOV, DEC @@ -60,7 +63,12 @@ def _populate(self, year): self[date(year, FEB, 23)] = "天皇誕生日" # Vernal Equinox Day - self[self._vernal_equinox_day(year)] = "春分の日" + epoch = Sun.get_equinox_solstice(year, target="spring") + equinox = map(int, Epoch(epoch).get_full_date()) + adjusted_date = datetime(*equinox, tzinfo=tz.UTC).astimezone( + tz.gettz("Asia/Tokyo") + ) + self[date(year, MAR, adjusted_date.day)] = "春分の日" # Showa Emperor's Birthday, Greenery Day or Showa Day if year <= 1988: @@ -105,7 +113,12 @@ def _populate(self, year): self[date(year, SEP, 1) + rd(weekday=MO(+3))] = "敬老の日" # Autumnal Equinox Day - self[self._autumnal_equinox_day(year)] = "秋分の日" + epoch = Sun.get_equinox_solstice(year, target="autumn") + equinox = map(int, Epoch(epoch).get_full_date()) + adjusted_date = datetime(*equinox, tzinfo=tz.UTC).astimezone( + tz.gettz("Asia/Tokyo") + ) + self[date(year, SEP, adjusted_date.day)] = "秋分の日" # Health and Sports Day if 1966 <= year <= 1999: @@ -136,37 +149,6 @@ def _populate(self, year): # Substitute holidays self._add_substitute_holidays(year) - def _vernal_equinox_day(self, year): - day = 20 - if year % 4 == 0: - if year <= 1956: - day = 21 - elif year >= 2092: - day = 19 - elif ( - (year % 4 == 1 and year <= 1989) - or (year % 4 == 2 and year <= 2022) - or (year % 4 == 3 and year <= 2055) - ): - day = 21 - - return date(year, MAR, day) - - def _autumnal_equinox_day(self, year): - day = 22 - if ( - (year % 4 == 0 and year <= 2008) - or (year % 4 == 1 and year <= 2041) - or (year % 4 == 2 and year <= 2074) - ): - day = 23 - elif year % 4 == 3: - day = 23 - if year <= 1979: - day = 24 - - return date(year, SEP, day) - def _add_national_holidays(self, year): if year in { 1988, diff --git a/requirements_dev.txt b/requirements_dev.txt index cdba6e51e..88d15e133 100644 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -1,15 +1,16 @@ # package runtime requirements -python-dateutil convertdate>=2.3.0 -korean_lunar_calendar hijri_converter +korean_lunar_calendar +pymeeus +python-dateutil # test requirements -pytest -pytest-cov coverage[toml]<7.0.0 -pre-commit flake8 +pre-commit +pytest +pytest-cov sphinx tox diff --git a/test/countries/test_japan.py b/test/countries/test_japan.py index 3cfe92e44..2422cf900 100644 --- a/test/countries/test_japan.py +++ b/test/countries/test_japan.py @@ -201,6 +201,14 @@ def test_vernal_equinox_day(self): (2048, 3, 20), (2049, 3, 20), (2050, 3, 20), + (2051, 3, 21), + (2052, 3, 20), + (2055, 3, 21), + (2056, 3, 20), + (2092, 3, 19), + (2093, 3, 20), + (2096, 3, 19), + (2097, 3, 20), ): self.assertIn(date(*dt), self.holidays) self.assertIn(date(2092, 3, 19), self.holidays) @@ -451,6 +459,13 @@ def test_autumnal_equinox_day(self): (1994, 9, 23), (1995, 9, 23), (1996, 9, 23), + (2021, 9, 23), + (2024, 9, 22), + (2027, 9, 23), + (2056, 9, 22), + (2068, 9, 22), + (2087, 9, 23), + (2089, 9, 22), ): self.assertIn(date(*dt), self.holidays) self.assertEqual(self.holidays[date(*dt)], "秋分の日") From f23a3ac582f2c1c128486cf4ebb5b3f4f314a9fc Mon Sep 17 00:00:00 2001 From: ~Jhellico Date: Thu, 22 Dec 2022 18:56:44 +0200 Subject: [PATCH 078/138] NYSE: fix Election Day holiday (#853) --- holidays/financial/ny_stock_exchange.py | 12 ++++++------ test/financial/test_ny_stock_exchange.py | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/holidays/financial/ny_stock_exchange.py b/holidays/financial/ny_stock_exchange.py index 20383f08e..e3577f66f 100644 --- a/holidays/financial/ny_stock_exchange.py +++ b/holidays/financial/ny_stock_exchange.py @@ -12,7 +12,7 @@ from datetime import date, timedelta from dateutil.easter import easter -from dateutil.relativedelta import MO, TU, TH, FR +from dateutil.relativedelta import MO, TH, FR from dateutil.relativedelta import relativedelta as rd from holidays.constants import JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP @@ -123,12 +123,12 @@ def _populate(self, year): colday = date(year, OCT, 12) self._set_observed_date(colday, "Columbus Day") - # ELECTION DAY: first Tues in NOV + # ELECTION DAY: Tuesday after first Monday in November (2 U.S. Code §7) # closed until 1969, then closed pres years 1972-80 - if year <= 1968: - self[date(year, NOV, 1) + rd(weekday=TU(1))] = "Election Day" - elif year in {1972, 1976, 1980}: - self[date(year, NOV, 1) + rd(weekday=TU(1))] = "Election Day" + if year <= 1968 or year in {1972, 1976, 1980}: + self[ + date(year, NOV, 1) + rd(weekday=MO) + rd(days=+1) + ] = "Election Day" # VETERAN'S DAY: Nov 11 - closed 1918, 1921, 1934-1953 if year in {1918, 1921} or (1934 <= year <= 1953): diff --git a/test/financial/test_ny_stock_exchange.py b/test/financial/test_ny_stock_exchange.py index e173d2261..9c55091cc 100644 --- a/test/financial/test_ny_stock_exchange.py +++ b/test/financial/test_ny_stock_exchange.py @@ -248,7 +248,7 @@ def test_columbusday(self): def test_electionday(self): for dt in [ - date(1887, NOV, 1), + date(1887, NOV, 8), date(1901, NOV, 5), date(1902, NOV, 4), date(1920, NOV, 2), From 958b51744794eb4dd802a93b74a26335b84b0e99 Mon Sep 17 00:00:00 2001 From: Arkadii Yakovets Date: Thu, 22 Dec 2022 08:59:31 -0800 Subject: [PATCH 079/138] Fix South Korea deprecation warnings. (#854) --- holidays/countries/south_korea.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/holidays/countries/south_korea.py b/holidays/countries/south_korea.py index 1e6d8fa96..6bbb1a03c 100644 --- a/holidays/countries/south_korea.py +++ b/holidays/countries/south_korea.py @@ -286,9 +286,9 @@ def __init__(self, *args, **kwargs) -> None: super().__init__(*args, **kwargs) -class KR(Korea): +class KR(SouthKorea): pass -class KOR(Korea): +class KOR(SouthKorea): pass From 2e8607fd870fdad1bffb8731e63eeaf86d1d24ac Mon Sep 17 00:00:00 2001 From: taljishi Date: Wed, 14 Dec 2022 13:41:21 +0300 Subject: [PATCH 080/138] Create bahrain.py --- holidays/countries/bahrain.py | 177 ++++++++++++++++++++++++++++++++++ 1 file changed, 177 insertions(+) create mode 100644 holidays/countries/bahrain.py diff --git a/holidays/countries/bahrain.py b/holidays/countries/bahrain.py new file mode 100644 index 000000000..1efcc21ba --- /dev/null +++ b/holidays/countries/bahrain.py @@ -0,0 +1,177 @@ +# 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 (c) 2017-2022 +# ryanss (c) 2014-2017 +# Website: https://github.com/dr-prodigy/python-holidays +# License: MIT (see LICENSE file) + +from datetime import date + +from dateutil.relativedelta import relativedelta as rd + +from holidays.constants import ( + FRI, + SAT, + JAN, + APR, + MAY, + JUN, + JUL, + AUG, + SEP, + NOV, + DEC, +) +from holidays.holiday_base import HolidayBase +from holidays.utils import _islamic_to_gre + +WEEKEND = (FRI, SAT) + +class Bahrain(HolidayBase): + """ + Bahrain holidays + + # Holidays based on the Islamic Calendar are estimated (and so denoted), + # as are announced each year and based on moon sightings: + # - Eid Al Fitr* + # - Eid Al Adha* + # - Al Hijra New Year* + # - Ashoora* + # - Prophets Birthday* + # *only if hijri-converter library is installed, otherwise a warning is + # raised that this holiday is missing. hijri-converter requires + # Python >= 3.6 + Primary sources: + https://www.cbb.gov.bh/official-bank-holidays/ + https://www.officeholidays.com/countries/bahrain/ + """ + + country = "BH" + + def _populate(self, year): + super()._populate(year) + + def _add_holiday(dt: date, hol: str) -> None: + """Only add if in current year; prevents adding holidays across + years (handles multi-day Islamic holidays that straddle Gregorian + years). + """ + if dt.year == year: + self[dt] = hol + + # New Year's Day + self[date(year, JAN, 1)] = "New Year's Day" + + # Labor day + self[date(year, MAY, 1)] = "Labour Day" + + # National Day + self[date(year, DEC, 16)] = "National Day" + self[date(year, DEC, 17)] = "National Day" + + # Eid Al Fitr + # Date is announced each year. Usually stretches along 3 or 4 days, + # in some instances prepending/appending a day or two + # before/after the official holiday. + fitr = "Eid Al Fitr" + if year in dates_obs: + for date_obs in dates_obs[year]: + hol_date = date(year, *date_obs) + self[hol_date] = fitr + self[hol_date + rd(days=1)] = f"{fitr} Holiday" + self[hol_date + rd(days=2)] = f"{fitr} Holiday" + else: + for yr in (year - 1, year): + for date_obs in _islamic_to_gre(yr, 10, 1): + hol_date = date_obs + _add_holiday(hol_date, f"{fitr}* (*estimated)") + _add_holiday( + hol_date + rd(days=1), + f"{fitr} Holiday* (*estimated)", + ) + _add_holiday( + hol_date + rd(days=2), + f"{fitr} Holiday* (*estimated)", + ) + + # Eid Al Adha + # Date is announced each year. Usually stretches along 3 or 4 days, + # in some instances prepending/appending a day or two + # before/after the official holiday. + adha = "Eid Al Adha" + if year in dates_obs: + for date_obs in dates_obs[year]: + hol_date = date(year, *date_obs) + self[hol_date + rd(days=1)] = adha + self[hol_date + rd(days=2)] = f"{adha} Holiday" + self[hol_date + rd(days=3)] = f"{adha} Holiday" + else: + for yr in (year - 1, year): + for date_obs in _islamic_to_gre(yr, 12, 9): + hol_date = date_obs + _add_holiday( + hol_date + rd(days=1), f"{adha}* (*estimated)" + ) + _add_holiday( + hol_date + rd(days=2), + f"{adha}* Holiday* (*estimated)", + ) + _add_holiday( + hol_date + rd(days=3), + f"{adha} Holiday* (*estimated)", + ) + + # Al Hijra New Year + new_hijri_year = "Al Hijra New Year" + if year in dates_obs: + for date_obs in dates_obs[year]: + hol_date = date(year, *date_obs) + self[hol_date] = new_hijri_year + else: + for date_obs in _islamic_to_gre(year, 1, 1): + hol_date = date_obs + self[hol_date] = f"{new_hijri_year}* (*estimated)" + + # Ashoora + # Date is announced each year. Usually the 9th and 10th Day, + # of the month of Muharam + ashoora = "Ashoora" + if year in dates_obs: + for date_obs in dates_obs[year]: + hol_date = date(year, *date_obs) + self[hol_date + rd(days=9)] = ashoora + self[hol_date + rd(days=10)] = f"{ashoora} Holiday" + else: + for yr in (year - 1, year): + for date_obs in _islamic_to_gre(yr, 1, 9): + hol_date = date_obs + _add_holiday( + hol_date + rd(days=9), f"{ashoora}* (*estimated)" + ) + _add_holiday( + hol_date + rd(days=10), + f"{ashoora}* Holiday* (*estimated)", + ) + + # Prophets Birthday + mawlud = "Prophets Birthday" + if year in dates_obs: + for date_obs in dates_obs[year]: + hol_date = date(year, *date_obs) + self[hol_date] = mawlud + else: + for date_obs in _islamic_to_gre(year, 3, 12): + hol_date = date_obs + self[hol_date] = f"{mawlud}* (*estimated)" + + +class BH(Bahrain): + pass + + +class BAH(Bahrain): + pass From 943f4b37c1e56cd4dec3afda2273bcc1a6997b1a Mon Sep 17 00:00:00 2001 From: taljishi Date: Wed, 21 Dec 2022 12:00:33 +0300 Subject: [PATCH 081/138] Update bahrain.py --- holidays/countries/bahrain.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/holidays/countries/bahrain.py b/holidays/countries/bahrain.py index 1efcc21ba..0b32ff3f3 100644 --- a/holidays/countries/bahrain.py +++ b/holidays/countries/bahrain.py @@ -137,7 +137,7 @@ def _add_holiday(dt: date, hol: str) -> None: self[hol_date] = f"{new_hijri_year}* (*estimated)" # Ashoora - # Date is announced each year. Usually the 9th and 10th Day, + # Date is announced each year, for the 9th and 10th Day, # of the month of Muharam ashoora = "Ashoora" if year in dates_obs: From 6952c2c6ac8e79ed00f63ed645d531495bec5639 Mon Sep 17 00:00:00 2001 From: ~Jhellico Date: Tue, 27 Dec 2022 13:15:21 +0200 Subject: [PATCH 082/138] United States: (#857) --- holidays/countries/united_states.py | 295 +++++++++++---------------- test/countries/test_united_states.py | 9 +- 2 files changed, 130 insertions(+), 174 deletions(-) diff --git a/holidays/countries/united_states.py b/holidays/countries/united_states.py index ba8fb7f00..5d0b65f27 100644 --- a/holidays/countries/united_states.py +++ b/holidays/countries/united_states.py @@ -88,19 +88,28 @@ class UnitedStates(HolidayBase): "WY", ] + def _add_with_observed( + self, dt: date, name: str, before: bool = True, after: bool = True + ) -> None: + self[dt] = name + if not self.observed: + return + if dt.weekday() == SAT and before: + self[dt + rd(days=-1)] = f"{name} (Observed)" + elif dt.weekday() == SUN and after: + self[dt + rd(days=+1)] = f"{name} (Observed)" + def _populate(self, year): super()._populate(year) # New Year's Day - if year > 1870: + if year >= 1871: name = "New Year's Day" - self[date(year, JAN, 1)] = name - if self.observed and date(year, JAN, 1).weekday() == SUN: - self[date(year, JAN, 1) + rd(days=+1)] = name + " (Observed)" + self._add_with_observed(date(year, JAN, 1), name, before=False) # The following year's observed New Year's Day can be in this year # when it falls on a Friday (Jan 1st is a Saturday). if self.observed and date(year, DEC, 31).weekday() == FRI: - self[date(year, DEC, 31)] = name + " (Observed)" + self[date(year, DEC, 31)] = f"{name} (Observed)" # Epiphany if self.subdiv == "PR": @@ -111,31 +120,27 @@ def _populate(self, year): self[date(year, JAN, 6)] = "Three King's Day" # Lee Jackson Day - name = "Lee Jackson Day" - if self.subdiv == "VA": - if 2000 <= year <= 2020: - dt = ( - date(year, JAN, 1) - + rd(weekday=MO(+3)) - + rd(weekday=FR(-1)) - ) + if self.subdiv == "VA" and year <= 2020: + name = "Lee Jackson Day" + if year >= 2000: + dt = date(year, JAN, 1) + rd(weekday=MO(+3)) + rd(days=-3) self[dt] = name - elif 1983 <= year <= 2020: + elif year >= 1983: self[date(year, JAN, 1) + rd(weekday=MO(+3))] = name - elif 1889 <= year <= 2020: + elif year >= 1889: self[date(year, JAN, 19)] = name # Inauguration Day - if self.subdiv in {"DC", "LA", "MD", "VA"} and year >= 1789: - name = "Inauguration Day" - if (year - 1789) % 4 == 0 and year >= 1937: - self[date(year, JAN, 20)] = name - if date(year, JAN, 20).weekday() == SUN: - self[date(year, JAN, 21)] = name + " (Observed)" - elif (year - 1789) % 4 == 0: - self[date(year, MAR, 4)] = name - if date(year, MAR, 4).weekday() == SUN: - self[date(year, MAR, 5)] = name + " (Observed)" + if ( + self.subdiv in {"DC", "LA", "MD", "VA"} + and year >= 1789 + and (year - 1789) % 4 == 0 + ): + if year >= 1937: + dt = date(year, JAN, 20) + else: + dt = date(year, MAR, 4) + self._add_with_observed(dt, "Inauguration Day", before=False) # Martin Luther King Jr. Day if year >= 1986: @@ -151,22 +156,17 @@ def _populate(self, year): ) elif self.subdiv in {"AZ", "NH"}: name = "Dr. Martin Luther King Jr./Civil Rights Day" - elif self.subdiv == "GA" and year < 2012: + elif self.subdiv == "GA" and year <= 2011: name = "Robert E. Lee's Birthday" elif self.subdiv == "ID" and year >= 2006: name = "Martin Luther King Jr. - Idaho Human Rights Day" self[date(year, JAN, 1) + rd(weekday=MO(+3))] = name # Lincoln's Birthday - name = "Lincoln's Birthday" if ( self.subdiv in {"CT", "IA", "IL", "NJ", "NY"} and year >= 1971 ) or (self.subdiv == "CA" and 1971 <= year <= 2009): - self[date(year, FEB, 12)] = name - if self.observed and date(year, FEB, 12).weekday() == SAT: - self[date(year, FEB, 11)] = name + " (Observed)" - elif self.observed and date(year, FEB, 12).weekday() == SUN: - self[date(year, FEB, 13)] = name + " (Observed)" + self._add_with_observed(date(year, FEB, 12), "Lincoln's Birthday") # Susan B. Anthony Day if ( @@ -186,7 +186,7 @@ def _populate(self, year): elif self.subdiv in {"PR", "VI"}: name = "Presidents' Day" if self.subdiv not in {"DE", "FL", "GA", "NM", "PR"}: - if year > 1970: + if year >= 1971: self[date(year, FEB, 1) + rd(weekday=MO(+3))] = name elif year >= 1879: self[date(year, FEB, 22)] = name @@ -222,42 +222,38 @@ def _populate(self, year): # Evacuation Day if self.subdiv == "MA" and year >= 1901: name = "Evacuation Day" - self[date(year, MAR, 17)] = name - if self._is_weekend(year, MAR, 17): - self[date(year, MAR, 17) + rd(weekday=MO)] = ( - name + " (Observed)" - ) + dt = date(year, MAR, 17) + self[dt] = name + if self.observed and self._is_weekend(dt): + self[dt + rd(weekday=MO)] = f"{name} (Observed)" # Emancipation Day if self.subdiv == "PR": - self[date(year, MAR, 22)] = "Emancipation Day" - if self.observed and date(year, MAR, 22).weekday() == SUN: - self[date(year, MAR, 23)] = "Emancipation Day (Observed)" + self._add_with_observed( + date(year, MAR, 22), "Emancipation Day", before=False + ) # Prince Jonah Kuhio Kalanianaole Day if self.subdiv == "HI" and year >= 1949: - name = "Prince Jonah Kuhio Kalanianaole Day" - self[date(year, MAR, 26)] = name - if self.observed and date(year, MAR, 26).weekday() == SAT: - self[date(year, MAR, 25)] = name + " (Observed)" - elif self.observed and date(year, MAR, 26).weekday() == SUN: - self[date(year, MAR, 27)] = name + " (Observed)" + self._add_with_observed( + date(year, MAR, 26), "Prince Jonah Kuhio Kalanianaole Day" + ) # Seward's Day - name = "Seward's Day" - if self.subdiv == "AK" and year >= 1955: - self[date(year, APR, 1) + rd(days=-1, weekday=MO(-1))] = name - elif self.subdiv == "AK" and year >= 1918: - self[date(year, MAR, 30)] = name + if self.subdiv == "AK": + name = "Seward's Day" + if year >= 1955: + self[date(year, MAR, 31) + rd(weekday=MO(-1))] = name + elif year >= 1918: + self[date(year, MAR, 30)] = name # César Chávez Day name = "César Chávez Day" + dt = date(year, MAR, 31) if self.subdiv == "CA" and year >= 1995: - self[date(year, MAR, 31)] = name - if self.observed and date(year, MAR, 31).weekday() == SUN: - self[date(year, APR, 1)] = name + " (Observed)" + self._add_with_observed(dt, name, before=False) elif self.subdiv == "TX" and year >= 2000: - self[date(year, MAR, 31)] = name + self[dt] = name # Transfer Day if self.subdiv == "VI": @@ -265,18 +261,15 @@ def _populate(self, year): # Emancipation Day if self.subdiv == "DC" and year >= 2005: - name = "Emancipation Day" - self[date(year, APR, 16)] = name - if self.observed and date(year, APR, 16).weekday() == SAT: - self[date(year, APR, 15)] = name + " (Observed)" - elif self.observed and date(year, APR, 16).weekday() == SUN: - self[date(year, APR, 17)] = name + " (Observed)" + self._add_with_observed(date(year, APR, 16), "Emancipation Day") # Patriots' Day - if self.subdiv in {"MA", "ME"} and year >= 1969: - self[date(year, APR, 1) + rd(weekday=MO(+3))] = "Patriots' Day" - elif self.subdiv in {"MA", "ME"} and year >= 1894: - self[date(year, APR, 19)] = "Patriots' Day" + if self.subdiv in {"MA", "ME"}: + name = "Patriots' Day" + if year >= 1969: + self[date(year, APR, 1) + rd(weekday=MO(+3))] = name + elif year >= 1894: + self[date(year, APR, 19)] = name # Holy Thursday if self.subdiv == "VI": @@ -320,41 +313,36 @@ def _populate(self, year): self[date(year, APR, 21)] = "San Jacinto Day" # Arbor Day - if self.subdiv == "NE" and year >= 1989: - self[date(year, APR, 30) + rd(weekday=FR(-1))] = "Arbor Day" - elif self.subdiv == "NE" and year >= 1875: - self[date(year, APR, 22)] = "Arbor Day" + if self.subdiv == "NE": + name = "Arbor Day" + if year >= 1989: + self[date(year, APR, 30) + rd(weekday=FR(-1))] = name + elif year >= 1875: + self[date(year, APR, 22)] = name # Primary Election Day if self.subdiv == "IN" and ( (year >= 2006 and year % 2 == 0) or year >= 2015 ): - dt = date(year, MAY, 1) + rd(weekday=MO) - self[dt + rd(days=+1)] = "Primary Election Day" + self[ + (date(year, MAY, 1) + rd(weekday=MO) + rd(days=+1)) + ] = "Primary Election Day" # Truman Day if self.subdiv == "MO" and year >= 1949: - name = "Truman Day" - self[date(year, MAY, 8)] = name - if self.observed and date(year, MAY, 8).weekday() == SAT: - self[date(year, MAY, 7)] = name + " (Observed)" - elif self.observed and date(year, MAY, 8).weekday() == SUN: - self[date(year, MAY, 10)] = name + " (Observed)" + self._add_with_observed(date(year, MAY, 8), "Truman Day") # Memorial Day - if year > 1970: + if year >= 1971: self[date(year, MAY, 31) + rd(weekday=MO(-1))] = "Memorial Day" elif year >= 1888: self[date(year, MAY, 30)] = "Memorial Day" # Juneteenth Day - if year > 2020: - name = "Juneteenth National Independence Day" - self[date(year, JUN, 19)] = name - if self.observed and date(year, JUN, 19).weekday() == SAT: - self[date(year, JUN, 18)] = name + " (Observed)" - elif self.observed and date(year, JUN, 19).weekday() == SUN: - self[date(year, JUN, 20)] = name + " (Observed)" + if year >= 2021: + self._add_with_observed( + date(year, JUN, 19), "Juneteenth National Independence Day" + ) # Jefferson Davis Birthday name = "Jefferson Davis Birthday" @@ -364,37 +352,27 @@ def _populate(self, year): # Kamehameha Day if self.subdiv == "HI" and year >= 1872: name = "Kamehameha Day" - self[date(year, JUN, 11)] = name - if self.observed and year >= 2011: - if date(year, JUN, 11).weekday() == SAT: - self[date(year, JUN, 10)] = name + " (Observed)" - elif date(year, JUN, 11).weekday() == SUN: - self[date(year, JUN, 12)] = name + " (Observed)" + dt = date(year, JUN, 11) + if year >= 2011: + self._add_with_observed(dt, name) + else: + self[dt] = name + # Emancipation Day In Texas if self.subdiv == "TX" and year >= 1980: self[date(year, JUN, 19)] = "Emancipation Day In Texas" # West Virginia Day - name = "West Virginia Day" if self.subdiv == "WV" and year >= 1927: - self[date(year, JUN, 20)] = name - if self.observed and date(year, JUN, 20).weekday() == SAT: - self[date(year, JUN, 19)] = name + " (Observed)" - elif self.observed and date(year, JUN, 20).weekday() == SUN: - self[date(year, JUN, 21)] = name + " (Observed)" + self._add_with_observed(date(year, JUN, 20), "West Virginia Day") # Emancipation Day in US Virgin Islands if self.subdiv == "VI": self[date(year, JUL, 3)] = "Emancipation Day" # Independence Day - if year > 1870: - name = "Independence Day" - self[date(year, JUL, 4)] = name - if self.observed and date(year, JUL, 4).weekday() == SAT: - self[date(year, JUL, 4) + rd(days=-1)] = name + " (Observed)" - elif self.observed and date(year, JUL, 4).weekday() == SUN: - self[date(year, JUL, 4) + rd(days=+1)] = name + " (Observed)" + if year >= 1871: + self._add_with_observed(date(year, JUL, 4), "Independence Day") # Liberation Day (Guam) if self.subdiv == "GU" and year >= 1945: @@ -402,18 +380,13 @@ def _populate(self, year): # Pioneer Day if self.subdiv == "UT" and year >= 1849: - name = "Pioneer Day" - self[date(year, JUL, 24)] = name - if self.observed and date(year, JUL, 24).weekday() == SAT: - self[date(year, JUL, 24) + rd(days=-1)] = name + " (Observed)" - elif self.observed and date(year, JUL, 24).weekday() == SUN: - self[date(year, JUL, 24) + rd(days=+1)] = name + " (Observed)" + self._add_with_observed(date(year, JUL, 24), "Pioneer Day") # Constitution Day if self.subdiv == "PR": - self[date(year, JUL, 25)] = "Constitution Day" - if self.observed and date(year, JUL, 25).weekday() == SUN: - self[date(year, JUL, 26)] = "Constitution Day (Observed)" + self._add_with_observed( + date(year, JUL, 25), "Constitution Day", before=False + ) # Victory Day if self.subdiv == "RI" and year >= 1948: @@ -425,12 +398,9 @@ def _populate(self, year): # Bennington Battle Day if self.subdiv == "VT" and year >= 1778: - name = "Bennington Battle Day" - self[date(year, AUG, 16)] = name - if self.observed and date(year, AUG, 16).weekday() == SAT: - self[date(year, AUG, 15)] = name + " (Observed)" - elif self.observed and date(year, AUG, 16).weekday() == SUN: - self[date(year, AUG, 17)] = name + " (Observed)" + self._add_with_observed( + date(year, AUG, 16), "Bennington Battle Day" + ) # Lyndon Baines Johnson Day if self.subdiv == "TX" and year >= 1973: @@ -455,23 +425,14 @@ def _populate(self, year): # Alaska Day if self.subdiv == "AK" and year >= 1867: - name = "Alaska Day" - self[date(year, OCT, 18)] = name - if self.observed and date(year, OCT, 18).weekday() == SAT: - self[date(year, OCT, 18) + rd(days=-1)] = name + " (Observed)" - elif self.observed and date(year, OCT, 18).weekday() == SUN: - self[date(year, OCT, 18) + rd(days=+1)] = name + " (Observed)" + self._add_with_observed(date(year, OCT, 18), "Alaska Day") # Nevada Day if self.subdiv == "NV" and year >= 1933: dt = date(year, OCT, 31) if year >= 2000: dt += rd(weekday=FR(-1)) - self[dt] = "Nevada Day" - if self.observed and dt.weekday() == SAT: - self[dt + rd(days=-1)] = "Nevada Day (Observed)" - elif self.observed and dt.weekday() == SUN: - self[dt + rd(days=+1)] = "Nevada Day (Observed)" + self._add_with_observed(dt, "Nevada Day") # Liberty Day if self.subdiv == "VI": @@ -484,35 +445,32 @@ def _populate(self, year): and year >= 2008 and year % 2 == 0 ) or (self.subdiv in {"IN", "NY"} and year >= 2015): - dt = date(year, NOV, 1) + rd(weekday=MO) - self[dt + rd(days=+1)] = "Election Day" + self[ + date(year, NOV, 1) + rd(weekday=MO) + rd(days=+1) + ] = "Election Day" # All Souls' Day if self.subdiv == "GU": self[date(year, NOV, 2)] = "All Souls' Day" # Veterans Day - if year > 1953: + if year >= 1954: name = "Veterans Day" else: name = "Armistice Day" - if 1978 > year > 1970: + if 1971 <= year <= 1977: self[date(year, OCT, 1) + rd(weekday=MO(+4))] = name elif year >= 1938: - self[date(year, NOV, 11)] = name - if self.observed and date(year, NOV, 11).weekday() == SAT: - self[date(year, NOV, 11) + rd(days=-1)] = name + " (Observed)" - elif self.observed and date(year, NOV, 11).weekday() == SUN: - self[date(year, NOV, 11) + rd(days=+1)] = name + " (Observed)" + self._add_with_observed(date(year, NOV, 11), name) # Discovery Day if self.subdiv == "PR": - self[date(year, NOV, 19)] = "Discovery Day" - if self.observed and date(year, NOV, 19).weekday() == SUN: - self[date(year, NOV, 20)] = "Discovery Day (Observed)" + self._add_with_observed( + date(year, NOV, 19), "Discovery Day", before=False + ) # Thanksgiving - if year > 1870: + if year >= 1871: self[date(year, NOV, 1) + rd(weekday=TH(+4))] = "Thanksgiving" # Day After Thanksgiving @@ -536,14 +494,13 @@ def _populate(self, year): name = "Friday After Thanksgiving" if self.subdiv == "IN": name = "Lincoln's Birthday" - if self.subdiv == "MD" and year >= 2008: + if self.subdiv == "MD": name = "American Indian Heritage Day" if self.subdiv == "NV": name = "Family Day" if self.subdiv == "NM": name = "Presidents' Day" - dt = date(year, NOV, 1) + rd(weekday=TH(+4)) - self[dt + rd(days=+1)] = name + self[date(year, NOV, 1) + rd(weekday=TH(+4)) + rd(days=+1)] = name # Robert E. Lee's Birthday if self.subdiv == "GA" and year >= 1986: @@ -565,48 +522,42 @@ def _populate(self, year): or (self.subdiv == "WI" and year >= 2012) ): name = "Christmas Eve" - self[date(year, DEC, 24)] = name - name = name + " (Observed)" + dt = date(year, DEC, 24) + self[dt] = name # If on Friday, observed on Thursday - if self.observed and date(year, DEC, 24).weekday() == FRI: - self[date(year, DEC, 24) + rd(days=-1)] = name + if self.observed and dt.weekday() == FRI: + self[dt + rd(days=-1)] = f"{name} (Observed)" # If on Saturday or Sunday, observed on Friday - elif self.observed and self._is_weekend(year, DEC, 24): - self[date(year, DEC, 24) + rd(weekday=FR(-1))] = name + elif self.observed and self._is_weekend(dt): + self[dt + rd(weekday=FR(-1))] = f"{name} (Observed)" # Christmas Day - if year > 1870: - name = "Christmas Day" - self[date(year, DEC, 25)] = "Christmas Day" - if self.observed and date(year, DEC, 25).weekday() == SAT: - self[date(year, DEC, 25) + rd(days=-1)] = name + " (Observed)" - elif self.observed and date(year, DEC, 25).weekday() == SUN: - self[date(year, DEC, 25) + rd(days=+1)] = name + " (Observed)" + if year >= 1871: + self._add_with_observed(date(year, DEC, 25), "Christmas Day") # Day After Christmas + dt = date(year, DEC, 26) if self.subdiv == "NC" and year >= 2013: name = "Day After Christmas" - self[date(year, DEC, 26)] = name - name = name + " (Observed)" + self[dt] = name # If on Saturday or Sunday, observed on Monday - if self.observed and self._is_weekend(year, DEC, 26): - self[date(year, DEC, 26) + rd(weekday=MO)] = name + if self.observed and self._is_weekend(dt): + self[dt + rd(weekday=MO)] = f"{name} (Observed)" # If on Monday, observed on Tuesday - elif self.observed and date(year, DEC, 26).weekday() == MON: - self[date(year, DEC, 26) + rd(days=+1)] = name + elif self.observed and dt.weekday() == MON: + self[dt + rd(days=+1)] = f"{name} (Observed)" elif self.subdiv == "TX" and year >= 1981: - self[date(year, DEC, 26)] = "Day After Christmas" + self[dt] = "Day After Christmas" elif self.subdiv == "VI": - self[date(year, DEC, 26)] = "Christmas Second Day" + self[dt] = "Christmas Second Day" # New Year's Eve if (self.subdiv in {"KY", "MI"} and year >= 2013) or ( self.subdiv == "WI" and year >= 2012 ): - name = "New Year's Eve" - self[date(year, DEC, 31)] = name - if self.observed and date(year, DEC, 31).weekday() == SAT: - self[date(year, DEC, 30)] = name + " (Observed)" + self._add_with_observed( + date(year, DEC, 31), "New Year's Eve", before=True, after=False + ) class US(UnitedStates): diff --git a/test/countries/test_united_states.py b/test/countries/test_united_states.py index 1ef63c974..bd0cb846b 100644 --- a/test/countries/test_united_states.py +++ b/test/countries/test_united_states.py @@ -472,6 +472,10 @@ def test_patriots_day(self): self.assertNotIn(date(year, 4, 19), self.holidays) self.assertIn(date(year, 4, 19), me_holidays) self.assertIn(date(year, 4, 19), ma_holidays) + for year in range(1870, 1893): + self.assertNotIn(date(year, 4, 19), self.holidays) + self.assertNotIn(date(year, 4, 19), me_holidays) + self.assertNotIn(date(year, 4, 19), ma_holidays) for dt in [ date(1969, 4, 21), date(1974, 4, 15), @@ -593,6 +597,7 @@ def test_arbor_day(self): ]: self.assertNotIn(dt, self.holidays) self.assertIn(dt, ne_holidays) + self.assertNotIn(date(1874, 4, 22), ne_holidays) def test_primary_election_day(self): in_holidays = holidays.US(subdiv="IN") @@ -620,10 +625,10 @@ def test_truman_day(self): self.assertNotIn(dt + relativedelta(days=-1), mo_holidays) self.assertNotIn(dt + relativedelta(days=+1), mo_holidays) self.assertNotIn(date(2004, 5, 7), mo_holidays) - self.assertNotIn(date(2005, 5, 10), mo_holidays) + self.assertNotIn(date(2005, 5, 9), mo_holidays) mo_holidays.observed = True self.assertIn(date(2004, 5, 7), mo_holidays) - self.assertIn(date(2005, 5, 10), mo_holidays) + self.assertIn(date(2005, 5, 9), mo_holidays) def test_memorial_day(self): for dt in [ From 048c7b4e901cda8b8d0855c5c176fcfa256e7e62 Mon Sep 17 00:00:00 2001 From: ~Jhellico Date: Tue, 27 Dec 2022 13:19:03 +0200 Subject: [PATCH 083/138] Malaysia multi-day Islamic holidays fixed (#858) --- holidays/countries/malaysia.py | 57 ++++++++++++++++++--------------- test/countries/test_malaysia.py | 8 +++++ 2 files changed, 39 insertions(+), 26 deletions(-) diff --git a/holidays/countries/malaysia.py b/holidays/countries/malaysia.py index 2a3150261..953945893 100644 --- a/holidays/countries/malaysia.py +++ b/holidays/countries/malaysia.py @@ -103,6 +103,10 @@ def __init__( super().__init__(years, expand, observed, subdiv, prov, state) def _populate(self, year): + def _add_holiday(dt: date, hol: str) -> None: + if dt.year == year: + self[dt] = hol + super()._populate(year) estimated_suffix = "* (*estimated)" @@ -282,18 +286,19 @@ def _populate(self, year): 2022: ((MAY, 2),), } name = "Hari Raya Puasa" - if year in dates_obs: - hol_dates = [ - (date(year, *date_obs), "") for date_obs in dates_obs[year] - ] - else: - hol_dates = [ - (date_obs, estimated_suffix) - for date_obs in _islamic_to_gre(year, 10, 1) - ] + hol_dates = [] + for yr in (year - 1, year): + if yr in dates_obs: + for date_obs in dates_obs[yr]: + hol_dates.append((date(yr, *date_obs), "")) + else: + for date_obs in _islamic_to_gre(year, 10, 1): + hol_dates.append((date_obs, estimated_suffix)) for hol_date, hol_suffix in hol_dates: - self[hol_date] = name + hol_suffix - self[hol_date + rd(days=+1)] = "Second day of " + name + hol_suffix + _add_holiday(hol_date, f"{name}{hol_suffix}") + _add_holiday( + hol_date + rd(days=+1), f"Second day of {name}{hol_suffix}" + ) # Hari Raya Haji and Arafat Day. # Date of observance is announced yearly. @@ -325,24 +330,24 @@ def _populate(self, year): 2022: ((JUL, 10),), } name = "Hari Raya Haji" - prev_day_name = "Arafat Day" - if year in dates_obs: - hol_dates = [ - (date(year, *date_obs), "") for date_obs in dates_obs[year] - ] - else: - hol_dates = [ - (date_obs, estimated_suffix) - for date_obs in _islamic_to_gre(year, 12, 10) - ] + hol_dates = [] + for yr in (year - 1, year): + if yr in dates_obs: + for date_obs in dates_obs[yr]: + hol_dates.append((date(yr, *date_obs), "")) + else: + for date_obs in _islamic_to_gre(year, 12, 10): + hol_dates.append((date_obs, estimated_suffix)) for hol_date, hol_suffix in hol_dates: - self[hol_date] = name + hol_suffix + _add_holiday(hol_date, f"{name}{hol_suffix}") if self.subdiv == "TRG": # Arafat Day is one day before Eid al-Adha - self[hol_date + rd(days=-1)] = prev_day_name + hol_suffix + _add_holiday(hol_date + rd(days=-1), f"Arafat Day{hol_suffix}") if self.subdiv in {"KDH", "KTN", "PLS", "TRG"}: # Second day - self[hol_date + rd(days=+1)] = name + " Holiday" + hol_suffix + _add_holiday( + hol_date + rd(days=+1), f"{name} Holiday{hol_suffix}" + ) # ---------------------------------------------------------# # Holidays from the Sarawak Ordinance (not included above) # @@ -623,9 +628,9 @@ def _populate(self, year): in_lieu_date = hol_date + rd(days=+1) if not in_lieu_date: continue - while in_lieu_date in self: + while in_lieu_date.year == year and in_lieu_date in self: in_lieu_date += rd(days=+1) - self[in_lieu_date] = hol_name + " [In lieu]" + _add_holiday(in_lieu_date, f"{hol_name} [In lieu]") # The last two days in May (Pesta Kaamatan). # (Sarawak Act) diff --git a/test/countries/test_malaysia.py b/test/countries/test_malaysia.py index a3e52584e..4f29762b0 100644 --- a/test/countries/test_malaysia.py +++ b/test/countries/test_malaysia.py @@ -1109,6 +1109,7 @@ def test_KDH_holidays(self): state_holidays = self.kedah_holidays # Hari Raya Haji + self.assertIn(date(2006, 12, 31), state_holidays) self.assertIn(date(2018, 8, 22), state_holidays) self.assertIn(date(2019, 8, 11), state_holidays) self.assertIn(date(2020, 7, 31), state_holidays) @@ -1116,6 +1117,7 @@ def test_KDH_holidays(self): self.assertIn(date(2022, 7, 10), state_holidays) self.assertIn(date(2023, 6, 28), state_holidays) # Hari Raya Haji Holiday + self.assertIn(date(2007, 1, 1), state_holidays) self.assertIn(date(2018, 8, 23), state_holidays) self.assertIn(date(2019, 8, 12), state_holidays) self.assertIn(date(2020, 8, 1), state_holidays) @@ -1152,6 +1154,7 @@ def test_KTN_holidays(self): self.assertIn(date(2020, 11, 11), state_holidays) self.assertNotIn(date(2001, 11, 11), state_holidays) # Hari Raya Haji + self.assertIn(date(2006, 12, 31), state_holidays) self.assertIn(date(2018, 8, 22), state_holidays) self.assertIn(date(2019, 8, 11), state_holidays) self.assertIn(date(2020, 7, 31), state_holidays) @@ -1159,6 +1162,7 @@ def test_KTN_holidays(self): self.assertIn(date(2022, 7, 10), state_holidays) self.assertIn(date(2023, 6, 28), state_holidays) # Hari Raya Haji Holiday + self.assertIn(date(2007, 1, 1), state_holidays) self.assertIn(date(2018, 8, 23), state_holidays) self.assertIn(date(2019, 8, 12), state_holidays) self.assertIn(date(2020, 8, 1), state_holidays) @@ -1379,6 +1383,7 @@ def test_TRG_holidays(self): self.assertIn(date(2022, 7, 12), state_holidays) # In lieu self.assertIn(date(2023, 6, 27), state_holidays) # Hari Raya Haji + self.assertIn(date(2006, 12, 31), state_holidays) self.assertIn(date(2018, 8, 22), state_holidays) self.assertIn(date(2019, 8, 11), state_holidays) self.assertIn(date(2020, 7, 31), state_holidays) @@ -1386,6 +1391,7 @@ def test_TRG_holidays(self): self.assertIn(date(2022, 7, 10), state_holidays) self.assertIn(date(2023, 6, 28), state_holidays) # Hari Raya Haji Holiday + self.assertIn(date(2007, 1, 1), state_holidays) self.assertIn(date(2018, 8, 23), state_holidays) self.assertIn(date(2019, 8, 12), state_holidays) self.assertIn(date(2020, 8, 1), state_holidays) @@ -1534,6 +1540,7 @@ def test_PLS_holidays(self): state_holidays = self.perlis_holidays # Hari Raya Haji + self.assertIn(date(2006, 12, 31), state_holidays) self.assertIn(date(2018, 8, 22), state_holidays) self.assertIn(date(2019, 8, 11), state_holidays) self.assertIn(date(2020, 7, 31), state_holidays) @@ -1541,6 +1548,7 @@ def test_PLS_holidays(self): self.assertIn(date(2022, 7, 10), state_holidays) self.assertIn(date(2023, 6, 28), state_holidays) # Hari Raya Haji Holiday + self.assertIn(date(2007, 1, 1), state_holidays) self.assertIn(date(2018, 8, 23), state_holidays) self.assertIn(date(2019, 8, 12), state_holidays) self.assertIn(date(2019, 8, 13), state_holidays) # In lieu From d364fecb8f14ae5369652115bb03ddaacb957c17 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 27 Dec 2022 12:25:06 +0100 Subject: [PATCH 084/138] Bump actions/setup-python from 4.3.0 to 4.4.0 (#871) Bumps [actions/setup-python](https://github.com/actions/setup-python) from 4.3.0 to 4.4.0. - [Release notes](https://github.com/actions/setup-python/releases) - [Commits](https://github.com/actions/setup-python/compare/v4.3.0...v4.4.0) --- updated-dependencies: - dependency-name: actions/setup-python dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Maurizio Montel <28216945+dr-prodigy@users.noreply.github.com> --- .github/workflows/ci-cd.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml index 014f0921f..d99560a66 100644 --- a/.github/workflows/ci-cd.yml +++ b/.github/workflows/ci-cd.yml @@ -12,7 +12,7 @@ jobs: - name: Check out repo uses: actions/checkout@v3 - name: Set up Python - uses: actions/setup-python@v4.3.1 + uses: actions/setup-python@v4.4.0 - name: Run pre-commit uses: pre-commit/action@v3.0.0 @@ -28,7 +28,7 @@ jobs: steps: - uses: actions/checkout@v3 - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v4.3.1 + uses: actions/setup-python@v4.4.0 with: python-version: ${{ matrix.python-version }} cache: pip @@ -68,7 +68,7 @@ jobs: steps: - uses: actions/checkout@v3 - name: Set up Python 3.9 - uses: actions/setup-python@v4.3.1 + uses: actions/setup-python@v4.4.0 with: python-version: "3.10" - name: Install dependencies From 63956b2bb86a89fc17923f5dcf675efae1740c88 Mon Sep 17 00:00:00 2001 From: ~Jhellico Date: Tue, 27 Dec 2022 13:28:16 +0200 Subject: [PATCH 085/138] Kazakhstan: (#867) - update holidays relevance period - update holidays names --- holidays/countries/kazakhstan.py | 91 +++++++++++++++++-------------- test/countries/test_kazakhstan.py | 65 +++++++++++++--------- 2 files changed, 90 insertions(+), 66 deletions(-) diff --git a/holidays/countries/kazakhstan.py b/holidays/countries/kazakhstan.py index 3c352a747..3e633e947 100644 --- a/holidays/countries/kazakhstan.py +++ b/holidays/countries/kazakhstan.py @@ -13,14 +13,17 @@ from dateutil.relativedelta import relativedelta as rd -from holidays.constants import WEEKEND, JAN, MAR, MAY, JUL, AUG, DEC +from holidays.constants import JAN, MAR, MAY, JUL, AUG, OCT, DEC from holidays.holiday_base import HolidayBase from holidays.utils import _islamic_to_gre class Kazakhstan(HolidayBase): """ - https://www.officeholidays.com/countries/kazakhstan/2020 + 1. https://www.officeholidays.com/countries/kazakhstan/2020 + 2. https://egov.kz/cms/en/articles/holidays-calend + 3. https://en.wikipedia.org/wiki/Public_holidays_in_Kazakhstan + 4. https://adilet.zan.kz/rus/docs/Z010000267_/history """ country = "KZ" @@ -28,66 +31,74 @@ class Kazakhstan(HolidayBase): def _populate(self, year): super()._populate(year) - """Populate the holidays for a given year - - All holidays get observed on weekdays if they fall on weekends, but - this has not been implemented as yet. - """ # New Year's holiday (2 days) - self[date(year, JAN, 1)] = "New Year" - self[date(year, JAN, 2)] = "New Year Holiday" - - # Orthodox Christmas - if year >= 2007: - self[date(year, JAN, 7)] = "Orthodox Christmas" - - # Women's Day - self[date(year, MAR, 8)] = "Women's Day" - - # Nauryz Holiday (3 days) - if year >= 2009: - self[date(year, MAR, 21)] = "Nauryz" - self[date(year, MAR, 22)] = "Nauryz Holiday" - self[date(year, MAR, 23)] = "Nauryz Holiday" - - # Unity Day - self[date(year, MAY, 1)] = "Unity Day" - - # Defender's Day + name = "New Year" + self[date(year, JAN, 1)] = name + self[date(year, JAN, 2)] = name + + # International Women's Day + self[date(year, MAR, 8)] = "International Women's Day" + + # Nauryz holiday + name = "Nauryz holiday" + if year >= 2010: + self[date(year, MAR, 21)] = name + self[date(year, MAR, 22)] = name + self[date(year, MAR, 23)] = name + elif year >= 2002: + self[date(year, MAR, 22)] = name + + # Kazakhstan People Solidarity Holiday + self[date(year, MAY, 1)] = "Kazakhstan People Solidarity Holiday" + + # Defender of the Fatherland Day if year >= 2013: - self[date(year, MAY, 7)] = "Defender's Day" + self[date(year, MAY, 7)] = "Defender of the Fatherland Day" # Victory Day self[date(year, MAY, 9)] = "Victory Day" - # Capital City Day + # Capital Day if year >= 2009: - self[date(year, JUL, 6)] = "Capital City Day" + self[date(year, JUL, 6)] = "Capital Day" - # Constitution Day + # Constitution Day of the Republic of Kazakhstan if year >= 1996: - self[date(year, AUG, 30)] = "Constitution Day" + self[ + date(year, AUG, 30) + ] = "Constitution Day of the Republic of Kazakhstan" + + # Republic Day + if 1994 <= year <= 2008 or year >= 2022: + self[date(year, OCT, 25)] = "Republic Day" # First President Day - if year >= 2013: + if 2012 <= year <= 2021: self[date(year, DEC, 1)] = "First President Day" - # Independence Day (2 days) - self[date(year, DEC, 16)] = "Independence Day" - self[date(year, DEC, 17)] = "Independence Day Holiday" + # Kazakhstan Independence Day + name = "Kazakhstan Independence Day" + self[date(year, DEC, 16)] = name + if 2002 <= year <= 2021: + self[date(year, DEC, 17)] = name - if self.observed: + if self.observed and year >= 2002: for k, v in list(self.items()): - if k.weekday() in WEEKEND and k.year == year: + if self._is_weekend(k) and k.year == year: next_workday = k + rd(days=+1) - while next_workday.weekday() in WEEKEND or self.get( + while self._is_weekend(next_workday) or self.get( next_workday ): next_workday += rd(days=+1) self[next_workday] = v + " (Observed)" + # Nonworking days (without extending) + # Orthodox Christmas + if year >= 2006: + self[date(year, JAN, 7)] = "Orthodox Christmas" + # Kurban Ait - if year >= 2007: + if year >= 2006: for hol_date in _islamic_to_gre(year, 12, 10): self[hol_date] = "Kurban Ait" diff --git a/test/countries/test_kazakhstan.py b/test/countries/test_kazakhstan.py index bd4806f68..e14a44dcb 100644 --- a/test/countries/test_kazakhstan.py +++ b/test/countries/test_kazakhstan.py @@ -46,38 +46,61 @@ def test2020(self): "2020-12-17", ) - def test_christmas(self): - self.assertHoliday(*[f"{year}-01-07" for year in range(2007, 2100)]) - self.assertNoHoliday(*[f"{year}-01-07" for year in range(1990, 2007)]) - def test_nauryz(self): - for year in range(2009, 2100): + for year in range(2010, 2100): self.assertHoliday( f"{year}-03-21", f"{year}-03-22", f"{year}-03-23" ) - for year in range(1990, 2009): + for year in range(1990, 2002): self.assertNoHoliday( f"{year}-03-21", f"{year}-03-22", f"{year}-03-23" ) + for year in range(2002, 2010): + self.assertNoHoliday( + Kazakhstan(observed=False, years=year), + f"{year}-03-21", + f"{year}-03-23", + ) def test_defenders_day(self): - self.assertHoliday(*[f"{year}-05-07" for year in range(2013, 2100)]) - self.assertNoHoliday(*[f"{year}-05-07" for year in range(1990, 2013)]) + self.assertHoliday(f"{year}-05-07" for year in range(2013, 2100)) + self.assertNoHoliday(f"{year}-05-07" for year in range(1990, 2013)) def test_capital_city_day(self): - self.assertHoliday(*[f"{year}-07-06" for year in range(2009, 2100)]) - self.assertNoHoliday(*[f"{year}-07-06" for year in range(1990, 2009)]) + self.assertHoliday(f"{year}-07-06" for year in range(2009, 2100)) + self.assertNoHoliday(f"{year}-07-06" for year in range(1990, 2009)) def test_constitution_day(self): - self.assertHoliday(*[f"{year}-08-30" for year in range(1996, 2100)]) - self.assertNoHoliday(*[f"{year}-08-30" for year in range(1990, 1996)]) + self.assertHoliday(f"{year}-08-30" for year in range(1996, 2100)) + self.assertNoHoliday(f"{year}-08-30" for year in range(1990, 1996)) + + def test_republic_day(self): + self.assertHoliday(f"{year}-10-25" for year in range(1994, 2009)) + self.assertHoliday(f"{year}-10-25" for year in range(2022, 2100)) + self.assertNoHoliday(f"{year}-10-25" for year in range(2009, 2022)) def test_first_president_day(self): - self.assertHoliday(*[f"{year}-12-01" for year in range(2013, 2100)]) - self.assertNoHoliday(*[f"{year}-12-01" for year in range(1990, 2013)]) + self.assertHoliday(f"{year}-12-01" for year in range(2012, 2022)) + self.assertNoHoliday(f"{year}-12-01" for year in range(1990, 2012)) + self.assertNoHoliday(f"{year}-12-01" for year in range(2022, 2100)) + + def test_independence_day(self): + self.assertHoliday(f"{year}-12-16" for year in range(1990, 2100)) + self.assertHoliday(f"{year}-12-17" for year in range(2002, 2022)) + self.assertNoHoliday(f"{year}-12-17" for year in range(1990, 2002)) + for year in range(2022, 2100): + self.assertNoHoliday( + Kazakhstan(observed=False, years=year), f"{year}-12-17" + ) + + def test_christmas(self): + self.assertHoliday(f"{year}-01-07" for year in range(2006, 2100)) + self.assertNoHoliday(f"{year}-01-07" for year in range(1990, 2006)) def test_kurban_ait(self): self.assertHoliday( + "2006-01-10", + "2006-12-31", "2007-12-20", "2008-12-08", "2009-11-27", @@ -97,16 +120,9 @@ def test_kurban_ait(self): "2023-06-28", ) - self.assertNoHoliday( - "2005-01-21", - "2006-01-10", - "2006-12-31", - ) - def test_observed(self): observed_holidays = ( "2012-01-03", - "2012-01-09", "2012-12-18", "2013-03-25", "2013-07-08", @@ -126,11 +142,9 @@ def test_observed(self): "2016-05-10", "2016-12-19", "2017-01-03", - "2017-01-09", "2017-05-08", "2017-12-18", "2017-12-19", - "2018-01-08", "2018-12-03", "2018-12-18", "2019-03-25", @@ -148,7 +162,6 @@ def test_observed(self): "2022-01-04", "2022-05-02", "2022-05-10", - "2022-12-19", ) - self.assertHoliday(Kazakhstan(observed=True), *observed_holidays) - self.assertNoHoliday(Kazakhstan(observed=False), *observed_holidays) + self.assertHoliday(Kazakhstan(observed=True), observed_holidays) + self.assertNoHoliday(Kazakhstan(observed=False), observed_holidays) From 537cadbb3944a3a272aff527a92050a89f6ade8e Mon Sep 17 00:00:00 2001 From: ~Jhellico Date: Tue, 27 Dec 2022 13:30:12 +0200 Subject: [PATCH 086/138] New Zealand: observed holidays calc optimizations (#872) --- holidays/countries/new_zealand.py | 83 +++++++++++++++---------------- 1 file changed, 41 insertions(+), 42 deletions(-) diff --git a/holidays/countries/new_zealand.py b/holidays/countries/new_zealand.py index 9364fc1fe..8aa2214d1 100644 --- a/holidays/countries/new_zealand.py +++ b/holidays/countries/new_zealand.py @@ -71,6 +71,13 @@ def _get_nearest_monday(d: date) -> date: else: return d + rd(weekday=MO) + def _add_observed(self, dt: date) -> None: + if self.observed and self._is_weekend(dt): + obs_date = dt + rd(weekday=MO) + if self.get(obs_date): + obs_date += rd(days=+1) + self[obs_date] = f"{self[dt]} (Observed)" + def _populate(self, year): # Bank Holidays Act 1873 # The Employment of Females Act 1873 @@ -82,22 +89,19 @@ def _populate(self, year): # Waitangi Day Act 1960, 1976 # Sovereign's Birthday Observance Act 1937, 1952 # Holidays Act 1981, 2003 + if year <= 1893: return super()._populate(year) # New Year's Day - name = "New Year's Day" jan1 = date(year, JAN, 1) - self[jan1] = name - if self.observed and self._is_weekend(jan1): - self[date(year, JAN, 3)] = name + " (Observed)" + self[jan1] = "New Year's Day" - name = "Day after New Year's Day" jan2 = date(year, JAN, 2) - self[jan2] = name - if self.observed and self._is_weekend(jan2): - self[date(year, JAN, 4)] = name + " (Observed)" + self[jan2] = "Day after New Year's Day" + self._add_observed(jan1) + self._add_observed(jan2) # Waitangi Day if year >= 1974: @@ -106,40 +110,39 @@ def _populate(self, year): name = "Waitangi Day" feb6 = date(year, FEB, 6) self[feb6] = name - if self.observed and year >= 2014 and self._is_weekend(feb6): - self[feb6 + rd(weekday=MO)] = name + " (Observed)" + if year >= 2014: + self._add_observed(feb6) + + # Anzac Day + if year >= 1921: + apr25 = date(year, APR, 25) + self[apr25] = "Anzac Day" + if year >= 2014: + self._add_observed(apr25) # Easter easter_date = easter(year) self[easter_date + rd(days=-2)] = "Good Friday" self[easter_date + rd(days=+1)] = "Easter Monday" - # Anzac Day - if year >= 1921: - name = "Anzac Day" - apr25 = date(year, APR, 25) - self[apr25] = name - if self.observed and year >= 2014 and self._is_weekend(apr25): - self[apr25 + rd(weekday=MO)] = name + " (Observed)" - # Sovereign's Birthday - if 1952 <= year <= 2022: - name = "Queen's Birthday" - elif year >= 1902: + if year >= 1902: name = "King's Birthday" - if year == 1952: - self[date(year, JUN, 2)] = name # Elizabeth II - elif year >= 1938: - self[date(year, JUN, 1) + rd(weekday=MO)] = name # EII & GVI - elif year == 1937: - self[date(year, JUN, 9)] = name # George VI - elif year == 1936: - self[date(year, JUN, 23)] = name # Edward VIII - elif year >= 1912: - self[date(year, JUN, 3)] = name # George V - elif year >= 1902: - # http://paperspast.natlib.govt.nz/cgi-bin/paperspast?a=d&d=NZH19091110.2.67 - self[date(year, NOV, 9)] = name # Edward VII + if 1952 <= year <= 2022: + name = "Queen's Birthday" + if year == 1952: + self[date(year, JUN, 2)] = name # Elizabeth II + elif year >= 1938: + self[date(year, JUN, 1) + rd(weekday=MO)] = name # EII & GVI + elif year == 1937: + self[date(year, JUN, 9)] = name # George VI + elif year == 1936: + self[date(year, JUN, 23)] = name # Edward VIII + elif year >= 1912: + self[date(year, JUN, 3)] = name # George V + else: + # http://paperspast.natlib.govt.nz/cgi-bin/paperspast?a=d&d=NZH19091110.2.67 + self[date(year, NOV, 9)] = name # Edward VII # Matariki dates_obs = { @@ -186,18 +189,14 @@ def _populate(self, year): self[date(year, OCT, 1) + rd(weekday=WE(+2))] = name # Christmas Day - name = "Christmas Day" dec25 = date(year, DEC, 25) - self[dec25] = name - if self.observed and self._is_weekend(dec25): - self[date(year, DEC, 27)] = name + " (Observed)" + self[dec25] = "Christmas Day" # Boxing Day - name = "Boxing Day" dec26 = date(year, DEC, 26) - self[dec26] = name - if self.observed and self._is_weekend(dec26): - self[date(year, DEC, 28)] = name + " (Observed)" + self[dec26] = "Boxing Day" + self._add_observed(dec25) + self._add_observed(dec26) # Province Anniversary Day if self.subdiv in {"Auckland", "AUK", "Northland", "NTL"}: From cc88ce8281858c85a904c47a61f03c18157aa67c Mon Sep 17 00:00:00 2001 From: Arkadii Yakovets Date: Tue, 27 Dec 2022 03:39:00 -0800 Subject: [PATCH 087/138] Refactor imports (#870) * Reconfigure holidays imports. * Unify top level imports style * Limit imports for holiday_base and utils * Reorder country imports * Add Moldova alpha-3 code * Add tests * Redesign holidays imports tests. --- holidays/__init__.py | 10 +++---- holidays/countries/__init__.py | 40 ++++++++++++++-------------- holidays/countries/moldova.py | 4 +++ holidays/holiday_base.py | 2 +- holidays/utils.py | 25 +++++++++--------- setup.cfg | 1 + test/test_imports.py | 48 ++++++++++++++++++++++++++++++++++ 7 files changed, 90 insertions(+), 40 deletions(-) create mode 100644 test/test_imports.py diff --git a/holidays/__init__.py b/holidays/__init__.py index 429c3f430..bd54a97da 100644 --- a/holidays/__init__.py +++ b/holidays/__init__.py @@ -8,13 +8,11 @@ # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) -from holidays.constants import JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP -from holidays.constants import OCT, NOV, DEC + +from holidays.constants import * from holidays.countries import * from holidays.financial import * -from holidays.holiday_base import HolidayBase, HolidaySum -from holidays.utils import CountryHoliday, country_holidays -from holidays.utils import financial_holidays, list_supported_countries -from holidays.utils import list_supported_financial +from holidays.holiday_base import * +from holidays.utils import * __version__ = "0.18" diff --git a/holidays/countries/__init__.py b/holidays/countries/__init__.py index a70bdd2ca..0257feda1 100644 --- a/holidays/countries/__init__.py +++ b/holidays/countries/__init__.py @@ -9,28 +9,28 @@ # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) -from .angola import AGO, AO, Angola +from .angola import AO, AGO, Angola from .argentina import AR, ARG, Argentina -from .aruba import ABW, AW, Aruba +from .aruba import AW, ABW, Aruba from .australia import AU, AUS, Australia from .austria import AT, AUT, Austria from .azerbaijan import AZ, AZE, Azerbaijan from .bangladesh import BD, BGD, Bangladesh -from .belarus import BLR, BY, Belarus +from .belarus import BY, BLR, Belarus from .belgium import BE, BEL, Belgium from .bolivia import BO, BOL, Bolivia from .bosnia_and_herzegovina import BA, BIH, BosniaAndHerzegovina from .botswana import BW, BWA, Botswana from .brazil import BR, BRA, Brazil from .bulgaria import BG, BLG, Bulgaria -from .burundi import BDI, BI, Burundi +from .burundi import BI, BDI, Burundi from .canada import CA, CAN, Canada -from .chile import CHL, CL, Chile -from .china import CHN, CN, China +from .chile import CL, CHL, Chile +from .china import CN, CHN, China from .colombia import CO, COL, Colombia from .croatia import HR, HRV, Croatia from .cuba import CU, CUB, Cuba -from .curacao import CUW, CW, Curacao +from .curacao import CW, CUW, Curacao from .cyprus import CY, CYP, Cyprus from .czechia import CZ, CZE, Czechia from .denmark import DK, DNK, Denmark @@ -55,23 +55,23 @@ from .isle_of_man import IM, IMN, IsleOfMan from .israel import IL, ISR, Israel from .italy import IT, ITA, Italy -from .jamaica import JAM, JM, Jamaica +from .jamaica import JM, JAM, Jamaica from .japan import JP, JPN, Japan -from .kazakhstan import KAZ, KZ, Kazakhstan +from .kazakhstan import KZ, KAZ, Kazakhstan from .kenya import KE, KEN, Kenya from .latvia import LV, LVA, Latvia from .lesotho import LS, LSO, Lesotho from .liechtenstein import LI, LIE, Liechtenstein from .lithuania import LT, LTU, Lithuania from .luxembourg import LU, LUX, Luxembourg -from .madagascar import MDG, MG, Madagascar +from .madagascar import MG, MDG, Madagascar from .malawi import MW, MWI, Malawi from .malaysia import MY, MYS, Malaysia -from .malta import MLT, MT, Malta -from .mexico import MEX, MX, Mexico -from .moldova import MD, Moldova +from .malta import MT, MLT, Malta +from .mexico import MX, MEX, Mexico +from .moldova import MD, MDA, Moldova from .morocco import MA, MOR, Morocco -from .mozambique import MOZ, MZ, Mozambique +from .mozambique import MZ, MOZ, Mozambique from .namibia import NA, NAM, Namibia from .netherlands import NL, NLD, Netherlands from .new_zealand import NZ, NZL, NewZealand @@ -79,11 +79,11 @@ from .nigeria import NG, NGA, Nigeria from .north_macedonia import MK, MKD, NorthMacedonia from .norway import NO, NOR, Norway -from .pakistan import PAK, PK, Pakistan -from .paraguay import PRY, PY, Paraguay +from .pakistan import PK, PAK, Pakistan +from .paraguay import PY, PRY, Paraguay from .peru import PE, PER, Peru from .poland import PL, POL, Poland -from .portugal import PRT, PT, Portugal +from .portugal import PT, PRT, Portugal from .romania import RO, ROU, Romania from .russia import RU, RUS, Russia from .saudi_arabia import SA, SAU, SaudiArabia @@ -92,7 +92,7 @@ from .slovakia import SK, SVK, Slovakia from .slovenia import SI, SVN, Slovenia from .south_africa import ZA, ZAF, SouthAfrica -from .south_korea import KOR, KR, Korea, SouthKorea +from .south_korea import KR, KOR, Korea, SouthKorea from .spain import ES, ESP, Spain from .sweden import SE, SWE, Sweden from .switzerland import CH, CHE, Switzerland @@ -101,9 +101,9 @@ from .turkey import TR, TUR, Turkey from .ukraine import UA, UKR, Ukraine from .united_arab_emirates import AE, ARE, UnitedArabEmirates -from .united_kingdom import GB, GBR, UK, UnitedKingdom +from .united_kingdom import GB, UK, GBR, UnitedKingdom from .united_states import US, USA, UnitedStates -from .uruguay import URY, UY, Uruguay +from .uruguay import UY, URY, Uruguay from .uzbekistan import UZ, UZB, Uzbekistan from .venezuela import VE, VEN, Venezuela from .vietnam import VN, VNM, Vietnam diff --git a/holidays/countries/moldova.py b/holidays/countries/moldova.py index cd4f2a3f9..6181d6813 100644 --- a/holidays/countries/moldova.py +++ b/holidays/countries/moldova.py @@ -71,3 +71,7 @@ def _populate(self, year): class MD(Moldova): pass + + +class MDA(Moldova): + pass diff --git a/holidays/holiday_base.py b/holidays/holiday_base.py index 08f3330d4..05d8c2ab9 100644 --- a/holidays/holiday_base.py +++ b/holidays/holiday_base.py @@ -9,7 +9,7 @@ # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) -# from __future__ import annotations # add in Python 3.7 +__all__ = ("DateLike", "HolidayBase", "HolidaySum") import warnings from datetime import date, datetime, timedelta diff --git a/holidays/utils.py b/holidays/utils.py index 6c11f2ce1..16586f8d6 100755 --- a/holidays/utils.py +++ b/holidays/utils.py @@ -9,7 +9,13 @@ # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) -# from __future__ import annotations # add in Python 3.7 +__all__ = ( + "CountryHoliday", + "country_holidays", + "financial_holidays", + "list_supported_countries", + "list_supported_financial", +) import inspect import math @@ -21,8 +27,7 @@ from hijri_converter import convert from hijri_converter.ummalqura import GREGORIAN_RANGE -import holidays.countries -import holidays.financial +from holidays import countries, financial from holidays.holiday_base import HolidayBase @@ -170,9 +175,7 @@ def country_holidays( See documentation for examples. """ try: - country_classes = inspect.getmembers( - holidays.countries, inspect.isclass - ) + country_classes = inspect.getmembers(countries, inspect.isclass) country_class = next( obj for name, obj in country_classes if name == country ) @@ -231,9 +234,7 @@ def financial_holidays( examples. """ try: - financial_classes = inspect.getmembers( - holidays.financial, inspect.isclass - ) + financial_classes = inspect.getmembers(financial, inspect.isclass) financial_class = next( obj for name, obj in financial_classes if name == market ) @@ -282,9 +283,7 @@ def list_supported_countries() -> Dict[str, List[str]]: """ return { cls.country: cls.subdivisions - for name, cls in inspect.getmembers( - holidays.countries, inspect.isclass - ) + for name, cls in inspect.getmembers(countries, inspect.isclass) if len(name) == 2 and issubclass(cls, HolidayBase) } @@ -299,7 +298,7 @@ def list_supported_financial() -> Dict[str, List[str]]: """ return { cls.market: cls.subdivisions - for _, cls in inspect.getmembers(holidays.financial, inspect.isclass) + for _, cls in inspect.getmembers(financial, inspect.isclass) if issubclass(cls, HolidayBase) } diff --git a/setup.cfg b/setup.cfg index b6f1d7d5d..fbb99b785 100644 --- a/setup.cfg +++ b/setup.cfg @@ -48,6 +48,7 @@ per-file-ignores = holidays/countries/__init__.py:F401 holidays/financial/__init__.py:F401 test/test_holiday_base.py:E203 + test/test_imports.py:F401 [rstcheck] ignore_language = python diff --git a/test/test_imports.py b/test/test_imports.py new file mode 100644 index 000000000..c12c337b1 --- /dev/null +++ b/test/test_imports.py @@ -0,0 +1,48 @@ +# 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 (c) 2017-2022 +# ryanss (c) 2014-2017 +# Website: https://github.com/dr-prodigy/python-holidays +# License: MIT (see LICENSE file) + +import holidays +from test.common import TestCase + + +class TestHolidaysImports(TestCase): + def assertImport(self, name): + self.assertTrue( + hasattr(holidays, name), + f"Import error: `from holidays import {name}`", + ) + + def test_constants(self): + for name in ( + "MON", + "TUE", + "WED", + "THU", + "FRI", + "SAT", + "SUN", + "WEEKEND", + ): + self.assertImport(name) + + def test_holidays_base(self): + for name in ("DateLike", "HolidayBase", "HolidaySum"): + self.assertImport(name) + + def test_utils(self): + for name in ( + "CountryHoliday", + "country_holidays", + "financial_holidays", + "list_supported_countries", + "list_supported_financial", + ): + self.assertImport(name) From 3577523b1a27695526f1676822d33690afe9f792 Mon Sep 17 00:00:00 2001 From: ~Jhellico Date: Tue, 27 Dec 2022 13:46:46 +0200 Subject: [PATCH 088/138] Added Armenia holidays (#875) * Added Armenia holidays * Update test/countries/test_armenia.py Co-authored-by: Arkadii Yakovets Co-authored-by: Maurizio Montel <28216945+dr-prodigy@users.noreply.github.com> Co-authored-by: Arkadii Yakovets --- README.rst | 5 +- holidays/countries/__init__.py | 1 + holidays/countries/armenia.py | 108 +++++++++++++++++++++++++++++++++ test/countries/test_armenia.py | 91 +++++++++++++++++++++++++++ 4 files changed, 204 insertions(+), 1 deletion(-) create mode 100644 holidays/countries/armenia.py create mode 100644 test/countries/test_armenia.py diff --git a/README.rst b/README.rst index 013c04ea5..4f249dee7 100644 --- a/README.rst +++ b/README.rst @@ -106,7 +106,7 @@ Available Countries .. _ISO 3166-1 alpha-2 code: https://en.wikipedia.org/wiki/List_of_ISO_3166_country_codes -We currently support 100 countries. The standard way to refer to a country is by +We currently support 101 countries. The standard way to refer to a country is by using its `ISO 3166-1 alpha-2 code`_, the same used for domain names. The following countries and their subdivisions are available: @@ -124,6 +124,9 @@ following countries and their subdivisions are available: * - Argentina - AR - None + * - Armenia + - AM + - None * - Aruba - AW - None diff --git a/holidays/countries/__init__.py b/holidays/countries/__init__.py index 0257feda1..8cb48c057 100644 --- a/holidays/countries/__init__.py +++ b/holidays/countries/__init__.py @@ -11,6 +11,7 @@ from .angola import AO, AGO, Angola from .argentina import AR, ARG, Argentina +from .armenia import AM, ARM, Armenia from .aruba import AW, ABW, Aruba from .australia import AU, AUS, Australia from .austria import AT, AUT, Austria diff --git a/holidays/countries/armenia.py b/holidays/countries/armenia.py new file mode 100644 index 000000000..769870ed7 --- /dev/null +++ b/holidays/countries/armenia.py @@ -0,0 +1,108 @@ +# 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 (c) 2017-2022 +# ryanss (c) 2014-2017 +# Website: https://github.com/dr-prodigy/python-holidays +# License: MIT (see LICENSE file) + +from datetime import date + +from holidays.constants import JAN, MAR, APR, MAY, JUL, SEP, DEC +from holidays.holiday_base import HolidayBase + + +class Armenia(HolidayBase): + """ + https://en.wikipedia.org/wiki/Public_holidays_in_Armenia + http://www.parliament.am/legislation.php?sel=show&ID=1274&lang=arm&enc=utf8 + https://www.arlis.am/documentview.aspx?docid=259 + """ + + country = "AM" + + def _populate(self, year): + + if year <= 1990: + return + super()._populate(year) + + # New Year's Day + name = "Ամանոր [New Year's Day]" + self[date(year, JAN, 1)] = name + self[date(year, JAN, 2)] = name + + # Christmas and Epiphany Day + self[ + date(year, JAN, 6) + ] = "Սուրբ Ծնունդ եւ Հայտնություն [Christmas and Epiphany Day]" + + if 2010 <= year <= 2021: + # New Year's holidays and Christmas Eve + self[date(year, JAN, 3)] = name + self[date(year, JAN, 4)] = name + self[date(year, JAN, 5)] = "նախածննդյան տոներ [Christmas Eve]" + + # The Day of Remembrance of the Dead + self[ + date(year, JAN, 7) + ] = "Մեռելոց հիշատակի օր [The Day of Remembrance of the Dead]" + + # Army Day + if year >= 2003: + self[date(year, JAN, 28)] = "Բանակի օր [Army Day]" + + # Women's Day + self[date(year, MAR, 8)] = "Կանանց տոն [Women's Day]" + + # Motherhood and Beauty Day + if 1994 <= year <= 2001: + self[ + date(year, APR, 7) + ] = "Մայրության և գեղեցկության տոն [Motherhood and Beauty Day]" + + # Armenian Genocide Remembrance Day + self[ + date(year, APR, 24) + ] = "Եղեռնի զոհերի հիշատակի օր [Armenian Genocide Remembrance Day]" + + # Labour Day + if year >= 2001: + name = ( + "Աշխատավորների համերաշխության միջազգային օր " + "[International Day of Workers' Solidarity]" + ) + if year >= 2002: + name = "Աշխատանքի օր [Labour Day]" + self[date(year, MAY, 1)] = name + + # Victory and Peace Day + if year >= 1995: + self[ + date(year, MAY, 9) + ] = "Հաղթանակի և Խաղաղության տոն [Victory and Peace Day]" + + # Republic Day + self[date(year, MAY, 28)] = "Հանրապետության օր [Republic Day]" + + # Constitution Day + if year >= 1996: + self[date(year, JUL, 5)] = "Սահմանադրության օր [Constitution Day]" + + # Independence Day + if year >= 1992: + self[date(year, SEP, 21)] = "Անկախության օր [Independence Day]" + + # New Year's Eve + self[date(year, DEC, 31)] = "Ամանոր [New Year's Eve]" + + +class AM(Armenia): + pass + + +class ARM(Armenia): + pass diff --git a/test/countries/test_armenia.py b/test/countries/test_armenia.py new file mode 100644 index 000000000..227fbf57c --- /dev/null +++ b/test/countries/test_armenia.py @@ -0,0 +1,91 @@ +# 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 (c) 2017-2022 +# ryanss (c) 2014-2017 +# Website: https://github.com/dr-prodigy/python-holidays +# License: MIT (see LICENSE file) + +from holidays.countries.armenia import AM, ARM, Armenia +from test.common import TestCase + + +class TestArmenia(TestCase): + def setUp(self): + self.holidays = Armenia() + + def test_country_aliases(self): + self.assertCountryAliases(Armenia, AM, ARM) + + def test_no_holidays(self): + self.assertNoHolidays(Armenia(years=1990)) + + def test_new_year_christmas(self): + for year in range(1991, 2100): + self.assertHoliday( + f"{year}-01-01", + f"{year}-01-02", + f"{year}-01-06", + f"{year}-12-31", + ) + for year in range(2010, 2022): + self.assertHoliday( + f"{year}-01-03", + f"{year}-01-04", + f"{year}-01-05", + f"{year}-01-07", + ) + for year in range(1991, 2010): + self.assertNoHoliday( + f"{year}-01-03", + f"{year}-01-04", + f"{year}-01-05", + f"{year}-01-07", + ) + for year in range(2022, 2100): + self.assertNoHoliday( + f"{year}-01-03", + f"{year}-01-04", + f"{year}-01-05", + f"{year}-01-07", + ) + + def test_army_day(self): + self.assertHoliday(f"{year}-01-28" for year in range(2003, 2100)) + self.assertNoHoliday(f"{year}-01-28" for year in range(1991, 2003)) + + def test_women_day(self): + self.assertHoliday(f"{year}-03-08" for year in range(1991, 2100)) + + def test_motherhood_and_beauty_day(self): + self.assertHoliday(f"{year}-04-07" for year in range(1994, 2002)) + self.assertNoHoliday(f"{year}-04-07" for year in range(1991, 1994)) + self.assertNoHoliday(f"{year}-04-07" for year in range(2002, 2100)) + + def test_genocide_remembrance_day(self): + self.assertHoliday(f"{year}-04-24" for year in range(1991, 2100)) + + def test_labour_day(self): + self.assertHoliday(f"{year}-05-01" for year in range(2001, 2100)) + self.assertNoHoliday(f"{year}-05-01" for year in range(1991, 2001)) + may1_old_name = "International Day of Workers' Solidarity" + self.assertIn(may1_old_name, self.holidays["2001-05-01"]) + self.assertNotIn(may1_old_name, self.holidays["2002-05-01"]) + + def test_victory_day(self): + self.assertHoliday(f"{year}-05-09" for year in range(1995, 2100)) + self.assertNoHoliday(f"{year}-05-09" for year in range(1991, 1995)) + + def test_republic_day(self): + self.assertHoliday(f"{year}-05-28" for year in range(1991, 2100)) + + def test_constitution_day(self): + self.assertHoliday(f"{year}-07-05" for year in range(1996, 2100)) + self.assertNoHoliday(f"{year}-07-05" for year in range(1991, 1996)) + + def test_independence_day(self): + self.assertHoliday(f"{year}-09-21" for year in range(1992, 2100)) + self.assertNoHoliday(f"{year}-09-21" for year in range(1991, 1992)) From d5f6a9e723353c9d163c951ab9d464bdd029f753 Mon Sep 17 00:00:00 2001 From: ~Jhellico Date: Tue, 27 Dec 2022 13:51:52 +0200 Subject: [PATCH 089/138] Azerbaijan: full refactoring #859 --- holidays/countries/azerbaijan.py | 202 +++++++++++++++++--------- test/countries/test_azerbaijan.py | 231 ++++++++++++++++++++++++------ 2 files changed, 325 insertions(+), 108 deletions(-) diff --git a/holidays/countries/azerbaijan.py b/holidays/countries/azerbaijan.py index 66c0b7df5..c57b0145a 100644 --- a/holidays/countries/azerbaijan.py +++ b/holidays/countries/azerbaijan.py @@ -13,106 +13,178 @@ from dateutil.relativedelta import relativedelta as rd -from holidays.constants import JAN, MAR, MAY, JUN, OCT, NOV, DEC, SAT, SUN +from holidays.constants import JAN, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT +from holidays.constants import NOV, DEC from holidays.holiday_base import HolidayBase from holidays.utils import _islamic_to_gre -OBSERVED_SUFFIX = " (Observed)" - class Azerbaijan(HolidayBase): - """ - https://en.wikipedia.org/wiki/Public_holidays_in_Azerbaijan - """ + # [1] https://en.wikipedia.org/wiki/Public_holidays_in_Azerbaijan + # [2] https://az.wikipedia.org/wiki/Az%C9%99rbaycan%C4%B1n_d%C3%B6vl%C9%99t_bayramlar%C4%B1_v%C9%99_x%C3%BCsusi_g%C3%BCnl%C9%99ri # noqa: E501 + # [3] https://www.sosial.gov.az/en/prod-calendar country = "AZ" - def _add_observed(self, holiday: date) -> None: - if self.observed and self._is_weekend(holiday): - next_monday = holiday + rd(days=7 - holiday.weekday()) - if next_monday.year == holiday.year and not self.get( - next_monday, None + def _populate(self, year: int) -> None: + def _add_observed(hol_date: date, hol_name: str) -> None: + next_workday = hol_date + rd(days=+1) + while next_workday.year == year and ( + self._is_weekend(next_workday) or self.get(next_workday) ): - self[next_monday] = self[holiday] + OBSERVED_SUFFIX + next_workday += rd(days=+1) + _add_holiday(next_workday, f"{hol_name} (Observed)") - def _populate(self, year: int) -> None: + def _add_holiday(hol_date: date, hol_name: str) -> None: + if hol_date.year == year: + self[hol_date] = hol_name + + if year <= 1989: + return super()._populate(year) - # 1st of Jan - self[date(year, JAN, 1)] = "New Year's Day" - self[date(year, JAN, 2)] = "New Year's Day" - self._add_observed(date(year, JAN, 2)) + # New Year + name = "New Year's Day" + self[date(year, JAN, 1)] = name + if year >= 2006: + self[date(year, JAN, 2)] = name # Black January - self[date(year, JAN, 20)] = "Black January" - self._add_observed(date(year, JAN, 20)) + if year >= 2000: + self[date(year, JAN, 20)] = "Black January" # International Women's Day self[date(year, MAR, 8)] = "International Women's Day" - self._add_observed(date(year, MAR, 8)) # Novruz - for i in range(5): - self[date(year, MAR, 20 + i)] = "Novruz" - self._add_observed(date(year, MAR, 24)) + if year >= 2007: + for i in range(20, 25): + self[date(year, MAR, i)] = "Novruz" # Victory Day self[date(year, MAY, 9)] = "Victory Day over Fascism" - self._add_observed(date(year, MAY, 9)) # Republic Day - self[date(year, MAY, 28)] = "Republic Day" - self._add_observed(date(year, MAY, 28)) + if year >= 1992: + name = "Independence Day" if year >= 2021 else "Republic Day" + self[date(year, MAY, 28)] = name # National Salvation Day - self[date(year, JUN, 15)] = "National Salvation Day" - self._add_observed(date(year, JUN, 15)) + if year >= 1997: + self[date(year, JUN, 15)] = "National Salvation Day" + + # Memorial Day + if year >= 2021: + self[date(year, SEP, 27)] = "Memorial Day" # Azerbaijan Armed Forces Day - self[date(year, JUN, 26)] = "Azerbaijan Armed Forces Day" - self._add_observed(date(year, JUN, 26)) + if year >= 1992: + name = "Azerbaijan Armed Forces Day" + if year <= 1997: + self[date(year, OCT, 9)] = name + else: + self[date(year, JUN, 26)] = name + + # Independence Day + if year <= 2005: + self[date(year, OCT, 18)] = "Independence Day" # Victory Day - if year > 2020: + if year >= 2021: self[date(year, NOV, 8)] = "Victory Day" - self._add_observed(date(year, NOV, 8)) # Flag Day - self[date(year, NOV, 9)] = "Flag Day" - self._add_observed(date(year, NOV, 9)) + if year >= 2010: + self[date(year, NOV, 9)] = "Flag Day" # International Solidarity Day of Azerbaijanis - self[ - date(year, DEC, 31) - ] = "International Solidarity Day of Azerbaijanis" - self._add_observed(date(year, DEC, 31)) - # If the prior year's International Solidarity Day of Azerbaijanis - # falls on a Saturday or Monday, the 1st Monday of the current year is - # also a holiday. - if self.observed and date(year - 1, DEC, 31).weekday() == SUN: - self[date(year, JAN, 1)] = ( - "International Solidarity Day of Azerbaijanis" - + OBSERVED_SUFFIX - ) - elif self.observed and date(year - 1, DEC, 31).weekday() == SAT: - self[date(year, JAN, 2)] = ( - "International Solidarity Day of Azerbaijanis" - + OBSERVED_SUFFIX - ) - - # Ramadan - # Date of observance is announced yearly, This is an estimate. - hol_date = _islamic_to_gre(year, OCT, 1)[0] - self[hol_date] = "Ramadan" - self[hol_date + rd(days=1)] = "Ramadan" - self._add_observed(hol_date + rd(days=1)) - - # Festival of the Sacrifice - # Date of observance is announced yearly, This is an estimate. - hol_date = _islamic_to_gre(year, DEC, 10)[0] - self[hol_date] = "Festival of the Sacrifice" - self[hol_date + rd(days=1)] = "Festival of the Sacrifice" - self._add_observed(hol_date + rd(days=1)) + if year >= 1993: + name = "International Solidarity Day of Azerbaijanis" + self[date(year, DEC, 31)] = name + if self.observed and year >= 2006: + dt = date(year - 1, DEC, 31) + if self._is_weekend(dt): + _add_observed(dt, name) + + ramazan_dates_obs = { + 2011: ((AUG, 30),), + 2012: ((AUG, 19),), + 2013: ((AUG, 8),), + 2014: ((JUL, 28),), + 2015: ((JUL, 17),), + 2016: ((JUL, 6),), + 2017: ((JUN, 26),), + 2018: ((JUN, 15),), + 2019: ((JUN, 5),), + 2020: ((MAY, 24),), + 2021: ((MAY, 13),), + 2022: ((MAY, 2),), + 2023: ((APR, 21),), + } + + gurban_dates_obs = { + 2011: ((NOV, 6),), + 2012: ((OCT, 25),), + 2013: ((OCT, 15),), + 2014: ((OCT, 4),), + 2015: ((SEP, 24),), + 2016: ((SEP, 12),), + 2017: ((SEP, 1),), + 2018: ((AUG, 22),), + 2019: ((AUG, 12),), + 2020: ((JUL, 31),), + 2021: ((JUL, 20),), + 2022: ((JUL, 9),), + 2023: ((JUN, 28),), + } + + religious_holidays = ( + ("Ramazan Bayrami", 10, 1, ramazan_dates_obs), + ("Gurban Bayrami", 12, 10, gurban_dates_obs), + ) + if year >= 1993: + for name, hmonth, hday, dates_obs in religious_holidays: + for yr in (year - 1, year): + if yr in dates_obs: + for date_obs in dates_obs[yr]: + _add_holiday(date(yr, *date_obs), name) + _add_holiday( + date(yr, *date_obs) + rd(days=+1), name + ) + else: + for dt in _islamic_to_gre(yr, hmonth, hday): + _add_holiday(dt, f"{name}* (*estimated)") + _add_holiday( + dt + rd(days=+1), f"{name}* (*estimated)" + ) + + """ + [2]: + Article 105 of the Labor Code of the Republic of Azerbaijan states: + 5. If interweekly rest days and holidays that are not considered + working days overlap, that rest day is immediately transferred to + the next working day. + 6. If the holidays of Qurban and Ramadan coincide with another holiday + that is not considered a working day, the next working day is + considered a rest day. *(machine translated)* + """ + if self.observed and year >= 2006: + for k, v in list(self.items()): + if ( + k.year == year + and self._is_weekend(k) + and k + not in ( + date(year, JAN, 20), + date(year, SEP, 27), + ) + ): + _add_observed(k, v) + hol_names = self.get_list(k) + if len(hol_names) > 1 and " (Observed)" not in v: + for name in hol_names: + if name in {hol[0] for hol in religious_holidays}: + _add_observed(k, name) class AZ(Azerbaijan): diff --git a/test/countries/test_azerbaijan.py b/test/countries/test_azerbaijan.py index 8952bdf0b..c237574fd 100644 --- a/test/countries/test_azerbaijan.py +++ b/test/countries/test_azerbaijan.py @@ -9,55 +9,200 @@ # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) -import importlib.util -import unittest -from datetime import date +from holidays.countries.azerbaijan import AZ, AZE, Azerbaijan +from test.common import TestCase -import holidays -from holidays.constants import DEC, JAN, JUN, MAR, MAY, NOV - -class TestAzerbaijan(unittest.TestCase): +class TestAzerbaijan(TestCase): def setUp(self): - self.holidays = holidays.AZ() + self.holidays = Azerbaijan() - def test_observed_days(self): - self.assertIn(date(2021, JUN, 28), self.holidays) - self.assertIn(date(2021, MAY, 10), self.holidays) - self.assertIn(date(2021, JAN, 4), self.holidays) - self.assertIn(date(2020, MAY, 11), self.holidays) - self.assertIn(date(2020, MAR, 9), self.holidays) + def test_country_aliases(self): + self.assertCountryAliases(Azerbaijan, AZ, AZE) + + def test_no_holidays(self): + self.assertNoHolidays(Azerbaijan(years=1989)) + + def test_new_year(self): + self.assertHoliday(f"{year}-01-01" for year in range(1990, 2050)) + self.assertHoliday(f"{year}-01-02" for year in range(2006, 2050)) + self.assertNoHoliday(f"{year}-01-02" for year in range(1990, 2006)) + + def test_black_january(self): + self.assertHoliday(f"{year}-01-20" for year in range(2000, 2050)) + self.assertNoHoliday(f"{year}-01-20" for year in range(1990, 2000)) + + def test_int_women_day(self): + self.assertHoliday(f"{year}-03-08" for year in range(1990, 2050)) + + def test_novruz(self): + for year in range(2007, 2050): + self.assertHoliday( + f"{year}-03-20", + f"{year}-03-21", + f"{year}-03-22", + f"{year}-03-23", + f"{year}-03-24", + ) + for year in range(1990, 2007): + self.assertEqual(Azerbaijan(years=year).get_named("Novruz"), []) + + def test_victory_day_may(self): + self.assertHoliday(f"{year}-05-09" for year in range(1990, 2050)) + + def test_republic_day(self): + self.assertHoliday(f"{year}-05-28" for year in range(1992, 2050)) + self.assertNoHoliday(f"{year}-05-28" for year in range(1990, 1992)) + for year in range(1992, 2021): + self.assertIn( + "Republic Day", + Azerbaijan(years=year).get_list(f"{year}-05-28"), + ) + for year in range(2021, 2050): + self.assertIn( + "Independence Day", + Azerbaijan(years=year).get_list(f"{year}-05-28"), + ) + + def test_salvation_day(self): + self.assertHoliday(f"{year}-06-15" for year in range(1997, 2050)) + self.assertNoHoliday(f"{year}-06-15" for year in range(1990, 1997)) + + def test_memorial_day(self): + self.assertHoliday(f"{year}-09-27" for year in range(2021, 2050)) + self.assertNoHoliday(f"{year}-09-27" for year in range(1990, 2021)) + + def test_armed_forces_day(self): + self.assertHoliday(f"{year}-10-09" for year in range(1992, 1998)) + self.assertHoliday(f"{year}-06-26" for year in range(1998, 2050)) + self.assertNoHoliday(f"{year}-10-09" for year in range(1990, 1992)) + self.assertNoHoliday(f"{year}-06-26" for year in range(1990, 1998)) def test_victory_day(self): - self.assertNotIn(date(2020, NOV, 8), self.holidays) - self.assertIn(date(2021, NOV, 8), self.holidays) + self.assertHoliday(f"{year}-11-08" for year in range(2021, 2050)) + for year in range(1990, 2021): + self.assertNotIn( + "Victory Day", Azerbaijan(years=year).get_list(f"{year}-11-08") + ) - def test_2020(self): - self.assertIn(date(2020, JAN, 1), self.holidays) - self.assertIn(date(2020, JAN, 2), self.holidays) - self.assertIn(date(2020, JAN, 20), self.holidays) - self.assertIn(date(2020, MAR, 8), self.holidays) - for day in range(20, 25): - self.assertIn(date(2020, MAR, day), self.holidays) - self.assertIn(date(2020, MAY, 9), self.holidays) - self.assertIn(date(2020, JUN, 15), self.holidays) - self.assertIn(date(2020, JUN, 26), self.holidays) - self.assertNotIn(date(2020, NOV, 8), self.holidays) - self.assertIn(date(2020, NOV, 9), self.holidays) - self.assertIn(date(2020, DEC, 31), self.holidays) + def test_independence_day(self): + self.assertHoliday(f"{year}-10-18" for year in range(1990, 2006)) + self.assertNoHoliday(f"{year}-10-18" for year in range(2006, 2050)) + + def test_flag_day(self): + self.assertHoliday(f"{year}-11-09" for year in range(2010, 2050)) + self.assertNoHoliday(f"{year}-11-09" for year in range(1990, 2010)) + + def test_int_solidarity_day(self): + self.assertHoliday(f"{year}-12-31" for year in range(1993, 2050)) + self.assertNoHoliday(f"{year}-12-31" for year in range(1990, 1993)) def test_hijri_based(self): - if importlib.util.find_spec("hijri_converter"): - self.holidays = holidays.AZ(years=[2020]) - # Ramadan Feast - self.assertIn(date(2020, 5, 24), self.holidays) - self.assertIn(date(2020, 5, 25), self.holidays) - # Sacrifice Feast - self.assertIn(date(2020, 7, 31), self.holidays) - self.assertIn(date(2020, 8, 1), self.holidays) - self.assertIn(date(2020, 8, 3), self.holidays) # observed - - def test_dec_31_on_weekend(self): - """Test when Dec 31 of previous year is on a weekend.""" - self.assertIn(date(2023, JAN, 2), self.holidays) - self.assertIn(date(2024, JAN, 1), self.holidays) + # Ramazan Bayrami + self.assertHoliday( + "2020-05-24", + "2020-05-25", + "2021-05-13", + "2021-05-14", + "2022-05-02", + "2022-05-03", + ) + # Gurban Bayrami + self.assertHoliday( + "2020-07-31", + "2020-08-01", + "2020-08-03", + "2021-07-20", + "2021-07-21", + "2022-07-09", + "2022-07-10", + "2022-07-11", + "2022-07-12", + ) + + def test_observed_days(self): + observed_holidays = ( + "2020-03-09", + "2020-03-25", + "2020-03-26", + "2020-05-11", + "2020-05-26", + "2020-08-03", + "2021-01-04", + "2021-03-25", + "2021-03-26", + "2021-05-10", + "2021-06-28", + "2022-01-03", + "2022-01-04", + "2022-03-25", + "2022-05-30", + "2022-06-27", + "2022-07-11", + "2022-07-12", + ) + self.assertHoliday(Azerbaijan(observed=True), observed_holidays) + self.assertNoHoliday(Azerbaijan(observed=False), observed_holidays) + + def test_2020(self): + self.assertHolidayDatesEqual( + Azerbaijan(years=2020), + "2020-01-01", + "2020-01-02", + "2020-01-20", + "2020-03-08", + "2020-03-09", + "2020-03-20", + "2020-03-21", + "2020-03-22", + "2020-03-23", + "2020-03-24", + "2020-03-25", + "2020-03-26", + "2020-05-09", + "2020-05-11", + "2020-05-24", + "2020-05-25", + "2020-05-26", + "2020-05-28", + "2020-06-15", + "2020-06-26", + "2020-07-31", + "2020-08-01", + "2020-08-03", + "2020-11-09", + "2020-12-31", + ) + + def test_2022(self): + self.assertHolidayDatesEqual( + Azerbaijan(years=2022), + "2022-01-01", + "2022-01-02", + "2022-01-03", + "2022-01-04", + "2022-01-20", + "2022-03-08", + "2022-03-20", + "2022-03-21", + "2022-03-22", + "2022-03-23", + "2022-03-24", + "2022-03-25", + "2022-05-02", + "2022-05-03", + "2022-05-09", + "2022-05-28", + "2022-05-30", + "2022-06-15", + "2022-06-26", + "2022-06-27", + "2022-07-09", + "2022-07-10", + "2022-07-11", + "2022-07-12", + "2022-09-27", + "2022-11-08", + "2022-11-09", + "2022-12-31", + ) From 0dca7ac1f59845140e2976486f6a0e11f7451437 Mon Sep 17 00:00:00 2001 From: dr-prodigy <28216945+dr-prodigy@users.noreply.github.com> Date: Tue, 27 Dec 2022 12:56:20 +0100 Subject: [PATCH 090/138] CHANGES sync --- CHANGES | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/CHANGES b/CHANGES index 7ee7df38f..8a09b7e9a 100644 --- a/CHANGES +++ b/CHANGES @@ -3,7 +3,7 @@ Version 0.18 Released ???????? ??, ???? -- Code refactoring #801 (arkid15r) +- Code refactoring #801, #870 (arkid15r) - Test refactoring / common functions #800, #830, #844 (arkid15r) - Pre-commit reviews #786, #795 (KJhellico, arkid15r, dr-p) - Import cleanup, flake8 settings review #792 (arkid15r, KJhellico, dr-p) @@ -13,23 +13,27 @@ Released ???????? ??, ???? - Special holidays refactoring for 13 countries #796 (arkid15r, KJhellico) - Support for Indonesia #787 (KJhellico) - Support for Pakistan #847 (KJhellico) +- Support for Armenia #875 (KJhellico) - Korea renamed to South Korea #797 (arkid15r) -- Hong Kong optimizations #786 (KJhellico) +- Azerbaijan: refactoring #859 (KJhellico) +- Hong Kong: optimizations #786 (KJhellico) - Korea fixes #791 (KJhellico) + test optimizations (dr-p) - Zambia: optimizations and refactoring #798 (KJhellico) - Vietnam: optimizations and refactoring #799 (KJhellico) -- Malaysia: optimizations and refactoring #802 (KJhellico) +- Malaysia: optimizations, refactoring and fixes #802, #858 (KJhellico) - New Zealand: optimizations and refactoring #836 (KJhellico) - Chile: optimizations #834 (KJhellico) + fixes #828 (Nalguedo) - Uruguay updates #809 (KJhellico) -- Kazakhstan updates #829 (KJhellico) +- Kazakhstan updates #829, #867 (KJhellico) - Canada fixes #811 (jasonjensen) - Nigeria updates #823 (KJhellico) -- NY Stock Exchange update #817 (SnowX65) +- NY Stock Exchange updates #817, #853 (SnowX65, KJHellico) +- New Zealand optimizazions #872 (KJhellico) - Madagascar updates #818 (KJhellico) - Paraguay updates #819 (KJhellico) - United Kingdom updates #840 (KJhellico) - South Africa: optimizations and updates #820, #848 (KJhellico) +- US updates #857 (KJhellico) - Switzerland: optimizations, fix #821 (KJhellico) - Angola: optimizations, fix #822, #835 (KJhellico) - India updates #825 (KJhellico) From 068b1243d423ce100de2b1c80bf6116088a63b4c Mon Sep 17 00:00:00 2001 From: Pedro Baptista <32106544+Nalguedo@users.noreply.github.com> Date: Tue, 27 Dec 2022 14:20:24 +0000 Subject: [PATCH 091/138] Chile: refactor equinox holiday to use pymeeus (#863) --- holidays/countries/chile.py | 14 +-- holidays/utils.py | 169 +----------------------------------- test/test_utils.py | 55 ------------ 3 files changed, 10 insertions(+), 228 deletions(-) delete mode 100644 test/test_utils.py diff --git a/holidays/countries/chile.py b/holidays/countries/chile.py index 191ce1415..74902fa21 100644 --- a/holidays/countries/chile.py +++ b/holidays/countries/chile.py @@ -9,16 +9,18 @@ # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) -from datetime import date +from datetime import date, datetime +from dateutil import tz from dateutil.easter import easter from dateutil.relativedelta import MO from dateutil.relativedelta import relativedelta as rd +from pymeeus.Epoch import Epoch +from pymeeus.Sun import Sun from holidays.constants import JAN, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC from holidays.constants import TUE, WED, THU, FRI, SAT, SUN from holidays.holiday_base import HolidayBase -from holidays.utils import _AstroMeeusAlgorithms class Chile(HolidayBase): @@ -105,12 +107,14 @@ def _populate(self, year): if year == 2021: self[date(year, JUN, 21)] = name elif year >= 2022: - astro_alg = _AstroMeeusAlgorithms() - equinox = astro_alg.jd2date(astro_alg.summer(year)) + epoch = Sun.get_equinox_solstice(year, target="summer") # Received date for UTC timezone needs to be adjusted # to match Chile's timezone # https://www.feriadoschilenos.cl/#DiaNacionalDeLosPueblosIndigenasII - adjusted_date = equinox + rd(hours=-4) + equinox = map(int, Epoch(epoch).get_full_date()) + adjusted_date = datetime(*equinox, tzinfo=tz.UTC).astimezone( + tz.gettz("America/Santiago") + ) self[date(year, JUN, adjusted_date.day)] = name # Saint Peter and Saint Paul (Law 16.840, Law 18.432) diff --git a/holidays/utils.py b/holidays/utils.py index 16586f8d6..0e2843b55 100755 --- a/holidays/utils.py +++ b/holidays/utils.py @@ -18,9 +18,8 @@ ) import inspect -import math import warnings -from datetime import date, datetime, timedelta +from datetime import date, timedelta from functools import lru_cache from typing import Dict, Iterable, List, Optional, Union @@ -792,169 +791,3 @@ def thaipusam_date(self, year: int) -> date: span_days += self._lunar_month_days(year, m) span_days -= 15 return self.SOLAR_START_DATE + timedelta(span_days) - - -class _AstroMeeusAlgorithms: - def __init__(self) -> None: - """ - This class provides some of Jean Meeus' algorithms from the book - `Astronomical Algorithms` required for equinox and solstice - calculations. - The complete list of algorithm implementations is available here: - https://github.com/pavolgaj/AstroAlgorithms4Python - - Usage example: - - >>> from holidays.utils import _AstroMeeusAlgorithms - >>> astro_alg = _AstroMeeusAlgorithms() - >>> equinox = astro_alg.jd2date(astro_alg.summer(2026)) - >>> print(equinox) - 2026-06-21 05:26:04 - """ - - def _corrections(self, jd: float) -> float: - """ - Corrections to times of equinox/solstice - - :param jd: Julian day - :return: The Julian date of the next equinox or solstice. - """ - T = (jd - 2451545) / 36525.0 - - W = math.radians(35999.373 * T - 2.47) - dl = 1 + 0.0334 * math.cos(W) + 0.0007 * math.cos(2 * W) - - A = [ - 485, - 203, - 199, - 182, - 156, - 136, - 77, - 74, - 70, - 58, - 52, - 50, - 45, - 44, - 29, - 18, - 17, - 16, - 14, - 12, - 12, - 12, - 9, - 8, - ] - B = [ - 324.96, - 337.23, - 342.08, - 27.85, - 73.14, - 171.52, - 222.54, - 296.72, - 243.58, - 119.81, - 297.17, - 21.02, - 247.54, - 325.15, - 60.93, - 155.12, - 288.79, - 198.04, - 199.76, - 95.39, - 287.11, - 320.81, - 227.73, - 15.45, - ] - C = [ - 1934.136, - 32964.467, - 20.186, - 445267.112, - 45036.886, - 22518.443, - 65928.934, - 3034.906, - 9037.513, - 33718.147, - 150.678, - 2281.226, - 29929.562, - 31555.956, - 4443.417, - 67555.328, - 4562.452, - 62894.029, - 31436.921, - 14577.848, - 31931.756, - 34777.259, - 1222.114, - 16859.074, - ] - - S = sum( - a * math.cos(math.radians(b + c * T)) for a, b, c in zip(A, B, C) - ) - - return jd + 0.00001 * S / dl - - def summer(self, year: int) -> float: - """ - Calculates summer (June) solstice for given year - - :param year: The year for which you want to calculate the solstice - :return: The Julian date of the summer solstice. - """ - Y = (year - 2000) / 1000.0 - jd0 = ( - 2451716.56767 - + 365241.62603 * Y - + 0.00325 * Y**2 - + 0.00888 * Y**3 - - 0.00030 * Y**4 - ) - return self._corrections(jd0) - - def jd2date(self, jd: float) -> datetime: - """ - Convert a Julian date to a Gregorian date. - - :param jd: Julian date - :return: The datetime object of the Julian date. - """ - jd += 0.5 - z = int(jd) - f = jd % 1 - if z < 2299161: - a = z - else: - alp = int((z - 1867216.25) / 36524.25) - a = z + 1 + alp - int(alp / 4) - b = a + 1524 - c = int((b - 122.1) / 365.25) - d = int(365.25 * c) - e = int((b - d) / 30.6001) - - h = int(f * 24) - m = int((f - h / 24.0) * 1440) - s = round((f - h / 24.0 - m / 1440.0) * 86400.0) - day = b - d - int(30.6001 * e) - year = c - 4716 - if e < 14: - mon = e - 1 - else: - mon = e - 13 - year += 1 - - return datetime(year, mon, day, h, m, s) diff --git a/test/test_utils.py b/test/test_utils.py deleted file mode 100644 index 035ffc8bb..000000000 --- a/test/test_utils.py +++ /dev/null @@ -1,55 +0,0 @@ -# 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 (c) 2017-2022 -# ryanss (c) 2014-2017 -# Website: https://github.com/dr-prodigy/python-holidays -# License: MIT (see LICENSE file) - -import unittest -from datetime import datetime - -from holidays.utils import _AstroMeeusAlgorithms - - -class TestMeeus(unittest.TestCase): - def setUp(self): - self.meeus = _AstroMeeusAlgorithms() - - def test_jd2date(self): - self.assertEqual(self.meeus.jd2date(2299161.5), datetime(1582, 10, 16)) - self.assertEqual(self.meeus.jd2date(2299159.5), datetime(1582, 10, 4)) - self.assertEqual( - self.meeus.jd2date(2459929.187962963), - datetime(2022, 12, 15, 16, 30, 40), - ) - for mon, jd in enumerate( - ( - 2459580.5, - 2459611.5, - 2459639.5, - 2459670.5, - 2459700.5, - 2459731.5, - 2459761.5, - 2459792.5, - 2459823.5, - 2459853.5, - 2459884.5, - 2459914.5, - ), - 1, - ): - self.assertEqual(self.meeus.jd2date(jd), datetime(2022, mon, 1)) - - def test_summer(self): - for year, jd in ( - (1900, 2415192.402799466), - (2000, 2451716.5755480495), - (2022, 2459751.885369888), - (2100, 2488240.732588952), - ): - self.assertEqual(self.meeus.summer(year), jd) From a98e0eee6441bd8c7ed978fde4944c015883a8b4 Mon Sep 17 00:00:00 2001 From: dr-prodigy <28216945+dr-prodigy@users.noreply.github.com> Date: Tue, 27 Dec 2022 15:24:35 +0100 Subject: [PATCH 092/138] Add PyMeeus explicit dependency #863 --- CHANGES | 2 +- requirements_dev.txt | 7 ++++--- setup.cfg | 1 + 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/CHANGES b/CHANGES index 8a09b7e9a..2bf7f527a 100644 --- a/CHANGES +++ b/CHANGES @@ -7,7 +7,7 @@ Released ???????? ??, ???? - Test refactoring / common functions #800, #830, #844 (arkid15r) - Pre-commit reviews #786, #795 (KJhellico, arkid15r, dr-p) - Import cleanup, flake8 settings review #792 (arkid15r, KJhellico, dr-p) -- Meeus algorithm for equinox and solstice calculation utils #828 (Nalguedo) +- PyMeeus for equinox and solstice calculation #828, #863 (Nalguedo) - Easter holidays refactoring and unification #803 (KJhellico) - Observed holidays calc optimizations #824 (KJhellico) - Special holidays refactoring for 13 countries #796 (arkid15r, KJhellico) diff --git a/requirements_dev.txt b/requirements_dev.txt index cdba6e51e..151af5a1a 100644 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -1,8 +1,9 @@ # package runtime requirements -python-dateutil convertdate>=2.3.0 -korean_lunar_calendar -hijri_converter +hijri-converter +korean-lunar-calendar +python-dateutil +PyMeeus # test requirements pytest diff --git a/setup.cfg b/setup.cfg index fbb99b785..f1b7c64f7 100644 --- a/setup.cfg +++ b/setup.cfg @@ -34,6 +34,7 @@ install_requires = hijri-converter korean-lunar-calendar python-dateutil + PyMeeus python_requires = >=3.7 [options.package_data] From 244e2a72d9e4950016e12d75f0cda046fc23fe5e Mon Sep 17 00:00:00 2001 From: dr-prodigy <28216945+dr-prodigy@users.noreply.github.com> Date: Tue, 27 Dec 2022 15:58:21 +0100 Subject: [PATCH 093/138] setup-cfg-fmt update --- setup.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.cfg b/setup.cfg index f1b7c64f7..3ef21b8e1 100644 --- a/setup.cfg +++ b/setup.cfg @@ -30,11 +30,11 @@ packages = holidays/countries holidays/financial install_requires = + PyMeeus convertdate>=2.3.0 hijri-converter korean-lunar-calendar python-dateutil - PyMeeus python_requires = >=3.7 [options.package_data] From c65af3325130046d1257b84683537e69af43ec28 Mon Sep 17 00:00:00 2001 From: dr-prodigy <28216945+dr-prodigy@users.noreply.github.com> Date: Tue, 27 Dec 2022 16:25:17 +0100 Subject: [PATCH 094/138] v.0.18 --- CHANGES | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index 2bf7f527a..eb1c2d243 100644 --- a/CHANGES +++ b/CHANGES @@ -1,7 +1,7 @@ Version 0.18 ============ -Released ???????? ??, ???? +Released December 27, 2022 - Code refactoring #801, #870 (arkid15r) - Test refactoring / common functions #800, #830, #844 (arkid15r) From d78715bfd8b4a0476184c31a0b4bd52f248ea104 Mon Sep 17 00:00:00 2001 From: ~Jhellico Date: Fri, 23 Dec 2022 14:33:18 +0200 Subject: [PATCH 095/138] Singapore: - observed holidays calculation fixed - some holidays dates fixed --- holidays/countries/singapore.py | 55 +++++++------- test/countries/test_singapore.py | 126 ++++++++++++++++++++++--------- 2 files changed, 120 insertions(+), 61 deletions(-) diff --git a/holidays/countries/singapore.py b/holidays/countries/singapore.py index f5df66a0f..e3db72904 100644 --- a/holidays/countries/singapore.py +++ b/holidays/countries/singapore.py @@ -84,6 +84,10 @@ def __init__( super().__init__(years, expand, observed, subdiv, prov, state) def _populate(self, year) -> None: + def _add_holiday(dt: date, hol: str) -> None: + if dt.year == year: + self[dt] = hol + super()._populate(year) # New Year's Day @@ -120,7 +124,7 @@ def _populate(self, year) -> None: 2019: ((JUN, 5),), 2020: ((MAY, 24),), 2021: ((MAY, 13),), - 2022: ((MAY, 2),), + 2022: ((MAY, 3),), 2023: ((APR, 22),), } if year in dates_fixed_multiple_obs: @@ -130,18 +134,14 @@ def _populate(self, year) -> None: # Second day of Hari Raya Puasa (up to and including 1968) # Removed since we don't have Hari Raya Puasa dates for the # the years <= 1968: - # if year <= 1968: - # self[hol_date + rd(days=+1), - # "Second day of Hari Raya Puasa") else: - for date_obs in _islamic_to_gre(year, 10, 1): - hol_date = date_obs + for hol_date in _islamic_to_gre(year, 10, 1): self[hol_date] = "Hari Raya Puasa* (*estimated)" # Second day of Hari Raya Puasa (up to and including 1968) if year <= 1968: - hol_date += rd(days=+1) - self[hol_date] = ( - "Second day of Hari Raya Puasa*" " (*estimated)" + _add_holiday( + hol_date + rd(days=+1), + "Second day of Hari Raya Puasa* (*estimated)", ) # Hari Raya Haji @@ -154,7 +154,7 @@ def _populate(self, year) -> None: 2003: ((FEB, 12),), 2004: ((FEB, 1),), 2005: ((JAN, 21),), - 2006: ((JAN, 10),), + 2006: ((JAN, 10), (DEC, 31)), 2007: ((DEC, 20),), 2008: ((DEC, 8),), 2009: ((NOV, 27),), @@ -170,7 +170,7 @@ def _populate(self, year) -> None: 2019: ((AUG, 11),), 2020: ((JUL, 31),), 2021: ((JUL, 20),), - 2022: ((JUL, 9),), + 2022: ((JUL, 10),), 2023: ((JUN, 29),), } if year in dates_fixed_multiple_obs: @@ -178,8 +178,7 @@ def _populate(self, year) -> None: hol_date = date(year, *month_day) self[hol_date] = "Hari Raya Haji" else: - for date_obs in _islamic_to_gre(year, 12, 10): - hol_date = date_obs + for hol_date in _islamic_to_gre(year, 12, 10): self[hol_date] = "Hari Raya Haji* (*estimated)" easter_date = easter(year) @@ -201,10 +200,10 @@ def _populate(self, year) -> None: # https://en.wikipedia.org/wiki/Vesak#Dates_of_observance dates_fixed_obs: Dict[int, Tuple[int, int]] = { 2001: (MAY, 7), - 2002: (MAY, 27), + 2002: (MAY, 26), 2003: (MAY, 15), 2004: (JUN, 2), - 2005: (MAY, 23), + 2005: (MAY, 22), 2006: (MAY, 12), 2007: (MAY, 31), 2008: (MAY, 19), @@ -215,7 +214,7 @@ def _populate(self, year) -> None: 2013: (MAY, 24), 2014: (MAY, 13), 2015: (JUN, 1), - 2016: (MAY, 20), + 2016: (MAY, 21), 2017: (MAY, 10), 2018: (MAY, 29), 2019: (MAY, 19), @@ -231,7 +230,7 @@ def _populate(self, year) -> None: self[hol_date] = "Vesak Day" else: hol_date = self.cnls.vesak_date(year) - self[hol_date] = "Vesak Day* (*estimated; ~10% chance +/- 1 day)" + self[hol_date] = "Vesak Day* (*estimated)" # National Day self[date(year, AUG, 9)] = "National Day" @@ -248,7 +247,7 @@ def _populate(self, year) -> None: 2006: (OCT, 21), 2007: (NOV, 8), 2008: (OCT, 27), - 2009: (OCT, 17), + 2009: (NOV, 15), 2010: (NOV, 5), 2011: (OCT, 26), 2012: (NOV, 13), @@ -269,7 +268,7 @@ def _populate(self, year) -> None: self[hol_date] = "Deepavali" else: hol_date = self.cnls.s_diwali_date(year) - self[hol_date] = "Deepavali* (*estimated; rarely on day after)" + self[hol_date] = "Deepavali* (*estimated)" # Christmas Day self[date(year, DEC, 25)] = "Christmas Day" @@ -282,13 +281,17 @@ def _populate(self, year) -> None: # of the Holidays Act: "if any day specified in the Schedule falls on # a Sunday, the day next following not being itself a public holiday # is declared a public holiday in Singapore." - for (hol_date, hol_name) in list(self.items()): - if hol_date.year == year and hol_date.weekday() == SUN: - self[hol_date] += " [Sunday]" - in_lieu_date = hol_date + rd(days=+1) - while in_lieu_date in self: - in_lieu_date += rd(days=+1) - self[in_lieu_date] = hol_name + " [In lieu]" + if self.observed and year >= 1998: + for (hol_date, hol_name) in list(self.items()): + if hol_date.year == year and hol_date.weekday() == SUN: + in_lieu_date = hol_date + rd(days=+1) + while in_lieu_date.year == year and in_lieu_date in self: + in_lieu_date += rd(days=+1) + _add_holiday(in_lieu_date, f"{hol_name} (Observed)") + + # special case (observed from previuos year) + if self.observed and year == 2007: + self[date(2007, JAN, 2)] = "Hari Raya Haji (Observed)" class SG(Singapore): diff --git a/test/countries/test_singapore.py b/test/countries/test_singapore.py index 8678e1bd1..913d7e960 100644 --- a/test/countries/test_singapore.py +++ b/test/countries/test_singapore.py @@ -9,12 +9,10 @@ # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) -import importlib.util import unittest from datetime import date import holidays -from holidays.constants import APR, AUG, DEC, JAN, JUN, MAY, NOV class TestSingapore(unittest.TestCase): @@ -30,9 +28,26 @@ def test_Singapore(self): self.assertIn(date(2015, 9, 11), self.holidays) # Year with lunar leap month self.assertIn(date(2015, 8, 7), self.holidays) - # Latest holidays - # Source: https://www.mom.gov.sg/employment-practices/public-holidays - # 2018 + # holidays estimated using lunar calendar + self.assertIn(date(2050, 6, 4), self.holidays) # Vesak Day + self.assertIn(date(2050, 11, 12), self.holidays) # Deepavali + + def test_hijri_holidays(self): + # holidays estimated using library hijri-converter + # <= 1968 holidays + self.assertIn(date(1968, 1, 2), self.holidays) + # > 2022 + self.assertIn(date(2050, 6, 20), self.holidays) # Hari Raya Puasa + self.assertIn(date(2050, 8, 28), self.holidays) # Hari Raya Haji + # twice in a Gregorian calendar year + self.assertIn(date(2006, 1, 10), self.holidays) + self.assertIn(date(2006, 12, 31), self.holidays) + # special rare case (Hari Raya Haji from 2006) + self.assertIn(date(2007, 1, 2), self.holidays) + + # Latest holidays + # Source: https://www.mom.gov.sg/employment-practices/public-holidays + def test_2018(self): self.assertIn(date(2018, 1, 1), self.holidays) self.assertIn(date(2018, 2, 16), self.holidays) self.assertIn(date(2018, 2, 17), self.holidays) @@ -46,7 +61,57 @@ def test_Singapore(self): self.assertIn(date(2018, 12, 25), self.holidays) # 2018: total holidays (11 + 0 falling on a Sunday) self.assertEqual(len(holidays.Singapore(years=[2018])), 11 + 0) - # 2022 + + def test_2019(self): + self.assertIn(date(2019, 1, 1), self.holidays) + self.assertIn(date(2019, 2, 5), self.holidays) + self.assertIn(date(2019, 2, 6), self.holidays) + self.assertIn(date(2019, 4, 19), self.holidays) + self.assertIn(date(2019, 5, 1), self.holidays) + self.assertIn(date(2019, 5, 19), self.holidays) + self.assertIn(date(2019, 5, 20), self.holidays) + self.assertIn(date(2019, 6, 5), self.holidays) + self.assertIn(date(2019, 8, 9), self.holidays) + self.assertIn(date(2019, 8, 11), self.holidays) + self.assertIn(date(2019, 8, 12), self.holidays) + self.assertIn(date(2019, 10, 27), self.holidays) + self.assertIn(date(2019, 10, 28), self.holidays) + self.assertIn(date(2019, 12, 25), self.holidays) + self.assertEqual(len(holidays.Singapore(years=[2019])), 14) + + def test_2020(self): + self.assertIn(date(2020, 1, 1), self.holidays) + self.assertIn(date(2020, 1, 25), self.holidays) + self.assertIn(date(2020, 1, 26), self.holidays) + self.assertIn(date(2020, 1, 27), self.holidays) + self.assertIn(date(2020, 4, 10), self.holidays) + self.assertIn(date(2020, 5, 1), self.holidays) + self.assertIn(date(2020, 5, 7), self.holidays) + self.assertIn(date(2020, 5, 24), self.holidays) + self.assertIn(date(2020, 5, 25), self.holidays) + self.assertIn(date(2020, 7, 10), self.holidays) + self.assertIn(date(2020, 7, 31), self.holidays) + self.assertIn(date(2020, 8, 9), self.holidays) + self.assertIn(date(2020, 8, 10), self.holidays) + self.assertIn(date(2020, 11, 14), self.holidays) + self.assertIn(date(2020, 12, 25), self.holidays) + self.assertEqual(len(holidays.Singapore(years=[2020])), 15) + + def test_2021(self): + self.assertIn(date(2021, 1, 1), self.holidays) + self.assertIn(date(2021, 2, 12), self.holidays) + self.assertIn(date(2021, 2, 13), self.holidays) + self.assertIn(date(2021, 4, 2), self.holidays) + self.assertIn(date(2021, 5, 1), self.holidays) + self.assertIn(date(2021, 5, 13), self.holidays) + self.assertIn(date(2021, 5, 26), self.holidays) + self.assertIn(date(2021, 7, 20), self.holidays) + self.assertIn(date(2021, 8, 9), self.holidays) + self.assertIn(date(2021, 11, 4), self.holidays) + self.assertIn(date(2021, 12, 25), self.holidays) + self.assertEqual(len(holidays.Singapore(years=[2021])), 11) + + def test_2022(self): self.assertIn(date(2022, 1, 1), self.holidays) self.assertIn(date(2022, 2, 1), self.holidays) self.assertIn(date(2022, 2, 2), self.holidays) @@ -56,42 +121,33 @@ def test_Singapore(self): self.assertIn(date(2022, 5, 3), self.holidays) self.assertIn(date(2022, 5, 15), self.holidays) self.assertIn(date(2022, 5, 16), self.holidays) - self.assertIn(date(2022, 7, 9), self.holidays) + self.assertIn(date(2022, 7, 10), self.holidays) + self.assertIn(date(2022, 7, 11), self.holidays) self.assertIn(date(2022, 8, 9), self.holidays) self.assertIn(date(2022, 10, 24), self.holidays) self.assertIn(date(2022, 12, 25), self.holidays) self.assertIn(date(2022, 12, 26), self.holidays) - # 2022: total holidays (11 + 3 falling on a Sunday) - self.assertEqual(len(holidays.Singapore(years=[2022])), 11 + 3) - # 2023 - self.assertIn(date(2023, JAN, 1), self.holidays) - self.assertIn(date(2023, JAN, 2), self.holidays) - self.assertIn(date(2023, JAN, 22), self.holidays) - self.assertIn(date(2023, JAN, 23), self.holidays) - self.assertIn(date(2023, JAN, 24), self.holidays) - self.assertIn(date(2023, APR, 7), self.holidays) - self.assertIn(date(2023, APR, 22), self.holidays) - self.assertIn(date(2023, MAY, 1), self.holidays) - self.assertIn(date(2023, JUN, 2), self.holidays) - self.assertIn(date(2023, JUN, 29), self.holidays) - self.assertIn(date(2023, AUG, 9), self.holidays) - self.assertIn(date(2023, NOV, 12), self.holidays) - self.assertIn(date(2023, NOV, 13), self.holidays) - self.assertIn(date(2023, DEC, 25), self.holidays) + # 2022: total holidays (11 + 4 falling on a Sunday) + self.assertEqual(len(holidays.Singapore(years=[2022])), 11 + 4) + + def test_2023(self): + self.assertIn(date(2023, 1, 1), self.holidays) + self.assertIn(date(2023, 1, 2), self.holidays) + self.assertIn(date(2023, 1, 22), self.holidays) + self.assertIn(date(2023, 1, 23), self.holidays) + self.assertIn(date(2023, 1, 24), self.holidays) + self.assertIn(date(2023, 4, 7), self.holidays) + self.assertIn(date(2023, 4, 22), self.holidays) + self.assertIn(date(2023, 5, 1), self.holidays) + self.assertIn(date(2023, 6, 2), self.holidays) + self.assertIn(date(2023, 6, 29), self.holidays) + self.assertIn(date(2023, 8, 9), self.holidays) + self.assertIn(date(2023, 11, 12), self.holidays) + self.assertIn(date(2023, 11, 13), self.holidays) + self.assertIn(date(2023, 12, 25), self.holidays) # 2023: total holidays (11 + 3 falling on a Sunday) self.assertEqual(len(holidays.Singapore(years=[2023])), 11 + 3) - # holidays estimated using lunar calendar - self.assertIn(date(2050, 6, 4), self.holidays) # Vesak Day - self.assertIn(date(2050, 11, 12), self.holidays) # Deepavali - # holidays estimated using library hijri-converter - if importlib.util.find_spec("hijri_converter"): - # <= 1968 holidays - self.assertIn(date(1968, 1, 2), self.holidays) - # 2021 - self.assertIn(date(2050, 6, 20), self.holidays) # Hari Raya Puasa - self.assertIn(date(2050, 8, 28), self.holidays) # Hari Raya Haji - def test_aliases(self): """For coverage purposes""" h = holidays.SG() From fb5a48e917fcfc61180d67c17c86126df66ba53c Mon Sep 17 00:00:00 2001 From: Arkadii Yakovets Date: Wed, 28 Dec 2022 09:18:00 -0800 Subject: [PATCH 096/138] Add supported countries tests. - Add README.rst country count test - Add README.rst supported countries tests - Add `UK` back to the list of supported countries - Sort `HolidayBase::subdivisions` - Fix supported countries table formatting --- README.rst | 42 +++++----- holidays/countries/brazil.py | 10 +-- holidays/countries/germany.py | 8 +- holidays/countries/isle_of_man.py | 5 ++ holidays/countries/italy.py | 16 ++-- holidays/countries/malaysia.py | 10 +-- holidays/countries/portugal.py | 2 +- holidays/countries/united_kingdom.py | 2 +- holidays/utils.py | 10 +-- test/test_docs.py | 121 +++++++++++++++++++++++++++ test/test_holiday_base.py | 4 +- 11 files changed, 179 insertions(+), 51 deletions(-) create mode 100644 test/test_docs.py diff --git a/README.rst b/README.rst index 4f249dee7..aad80bf8b 100644 --- a/README.rst +++ b/README.rst @@ -153,13 +153,13 @@ following countries and their subdivisions are available: - Departments: B, C, H, L, N, O, P, S, T * - Bosnia and Herzegovina - BA - - Departments: FBiH, RS, BD + - Departments: BD, FBiH, RS * - Botswana - BW - None * - Brazil - BR - - States: AC, AL, AM, AP, BA, CE, DF, ES, GO, MA, MG, MS, MT, PA, PB, PE, PI, RJ, RN, RO, RR, RS, SC, SE, SP, TO + - States: AC, AL, AM, AP, BA, CE, DF, ES, GO, MA, MG, MS, MT, PA, PB, PE, PI, PR, RJ, RN, RO, RR, RS, SC, SE, SP, TO * - Bulgaria - BG - None @@ -168,7 +168,7 @@ following countries and their subdivisions are available: - None * - Canada - CA - - Provinces and territories: AB, BC, MB, NB, NL, NS NT, NU, **ON** (default), PE, QC, SK, YT + - Provinces and territories: AB, BC, MB, NB, NL, NS, NT, NU, **ON** (default), PE, QC, SK, YT * - Chile - CL - Regions: AI, AN, AP, AR, AT, BI, CO, LI, LL, LR, MA, ML, NB, RM, TA, VS @@ -184,7 +184,7 @@ following countries and their subdivisions are available: * - Cuba - CU - None - * - Curaçao + * - Curacao - CW - None * - Cyprus @@ -208,6 +208,9 @@ following countries and their subdivisions are available: * - Estonia - EE - None + * - Eswatini + - SZ + - None * - Ethiopia - ET - None @@ -255,7 +258,7 @@ following countries and their subdivisions are available: - None * - Italy - IT - - Provinces: AG, AL, AN, AO, AP, AQ, AR, AT, AV, BA, BG, BI, BL, BN, BO, BR, BS, BT, BZ, CA, CB, CE, CH, CL, CN, CO, CR, CS, CT, CZ, EN, FC, FE, FG, FI, FM, FR, GE, GO, GR, IM, IS, KR, LC, LE, LI, LO, LT, LU, MB, MC, ME, MI, MN, MO, MS, MT, NA, NO, NU, OR, PA, PC, PD, PE, PG, PI, PN, PO, PR, PT, PU, PV, PZ, RA, RC, RE, RG, RI, RM, RN, RO, SA, SI, SO, SP, SR, SS, SU, SV, TA, TE, TN, TO, TP, TR, TS, TV, UD, VA, VB, VC, VE, VI, VR, VT, VV; Cities: Barletta, Andria, Trani, Cesena, Forlì, Pesaro, Urbino + - Provinces: AG, AL, AN, AO, AP, AQ, AR, AT, AV, BA, BG, BI, BL, BN, BO, BR, BS, BT, BZ, CA, CB, CE, CH, CL, CN, CO, CR, CS, CT, CZ, EN, FC, FE, FG, FI, FM, FR, GE, GO, GR, IM, IS, KR, LC, LE, LI, LO, LT, LU, MB, MC, ME, MI, MN, MO, MS, MT, NA, NO, NU, OR, PA, PC, PD, PE, PG, PI, PN, PO, PR, PT, PU, PV, PZ, RA, RC, RE, RG, RI, RM, RN, RO, SA, SI, SO, SP, SR, SS, SU, SV, TA, TE, TN, TO, TP, TR, TS, TV, UD, VA, VB, VC, VE, VI, VR, VT, VV. Cities: Andria, Barletta, Cesena, Forlì, Pesaro, Trani, Urbino * - Jamaica - JM - None @@ -286,12 +289,12 @@ following countries and their subdivisions are available: * - Madagascar - MG - None - * - Malaysia - - MY - - States: JHR, KDH, KTN, MLK, NSN, PHG, PNG, PRK, PLS, SBH, SWK, SGR, TRG, KUL, LBN, PJY * - Malawi - MW - None + * - Malaysia + - MY + - States: JHR, KDH, KTN, KUL, LBN, MLK, NSN, PHG, PJY, PLS, PNG, PRK, SBH, SGR, SWK, TRG * - Malta - MT - None @@ -307,15 +310,15 @@ following countries and their subdivisions are available: * - Mozambique - MZ - None - * - Netherlands - - NL - - None * - Namibia - NA - None + * - Netherlands + - NL + - None * - New Zealand - NZ - - Regions: AUK, CAN, HKB, MBH, NSN, NTL, OTA, STL, TKI, WGN, WTC, CIT; Sub-regions: South Canterbury + - Regions: AUK, CAN, HKB, MBH, NSN, NTL, OTA, STL, TKI, WGN, WTC, CIT. Sub-regions: South Canterbury * - Nicaragua - NI - Departments: **MN** (default) @@ -342,7 +345,7 @@ following countries and their subdivisions are available: - None * - Portugal - PT - - Districts: 01, 02, 03, 04, 05, 06, 07, 08, 09, 10, 11, 12, 13, 14, 15, 16, 17, 18; Use subdiv='Ext' to include holidays most people have off + - Districts: 01, 02, 03, 04, 05, 06, 07, 08, 09, 10, 11, 12, 13, 14, 15, 16, 17, 18, Ext; Use subdiv='Ext' to include holidays most people have off * - Romania - RO - None @@ -372,10 +375,7 @@ following countries and their subdivisions are available: - None * - Spain - ES - - Autonomous communities: AN (Andalucía), AR (Aragón), AS (Asturias), CB (Cantabria), CE (Ceuta), CL (Castilla y León), CM (Castilla La Mancha), CN (Canarias), CT (Cataluña), EX (Extremadura), GA (Galicia), IB (Islas Baleares), MC (Murcia), MD (Madrid), NC (Navarra), PV (País Vasco), RI (La Rioja), VC (Comunidad Valenciana) - * - Swaziland - - SZ - - None + - Autonomous communities: AN, AR, AS, CB, CE, CL, CM, CN, CT, EX, GA, IB, MC, MD, ML, NC, PV, RI, VC * - Sweden - SE - None @@ -385,12 +385,12 @@ following countries and their subdivisions are available: * - Taiwan - TW - None - * - Turkey - - TR - - None * - Tunisia - TN - None + * - Turkey + - TR + - None * - Ukraine - UA - None @@ -399,7 +399,7 @@ following countries and their subdivisions are available: - None * - United Kingdom - GB - - Subdivisions: **UK** (default), England, Northern Ireland, Scotland, Wales. For Isle of Man use country code IM. + - Subdivisions: England, Northern Ireland, Scotland, **UK** (default), Wales; For Isle of Man use country code IM * - United States - US - States and territories: AL, AK, AS, AZ, AR, CA, CO, CT, DE, DC, FL, GA, GU, HI, ID, IL, IN, IA, KS, KY, LA, ME, MD, MH, MA, MI, FM, MN, MS, MO, MT, NE, NV, NH, NJ, NM, NY, NC, ND, MP, OH, OK, OR, PW, PA, PR, RI, SC, SD, TN, TX, UT, VT, VA, VI, WA, WV, WI, WY diff --git a/holidays/countries/brazil.py b/holidays/countries/brazil.py index 95315a324..c26d32df3 100644 --- a/holidays/countries/brazil.py +++ b/holidays/countries/brazil.py @@ -29,17 +29,17 @@ class Brazil(HolidayBase): subdivisions = [ "AC", "AL", - "AP", "AM", + "AP", "BA", "CE", "DF", "ES", "GO", "MA", - "MT", - "MS", "MG", + "MS", + "MT", "PA", "PB", "PE", @@ -47,12 +47,12 @@ class Brazil(HolidayBase): "PR", "RJ", "RN", - "RS", "RO", "RR", + "RS", "SC", - "SP", "SE", + "SP", "TO", ] diff --git a/holidays/countries/germany.py b/holidays/countries/germany.py index 75b1b608a..299a74375 100644 --- a/holidays/countries/germany.py +++ b/holidays/countries/germany.py @@ -56,22 +56,22 @@ class Germany(HolidayBase): country = "DE" subdivisions = [ + "BB", + "BE", "BW", "BY", "BYP", - "BE", - "BB", "HB", - "HH", "HE", + "HH", "MV", "NI", "NW", "RP", + "SH", "SL", "SN", "ST", - "SH", "TH", ] diff --git a/holidays/countries/isle_of_man.py b/holidays/countries/isle_of_man.py index 30377dd6f..f47569d4e 100644 --- a/holidays/countries/isle_of_man.py +++ b/holidays/countries/isle_of_man.py @@ -14,6 +14,7 @@ from dateutil.relativedelta import relativedelta as rd from holidays.constants import JUN, JUL +from holidays.holiday_base import HolidayBase from .united_kingdom import UnitedKingdom @@ -22,6 +23,10 @@ class IsleOfMan(UnitedKingdom): """Using existing code in UnitedKingdom for now.""" country = "IM" + subdivisions = [] # Override UnitedKingdom subdivisions. + + def __init__(self, **kwargs): # Override UnitedKingdom __init__(). + HolidayBase.__init__(self, **kwargs) def _populate(self, year: int) -> None: super()._populate(year) diff --git a/holidays/countries/italy.py b/holidays/countries/italy.py index b7eaf4782..553697193 100644 --- a/holidays/countries/italy.py +++ b/holidays/countries/italy.py @@ -33,6 +33,7 @@ class Italy(HolidayBase): # Patrono defined. If you want one specific you'll have to use # the full name of the city like "Andria" instead of "BT". subdivisions = [ + # Provinces. "AG", "AL", "AN", @@ -51,9 +52,6 @@ class Italy(HolidayBase): "BR", "BS", "BT", - "Barletta", - "Andria", - "Trani", "BZ", "CA", "CB", @@ -68,8 +66,6 @@ class Italy(HolidayBase): "CZ", "EN", "FC", - "Forlì", - "Cesena", "FE", "FG", "FI", @@ -110,8 +106,6 @@ class Italy(HolidayBase): "PR", "PT", "PU", - "Pesaro", - "Urbino", "PV", "PZ", "RA", @@ -147,6 +141,14 @@ class Italy(HolidayBase): "VR", "VT", "VV", + # Cities. + "Andria", + "Barletta", + "Cesena", + "Forlì", + "Pesaro", + "Trani", + "Urbino", ] def _populate(self, year): diff --git a/holidays/countries/malaysia.py b/holidays/countries/malaysia.py index 953945893..47fdeef80 100644 --- a/holidays/countries/malaysia.py +++ b/holidays/countries/malaysia.py @@ -36,19 +36,19 @@ class Malaysia(HolidayBase): "JHR", "KDH", "KTN", + "KUL", + "LBN", "MLK", "NSN", "PHG", - "PRK", + "PJY", "PLS", "PNG", + "PRK", "SBH", - "SWK", "SGR", + "SWK", "TRG", - "KUL", - "LBN", - "PJY", ] def __init__( diff --git a/holidays/countries/portugal.py b/holidays/countries/portugal.py index 16b2d02af..ffc02570d 100644 --- a/holidays/countries/portugal.py +++ b/holidays/countries/portugal.py @@ -29,7 +29,6 @@ class Portugal(HolidayBase): # Only the 18 mainland districts have been included # `Ext` represents the national holidays most people have off subdivisions = [ - "Ext", "01", "02", "03", @@ -48,6 +47,7 @@ class Portugal(HolidayBase): "16", "17", "18", + "Ext", ] def _populate(self, year): diff --git a/holidays/countries/united_kingdom.py b/holidays/countries/united_kingdom.py index 634348fb8..3beb88d08 100644 --- a/holidays/countries/united_kingdom.py +++ b/holidays/countries/united_kingdom.py @@ -42,7 +42,7 @@ class UnitedKingdom(HolidayBase): ), 2023: ((MAY, 8, "Coronation of Charles III"),), } - subdivisions = ["UK", "England", "Northern Ireland", "Scotland", "Wales"] + subdivisions = ["England", "Northern Ireland", "Scotland", "UK", "Wales"] def __init__(self, **kwargs: Any) -> None: # default subdiv to UK; state for backwards compatibility diff --git a/holidays/utils.py b/holidays/utils.py index 0e2843b55..33c36d76f 100755 --- a/holidays/utils.py +++ b/holidays/utils.py @@ -272,7 +272,7 @@ def CountryHoliday( ) -def list_supported_countries() -> Dict[str, List[str]]: +def list_supported_countries(unique=False) -> Dict[str, List[str]]: """ Get all supported countries and their subdivisions. @@ -281,13 +281,13 @@ def list_supported_countries() -> Dict[str, List[str]]: the value is a list of supported subdivision codes. """ return { - cls.country: cls.subdivisions + cls.country if unique else name: cls.subdivisions for name, cls in inspect.getmembers(countries, inspect.isclass) if len(name) == 2 and issubclass(cls, HolidayBase) } -def list_supported_financial() -> Dict[str, List[str]]: +def list_supported_financial(unique=False) -> Dict[str, List[str]]: """ Get all supported financial markets and their subdivisions. @@ -296,8 +296,8 @@ def list_supported_financial() -> Dict[str, List[str]]: the value is a list of supported subdivision codes. """ return { - cls.market: cls.subdivisions - for _, cls in inspect.getmembers(financial, inspect.isclass) + cls.market if unique else name: cls.subdivisions + for name, cls in inspect.getmembers(financial, inspect.isclass) if issubclass(cls, HolidayBase) } diff --git a/test/test_docs.py b/test/test_docs.py new file mode 100644 index 000000000..e05ca08fb --- /dev/null +++ b/test/test_docs.py @@ -0,0 +1,121 @@ +# 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 (c) 2017-2022 +# ryanss (c) 2014-2017 +# Website: https://github.com/dr-prodigy/python-holidays +# License: MIT (see LICENSE file) + +import re + +from holidays import country_holidays, list_supported_countries +from test.common import TestCase + + +class TestReadme(TestCase): + @classmethod + def setUpClass(cls): + with open("README.rst", "r") as readme_file: + cls.readme_content = "".join(readme_file.readlines()) + + super().setUpClass() + + def test_supported_countries_count(self): + actual_country_count = len(list_supported_countries(unique=True)) + readme_country_count = int( + re.findall( + r"We currently support (\d+) countries.", + self.readme_content, + )[0] + ) + self.assertEqual( + readme_country_count, + actual_country_count, + "README.rst supported countries statement is out of date: " + f"'We currently support {readme_country_count} countries'. " + f"Actual supported countries count: {actual_country_count}", + ) + + def test_supported_countries_table(self): + # Parse table data. + table_content = [ + line.strip() + for line in re.findall( + r"Subdivisions Available(.*)Available Financial Markets", + self.readme_content, + re.DOTALL, + )[0].split("\n") + if line + ] + country_names = [] + country_alpha_2_codes = set() + country_subdivisions = {} + subdivisions_re = re.compile(".*: (.*)") + for idx in range(0, len(table_content), 3): # 3 column table. + # 1st column. + name = table_content[idx].strip(" *-").replace(" ", "").lower() + country_names.append(name) + + # 2nd column. + alpha_2_code = table_content[idx + 1].strip(" -") + country_alpha_2_codes.add(alpha_2_code) + + # 3rd column. + country_subdivisions[alpha_2_code] = [] + subdivisions = table_content[idx + 2].split(".") + for subdivision in subdivisions: + subdivision_group = subdivision.split(";")[0].strip(" -") + if subdivision_group == "None": # Exclude empty subdivisions. + country_subdivisions[alpha_2_code] = [] + continue + + # Combine all subdivision codes. + country_subdivisions[alpha_2_code].extend( + [ + subdivision_code.replace("(default)", "").strip("* ") + for subdivision_code in subdivisions_re.findall( + subdivision_group + )[0].split(",") + ] + ) + + # Check data. + self.assertEqual( + country_names, + sorted(country_names), + "The supported countries table must be sorted alphabetically by " + "country name.", + ) + + country_names = set(country_names) + supported_countries = list_supported_countries(unique=True) + for country_alpha_2_code in supported_countries: + country = country_holidays(country_alpha_2_code) + country_name = country.__class__.__base__.__name__ + + # Make sure country name is shown correctly. + self.assertIn( + country_name.lower(), + country_names, + f"Country class '{country_name}' is not shown correctly " + "in the table.", + ) + + # Make sure country alpha-2 code is shown correctly. + self.assertIn( + country.country, + country_alpha_2_codes, + f"Country alpha-2 code '{country_alpha_2_code}' is not " + "shown correctly in the table.", + ) + + # Make sure country subdivisions are shown correctly. + self.assertEqual( + supported_countries[country_alpha_2_code], + country_subdivisions[country_alpha_2_code], + f"Country class '{country_name}' subdivisions are not " + "shown correctly in the table.", + ) diff --git a/test/test_holiday_base.py b/test/test_holiday_base.py index 9e8c16526..1f42cf38b 100644 --- a/test/test_holiday_base.py +++ b/test/test_holiday_base.py @@ -351,7 +351,7 @@ def test_get_list(self): self.assertEqual(na.get_list(date(1969, 1, 3)), []) def test_list_supported_countries(self): - supported_countries = holidays.list_supported_countries() + supported_countries = holidays.list_supported_countries(unique=True) countries_files = [ path @@ -369,7 +369,7 @@ def test_list_supported_countries(self): self.assertIn("ZA", supported_countries) def test_list_supported_financial(self): - supported_financial = holidays.list_supported_financial() + supported_financial = holidays.list_supported_financial(unique=True) financial_files = [ path From 0498c1c89eb3607aac7ec35870a4291e06be8e44 Mon Sep 17 00:00:00 2001 From: Arkadii Yakovets Date: Wed, 28 Dec 2022 09:38:47 -0800 Subject: [PATCH 097/138] Fix France tests. --- README.rst | 2 +- holidays/countries/france.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.rst b/README.rst index aad80bf8b..3481faa81 100644 --- a/README.rst +++ b/README.rst @@ -219,7 +219,7 @@ following countries and their subdivisions are available: - None * - France - FR - - Départements: **Métropole** (default), Alsace-Moselle, Guadeloupe, Guyane, Martinique, Mayotte, Nouvelle-Calédonie, La Réunion, Polynésie Française, Saint-Barthélémy, Saint-Martin, Wallis-et-Futuna + - Départements: Alsace-Moselle, Guadeloupe, Guyane, La Réunion, Martinique, Mayotte, **Métropole** (default), Nouvelle-Calédonie, Polynésie Française, Saint-Barthélémy, Saint-Martin, Wallis-et-Futuna * - Georgia - GE - None diff --git a/holidays/countries/france.py b/holidays/countries/france.py index 057b9db04..9d04e0656 100644 --- a/holidays/countries/france.py +++ b/holidays/countries/france.py @@ -35,14 +35,14 @@ class France(HolidayBase): country = "FR" subdivisions = [ - "Métropole", "Alsace-Moselle", "Guadeloupe", "Guyane", + "La Réunion", "Martinique", "Mayotte", + "Métropole", "Nouvelle-Calédonie", - "La Réunion", "Polynésie Française", "Saint-Barthélémy", "Saint-Martin", From 107c75052290377854ab658a65074f6d0a3e6224 Mon Sep 17 00:00:00 2001 From: Arkadii Yakovets Date: Wed, 28 Dec 2022 09:55:31 -0800 Subject: [PATCH 098/138] Fix Windows tests. --- test/test_docs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_docs.py b/test/test_docs.py index e05ca08fb..78922fe3a 100644 --- a/test/test_docs.py +++ b/test/test_docs.py @@ -18,7 +18,7 @@ class TestReadme(TestCase): @classmethod def setUpClass(cls): - with open("README.rst", "r") as readme_file: + with open("README.rst", encoding="utf-8") as readme_file: cls.readme_content = "".join(readme_file.readlines()) super().setUpClass() From 36960d0d84829004edd7d19906a7f0e7b6fd552b Mon Sep 17 00:00:00 2001 From: ~Jhellico Date: Wed, 28 Dec 2022 15:11:43 +0200 Subject: [PATCH 099/138] Added Monaco holidays --- README.rst | 5 +- holidays/countries/__init__.py | 1 + holidays/countries/monaco.py | 99 +++++++++++++++++++++++++ test/countries/test_monaco.py | 127 +++++++++++++++++++++++++++++++++ 4 files changed, 231 insertions(+), 1 deletion(-) create mode 100644 holidays/countries/monaco.py create mode 100644 test/countries/test_monaco.py diff --git a/README.rst b/README.rst index 4f249dee7..f1df8512c 100644 --- a/README.rst +++ b/README.rst @@ -106,7 +106,7 @@ Available Countries .. _ISO 3166-1 alpha-2 code: https://en.wikipedia.org/wiki/List_of_ISO_3166_country_codes -We currently support 101 countries. The standard way to refer to a country is by +We currently support 102 countries. The standard way to refer to a country is by using its `ISO 3166-1 alpha-2 code`_, the same used for domain names. The following countries and their subdivisions are available: @@ -301,6 +301,9 @@ following countries and their subdivisions are available: * - Moldova - MD - None + * - Monaco + - MC + - None * - Morocco - MA - None diff --git a/holidays/countries/__init__.py b/holidays/countries/__init__.py index 8cb48c057..858a1ce37 100644 --- a/holidays/countries/__init__.py +++ b/holidays/countries/__init__.py @@ -71,6 +71,7 @@ from .malta import MT, MLT, Malta from .mexico import MX, MEX, Mexico from .moldova import MD, MDA, Moldova +from .monaco import MC, MCO, Monaco from .morocco import MA, MOR, Morocco from .mozambique import MZ, MOZ, Mozambique from .namibia import NA, NAM, Namibia diff --git a/holidays/countries/monaco.py b/holidays/countries/monaco.py new file mode 100644 index 000000000..e4eeaee1c --- /dev/null +++ b/holidays/countries/monaco.py @@ -0,0 +1,99 @@ +# 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 (c) 2017-2022 +# ryanss (c) 2014-2017 +# Website: https://github.com/dr-prodigy/python-holidays +# License: MIT (see LICENSE file) + +from datetime import date + +from dateutil.easter import easter +from dateutil.relativedelta import relativedelta as rd + +from holidays.constants import SUN, JAN, MAY, AUG, NOV, DEC +from holidays.holiday_base import HolidayBase + + +class Monaco(HolidayBase): + """ + https://en.wikipedia.org/wiki/Public_holidays_in_Monaco + https://en.service-public-entreprises.gouv.mc/Employment-and-social-affairs/Employment-regulations/Leave/Public-Holidays # noqa: E501 + """ + + country = "MC" + special_holidays = { + 2015: ((JAN, 7, "Jour férié [Public holiday]"),), + } + + def _populate(self, year): + def _add_with_observed(hol_date: date, hol_name: str) -> None: + self[hol_date] = hol_name + if self.observed and hol_date.weekday() == SUN: + self[hol_date + rd(days=+1)] = f"{hol_name} (Observed)" + + super()._populate(year) + + # New Year's Day + _add_with_observed( + date(year, JAN, 1), "Le jour de l'An [New Year's Day]" + ) + + # Saint Dévote's Day + self[date(year, JAN, 27)] = "La Sainte Dévote [Saint Dévote's Day]" + + easter_date = easter(year) + + # Easter Monday + self[easter_date + rd(days=+1)] = "Le lundi de Pâques [Easter Monday]" + + # Labour Day + _add_with_observed( + date(year, MAY, 1), "Fête de la Travaille [Labour Day]" + ) + + # Ascension's Day + self[easter_date + rd(days=+39)] = "L'Ascension [Ascension's Day]" + + # Whit Monday + self[ + easter_date + rd(days=+50) + ] = "Le lundi de Pentecôte [Whit Monday]" + + # Corpus Christi + self[easter_date + rd(days=+60)] = "La Fête Dieu [Corpus Christi]" + + # Assumption's Day + _add_with_observed( + date(year, AUG, 15), "L'Assomption de Marie [Assumption's Day]" + ) + + # All Saints' Day + _add_with_observed( + date(year, NOV, 1), "La Toussaint [All Saints' Day]" + ) + + # Prince's Day + _add_with_observed( + date(year, NOV, 19), "La Fête du Prince [Prince's Day]" + ) + + # Immaculate Conception's Day + dt = date(year, DEC, 8) + if year >= 2019 and dt.weekday() == SUN: + dt += rd(days=+1) + self[dt] = "L'Immaculée Conception [Immaculate Conception's Day]" + + # Christmas Day + _add_with_observed(date(year, DEC, 25), "Noël [Christmas Day]") + + +class MC(Monaco): + pass + + +class MCO(Monaco): + pass diff --git a/test/countries/test_monaco.py b/test/countries/test_monaco.py new file mode 100644 index 000000000..89b1ddeb5 --- /dev/null +++ b/test/countries/test_monaco.py @@ -0,0 +1,127 @@ +# 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 (c) 2017-2022 +# ryanss (c) 2014-2017 +# Website: https://github.com/dr-prodigy/python-holidays +# License: MIT (see LICENSE file) + +from holidays.countries.monaco import MC, MCO, Monaco +from test.common import TestCase + + +class TestMonaco(TestCase): + def setUp(self): + self.holidays = Monaco() + + def test_country_aliases(self): + self.assertCountryAliases(Monaco, MC, MCO) + + def test_immaculate_conception_day(self): + self.assertHoliday( + "2018-12-08", + "2019-12-09", + "2020-12-08", + "2021-12-08", + "2022-12-08", + "2023-12-08", + "2024-12-09", + ) + + def test_observed(self): + observed_holidays = ( + "2010-08-16", + "2011-05-02", + "2011-12-26", + "2012-01-02", + "2015-11-02", + "2016-05-02", + "2016-12-26", + "2017-01-02", + "2017-11-20", + "2020-11-02", + "2021-08-16", + "2022-05-02", + "2022-12-26", + "2023-01-02", + "2023-11-20", + ) + self.assertHoliday(Monaco(observed=True), observed_holidays) + self.assertNoHoliday(Monaco(observed=False), observed_holidays) + + def test_2020(self): + self.assertHolidayDatesEqual( + Monaco(years=2020), + "2020-01-01", + "2020-01-27", + "2020-04-13", + "2020-05-01", + "2020-05-21", + "2020-06-01", + "2020-06-11", + "2020-08-15", + "2020-11-01", + "2020-11-02", + "2020-11-19", + "2020-12-08", + "2020-12-25", + ) + + def test_2021(self): + self.assertHolidayDatesEqual( + Monaco(years=2021), + "2021-01-01", + "2021-01-27", + "2021-04-05", + "2021-05-01", + "2021-05-13", + "2021-05-24", + "2021-06-03", + "2021-08-15", + "2021-08-16", + "2021-11-01", + "2021-11-19", + "2021-12-08", + "2021-12-25", + ) + + def test_2022(self): + self.assertHolidayDatesEqual( + Monaco(years=2022), + "2022-01-01", + "2022-01-27", + "2022-04-18", + "2022-05-01", + "2022-05-02", + "2022-05-26", + "2022-06-06", + "2022-06-16", + "2022-08-15", + "2022-11-01", + "2022-11-19", + "2022-12-08", + "2022-12-25", + "2022-12-26", + ) + + def test_2023(self): + self.assertHolidayDatesEqual( + Monaco(years=2023), + "2023-01-01", + "2023-01-02", + "2023-01-27", + "2023-04-10", + "2023-05-01", + "2023-05-18", + "2023-05-29", + "2023-06-08", + "2023-08-15", + "2023-11-01", + "2023-11-19", + "2023-11-20", + "2023-12-08", + "2023-12-25", + ) From 04baa4e860c0e04137e48501276f2f04d827ff03 Mon Sep 17 00:00:00 2001 From: ~Jhellico Date: Thu, 29 Dec 2022 17:49:32 +0200 Subject: [PATCH 100/138] Japan: substitute holidays and citizens' holidays calculation --- holidays/countries/japan.py | 183 ++++------------------------------- test/countries/test_japan.py | 29 +++--- 2 files changed, 34 insertions(+), 178 deletions(-) diff --git a/holidays/countries/japan.py b/holidays/countries/japan.py index f44272b6f..98178cd86 100644 --- a/holidays/countries/japan.py +++ b/holidays/countries/japan.py @@ -17,7 +17,7 @@ from pymeeus.Epoch import Epoch from pymeeus.Sun import Sun -from holidays.constants import JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP +from holidays.constants import SUN, JAN, FEB, APR, MAY, JUN, JUL, AUG, SEP from holidays.constants import OCT, NOV, DEC from holidays.holiday_base import HolidayBase @@ -68,7 +68,7 @@ def _populate(self, year): adjusted_date = datetime(*equinox, tzinfo=tz.UTC).astimezone( tz.gettz("Asia/Tokyo") ) - self[date(year, MAR, adjusted_date.day)] = "春分の日" + self[adjusted_date.date()] = "春分の日" # Showa Emperor's Birthday, Greenery Day or Showa Day if year <= 1988: @@ -118,7 +118,7 @@ def _populate(self, year): adjusted_date = datetime(*equinox, tzinfo=tz.UTC).astimezone( tz.gettz("Asia/Tokyo") ) - self[date(year, SEP, adjusted_date.day)] = "秋分の日" + self[adjusted_date.date()] = "秋分の日" # Health and Sports Day if 1966 <= year <= 1999: @@ -143,166 +143,23 @@ def _populate(self, year): # Heisei Emperor's Birthday self[date(year, DEC, 23)] = "天皇誕生日" - # A weekday between national holidays becomes a holiday too (国民の休日) - self._add_national_holidays(year) - - # Substitute holidays - self._add_substitute_holidays(year) - - def _add_national_holidays(self, year): - if year in { - 1988, - 1989, - 1990, - 1991, - 1993, - 1994, - 1995, - 1996, - 1999, - 2000, - 2001, - 2002, - 2004, - 2005, - 2006, - }: - self[date(year, MAY, 4)] = "国民の休日" - - if year in {2032, 2049, 2060, 2077, 2088, 2094}: - self[date(year, SEP, 21)] = "国民の休日" - elif year in {2009, 2015, 2026, 2037, 2043, 2054, 2065, 2071, 2099}: - self[date(year, SEP, 22)] = "国民の休日" - elif year == 2019: - self[date(year, APR, 30)] = "国民の休日" - self[date(year, MAY, 2)] = "国民の休日" - - def _add_substitute_holidays(self, year): - table = ( - ( - 1, - 2, - { - 1978, - 1984, - 1989, - 1995, - 2006, - 2012, - 2017, - 2023, - 2034, - 2040, - 2045, - }, - ), - (1, 16, {1978, 1984, 1989, 1995}), - ( - 2, - 12, - {1979, 1990, 1996, 2001, 2007, 2018, 2024, 2029, 2035, 2046}, - ), - (2, 24, {2020, 2025, 2031, 2042, 2048}), - (3, 21, {1988, 2005, 2016, 2033, 2044, 2050}), - (3, 22, {1982, 1999, 2010, 2027}), - ( - 4, - 30, - { - 1973, - 1979, - 1984, - 1990, - 2001, - 2007, - 2012, - 2018, - 2029, - 2035, - 2040, - 2046, - }, - ), - (5, 4, {1981, 1987, 1992, 1998}), - ( - 5, - 6, - { - 1974, - 1985, - 1991, - 1996, - 2002, - 2013, - 2019, - 2024, - 2030, - 2041, - 2047, - 2008, - 2014, - 2025, - 2031, - 2036, - 2042, - 2009, - 2015, - 2020, - 2026, - 2037, - 2043, - 2048, - }, - ), - (7, 21, {1997}), - (8, 9, {2021}), - (8, 12, {2019, 2024, 2030, 2041, 2047}), - (9, 16, {1974, 1985, 1991, 1996, 2002}), - (9, 23, {2024}), - (9, 24, {1973, 1984, 1990, 2001, 2007, 2018, 2029, 2035, 2046}), - (10, 11, {1976, 1982, 1993, 1999}), - ( - 11, - 4, - { - 1974, - 1985, - 1991, - 1996, - 2002, - 2013, - 2019, - 2024, - 2030, - 2041, - 2047, - }, - ), - ( - 11, - 24, - { - 1975, - 1980, - 1986, - 1997, - 2003, - 2008, - 2014, - 2025, - 2031, - 2036, - 2042, - }, - ), - (12, 24, {1990, 2001, 2007, 2012, 2018}), - ) - for holiday in table: - month = holiday[0] - day = holiday[1] - years = holiday[2] - if year in years: - self[date(year, month, day)] = "振替休日" + if self.observed: + # When a national holiday falls on Sunday, next working day + # shall become a public holiday (振替休日) - substitute holidays + for dt in list(self.keys()): + if dt.year == year and dt.weekday() == SUN: + hol_date = dt + rd(days=+1) + while hol_date in self: + hol_date += rd(days=+1) + self[hol_date] = "振替休日" + + # A weekday between national holidays becomes + # a holiday too (国民の休日) - citizens' holidays + for dt in list(self.keys()): + if dt.year == year and dt + rd(days=+2) in self: + hol_date = dt + rd(days=+1) + if hol_date.weekday() != SUN and hol_date not in self: + self[hol_date] = "国民の休日" class JP(Japan): diff --git a/test/countries/test_japan.py b/test/countries/test_japan.py index 2422cf900..2892d2ade 100644 --- a/test/countries/test_japan.py +++ b/test/countries/test_japan.py @@ -17,7 +17,7 @@ class TestJapan(unittest.TestCase): def setUp(self): - self.holidays = holidays.Japan(observed=False) + self.holidays = holidays.Japan() def test_not_implemented(self): with self.assertRaises(NotImplementedError): @@ -573,19 +573,10 @@ def test_reiwa_emperor_holidays(self): self.assertIn(date(2019, 5, 2), self.holidays) self.assertIn(date(2019, 10, 22), self.holidays) - def test_national_holidays(self): - self.assertIn(date(2032, 9, 21), self.holidays) - - def test_invalid_years(self): - self.assertRaises( - NotImplementedError, lambda: date(1948, 1, 1) in self.holidays - ) - self.assertRaises( - NotImplementedError, lambda: date(2100, 1, 1) in self.holidays - ) - - def test_substitute_holidays(self): - for dt in ( + def test_observed_holidays(self): + no_observed = holidays.Japan(observed=False) + hol_list = ( + # 振替休日 (1973, 4, 30), (1973, 9, 24), (1974, 5, 6), @@ -718,5 +709,13 @@ def test_substitute_holidays(self): (2048, 2, 24), (2048, 5, 6), (2050, 3, 21), - ): + # 国民の休日 + (2019, 4, 30), + (2019, 5, 2), + (2026, 9, 22), + (2032, 9, 21), + (2037, 9, 22), + ) + for dt in hol_list: self.assertIn(date(*dt), self.holidays) + self.assertNotIn(date(*dt), no_observed) From a82ec5dcd2a55cd6396efe606e32947005af8e3a Mon Sep 17 00:00:00 2001 From: Arkadii Yakovets Date: Fri, 30 Dec 2022 09:07:43 -0800 Subject: [PATCH 101/138] Update `common.TestCase`. Add `TestCase::assertHolidayName`, `TestCase::NoHolidayName`. Refactor Chile, Vietnam tests. --- test/common.py | 89 +++++++++++-------- test/countries/test_chile.py | 157 ++++++++++++++++++++------------- test/countries/test_vietnam.py | 157 ++++++++++++++++----------------- 3 files changed, 226 insertions(+), 177 deletions(-) diff --git a/test/common.py b/test/common.py index 481d86906..de2b81d9e 100644 --- a/test/common.py +++ b/test/common.py @@ -8,7 +8,6 @@ # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) -# Copyright: Arkadii Yakovets , 2022 import unittest from typing import Generator @@ -23,12 +22,12 @@ class TestCase(unittest.TestCase): """Base class for python-holiday test cases.""" def parse_arguments(self, args): - date_args = args + item_args = args instance = None if issubclass(args[0].__class__, HolidayBase): instance = args[0] - date_args = args[1:] + item_args = args[1:] else: try: instance = getattr(self, "holidays") @@ -43,16 +42,16 @@ def parse_arguments(self, args): "`setUp()` method." ) - dates = [] - for date_arg in date_args: - if type(date_arg) in {list, tuple}: - dates.extend(date_arg) - elif isinstance(date_arg, Generator): - dates.extend(tuple(date_arg)) + items = [] + for item_arg in item_args: + if type(item_arg) in {list, tuple}: + items.extend(item_arg) + elif isinstance(item_arg, Generator): + items.extend(tuple(item_arg)) else: - dates.append(date_arg) + items.append(item_arg) - return instance, dates + return instance, items def verify_type(self, holidays): self.assertTrue( @@ -61,7 +60,7 @@ def verify_type(self, holidays): ) def assertCountryAliases(self, cls, alpha_2, alpha_3): - """Asserts country aliases match.""" + """Assert country aliases match.""" self.assertTrue( issubclass(cls, HolidayBase), @@ -74,7 +73,6 @@ def assertCountryAliases(self, cls, alpha_2, alpha_3): for alias in (alpha_2, alpha_3): self.assertIsNotNone(alias, type_error_message) self.assertTrue(issubclass(alias, cls), type_error_message) - self.assertEqual(alias(), cls()) length_error_message = ( "This method accepts exactly 3 arguments " @@ -94,16 +92,38 @@ def assertCountryAliases(self, cls, alpha_2, alpha_3): "look like alpha-3 country code." ) - def assertNoHolidays(self, holidays): - """Asserts holidays dict is empty.""" + def assertHoliday(self, *args): + """Assert each date is a holiday.""" + + holidays, dates = self.parse_arguments(args) + for dt in dates: + self.assertIn(dt, holidays, f"{dt}") + + def assertHolidayDatesEqual(self, holidays, *dates): + """Assert holiday dates exactly match expected dates.""" self.verify_type(holidays) - self.assertEqual(0, len(holidays)) - self.assertFalse(holidays) + self.assertEqual(len(dates), len(holidays.keys())) + for dt in dates: # Check one by one for descriptive error messages. + self.assertIn(dt, holidays, f"{dt}") + + def assertHolidayName(self, *args): + """Assert a holiday with a specific name exists.""" + + holidays, names = self.parse_arguments(args) + for name in names: + self.assertTrue(holidays.get_named(name)) + + def assertHolidayNames(self, name, *args): + """Assert each holiday name matches an expected one.""" + + holidays, dates = self.parse_arguments(args) + for dt in dates: + self.assertEqual(name, holidays.get(dt), f"{dt}") def assertHolidaysEqual(self, holidays, *expected_holidays): - """Asserts holidays exactly match expected holidays.""" + """Assert holidays exactly match expected holidays.""" self.verify_type(holidays) @@ -111,30 +131,29 @@ def assertHolidaysEqual(self, holidays, *expected_holidays): # Check one by one for descriptive error messages. for dt, name in expected_holidays: self.assertIn(dt, holidays) - self.assertEqual(name, holidays[dt]) + self.assertEqual(name, holidays[dt], f"{dt}") - def assertHolidayDatesEqual(self, holidays, *dates): - """Asserts holiday dates exactly match expected dates.""" + def assertNoHoliday(self, *args): + """Assert each date is not a holiday.""" - self.verify_type(holidays) + holidays, dates = self.parse_arguments(args) + for dt in dates: + self.assertNotIn(dt, holidays, f"{dt}") - self.assertEqual(len(dates), len(holidays.keys())) - for date in dates: # Check one by one for descriptive error messages. - self.assertIn(date, holidays) + def assertNoHolidayName(self, *args): + """Assert a holiday with a specific name doesn't exist.""" - def assertHoliday(self, *args): - """Asserts each date is a holiday.""" + holidays, names = self.parse_arguments(args) + for name in names: + self.assertFalse(holidays.get_named(name)) - holidays, dates = self.parse_arguments(args) - for dt in dates: - self.assertIn(dt, holidays) + def assertNoHolidays(self, holidays): + """Assert holidays dict is empty.""" - def assertNoHoliday(self, *args): - """Asserts each date is not a holiday.""" + self.verify_type(holidays) - holidays, dates = self.parse_arguments(args) - for dt in dates: - self.assertNotIn(dt, holidays) + self.assertFalse(holidays) + self.assertEqual(0, len(holidays)) class SundayHolidays(TestCase): diff --git a/test/countries/test_chile.py b/test/countries/test_chile.py index fc82da92e..f4ed163c7 100644 --- a/test/countries/test_chile.py +++ b/test/countries/test_chile.py @@ -16,20 +16,22 @@ class TestChile(TestCase): def setUp(self): self.holidays = Chile() - self.holidays_AP = Chile(subdiv="AP") - self.holidays_NB = Chile(subdiv="NB") + self.holidays_ap = Chile(subdiv="AP") + self.holidays_nb = Chile(subdiv="NB") def test_country_aliases(self): self.assertCountryAliases(Chile, CL, CHL) def test_special_holidays(self): - self.assertHoliday("2022-09-16") + self.assertHoliday( + "2022-09-16", + ) def test_no_holidays(self): self.assertNoHolidays(Chile(years=1914)) def test_new_year(self): - self.assertHoliday(*[f"{year}-01-01" for year in range(1915, 2050)]) + self.assertHoliday(f"{year}-01-01" for year in range(1915, 2050)) self.assertHoliday( "2017-01-02", "2023-01-02", @@ -66,14 +68,15 @@ def test_ascension(self): "1967-05-04", ) for year in range(1915, 1968): - self.assertIn( + self.assertHolidayName( + Chile(years=year), "Ascensión del Señor [Ascension of Jesus]", - ";".join(Chile(years=year).values()), ) + for year in range(1968, 2050): - self.assertNotIn( + self.assertNoHolidayName( + Chile(years=year), "Ascensión del Señor [Ascension of Jesus]", - ";".join(Chile(years=year).values()), ) def test_corpus_christi(self): @@ -88,27 +91,27 @@ def test_corpus_christi(self): "2006-06-12", ) for year in range(1915, 1968): - self.assertIn( + self.assertHolidayName( + Chile(years=year), "Corpus Christi [Corpus Christi]", - ";".join(Chile(years=year).values()), ) for year in range(1968, 1987): - self.assertNotIn( + self.assertNoHolidayName( + Chile(years=year), "Corpus Christi [Corpus Christi]", - ";".join(Chile(years=year).values()), ) for year in range(1987, 2006): - self.assertIn( + self.assertHolidayName( + Chile(years=year), "Corpus Christi [Corpus Christi]", - ";".join(Chile(years=year).values()), ) def test_labour_day(self): - self.assertHoliday(*[f"{year}-05-01" for year in range(1932, 2050)]) - self.assertNoHoliday(*[f"{year}-05-01" for year in range(1915, 1932)]) + self.assertHoliday(f"{year}-05-01" for year in range(1932, 2050)) + self.assertNoHoliday(f"{year}-05-01" for year in range(1915, 1932)) def test_navy_day(self): - self.assertHoliday(*[f"{year}-05-21" for year in range(1915, 2050)]) + self.assertHoliday(f"{year}-05-21" for year in range(1915, 2050)) def test_indigenous_peoples_day(self): self.assertHoliday( @@ -149,14 +152,14 @@ def test_indigenous_peoples_day(self): "2079-06-20", ) for year in range(1915, 2021): - self.assertNotIn( + self.assertNoHolidayName( + Chile(years=year), "Día Nacional de los Pueblos Indígenas", - ";".join(Chile(years=year).values()), ) def test_saint_peter_and_paul(self): - self.assertHoliday(*[f"{year}-06-29" for year in range(1915, 1967)]) - self.assertHoliday(*[f"{year}-06-29" for year in range(1986, 2000)]) + self.assertHoliday(f"{year}-06-29" for year in range(1915, 1967)) + self.assertHoliday(f"{year}-06-29" for year in range(1986, 2000)) self.assertHoliday( "2000-06-26", "2001-07-02", @@ -184,32 +187,36 @@ def test_saint_peter_and_paul(self): "2023-06-26", "2024-06-29", ) + for year in range(1968, 1986): - self.assertNotIn( + self.assertNoHolidayName( + Chile(years=year), "San Pedro y San Pablo", - ";".join(Chile(years=year).values()), ) def test_virgin_of_carmen(self): # Day of Virgin of Carmen started after 2006 - self.assertHoliday(*[f"{year}-07-16" for year in range(2007, 2050)]) - self.assertNoHoliday(*[f"{year}-07-16" for year in range(1915, 2007)]) + self.assertHoliday(f"{year}-07-16" for year in range(2007, 2050)) + self.assertNoHoliday(f"{year}-07-16" for year in range(1915, 2007)) def test_assumption_of_mary(self): - self.assertHoliday(*[f"{year}-08-15" for year in range(1915, 2050)]) + self.assertHoliday(f"{year}-08-15" for year in range(1915, 2050)) def test_national_liberation(self): - self.assertHoliday(*[f"{year}-09-11" for year in range(1981, 1999)]) - self.assertNoHoliday("1980-09-11", "1999-09-11") + self.assertHoliday(f"{year}-09-11" for year in range(1981, 1999)) + self.assertNoHoliday( + "1980-09-11", + "1999-09-11", + ) for year in range(1915, 1981): - self.assertNotIn( + self.assertNoHolidayName( + Chile(years=year), "Día de la Liberación Nacional", - ";".join(Chile(years=year).values()), ) for year in range(1999, 2050): - self.assertNotIn( + self.assertNoHolidayName( + Chile(years=year), "Día de la Liberación Nacional", - ";".join(Chile(years=year).values()), ) def test_national_unity(self): @@ -218,17 +225,22 @@ def test_national_unity(self): "2000-09-04", "2001-09-03", ) - self.assertNoHoliday("1998-09-07", "2002-09-02") + self.assertNoHoliday( + "1998-09-07", + "2002-09-02", + ) + for year in range(1915, 2050): - if year not in {1999, 2000, 2001}: - self.assertNotIn( - "Día de la Unidad Nacional", - ";".join(Chile(years=year).values()), - ) + if year in {1999, 2000, 2001}: + continue + self.assertNoHolidayName( + Chile(years=year), + "Día de la Unidad Nacional", + ) def test_independence_holidays(self): - self.assertHoliday(*[f"{year}-09-18" for year in range(1915, 2050)]) - self.assertHoliday(*[f"{year}-09-19" for year in range(1915, 2050)]) + self.assertHoliday(f"{year}-09-18" for year in range(1915, 2050)) + self.assertHoliday(f"{year}-09-19" for year in range(1915, 2050)) self.assertHoliday( "2007-09-17", "2012-09-17", @@ -238,21 +250,22 @@ def test_independence_holidays(self): "2021-09-17", "2024-09-20", ) - self.assertHoliday(*[f"{year}-09-20" for year in range(1932, 1945)]) + self.assertHoliday(f"{year}-09-20" for year in range(1932, 1945)) def test_columbus_day(self): for year in range(1922, 2000): if year != 1973: self.assertHoliday(f"{year}-10-12") - self.assertIn( + self.assertHolidayName( + Chile(years=year), "Día de la Raza [Columbus day]", - ";".join(Chile(years=year).values()), ) else: - self.assertNotIn( + self.assertNoHolidayName( + Chile(years=year), "Día de la Raza [Columbus day]", - ";".join(Chile(years=year).values()), ) + self.assertHoliday( "2000-10-09", "2005-10-10", @@ -264,15 +277,17 @@ def test_columbus_day(self): "2022-10-10", "2023-10-09", ) + for year in range(2000, 2020): - self.assertIn( + self.assertHolidayName( + Chile(years=year), "Día del Respeto a la Diversidad", - ";".join(Chile(years=year).values()), ) + for year in range(2020, 2050): - self.assertIn( + self.assertHolidayName( + Chile(years=year), "Día del Descubrimiento de dos Mundos", - ";".join(Chile(years=year).values()), ) def test_reformation_day(self): @@ -295,22 +310,22 @@ def test_reformation_day(self): "2023-10-27", ) for year in range(1915, 2008): - self.assertNotIn( + self.assertNoHolidayName( + Chile(years=year), "Día Nacional de las Iglesias Evangélicas y Protestantes", - ";".join(Chile(years=year).values()), ) def test_all_saints(self): - self.assertHoliday(*[f"{year}-11-01" for year in range(1915, 2050)]) + self.assertHoliday(f"{year}-11-01" for year in range(1915, 2050)) def test_immaculate_conception(self): - self.assertHoliday(*[f"{year}-12-08" for year in range(1915, 2050)]) + self.assertHoliday(f"{year}-12-08" for year in range(1915, 2050)) def test_christmas(self): - self.assertHoliday(*[f"{year}-12-25" for year in range(1915, 2050)]) - self.assertHoliday(*[f"{year}-12-24" for year in range(1944, 1989)]) - self.assertNoHoliday(*[f"{year}-12-24" for year in range(1915, 1944)]) - self.assertNoHoliday(*[f"{year}-12-24" for year in range(1989, 2050)]) + self.assertHoliday(f"{year}-12-25" for year in range(1915, 2050)) + self.assertHoliday(f"{year}-12-24" for year in range(1944, 1989)) + self.assertNoHoliday(f"{year}-12-24" for year in range(1915, 1944)) + self.assertNoHoliday(f"{year}-12-24" for year in range(1989, 2050)) def test_2019(self): # No laborables (sector público) not included @@ -350,8 +365,14 @@ def test_2020(self): "2020-12-08", "2020-12-25", ) - self.assertHoliday(self.holidays_AP, "2020-06-07") - self.assertHoliday(self.holidays_NB, "2020-08-20") + self.assertHoliday( + self.holidays_ap, + "2020-06-07", + ) + self.assertHoliday( + self.holidays_nb, + "2020-08-20", + ) def test_2021(self): # from https://feriados.cl/2021.htm @@ -374,11 +395,21 @@ def test_2021(self): "2021-12-08", "2021-12-25", ) - self.assertHoliday(self.holidays_AP, "2021-06-07") - self.assertHoliday(self.holidays_NB, "2021-08-20") + self.assertHoliday( + self.holidays_ap, + "2021-06-07", + ) + self.assertHoliday( + self.holidays_nb, + "2021-08-20", + ) def test_2050(self): - self.assertHoliday("2050-06-20") + self.assertHoliday( + "2050-06-20", + ) def test_2079(self): - self.assertHoliday("2079-06-20") + self.assertHoliday( + "2079-06-20", + ) diff --git a/test/countries/test_vietnam.py b/test/countries/test_vietnam.py index 66612c194..c6fe5a0e1 100644 --- a/test/countries/test_vietnam.py +++ b/test/countries/test_vietnam.py @@ -9,31 +9,35 @@ # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) -import unittest from datetime import date -from dateutil.relativedelta import relativedelta +from dateutil.relativedelta import relativedelta as rd -import holidays +from holidays.countries.vietnam import Vietnam, VN, VNM +from test.common import TestCase -class TestVietnam(unittest.TestCase): +class TestVietnam(TestCase): def setUp(self): - self.holidays = holidays.VN() + self.holidays = Vietnam() + + def test_country_aliases(self): + self.assertCountryAliases(Vietnam, VN, VNM) def test_common(self): - self.assertEqual( - self.holidays[date(2020, 1, 1)], "International New Year's Day" + self.assertHolidayNames( + "International New Year's Day", + "2020-01-01", ) def test_first_day_of_january(self): - for year in range(1979, 2050): - self.assertIn( - "International New Year's Day", self.holidays[date(year, 1, 1)] - ) + self.assertHolidayNames( + "International New Year's Day", + (f"{year}-01-01" for year in range(1979, 2050)), + ) def test_lunar_new_year(self): - for year, month, day in ( + for dt in ( (2008, 2, 7), (2009, 1, 26), (2010, 2, 14), @@ -50,94 +54,89 @@ def test_lunar_new_year(self): (2021, 2, 12), (2022, 2, 1), ): - self.assertEqual( - self.holidays[date(year, month, day) + relativedelta(days=-1)], + self.assertHolidayNames( "Vietnamese New Year's Eve", + date(*dt) + rd(days=-1), ) - self.assertEqual( - self.holidays[date(year, month, day) + relativedelta(days=0)], + self.assertHolidayNames( "Vietnamese New Year", + date(*dt), ) - self.assertEqual( - self.holidays[date(year, month, day) + relativedelta(days=+1)], + self.assertHolidayNames( "The second day of Tet Holiday", + date(*dt) + rd(days=+1), ) - self.assertEqual( - self.holidays[date(year, month, day) + relativedelta(days=+2)], + self.assertHolidayNames( "The third day of Tet Holiday", + date(*dt) + rd(days=+2), ) - self.assertEqual( - self.holidays[date(year, month, day) + relativedelta(days=+3)], + self.assertHolidayNames( "The forth day of Tet Holiday", + date(*dt) + rd(days=+3), ) - self.assertEqual( - self.holidays[date(year, month, day) + relativedelta(days=+4)], + self.assertHolidayNames( "The fifth day of Tet Holiday", + date(*dt) + rd(days=+4), ) def test_king_hung_day(self): - for year, month, day in ((2020, 4, 2), (2021, 4, 21), (2022, 4, 10)): - self.assertEqual( - self.holidays[date(year, month, day)], - "Hung Kings Commemoration Day", - ) + self.assertHolidayNames( + "Hung Kings Commemoration Day", + "2020-04-02", + "2021-04-21", + "2022-04-10", + ) def test_liberation_day(self): - for year in range(1979, 2050): - self.assertIn( - "Liberation Day/Reunification Day", - self.holidays[date(year, 4, 30)], - ) + self.assertHolidayNames( + "Liberation Day/Reunification Day", + (f"{year}-04-30" for year in range(1979, 2050)), + ) def test_international_labor_day(self): - for year in range(1979, 2050): - self.assertIn( - "International Labor Day", self.holidays[date(year, 5, 1)] - ) + self.assertHolidayNames( + "International Labor Day", + (f"{year}-05-01" for year in range(1979, 2050)), + ) def test_independence_day(self): - for year in range(1979, 2050): - self.assertIn("Independence Day", self.holidays[date(year, 9, 2)]) - - def test_years_range(self): - self.holidays = holidays.VN(years=range(1979, 2050)) - for year in range(1979, 2050): - self.assertIn( - "International New Year's Day", self.holidays[date(year, 1, 1)] - ) + self.assertHolidayNames( + "Independence Day", + (f"{year}-09-02" for year in range(1979, 2050)), + ) def test_observed(self): - for year, month, day in ( - # International New Year's Day - (2012, 1, 2), - (2017, 1, 2), - (2022, 1, 3), - # Hung Kings Commemoration Day - (2012, 4, 2), - (2016, 4, 18), - (2019, 4, 15), - (2022, 4, 11), - (2023, 5, 2), - # Liberation Day/Reunification Day - (2011, 5, 2), - (2016, 5, 2), - (2017, 5, 2), - (2022, 5, 2), - (2023, 5, 3), - # International Labor Day - (2011, 5, 3), - (2016, 5, 3), - (2021, 5, 3), - (2022, 5, 3), - # Independence Day - (2012, 9, 3), - (2017, 9, 4), - (2018, 9, 3), - (2023, 9, 4), - ): - self.assertIn(date(year, month, day), self.holidays) + self.assertHoliday( + # International New Year's Day. + "2012-01-02", + "2017-01-02", + "2022-01-03", + # Hung Kings Commemoration Day. + "2012-04-02", + "2016-04-18", + "2019-04-15", + "2022-04-11", + "2023-05-02", + # Liberation Day/Reunification Day. + "2011-05-02", + "2016-05-02", + "2017-05-02", + "2022-05-02", + "2023-05-03", + # International Labor Day. + "2011-05-03", + "2016-05-03", + "2021-05-03", + "2022-05-03", + # Independence Day. + "2012-09-03", + "2017-09-04", + "2018-09-03", + "2023-09-04", + ) def test_not_observed(self): - self.holidays = holidays.VN(observed=False) - # New Years Day - self.assertNotIn("2023-01-02", self.holidays) + self.assertNoHoliday( + Vietnam(observed=False), + "2023-01-02", + ) From 14520d0cb641db0036ae8fd76ab439e1d4b67ba4 Mon Sep 17 00:00:00 2001 From: Arkadii Yakovets Date: Tue, 3 Jan 2023 07:53:16 -0800 Subject: [PATCH 102/138] Migrate prophet.hdays countries. - Add Philippines, Thailand initial support. - Update Belarus, Georgia, India, Indonesia, Russia. - Refactor tests. --- holidays/countries/__init__.py | 2 + holidays/countries/belarus.py | 23 ++-- holidays/countries/georgia.py | 2 +- holidays/countries/india.py | 35 ++++++ holidays/countries/indonesia.py | 53 ++++----- holidays/countries/philippines.py | 103 +++++++++++++++++ holidays/countries/russia.py | 40 +++---- holidays/countries/thailand.py | 171 +++++++++++++++++++++++++++++ test/common.py | 4 +- test/countries/test_belarus.py | 94 ++++++++-------- test/countries/test_georgia.py | 55 ++++++---- test/countries/test_india.py | 110 +++++++++++-------- test/countries/test_indonesia.py | 13 ++- test/countries/test_philippines.py | 45 ++++++++ test/countries/test_russia.py | 57 +++++----- test/countries/test_thailand.py | 80 ++++++++++++++ 16 files changed, 684 insertions(+), 203 deletions(-) create mode 100644 holidays/countries/philippines.py create mode 100644 holidays/countries/thailand.py create mode 100644 test/countries/test_philippines.py create mode 100644 test/countries/test_thailand.py diff --git a/holidays/countries/__init__.py b/holidays/countries/__init__.py index 8cb48c057..286d2430e 100644 --- a/holidays/countries/__init__.py +++ b/holidays/countries/__init__.py @@ -83,6 +83,7 @@ from .pakistan import PK, PAK, Pakistan from .paraguay import PY, PRY, Paraguay from .peru import PE, PER, Peru +from .philippines import PH, PHL, Philippines from .poland import PL, POL, Poland from .portugal import PT, PRT, Portugal from .romania import RO, ROU, Romania @@ -98,6 +99,7 @@ from .sweden import SE, SWE, Sweden from .switzerland import CH, CHE, Switzerland from .taiwan import TW, TWN, Taiwan +from .thailand import TH, THA, Thailand from .tunisia import TN, TUN, Tunisia from .turkey import TR, TUR, Turkey from .ukraine import UA, UKR, Ukraine diff --git a/holidays/countries/belarus.py b/holidays/countries/belarus.py index 348a7f2e0..58c3e6dfb 100644 --- a/holidays/countries/belarus.py +++ b/holidays/countries/belarus.py @@ -27,26 +27,25 @@ class Belarus(HolidayBase): country = "BY" def _populate(self, year): - super()._populate(year) - # The current set of holidays came into force in 1998 # http://laws.newsby.org/documents/ukazp/pos05/ukaz05806.htm if year <= 1998: return + super()._populate(year) + # New Year's Day self[date(year, JAN, 1)] = "Новый год" # Jan 2nd is the national holiday (New Year) from 2020 # http://president.gov.by/uploads/documents/2019/464uk.pdf if year >= 2020: - # New Year's Day self[date(year, JAN, 2)] = "Новый год" # Christmas Day (Orthodox) - self[date(year, JAN, 7)] = ( - "Рождество Христово " "(православное Рождество)" - ) + self[ + date(year, JAN, 7) + ] = "Рождество Христово (православное Рождество)" # Women's Day self[date(year, MAR, 8)] = "День женщин" @@ -61,17 +60,17 @@ def _populate(self, year): self[date(year, MAY, 9)] = "День Победы" # Independence Day - self[date(year, JUL, 3)] = ( - "День Независимости Республики Беларусь " "(День Республики)" - ) + self[ + date(year, JUL, 3) + ] = "День Независимости Республики Беларусь (День Республики)" # October Revolution Day self[date(year, NOV, 7)] = "День Октябрьской революции" # Christmas Day (Catholic) - self[date(year, DEC, 25)] = ( - "Рождество Христово " "(католическое Рождество)" - ) + self[ + date(year, DEC, 25) + ] = "Рождество Христово (католическое Рождество)" class BY(Belarus): diff --git a/holidays/countries/georgia.py b/holidays/countries/georgia.py index f223ece7d..39c0114b1 100644 --- a/holidays/countries/georgia.py +++ b/holidays/countries/georgia.py @@ -61,7 +61,7 @@ def _populate(self, year): name = "დიდი შაბათი" self[easter_date + rd(days=-1)] = name - # Orthodox Easter Sunday + # Orthodox Easter Sunday name = "აღდგომა" self[easter_date] = name diff --git a/holidays/countries/india.py b/holidays/countries/india.py index 004bb7754..bc5d98b93 100644 --- a/holidays/countries/india.py +++ b/holidays/countries/india.py @@ -12,8 +12,12 @@ import warnings from datetime import date +from dateutil.easter import easter +from dateutil.relativedelta import relativedelta as rd + from holidays.constants import JAN, MAR, APR, MAY, JUN, AUG, OCT, NOV, DEC from holidays.holiday_base import HolidayBase +from holidays.utils import _islamic_to_gre class India(HolidayBase): @@ -250,6 +254,37 @@ def _populate(self, year): hol_date = date(year, *holi_dates[year]) self[hol_date] = "Holi" + # Islamic holidays + # Day of Ashura (10th day of 1st Islamic month) + name = "Day of Ashura" + for dt in _islamic_to_gre(year, 10, 1): + self[dt] = f"{name}* (*estimated)" + + # Mawlid, Birth of the Prophet (12th day of 3rd Islamic month) + name = "Mawlid" + for dt in _islamic_to_gre(year, 10, 1): + self[dt] = f"f{name}* (*estimated)" + + # Eid ul-Fitr (1st and 2nd day of 10th Islamic month) + name = "Eid ul-Fitr" + for dt in _islamic_to_gre(year, 10, 1): + self[dt] = f"{name}* (*estimated)" + self[dt + rd(days=+1)] = f"{name}* (*estimated)" + + # Eid al-Adha, i.e., Feast of the Sacrifice + name = "Eid al-Adha" + for dt in _islamic_to_gre(year, 12, 10): + self[dt] = f"{name}* (*estimated)" + self[dt + rd(days=+1)] = f"{name}* (*estimated)" + + # Christian holidays + easter_date = easter(year) + self[easter_date + rd(days=-7)] = "Palm Sunday" + self[easter_date + rd(days=-2)] = "Good Friday" + self[easter_date] = "Easter Sunday" + self[easter_date + rd(days=+49)] = "Feast of Pentecost" + self[date(year, DEC, 25)] = "Christmas Day" + class IN(India): pass diff --git a/holidays/countries/indonesia.py b/holidays/countries/indonesia.py index c5ee8e0d2..b13890dcc 100644 --- a/holidays/countries/indonesia.py +++ b/holidays/countries/indonesia.py @@ -47,31 +47,32 @@ def _populate(self, year): hol_date = self.cnls.lunar_n_y_date(year) self[hol_date] = "Tahun Baru Imlek" - # Day of Silence - # https://en.wikipedia.org/wiki/Nyepi - dates_obs = { - 2009: (MAR, 26), - 2010: (MAR, 16), - 2011: (MAR, 5), - 2012: (MAR, 23), - 2013: (MAR, 12), - 2014: (MAR, 31), - 2015: (MAR, 21), - 2016: (MAR, 9), - 2017: (MAR, 28), - 2018: (MAR, 17), - 2019: (MAR, 7), - 2020: (MAR, 25), - 2021: (MAR, 14), - 2022: (MAR, 3), - 2023: (MAR, 22), - 2024: (MAR, 11), - 2025: (MAR, 29), - 2026: (MAR, 19), - } - if year in dates_obs: - hol_date = date(year, *dates_obs[year]) - self[hol_date] = "Hari Suci Nyepi" + if year >= 1983: + # Day of Silence + # https://en.wikipedia.org/wiki/Nyepi + dates_obs = { + 2009: (MAR, 26), + 2010: (MAR, 16), + 2011: (MAR, 5), + 2012: (MAR, 23), + 2013: (MAR, 12), + 2014: (MAR, 31), + 2015: (MAR, 21), + 2016: (MAR, 9), + 2017: (MAR, 28), + 2018: (MAR, 17), + 2019: (MAR, 7), + 2020: (MAR, 25), + 2021: (MAR, 14), + 2022: (MAR, 3), + 2023: (MAR, 22), + 2024: (MAR, 11), + 2025: (MAR, 29), + 2026: (MAR, 19), + } + if year in dates_obs: + hol_date = date(year, *dates_obs[year]) + self[hol_date] = "Hari Suci Nyepi" # Eid al-Fitr dates_obs = { @@ -288,7 +289,7 @@ def _populate(self, year): if year >= 2017: self[date(year, JUN, 1)] = "Hari Lahir Pancasila" - # National Day + # Independence Day self[date(year, AUG, 17)] = "Hari Kemerdekaan Republik Indonesia" # Christmas Day diff --git a/holidays/countries/philippines.py b/holidays/countries/philippines.py new file mode 100644 index 000000000..d65d7149f --- /dev/null +++ b/holidays/countries/philippines.py @@ -0,0 +1,103 @@ +# 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 (c) 2017-2022 +# ryanss (c) 2014-2017 +# Website: https://github.com/dr-prodigy/python-holidays +# License: MIT (see LICENSE file) + +from datetime import date + +from dateutil.easter import easter +from dateutil.relativedelta import relativedelta as rd + +from holidays.constants import JAN, FEB, APR, MAY, JUN, AUG, NOV, DEC +from holidays.holiday_base import HolidayBase +from holidays.utils import _ChineseLuniSolar, _islamic_to_gre + + +class Philippines(HolidayBase): + """ + Philippines holidays. + + References: + - https://en.wikipedia.org/wiki/Public_holidays_in_Thailand + """ + + country = "PH" + + def __init__(self, **kwargs): + self.cnls = _ChineseLuniSolar() + HolidayBase.__init__(self, **kwargs) + + def _populate(self, year): + super()._populate(year) + + # New Year's Day. + self[date(year, JAN, 1)] = "New Year's Day" + + # Chinese New Year. + self[self.cnls.lunar_n_y_date(year)] = "Chinese New Year" + + # People Power Anniversary. + self[date(year, FEB, 25)] = "EDSA Revolution Anniversary" + + # Day of Valor. + self[date(year, APR, 9)] = "Day of Valor" + + easter_date = easter(year) + # Maundy Thursday. + self[easter_date + rd(days=-3)] = "Maundy Thursday" + # Good Friday. + self[easter_date + rd(days=-2)] = "Good Friday" + # Black Saturday. + self[easter_date + rd(days=-1)] = "Black Saturday" + + # Labour Day. + self[date(year, MAY, 1)] = "Labour Day" + + # Eid al-Fitr. + for dt in _islamic_to_gre(year, 10, 1): + self[dt] = "Eid'l Fitr" + + # Independence Day. + self[date(year, JUN, 12)] = "Independence Day" + + # Eid al-Adha. + for dt in _islamic_to_gre(year, 12, 10): + self[dt] = "Eid'l Adha" + + # Ninoy Aquino Day. + self[date(year, AUG, 21)] = "Ninoy Aquino Day" + + # National Heroes Day. + self[date(year, AUG, 27)] = "National Heroes Day" + + # All Saints' Day. + self[date(year, NOV, 1)] = "All Saints' Day" + + # Bonifacio Day. + self[date(year, NOV, 30)] = "Bonifacio Day" + + # Immaculate Conception Day. + self[date(year, DEC, 8)] = "Immaculate Conception Day" + + # Christmas Day. + self[date(year, DEC, 25)] = "Christmas Day" + + # Rizal Day. + self[date(year, DEC, 30)] = "Rizal Day" + + # New Year's Eve. + self[date(year, DEC, 31)] = "New Year's Eve" + + +class PH(Philippines): + pass + + +class PHL(Philippines): + pass diff --git a/holidays/countries/russia.py b/holidays/countries/russia.py index 2b0c40f1c..e3311dd22 100644 --- a/holidays/countries/russia.py +++ b/holidays/countries/russia.py @@ -11,7 +11,7 @@ from datetime import date -from holidays.constants import JAN, FEB, MAR, MAY, JUN, NOV, DEC +from holidays.constants import JAN, FEB, MAR, MAY, JUN, NOV from holidays.holiday_base import HolidayBase @@ -25,40 +25,36 @@ class Russia(HolidayBase): def _populate(self, year): super()._populate(year) - # New Year's Day - self[date(year, JAN, 1)] = "Новый год" - # New Year's Day - self[date(year, JAN, 2)] = "Новый год" - # New Year's Day - self[date(year, JAN, 3)] = "Новый год" - # New Year's Day - self[date(year, JAN, 4)] = "Новый год" - # New Year's Day - self[date(year, JAN, 5)] = "Новый год" - # New Year's Day - self[date(year, JAN, 6)] = "Новый год" + # New Year Holidays + name = "Новогодние каникулы" + for day in range(1, 7): + self[date(year, JAN, day)] = name + self[date(year, JAN, 8)] = name + # Christmas Day (Orthodox) - self[date(year, JAN, 7)] = "Православное Рождество" - # New Year's Day - self[date(year, JAN, 8)] = "Новый год" - # Man Day - self[date(year, FEB, 23)] = "День защитника отечества" - # Women's Day - self[date(year, MAR, 8)] = "День женщин" + self[date(year, JAN, 7)] = "Рождество Христово" + + # Defender of the Fatherland Day + self[date(year, FEB, 23)] = "День защитника Отечества" + + # International Women's Day + self[date(year, MAR, 8)] = "Международный женский день" + # Labour Day self[date(year, MAY, 1)] = "Праздник Весны и Труда" + # Victory Day self[date(year, MAY, 9)] = "День Победы" + # Russia's Day self[date(year, JUN, 12)] = "День России" + if year >= 2005: # Unity Day self[date(year, NOV, 4)] = "День народного единства" else: # October Revolution Day self[date(year, NOV, 7)] = "День Октябрьской революции" - # New Year's Day - self[date(year, DEC, 31)] = "Новый год" class RU(Russia): diff --git a/holidays/countries/thailand.py b/holidays/countries/thailand.py new file mode 100644 index 000000000..a013983ee --- /dev/null +++ b/holidays/countries/thailand.py @@ -0,0 +1,171 @@ +# 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 (c) 2017-2022 +# ryanss (c) 2014-2017 +# Website: https://github.com/dr-prodigy/python-holidays +# License: MIT (see LICENSE file) + +from datetime import date + +from dateutil.relativedelta import relativedelta as rd + +from holidays.constants import FEB, MAR, APR, MAY, JUN, JUL, AUG, OCT, DEC, SAT +from holidays.holiday_base import HolidayBase +from holidays.utils import _ChineseLuniSolar + + +class Thailand(HolidayBase): + """ + Thailand holidays. + + References: + - https://en.wikipedia.org/wiki/Public_holidays_in_Thailand + """ + + country = "TH" + + def __init__(self, **kwargs): + self.cnls = _ChineseLuniSolar() + HolidayBase.__init__(self, **kwargs) + + def _populate(self, year): + def add_holiday(dt, holiday_name): + if dt.year != year: + return + + self[dt] = holiday_name + if self.observed and self._is_weekend(dt): + in_lieu = dt + rd(days=2 if dt.weekday() == SAT else 1) + while in_lieu.year == year and in_lieu in self: + in_lieu += rd(days=+1) + + add_holiday(in_lieu, f"{holiday_name} (in lieu)") + + super()._populate(year) + + # New Year's Day. + add_holiday(date(year, 1, 1), "New Year's Day") + + # Magha Pujab. + # TODO(ark): research Buddhist calendar options. + magha_puja = { + 2016: (FEB, 22), + 2017: (FEB, 11), + 2018: (MAR, 1), + 2019: (FEB, 19), + 2020: (FEB, 26), + 2021: (FEB, 26), + 2022: (FEB, 16), + 2023: (MAR, 6), + } + if year in magha_puja: + add_holiday(date(year, *magha_puja[year]), "Makha Bucha") + + # Chakri Memorial Day. + add_holiday(date(year, APR, 6), "Chakri Memorial Day") + + # Songkran Festival. + songkran_festival = "Songkran Festival" + add_holiday(date(year, APR, 13), songkran_festival) + add_holiday(date(year, APR, 14), songkran_festival) + add_holiday(date(year, APR, 15), songkran_festival) + + # Labour day. + add_holiday(date(year, MAY, 1), "Labour Day") + + # Buddha's Birthday. + add_holiday(self.cnls.vesak_may_date(year), "Buddha's Birthday") + + # Coronation Day. + if year <= 2016: + add_holiday(date(year, MAY, 4), "Coronation Day") + + # Queen's Birthday. + add_holiday(date(year, JUN, 3), "Queen Suthida's Birthday") + + # King's Birthday. + add_holiday(date(year, JUL, 28), "King's Birthday") + + # Asalha Puja. + asalha_puja = { + 2006: (JUL, 11), + 2007: (JUN, 30), + 2008: (JUL, 18), + 2009: (JUL, 7), + 2010: (JUL, 25), + 2011: (JUL, 15), + 2012: (AUG, 2), + 2013: (JUL, 30), + 2014: (JUL, 13), + 2015: (JUL, 30), + 2016: (JUL, 15), + 2017: (JUL, 9), + 2018: (JUL, 29), + 2019: (JUL, 16), + 2020: (JUL, 5), + 2021: (JUL, 24), + 2022: (JUL, 13), + 2023: (JUL, 3), + 2024: (JUL, 21), + 2025: (JUL, 10), + } + if year in asalha_puja: + add_holiday(date(year, *asalha_puja[year]), "Asalha Puja") + + # Beginning of Vassa. + vassa = { + 2006: (JUL, 12), + 2007: (JUL, 31), + 2008: (JUL, 19), + 2009: (JUL, 8), + 2010: (JUL, 27), + 2011: (JUL, 16), + 2012: (AUG, 3), + 2013: (JUL, 23), + 2014: (JUL, 13), + 2015: (AUG, 1), + 2016: (JUL, 20), + 2017: (JUL, 9), + 2018: (JUL, 28), + 2019: (JUL, 17), + 2020: (JUL, 6), + 2021: (JUL, 25), + 2022: (JUL, 14), + 2023: (AUG, 2), + 2024: (JUL, 21), + 2025: (JUL, 23), + } + if year in vassa: + add_holiday(date(year, *vassa[year]), "Beginning of Vassa") + + # The Queen Sirikit's Birthday. + add_holiday(date(year, AUG, 12), "The Queen Mother's Birthday") + + # Anniversary for the Death of King Bhumibol Adulyadej. + add_holiday( + date(year, OCT, 13), "King Bhumibol Adulyadej Memorial Day" + ) + + # King Chulalongkorn Day + add_holiday(date(year, OCT, 23), "King Chulalongkorn Day") + + # King Bhumibol Adulyadej's Birthday Anniversary. + add_holiday(date(year, DEC, 5), "King Bhumibol Adulyadej's Birthday") + + # Constitution Day. + add_holiday(date(year, DEC, 10), "Constitution Day") + + # New Year's Eve. + add_holiday(date(year, DEC, 31), "New Year's Eve") + + +class TH(Thailand): + pass + + +class THA(Thailand): + pass diff --git a/test/common.py b/test/common.py index 481d86906..7eb0e1d47 100644 --- a/test/common.py +++ b/test/common.py @@ -74,7 +74,6 @@ def assertCountryAliases(self, cls, alpha_2, alpha_3): for alias in (alpha_2, alpha_3): self.assertIsNotNone(alias, type_error_message) self.assertTrue(issubclass(alias, cls), type_error_message) - self.assertEqual(alias(), cls()) length_error_message = ( "This method accepts exactly 3 arguments " @@ -107,12 +106,13 @@ def assertHolidaysEqual(self, holidays, *expected_holidays): self.verify_type(holidays) - self.assertEqual(len(holidays), len(expected_holidays)) # Check one by one for descriptive error messages. for dt, name in expected_holidays: self.assertIn(dt, holidays) self.assertEqual(name, holidays[dt]) + self.assertEqual(len(holidays), len(expected_holidays)) + def assertHolidayDatesEqual(self, holidays, *dates): """Asserts holiday dates exactly match expected dates.""" diff --git a/test/countries/test_belarus.py b/test/countries/test_belarus.py index c17151f8a..32c6cc928 100644 --- a/test/countries/test_belarus.py +++ b/test/countries/test_belarus.py @@ -1,6 +1,6 @@ # python-holidays # --------------- -# A fast, efficient Python library for generating country, province and state +# 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. # @@ -9,58 +9,66 @@ # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) -import unittest -from datetime import date +from holidays.countries.belarus import BY, BLR, Belarus +from test.common import TestCase -import holidays - -class TestBelarus(unittest.TestCase): +class TestBelarus(TestCase): def setUp(self): - self.holidays = holidays.BY() + self.holidays = Belarus() + + def test_country_aliases(self): + self.assertCountryAliases(Belarus, BY, BLR) def test_2018(self): # http://calendar.by/procal.php?year=2018 # https://www.officeholidays.com/countries/belarus/index.php - self.assertIn(date(2018, 1, 1), self.holidays) - self.assertIn(date(2018, 1, 7), self.holidays) - self.assertIn(date(2018, 3, 8), self.holidays) - self.assertIn(date(2018, 4, 17), self.holidays) - self.assertIn(date(2018, 5, 1), self.holidays) - self.assertIn(date(2018, 5, 9), self.holidays) - self.assertIn(date(2018, 7, 3), self.holidays) - self.assertIn(date(2018, 11, 7), self.holidays) - self.assertIn(date(2018, 12, 25), self.holidays) + self.assertHoliday( + "2018-01-01", + "2018-01-07", + "2018-03-08", + "2018-04-17", + "2018-05-01", + "2018-05-09", + "2018-07-03", + "2018-11-07", + "2018-12-25", + ) def test_new_year(self): - self.assertIn(date(2019, 1, 1), self.holidays) - self.assertNotIn(date(2019, 1, 2), self.holidays) - self.assertIn(date(2020, 1, 1), self.holidays) - self.assertIn(date(2020, 1, 2), self.holidays) - self.assertIn(date(2021, 1, 1), self.holidays) - self.assertIn(date(2021, 1, 2), self.holidays) + self.assertHoliday( + "2019-01-01", + "2020-01-01", + "2020-01-02", + "2021-01-01", + "2021-01-02", + ) + + self.assertNoHoliday("2019-01-02") def test_radunitsa(self): # http://calendar.by/content.php?id=20 - self.assertIn(date(2012, 4, 24), self.holidays) - self.assertIn(date(2013, 5, 14), self.holidays) - self.assertIn(date(2014, 4, 29), self.holidays) - self.assertIn(date(2015, 4, 21), self.holidays) - self.assertIn(date(2016, 5, 10), self.holidays) - self.assertIn(date(2017, 4, 25), self.holidays) - self.assertIn(date(2018, 4, 17), self.holidays) - self.assertIn(date(2019, 5, 7), self.holidays) - self.assertIn(date(2020, 4, 28), self.holidays) - self.assertIn(date(2021, 5, 11), self.holidays) - self.assertIn(date(2022, 5, 3), self.holidays) - self.assertIn(date(2023, 4, 25), self.holidays) - self.assertIn(date(2024, 5, 14), self.holidays) - self.assertIn(date(2025, 4, 29), self.holidays) - self.assertIn(date(2026, 4, 21), self.holidays) - self.assertIn(date(2027, 5, 11), self.holidays) - self.assertIn(date(2028, 4, 25), self.holidays) - self.assertIn(date(2029, 4, 17), self.holidays) - self.assertIn(date(2030, 5, 7), self.holidays) + self.assertHoliday( + "2012-04-24", + "2013-05-14", + "2014-04-29", + "2015-04-21", + "2016-05-10", + "2017-04-25", + "2018-04-17", + "2019-05-07", + "2020-04-28", + "2021-05-11", + "2022-05-03", + "2023-04-25", + "2024-05-14", + "2025-04-29", + "2026-04-21", + "2027-05-11", + "2028-04-25", + "2029-04-17", + "2030-05-07", + ) - def test_before_1998(self): - self.assertNotIn(date(1997, 7, 3), self.holidays) + def test_pre_1998(self): + self.assertNoHoliday("1997-07-03") diff --git a/test/countries/test_georgia.py b/test/countries/test_georgia.py index 11cf61ed1..4cd0fd972 100644 --- a/test/countries/test_georgia.py +++ b/test/countries/test_georgia.py @@ -9,37 +9,44 @@ # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) -import unittest -from datetime import date +from holidays.countries.georgia import GE, GEO, Georgia +from test.common import TestCase -import holidays - -class TestGeorgia(unittest.TestCase): +class TestGeorgia(TestCase): def setUp(self): - self.holidays = holidays.GE() + self.holidays = Georgia() + + def test_country_aliases(self): + self.assertCountryAliases(Georgia, GE, GEO) def test_easter(self): - self.assertIn(date(2020, 4, 19), self.holidays) - self.assertIn(date(2019, 4, 28), self.holidays) - self.assertIn(date(2018, 4, 8), self.holidays) + self.assertHoliday( + "2020-04-19", + "2019-04-28", + "2018-04-08", + ) def test_2020(self): # https://en.wikipedia.org/wiki/Public_holidays_in_Georgia_(country) - self.assertIn(date(2020, 1, 1), self.holidays) - self.assertIn(date(2020, 1, 2), self.holidays) - self.assertIn(date(2020, 1, 7), self.holidays) - self.assertIn(date(2020, 1, 19), self.holidays) - self.assertIn(date(2020, 3, 3), self.holidays) - self.assertIn(date(2020, 3, 8), self.holidays) - self.assertIn(date(2020, 4, 9), self.holidays) - self.assertIn(date(2020, 5, 9), self.holidays) - self.assertIn(date(2020, 5, 12), self.holidays) - self.assertIn(date(2020, 5, 26), self.holidays) - self.assertIn(date(2020, 8, 28), self.holidays) - self.assertIn(date(2020, 10, 14), self.holidays) - self.assertIn(date(2020, 11, 23), self.holidays) + self.assertHoliday( + "2020-01-01", + "2020-01-02", + "2020-01-07", + "2020-01-19", + "2020-03-03", + "2020-03-08", + "2020-04-09", + "2020-05-09", + "2020-05-12", + "2020-05-26", + "2020-08-28", + "2020-10-14", + "2020-11,-23", + ) def test_not_holiday(self): - self.assertNotIn("2020-08-16", self.holidays) - self.assertNotIn("2008-08-05", self.holidays) + self.assertNoHoliday( + "2020-08-16", + "2008-08-05", + ) diff --git a/test/countries/test_india.py b/test/countries/test_india.py index ca2749e0e..d0d843c6c 100644 --- a/test/countries/test_india.py +++ b/test/countries/test_india.py @@ -9,16 +9,19 @@ # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) -import unittest import warnings from datetime import date -import holidays +from holidays.countries.india import IN, IND, India +from test.common import TestCase -class TestIND(unittest.TestCase): +class TestIndia(TestCase): def setUp(self): - self.holidays = holidays.IND() + self.holidays = India() + + def test_country_aliases(self): + self.assertCountryAliases(India, IN, IND) def test_2018(self): self.assertIn(date(2018, 1, 14), self.holidays) @@ -31,43 +34,43 @@ def test_2018(self): self.assertIn(date(2018, 11, 7), self.holidays) self.assertIn(date(2018, 3, 2), self.holidays) - ap_holidays = holidays.IND(subdiv="AP") - ar_holidays = holidays.IND(subdiv="AR") - as_holidays = holidays.IND(subdiv="AS") - br_holidays = holidays.IND(subdiv="BR") - cg_holidays = holidays.IND(subdiv="CG") - ga_holidays = holidays.IND(subdiv="GA") - gj_holidays = holidays.IND(subdiv="GJ") - hr_holidays = holidays.IND(subdiv="HR") - hp_holidays = holidays.IND(subdiv="HP") - jk_holidays = holidays.IND(subdiv="JK") - jh_holidays = holidays.IND(subdiv="JH") - ka_holidays = holidays.IND(subdiv="KA") - kl_holidays = holidays.IND(subdiv="KL") - mp_holidays = holidays.IND(subdiv="MP") - mh_holidays = holidays.IND(subdiv="MH") - mn_holidays = holidays.IND(subdiv="MN") - ml_holidays = holidays.IND(subdiv="ML") - mz_holidays = holidays.IND(subdiv="MZ") - nl_holidays = holidays.IND(subdiv="NL") - or_holidays = holidays.IND(subdiv="OR") - pb_holidays = holidays.IND(subdiv="PB") - rj_holidays = holidays.IND(subdiv="RJ") - sk_holidays = holidays.IND(subdiv="SK") - tn_holidays = holidays.IND(subdiv="TN") - tr_holidays = holidays.IND(subdiv="TR") - ts_holidays = holidays.IND(subdiv="TS") - uk_holidays = holidays.IND(subdiv="UK") - up_holidays = holidays.IND(subdiv="UP") - wb_holidays = holidays.IND(subdiv="WB") - an_holidays = holidays.IND(subdiv="AN") - ch_holidays = holidays.IND(subdiv="CH") - dh_holidays = holidays.IND(subdiv="DH") - dd_holidays = holidays.IND(subdiv="DD") - dl_holidays = holidays.IND(subdiv="DL") - la_holidays = holidays.IND(subdiv="LA") - ld_holidays = holidays.IND(subdiv="LD") - py_holidays = holidays.IND(subdiv="PY") + ap_holidays = India(subdiv="AP") + ar_holidays = India(subdiv="AR") + as_holidays = India(subdiv="AS") + br_holidays = India(subdiv="BR") + cg_holidays = India(subdiv="CG") + ga_holidays = India(subdiv="GA") + gj_holidays = India(subdiv="GJ") + hr_holidays = India(subdiv="HR") + hp_holidays = India(subdiv="HP") + jk_holidays = India(subdiv="JK") + jh_holidays = India(subdiv="JH") + ka_holidays = India(subdiv="KA") + kl_holidays = India(subdiv="KL") + mp_holidays = India(subdiv="MP") + mh_holidays = India(subdiv="MH") + mn_holidays = India(subdiv="MN") + ml_holidays = India(subdiv="ML") + mz_holidays = India(subdiv="MZ") + nl_holidays = India(subdiv="NL") + or_holidays = India(subdiv="OR") + pb_holidays = India(subdiv="PB") + rj_holidays = India(subdiv="RJ") + sk_holidays = India(subdiv="SK") + tn_holidays = India(subdiv="TN") + tr_holidays = India(subdiv="TR") + ts_holidays = India(subdiv="TS") + uk_holidays = India(subdiv="UK") + up_holidays = India(subdiv="UP") + wb_holidays = India(subdiv="WB") + an_holidays = India(subdiv="AN") + ch_holidays = India(subdiv="CH") + dh_holidays = India(subdiv="DH") + dd_holidays = India(subdiv="DD") + dl_holidays = India(subdiv="DL") + la_holidays = India(subdiv="LA") + ld_holidays = India(subdiv="LD") + py_holidays = India(subdiv="PY") for dt in [date(2018, 1, 14), date(2018, 5, 1), date(2018, 10, 31)]: self.assertIn(dt, gj_holidays) @@ -128,11 +131,11 @@ def test_diwali_and_holi(self): warnings.simplefilter("always") with self.assertWarns(Warning): # Diwali and Holi out of range - holidays.IN(years=2000) + India(years=2000) with self.assertWarns(Warning): # Diwali and Holi out of range - holidays.IN(years=2031) + India(years=2031) diwali_name = "Diwali" holi_name = "Holi" @@ -184,3 +187,24 @@ def test_pre_1947(self): def test_pre_1950(self): self.assertNotIn(date(1949, 1, 26), self.holidays) + + def test_good_friday(self): + self.assertHoliday( + "1994-04-01", + "2017-04-14", + "2020-04-10", + ) + + def test_easter_sunday(self): + self.assertHoliday( + "1994-04-03", + "2017-04-16", + "2020-04-12", + ) + + def test_palm_sunday(self): + self.assertHoliday( + "1994-03-27", + "2017-04-09", + "2020-04-05", + ) diff --git a/test/countries/test_indonesia.py b/test/countries/test_indonesia.py index 774ce5454..27942f478 100644 --- a/test/countries/test_indonesia.py +++ b/test/countries/test_indonesia.py @@ -9,15 +9,18 @@ # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) -import unittest from datetime import date -import holidays +from holidays.countries.indonesia import ID, IDN, Indonesia +from test.common import TestCase -class TestIndonesia(unittest.TestCase): +class TestIndonesia(TestCase): def setUp(self): - self.holidays = holidays.ID() + self.holidays = Indonesia() + + def test_country_aliases(self): + self.assertCountryAliases(Indonesia, ID, IDN) def test_lunar_new_year(self): for year, month, day in ( @@ -57,6 +60,8 @@ def test_day_of_silence(self): self.holidays[date(year, month, day)], "Hari Suci Nyepi" ) + self.assertFalse(Indonesia(years=1982).get_named("Hari Suci Nyepi")) + def test_islamic_holidays(self): for year, month, day in ( # Eid al-Fitr diff --git a/test/countries/test_philippines.py b/test/countries/test_philippines.py new file mode 100644 index 000000000..b5372c1ad --- /dev/null +++ b/test/countries/test_philippines.py @@ -0,0 +1,45 @@ +# 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 (c) 2017-2022 +# ryanss (c) 2014-2017 +# Website: https://github.com/dr-prodigy/python-holidays +# License: MIT (see LICENSE file) + +from holidays.countries.philippines import PH, PHL, Philippines +from test.common import TestCase + + +class TestPhilippines(TestCase): + def setUp(self): + self.holidays = Philippines() + + def test_country_aliases(self): + self.assertCountryAliases(Philippines, PH, PHL) + + def test_2022(self): + self.assertHolidaysEqual( + Philippines(years=2022), + ("2022-01-01", "New Year's Day"), + ("2022-02-01", "Chinese New Year"), + ("2022-02-25", "EDSA Revolution Anniversary"), + ("2022-04-09", "Day of Valor"), + ("2022-04-14", "Maundy Thursday"), + ("2022-04-15", "Good Friday"), + ("2022-04-16", "Black Saturday"), + ("2022-05-01", "Labour Day"), + ("2022-05-02", "Eid'l Fitr"), + ("2022-06-12", "Independence Day"), + ("2022-07-09", "Eid'l Adha"), + ("2022-08-21", "Ninoy Aquino Day"), + ("2022-08-27", "National Heroes Day"), + ("2022-11-01", "All Saints' Day"), + ("2022-11-30", "Bonifacio Day"), + ("2022-12-08", "Immaculate Conception Day"), + ("2022-12-25", "Christmas Day"), + ("2022-12-30", "Rizal Day"), + ("2022-12-31", "New Year's Eve"), + ) diff --git a/test/countries/test_russia.py b/test/countries/test_russia.py index 0346770a7..c72720ee6 100644 --- a/test/countries/test_russia.py +++ b/test/countries/test_russia.py @@ -9,35 +9,40 @@ # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) -import unittest -from datetime import date +from holidays.countries.russia import RU, RUS, Russia +from test.common import TestCase -import holidays - -class TestRussia(unittest.TestCase): +class TestRussia(TestCase): def setUp(self): - self.holidays = holidays.RU() + self.holidays = Russia() + + def test_country_aliases(self): + self.assertCountryAliases(Russia, RU, RUS) - def test_before_2005(self): - self.assertIn(date(2004, 11, 7), self.holidays) - self.assertNotIn(date(2004, 11, 4), self.holidays) + def test_pre_2005(self): + self.assertHoliday("2004-11-07") + self.assertNoHoliday("2004-11-04") def test_2018(self): - # https://en.wikipedia.org/wiki/Public_holidays_in_Russia - self.assertIn(date(2018, 1, 1), self.holidays) - self.assertIn(date(2018, 1, 2), self.holidays) - self.assertIn(date(2018, 1, 3), self.holidays) - self.assertIn(date(2018, 1, 4), self.holidays) - self.assertIn(date(2018, 1, 5), self.holidays) - self.assertIn(date(2018, 1, 6), self.holidays) - self.assertIn(date(2018, 1, 7), self.holidays) - self.assertIn(date(2018, 1, 8), self.holidays) - self.assertIn(date(2018, 2, 23), self.holidays) - self.assertIn(date(2018, 3, 8), self.holidays) - self.assertIn(date(2018, 5, 1), self.holidays) - self.assertIn(date(2018, 5, 9), self.holidays) - self.assertIn(date(2018, 6, 12), self.holidays) - self.assertIn(date(2018, 11, 4), self.holidays) - self.assertNotIn(date(2018, 11, 7), self.holidays) - self.assertIn(date(2018, 12, 31), self.holidays) + self.assertHoliday( + "2018-01-01", + "2018-01-02", + "2018-01-03", + "2018-01-04", + "2018-01-05", + "2018-01-06", + "2018-01-07", + "2018-01-08", + "2018-02-23", + "2018-03-08", + "2018-05-01", + "2018-05-09", + "2018-06-12", + "2018-11-04", + ) + + self.assertNoHoliday( + "2018-11-07", + "2018-12-31", + ) diff --git a/test/countries/test_thailand.py b/test/countries/test_thailand.py new file mode 100644 index 000000000..797e96caf --- /dev/null +++ b/test/countries/test_thailand.py @@ -0,0 +1,80 @@ +# 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 (c) 2017-2022 +# ryanss (c) 2014-2017 +# Website: https://github.com/dr-prodigy/python-holidays +# License: MIT (see LICENSE file) + +from holidays.countries.thailand import TH, THA, Thailand +from test.common import TestCase + + +class TestRussia(TestCase): + def setUp(self): + self.holidays = Thailand() + + def test_country_aliases(self): + self.assertCountryAliases(Thailand, TH, THA) + + def test_2022(self): + self.assertHolidaysEqual( + Thailand(years=2022), + ("2022-01-01", "New Year's Day"), + ("2022-01-03", "New Year's Day (in lieu)"), + ("2022-02-16", "Makha Bucha"), + ("2022-04-06", "Chakri Memorial Day"), + ("2022-04-13", "Songkran Festival"), + ("2022-04-14", "Songkran Festival"), + ("2022-04-15", "Songkran Festival"), + ("2022-05-01", "Labour Day"), + ("2022-05-02", "Labour Day (in lieu)"), + ("2022-05-15", "Buddha's Birthday"), + ("2022-05-16", "Buddha's Birthday (in lieu)"), + ("2022-06-03", "Queen Suthida's Birthday"), + ("2022-07-13", "Asalha Puja"), + ("2022-07-14", "Beginning of Vassa"), + ("2022-07-28", "King's Birthday"), + ("2022-08-12", "The Queen Mother's Birthday"), + ("2022-10-13", "King Bhumibol Adulyadej Memorial Day"), + ("2022-10-23", "King Chulalongkorn Day"), + ("2022-10-24", "King Chulalongkorn Day (in lieu)"), + ("2022-12-05", "King Bhumibol Adulyadej's Birthday"), + ("2022-12-10", "Constitution Day"), + ("2022-12-12", "Constitution Day (in lieu)"), + ("2022-12-31", "New Year's Eve"), + ) + + def test_new_years_day(self): + self.assertHoliday( + Thailand(observed=True), + "2010-01-01", + "2011-01-03", + "2012-01-02", + ) + + self.assertNoHoliday( + Thailand(observed=False), + "2010-01-03", + "2011-01-03", + "2012-01-02", + ) + + def test_new_years_eve(self): + self.assertHoliday( + Thailand(), + "2012-12-31", + "2013-01-01", + "2028-12-31", + "2029-01-01", + ) + + def test_pre_2006(self): + self.assertFalse(Thailand(years=2005).get_named("Asalha Puja")) + self.assertFalse(Thailand(years=2005).get_named("Beginning of Vassa")) + + def test_pre_2017(self): + self.assertHoliday(Thailand(years=2016), "2016-05-04") From d565a6b3c436044117c9dd5a6e835609c3aa6f39 Mon Sep 17 00:00:00 2001 From: Arkadii Yakovets Date: Tue, 3 Jan 2023 08:41:27 -0800 Subject: [PATCH 103/138] Fix test_belarus.py header. --- test/countries/test_belarus.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/countries/test_belarus.py b/test/countries/test_belarus.py index 32c6cc928..bdbae49bc 100644 --- a/test/countries/test_belarus.py +++ b/test/countries/test_belarus.py @@ -1,6 +1,6 @@ # python-holidays # --------------- -# A fast-efficient Python library for generating country-province and state +# 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. # From fc95015a5b0421962fedc428b257ca9f81962e4f Mon Sep 17 00:00:00 2001 From: Arkadii Yakovets Date: Tue, 3 Jan 2023 10:04:44 -0800 Subject: [PATCH 104/138] Update holidays/countries/india.py Co-authored-by: ~Jhellico --- holidays/countries/india.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/holidays/countries/india.py b/holidays/countries/india.py index bc5d98b93..5db593133 100644 --- a/holidays/countries/india.py +++ b/holidays/countries/india.py @@ -257,7 +257,7 @@ def _populate(self, year): # Islamic holidays # Day of Ashura (10th day of 1st Islamic month) name = "Day of Ashura" - for dt in _islamic_to_gre(year, 10, 1): + for dt in _islamic_to_gre(year, 1, 10): self[dt] = f"{name}* (*estimated)" # Mawlid, Birth of the Prophet (12th day of 3rd Islamic month) From 93b39fe39949eb067f00ab0b75f7f30ff7218c7a Mon Sep 17 00:00:00 2001 From: Arkadii Yakovets Date: Tue, 3 Jan 2023 10:04:52 -0800 Subject: [PATCH 105/138] Update holidays/countries/india.py Co-authored-by: ~Jhellico --- holidays/countries/india.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/holidays/countries/india.py b/holidays/countries/india.py index 5db593133..d734b7231 100644 --- a/holidays/countries/india.py +++ b/holidays/countries/india.py @@ -262,7 +262,7 @@ def _populate(self, year): # Mawlid, Birth of the Prophet (12th day of 3rd Islamic month) name = "Mawlid" - for dt in _islamic_to_gre(year, 10, 1): + for dt in _islamic_to_gre(year, 3, 12): self[dt] = f"f{name}* (*estimated)" # Eid ul-Fitr (1st and 2nd day of 10th Islamic month) From a2a160afb28127038eb92150dd959918ac1381fa Mon Sep 17 00:00:00 2001 From: Arkadii Yakovets Date: Tue, 3 Jan 2023 10:05:19 -0800 Subject: [PATCH 106/138] Update holidays/countries/philippines.py Co-authored-by: ~Jhellico --- holidays/countries/philippines.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/holidays/countries/philippines.py b/holidays/countries/philippines.py index d65d7149f..6655507e6 100644 --- a/holidays/countries/philippines.py +++ b/holidays/countries/philippines.py @@ -24,7 +24,7 @@ class Philippines(HolidayBase): Philippines holidays. References: - - https://en.wikipedia.org/wiki/Public_holidays_in_Thailand + - https://en.wikipedia.org/wiki/Public_holidays_in_the_Philippines """ country = "PH" From a79c4c39bd98e162e43e3dc95136b363bc27cb1d Mon Sep 17 00:00:00 2001 From: Arkadii Yakovets Date: Tue, 3 Jan 2023 10:05:33 -0800 Subject: [PATCH 107/138] Update holidays/countries/philippines.py Co-authored-by: ~Jhellico --- holidays/countries/philippines.py | 1 + 1 file changed, 1 insertion(+) diff --git a/holidays/countries/philippines.py b/holidays/countries/philippines.py index 6655507e6..28b965228 100644 --- a/holidays/countries/philippines.py +++ b/holidays/countries/philippines.py @@ -12,6 +12,7 @@ from datetime import date from dateutil.easter import easter +from dateutil.relativedelta import MO from dateutil.relativedelta import relativedelta as rd from holidays.constants import JAN, FEB, APR, MAY, JUN, AUG, NOV, DEC From 75c0789a2e8bdcf3a20cb979822b7f4b1394296c Mon Sep 17 00:00:00 2001 From: Arkadii Yakovets Date: Tue, 3 Jan 2023 10:05:42 -0800 Subject: [PATCH 108/138] Update holidays/countries/philippines.py Co-authored-by: ~Jhellico --- holidays/countries/philippines.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/holidays/countries/philippines.py b/holidays/countries/philippines.py index 28b965228..d02017cc8 100644 --- a/holidays/countries/philippines.py +++ b/holidays/countries/philippines.py @@ -75,7 +75,7 @@ def _populate(self, year): self[date(year, AUG, 21)] = "Ninoy Aquino Day" # National Heroes Day. - self[date(year, AUG, 27)] = "National Heroes Day" + self[date(year, AUG, 31) + rd(weekday=MO(-1))] = "National Heroes Day" # All Saints' Day. self[date(year, NOV, 1)] = "All Saints' Day" From 79a3aaea3584065d1c69a9be7cb6029b6573b2cc Mon Sep 17 00:00:00 2001 From: Arkadii Yakovets Date: Tue, 3 Jan 2023 10:05:54 -0800 Subject: [PATCH 109/138] Update holidays/countries/thailand.py Co-authored-by: ~Jhellico --- holidays/countries/thailand.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/holidays/countries/thailand.py b/holidays/countries/thailand.py index a013983ee..28e97c863 100644 --- a/holidays/countries/thailand.py +++ b/holidays/countries/thailand.py @@ -82,6 +82,8 @@ def add_holiday(dt, holiday_name): # Coronation Day. if year <= 2016: + add_holiday(date(year, MAY, 5), "Coronation Day") + elif year >= 2020: add_holiday(date(year, MAY, 4), "Coronation Day") # Queen's Birthday. From 78a095ebddf230ee516e5f33613dd69f55f8efcd Mon Sep 17 00:00:00 2001 From: Arkadii Yakovets Date: Tue, 3 Jan 2023 10:31:18 -0800 Subject: [PATCH 110/138] Fix tests after addressing review comments. --- test/countries/test_philippines.py | 2 +- test/countries/test_thailand.py | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/test/countries/test_philippines.py b/test/countries/test_philippines.py index b5372c1ad..77fdf119b 100644 --- a/test/countries/test_philippines.py +++ b/test/countries/test_philippines.py @@ -35,7 +35,7 @@ def test_2022(self): ("2022-06-12", "Independence Day"), ("2022-07-09", "Eid'l Adha"), ("2022-08-21", "Ninoy Aquino Day"), - ("2022-08-27", "National Heroes Day"), + ("2022-08-29", "National Heroes Day"), ("2022-11-01", "All Saints' Day"), ("2022-11-30", "Bonifacio Day"), ("2022-12-08", "Immaculate Conception Day"), diff --git a/test/countries/test_thailand.py b/test/countries/test_thailand.py index 797e96caf..bca54cdf3 100644 --- a/test/countries/test_thailand.py +++ b/test/countries/test_thailand.py @@ -13,7 +13,7 @@ from test.common import TestCase -class TestRussia(TestCase): +class TestThailand(TestCase): def setUp(self): self.holidays = Thailand() @@ -32,6 +32,7 @@ def test_2022(self): ("2022-04-15", "Songkran Festival"), ("2022-05-01", "Labour Day"), ("2022-05-02", "Labour Day (in lieu)"), + ("2022-05-04", "Coronation Day"), ("2022-05-15", "Buddha's Birthday"), ("2022-05-16", "Buddha's Birthday (in lieu)"), ("2022-06-03", "Queen Suthida's Birthday"), @@ -76,5 +77,6 @@ def test_pre_2006(self): self.assertFalse(Thailand(years=2005).get_named("Asalha Puja")) self.assertFalse(Thailand(years=2005).get_named("Beginning of Vassa")) - def test_pre_2017(self): - self.assertHoliday(Thailand(years=2016), "2016-05-04") + def test_coronation_day(self): + self.assertHoliday("2016-05-05", "2020-05-04") + self.assertNoHoliday("2017-05-04", "2017-05-05") From af239d651d751e83c0e490f7dfc40f96b47d1e63 Mon Sep 17 00:00:00 2001 From: Arkadii Yakovets Date: Tue, 3 Jan 2023 21:27:18 -0800 Subject: [PATCH 111/138] Add Bahrain initial support. --- README.rst | 3 + holidays/countries/__init__.py | 1 + holidays/countries/bahrain.py | 223 ++++++++++++++------------------- test/countries/test_bahrain.py | 82 ++++++++++++ 4 files changed, 177 insertions(+), 132 deletions(-) create mode 100644 test/countries/test_bahrain.py diff --git a/README.rst b/README.rst index 4f249dee7..5f796e3e0 100644 --- a/README.rst +++ b/README.rst @@ -139,6 +139,9 @@ following countries and their subdivisions are available: * - Azerbaijan - AZ - None + * - Bahrain + - BH + - None * - Bangladesh - BD - None diff --git a/holidays/countries/__init__.py b/holidays/countries/__init__.py index 8cb48c057..ee1177a14 100644 --- a/holidays/countries/__init__.py +++ b/holidays/countries/__init__.py @@ -16,6 +16,7 @@ from .australia import AU, AUS, Australia from .austria import AT, AUT, Austria from .azerbaijan import AZ, AZE, Azerbaijan +from .bahrain import BH, BAH, Bahrain from .bangladesh import BD, BGD, Bangladesh from .belarus import BY, BLR, Belarus from .belgium import BE, BEL, Belgium diff --git a/holidays/countries/bahrain.py b/holidays/countries/bahrain.py index 0b32ff3f3..807c7e396 100644 --- a/holidays/countries/bahrain.py +++ b/holidays/countries/bahrain.py @@ -13,160 +13,119 @@ from dateutil.relativedelta import relativedelta as rd -from holidays.constants import ( - FRI, - SAT, - JAN, - APR, - MAY, - JUN, - JUL, - AUG, - SEP, - NOV, - DEC, -) +from holidays.constants import FRI, SAT, JAN, MAY, JUL, AUG, OCT, DEC from holidays.holiday_base import HolidayBase from holidays.utils import _islamic_to_gre -WEEKEND = (FRI, SAT) class Bahrain(HolidayBase): """ - Bahrain holidays - - # Holidays based on the Islamic Calendar are estimated (and so denoted), - # as are announced each year and based on moon sightings: - # - Eid Al Fitr* - # - Eid Al Adha* - # - Al Hijra New Year* - # - Ashoora* - # - Prophets Birthday* - # *only if hijri-converter library is installed, otherwise a warning is - # raised that this holiday is missing. hijri-converter requires - # Python >= 3.6 - Primary sources: - https://www.cbb.gov.bh/official-bank-holidays/ - https://www.officeholidays.com/countries/bahrain/ + Bahrain holidays. + + References: + - https://www.cbb.gov.bh/official-bank-holidays/ + - https://www.officeholidays.com/countries/bahrain/ """ country = "BH" + weekend = {FRI, SAT} def _populate(self, year): super()._populate(year) - def _add_holiday(dt: date, hol: str) -> None: - """Only add if in current year; prevents adding holidays across - years (handles multi-day Islamic holidays that straddle Gregorian - years). - """ - if dt.year == year: - self[dt] = hol - - # New Year's Day + # New Year's Day. self[date(year, JAN, 1)] = "New Year's Day" - # Labor day + # Labour day. self[date(year, MAY, 1)] = "Labour Day" - # National Day - self[date(year, DEC, 16)] = "National Day" - self[date(year, DEC, 17)] = "National Day" - - # Eid Al Fitr - # Date is announced each year. Usually stretches along 3 or 4 days, - # in some instances prepending/appending a day or two - # before/after the official holiday. - fitr = "Eid Al Fitr" - if year in dates_obs: - for date_obs in dates_obs[year]: - hol_date = date(year, *date_obs) - self[hol_date] = fitr - self[hol_date + rd(days=1)] = f"{fitr} Holiday" - self[hol_date + rd(days=2)] = f"{fitr} Holiday" + # Eid Al Fitr. + eid_al_fitr = "Eid Al Fitr" + eid_al_fitr_mapping = { + 2022: ((MAY, 2),), + } + if year in eid_al_fitr_mapping: + for dt in eid_al_fitr_mapping[year]: + eid_al_fitr_day = date(year, *dt) + self[eid_al_fitr_day] = eid_al_fitr + self[eid_al_fitr_day + rd(days=+1)] = f"{eid_al_fitr} Holiday" + self[eid_al_fitr_day + rd(days=+2)] = f"{eid_al_fitr} Holiday" else: - for yr in (year - 1, year): - for date_obs in _islamic_to_gre(yr, 10, 1): - hol_date = date_obs - _add_holiday(hol_date, f"{fitr}* (*estimated)") - _add_holiday( - hol_date + rd(days=1), - f"{fitr} Holiday* (*estimated)", - ) - _add_holiday( - hol_date + rd(days=2), - f"{fitr} Holiday* (*estimated)", - ) - - # Eid Al Adha - # Date is announced each year. Usually stretches along 3 or 4 days, - # in some instances prepending/appending a day or two - # before/after the official holiday. - adha = "Eid Al Adha" - if year in dates_obs: - for date_obs in dates_obs[year]: - hol_date = date(year, *date_obs) - self[hol_date + rd(days=1)] = adha - self[hol_date + rd(days=2)] = f"{adha} Holiday" - self[hol_date + rd(days=3)] = f"{adha} Holiday" + for eid_al_fitr_day in _islamic_to_gre(year, 10, 1): + self[eid_al_fitr_day] = f"{eid_al_fitr}* (*estimated)" + self[ + eid_al_fitr_day + rd(days=+1) + ] = f"{eid_al_fitr} Holiday* (*estimated)" + self[ + eid_al_fitr_day + rd(days=+2) + ] = f"{eid_al_fitr} Holiday* (*estimated)" + + # Eid Al Adha. + eid_al_adha = "Eid Al Adha" + eid_al_adha_mapping = { + 2022: ((JUL, 9),), + } + if year in eid_al_adha_mapping: + for dt in eid_al_adha_mapping[year]: + eid_al_adha_day = date(year, *dt) + self[eid_al_adha_day] = eid_al_adha + self[eid_al_adha_day + rd(days=+1)] = f"{eid_al_adha} Holiday" + self[eid_al_adha_day + rd(days=+2)] = f"{eid_al_adha} Holiday" else: - for yr in (year - 1, year): - for date_obs in _islamic_to_gre(yr, 12, 9): - hol_date = date_obs - _add_holiday( - hol_date + rd(days=1), f"{adha}* (*estimated)" - ) - _add_holiday( - hol_date + rd(days=2), - f"{adha}* Holiday* (*estimated)", - ) - _add_holiday( - hol_date + rd(days=3), - f"{adha} Holiday* (*estimated)", - ) - - # Al Hijra New Year - new_hijri_year = "Al Hijra New Year" - if year in dates_obs: - for date_obs in dates_obs[year]: - hol_date = date(year, *date_obs) - self[hol_date] = new_hijri_year + for eid_al_adha_day in _islamic_to_gre(year, 12, 9): + self[ + eid_al_adha_day + rd(days=+1) + ] = f"{eid_al_adha}* (*estimated)" + self[ + eid_al_adha_day + rd(days=+2) + ] = f"{eid_al_adha}* (*estimated)" + self[ + eid_al_adha_day + rd(days=+3) + ] = f"{eid_al_adha}* (*estimated)" + + # Al Hijra New Year. + hijri_new_year = "Al Hijra New Year" + hijri_new_year_mapping = { + 2022: ((JUL, 30),), + } + if year in hijri_new_year_mapping: + for dt in hijri_new_year_mapping[year]: + self[date(year, *dt)] = hijri_new_year else: - for date_obs in _islamic_to_gre(year, 1, 1): - hol_date = date_obs - self[hol_date] = f"{new_hijri_year}* (*estimated)" - - # Ashoora - # Date is announced each year, for the 9th and 10th Day, - # of the month of Muharam - ashoora = "Ashoora" - if year in dates_obs: - for date_obs in dates_obs[year]: - hol_date = date(year, *date_obs) - self[hol_date + rd(days=9)] = ashoora - self[hol_date + rd(days=10)] = f"{ashoora} Holiday" + for dt in _islamic_to_gre(year, 1, 1): + self[dt] = f"{hijri_new_year}* (*estimated)" + + # Ashura. + ashura = "Ashura" + ashura_mapping = { + 2022: ((AUG, 7),), + } + if year in ashura_mapping: + for dt in ashura_mapping[year]: + ashura_day = date(year, *dt) + self[ashura_day] = ashura + self[ashura_day + rd(days=+1)] = f"{ashura} Holiday" else: - for yr in (year - 1, year): - for date_obs in _islamic_to_gre(yr, 1, 9): - hol_date = date_obs - _add_holiday( - hol_date + rd(days=9), f"{ashoora}* (*estimated)" - ) - _add_holiday( - hol_date + rd(days=10), - f"{ashoora}* Holiday* (*estimated)", - ) - - # Prophets Birthday + for ashura_day in _islamic_to_gre(year, 1, 9): + self[ashura_day] = f"{ashura}* (*estimated)" + self[ + ashura_day + rd(days=+1) + ] = f"{ashura}* Holiday* (*estimated)" + + # Prophets Birthday. mawlud = "Prophets Birthday" - if year in dates_obs: - for date_obs in dates_obs[year]: - hol_date = date(year, *date_obs) - self[hol_date] = mawlud - else: - for date_obs in _islamic_to_gre(year, 3, 12): - hol_date = date_obs - self[hol_date] = f"{mawlud}* (*estimated)" + mawlud_mapping = {2022: ((OCT, 8),)} + if year in mawlud_mapping: + for dt in mawlud_mapping[year]: + self[date(year, *dt)] = mawlud + else: + for dt in _islamic_to_gre(year, 3, 12): + self[dt] = f"{mawlud}* (*estimated)" + + # National Day. + national_day = "National Day" + self[date(year, DEC, 16)] = national_day + self[date(year, DEC, 17)] = national_day class BH(Bahrain): diff --git a/test/countries/test_bahrain.py b/test/countries/test_bahrain.py new file mode 100644 index 000000000..056b4b9ee --- /dev/null +++ b/test/countries/test_bahrain.py @@ -0,0 +1,82 @@ +# 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 (c) 2017-2022 +# ryanss (c) 2014-2017 +# Website: https://github.com/dr-prodigy/python-holidays +# License: MIT (see LICENSE file) + +import importlib.util + +from holidays.countries.bahrain import BH, BAH, Bahrain +from test.common import TestCase + + +class TestBahrain(TestCase): + def setUp(self): + self.holidays = Bahrain() + + def test_country_aliases(self): + self.assertCountryAliases(Bahrain, BH, BAH) + + def test_2022(self): + self.assertHoliday( + "2022-01-01", + "2022-05-01", + "2022-05-02", + "2022-05-03", + "2022-05-04", + "2022-07-09", + "2022-07-10", + "2022-07-11", + "2022-07-30", + "2022-08-07", + "2022-08-08", + "2022-10-08", + "2022-12-16", + "2022-12-17", + ) + + def test_2023(self): + self.assertHoliday( + "2023-01-01", + "2023-04-21", + "2023-04-22", + "2023-04-23", + "2023-05-01", + "2023-06-28", + "2023-06-29", + "2023-06-30", + "2023-07-19", + "2023-07-27", + "2023-07-28", + "2023-09-27", + "2023-12-16", + "2023-12-17", + ) + + def test_hijri_based(self): + if not importlib.util.find_spec("hijri_converter"): + return + + # Eid Al-Fitr. + self.assertHoliday( + "2020-05-24", + "2020-05-25", + "2020-05-26", + ) + + # Eid Al-Adha. + self.assertHoliday( + "2020-07-31", + "2020-08-01", + "2020-08-02", + ) + + # Islamic New Year. + self.assertHoliday( + "2020-08-20", + ) From 785740fc032c934e950258c48f15659a14e74cdc Mon Sep 17 00:00:00 2001 From: Arkadii Yakovets Date: Tue, 3 Jan 2023 21:40:21 -0800 Subject: [PATCH 112/138] Update README. --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 5f796e3e0..ffc11e0cf 100644 --- a/README.rst +++ b/README.rst @@ -106,7 +106,7 @@ Available Countries .. _ISO 3166-1 alpha-2 code: https://en.wikipedia.org/wiki/List_of_ISO_3166_country_codes -We currently support 101 countries. The standard way to refer to a country is by +We currently support 102 countries. The standard way to refer to a country is by using its `ISO 3166-1 alpha-2 code`_, the same used for domain names. The following countries and their subdivisions are available: From 8f7dbda22b64fbfc08893dbd273bb6981267499d Mon Sep 17 00:00:00 2001 From: Arkadii Yakovets Date: Wed, 4 Jan 2023 11:50:45 -0800 Subject: [PATCH 113/138] Update India tests. --- holidays/countries/india.py | 2 +- test/countries/test_india.py | 295 ++++++++++++++++------------------- 2 files changed, 139 insertions(+), 158 deletions(-) diff --git a/holidays/countries/india.py b/holidays/countries/india.py index d734b7231..2c4e9530c 100644 --- a/holidays/countries/india.py +++ b/holidays/countries/india.py @@ -263,7 +263,7 @@ def _populate(self, year): # Mawlid, Birth of the Prophet (12th day of 3rd Islamic month) name = "Mawlid" for dt in _islamic_to_gre(year, 3, 12): - self[dt] = f"f{name}* (*estimated)" + self[dt] = f"{name}* (*estimated)" # Eid ul-Fitr (1st and 2nd day of 10th Islamic month) name = "Eid ul-Fitr" diff --git a/test/countries/test_india.py b/test/countries/test_india.py index d0d843c6c..fcd19cdbf 100644 --- a/test/countries/test_india.py +++ b/test/countries/test_india.py @@ -10,7 +10,6 @@ # License: MIT (see LICENSE file) import warnings -from datetime import date from holidays.countries.india import IN, IND, India from test.common import TestCase @@ -24,169 +23,151 @@ def test_country_aliases(self): self.assertCountryAliases(India, IN, IND) def test_2018(self): - self.assertIn(date(2018, 1, 14), self.holidays) - self.assertIn(date(2018, 1, 26), self.holidays) - self.assertIn(date(2018, 10, 2), self.holidays) - self.assertIn(date(2018, 5, 1), self.holidays) - self.assertIn(date(2018, 8, 15), self.holidays) - self.assertIn(date(2018, 10, 2), self.holidays) - self.assertIn(date(2018, 12, 25), self.holidays) - self.assertIn(date(2018, 11, 7), self.holidays) - self.assertIn(date(2018, 3, 2), self.holidays) - - ap_holidays = India(subdiv="AP") - ar_holidays = India(subdiv="AR") - as_holidays = India(subdiv="AS") - br_holidays = India(subdiv="BR") - cg_holidays = India(subdiv="CG") - ga_holidays = India(subdiv="GA") - gj_holidays = India(subdiv="GJ") - hr_holidays = India(subdiv="HR") - hp_holidays = India(subdiv="HP") - jk_holidays = India(subdiv="JK") - jh_holidays = India(subdiv="JH") - ka_holidays = India(subdiv="KA") - kl_holidays = India(subdiv="KL") - mp_holidays = India(subdiv="MP") - mh_holidays = India(subdiv="MH") - mn_holidays = India(subdiv="MN") - ml_holidays = India(subdiv="ML") - mz_holidays = India(subdiv="MZ") - nl_holidays = India(subdiv="NL") - or_holidays = India(subdiv="OR") - pb_holidays = India(subdiv="PB") - rj_holidays = India(subdiv="RJ") - sk_holidays = India(subdiv="SK") - tn_holidays = India(subdiv="TN") - tr_holidays = India(subdiv="TR") - ts_holidays = India(subdiv="TS") - uk_holidays = India(subdiv="UK") - up_holidays = India(subdiv="UP") - wb_holidays = India(subdiv="WB") - an_holidays = India(subdiv="AN") - ch_holidays = India(subdiv="CH") - dh_holidays = India(subdiv="DH") - dd_holidays = India(subdiv="DD") - dl_holidays = India(subdiv="DL") - la_holidays = India(subdiv="LA") - ld_holidays = India(subdiv="LD") - py_holidays = India(subdiv="PY") - - for dt in [date(2018, 1, 14), date(2018, 5, 1), date(2018, 10, 31)]: - self.assertIn(dt, gj_holidays) - for dt in [date(2018, 4, 15), date(2018, 4, 14)]: - self.assertIn(dt, tn_holidays) - self.assertIn(dt, wb_holidays) - - self.assertIn(date(2018, 3, 22), br_holidays) - self.assertIn(date(2018, 3, 30), rj_holidays) - self.assertIn(date(2018, 6, 15), rj_holidays) - self.assertIn(date(2018, 4, 1), or_holidays) - self.assertIn(date(2018, 4, 6), ts_holidays) - self.assertIn(date(2018, 4, 15), or_holidays) - self.assertIn(date(2018, 4, 14), or_holidays) - self.assertIn(date(2018, 4, 14), br_holidays) - self.assertIn(date(2018, 4, 14), kl_holidays) - self.assertIn(date(2018, 4, 14), up_holidays) - self.assertIn(date(2018, 4, 14), uk_holidays) - self.assertIn(date(2018, 4, 14), hr_holidays) - self.assertIn(date(2018, 4, 14), mh_holidays) - self.assertIn(date(2018, 4, 14), wb_holidays) - self.assertIn(date(2018, 5, 9), wb_holidays) - self.assertIn(date(2018, 4, 15), as_holidays) - self.assertIn(date(2018, 5, 1), mh_holidays) - self.assertIn(date(2018, 5, 16), sk_holidays) - self.assertIn(date(2018, 10, 6), ts_holidays) - self.assertIn(date(2018, 11, 1), ka_holidays) - self.assertIn(date(2018, 11, 1), ap_holidays) - self.assertIn(date(2018, 11, 1), hr_holidays) - self.assertIn(date(2018, 11, 1), mp_holidays) - self.assertIn(date(2018, 11, 1), kl_holidays) - self.assertIn(date(2018, 11, 1), cg_holidays) - self.assertIn(date(2018, 8, 15), ar_holidays) - self.assertIn(date(2018, 8, 15), ga_holidays) - self.assertIn(date(2018, 8, 15), gj_holidays) - self.assertIn(date(2018, 8, 15), hp_holidays) - self.assertIn(date(2018, 8, 15), jk_holidays) - self.assertIn(date(2018, 8, 15), jh_holidays) - self.assertIn(date(2018, 8, 15), mn_holidays) - self.assertIn(date(2018, 8, 15), ml_holidays) - self.assertIn(date(2018, 8, 15), mz_holidays) - self.assertIn(date(2018, 8, 15), nl_holidays) - self.assertIn(date(2018, 8, 15), or_holidays) - self.assertIn(date(2018, 8, 15), pb_holidays) - self.assertIn(date(2018, 8, 15), tn_holidays) - self.assertIn(date(2018, 8, 15), tr_holidays) - self.assertIn(date(2018, 8, 15), an_holidays) - self.assertIn(date(2018, 8, 15), ch_holidays) - self.assertIn(date(2018, 8, 15), dh_holidays) - self.assertIn(date(2018, 8, 15), dd_holidays) - self.assertIn(date(2018, 8, 15), dl_holidays) - self.assertIn(date(2018, 8, 15), la_holidays) - self.assertIn(date(2018, 8, 15), ld_holidays) - self.assertIn(date(2018, 8, 15), py_holidays) - self.assertIn(date(2018, 10, 15), mh_holidays) + self.assertHoliday( + "2018-01-14", + "2018-01-26", + "2018-03-02", + "2018-03-25", + "2018-03-30", + "2018-04-01", + "2018-05-01", + "2018-05-20", + "2018-06-15", + "2018-06-15", + "2018-08-15", + "2018-08-21", + "2018-08-22", + "2018-09-20", + "2018-10-02", + "2018-10-02", + "2018-11-07", + "2018-11-20", + "2018-12-25", + ) + + subdiv_holidays_mapping = { + "AN": ("2018-08-15",), + "AP": ("2018-11-01",), + "AR": ("2018-08-15",), + "AS": ("2018-04-15",), + "BR": ( + "2018-03-22", + "2018-04-14", + ), + "CG": ("2018-11-01",), + "CH": ("2018-08-15",), + "DD": ("2018-08-15",), + "DH": ("2018-08-15",), + "DL": ("2018-08-15",), + "GA": ("2018-08-15",), + "GJ": ( + "2018-01-14", + "2018-05-01", + "2018-08-15", + "2018-10-31", + ), + "HP": ("2018-08-15",), + "HR": ("2018-04-14", "2018-11-01"), + "JK": ("2018-08-15",), + "JH": ("2018-08-15",), + "KA": ("2018-11-01",), + "KL": ( + "2018-04-14", + "2018-11-01", + ), + "LA": ("2018-08-15",), + "LD": ("2018-08-15",), + "MH": ( + "2018-04-14", + "2018-05-01", + "2018-10-15", + ), + "ML": ("2018-08-15",), + "MN": ("2018-08-15",), + "MP": ("2018-11-01",), + "MZ": ("2018-08-15",), + "NL": ("2018-08-15",), + "OR": ("2018-04-01", "2018-04-14", "2018-08-15"), + "PB": ("2018-08-15",), + "PY": ("2018-08-15",), + "RJ": ("2018-03-30", "2018-06-15"), + "SK": ("2018-05-16",), + "TN": ( + "2018-04-14", + "2018-04-15", + "2018-08-15", + ), + "TR": ("2018-08-15",), + "TS": ("2018-04-06", "2018-10-06"), + "UK": ("2018-04-14",), + "UP": ("2018-04-14",), + "WB": ("2018-04-14", "2018-04-15", "2018-05-09"), + } + + for subdiv, holidays in subdiv_holidays_mapping.items(): + self.assertHoliday(India(subdiv=subdiv), holidays) def test_diwali_and_holi(self): warnings.simplefilter("always") - with self.assertWarns(Warning): - # Diwali and Holi out of range - India(years=2000) - - with self.assertWarns(Warning): - # Diwali and Holi out of range - India(years=2031) - - diwali_name = "Diwali" - holi_name = "Holi" - self.assertEqual(self.holidays[date(2010, 11, 5)], diwali_name) - self.assertEqual(self.holidays[date(2010, 3, 1)], holi_name) - self.assertEqual(self.holidays[date(2011, 3, 20)], holi_name) - self.assertEqual(self.holidays[date(2011, 10, 26)], diwali_name) - self.assertEqual(self.holidays[date(2012, 3, 8)], holi_name) - self.assertEqual(self.holidays[date(2012, 11, 13)], diwali_name) - self.assertEqual(self.holidays[date(2013, 3, 27)], holi_name) - self.assertEqual(self.holidays[date(2013, 11, 3)], diwali_name) - self.assertEqual(self.holidays[date(2014, 3, 17)], holi_name) - self.assertEqual(self.holidays[date(2014, 10, 23)], diwali_name) - self.assertEqual(self.holidays[date(2015, 3, 6)], holi_name) - self.assertEqual(self.holidays[date(2015, 11, 11)], diwali_name) - self.assertEqual(self.holidays[date(2016, 3, 24)], holi_name) - self.assertEqual(self.holidays[date(2016, 10, 30)], diwali_name) - self.assertEqual(self.holidays[date(2017, 3, 13)], holi_name) - self.assertEqual(self.holidays[date(2017, 10, 19)], diwali_name) - self.assertEqual(self.holidays[date(2018, 3, 2)], holi_name) - self.assertEqual(self.holidays[date(2018, 11, 7)], diwali_name) - self.assertEqual(self.holidays[date(2019, 3, 21)], holi_name) - self.assertEqual(self.holidays[date(2019, 10, 27)], diwali_name) - self.assertEqual(self.holidays[date(2020, 3, 10)], holi_name) - self.assertEqual(self.holidays[date(2020, 11, 14)], diwali_name) - self.assertEqual(self.holidays[date(2021, 3, 29)], holi_name) - self.assertEqual(self.holidays[date(2021, 11, 4)], diwali_name) - self.assertEqual(self.holidays[date(2022, 3, 18)], holi_name) - self.assertEqual(self.holidays[date(2022, 10, 24)], diwali_name) - self.assertEqual(self.holidays[date(2023, 3, 8)], holi_name) - self.assertEqual(self.holidays[date(2023, 11, 12)], diwali_name) - self.assertEqual(self.holidays[date(2024, 3, 25)], holi_name) - self.assertEqual(self.holidays[date(2024, 11, 1)], diwali_name) - self.assertEqual(self.holidays[date(2025, 3, 14)], holi_name) - self.assertEqual(self.holidays[date(2025, 10, 20)], diwali_name) - self.assertEqual(self.holidays[date(2026, 3, 4)], holi_name) - self.assertEqual(self.holidays[date(2026, 11, 8)], diwali_name) - self.assertEqual(self.holidays[date(2027, 3, 22)], holi_name) - self.assertEqual(self.holidays[date(2027, 10, 29)], diwali_name) - self.assertEqual(self.holidays[date(2028, 3, 11)], holi_name) - self.assertEqual(self.holidays[date(2028, 10, 17)], diwali_name) - self.assertEqual(self.holidays[date(2029, 3, 1)], holi_name) - self.assertEqual(self.holidays[date(2029, 11, 5)], diwali_name) - self.assertEqual(self.holidays[date(2030, 3, 20)], holi_name) - self.assertEqual(self.holidays[date(2030, 10, 26)], diwali_name) + for year in (2000, 2031): # Diwali and Holi out of range. + with self.assertWarns(Warning): + India(years=year) + + for dt in ( + "2010-11-05", + "2011-10-26", + "2012-11-13", + "2013-11-03", + "2014-10-23", + "2015-11-11", + "2016-10-30", + "2017-10-19", + "2018-11-07", + "2019-10-27", + "2020-11-14", + "2021-11-04", + "2022-10-24", + "2023-11-12", + "2024-11-01", + "2025-10-20", + "2026-11-08", + "2027-10-29", + "2028-10-17", + "2029-11-05", + "2030-10-26", + ): + self.assertEqual(self.holidays[dt], "Diwali") + + for dt in ( + "2010-03-01", + "2011-03-20", + "2012-03-08", + "2013-03-27", + "2014-03-17", + "2015-03-06", + "2016-03-24", + "2017-03-13", + "2018-03-02", + "2019-03-21", + "2020-03-10", + "2021-03-29", + "2022-03-18", + "2023-03-08", + "2024-03-25", + "2025-03-14", + "2026-03-04", + "2027-03-22", + "2028-03-11", + "2029-03-01", + "2030-03-20", + ): + self.assertEqual(self.holidays[dt], "Holi") def test_pre_1947(self): - self.assertNotIn(date(1946, 8, 15), self.holidays) + self.assertNoHoliday("1946-08-15") def test_pre_1950(self): - self.assertNotIn(date(1949, 1, 26), self.holidays) + self.assertNoHoliday("1949-01-26") def test_good_friday(self): self.assertHoliday( From 417d2d5fd0aa97a5e227e6dba729932116e99537 Mon Sep 17 00:00:00 2001 From: Arkadii Yakovets Date: Tue, 10 Jan 2023 09:14:50 -0800 Subject: [PATCH 114/138] Add Kyrgyzstan initial support. --- README.rst | 5 +- holidays/countries/__init__.py | 1 + holidays/countries/kyrgyzstan.py | 90 +++++++++++++++++++++++++++++++ test/countries/test_kyrgyzstan.py | 67 +++++++++++++++++++++++ 4 files changed, 162 insertions(+), 1 deletion(-) create mode 100644 holidays/countries/kyrgyzstan.py create mode 100644 test/countries/test_kyrgyzstan.py diff --git a/README.rst b/README.rst index 4f249dee7..dbf6a77c5 100644 --- a/README.rst +++ b/README.rst @@ -106,7 +106,7 @@ Available Countries .. _ISO 3166-1 alpha-2 code: https://en.wikipedia.org/wiki/List_of_ISO_3166_country_codes -We currently support 101 countries. The standard way to refer to a country is by +We currently support 102 countries. The standard way to refer to a country is by using its `ISO 3166-1 alpha-2 code`_, the same used for domain names. The following countries and their subdivisions are available: @@ -268,6 +268,9 @@ following countries and their subdivisions are available: * - Kenya - KE - None + * - Kyrgyzstan + - KG + - None * - Latvia - LV - None diff --git a/holidays/countries/__init__.py b/holidays/countries/__init__.py index 286d2430e..7df683c8a 100644 --- a/holidays/countries/__init__.py +++ b/holidays/countries/__init__.py @@ -60,6 +60,7 @@ from .japan import JP, JPN, Japan from .kazakhstan import KZ, KAZ, Kazakhstan from .kenya import KE, KEN, Kenya +from .kyrgyzstan import KG, KGZ, Kyrgyzstan from .latvia import LV, LVA, Latvia from .lesotho import LS, LSO, Lesotho from .liechtenstein import LI, LIE, Liechtenstein diff --git a/holidays/countries/kyrgyzstan.py b/holidays/countries/kyrgyzstan.py new file mode 100644 index 000000000..75652c9cc --- /dev/null +++ b/holidays/countries/kyrgyzstan.py @@ -0,0 +1,90 @@ +# 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 (c) 2017-2022 +# ryanss (c) 2014-2017 +# Website: https://github.com/dr-prodigy/python-holidays +# License: MIT (see LICENSE file) + +from datetime import date + +from dateutil.relativedelta import relativedelta as rd + +from holidays.constants import JAN, FEB, MAR, APR, MAY, AUG, NOV, DEC +from holidays.holiday_base import HolidayBase +from holidays.utils import _islamic_to_gre + + +class Kyrgyzstan(HolidayBase): + """ + Kyrgyzstan holidays. + + References: + - https://en.wikipedia.org/wiki/Public_holidays_in_Kyrgyzstan + """ + + country = "KG" + + def _populate(self, year): + super()._populate(year) + + # New Year's Day. + self[date(year, JAN, 1)] = "New Year's Day" + + # Orthodox Christmas. + self[date(year, JAN, 7)] = "Christmas Day" + + # Feb. 23 Fatherland Defender's Day. + self[date(year, FEB, 23)] = "Fatherland Defender's Day" + + # International Women's Day. + self[date(year, MAR, 8)] = "International Women's Day" + + # Nooruz Mairamy. + self[date(year, MAR, 21)] = "Nooruz Mairamy" + + if year >= 2016: + # Day of the People's April Revolution. + self[date(year, APR, 7)] = "Day of the People's April Revolution" + + # International Workers' Day. + self[date(year, MAY, 1)] = "International Workers' Day" + + # Constitution Day. + self[date(year, MAY, 5)] = "Constitution Day" + + # Victory Day. + self[date(year, MAY, 9)] = "Victory Day" + + # Independence Day. + self[date(year, AUG, 31)] = "Independence Day" + + # Days History and Commemoration of Ancestors. + name = "Days of History and Commemoration of Ancestors" + self[date(year, NOV, 7)] = name + self[date(year, NOV, 8)] = name + + # New Year's Eve. + self[date(year, DEC, 31)] = "New Year's Eve" + + # Islamic Holidays. + # Orozo Ait. + name = "Orozo Ait" + for dt in _islamic_to_gre(year, 10, 1): + self[dt] = name + self[dt + rd(days=+1)] = name + + # Kurman Ait. + for dt in _islamic_to_gre(year, 12, 10): + self[dt] = "Kurman Ait" + + +class KG(Kyrgyzstan): + pass + + +class KGZ(Kyrgyzstan): + pass diff --git a/test/countries/test_kyrgyzstan.py b/test/countries/test_kyrgyzstan.py new file mode 100644 index 000000000..0185be48d --- /dev/null +++ b/test/countries/test_kyrgyzstan.py @@ -0,0 +1,67 @@ +# 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 (c) 2017-2022 +# ryanss (c) 2014-2017 +# Website: https://github.com/dr-prodigy/python-holidays +# License: MIT (see LICENSE file) + +from holidays.countries.kyrgyzstan import KG, KGZ, Kyrgyzstan +from test.common import TestCase + + +class TestKyrgyzstan(TestCase): + def setUp(self): + self.holidays = Kyrgyzstan() + + def test_country_aliases(self): + self.assertCountryAliases(Kyrgyzstan, KG, KGZ) + + def test_2022(self): + self.assertHolidaysEqual( + Kyrgyzstan(years=2022), + ("2022-01-01", "New Year's Day"), + ("2022-01-07", "Christmas Day"), + ("2022-02-23", "Fatherland Defender's Day"), + ("2022-03-08", "International Women's Day"), + ("2022-03-21", "Nooruz Mairamy"), + ("2022-04-07", "Day of the People's April Revolution"), + ("2022-05-01", "International Workers' Day"), + ("2022-05-02", "Orozo Ait"), + ("2022-05-03", "Orozo Ait"), + ("2022-05-05", "Constitution Day"), + ("2022-05-09", "Victory Day"), + ("2022-07-09", "Kurman Ait"), + ("2022-08-31", "Independence Day"), + ("2022-11-07", "Days of History and Commemoration of Ancestors"), + ("2022-11-08", "Days of History and Commemoration of Ancestors"), + ("2022-12-31", "New Year's Eve"), + ) + + def test_2023(self): + self.assertHolidaysEqual( + Kyrgyzstan(years=2023), + ("2023-01-01", "New Year's Day"), + ("2023-01-07", "Christmas Day"), + ("2023-02-23", "Fatherland Defender's Day"), + ("2023-03-08", "International Women's Day"), + ("2023-03-21", "Nooruz Mairamy"), + ("2023-04-07", "Day of the People's April Revolution"), + ("2023-04-21", "Orozo Ait"), + ("2023-04-22", "Orozo Ait"), + ("2023-05-01", "International Workers' Day"), + ("2023-05-05", "Constitution Day"), + ("2023-05-09", "Victory Day"), + ("2023-06-28", "Kurman Ait"), + ("2023-08-31", "Independence Day"), + ("2023-11-07", "Days of History and Commemoration of Ancestors"), + ("2023-11-08", "Days of History and Commemoration of Ancestors"), + ("2023-12-31", "New Year's Eve"), + ) + + def test_day_of_peoples_revolution(self): + self.assertNoHoliday("2015-04-07") + self.assertHoliday("2016-04-07", "2017-04-07") From 90dc5a1d8fc9c2f3a62c43d23fd53fbd0bf8e4cc Mon Sep 17 00:00:00 2001 From: Arkadii Yakovets Date: Tue, 10 Jan 2023 10:03:36 -0800 Subject: [PATCH 115/138] Use augmented assignment statements. --- holidays/countries/aruba.py | 7 ++----- holidays/countries/curacao.py | 9 +++------ holidays/countries/netherlands.py | 7 ++----- holidays/countries/south_korea.py | 2 +- 4 files changed, 8 insertions(+), 17 deletions(-) diff --git a/holidays/countries/aruba.py b/holidays/countries/aruba.py index 731fdb1ad..abf3d078f 100644 --- a/holidays/countries/aruba.py +++ b/holidays/countries/aruba.py @@ -58,7 +58,7 @@ def _populate(self, year): if year >= 2014: kings_day = date(year, APR, 27) if kings_day.weekday() == SUN: - kings_day = kings_day - rd(days=1) + kings_day += rd(days=-1) self[kings_day] = "Aña di Rey [King's Day]" @@ -69,10 +69,7 @@ def _populate(self, year): queens_day = date(year, AUG, 31) if queens_day.weekday() == SUN: - if year < 1980: - queens_day = queens_day + rd(days=1) - else: - queens_day = queens_day - rd(days=1) + queens_day += rd(days=+1) if year < 1980 else rd(days=-1) self[queens_day] = "Aña di La Reina [Queen's Day]" diff --git a/holidays/countries/curacao.py b/holidays/countries/curacao.py index 139e4a492..562132980 100644 --- a/holidays/countries/curacao.py +++ b/holidays/countries/curacao.py @@ -49,7 +49,7 @@ def _populate(self, year): if year >= 2014: kings_day = date(year, APR, 27) if kings_day.weekday() == SUN: - kings_day = kings_day - rd(days=1) + kings_day += rd(days=-1) self[kings_day] = "Koningsdag [King's Day]" @@ -60,17 +60,14 @@ def _populate(self, year): queens_day = date(year, AUG, 31) if queens_day.weekday() == SUN: - if year < 1980: - queens_day = queens_day + rd(days=1) - else: - queens_day = queens_day - rd(days=1) + queens_day += rd(days=1) if year < 1980 else rd(days=-1) self[queens_day] = "Anja di La Reina [Queen's Day]" # Labour Day labour_day = date(year, MAY, 1) if labour_day.weekday() == SUN: - labour_day = labour_day + rd(days=1) + labour_day += rd(days=+1) self[labour_day] = "Dia di Obrero [Labour Day]" # Ascension Day diff --git a/holidays/countries/netherlands.py b/holidays/countries/netherlands.py index a0c502745..dcf51d60b 100644 --- a/holidays/countries/netherlands.py +++ b/holidays/countries/netherlands.py @@ -65,7 +65,7 @@ def _populate(self, year): if year >= 2014: kings_day = date(year, APR, 27) if kings_day.weekday() == SUN: - kings_day = kings_day - rd(days=1) + kings_day += rd(days=-1) self[kings_day] = "Koningsdag" @@ -76,10 +76,7 @@ def _populate(self, year): queens_day = date(year, AUG, 31) if queens_day.weekday() == SUN: - if year < 1980: - queens_day = queens_day + rd(days=1) - else: - queens_day = queens_day - rd(days=1) + queens_day += rd(days=1) if year < 1980 else rd(days=-1) self[queens_day] = "Koninginnedag" diff --git a/holidays/countries/south_korea.py b/holidays/countries/south_korea.py index 6bbb1a03c..5618a12ee 100644 --- a/holidays/countries/south_korea.py +++ b/holidays/countries/south_korea.py @@ -269,7 +269,7 @@ def get_next_first_non_holiday( cur in self and name != self[cur] ) # Exclude if already a holiday while check_1 or check_2: - cur = cur + rd(days=1) + cur += rd(days=+1) check_1 = cur.weekday() in target_weekday check_2 = cur in self and name != self[cur] From 976686a5049493a334803330611abe3fd7323ec6 Mon Sep 17 00:00:00 2001 From: Arkadii Yakovets Date: Thu, 12 Jan 2023 10:02:31 -0800 Subject: [PATCH 116/138] Standardize `relativedelta` days usage. Replace `timedelta` with `relativedelta`. --- holidays/countries/aruba.py | 6 +- holidays/countries/belarus.py | 2 +- holidays/countries/botswana.py | 2 +- holidays/countries/burundi.py | 2 +- holidays/countries/canada.py | 8 +- holidays/countries/curacao.py | 8 +- holidays/countries/djibouti.py | 6 +- holidays/countries/egypt.py | 10 +-- holidays/countries/ethiopia.py | 4 +- holidays/countries/honduras.py | 4 +- holidays/countries/ireland.py | 2 +- holidays/countries/israel.py | 28 +++---- holidays/countries/morocco.py | 6 +- holidays/countries/netherlands.py | 6 +- holidays/countries/nigeria.py | 4 +- holidays/countries/portugal.py | 2 +- holidays/countries/saudi_arabia.py | 10 +-- holidays/countries/south_korea.py | 2 +- holidays/countries/taiwan.py | 8 +- holidays/countries/tunisia.py | 10 +-- holidays/countries/turkey.py | 10 +-- holidays/countries/united_arab_emirates.py | 20 ++--- holidays/countries/zambia.py | 4 +- holidays/countries/zimbabwe.py | 2 +- holidays/financial/european_central_bank.py | 4 +- holidays/financial/ny_stock_exchange.py | 13 ++-- holidays/holiday_base.py | 3 +- holidays/utils.py | 17 ++-- test/countries/test_argentina.py | 46 +++++------ test/countries/test_australia.py | 8 +- test/countries/test_austria.py | 24 +++--- test/countries/test_bulgaria.py | 10 ++- test/countries/test_canada.py | 70 ++++++++--------- test/countries/test_colombia.py | 6 +- test/countries/test_cuba.py | 6 +- test/countries/test_ireland.py | 8 +- test/countries/test_israel.py | 42 +++------- test/countries/test_mexico.py | 34 ++++---- test/countries/test_new_zealand.py | 18 ++--- test/countries/test_paraguay.py | 8 +- test/countries/test_united_kingdom.py | 38 ++++----- test/countries/test_united_states.py | 82 ++++++++++---------- test/countries/test_uruguay.py | 30 +++---- test/countries/test_venezuela.py | 6 +- test/countries/test_vietnam.py | 14 ++-- test/financial/test_european_central_bank.py | 20 ++--- test/financial/test_ny_stock_exchange.py | 9 +-- 47 files changed, 334 insertions(+), 348 deletions(-) diff --git a/holidays/countries/aruba.py b/holidays/countries/aruba.py index 731fdb1ad..9c5dfbec8 100644 --- a/holidays/countries/aruba.py +++ b/holidays/countries/aruba.py @@ -58,7 +58,7 @@ def _populate(self, year): if year >= 2014: kings_day = date(year, APR, 27) if kings_day.weekday() == SUN: - kings_day = kings_day - rd(days=1) + kings_day = kings_day + rd(days=-1) self[kings_day] = "Aña di Rey [King's Day]" @@ -70,9 +70,9 @@ def _populate(self, year): if queens_day.weekday() == SUN: if year < 1980: - queens_day = queens_day + rd(days=1) + queens_day = queens_day + rd(days=+1) else: - queens_day = queens_day - rd(days=1) + queens_day = queens_day + rd(days=-1) self[queens_day] = "Aña di La Reina [Queen's Day]" diff --git a/holidays/countries/belarus.py b/holidays/countries/belarus.py index 348a7f2e0..6c1334f92 100644 --- a/holidays/countries/belarus.py +++ b/holidays/countries/belarus.py @@ -52,7 +52,7 @@ def _populate(self, year): self[date(year, MAR, 8)] = "День женщин" # Radunitsa ("Day of Rejoicing") - self[easter(year, method=EASTER_ORTHODOX) + rd(days=9)] = "Радуница" + self[easter(year, method=EASTER_ORTHODOX) + rd(days=+9)] = "Радуница" # Labour Day self[date(year, MAY, 1)] = "Праздник труда" diff --git a/holidays/countries/botswana.py b/holidays/countries/botswana.py index 6067e426c..98dd0189f 100644 --- a/holidays/countries/botswana.py +++ b/holidays/countries/botswana.py @@ -52,7 +52,7 @@ def _populate(self, year: int): # 3rd Monday of July = "President's Day" d = date(year, JUL, 1) + rd(weekday=MO(+3)) self[d] = "President's Day" - self[d + rd(days=1)] = "President's Day Holiday" + self[d + rd(days=+1)] = "President's Day Holiday" self[date(year, SEP, 30)] = "Botswana Day" self[date(year, OCT, 1)] = "Botswana Day Holiday" diff --git a/holidays/countries/burundi.py b/holidays/countries/burundi.py index b0d5cfd81..68b2c0664 100644 --- a/holidays/countries/burundi.py +++ b/holidays/countries/burundi.py @@ -82,7 +82,7 @@ def _add_holiday(dt: date, hol: str) -> None: for date_obs in _islamic_to_gre(yr, 12, 10): hol_date = date_obs _add_holiday(hol_date, "Eid Al Adha") - _add_holiday(hol_date + rd(days=1), "Eid Al Adha") + _add_holiday(hol_date + rd(days=+1), "Eid Al Adha") # Assumption Day name = "Assumption Day" diff --git a/holidays/countries/canada.py b/holidays/countries/canada.py index f219620f9..8f44691d5 100644 --- a/holidays/countries/canada.py +++ b/holidays/countries/canada.py @@ -144,7 +144,7 @@ def _populate(self, year): dt = date(year, JUN, 24) self[dt] = name if self.observed and dt.weekday() == SUN: - self[dt + rd(days=1)] = name + " (Observed)" + self[dt + rd(days=+1)] = name + " (Observed)" # Discovery Day if self.subdiv == "NL" and year >= 1997: @@ -171,7 +171,7 @@ def _populate(self, year): dt = date(year, JUL, 9) self[dt] = name if self.observed and dt.weekday() == SUN: - self[dt + rd(days=1)] = name + " (Observed)" + self[dt + rd(days=+1)] = name + " (Observed)" elif year == 2000: self[date(2000, APR, 1)] = name @@ -243,14 +243,14 @@ def _populate(self, year): dt = date(year, DEC, 25) self[dt] = name if self.observed and self._is_weekend(dt): - self[dt + rd(days=2)] = name + " (Observed)" + self[dt + rd(days=+2)] = name + " (Observed)" # Boxing Day name = "Boxing Day" dt = date(year, DEC, 26) self[dt] = name if self.observed and self._is_weekend(dt): - self[dt + rd(days=2)] = name + " (Observed)" + self[dt + rd(days=+2)] = name + " (Observed)" class CA(Canada): diff --git a/holidays/countries/curacao.py b/holidays/countries/curacao.py index 139e4a492..44757f1d7 100644 --- a/holidays/countries/curacao.py +++ b/holidays/countries/curacao.py @@ -49,7 +49,7 @@ def _populate(self, year): if year >= 2014: kings_day = date(year, APR, 27) if kings_day.weekday() == SUN: - kings_day = kings_day - rd(days=1) + kings_day = kings_day + rd(days=-1) self[kings_day] = "Koningsdag [King's Day]" @@ -61,16 +61,16 @@ def _populate(self, year): if queens_day.weekday() == SUN: if year < 1980: - queens_day = queens_day + rd(days=1) + queens_day = queens_day + rd(days=+1) else: - queens_day = queens_day - rd(days=1) + queens_day = queens_day + rd(days=-1) self[queens_day] = "Anja di La Reina [Queen's Day]" # Labour Day labour_day = date(year, MAY, 1) if labour_day.weekday() == SUN: - labour_day = labour_day + rd(days=1) + labour_day = labour_day + rd(days=+1) self[labour_day] = "Dia di Obrero [Labour Day]" # Ascension Day diff --git a/holidays/countries/djibouti.py b/holidays/countries/djibouti.py index a299d5bd7..5b4f0662c 100644 --- a/holidays/countries/djibouti.py +++ b/holidays/countries/djibouti.py @@ -77,7 +77,7 @@ def _add_holiday(dt: date, hol: str) -> None: hol_date = date_obs _add_holiday(hol_date, "Eid al-Fitr") _add_holiday( - hol_date + rd(days=1), "Eid al-Fitr deuxième jour" + hol_date + rd(days=+1), "Eid al-Fitr deuxième jour" ) # Arafat & Eid al-Adha - Scarfice Festive @@ -86,9 +86,9 @@ def _add_holiday(dt: date, hol: str) -> None: for date_obs in _islamic_to_gre(yr, 12, 9): hol_date = date_obs _add_holiday(hol_date, "Arafat") - _add_holiday(hol_date + rd(days=1), "Eid al-Adha") + _add_holiday(hol_date + rd(days=+1), "Eid al-Adha") _add_holiday( - hol_date + rd(days=2), "Eid al-Adha deuxième jour" + hol_date + rd(days=+2), "Eid al-Adha deuxième jour" ) # Islamic New Year - (hijari_year, 1, 1) diff --git a/holidays/countries/egypt.py b/holidays/countries/egypt.py index 8ddc3990c..652e93fd6 100644 --- a/holidays/countries/egypt.py +++ b/holidays/countries/egypt.py @@ -95,8 +95,8 @@ def _add_holiday(dt: date, hol: str) -> None: for date_obs in _islamic_to_gre(yr, 10, 1): hol_date = date_obs _add_holiday(hol_date, "Eid al-Fitr") - _add_holiday(hol_date + rd(days=1), "Eid al-Fitr Holiday") - _add_holiday(hol_date + rd(days=2), "Eid al-Fitr Holiday") + _add_holiday(hol_date + rd(days=+1), "Eid al-Fitr Holiday") + _add_holiday(hol_date + rd(days=+2), "Eid al-Fitr Holiday") # Arafat Day & Eid al-Adha - Scarfice Festive # date of observance is announced yearly @@ -104,9 +104,9 @@ def _add_holiday(dt: date, hol: str) -> None: for date_obs in _islamic_to_gre(yr, 12, 9): hol_date = date_obs _add_holiday(hol_date, "Arafat Day") - _add_holiday(hol_date + rd(days=1), "Eid al-Adha") - _add_holiday(hol_date + rd(days=2), "Eid al-Adha Holiday") - _add_holiday(hol_date + rd(days=3), "Eid al-Adha Holiday") + _add_holiday(hol_date + rd(days=+1), "Eid al-Adha") + _add_holiday(hol_date + rd(days=+2), "Eid al-Adha Holiday") + _add_holiday(hol_date + rd(days=+3), "Eid al-Adha Holiday") # Islamic New Year - (hijari_year, 1, 1) for date_obs in _islamic_to_gre(year, 1, 1): diff --git a/holidays/countries/ethiopia.py b/holidays/countries/ethiopia.py index 16e329812..a1e5bf1b1 100644 --- a/holidays/countries/ethiopia.py +++ b/holidays/countries/ethiopia.py @@ -108,12 +108,12 @@ def _populate(self, year): # date of observance is announced yearly for date_obs in _islamic_to_gre(year, 12, 9): hol_date = date_obs - self[hol_date + rd(days=1)] = "አረፋ/Eid-Al-Adha" + self[hol_date + rd(days=+1)] = "አረፋ/Eid-Al-Adha" # Prophet Muhammad's Birthday - (hijari_year, 3, 12) for date_obs in _islamic_to_gre(year, 3, 12): hol_date = date_obs - self[hol_date + rd(days=1)] = "መውሊድ/Prophet Muhammad's Birthday" + self[hol_date + rd(days=+1)] = "መውሊድ/Prophet Muhammad's Birthday" # Ethiopian leap years are coincident with leap years in the Gregorian # calendar until the end of February 2100. It starts earlier from new year diff --git a/holidays/countries/honduras.py b/holidays/countries/honduras.py index a163baec9..c90667852 100644 --- a/holidays/countries/honduras.py +++ b/holidays/countries/honduras.py @@ -68,8 +68,8 @@ def _populate(self, year): holiday_name = "Semana Morazánica [Morazan Weekend]" first_wednesday = date(year, OCT, 1) + rd(weekday=WE(+1)) self[first_wednesday] = holiday_name - self[first_wednesday + rd(days=1)] = holiday_name - self[first_wednesday + rd(days=2)] = holiday_name + self[first_wednesday + rd(days=+1)] = holiday_name + self[first_wednesday + rd(days=+2)] = holiday_name # Christmas self[date(year, DEC, 25)] = "Navidad [Christmas]" diff --git a/holidays/countries/ireland.py b/holidays/countries/ireland.py index b8a330ebe..5d6f515fb 100644 --- a/holidays/countries/ireland.py +++ b/holidays/countries/ireland.py @@ -83,7 +83,7 @@ def _populate(self, year): dt = date(year, DEC, 26) self[dt] = name if self.observed and self._is_weekend(dt): - self[dt + rd(days=2)] = name + " (Observed)" + self[dt + rd(days=+2)] = name + " (Observed)" class IE(Ireland): diff --git a/holidays/countries/israel.py b/holidays/countries/israel.py index 7da13450c..b0df88092 100644 --- a/holidays/countries/israel.py +++ b/holidays/countries/israel.py @@ -32,15 +32,15 @@ def _populate(self, year): name = "Passover I" passover_start_dt = date(*passover(year, eve=True)) self[passover_start_dt] = name + " - Eve" - self[passover_start_dt + rd(days=1)] = name + self[passover_start_dt + rd(days=+1)] = name name = "Passover" for offset in range(2, 6): self[passover_start_dt + rd(days=offset)] = name + " - Chol HaMoed" name = "Passover VII" - self[passover_start_dt + rd(days=6)] = name + " - Eve" - self[passover_start_dt + rd(days=7)] = name + self[passover_start_dt + rd(days=+6)] = name + " - Eve" + self[passover_start_dt + rd(days=+7)] = name # Memorial Day name = "Memorial Day" @@ -49,7 +49,7 @@ def _populate(self, year): hebrew.to_jd_gregorianyear(year, hebrew.IYYAR, 3) ) ) - self[memorial_day_dt + rd(days=1)] = name + self[memorial_day_dt + rd(days=+1)] = name observed_delta = 0 if self.observed: @@ -66,7 +66,7 @@ def _populate(self, year): # Independence Day name = "Independence Day" - self[memorial_day_dt + rd(days=2)] = name + self[memorial_day_dt + rd(days=+2)] = name if self.observed and observed_delta != 0: self[memorial_day_dt + rd(days=observed_delta + 2)] = ( @@ -82,34 +82,34 @@ def _populate(self, year): name = "Shavuot" shavuot_dt = date(*shavuot(year, eve=True)) self[shavuot_dt] = name + " - Eve" - self[shavuot_dt + rd(days=1)] = name + self[shavuot_dt + rd(days=+1)] = name # Rosh Hashana name = "Rosh Hashanah" rosh_hashanah_dt = date(*rosh_hashanah(year, eve=True)) self[rosh_hashanah_dt] = name + " - Eve" - self[rosh_hashanah_dt + rd(days=1)] = name - self[rosh_hashanah_dt + rd(days=2)] = name + self[rosh_hashanah_dt + rd(days=+1)] = name + self[rosh_hashanah_dt + rd(days=+2)] = name # Yom Kippur name = "Yom Kippur" yom_kippur_dt = date(*yom_kippur(year, eve=True)) self[yom_kippur_dt] = name + " - Eve" - self[yom_kippur_dt + rd(days=1)] = name + self[yom_kippur_dt + rd(days=+1)] = name # Sukkot name = "Sukkot I" sukkot_start_dt = date(*sukkot(year, eve=True)) self[sukkot_start_dt] = name + " - Eve" - self[sukkot_start_dt + rd(days=1)] = name + self[sukkot_start_dt + rd(days=+1)] = name name = "Sukkot" for offset in range(2, 7): self[sukkot_start_dt + rd(days=offset)] = name + " - Chol HaMoed" name = "Sukkot VII" - self[sukkot_start_dt + rd(days=7)] = name + " - Eve" - self[sukkot_start_dt + rd(days=8)] = name + self[sukkot_start_dt + rd(days=+7)] = name + " - Eve" + self[sukkot_start_dt + rd(days=+8)] = name # Hanukkah name = "Hanukkah" @@ -129,8 +129,8 @@ def _populate(self, year): name = "Purim" purim_date = date(*purim(year, eve=True)) self[purim_date] = name + " - Eve" - self[purim_date + rd(days=1)] = name - self[purim_date + rd(days=2)] = "Shushan Purim" + self[purim_date + rd(days=+1)] = name + self[purim_date + rd(days=+2)] = "Shushan Purim" class IL(Israel): diff --git a/holidays/countries/morocco.py b/holidays/countries/morocco.py index 0d4bf8f8b..8f6abca88 100644 --- a/holidays/countries/morocco.py +++ b/holidays/countries/morocco.py @@ -103,7 +103,7 @@ def _add_holiday(dt: date, hol: str) -> None: for date_obs in _islamic_to_gre(yr, 10, 1): hol_date = date_obs _add_holiday(hol_date, "Eid al-Fitr") - _add_holiday(hol_date + rd(days=1), "Eid al-Fitr") + _add_holiday(hol_date + rd(days=+1), "Eid al-Fitr") # Eid al-Adha - Sacrifice Festive # date of observance is announced yearly @@ -111,7 +111,7 @@ def _add_holiday(dt: date, hol: str) -> None: for date_obs in _islamic_to_gre(yr, 12, 10): hol_date = date_obs _add_holiday(hol_date, "Eid al-Adha") - _add_holiday(hol_date + rd(days=1), "Eid al-Adha") + _add_holiday(hol_date + rd(days=+1), "Eid al-Adha") # Islamic New Year - (hijari_year, 1, 1) for date_obs in _islamic_to_gre(year, 1, 1): @@ -123,7 +123,7 @@ def _add_holiday(dt: date, hol: str) -> None: for date_obs in _islamic_to_gre(yr, 3, 12): hol_date = date_obs _add_holiday(hol_date, "Aid al Mawlid Annabawi") - _add_holiday(hol_date + rd(days=1), "Aid al Mawlid Annabawi") + _add_holiday(hol_date + rd(days=+1), "Aid al Mawlid Annabawi") class MA(Morocco): diff --git a/holidays/countries/netherlands.py b/holidays/countries/netherlands.py index a0c502745..5cb360508 100644 --- a/holidays/countries/netherlands.py +++ b/holidays/countries/netherlands.py @@ -65,7 +65,7 @@ def _populate(self, year): if year >= 2014: kings_day = date(year, APR, 27) if kings_day.weekday() == SUN: - kings_day = kings_day - rd(days=1) + kings_day = kings_day + rd(days=-1) self[kings_day] = "Koningsdag" @@ -77,9 +77,9 @@ def _populate(self, year): if queens_day.weekday() == SUN: if year < 1980: - queens_day = queens_day + rd(days=1) + queens_day = queens_day + rd(days=+1) else: - queens_day = queens_day - rd(days=1) + queens_day = queens_day + rd(days=-1) self[queens_day] = "Koninginnedag" diff --git a/holidays/countries/nigeria.py b/holidays/countries/nigeria.py index 017b21b0f..b17f467bd 100644 --- a/holidays/countries/nigeria.py +++ b/holidays/countries/nigeria.py @@ -58,7 +58,7 @@ def _add_holiday(dt: date, hol: str) -> None: for yr in (year - 1, year): for hol_date in _islamic_to_gre(yr, 10, 1): _add_holiday(hol_date, "Eid al-Fitr") - _add_holiday(hol_date + rd(days=1), "Eid al-Fitr Holiday") + _add_holiday(hol_date + rd(days=+1), "Eid al-Fitr Holiday") # Arafat Day & Eid al-Adha - Scarfice Festive # This is an estimate @@ -66,7 +66,7 @@ def _add_holiday(dt: date, hol: str) -> None: for yr in (year - 1, year): for hol_date in _islamic_to_gre(yr, 12, 10): _add_holiday(hol_date, "Eid al-Adha") - _add_holiday(hol_date + rd(days=1), "Eid al-Adha Holiday") + _add_holiday(hol_date + rd(days=+1), "Eid al-Adha Holiday") # Birthday of Prophet Muhammad for hol_date in _islamic_to_gre(year, 3, 12): diff --git a/holidays/countries/portugal.py b/holidays/countries/portugal.py index 16b2d02af..d41434f70 100644 --- a/holidays/countries/portugal.py +++ b/holidays/countries/portugal.py @@ -59,7 +59,7 @@ def _populate(self, year): # carnival is no longer a holiday, but some companies let workers off. # @todo recollect the years in which it was a public holiday - # self[e - rd(days=47)] = "Carnaval" + # self[e + rd(days=-47)] = "Carnaval" self[easter_date + rd(days=-2)] = "Sexta-feira Santa" self[easter_date] = "Páscoa" diff --git a/holidays/countries/saudi_arabia.py b/holidays/countries/saudi_arabia.py index a07a53aeb..960b64a04 100644 --- a/holidays/countries/saudi_arabia.py +++ b/holidays/countries/saudi_arabia.py @@ -69,7 +69,7 @@ def _add_holiday(dt: date, hol: str) -> None: holiday_name = "Eid al-Fitr Holiday" for yr in (year - 1, year): for hijri_date in _islamic_to_gre(yr, 9, 29): - hijri_date += rd(days=1) + hijri_date += rd(days=+1) for dys in range(4): _add_holiday((hijri_date + rd(days=dys)), holiday_name) if self.observed: @@ -117,13 +117,13 @@ def _add_holiday(dt: date, hol: str) -> None: self[national_day] = holiday_name # First weekend day(Thursaday before 2013 and Friday otherwise) if self.observed and national_day.weekday() == self.weekend[0]: - national_day -= rd(days=1) + national_day += rd(days=-1) self[national_day] = holiday_name + observed_str # Second weekend day(Friday before 2013 and Saturday otherwise) elif ( self.observed and national_day.weekday() == self.weekend[1] ): - national_day += rd(days=1) + national_day += rd(days=+1) self[national_day] = holiday_name + observed_str # Founding Day holiday (started 2022). @@ -136,13 +136,13 @@ def _add_holiday(dt: date, hol: str) -> None: self[founding_day] = holiday_name # First weekend day(Thursaday before 2013 and Friday otherwise) if self.observed and founding_day.weekday() == self.weekend[0]: - founding_day -= rd(days=1) + founding_day += rd(days=-1) self[founding_day] = holiday_name + observed_str # Second weekend day(Friday before 2013 and Saturday otherwise) elif ( self.observed and founding_day.weekday() == self.weekend[1] ): - founding_day += rd(days=1) + founding_day += rd(days=+1) self[founding_day] = holiday_name + observed_str diff --git a/holidays/countries/south_korea.py b/holidays/countries/south_korea.py index 6bbb1a03c..5ebe184d2 100644 --- a/holidays/countries/south_korea.py +++ b/holidays/countries/south_korea.py @@ -269,7 +269,7 @@ def get_next_first_non_holiday( cur in self and name != self[cur] ) # Exclude if already a holiday while check_1 or check_2: - cur = cur + rd(days=1) + cur = cur + rd(days=+1) check_1 = cur.weekday() in target_weekday check_2 = cur in self and name != self[cur] diff --git a/holidays/countries/taiwan.py b/holidays/countries/taiwan.py index 3a496b5c3..ab4322c82 100644 --- a/holidays/countries/taiwan.py +++ b/holidays/countries/taiwan.py @@ -40,8 +40,8 @@ def _populate(self, year): hol_date = self.cnls.lunar_n_y_date(year) self[hol_date + rd(days=-1)] = "Chinese New Year's Eve" self[hol_date] = "Spring Festival" - self[hol_date + rd(days=1)] = "Spring Festival" - self[hol_date + rd(days=2)] = "Spring Festival" + self[hol_date + rd(days=+1)] = "Spring Festival" + self[hol_date + rd(days=+2)] = "Spring Festival" self[date(year, APR, 4)] = "Children's Day" self[self.cnls.lunar_to_gre(year, 5, 5)] = "Dragon Boat Festival" self[self.cnls.lunar_to_gre(year, 8, 15)] = "Mid-Autumn Festival" @@ -51,8 +51,8 @@ def _populate(self, year): self[date(year, FEB, 28)] = "Peace Memorial Day" if year == 2021: hol_date = self.cnls.lunar_n_y_date(year) - self[hol_date + rd(days=3)] = "Spring Festival" - self[hol_date + rd(days=4)] = "Spring Festival" + self[hol_date + rd(days=+3)] = "Spring Festival" + self[hol_date + rd(days=+4)] = "Spring Festival" class TW(Taiwan): diff --git a/holidays/countries/tunisia.py b/holidays/countries/tunisia.py index 7cebd090e..150c66700 100644 --- a/holidays/countries/tunisia.py +++ b/holidays/countries/tunisia.py @@ -78,8 +78,8 @@ def _add_holiday(dt: date, hol: str) -> None: for date_obs in _islamic_to_gre(yr, 10, 1): hol_date = date_obs _add_holiday(hol_date, "Eid al-Fitr") - _add_holiday(hol_date + rd(days=1), "Eid al-Fitr Holiday") - _add_holiday(hol_date + rd(days=2), "Eid al-Fitr Holiday") + _add_holiday(hol_date + rd(days=+1), "Eid al-Fitr Holiday") + _add_holiday(hol_date + rd(days=+2), "Eid al-Fitr Holiday") # Arafat Day & Eid al-Adha - Scarfice Festive # date of observance is announced yearly @@ -87,9 +87,9 @@ def _add_holiday(dt: date, hol: str) -> None: for date_obs in _islamic_to_gre(yr, 12, 9): hol_date = date_obs _add_holiday(hol_date, "Arafat Day") - _add_holiday(hol_date + rd(days=1), "Eid al-Adha") - _add_holiday(hol_date + rd(days=2), "Eid al-Adha Holiday") - _add_holiday(hol_date + rd(days=3), "Eid al-Adha Holiday") + _add_holiday(hol_date + rd(days=+1), "Eid al-Adha") + _add_holiday(hol_date + rd(days=+2), "Eid al-Adha Holiday") + _add_holiday(hol_date + rd(days=+3), "Eid al-Adha Holiday") # Islamic New Year - (hijari_year, 1, 1) for date_obs in _islamic_to_gre(year, 1, 1): diff --git a/holidays/countries/turkey.py b/holidays/countries/turkey.py index 61c81848a..77f0c7362 100644 --- a/holidays/countries/turkey.py +++ b/holidays/countries/turkey.py @@ -67,8 +67,8 @@ def _add_holiday(dt: date, hol: str) -> None: for date_obs in _islamic_to_gre(yr, 10, 1): hol_date = date_obs _add_holiday(hol_date, "Ramadan Feast") - _add_holiday(hol_date + rd(days=1), "Ramadan Feast Holiday") - _add_holiday(hol_date + rd(days=2), "Ramadan Feast Holiday") + _add_holiday(hol_date + rd(days=+1), "Ramadan Feast Holiday") + _add_holiday(hol_date + rd(days=+2), "Ramadan Feast Holiday") # Sacrifice Feast # Date of observance is announced yearly, This is an estimate. @@ -76,9 +76,9 @@ def _add_holiday(dt: date, hol: str) -> None: for date_obs in _islamic_to_gre(yr, 12, 10): hol_date = date_obs _add_holiday(hol_date, "Sacrifice Feast") - _add_holiday(hol_date + rd(days=1), "Sacrifice Feast Holiday") - _add_holiday(hol_date + rd(days=2), "Sacrifice Feast Holiday") - _add_holiday(hol_date + rd(days=3), "Sacrifice Feast Holiday") + _add_holiday(hol_date + rd(days=+1), "Sacrifice Feast Holiday") + _add_holiday(hol_date + rd(days=+2), "Sacrifice Feast Holiday") + _add_holiday(hol_date + rd(days=+3), "Sacrifice Feast Holiday") class TR(Turkey): diff --git a/holidays/countries/united_arab_emirates.py b/holidays/countries/united_arab_emirates.py index e79c7c38e..71cb9be35 100644 --- a/holidays/countries/united_arab_emirates.py +++ b/holidays/countries/united_arab_emirates.py @@ -87,19 +87,19 @@ def _add_holiday(dt: date, hol: str) -> None: for date_obs in dates_obs[year]: hol_date = date(year, *date_obs) self[hol_date] = fitr - self[hol_date + rd(days=1)] = f"{fitr} Holiday" - self[hol_date + rd(days=2)] = f"{fitr} Holiday" + self[hol_date + rd(days=+1)] = f"{fitr} Holiday" + self[hol_date + rd(days=+2)] = f"{fitr} Holiday" else: for yr in (year - 1, year): for date_obs in _islamic_to_gre(yr, 10, 1): hol_date = date_obs _add_holiday(hol_date, f"{fitr}* (*estimated)") _add_holiday( - hol_date + rd(days=1), + hol_date + rd(days=+1), f"{fitr} Holiday* (*estimated)", ) _add_holiday( - hol_date + rd(days=2), + hol_date + rd(days=+2), f"{fitr} Holiday* (*estimated)", ) @@ -116,23 +116,23 @@ def _add_holiday(dt: date, hol: str) -> None: for date_obs in dates_obs[year]: hol_date = date(year, *date_obs) self[hol_date] = hajj - self[hol_date + rd(days=1)] = adha - self[hol_date + rd(days=2)] = f"{adha} Holiday" - self[hol_date + rd(days=3)] = f"{adha} Holiday" + self[hol_date + rd(days=+1)] = adha + self[hol_date + rd(days=+2)] = f"{adha} Holiday" + self[hol_date + rd(days=+3)] = f"{adha} Holiday" else: for yr in (year - 1, year): for date_obs in _islamic_to_gre(yr, 12, 9): hol_date = date_obs _add_holiday(hol_date, f"{hajj}* (*estimated)") _add_holiday( - hol_date + rd(days=1), f"{adha}* (*estimated)" + hol_date + rd(days=+1), f"{adha}* (*estimated)" ) _add_holiday( - hol_date + rd(days=2), + hol_date + rd(days=+2), f"{adha}* Holiday* (*estimated)", ) _add_holiday( - hol_date + rd(days=3), + hol_date + rd(days=+3), f"{adha} Holiday* (*estimated)", ) diff --git a/holidays/countries/zambia.py b/holidays/countries/zambia.py index 88240170f..4b307b769 100644 --- a/holidays/countries/zambia.py +++ b/holidays/countries/zambia.py @@ -81,7 +81,7 @@ def _populate(self, year): # 1st Monday of July = "Heroes' Day" dt = date(year, JUL, 1) + rd(weekday=MO) self[dt] = "Heroes' Day" - self[dt + rd(days=1)] = "Unity Day" + self[dt + rd(days=+1)] = "Unity Day" # 1st Monday of Aug = "Farmers' Day" dt = date(year, AUG, 1) + rd(weekday=MO) @@ -98,7 +98,7 @@ def _populate(self, year): if self.observed: for k, v in list(self.items()): if k.year == year and k.weekday() == SUN: - self[k + rd(days=1)] = v + " (Observed)" + self[k + rd(days=+1)] = v + " (Observed)" class ZM(Zambia): diff --git a/holidays/countries/zimbabwe.py b/holidays/countries/zimbabwe.py index f17c0d4f7..04691ff06 100644 --- a/holidays/countries/zimbabwe.py +++ b/holidays/countries/zimbabwe.py @@ -55,7 +55,7 @@ def _populate(self, year): self[zimbabwe_heroes_day] = "Zimbabwe Heroes' Day" # Tuesday after 2nd Monday of August - defence_forces_day = zimbabwe_heroes_day + rd(days=1) + defence_forces_day = zimbabwe_heroes_day + rd(days=+1) self[defence_forces_day] = "Defense Forces Day" self[date(year, DEC, 22)] = "Unity Day" diff --git a/holidays/financial/european_central_bank.py b/holidays/financial/european_central_bank.py index cfdfda324..4ab9d88e4 100644 --- a/holidays/financial/european_central_bank.py +++ b/holidays/financial/european_central_bank.py @@ -32,8 +32,8 @@ def _populate(self, year): self[date(year, JAN, 1)] = "New Year's Day" e = easter(year) - self[e - rd(days=2)] = "Good Friday" - self[e + rd(days=1)] = "Easter Monday" + self[e + rd(days=-2)] = "Good Friday" + self[e + rd(days=+1)] = "Easter Monday" self[date(year, MAY, 1)] = "1 May (Labour Day)" self[date(year, DEC, 25)] = "Christmas Day" self[date(year, DEC, 26)] = "26 December" diff --git a/holidays/financial/ny_stock_exchange.py b/holidays/financial/ny_stock_exchange.py index e3577f66f..f3f9d9c29 100644 --- a/holidays/financial/ny_stock_exchange.py +++ b/holidays/financial/ny_stock_exchange.py @@ -9,7 +9,7 @@ # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) -from datetime import date, timedelta +from datetime import date from dateutil.easter import easter from dateutil.relativedelta import MO, TH, FR @@ -88,7 +88,7 @@ def _populate(self, year): # GOOD FRIDAY - closed every year except 1898, 1906, and 1907 e = easter(year) if year not in {1898, 1906, 1907}: - self[e - rd(days=2)] = "Good Friday" + self[e + rd(days=-2)] = "Good Friday" # MEM DAY (May 30) - closed every year since 1873 # last Mon in May since 1971 @@ -178,8 +178,7 @@ def _populate(self, year): begin = date(year, JUL, 31) end = date(year, NOV, 27) for d in ( - begin + timedelta(days=n) - for n in range((end - begin).days + 1) + begin + rd(days=n) for n in range((end - begin).days + 1) ): if self._is_weekend(d): continue @@ -210,8 +209,7 @@ def _populate(self, year): begin = date(year, MAR, 6) end = date(year, MAR, 14) for d in ( - begin + timedelta(days=n) - for n in range((end - begin).days + 1) + begin + rd(days=n) for n in range((end - begin).days + 1) ): if self._is_weekend(d): continue @@ -240,8 +238,7 @@ def _populate(self, year): begin = date(year, JUN, 12) end = date(year, DEC, 31) for d in ( - begin + timedelta(days=n) - for n in range((end - begin).days + 1) + begin + rd(days=n) for n in range((end - begin).days + 1) ): if d.weekday() != WED: # Wednesday special holiday continue diff --git a/holidays/holiday_base.py b/holidays/holiday_base.py index 05d8c2ab9..6c87c03ef 100644 --- a/holidays/holiday_base.py +++ b/holidays/holiday_base.py @@ -17,6 +17,7 @@ from typing import Union, cast from dateutil.parser import parse +from dateutil.relativedelta import relativedelta as rd from holidays.constants import SAT, SUN @@ -362,7 +363,7 @@ def __getitem__(self, key: DateLike) -> Any: days_in_range = [] for delta_days in range(0, date_diff.days, step): - day = start + timedelta(days=delta_days) + day = start + rd(days=delta_days) try: self.__getitem__(day) days_in_range.append(day) diff --git a/holidays/utils.py b/holidays/utils.py index 0e2843b55..b8a59abf0 100755 --- a/holidays/utils.py +++ b/holidays/utils.py @@ -19,10 +19,11 @@ import inspect import warnings -from datetime import date, timedelta +from datetime import date from functools import lru_cache from typing import Dict, Iterable, List, Optional, Union +from dateutil.relativedelta import relativedelta as rd from hijri_converter import convert from hijri_converter.ummalqura import GREGORIAN_RANGE @@ -679,7 +680,7 @@ def lunar_n_y_date(self, year: int) -> date: # leap_month = self._get_leap_month(year) # for m in range(1, 1 + (1 > leap_month)): # span_days += self._lunar_month_days(year, m) - return self.SOLAR_START_DATE + timedelta(span_days) + return self.SOLAR_START_DATE + rd(days=span_days) def lunar_to_gre( self, year: int, month: int, day: int, leap: bool = True @@ -705,7 +706,7 @@ def lunar_to_gre( for m in range(1, month + (month > leap_month)): span_days += self._lunar_month_days(year, m) span_days += day - 1 - return self.SOLAR_START_DATE + timedelta(span_days) + return self.SOLAR_START_DATE + rd(days=span_days) def vesak_date(self, year: int) -> date: """ @@ -726,7 +727,7 @@ def vesak_date(self, year: int) -> date: for m in range(1, 4 + (4 > leap_month)): span_days += self._lunar_month_days(year, m) span_days += 14 - return self.SOLAR_START_DATE + timedelta(span_days) + return self.SOLAR_START_DATE + rd(days=span_days) def vesak_may_date(self, year: int) -> date: """ @@ -742,10 +743,10 @@ def vesak_may_date(self, year: int) -> date: Estimated Gregorian date of Vesak (first full moon in May). """ span_days = self._span_days(year) - vesak_may_date = self.SOLAR_START_DATE + timedelta(span_days + 14) + vesak_may_date = self.SOLAR_START_DATE + rd(days=span_days + 14) m = 1 while vesak_may_date.month < 5: - vesak_may_date += timedelta(self._lunar_month_days(year, m)) + vesak_may_date += rd(days=self._lunar_month_days(year, m)) m += 1 return vesak_may_date @@ -769,7 +770,7 @@ def s_diwali_date(self, year: int) -> date: for m in range(1, 10 + (10 > leap_month)): span_days += self._lunar_month_days(year, m) span_days -= 2 - return self.SOLAR_START_DATE + timedelta(span_days) + return self.SOLAR_START_DATE + rd(days=span_days) def thaipusam_date(self, year: int) -> date: """ @@ -790,4 +791,4 @@ def thaipusam_date(self, year: int) -> date: for m in range(1, 1 + (leap_month <= 6)): span_days += self._lunar_month_days(year, m) span_days -= 15 - return self.SOLAR_START_DATE + timedelta(span_days) + return self.SOLAR_START_DATE + rd(days=span_days) diff --git a/test/countries/test_argentina.py b/test/countries/test_argentina.py index ea93271d9..a3f2564f4 100644 --- a/test/countries/test_argentina.py +++ b/test/countries/test_argentina.py @@ -11,7 +11,7 @@ from datetime import date -from dateutil.relativedelta import relativedelta +from dateutil.relativedelta import relativedelta as rd from holidays.constants import MAY, JUN, JUL, AUG, OCT from holidays.countries.argentina import AR, ARG, Argentina @@ -41,8 +41,8 @@ def test_new_years_day(self): dt = date(year, 1, 1) self.assertHoliday(dt) self.assertNoHoliday( - dt + relativedelta(days=-1), - dt + relativedelta(days=+1), + dt + rd(days=-1), + dt + rd(days=+1), ) def test_carnival_day(self): @@ -98,8 +98,8 @@ def test_labor_day(self): dt = date(year, MAY, 1) self.assertHoliday(dt) self.assertNoHoliday( - dt + relativedelta(days=-1), - dt + relativedelta(days=+1), + dt + rd(days=-1), + dt + rd(days=+1), ) def test_may_revolution_day(self): @@ -114,8 +114,8 @@ def test_may_revolution_day(self): dt = date(year, MAY, 25) self.assertHoliday(dt) self.assertNoHoliday( - dt + relativedelta(days=-1), - dt + relativedelta(days=+1), + dt + rd(days=-1), + dt + rd(days=+1), ) def test_guemes_day(self): @@ -123,8 +123,8 @@ def test_guemes_day(self): dt = date(year, JUN, 17) self.assertHoliday(dt) self.assertNoHoliday( - dt + relativedelta(days=-1), - dt + relativedelta(days=+1), + dt + rd(days=-1), + dt + rd(days=+1), ) def test_belgrano_day(self): @@ -132,8 +132,8 @@ def test_belgrano_day(self): dt = date(year, JUN, 20) self.assertHoliday(dt) self.assertNoHoliday( - dt + relativedelta(days=-1), - dt + relativedelta(days=+1), + dt + rd(days=-1), + dt + rd(days=+1), ) def test_independence_day(self): @@ -153,8 +153,8 @@ def test_independence_day(self): dt = date(year, JUL, 9) self.assertHoliday(dt) self.assertNoHoliday( - dt + relativedelta(days=-1), - dt + relativedelta(days=+1), + dt + rd(days=-1), + dt + rd(days=+1), ) def test_san_martin_day(self): @@ -169,8 +169,8 @@ def test_san_martin_day(self): dt = date(year, AUG, 17) self.assertHoliday(dt) self.assertNoHoliday( - dt + relativedelta(days=-1), - dt + relativedelta(days=+1), + dt + rd(days=-1), + dt + rd(days=+1), ) def test_cultural_day(self): @@ -185,8 +185,8 @@ def test_cultural_day(self): dt = date(year, OCT, 12) self.assertHoliday(dt) self.assertNoHoliday( - dt + relativedelta(days=-1), - dt + relativedelta(days=+1), + dt + rd(days=-1), + dt + rd(days=+1), ) def test_national_sovereignty_day(self): @@ -197,8 +197,8 @@ def test_national_sovereignty_day(self): else: self.assertHoliday(dt) self.assertNoHoliday( - dt + relativedelta(days=-1), - dt + relativedelta(days=+1), + dt + rd(days=-1), + dt + rd(days=+1), ) def test_immaculate_conception_day(self): @@ -213,8 +213,8 @@ def test_immaculate_conception_day(self): dt = date(year, 12, 8) self.assertHoliday(dt) self.assertNoHoliday( - dt + relativedelta(days=-1), - dt + relativedelta(days=+1), + dt + rd(days=-1), + dt + rd(days=+1), ) def test_christmas(self): @@ -222,8 +222,8 @@ def test_christmas(self): dt = date(year, 12, 25) self.assertHoliday(dt) self.assertNoHoliday( - dt + relativedelta(days=-1), - dt + relativedelta(days=+1), + dt + rd(days=-1), + dt + rd(days=+1), ) def test_2022(self): diff --git a/test/countries/test_australia.py b/test/countries/test_australia.py index 50bed1e4a..70ddd4be1 100644 --- a/test/countries/test_australia.py +++ b/test/countries/test_australia.py @@ -12,7 +12,7 @@ import unittest from datetime import date -from dateutil.relativedelta import relativedelta +from dateutil.relativedelta import relativedelta as rd import holidays @@ -125,7 +125,7 @@ def test_easter_monday(self): ]: self.assertIn(dt, self.holidays) self.assertEqual(self.holidays[dt], "Easter Monday") - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) def test_bank_holiday(self): for dt in [ @@ -328,7 +328,7 @@ def test_christmas_day(self): for year in range(1900, 2100): dt = date(year, 12, 25) self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) self.assertNotIn(date(2010, 12, 24), self.holidays) self.assertNotEqual( self.holidays[date(2011, 12, 26)], "Christmas Day (Observed)" @@ -372,7 +372,7 @@ def test_boxing_day(self): for year in range(1900, 2100): dt = date(year, 12, 26) self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) self.assertNotIn(date(2009, 12, 28), self.holidays) self.assertNotIn(date(2010, 12, 27), self.holidays) self.holidays.observed = True diff --git a/test/countries/test_austria.py b/test/countries/test_austria.py index 130ae6cca..f43a7e6cc 100644 --- a/test/countries/test_austria.py +++ b/test/countries/test_austria.py @@ -12,7 +12,7 @@ import unittest from datetime import date -from dateutil.relativedelta import relativedelta +from dateutil.relativedelta import relativedelta as rd import holidays @@ -25,16 +25,16 @@ def test_new_years(self): for year in range(1900, 2100): dt = date(year, 1, 1) self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) def test_christmas(self): for year in range(1900, 2100): dt = date(year, 12, 25) self.assertIn(dt, self.holidays) - self.assertIn(dt + relativedelta(days=+1), self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+2), self.holidays) + self.assertIn(dt + rd(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=+2), self.holidays) def test_easter_monday(self): for dt in [ @@ -49,20 +49,20 @@ def test_easter_monday(self): date(2020, 4, 13), ]: self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) def test_national_day(self): for year in range(1919, 1934): dt = date(year, 11, 12) self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) for year in range(1967, 2100): dt = date(year, 10, 26) self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) def test_all_holidays_present(self): at_2015 = holidays.AT(years=[2015]) diff --git a/test/countries/test_bulgaria.py b/test/countries/test_bulgaria.py index 998d4efc8..3de5f1c2f 100644 --- a/test/countries/test_bulgaria.py +++ b/test/countries/test_bulgaria.py @@ -10,7 +10,9 @@ # License: MIT (see LICENSE file) import unittest -from datetime import date, timedelta +from datetime import date + +from dateutil.relativedelta import relativedelta as rd import holidays @@ -87,9 +89,9 @@ def test_easter(self): (2022, 4, 24), ]: easter = date(year, month, day) - easter_friday = easter - timedelta(days=2) - easter_saturday = easter - timedelta(days=1) - easter_monday = easter + timedelta(days=1) + easter_friday = easter + rd(days=-2) + easter_saturday = easter + rd(days=-1) + easter_monday = easter + rd(days=+1) for holiday in [ easter_friday, easter_saturday, diff --git a/test/countries/test_canada.py b/test/countries/test_canada.py index 12253a6a1..ee2519f08 100644 --- a/test/countries/test_canada.py +++ b/test/countries/test_canada.py @@ -12,7 +12,7 @@ import unittest from datetime import date -from dateutil.relativedelta import relativedelta +from dateutil.relativedelta import relativedelta as rd import holidays @@ -34,8 +34,8 @@ def test_new_years(self): for year in range(1900, 2100): dt = date(year, 1, 1) self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) def test_islander_day(self): pei_holidays = holidays.CA(subdiv="PE") @@ -55,8 +55,8 @@ def test_islander_day(self): elif dt.year == 2009: self.assertNotIn(dt, self.holidays) self.assertIn(dt, pei_holidays) - self.assertNotIn(dt + relativedelta(days=-1), pei_holidays) - self.assertNotIn(dt + relativedelta(days=+1), pei_holidays) + self.assertNotIn(dt + rd(days=-1), pei_holidays) + self.assertNotIn(dt + rd(days=+1), pei_holidays) def test_yukon_heritage_day(self): # https://www.timeanddate.com/holidays/canada/heritage-day-yukon @@ -70,8 +70,8 @@ def test_yukon_heritage_day(self): date(2022, 2, 25), ]: self.assertIn(dt, yt_holidays) - self.assertNotIn(dt + relativedelta(days=-1), yt_holidays) - self.assertNotIn(dt + relativedelta(days=+1), yt_holidays) + self.assertNotIn(dt + rd(days=-1), yt_holidays) + self.assertNotIn(dt + rd(days=+1), yt_holidays) def test_family_day(self): ab_holidays = holidays.CA(subdiv="AB") @@ -140,8 +140,8 @@ def test_st_patricks_day(self): ]: self.assertNotIn(dt, self.holidays) self.assertIn(dt, nl_holidays) - self.assertNotIn(dt + relativedelta(days=-1), nl_holidays) - self.assertNotIn(dt + relativedelta(days=+1), nl_holidays) + self.assertNotIn(dt + rd(days=-1), nl_holidays) + self.assertNotIn(dt + rd(days=+1), nl_holidays) def test_good_friday(self): for dt in [ @@ -156,8 +156,8 @@ def test_good_friday(self): date(2020, 4, 10), ]: self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) def test_easter_monday(self): for dt in [ @@ -172,8 +172,8 @@ def test_easter_monday(self): date(2020, 4, 13), ]: self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) def test_st_georges_day(self): nl_holidays = holidays.CA(subdiv="NL") @@ -186,8 +186,8 @@ def test_st_georges_day(self): ]: self.assertNotIn(dt, self.holidays) self.assertIn(dt, nl_holidays) - self.assertNotIn(dt + relativedelta(days=-1), nl_holidays) - self.assertNotIn(dt + relativedelta(days=+1), nl_holidays) + self.assertNotIn(dt + rd(days=-1), nl_holidays) + self.assertNotIn(dt + rd(days=+1), nl_holidays) def test_victoria_day(self): for dt in [ @@ -199,8 +199,8 @@ def test_victoria_day(self): date(2020, 5, 18), ]: self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) def test_national_aboriginal_day(self): nt_holidays = holidays.CA(subdiv="NT") @@ -209,8 +209,8 @@ def test_national_aboriginal_day(self): dt = date(year, 6, 21) self.assertNotIn(dt, self.holidays) self.assertIn(dt, nt_holidays) - self.assertNotIn(dt + relativedelta(days=-1), nt_holidays) - self.assertNotIn(dt + relativedelta(days=+1), nt_holidays) + self.assertNotIn(dt + rd(days=-1), nt_holidays) + self.assertNotIn(dt + rd(days=+1), nt_holidays) def test_st_jean_baptiste_day(self): qc_holidays = holidays.CA(subdiv="QC", observed=False) @@ -219,8 +219,8 @@ def test_st_jean_baptiste_day(self): dt = date(year, 6, 24) self.assertNotIn(dt, self.holidays) self.assertIn(dt, qc_holidays) - self.assertNotIn(dt + relativedelta(days=-1), qc_holidays) - self.assertNotIn(dt + relativedelta(days=+1), qc_holidays) + self.assertNotIn(dt + rd(days=-1), qc_holidays) + self.assertNotIn(dt + rd(days=+1), qc_holidays) self.assertNotIn(date(2001, 6, 25), qc_holidays) qc_holidays.observed = True self.assertIn(date(2001, 6, 25), qc_holidays) @@ -255,8 +255,8 @@ def test_canada_day(self): for year in range(1900, 2100): dt = date(year, 7, 1) self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) self.assertNotIn(date(2006, 7, 3), self.holidays) self.assertNotIn(date(2007, 7, 2), self.holidays) self.holidays.observed = True @@ -272,8 +272,8 @@ def test_nunavut_day(self): dt = date(year, 7, 9) self.assertNotIn(dt, self.holidays) self.assertIn(dt, nu_holidays) - self.assertNotIn(dt + relativedelta(days=-1), nu_holidays) - self.assertNotIn(dt + relativedelta(days=+1), nu_holidays) + self.assertNotIn(dt + rd(days=-1), nu_holidays) + self.assertNotIn(dt + rd(days=+1), nu_holidays) self.assertNotIn(date(2017, 7, 10), nu_holidays) nu_holidays.observed = True self.assertIn(date(2017, 7, 10), nu_holidays) @@ -305,8 +305,8 @@ def test_labour_day(self): date(2015, 9, 7), ]: self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) def test_national_day_for_truth_and_reconciliation(self): for dt in [ @@ -314,14 +314,14 @@ def test_national_day_for_truth_and_reconciliation(self): date(2020, 9, 30), ]: self.assertNotIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) mb_holidays = holidays.CA(subdiv="MB") for dt in [ date(2021, 9, 30), date(2030, 9, 30), ]: self.assertIn(dt, mb_holidays) - self.assertNotIn(dt + relativedelta(days=-1), mb_holidays) + self.assertNotIn(dt + rd(days=-1), mb_holidays) self.assertNotIn(dt, self.holidays) def test_thanksgiving(self): @@ -335,8 +335,8 @@ def test_thanksgiving(self): date(2020, 10, 12), ]: self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) self.assertNotIn(dt, ns_holidays) def test_remembrance_day(self): @@ -349,8 +349,8 @@ def test_remembrance_day(self): self.assertNotIn(dt, self.holidays) self.assertIn(dt, ab_holidays) self.assertIn(dt, nl_holidays) - self.assertNotIn(dt + relativedelta(days=-1), nl_holidays) - self.assertNotIn(dt + relativedelta(days=+1), nl_holidays) + self.assertNotIn(dt + rd(days=-1), nl_holidays) + self.assertNotIn(dt + rd(days=+1), nl_holidays) self.assertNotIn(date(2007, 11, 12), ab_holidays) self.assertNotIn(date(2007, 11, 12), nl_holidays) ab_holidays.observed = True @@ -363,7 +363,7 @@ def test_christmas_day(self): for year in range(1900, 2100): dt = date(year, 12, 25) self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) self.assertNotIn(date(2010, 12, 27), self.holidays) self.assertNotEqual( self.holidays[date(2011, 12, 26)], "Christmas Day (Observed)" @@ -378,7 +378,7 @@ def test_boxing_day(self): for year in range(1900, 2100): dt = date(year, 12, 26) self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) self.assertNotIn(date(2009, 12, 28), self.holidays) self.assertNotIn(date(2010, 12, 27), self.holidays) self.holidays.observed = True diff --git a/test/countries/test_colombia.py b/test/countries/test_colombia.py index b16c98daf..f336a4f5f 100644 --- a/test/countries/test_colombia.py +++ b/test/countries/test_colombia.py @@ -10,7 +10,9 @@ # License: MIT (see LICENSE file) import unittest -from datetime import date, timedelta +from datetime import date + +from dateutil.relativedelta import relativedelta as rd import holidays from holidays.constants import APR, AUG, DEC, JAN, JUL, JUN, MAR, MAY, NOV, OCT @@ -23,7 +25,7 @@ def setUp(self): def _check_all_dates(self, year, expected_holidays): start_date = date(year, 1, 1) end_date = date(year, 12, 31) - delta = timedelta(days=1) + delta = rd(days=+1) while start_date <= end_date: if start_date in expected_holidays: diff --git a/test/countries/test_cuba.py b/test/countries/test_cuba.py index 37f0810e6..d2b415c15 100644 --- a/test/countries/test_cuba.py +++ b/test/countries/test_cuba.py @@ -10,7 +10,9 @@ # License: MIT (see LICENSE file) import unittest -from datetime import date, timedelta +from datetime import date + +from dateutil.relativedelta import relativedelta as rd import holidays from holidays.constants import APR, DEC, JAN, JUL, MAR, MAY, OCT @@ -23,7 +25,7 @@ def setUp(self): def _check_all_dates(self, year, expected_holidays): start_date = date(year, 1, 1) end_date = date(year, 12, 31) - delta = timedelta(days=1) + delta = rd(days=+1) while start_date <= end_date: if start_date in expected_holidays: diff --git a/test/countries/test_ireland.py b/test/countries/test_ireland.py index 067c08863..0bd3d7e4d 100644 --- a/test/countries/test_ireland.py +++ b/test/countries/test_ireland.py @@ -12,7 +12,7 @@ import unittest from datetime import date -from dateutil.relativedelta import relativedelta +from dateutil.relativedelta import relativedelta as rd import holidays @@ -49,8 +49,8 @@ def test_may_day(self): date(2020, 5, 4), ]: self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) def test_st_stephens_day(self): # St. Stephen's Day @@ -59,7 +59,7 @@ def test_st_stephens_day(self): for year in range(1900, 2100): dt = date(year, 12, 26) self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) self.assertNotIn(date(2009, 12, 28), self.holidays) self.assertNotIn(date(2010, 12, 27), self.holidays) self.holidays.observed = True diff --git a/test/countries/test_israel.py b/test/countries/test_israel.py index fa23f1214..c1b51c2f5 100644 --- a/test/countries/test_israel.py +++ b/test/countries/test_israel.py @@ -12,7 +12,7 @@ import unittest from datetime import date -from dateutil.relativedelta import relativedelta +from dateutil.relativedelta import relativedelta as rd import holidays @@ -42,12 +42,8 @@ def _test_observed_holidays(self, holiday_name): # Postponed il_holidays = holidays.IL(years=[2017], observed=True) - official_memorial_day = date(2017, 4, 30) + relativedelta( - days=days_delta - ) - observed_memorial_day = date(2017, 5, 1) + relativedelta( - days=days_delta - ) + official_memorial_day = date(2017, 4, 30) + rd(days=days_delta) + observed_memorial_day = date(2017, 5, 1) + rd(days=days_delta) self.assertIn(official_memorial_day, il_holidays) self.assertIn(holiday_name, il_holidays[official_memorial_day]) self.assertIn(observed_memorial_day, il_holidays) @@ -57,12 +53,8 @@ def _test_observed_holidays(self, holiday_name): # Earlier il_holidays = holidays.IL(years=[2018], observed=True) - official_memorial_day = date(2018, 4, 19) + relativedelta( - days=days_delta - ) - observed_memorial_day = date(2018, 4, 18) + relativedelta( - days=days_delta - ) + official_memorial_day = date(2018, 4, 19) + rd(days=days_delta) + observed_memorial_day = date(2018, 4, 18) + rd(days=days_delta) self.assertIn(official_memorial_day, il_holidays) self.assertIn(holiday_name, il_holidays[official_memorial_day]) self.assertIn(observed_memorial_day, il_holidays) @@ -72,9 +64,7 @@ def _test_observed_holidays(self, holiday_name): # On time il_holidays = holidays.IL(years=[2020], observed=True) - official_memorial_day = date(2020, 4, 28) + relativedelta( - days=days_delta - ) + official_memorial_day = date(2020, 4, 28) + rd(days=days_delta) self.assertIn(official_memorial_day, il_holidays) self.assertIn(holiday_name, il_holidays[official_memorial_day]) @@ -86,33 +76,23 @@ def _test_nonobserved_holidays(self, holiday_name): # Postponed il_holidays = holidays.IL(years=[2017], observed=False) - official_memorial_day = date(2017, 4, 30) + relativedelta( - days=days_delta - ) - observed_memorial_day = date(2017, 5, 1) + relativedelta( - days=days_delta - ) + official_memorial_day = date(2017, 4, 30) + rd(days=days_delta) + observed_memorial_day = date(2017, 5, 1) + rd(days=days_delta) self.assertIn(official_memorial_day, il_holidays) self.assertIn(holiday_name, il_holidays[official_memorial_day]) self.assertNotEqual(il_holidays[observed_memorial_day], "Memorial Day") # Earlier il_holidays = holidays.IL(years=[2018], observed=False) - official_memorial_day = date(2018, 4, 19) + relativedelta( - days=days_delta - ) - observed_memorial_day = date(2018, 4, 18) + relativedelta( - days=days_delta - ) + official_memorial_day = date(2018, 4, 19) + rd(days=days_delta) + observed_memorial_day = date(2018, 4, 18) + rd(days=days_delta) self.assertIn(official_memorial_day, il_holidays) self.assertIn(holiday_name, il_holidays[official_memorial_day]) self.assertNotIn(observed_memorial_day, il_holidays) # On time il_holidays = holidays.IL(years=[2020], observed=False) - official_memorial_day = date(2020, 4, 28) + relativedelta( - days=days_delta - ) + official_memorial_day = date(2020, 4, 28) + rd(days=days_delta) self.assertIn(official_memorial_day, il_holidays) self.assertIn(holiday_name, il_holidays[official_memorial_day]) diff --git a/test/countries/test_mexico.py b/test/countries/test_mexico.py index e1435fe16..51029192c 100644 --- a/test/countries/test_mexico.py +++ b/test/countries/test_mexico.py @@ -12,7 +12,7 @@ import unittest from datetime import date -from dateutil.relativedelta import relativedelta +from dateutil.relativedelta import relativedelta as rd import holidays @@ -31,8 +31,8 @@ def test_new_years(self): for year in range(1900, 2100): dt = date(year, 1, 1) self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) def test_constitution_day(self): for dt in [ @@ -48,8 +48,8 @@ def test_constitution_day(self): date(2022, 2, 5), ]: self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) self.holidays.observed = True for dt in [ date(2005, 2, 5), @@ -89,8 +89,8 @@ def test_benito_juarez(self): date(2024, 3, 21), ]: self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) self.holidays.observed = True for dt in [ date(2005, 3, 21), @@ -130,8 +130,8 @@ def test_labor_day(self): for year in range(1923, 2100): dt = date(year, 5, 1) self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) def test_independence_day(self): self.assertNotIn(date(2006, 9, 15), self.holidays) @@ -143,8 +143,8 @@ def test_independence_day(self): for year in range(1900, 2100): dt = date(year, 9, 16) self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) def test_revolution_day(self): for dt in [ @@ -162,8 +162,8 @@ def test_revolution_day(self): date(2023, 11, 20), ]: self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) self.holidays.observed = True for dt in [ date(2005, 11, 20), @@ -190,8 +190,8 @@ def test_change_of_government(self): dt = date(year, 12, 1) if (year >= 1970) and ((2096 - year) % 6) == 0: self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) else: self.assertNotIn(dt, self.holidays) @@ -199,8 +199,8 @@ def test_christmas(self): for year in range(1900, 2100): dt = date(year, 12, 25) self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) self.assertNotIn(date(2010, 12, 24), self.holidays) self.assertNotIn(date(2016, 12, 26), self.holidays) self.holidays.observed = True diff --git a/test/countries/test_new_zealand.py b/test/countries/test_new_zealand.py index 09281a266..c1c62fd9d 100644 --- a/test/countries/test_new_zealand.py +++ b/test/countries/test_new_zealand.py @@ -12,7 +12,7 @@ import unittest from datetime import date -from dateutil.relativedelta import relativedelta +from dateutil.relativedelta import relativedelta as rd import holidays @@ -150,8 +150,8 @@ def test_good_friday(self): date(2020, 4, 10), ]: self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) def test_easter_monday(self): for dt in [ @@ -165,8 +165,8 @@ def test_easter_monday(self): date(2020, 4, 13), ]: self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) def test_anzac_day(self): for year in range(1900, 1921): @@ -284,8 +284,8 @@ def test_matariki(self): ]: self.assertIn(dt, self.holidays) self.assertEqual(self.holidays[dt], "Matariki") - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) def test_labour_day(self): for year, day in enumerate( @@ -323,7 +323,7 @@ def test_christmas_day(self): for year in range(1900, 2100): dt = date(year, 12, 25) self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) self.assertNotIn(date(2010, 12, 24), self.holidays) self.assertNotEqual( self.holidays[date(2011, 12, 26)], "Christmas Day (Observed)" @@ -367,7 +367,7 @@ def test_boxing_day(self): for year in range(1900, 2100): dt = date(year, 12, 26) self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) self.assertNotIn(date(2009, 12, 28), self.holidays) self.assertNotIn(date(2010, 12, 27), self.holidays) self.holidays.observed = True diff --git a/test/countries/test_paraguay.py b/test/countries/test_paraguay.py index 14eea4f12..b25809422 100644 --- a/test/countries/test_paraguay.py +++ b/test/countries/test_paraguay.py @@ -10,7 +10,9 @@ # License: MIT (see LICENSE file) import unittest -from datetime import date, timedelta +from datetime import date + +from dateutil.relativedelta import relativedelta as rd import holidays @@ -152,7 +154,7 @@ def test_easter(self): (2022, 4, 17), ]: easter = date(year, month, day) - easter_thursday = easter - timedelta(days=3) - easter_friday = easter - timedelta(days=2) + easter_thursday = easter + rd(days=-3) + easter_friday = easter + rd(days=-2) for holiday in [easter_thursday, easter_friday, easter]: self.assertIn(holiday, self.holidays) diff --git a/test/countries/test_united_kingdom.py b/test/countries/test_united_kingdom.py index b1e516958..8a019dafd 100644 --- a/test/countries/test_united_kingdom.py +++ b/test/countries/test_united_kingdom.py @@ -12,7 +12,7 @@ import unittest from datetime import date -from dateutil.relativedelta import relativedelta +from dateutil.relativedelta import relativedelta as rd import holidays @@ -44,9 +44,9 @@ def test_new_years(self): dt = date(year, 1, 1) self.assertIn(dt, self.holidays) if year == 2000: - self.assertIn(dt + relativedelta(days=-1), self.holidays) + self.assertIn(dt + rd(days=-1), self.holidays) else: - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) def test_good_friday(self): for dt in [ @@ -61,8 +61,8 @@ def test_good_friday(self): date(2020, 4, 10), ]: self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) def test_easter_monday(self): for dt in [ @@ -77,14 +77,14 @@ def test_easter_monday(self): date(2020, 4, 13), ]: self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) def test_royal_weddings(self): for dt in [date(1981, 7, 29), date(2011, 4, 29)]: self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(years=-1), self.holidays) - self.assertNotIn(dt + relativedelta(years=+1), self.holidays) + self.assertNotIn(dt + rd(years=-1), self.holidays) + self.assertNotIn(dt + rd(years=+1), self.holidays) def test_queens_jubilees(self): for dt in [ @@ -94,16 +94,16 @@ def test_queens_jubilees(self): date(2022, 6, 3), ]: self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(years=-1), self.holidays) - self.assertNotIn(dt + relativedelta(years=+1), self.holidays) + self.assertNotIn(dt + rd(years=-1), self.holidays) + self.assertNotIn(dt + rd(years=+1), self.holidays) def test_royal_funerals(self): for dt in [ date(2022, 9, 19), ]: self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(years=-1), self.holidays) - self.assertNotIn(dt + relativedelta(years=+1), self.holidays) + self.assertNotIn(dt + rd(years=-1), self.holidays) + self.assertNotIn(dt + rd(years=+1), self.holidays) def test_may_day(self): for dt in [ @@ -119,8 +119,8 @@ def test_may_day(self): date(2020, 5, 8), ]: self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) self.assertNotIn(date(2020, 5, 4), self.holidays) def test_spring_bank_holiday(self): @@ -137,16 +137,16 @@ def test_spring_bank_holiday(self): date(2022, 6, 2), ]: self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) if dt != date(2022, 6, 2): - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) def test_christmas_day(self): self.holidays.observed = False for year in range(1900, 2100): dt = date(year, 12, 25) self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) self.assertNotIn(date(2010, 12, 24), self.holidays) self.assertNotEqual( self.holidays[date(2011, 12, 26)], "Christmas Day (Observed)" @@ -191,7 +191,7 @@ def test_boxing_day(self): for year in range(1900, 2100): dt = date(year, 12, 26) self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) self.assertNotIn(date(2009, 12, 28), self.holidays) self.assertNotIn(date(2010, 12, 27), self.holidays) self.holidays.observed = True diff --git a/test/countries/test_united_states.py b/test/countries/test_united_states.py index bd0cb846b..58d6a087a 100644 --- a/test/countries/test_united_states.py +++ b/test/countries/test_united_states.py @@ -12,7 +12,7 @@ import unittest from datetime import date -from dateutil.relativedelta import relativedelta +from dateutil.relativedelta import relativedelta as rd import holidays from holidays.constants import SAT, SUN @@ -32,8 +32,8 @@ def test_new_years(self): for year in range(1900, 2100): dt = date(year, 1, 1) self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) def test_Juneteenth_day(self): @@ -120,8 +120,8 @@ def test_martin_luther(self): date(2020, 1, 20), ]: self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) self.assertNotIn( "Martin Luther King Jr. Day", holidays.US(years=[1985]).values() ) @@ -288,8 +288,8 @@ def test_washingtons_birthday(self): date(2020, 2, 17), ]: self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) self.assertNotIn(dt, de_holidays) self.assertNotEqual(fl_holidays.get(dt), "Washington's Birthday") self.assertNotIn(dt, ga_holidays) @@ -622,8 +622,8 @@ def test_truman_day(self): dt = date(year, 5, 8) self.assertNotIn(dt, self.holidays) self.assertIn(dt, mo_holidays) - self.assertNotIn(dt + relativedelta(days=-1), mo_holidays) - self.assertNotIn(dt + relativedelta(days=+1), mo_holidays) + self.assertNotIn(dt + rd(days=-1), mo_holidays) + self.assertNotIn(dt + rd(days=+1), mo_holidays) self.assertNotIn(date(2004, 5, 7), mo_holidays) self.assertNotIn(date(2005, 5, 9), mo_holidays) mo_holidays.observed = True @@ -646,8 +646,8 @@ def test_memorial_day(self): date(2020, 5, 25), ]: self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) def test_jefferson_davis_birthday(self): al_holidays = holidays.US(subdiv="AL") @@ -726,8 +726,8 @@ def test_independence_day(self): for year in range(1900, 2100): dt = date(year, 7, 4) self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) self.assertNotIn(date(2010, 7, 5), self.holidays) self.assertNotIn(date(2020, 7, 3), self.holidays) self.holidays.observed = True @@ -843,8 +843,8 @@ def test_labor_day(self): date(2020, 9, 7), ]: self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) def test_columbus_day(self): ak_holidays = holidays.US(subdiv="AK") @@ -869,8 +869,8 @@ def test_columbus_day(self): self.assertNotIn(dt, de_holidays) self.assertNotIn(dt, fl_holidays) self.assertNotIn(dt, hi_holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) self.assertEqual(sd_holidays.get(dt), "Native American Day") self.assertEqual( vi_holidays.get(dt), @@ -988,8 +988,8 @@ def test_veterans_day(self): date(2020, 11, 11), ]: self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) self.assertNotIn("Armistice Day", holidays.US(years=[1937]).values()) self.assertNotIn("Armistice Day", holidays.US(years=[1937]).values()) self.assertIn("Armistice Day", holidays.US(years=[1938]).values()) @@ -1036,66 +1036,64 @@ def test_thanksgiving_day(self): date(2020, 11, 26), ]: self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) - self.assertIn(dt + relativedelta(days=+1), de_holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) + self.assertIn(dt + rd(days=+1), de_holidays) self.assertEqual( - ca_holidays.get(dt + relativedelta(days=+1)), + ca_holidays.get(dt + rd(days=+1)), "Day After Thanksgiving", ) self.assertEqual( - de_holidays.get(dt + relativedelta(days=+1)), + de_holidays.get(dt + rd(days=+1)), "Day After Thanksgiving", ) self.assertEqual( - nh_holidays.get(dt + relativedelta(days=+1)), + nh_holidays.get(dt + rd(days=+1)), "Day After Thanksgiving", ) self.assertEqual( - nc_holidays.get(dt + relativedelta(days=+1)), + nc_holidays.get(dt + rd(days=+1)), "Day After Thanksgiving", ) self.assertEqual( - ok_holidays.get(dt + relativedelta(days=+1)), + ok_holidays.get(dt + rd(days=+1)), "Day After Thanksgiving", ) self.assertEqual( - pa_holidays.get(dt + relativedelta(days=+1)), + pa_holidays.get(dt + rd(days=+1)), "Day After Thanksgiving", ) self.assertEqual( - wv_holidays.get(dt + relativedelta(days=+1)), + wv_holidays.get(dt + rd(days=+1)), "Day After Thanksgiving", ) - self.assertIn(dt + relativedelta(days=+1), fl_holidays) + self.assertIn(dt + rd(days=+1), fl_holidays) self.assertEqual( - fl_holidays.get(dt + relativedelta(days=+1)), + fl_holidays.get(dt + rd(days=+1)), "Friday After Thanksgiving", ) - self.assertIn(dt + relativedelta(days=+1), tx_holidays) + self.assertIn(dt + rd(days=+1), tx_holidays) self.assertEqual( - tx_holidays.get(dt + relativedelta(days=+1)), + tx_holidays.get(dt + rd(days=+1)), "Friday After Thanksgiving", ) + self.assertEqual(nv_holidays.get(dt + rd(days=+1)), "Family Day") self.assertEqual( - nv_holidays.get(dt + relativedelta(days=+1)), "Family Day" - ) - self.assertEqual( - nm_holidays.get(dt + relativedelta(days=+1)), "Presidents' Day" + nm_holidays.get(dt + rd(days=+1)), "Presidents' Day" ) if dt.year >= 2008: self.assertEqual( - md_holidays.get(dt + relativedelta(days=1)), + md_holidays.get(dt + rd(days=+1)), "American Indian Heritage Day", ) if dt.year >= 2010: self.assertEqual( - in_holidays.get(dt + relativedelta(days=1)), + in_holidays.get(dt + rd(days=+1)), "Lincoln's Birthday", ) else: self.assertNotEqual( - in_holidays.get(dt + relativedelta(days=1)), + in_holidays.get(dt + rd(days=+1)), "Lincoln's Birthday", ) @@ -1192,8 +1190,8 @@ def test_christmas_day(self): for year in range(1900, 2100): dt = date(year, 12, 25) self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) self.assertNotIn(date(2010, 12, 24), self.holidays) self.assertNotIn(date(2016, 12, 26), self.holidays) self.holidays.observed = True diff --git a/test/countries/test_uruguay.py b/test/countries/test_uruguay.py index 825c36267..e3d8c0d37 100644 --- a/test/countries/test_uruguay.py +++ b/test/countries/test_uruguay.py @@ -12,7 +12,7 @@ import unittest from datetime import date -from dateutil.relativedelta import relativedelta +from dateutil.relativedelta import relativedelta as rd import holidays @@ -32,8 +32,8 @@ def test_new_years(self): for year in range(1900, 2100): dt = date(year, 1, 1) self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) self.assertEqual(self.holidays[dt], "Año Nuevo [New Year's Day]") def test_labor_day(self): @@ -45,8 +45,8 @@ def test_labor_day(self): for year in range(1900, 2100): dt = date(year, 5, 1) self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) self.assertEqual( self.holidays[dt], "Día de los Trabajadores [International Workers' Day]", @@ -56,8 +56,8 @@ def test_jura_de_la_constitucion_day(self): for year in range(1900, 2100): dt = date(year, 7, 18) self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) self.assertEqual( self.holidays[dt], "Jura de la Constitución [Constitution Day]" ) @@ -66,8 +66,8 @@ def test_declaratoria_de_la_independencia_day(self): for year in range(1900, 2100): dt = date(year, 8, 25) self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) self.assertEqual( self.holidays[dt], "Día de la Independencia [Independence Day]" ) @@ -76,8 +76,8 @@ def test_christmas(self): for year in range(1900, 2100): dt = date(year, 12, 25) self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) self.assertEqual( self.holidays[dt], "Día de la Familia [Day of the Family]" ) @@ -97,8 +97,8 @@ def test_natalicio_artigas_day(self): for year in range(1900, 2100): dt = date(year, 6, 19) self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) self.assertEqual( self.holidays[dt], "Natalicio de José Gervasio Artigas " @@ -109,8 +109,8 @@ def test_dia_de_los_difuntos_day(self): for year in range(1900, 2100): dt = date(year, 11, 2) self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) self.assertEqual( self.holidays[dt], "Día de los Difuntos [All Souls' Day]" ) diff --git a/test/countries/test_venezuela.py b/test/countries/test_venezuela.py index 515840dea..b9bb5068c 100644 --- a/test/countries/test_venezuela.py +++ b/test/countries/test_venezuela.py @@ -10,7 +10,9 @@ # License: MIT (see LICENSE file) import unittest -from datetime import date, timedelta +from datetime import date + +from dateutil.relativedelta import relativedelta as rd import holidays from holidays.constants import JAN, FEB, MAR, APR, MAY, JUN, JUL, OCT, DEC @@ -23,7 +25,7 @@ def setUp(self): def _check_all_dates(self, year, expected_holidays): start_date = date(year, 1, 1) end_date = date(year, 12, 31) - delta = timedelta(days=1) + delta = rd(days=+1) while start_date <= end_date: if start_date in expected_holidays: diff --git a/test/countries/test_vietnam.py b/test/countries/test_vietnam.py index 66612c194..99da392bd 100644 --- a/test/countries/test_vietnam.py +++ b/test/countries/test_vietnam.py @@ -12,7 +12,7 @@ import unittest from datetime import date -from dateutil.relativedelta import relativedelta +from dateutil.relativedelta import relativedelta as rd import holidays @@ -51,27 +51,27 @@ def test_lunar_new_year(self): (2022, 2, 1), ): self.assertEqual( - self.holidays[date(year, month, day) + relativedelta(days=-1)], + self.holidays[date(year, month, day) + rd(days=-1)], "Vietnamese New Year's Eve", ) self.assertEqual( - self.holidays[date(year, month, day) + relativedelta(days=0)], + self.holidays[date(year, month, day)], "Vietnamese New Year", ) self.assertEqual( - self.holidays[date(year, month, day) + relativedelta(days=+1)], + self.holidays[date(year, month, day) + rd(days=+1)], "The second day of Tet Holiday", ) self.assertEqual( - self.holidays[date(year, month, day) + relativedelta(days=+2)], + self.holidays[date(year, month, day) + rd(days=+2)], "The third day of Tet Holiday", ) self.assertEqual( - self.holidays[date(year, month, day) + relativedelta(days=+3)], + self.holidays[date(year, month, day) + rd(days=+3)], "The forth day of Tet Holiday", ) self.assertEqual( - self.holidays[date(year, month, day) + relativedelta(days=+4)], + self.holidays[date(year, month, day) + rd(days=+4)], "The fifth day of Tet Holiday", ) diff --git a/test/financial/test_european_central_bank.py b/test/financial/test_european_central_bank.py index 65ea5c269..bd4834461 100644 --- a/test/financial/test_european_central_bank.py +++ b/test/financial/test_european_central_bank.py @@ -12,7 +12,7 @@ import unittest from datetime import date -from dateutil.relativedelta import relativedelta +from dateutil.relativedelta import relativedelta as rd import holidays @@ -25,7 +25,7 @@ def test_new_years(self): for year in range(1974, 2100): dt = date(year, 1, 1) self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) def test_good_friday(self): for dt in [ @@ -40,8 +40,8 @@ def test_good_friday(self): date(2020, 4, 10), ]: self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) def test_easter_monday(self): for dt in [ @@ -56,27 +56,27 @@ def test_easter_monday(self): date(2020, 4, 13), ]: self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) def test_labour_day(self): for year in range(1900, 2100): dt = date(year, 5, 1) self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) def test_christmas_day(self): for year in range(1900, 2100): dt = date(year, 12, 25) self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) def test_26_december_day(self): for year in range(1900, 2100): dt = date(year, 12, 26) self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) def test_all_holidays_present(self): tar_2015 = holidays.TAR(years=[2015]) diff --git a/test/financial/test_ny_stock_exchange.py b/test/financial/test_ny_stock_exchange.py index 9c55091cc..f130bb206 100644 --- a/test/financial/test_ny_stock_exchange.py +++ b/test/financial/test_ny_stock_exchange.py @@ -10,7 +10,7 @@ # License: MIT (see LICENSE file) import unittest -from datetime import date, timedelta +from datetime import date from dateutil.relativedelta import WE from dateutil.relativedelta import relativedelta as rd @@ -420,8 +420,7 @@ def test_special_holidays(self): def _make_special_holiday_list(begin, end, days=None, weekends=False): _list = [] for d in ( - begin + timedelta(days=n) - for n in range((end - begin).days + 1) + begin + rd(days=n) for n in range((end - begin).days + 1) ): if not weekends and d.weekday() in {SAT, SUN}: continue @@ -454,14 +453,14 @@ def _make_special_holiday_list(begin, end, days=None, weekends=False): date(1968, JUN, 12), # begin paper crisis holidays ]: self.assertIn(dt, self.holidays) - self.assertNotIn(dt - timedelta(days=1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) for dt in [ date(1914, NOV, 27), # end WWI holidays date(1933, MAR, 14), # end oneoff bank holidays ]: self.assertIn(dt, self.holidays) - self.assertNotIn(dt + timedelta(days=1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) def test_all_modern_holidays_present(self): nyse_2021 = holidays.NewYorkStockExchange(years=[2021]) From ede74f4b763525aa3c7d4f9f538826fe9517eac3 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 13 Jan 2023 22:00:34 +0000 Subject: [PATCH 117/138] Bump actions/setup-python from 4.4.0 to 4.5.0 Bumps [actions/setup-python](https://github.com/actions/setup-python) from 4.4.0 to 4.5.0. - [Release notes](https://github.com/actions/setup-python/releases) - [Commits](https://github.com/actions/setup-python/compare/v4.4.0...v4.5.0) --- updated-dependencies: - dependency-name: actions/setup-python dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- .github/workflows/ci-cd.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml index d99560a66..409008369 100644 --- a/.github/workflows/ci-cd.yml +++ b/.github/workflows/ci-cd.yml @@ -12,7 +12,7 @@ jobs: - name: Check out repo uses: actions/checkout@v3 - name: Set up Python - uses: actions/setup-python@v4.4.0 + uses: actions/setup-python@v4.5.0 - name: Run pre-commit uses: pre-commit/action@v3.0.0 @@ -28,7 +28,7 @@ jobs: steps: - uses: actions/checkout@v3 - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v4.4.0 + uses: actions/setup-python@v4.5.0 with: python-version: ${{ matrix.python-version }} cache: pip @@ -68,7 +68,7 @@ jobs: steps: - uses: actions/checkout@v3 - name: Set up Python 3.9 - uses: actions/setup-python@v4.4.0 + uses: actions/setup-python@v4.5.0 with: python-version: "3.10" - name: Install dependencies From 40a65ec910c25c6900aba3764a4ddbe0b7bc4dd6 Mon Sep 17 00:00:00 2001 From: dr-prodigy Date: Sun, 15 Jan 2023 14:18:41 +0100 Subject: [PATCH 118/138] v.0.18 beta init, copyright 2023, authors/maintainers update --- CHANGES | 8 ++++++++ LICENSE | 2 +- holidays/__init__.py | 4 ++-- holidays/constants.py | 2 +- holidays/countries/__init__.py | 2 +- holidays/countries/angola.py | 2 +- holidays/countries/argentina.py | 2 +- holidays/countries/armenia.py | 2 +- holidays/countries/aruba.py | 2 +- holidays/countries/australia.py | 2 +- holidays/countries/austria.py | 2 +- holidays/countries/azerbaijan.py | 2 +- holidays/countries/bangladesh.py | 2 +- holidays/countries/belarus.py | 2 +- holidays/countries/belgium.py | 2 +- holidays/countries/bolivia.py | 2 +- holidays/countries/bosnia_and_herzegovina.py | 2 +- holidays/countries/botswana.py | 2 +- holidays/countries/brazil.py | 2 +- holidays/countries/bulgaria.py | 2 +- holidays/countries/burundi.py | 2 +- holidays/countries/canada.py | 2 +- holidays/countries/chile.py | 2 +- holidays/countries/china.py | 2 +- holidays/countries/colombia.py | 2 +- holidays/countries/croatia.py | 2 +- holidays/countries/cuba.py | 2 +- holidays/countries/curacao.py | 2 +- holidays/countries/cyprus.py | 2 +- holidays/countries/czechia.py | 2 +- holidays/countries/denmark.py | 2 +- holidays/countries/djibouti.py | 2 +- holidays/countries/dominican_republic.py | 2 +- holidays/countries/egypt.py | 2 +- holidays/countries/estonia.py | 2 +- holidays/countries/eswatini.py | 2 +- holidays/countries/ethiopia.py | 2 +- holidays/countries/finland.py | 2 +- holidays/countries/france.py | 2 +- holidays/countries/georgia.py | 2 +- holidays/countries/germany.py | 2 +- holidays/countries/greece.py | 2 +- holidays/countries/honduras.py | 2 +- holidays/countries/hongkong.py | 2 +- holidays/countries/hungary.py | 2 +- holidays/countries/iceland.py | 2 +- holidays/countries/india.py | 2 +- holidays/countries/indonesia.py | 2 +- holidays/countries/ireland.py | 2 +- holidays/countries/isle_of_man.py | 2 +- holidays/countries/israel.py | 2 +- holidays/countries/italy.py | 2 +- holidays/countries/jamaica.py | 2 +- holidays/countries/japan.py | 2 +- holidays/countries/kazakhstan.py | 2 +- holidays/countries/kenya.py | 2 +- holidays/countries/latvia.py | 2 +- holidays/countries/lesotho.py | 2 +- holidays/countries/liechtenstein.py | 2 +- holidays/countries/lithuania.py | 2 +- holidays/countries/luxembourg.py | 2 +- holidays/countries/madagascar.py | 2 +- holidays/countries/malawi.py | 2 +- holidays/countries/malaysia.py | 2 +- holidays/countries/malta.py | 2 +- holidays/countries/mexico.py | 2 +- holidays/countries/moldova.py | 2 +- holidays/countries/morocco.py | 2 +- holidays/countries/mozambique.py | 2 +- holidays/countries/namibia.py | 2 +- holidays/countries/netherlands.py | 2 +- holidays/countries/new_zealand.py | 2 +- holidays/countries/nicaragua.py | 2 +- holidays/countries/nigeria.py | 2 +- holidays/countries/north_macedonia.py | 2 +- holidays/countries/norway.py | 2 +- holidays/countries/pakistan.py | 2 +- holidays/countries/paraguay.py | 2 +- holidays/countries/peru.py | 2 +- holidays/countries/poland.py | 2 +- holidays/countries/portugal.py | 2 +- holidays/countries/romania.py | 2 +- holidays/countries/russia.py | 2 +- holidays/countries/saudi_arabia.py | 2 +- holidays/countries/serbia.py | 2 +- holidays/countries/singapore.py | 2 +- holidays/countries/slovakia.py | 2 +- holidays/countries/slovenia.py | 2 +- holidays/countries/south_africa.py | 2 +- holidays/countries/south_korea.py | 2 +- holidays/countries/spain.py | 2 +- holidays/countries/sweden.py | 2 +- holidays/countries/switzerland.py | 2 +- holidays/countries/taiwan.py | 2 +- holidays/countries/tunisia.py | 2 +- holidays/countries/turkey.py | 2 +- holidays/countries/ukraine.py | 2 +- holidays/countries/united_arab_emirates.py | 2 +- holidays/countries/united_kingdom.py | 2 +- holidays/countries/united_states.py | 2 +- holidays/countries/uruguay.py | 2 +- holidays/countries/uzbekistan.py | 2 +- holidays/countries/venezuela.py | 2 +- holidays/countries/vietnam.py | 2 +- holidays/countries/zambia.py | 2 +- holidays/countries/zimbabwe.py | 2 +- holidays/financial/__init__.py | 2 +- holidays/financial/european_central_bank.py | 2 +- holidays/financial/ny_stock_exchange.py | 2 +- holidays/holiday_base.py | 2 +- holidays/utils.py | 2 +- setup.cfg | 8 +++++--- setup.py | 2 +- test/common.py | 2 +- test/countries/__init__.py | 2 +- test/countries/test_angola.py | 2 +- test/countries/test_argentina.py | 2 +- test/countries/test_armenia.py | 2 +- test/countries/test_aruba.py | 2 +- test/countries/test_australia.py | 2 +- test/countries/test_austria.py | 2 +- test/countries/test_azerbaijan.py | 2 +- test/countries/test_bangladesh.py | 2 +- test/countries/test_belarus.py | 2 +- test/countries/test_belgium.py | 2 +- test/countries/test_bolivia.py | 2 +- test/countries/test_bosnia_and_herzegovina.py | 2 +- test/countries/test_botswana.py | 2 +- test/countries/test_brazil.py | 2 +- test/countries/test_bulgaria.py | 2 +- test/countries/test_burundi.py | 2 +- test/countries/test_canada.py | 2 +- test/countries/test_chile.py | 2 +- test/countries/test_china.py | 2 +- test/countries/test_colombia.py | 2 +- test/countries/test_croatia.py | 2 +- test/countries/test_cuba.py | 2 +- test/countries/test_curacao.py | 2 +- test/countries/test_cyprus.py | 2 +- test/countries/test_czechia.py | 2 +- test/countries/test_denmark.py | 2 +- test/countries/test_djibouti.py | 2 +- test/countries/test_dominican_republic.py | 2 +- test/countries/test_egypt.py | 2 +- test/countries/test_estonia.py | 2 +- test/countries/test_eswatini.py | 2 +- test/countries/test_ethiopia.py | 2 +- test/countries/test_finland.py | 2 +- test/countries/test_france.py | 2 +- test/countries/test_georgia.py | 2 +- test/countries/test_germany.py | 2 +- test/countries/test_greece.py | 2 +- test/countries/test_honduras.py | 2 +- test/countries/test_hongkong.py | 2 +- test/countries/test_hungary.py | 2 +- test/countries/test_iceland.py | 2 +- test/countries/test_india.py | 2 +- test/countries/test_indonesia.py | 2 +- test/countries/test_ireland.py | 2 +- test/countries/test_isle_of_man.py | 2 +- test/countries/test_israel.py | 2 +- test/countries/test_italy.py | 2 +- test/countries/test_jamaica.py | 2 +- test/countries/test_japan.py | 2 +- test/countries/test_kazakhstan.py | 2 +- test/countries/test_kenya.py | 2 +- test/countries/test_latvia.py | 2 +- test/countries/test_lesotho.py | 2 +- test/countries/test_liechtenstein.py | 2 +- test/countries/test_lithuania.py | 2 +- test/countries/test_luxembourg.py | 2 +- test/countries/test_madagascar.py | 2 +- test/countries/test_malawi.py | 2 +- test/countries/test_malaysia.py | 2 +- test/countries/test_malta.py | 2 +- test/countries/test_mexico.py | 2 +- test/countries/test_moldova.py | 2 +- test/countries/test_morocco.py | 2 +- test/countries/test_mozambique.py | 2 +- test/countries/test_namibia.py | 2 +- test/countries/test_netherlands.py | 2 +- test/countries/test_new_zealand.py | 2 +- test/countries/test_nicaragua.py | 2 +- test/countries/test_nigeria.py | 2 +- test/countries/test_north_macedonia.py | 2 +- test/countries/test_norway.py | 2 +- test/countries/test_pakistan.py | 2 +- test/countries/test_paraguay.py | 2 +- test/countries/test_peru.py | 2 +- test/countries/test_poland.py | 2 +- test/countries/test_portugal.py | 2 +- test/countries/test_romania.py | 2 +- test/countries/test_russia.py | 2 +- test/countries/test_saudi_arabia.py | 2 +- test/countries/test_serbia.py | 2 +- test/countries/test_singapore.py | 2 +- test/countries/test_slovakia.py | 2 +- test/countries/test_slovenia.py | 2 +- test/countries/test_south_africa.py | 2 +- test/countries/test_south_korea.py | 2 +- test/countries/test_spain.py | 2 +- test/countries/test_sweden.py | 2 +- test/countries/test_switzerland.py | 2 +- test/countries/test_taiwan.py | 2 +- test/countries/test_tunisia.py | 2 +- test/countries/test_turkey.py | 2 +- test/countries/test_ukraine.py | 2 +- test/countries/test_united_arab_emirates.py | 2 +- test/countries/test_united_kingdom.py | 2 +- test/countries/test_united_states.py | 2 +- test/countries/test_uruguay.py | 2 +- test/countries/test_uzbekistan.py | 2 +- test/countries/test_venezuela.py | 2 +- test/countries/test_vietnam.py | 2 +- test/countries/test_zambia.py | 2 +- test/countries/test_zimbabwe.py | 2 +- test/financial/test_european_central_bank.py | 2 +- test/financial/test_ny_stock_exchange.py | 2 +- test/test_holiday_base.py | 2 +- test/test_imports.py | 2 +- 220 files changed, 232 insertions(+), 222 deletions(-) diff --git a/CHANGES b/CHANGES index eb1c2d243..aeb612383 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,11 @@ +Version 0.19 +============ + +Released ???????? ??, ???? + +- Copyright update 2023 +- Added Arkadii Yakovets (arkid15r) to project collaborators / maintainers - welcome! + Version 0.18 ============ diff --git a/LICENSE b/LICENSE index 17173584e..e0fe1cf91 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2017-2022 +Copyright (c) 2017-2023 Copyright (c) 2014-2017 Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/holidays/__init__.py b/holidays/__init__.py index bd54a97da..6055b3ede 100644 --- a/holidays/__init__.py +++ b/holidays/__init__.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) @@ -15,4 +15,4 @@ from holidays.holiday_base import * from holidays.utils import * -__version__ = "0.18" +__version__ = "0.19" diff --git a/holidays/constants.py b/holidays/constants.py index 795cbd306..43b490dfe 100644 --- a/holidays/constants.py +++ b/holidays/constants.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/countries/__init__.py b/holidays/countries/__init__.py index 8cb48c057..5d2183dde 100644 --- a/holidays/countries/__init__.py +++ b/holidays/countries/__init__.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/countries/angola.py b/holidays/countries/angola.py index 3b57a31c4..75783b98c 100644 --- a/holidays/countries/angola.py +++ b/holidays/countries/angola.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/countries/argentina.py b/holidays/countries/argentina.py index 21162bacf..539752993 100644 --- a/holidays/countries/argentina.py +++ b/holidays/countries/argentina.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/countries/armenia.py b/holidays/countries/armenia.py index 769870ed7..1c976fda9 100644 --- a/holidays/countries/armenia.py +++ b/holidays/countries/armenia.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/countries/aruba.py b/holidays/countries/aruba.py index 731fdb1ad..973031746 100644 --- a/holidays/countries/aruba.py +++ b/holidays/countries/aruba.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/countries/australia.py b/holidays/countries/australia.py index 096565f87..72fa5e3af 100644 --- a/holidays/countries/australia.py +++ b/holidays/countries/australia.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/countries/austria.py b/holidays/countries/austria.py index 8fb2bcfe7..18642800c 100644 --- a/holidays/countries/austria.py +++ b/holidays/countries/austria.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/countries/azerbaijan.py b/holidays/countries/azerbaijan.py index c57b0145a..792703c64 100644 --- a/holidays/countries/azerbaijan.py +++ b/holidays/countries/azerbaijan.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/countries/bangladesh.py b/holidays/countries/bangladesh.py index 0979693ba..e0ae05f36 100644 --- a/holidays/countries/bangladesh.py +++ b/holidays/countries/bangladesh.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # tasnim # Website: https://github.com/dr-prodigy/python-holidays diff --git a/holidays/countries/belarus.py b/holidays/countries/belarus.py index 348a7f2e0..ce04b3c98 100644 --- a/holidays/countries/belarus.py +++ b/holidays/countries/belarus.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/countries/belgium.py b/holidays/countries/belgium.py index bfcb0efb9..2c8ec200e 100644 --- a/holidays/countries/belgium.py +++ b/holidays/countries/belgium.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/countries/bolivia.py b/holidays/countries/bolivia.py index 0b18af564..b760dc395 100644 --- a/holidays/countries/bolivia.py +++ b/holidays/countries/bolivia.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/countries/bosnia_and_herzegovina.py b/holidays/countries/bosnia_and_herzegovina.py index 59abdcbbb..d299c6241 100644 --- a/holidays/countries/bosnia_and_herzegovina.py +++ b/holidays/countries/bosnia_and_herzegovina.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/countries/botswana.py b/holidays/countries/botswana.py index 6067e426c..75ca88d8d 100644 --- a/holidays/countries/botswana.py +++ b/holidays/countries/botswana.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/countries/brazil.py b/holidays/countries/brazil.py index 95315a324..00f9ecff6 100644 --- a/holidays/countries/brazil.py +++ b/holidays/countries/brazil.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/countries/bulgaria.py b/holidays/countries/bulgaria.py index aee2ca563..605ccf3fe 100644 --- a/holidays/countries/bulgaria.py +++ b/holidays/countries/bulgaria.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/countries/burundi.py b/holidays/countries/burundi.py index b0d5cfd81..fa2db3fab 100644 --- a/holidays/countries/burundi.py +++ b/holidays/countries/burundi.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/countries/canada.py b/holidays/countries/canada.py index f219620f9..1a09e1acf 100644 --- a/holidays/countries/canada.py +++ b/holidays/countries/canada.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/countries/chile.py b/holidays/countries/chile.py index 74902fa21..e144a33d8 100644 --- a/holidays/countries/chile.py +++ b/holidays/countries/chile.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/countries/china.py b/holidays/countries/china.py index f0ddef3b2..a0c0e2db7 100644 --- a/holidays/countries/china.py +++ b/holidays/countries/china.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/countries/colombia.py b/holidays/countries/colombia.py index e37ade1ca..6b4a9eaac 100644 --- a/holidays/countries/colombia.py +++ b/holidays/countries/colombia.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/countries/croatia.py b/holidays/countries/croatia.py index 137f0c139..4d023e6b5 100644 --- a/holidays/countries/croatia.py +++ b/holidays/countries/croatia.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/countries/cuba.py b/holidays/countries/cuba.py index 6c7f1da8a..d1312a988 100644 --- a/holidays/countries/cuba.py +++ b/holidays/countries/cuba.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/countries/curacao.py b/holidays/countries/curacao.py index 139e4a492..194e65aed 100644 --- a/holidays/countries/curacao.py +++ b/holidays/countries/curacao.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/countries/cyprus.py b/holidays/countries/cyprus.py index a0cc209e5..3f5650925 100644 --- a/holidays/countries/cyprus.py +++ b/holidays/countries/cyprus.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/countries/czechia.py b/holidays/countries/czechia.py index 90ee108ad..490758a38 100644 --- a/holidays/countries/czechia.py +++ b/holidays/countries/czechia.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/countries/denmark.py b/holidays/countries/denmark.py index df0ebcac8..a5e8d38b7 100644 --- a/holidays/countries/denmark.py +++ b/holidays/countries/denmark.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/countries/djibouti.py b/holidays/countries/djibouti.py index a299d5bd7..28a53e6c6 100644 --- a/holidays/countries/djibouti.py +++ b/holidays/countries/djibouti.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/countries/dominican_republic.py b/holidays/countries/dominican_republic.py index 64a314cd8..a12546d6c 100644 --- a/holidays/countries/dominican_republic.py +++ b/holidays/countries/dominican_republic.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/countries/egypt.py b/holidays/countries/egypt.py index 8ddc3990c..0758b9c87 100644 --- a/holidays/countries/egypt.py +++ b/holidays/countries/egypt.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/countries/estonia.py b/holidays/countries/estonia.py index af04edb91..d09056317 100644 --- a/holidays/countries/estonia.py +++ b/holidays/countries/estonia.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/countries/eswatini.py b/holidays/countries/eswatini.py index 6c9e22be9..f06c5a814 100644 --- a/holidays/countries/eswatini.py +++ b/holidays/countries/eswatini.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/countries/ethiopia.py b/holidays/countries/ethiopia.py index 16e329812..54fff8990 100644 --- a/holidays/countries/ethiopia.py +++ b/holidays/countries/ethiopia.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/countries/finland.py b/holidays/countries/finland.py index 0a9a8e650..156ad930c 100644 --- a/holidays/countries/finland.py +++ b/holidays/countries/finland.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/countries/france.py b/holidays/countries/france.py index 057b9db04..caed9a4a1 100644 --- a/holidays/countries/france.py +++ b/holidays/countries/france.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/countries/georgia.py b/holidays/countries/georgia.py index f223ece7d..8f668c1b9 100644 --- a/holidays/countries/georgia.py +++ b/holidays/countries/georgia.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/countries/germany.py b/holidays/countries/germany.py index 75b1b608a..e2599fb57 100644 --- a/holidays/countries/germany.py +++ b/holidays/countries/germany.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/countries/greece.py b/holidays/countries/greece.py index b85a2a61e..f206369ce 100644 --- a/holidays/countries/greece.py +++ b/holidays/countries/greece.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/countries/honduras.py b/holidays/countries/honduras.py index a163baec9..bc12512cb 100644 --- a/holidays/countries/honduras.py +++ b/holidays/countries/honduras.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/countries/hongkong.py b/holidays/countries/hongkong.py index 055e66cf8..19f0c8019 100644 --- a/holidays/countries/hongkong.py +++ b/holidays/countries/hongkong.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/countries/hungary.py b/holidays/countries/hungary.py index a594e7efe..101d765b9 100644 --- a/holidays/countries/hungary.py +++ b/holidays/countries/hungary.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/countries/iceland.py b/holidays/countries/iceland.py index c4f7019d1..ba581537b 100644 --- a/holidays/countries/iceland.py +++ b/holidays/countries/iceland.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/countries/india.py b/holidays/countries/india.py index 004bb7754..40ef3c6c1 100644 --- a/holidays/countries/india.py +++ b/holidays/countries/india.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/countries/indonesia.py b/holidays/countries/indonesia.py index c5ee8e0d2..e254ecc2e 100644 --- a/holidays/countries/indonesia.py +++ b/holidays/countries/indonesia.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/countries/ireland.py b/holidays/countries/ireland.py index b8a330ebe..4c9c3ea52 100644 --- a/holidays/countries/ireland.py +++ b/holidays/countries/ireland.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/countries/isle_of_man.py b/holidays/countries/isle_of_man.py index 30377dd6f..33ffa7ad1 100644 --- a/holidays/countries/isle_of_man.py +++ b/holidays/countries/isle_of_man.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/countries/israel.py b/holidays/countries/israel.py index 7da13450c..918debd09 100644 --- a/holidays/countries/israel.py +++ b/holidays/countries/israel.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/countries/italy.py b/holidays/countries/italy.py index b7eaf4782..ecf69786b 100644 --- a/holidays/countries/italy.py +++ b/holidays/countries/italy.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Provinces completed by Henrik Sozzi # Website: https://github.com/dr-prodigy/python-holidays diff --git a/holidays/countries/jamaica.py b/holidays/countries/jamaica.py index 20ada9d50..8f91caa76 100644 --- a/holidays/countries/jamaica.py +++ b/holidays/countries/jamaica.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/countries/japan.py b/holidays/countries/japan.py index f44272b6f..f0c6b3705 100644 --- a/holidays/countries/japan.py +++ b/holidays/countries/japan.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/countries/kazakhstan.py b/holidays/countries/kazakhstan.py index 3e633e947..d31cc220a 100644 --- a/holidays/countries/kazakhstan.py +++ b/holidays/countries/kazakhstan.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/countries/kenya.py b/holidays/countries/kenya.py index 6ac18b0e1..762a512be 100644 --- a/holidays/countries/kenya.py +++ b/holidays/countries/kenya.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/countries/latvia.py b/holidays/countries/latvia.py index f071f2347..dbe73b206 100644 --- a/holidays/countries/latvia.py +++ b/holidays/countries/latvia.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/countries/lesotho.py b/holidays/countries/lesotho.py index 1d0a84557..a229c4302 100644 --- a/holidays/countries/lesotho.py +++ b/holidays/countries/lesotho.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/countries/liechtenstein.py b/holidays/countries/liechtenstein.py index 96f0e9086..18cb4bb1a 100644 --- a/holidays/countries/liechtenstein.py +++ b/holidays/countries/liechtenstein.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/countries/lithuania.py b/holidays/countries/lithuania.py index 3eb67e7b4..1a1847990 100644 --- a/holidays/countries/lithuania.py +++ b/holidays/countries/lithuania.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/countries/luxembourg.py b/holidays/countries/luxembourg.py index 3b76d942a..bbe46f332 100644 --- a/holidays/countries/luxembourg.py +++ b/holidays/countries/luxembourg.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/countries/madagascar.py b/holidays/countries/madagascar.py index 842161ba6..cb1afa11f 100644 --- a/holidays/countries/madagascar.py +++ b/holidays/countries/madagascar.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/countries/malawi.py b/holidays/countries/malawi.py index c10c6fd2e..ef0422de6 100644 --- a/holidays/countries/malawi.py +++ b/holidays/countries/malawi.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/countries/malaysia.py b/holidays/countries/malaysia.py index 953945893..597dc48b7 100644 --- a/holidays/countries/malaysia.py +++ b/holidays/countries/malaysia.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/countries/malta.py b/holidays/countries/malta.py index 3ff0be886..ff4debef1 100644 --- a/holidays/countries/malta.py +++ b/holidays/countries/malta.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/countries/mexico.py b/holidays/countries/mexico.py index 0bd4c1327..3832a7b82 100644 --- a/holidays/countries/mexico.py +++ b/holidays/countries/mexico.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/countries/moldova.py b/holidays/countries/moldova.py index 6181d6813..7b03aedad 100644 --- a/holidays/countries/moldova.py +++ b/holidays/countries/moldova.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/countries/morocco.py b/holidays/countries/morocco.py index 0d4bf8f8b..1fa1ab854 100644 --- a/holidays/countries/morocco.py +++ b/holidays/countries/morocco.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/countries/mozambique.py b/holidays/countries/mozambique.py index 1d418a06c..809fe2129 100644 --- a/holidays/countries/mozambique.py +++ b/holidays/countries/mozambique.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/countries/namibia.py b/holidays/countries/namibia.py index 0a5b0af6a..65f8f0ebb 100644 --- a/holidays/countries/namibia.py +++ b/holidays/countries/namibia.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/countries/netherlands.py b/holidays/countries/netherlands.py index a0c502745..0c4e69b76 100644 --- a/holidays/countries/netherlands.py +++ b/holidays/countries/netherlands.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/countries/new_zealand.py b/holidays/countries/new_zealand.py index 8aa2214d1..f4dc5f30b 100644 --- a/holidays/countries/new_zealand.py +++ b/holidays/countries/new_zealand.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/countries/nicaragua.py b/holidays/countries/nicaragua.py index 72b396f1a..797e4b46f 100644 --- a/holidays/countries/nicaragua.py +++ b/holidays/countries/nicaragua.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/countries/nigeria.py b/holidays/countries/nigeria.py index 017b21b0f..2188a9a60 100644 --- a/holidays/countries/nigeria.py +++ b/holidays/countries/nigeria.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/countries/north_macedonia.py b/holidays/countries/north_macedonia.py index 748018bab..d6786ab09 100644 --- a/holidays/countries/north_macedonia.py +++ b/holidays/countries/north_macedonia.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/countries/norway.py b/holidays/countries/norway.py index b85fd15e4..594cbe42c 100644 --- a/holidays/countries/norway.py +++ b/holidays/countries/norway.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/countries/pakistan.py b/holidays/countries/pakistan.py index 7d96d1c71..0ab278307 100644 --- a/holidays/countries/pakistan.py +++ b/holidays/countries/pakistan.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/countries/paraguay.py b/holidays/countries/paraguay.py index e2c44509f..dc7b79339 100644 --- a/holidays/countries/paraguay.py +++ b/holidays/countries/paraguay.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/countries/peru.py b/holidays/countries/peru.py index dfd8f1de6..76882ff4c 100644 --- a/holidays/countries/peru.py +++ b/holidays/countries/peru.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/countries/poland.py b/holidays/countries/poland.py index 02c0095b1..d0140fd47 100644 --- a/holidays/countries/poland.py +++ b/holidays/countries/poland.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/countries/portugal.py b/holidays/countries/portugal.py index 16b2d02af..3ac5cd44c 100644 --- a/holidays/countries/portugal.py +++ b/holidays/countries/portugal.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/countries/romania.py b/holidays/countries/romania.py index 0ed1804f5..69ae46335 100644 --- a/holidays/countries/romania.py +++ b/holidays/countries/romania.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/countries/russia.py b/holidays/countries/russia.py index 2b0c40f1c..9fe4dd7b9 100644 --- a/holidays/countries/russia.py +++ b/holidays/countries/russia.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/countries/saudi_arabia.py b/holidays/countries/saudi_arabia.py index a07a53aeb..a07c22101 100644 --- a/holidays/countries/saudi_arabia.py +++ b/holidays/countries/saudi_arabia.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/countries/serbia.py b/holidays/countries/serbia.py index 2caeea4ce..673cc0c48 100644 --- a/holidays/countries/serbia.py +++ b/holidays/countries/serbia.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/countries/singapore.py b/holidays/countries/singapore.py index f5df66a0f..5852136a9 100644 --- a/holidays/countries/singapore.py +++ b/holidays/countries/singapore.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/countries/slovakia.py b/holidays/countries/slovakia.py index 426cadfcd..bea96ccbb 100644 --- a/holidays/countries/slovakia.py +++ b/holidays/countries/slovakia.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/countries/slovenia.py b/holidays/countries/slovenia.py index 93c3f9c65..7a336ccca 100644 --- a/holidays/countries/slovenia.py +++ b/holidays/countries/slovenia.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/countries/south_africa.py b/holidays/countries/south_africa.py index ac1b4ec27..7afac5c6e 100644 --- a/holidays/countries/south_africa.py +++ b/holidays/countries/south_africa.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/countries/south_korea.py b/holidays/countries/south_korea.py index 6bbb1a03c..a5b1b5118 100644 --- a/holidays/countries/south_korea.py +++ b/holidays/countries/south_korea.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/countries/spain.py b/holidays/countries/spain.py index 24ecd155f..e32ab1a8b 100644 --- a/holidays/countries/spain.py +++ b/holidays/countries/spain.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/countries/sweden.py b/holidays/countries/sweden.py index 3f16eca86..e61d3a16f 100644 --- a/holidays/countries/sweden.py +++ b/holidays/countries/sweden.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/countries/switzerland.py b/holidays/countries/switzerland.py index 2954e7a41..f7b6606c4 100644 --- a/holidays/countries/switzerland.py +++ b/holidays/countries/switzerland.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/countries/taiwan.py b/holidays/countries/taiwan.py index 3a496b5c3..adb5cbf39 100644 --- a/holidays/countries/taiwan.py +++ b/holidays/countries/taiwan.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/countries/tunisia.py b/holidays/countries/tunisia.py index 7cebd090e..d19ae5c23 100644 --- a/holidays/countries/tunisia.py +++ b/holidays/countries/tunisia.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/countries/turkey.py b/holidays/countries/turkey.py index 61c81848a..cadcde4c2 100644 --- a/holidays/countries/turkey.py +++ b/holidays/countries/turkey.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/countries/ukraine.py b/holidays/countries/ukraine.py index 6da55c449..f53e9ab81 100644 --- a/holidays/countries/ukraine.py +++ b/holidays/countries/ukraine.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/countries/united_arab_emirates.py b/holidays/countries/united_arab_emirates.py index e79c7c38e..812565937 100644 --- a/holidays/countries/united_arab_emirates.py +++ b/holidays/countries/united_arab_emirates.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/countries/united_kingdom.py b/holidays/countries/united_kingdom.py index 634348fb8..5e0fa7069 100644 --- a/holidays/countries/united_kingdom.py +++ b/holidays/countries/united_kingdom.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/countries/united_states.py b/holidays/countries/united_states.py index 5d0b65f27..0d2e70911 100644 --- a/holidays/countries/united_states.py +++ b/holidays/countries/united_states.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/countries/uruguay.py b/holidays/countries/uruguay.py index 8b2dee8a7..1f4fc2465 100644 --- a/holidays/countries/uruguay.py +++ b/holidays/countries/uruguay.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/countries/uzbekistan.py b/holidays/countries/uzbekistan.py index 643874759..0c305281a 100644 --- a/holidays/countries/uzbekistan.py +++ b/holidays/countries/uzbekistan.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/countries/venezuela.py b/holidays/countries/venezuela.py index 198b2acea..42a47e88b 100644 --- a/holidays/countries/venezuela.py +++ b/holidays/countries/venezuela.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/countries/vietnam.py b/holidays/countries/vietnam.py index b036c31a2..6edf3b826 100644 --- a/holidays/countries/vietnam.py +++ b/holidays/countries/vietnam.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/countries/zambia.py b/holidays/countries/zambia.py index 88240170f..fc17b6cf4 100644 --- a/holidays/countries/zambia.py +++ b/holidays/countries/zambia.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/countries/zimbabwe.py b/holidays/countries/zimbabwe.py index f17c0d4f7..8d6c86a94 100644 --- a/holidays/countries/zimbabwe.py +++ b/holidays/countries/zimbabwe.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/financial/__init__.py b/holidays/financial/__init__.py index 657e37220..5765ae4b1 100644 --- a/holidays/financial/__init__.py +++ b/holidays/financial/__init__.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/financial/european_central_bank.py b/holidays/financial/european_central_bank.py index cfdfda324..958771421 100644 --- a/holidays/financial/european_central_bank.py +++ b/holidays/financial/european_central_bank.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/financial/ny_stock_exchange.py b/holidays/financial/ny_stock_exchange.py index e3577f66f..e567556b9 100644 --- a/holidays/financial/ny_stock_exchange.py +++ b/holidays/financial/ny_stock_exchange.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/holiday_base.py b/holidays/holiday_base.py index 05d8c2ab9..f74a6433a 100644 --- a/holidays/holiday_base.py +++ b/holidays/holiday_base.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/utils.py b/holidays/utils.py index 0e2843b55..221b72546 100755 --- a/holidays/utils.py +++ b/holidays/utils.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/setup.cfg b/setup.cfg index 3ef21b8e1..4a0b3f3ee 100644 --- a/setup.cfg +++ b/setup.cfg @@ -5,8 +5,10 @@ description = Generate and work with holidays in Python long_description = file: README.rst long_description_content_type = text/x-rst url = https://github.com/dr-prodigy/python-holidays -author = dr-prodigy (formerly ryanss) -author_email = maurizio.montel@gmail.com +author = Maurizio Montel (dr-prodigy) +author_email = dr.prodigy.github@gmail.com +maintainer = Arkadii Yakovets (arkid15r) +maintainer_email = ark@cho.red license = MIT license_file = LICENSE platforms = any @@ -41,7 +43,7 @@ python_requires = >=3.7 holidays = py.typed [bumpversion] -current_version = 0.18 +current_version = 0.19 [flake8] per-file-ignores = diff --git a/setup.py b/setup.py index c389e2ed8..68f5fd7a7 100644 --- a/setup.py +++ b/setup.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/common.py b/test/common.py index 481d86906..3a07c72b3 100644 --- a/test/common.py +++ b/test/common.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/countries/__init__.py b/test/countries/__init__.py index b6ec3a105..74e93d096 100644 --- a/test/countries/__init__.py +++ b/test/countries/__init__.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/countries/test_angola.py b/test/countries/test_angola.py index 23ee4a07a..4774704e3 100644 --- a/test/countries/test_angola.py +++ b/test/countries/test_angola.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/countries/test_argentina.py b/test/countries/test_argentina.py index ea93271d9..bb3598c5d 100644 --- a/test/countries/test_argentina.py +++ b/test/countries/test_argentina.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/countries/test_armenia.py b/test/countries/test_armenia.py index 227fbf57c..0bd1ad8d4 100644 --- a/test/countries/test_armenia.py +++ b/test/countries/test_armenia.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/countries/test_aruba.py b/test/countries/test_aruba.py index b4db5b5a0..f7161f0ef 100644 --- a/test/countries/test_aruba.py +++ b/test/countries/test_aruba.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/countries/test_australia.py b/test/countries/test_australia.py index 50bed1e4a..b82be0d24 100644 --- a/test/countries/test_australia.py +++ b/test/countries/test_australia.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/countries/test_austria.py b/test/countries/test_austria.py index 130ae6cca..42c5da34c 100644 --- a/test/countries/test_austria.py +++ b/test/countries/test_austria.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/countries/test_azerbaijan.py b/test/countries/test_azerbaijan.py index c237574fd..6d39ebad3 100644 --- a/test/countries/test_azerbaijan.py +++ b/test/countries/test_azerbaijan.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/countries/test_bangladesh.py b/test/countries/test_bangladesh.py index 9abc8e7ac..419180e5a 100644 --- a/test/countries/test_bangladesh.py +++ b/test/countries/test_bangladesh.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/countries/test_belarus.py b/test/countries/test_belarus.py index c17151f8a..16661dab9 100644 --- a/test/countries/test_belarus.py +++ b/test/countries/test_belarus.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/countries/test_belgium.py b/test/countries/test_belgium.py index 990bb9965..d5918f05f 100644 --- a/test/countries/test_belgium.py +++ b/test/countries/test_belgium.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/countries/test_bolivia.py b/test/countries/test_bolivia.py index bf45d0152..248d7b1ae 100644 --- a/test/countries/test_bolivia.py +++ b/test/countries/test_bolivia.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/countries/test_bosnia_and_herzegovina.py b/test/countries/test_bosnia_and_herzegovina.py index c3b42f67e..a68bfa0da 100644 --- a/test/countries/test_bosnia_and_herzegovina.py +++ b/test/countries/test_bosnia_and_herzegovina.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/countries/test_botswana.py b/test/countries/test_botswana.py index 33fb5a298..515c221e8 100644 --- a/test/countries/test_botswana.py +++ b/test/countries/test_botswana.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/countries/test_brazil.py b/test/countries/test_brazil.py index f709e652f..6e37d6751 100644 --- a/test/countries/test_brazil.py +++ b/test/countries/test_brazil.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/countries/test_bulgaria.py b/test/countries/test_bulgaria.py index 998d4efc8..c67d8c76e 100644 --- a/test/countries/test_bulgaria.py +++ b/test/countries/test_bulgaria.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/countries/test_burundi.py b/test/countries/test_burundi.py index d01fb45e8..4ac86c38d 100644 --- a/test/countries/test_burundi.py +++ b/test/countries/test_burundi.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/countries/test_canada.py b/test/countries/test_canada.py index 12253a6a1..865c5e3cd 100644 --- a/test/countries/test_canada.py +++ b/test/countries/test_canada.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/countries/test_chile.py b/test/countries/test_chile.py index fc82da92e..fa97bffa0 100644 --- a/test/countries/test_chile.py +++ b/test/countries/test_chile.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/countries/test_china.py b/test/countries/test_china.py index 62c2b3c2b..a62ac18ea 100644 --- a/test/countries/test_china.py +++ b/test/countries/test_china.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/countries/test_colombia.py b/test/countries/test_colombia.py index b16c98daf..41fcae245 100644 --- a/test/countries/test_colombia.py +++ b/test/countries/test_colombia.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/countries/test_croatia.py b/test/countries/test_croatia.py index 4f5b6e0c5..4e17df200 100644 --- a/test/countries/test_croatia.py +++ b/test/countries/test_croatia.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/countries/test_cuba.py b/test/countries/test_cuba.py index 37f0810e6..fb7137595 100644 --- a/test/countries/test_cuba.py +++ b/test/countries/test_cuba.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/countries/test_curacao.py b/test/countries/test_curacao.py index bdeeb394c..44bacbb6f 100644 --- a/test/countries/test_curacao.py +++ b/test/countries/test_curacao.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/countries/test_cyprus.py b/test/countries/test_cyprus.py index 9fc0f53db..5d12dce3a 100644 --- a/test/countries/test_cyprus.py +++ b/test/countries/test_cyprus.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/countries/test_czechia.py b/test/countries/test_czechia.py index e56feb93f..9961af8d0 100644 --- a/test/countries/test_czechia.py +++ b/test/countries/test_czechia.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/countries/test_denmark.py b/test/countries/test_denmark.py index beef252d0..d59501afd 100644 --- a/test/countries/test_denmark.py +++ b/test/countries/test_denmark.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/countries/test_djibouti.py b/test/countries/test_djibouti.py index c7e0a3089..0a18e817d 100644 --- a/test/countries/test_djibouti.py +++ b/test/countries/test_djibouti.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/countries/test_dominican_republic.py b/test/countries/test_dominican_republic.py index 3149b0fb3..a6a670577 100644 --- a/test/countries/test_dominican_republic.py +++ b/test/countries/test_dominican_republic.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/countries/test_egypt.py b/test/countries/test_egypt.py index c35fa458f..dfbfa4f31 100644 --- a/test/countries/test_egypt.py +++ b/test/countries/test_egypt.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/countries/test_estonia.py b/test/countries/test_estonia.py index 17432dbba..6067f86d3 100644 --- a/test/countries/test_estonia.py +++ b/test/countries/test_estonia.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/countries/test_eswatini.py b/test/countries/test_eswatini.py index 3604b5239..9ad6d4b6b 100644 --- a/test/countries/test_eswatini.py +++ b/test/countries/test_eswatini.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/countries/test_ethiopia.py b/test/countries/test_ethiopia.py index 6befc92b0..8ee855fb0 100644 --- a/test/countries/test_ethiopia.py +++ b/test/countries/test_ethiopia.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/countries/test_finland.py b/test/countries/test_finland.py index 977ba4cc5..d088d7687 100644 --- a/test/countries/test_finland.py +++ b/test/countries/test_finland.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/countries/test_france.py b/test/countries/test_france.py index 949cd99c0..f59061f65 100644 --- a/test/countries/test_france.py +++ b/test/countries/test_france.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/countries/test_georgia.py b/test/countries/test_georgia.py index 11cf61ed1..8dae4500b 100644 --- a/test/countries/test_georgia.py +++ b/test/countries/test_georgia.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/countries/test_germany.py b/test/countries/test_germany.py index b6ad15784..010fd3074 100644 --- a/test/countries/test_germany.py +++ b/test/countries/test_germany.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/countries/test_greece.py b/test/countries/test_greece.py index 55548ec73..a99d28eac 100644 --- a/test/countries/test_greece.py +++ b/test/countries/test_greece.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/countries/test_honduras.py b/test/countries/test_honduras.py index 2e1d41fbb..196e43fbb 100644 --- a/test/countries/test_honduras.py +++ b/test/countries/test_honduras.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/countries/test_hongkong.py b/test/countries/test_hongkong.py index 37bcdfcce..28b4d79dd 100644 --- a/test/countries/test_hongkong.py +++ b/test/countries/test_hongkong.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/countries/test_hungary.py b/test/countries/test_hungary.py index 969a82293..26b442420 100644 --- a/test/countries/test_hungary.py +++ b/test/countries/test_hungary.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/countries/test_iceland.py b/test/countries/test_iceland.py index ba56a34c5..b12d788e4 100644 --- a/test/countries/test_iceland.py +++ b/test/countries/test_iceland.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/countries/test_india.py b/test/countries/test_india.py index ca2749e0e..e0740557e 100644 --- a/test/countries/test_india.py +++ b/test/countries/test_india.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/countries/test_indonesia.py b/test/countries/test_indonesia.py index 774ce5454..4017f5a41 100644 --- a/test/countries/test_indonesia.py +++ b/test/countries/test_indonesia.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/countries/test_ireland.py b/test/countries/test_ireland.py index 067c08863..b6986738f 100644 --- a/test/countries/test_ireland.py +++ b/test/countries/test_ireland.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/countries/test_isle_of_man.py b/test/countries/test_isle_of_man.py index 084a0c296..ac11fa83f 100644 --- a/test/countries/test_isle_of_man.py +++ b/test/countries/test_isle_of_man.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/countries/test_israel.py b/test/countries/test_israel.py index fa23f1214..dfbcf36eb 100644 --- a/test/countries/test_israel.py +++ b/test/countries/test_israel.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/countries/test_italy.py b/test/countries/test_italy.py index 317db02bd..9ec2b2478 100644 --- a/test/countries/test_italy.py +++ b/test/countries/test_italy.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/countries/test_jamaica.py b/test/countries/test_jamaica.py index d9cdfc24f..8069a4221 100644 --- a/test/countries/test_jamaica.py +++ b/test/countries/test_jamaica.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/countries/test_japan.py b/test/countries/test_japan.py index 2422cf900..89186bee8 100644 --- a/test/countries/test_japan.py +++ b/test/countries/test_japan.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/countries/test_kazakhstan.py b/test/countries/test_kazakhstan.py index e14a44dcb..937945e54 100644 --- a/test/countries/test_kazakhstan.py +++ b/test/countries/test_kazakhstan.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/countries/test_kenya.py b/test/countries/test_kenya.py index 4885f7946..858492473 100644 --- a/test/countries/test_kenya.py +++ b/test/countries/test_kenya.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/countries/test_latvia.py b/test/countries/test_latvia.py index 2758620f4..b08d1c5ec 100644 --- a/test/countries/test_latvia.py +++ b/test/countries/test_latvia.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/countries/test_lesotho.py b/test/countries/test_lesotho.py index 7e5ad10b3..3619d5706 100644 --- a/test/countries/test_lesotho.py +++ b/test/countries/test_lesotho.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/countries/test_liechtenstein.py b/test/countries/test_liechtenstein.py index 840256b4a..580486b5f 100644 --- a/test/countries/test_liechtenstein.py +++ b/test/countries/test_liechtenstein.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/countries/test_lithuania.py b/test/countries/test_lithuania.py index 55e2b77ff..6cd1f242d 100644 --- a/test/countries/test_lithuania.py +++ b/test/countries/test_lithuania.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/countries/test_luxembourg.py b/test/countries/test_luxembourg.py index ffcba43c8..b9f7af4f7 100644 --- a/test/countries/test_luxembourg.py +++ b/test/countries/test_luxembourg.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/countries/test_madagascar.py b/test/countries/test_madagascar.py index 1559deec1..04cd21a4a 100644 --- a/test/countries/test_madagascar.py +++ b/test/countries/test_madagascar.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/countries/test_malawi.py b/test/countries/test_malawi.py index 794f74ed2..a12c4364a 100644 --- a/test/countries/test_malawi.py +++ b/test/countries/test_malawi.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/countries/test_malaysia.py b/test/countries/test_malaysia.py index 4f29762b0..afb4e4ddc 100644 --- a/test/countries/test_malaysia.py +++ b/test/countries/test_malaysia.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/countries/test_malta.py b/test/countries/test_malta.py index 343c57082..a6e5c3773 100644 --- a/test/countries/test_malta.py +++ b/test/countries/test_malta.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/countries/test_mexico.py b/test/countries/test_mexico.py index e1435fe16..0a11cb9a7 100644 --- a/test/countries/test_mexico.py +++ b/test/countries/test_mexico.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/countries/test_moldova.py b/test/countries/test_moldova.py index 986be5f84..0696ce1c0 100644 --- a/test/countries/test_moldova.py +++ b/test/countries/test_moldova.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/countries/test_morocco.py b/test/countries/test_morocco.py index 21c724bc8..67ec2ff48 100644 --- a/test/countries/test_morocco.py +++ b/test/countries/test_morocco.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/countries/test_mozambique.py b/test/countries/test_mozambique.py index 154d4c482..9882abda9 100644 --- a/test/countries/test_mozambique.py +++ b/test/countries/test_mozambique.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/countries/test_namibia.py b/test/countries/test_namibia.py index 5d43e4e01..3ae292a25 100644 --- a/test/countries/test_namibia.py +++ b/test/countries/test_namibia.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/countries/test_netherlands.py b/test/countries/test_netherlands.py index 6f773363f..ad24e3331 100644 --- a/test/countries/test_netherlands.py +++ b/test/countries/test_netherlands.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/countries/test_new_zealand.py b/test/countries/test_new_zealand.py index 09281a266..4d20a5edc 100644 --- a/test/countries/test_new_zealand.py +++ b/test/countries/test_new_zealand.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/countries/test_nicaragua.py b/test/countries/test_nicaragua.py index 0b0267365..bca0e370c 100644 --- a/test/countries/test_nicaragua.py +++ b/test/countries/test_nicaragua.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/countries/test_nigeria.py b/test/countries/test_nigeria.py index d0420ef53..2281c6cde 100644 --- a/test/countries/test_nigeria.py +++ b/test/countries/test_nigeria.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/countries/test_north_macedonia.py b/test/countries/test_north_macedonia.py index 91d0fd255..dfcafbc79 100644 --- a/test/countries/test_north_macedonia.py +++ b/test/countries/test_north_macedonia.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/countries/test_norway.py b/test/countries/test_norway.py index 2d6e308a8..9db4ec856 100644 --- a/test/countries/test_norway.py +++ b/test/countries/test_norway.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/countries/test_pakistan.py b/test/countries/test_pakistan.py index 47e2707cd..6df6ddb60 100644 --- a/test/countries/test_pakistan.py +++ b/test/countries/test_pakistan.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/countries/test_paraguay.py b/test/countries/test_paraguay.py index 14eea4f12..745a11f40 100644 --- a/test/countries/test_paraguay.py +++ b/test/countries/test_paraguay.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/countries/test_peru.py b/test/countries/test_peru.py index 2cbda93eb..9d1e0bb93 100644 --- a/test/countries/test_peru.py +++ b/test/countries/test_peru.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/countries/test_poland.py b/test/countries/test_poland.py index 0a0c43a08..d63d297a1 100644 --- a/test/countries/test_poland.py +++ b/test/countries/test_poland.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/countries/test_portugal.py b/test/countries/test_portugal.py index 80f5eda45..5f6c4b3a4 100644 --- a/test/countries/test_portugal.py +++ b/test/countries/test_portugal.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/countries/test_romania.py b/test/countries/test_romania.py index 09b037504..e495157b5 100644 --- a/test/countries/test_romania.py +++ b/test/countries/test_romania.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/countries/test_russia.py b/test/countries/test_russia.py index 0346770a7..bbb94f2da 100644 --- a/test/countries/test_russia.py +++ b/test/countries/test_russia.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/countries/test_saudi_arabia.py b/test/countries/test_saudi_arabia.py index 65caf2b7a..d18503dbe 100644 --- a/test/countries/test_saudi_arabia.py +++ b/test/countries/test_saudi_arabia.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/countries/test_serbia.py b/test/countries/test_serbia.py index f15937ea1..250643c07 100644 --- a/test/countries/test_serbia.py +++ b/test/countries/test_serbia.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/countries/test_singapore.py b/test/countries/test_singapore.py index 8678e1bd1..8a1efe391 100644 --- a/test/countries/test_singapore.py +++ b/test/countries/test_singapore.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/countries/test_slovakia.py b/test/countries/test_slovakia.py index 44b18ee69..915827d42 100644 --- a/test/countries/test_slovakia.py +++ b/test/countries/test_slovakia.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/countries/test_slovenia.py b/test/countries/test_slovenia.py index cccef3d55..6b9339694 100644 --- a/test/countries/test_slovenia.py +++ b/test/countries/test_slovenia.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/countries/test_south_africa.py b/test/countries/test_south_africa.py index 8d407c93d..356d8795b 100644 --- a/test/countries/test_south_africa.py +++ b/test/countries/test_south_africa.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/countries/test_south_korea.py b/test/countries/test_south_korea.py index 7a8ecf9fb..1def7448e 100644 --- a/test/countries/test_south_korea.py +++ b/test/countries/test_south_korea.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/countries/test_spain.py b/test/countries/test_spain.py index 939b1fe28..b86d4c5cf 100644 --- a/test/countries/test_spain.py +++ b/test/countries/test_spain.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/countries/test_sweden.py b/test/countries/test_sweden.py index a07608eb5..779bf5c93 100644 --- a/test/countries/test_sweden.py +++ b/test/countries/test_sweden.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/countries/test_switzerland.py b/test/countries/test_switzerland.py index d5ac32715..5b5ebfa77 100644 --- a/test/countries/test_switzerland.py +++ b/test/countries/test_switzerland.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/countries/test_taiwan.py b/test/countries/test_taiwan.py index 473b0e58f..6a36afda9 100644 --- a/test/countries/test_taiwan.py +++ b/test/countries/test_taiwan.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/countries/test_tunisia.py b/test/countries/test_tunisia.py index 2bffeae95..4c220441d 100644 --- a/test/countries/test_tunisia.py +++ b/test/countries/test_tunisia.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/countries/test_turkey.py b/test/countries/test_turkey.py index 4f96ae2ec..2ecff8f1a 100644 --- a/test/countries/test_turkey.py +++ b/test/countries/test_turkey.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/countries/test_ukraine.py b/test/countries/test_ukraine.py index cb2ee9f06..48fa472fa 100644 --- a/test/countries/test_ukraine.py +++ b/test/countries/test_ukraine.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/countries/test_united_arab_emirates.py b/test/countries/test_united_arab_emirates.py index 53816600a..4a5e85acf 100644 --- a/test/countries/test_united_arab_emirates.py +++ b/test/countries/test_united_arab_emirates.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/countries/test_united_kingdom.py b/test/countries/test_united_kingdom.py index b1e516958..d92617296 100644 --- a/test/countries/test_united_kingdom.py +++ b/test/countries/test_united_kingdom.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/countries/test_united_states.py b/test/countries/test_united_states.py index bd0cb846b..60247998c 100644 --- a/test/countries/test_united_states.py +++ b/test/countries/test_united_states.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/countries/test_uruguay.py b/test/countries/test_uruguay.py index 825c36267..382e96d6a 100644 --- a/test/countries/test_uruguay.py +++ b/test/countries/test_uruguay.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/countries/test_uzbekistan.py b/test/countries/test_uzbekistan.py index 660d78364..ffddebe83 100644 --- a/test/countries/test_uzbekistan.py +++ b/test/countries/test_uzbekistan.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/countries/test_venezuela.py b/test/countries/test_venezuela.py index 515840dea..1feeaf201 100644 --- a/test/countries/test_venezuela.py +++ b/test/countries/test_venezuela.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/countries/test_vietnam.py b/test/countries/test_vietnam.py index 66612c194..c1aace864 100644 --- a/test/countries/test_vietnam.py +++ b/test/countries/test_vietnam.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/countries/test_zambia.py b/test/countries/test_zambia.py index eace9c023..ee74b7d66 100644 --- a/test/countries/test_zambia.py +++ b/test/countries/test_zambia.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/countries/test_zimbabwe.py b/test/countries/test_zimbabwe.py index 55d60c411..8ebac701e 100644 --- a/test/countries/test_zimbabwe.py +++ b/test/countries/test_zimbabwe.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/financial/test_european_central_bank.py b/test/financial/test_european_central_bank.py index 65ea5c269..7294c621f 100644 --- a/test/financial/test_european_central_bank.py +++ b/test/financial/test_european_central_bank.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/financial/test_ny_stock_exchange.py b/test/financial/test_ny_stock_exchange.py index 9c55091cc..ff5c2a757 100644 --- a/test/financial/test_ny_stock_exchange.py +++ b/test/financial/test_ny_stock_exchange.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/test_holiday_base.py b/test/test_holiday_base.py index 9e8c16526..d53423e54 100644 --- a/test/test_holiday_base.py +++ b/test/test_holiday_base.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/test_imports.py b/test/test_imports.py index c12c337b1..801dd8fc7 100644 --- a/test/test_imports.py +++ b/test/test_imports.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) From 43f15149cb6ea7ff337729ead45cf05651fdd9c1 Mon Sep 17 00:00:00 2001 From: Arkadii Yakovets Date: Mon, 16 Jan 2023 10:17:43 -0800 Subject: [PATCH 119/138] Update supported countries number. --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 524bc57e9..5667459eb 100644 --- a/README.rst +++ b/README.rst @@ -106,7 +106,7 @@ Available Countries .. _ISO 3166-1 alpha-2 code: https://en.wikipedia.org/wiki/List_of_ISO_3166_country_codes -We currently support 102 countries. The standard way to refer to a country is by +We currently support 103 countries. The standard way to refer to a country is by using its `ISO 3166-1 alpha-2 code`_, the same used for domain names. The following countries and their subdivisions are available: From a349e672d6e88cab89271d5dff4fa55b025726d2 Mon Sep 17 00:00:00 2001 From: Arkadii Yakovets Date: Mon, 16 Jan 2023 13:14:28 -0800 Subject: [PATCH 120/138] Update tox configuration. (#881) - Disable test coverage when tests fail - Reformat tox.ini - Enable pre-commit automatic update --- .pre-commit-config.yaml | 4 ++-- tox.ini | 50 ++++++++++++++++++++++++----------------- 2 files changed, 32 insertions(+), 22 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 5ce1a4e83..301efdde0 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -12,13 +12,13 @@ repos: args: [--fix=lf] - repo: https://github.com/python/black - rev: 22.10.0 + rev: 22.12.0 hooks: - id: black language_version: python3 - repo: https://github.com/pycqa/flake8 - rev: 5.0.4 + rev: 6.0.0 hooks: - id: flake8 additional_dependencies: diff --git a/tox.ini b/tox.ini index 0c2eb6206..3a1975434 100644 --- a/tox.ini +++ b/tox.ini @@ -1,33 +1,43 @@ -[tox] -minversion = 3.24.5 -skip_missing_interpreters = true -envlist = py{37,38,39,310,py3}, pre-commit, docs - [pytest] -addopts = --cov=./ --cov-report term --cov-report xml --cov-config=./pyproject.toml - -[testenv:pre-commit] -basepython = python -deps = pre-commit -commands = -# autoupdate disabled to avoid flake8 6.0.0 failing dependencies -# pre-commit autoupdate - pre-commit run -a +addopts = + --cov=. + --cov-config=pyproject.toml + --cov-report term + --cov-report xml + --no-cov-on-fail [testenv] -deps = -r{toxinidir}/requirements_dev.txt -commands = pytest +commands = + pytest +deps = + -r{toxinidir}/requirements_dev.txt [testenv:docs] -# Test docs +# Test docs. # We run it in Python 3.9 to match # https://docs.readthedocs.io/en/stable/config-file/v2.html?#build-image -basepython = python3.9 -commands = - sphinx-build -W -j auto docs/source docs/_build allowlist_externals = cmd sphinx-build +basepython = python3.9 +commands = + sphinx-build -W -j auto docs/source docs/_build deps = -r{toxinidir}/requirements_dev.txt -r{toxinidir}/docs/requirements.txt + +[testenv:pre-commit] +basepython = python +commands = + pre-commit autoupdate + pre-commit run -a +deps = + pre-commit + +[tox] +envlist = + py{37,38,39,310,py3} + pre-commit + docs +minversion = 3.24.5 +skip_missing_interpreters = true From 7fce57d99eb625db97c3d7085e941a2e19f71e97 Mon Sep 17 00:00:00 2001 From: Arkadii Yakovets Date: Mon, 16 Jan 2023 14:25:36 -0800 Subject: [PATCH 121/138] Fix doc tests. --- README.rst | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/README.rst b/README.rst index a7f691596..5ca95a0d2 100644 --- a/README.rst +++ b/README.rst @@ -106,7 +106,7 @@ Available Countries .. _ISO 3166-1 alpha-2 code: https://en.wikipedia.org/wiki/List_of_ISO_3166_country_codes -We currently support 103 countries. The standard way to refer to a country is by +We currently support 106 countries. The standard way to refer to a country is by using its `ISO 3166-1 alpha-2 code`_, the same used for domain names. The following countries and their subdivisions are available: @@ -349,6 +349,9 @@ following countries and their subdivisions are available: * - Peru - PE - None + * - Philippines + - PH + - None * - Poland - PL - None @@ -394,6 +397,9 @@ following countries and their subdivisions are available: * - Taiwan - TW - None + * - Thailand + - TH + - None * - Tunisia - TN - None From 29b77a42e47bb3e5f07fca0cd3dd72fc71b8e566 Mon Sep 17 00:00:00 2001 From: dr-prodigy Date: Mon, 16 Jan 2023 23:39:34 +0100 Subject: [PATCH 122/138] CHANGES sync --- .pre-commit-config.yaml | 2 +- CHANGES | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 301efdde0..6ab43cd59 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -42,7 +42,7 @@ repos: - --implicit-optional - repo: https://github.com/pre-commit/pygrep-hooks - rev: v1.9.0 + rev: v1.10.0 hooks: - id: rst-backticks diff --git a/CHANGES b/CHANGES index aeb612383..64e05689f 100644 --- a/CHANGES +++ b/CHANGES @@ -5,6 +5,9 @@ Released ???????? ??, ???? - Copyright update 2023 - Added Arkadii Yakovets (arkid15r) to project collaborators / maintainers - welcome! +- Support for Monaco #877 (KJhellico) +- Support for Bahrain #888 (arkid15r) +- Japan: optimizations and refactoring #879 (KJhellico) Version 0.18 ============ From 56ac25a241bb9361b0c7ce33c7e1933fca65b0d3 Mon Sep 17 00:00:00 2001 From: Arkadii Yakovets Date: Mon, 16 Jan 2023 15:28:37 -0800 Subject: [PATCH 123/138] Split tests. --- test/countries/test_argentina.py | 46 +++++------ test/countries/test_australia.py | 8 +- test/countries/test_austria.py | 24 +++--- test/countries/test_bulgaria.py | 10 +-- test/countries/test_canada.py | 70 ++++++++--------- test/countries/test_colombia.py | 6 +- test/countries/test_cuba.py | 6 +- test/countries/test_ireland.py | 8 +- test/countries/test_israel.py | 42 +++++++--- test/countries/test_mexico.py | 34 ++++---- test/countries/test_new_zealand.py | 18 ++--- test/countries/test_paraguay.py | 8 +- test/countries/test_united_kingdom.py | 38 ++++----- test/countries/test_united_states.py | 82 ++++++++++---------- test/countries/test_uruguay.py | 30 +++---- test/countries/test_venezuela.py | 6 +- test/countries/test_vietnam.py | 14 ++-- test/financial/test_european_central_bank.py | 20 ++--- test/financial/test_ny_stock_exchange.py | 9 ++- 19 files changed, 246 insertions(+), 233 deletions(-) diff --git a/test/countries/test_argentina.py b/test/countries/test_argentina.py index d1e275124..bb3598c5d 100644 --- a/test/countries/test_argentina.py +++ b/test/countries/test_argentina.py @@ -11,7 +11,7 @@ from datetime import date -from dateutil.relativedelta import relativedelta as rd +from dateutil.relativedelta import relativedelta from holidays.constants import MAY, JUN, JUL, AUG, OCT from holidays.countries.argentina import AR, ARG, Argentina @@ -41,8 +41,8 @@ def test_new_years_day(self): dt = date(year, 1, 1) self.assertHoliday(dt) self.assertNoHoliday( - dt + rd(days=-1), - dt + rd(days=+1), + dt + relativedelta(days=-1), + dt + relativedelta(days=+1), ) def test_carnival_day(self): @@ -98,8 +98,8 @@ def test_labor_day(self): dt = date(year, MAY, 1) self.assertHoliday(dt) self.assertNoHoliday( - dt + rd(days=-1), - dt + rd(days=+1), + dt + relativedelta(days=-1), + dt + relativedelta(days=+1), ) def test_may_revolution_day(self): @@ -114,8 +114,8 @@ def test_may_revolution_day(self): dt = date(year, MAY, 25) self.assertHoliday(dt) self.assertNoHoliday( - dt + rd(days=-1), - dt + rd(days=+1), + dt + relativedelta(days=-1), + dt + relativedelta(days=+1), ) def test_guemes_day(self): @@ -123,8 +123,8 @@ def test_guemes_day(self): dt = date(year, JUN, 17) self.assertHoliday(dt) self.assertNoHoliday( - dt + rd(days=-1), - dt + rd(days=+1), + dt + relativedelta(days=-1), + dt + relativedelta(days=+1), ) def test_belgrano_day(self): @@ -132,8 +132,8 @@ def test_belgrano_day(self): dt = date(year, JUN, 20) self.assertHoliday(dt) self.assertNoHoliday( - dt + rd(days=-1), - dt + rd(days=+1), + dt + relativedelta(days=-1), + dt + relativedelta(days=+1), ) def test_independence_day(self): @@ -153,8 +153,8 @@ def test_independence_day(self): dt = date(year, JUL, 9) self.assertHoliday(dt) self.assertNoHoliday( - dt + rd(days=-1), - dt + rd(days=+1), + dt + relativedelta(days=-1), + dt + relativedelta(days=+1), ) def test_san_martin_day(self): @@ -169,8 +169,8 @@ def test_san_martin_day(self): dt = date(year, AUG, 17) self.assertHoliday(dt) self.assertNoHoliday( - dt + rd(days=-1), - dt + rd(days=+1), + dt + relativedelta(days=-1), + dt + relativedelta(days=+1), ) def test_cultural_day(self): @@ -185,8 +185,8 @@ def test_cultural_day(self): dt = date(year, OCT, 12) self.assertHoliday(dt) self.assertNoHoliday( - dt + rd(days=-1), - dt + rd(days=+1), + dt + relativedelta(days=-1), + dt + relativedelta(days=+1), ) def test_national_sovereignty_day(self): @@ -197,8 +197,8 @@ def test_national_sovereignty_day(self): else: self.assertHoliday(dt) self.assertNoHoliday( - dt + rd(days=-1), - dt + rd(days=+1), + dt + relativedelta(days=-1), + dt + relativedelta(days=+1), ) def test_immaculate_conception_day(self): @@ -213,8 +213,8 @@ def test_immaculate_conception_day(self): dt = date(year, 12, 8) self.assertHoliday(dt) self.assertNoHoliday( - dt + rd(days=-1), - dt + rd(days=+1), + dt + relativedelta(days=-1), + dt + relativedelta(days=+1), ) def test_christmas(self): @@ -222,8 +222,8 @@ def test_christmas(self): dt = date(year, 12, 25) self.assertHoliday(dt) self.assertNoHoliday( - dt + rd(days=-1), - dt + rd(days=+1), + dt + relativedelta(days=-1), + dt + relativedelta(days=+1), ) def test_2022(self): diff --git a/test/countries/test_australia.py b/test/countries/test_australia.py index 8a4df7950..b82be0d24 100644 --- a/test/countries/test_australia.py +++ b/test/countries/test_australia.py @@ -12,7 +12,7 @@ import unittest from datetime import date -from dateutil.relativedelta import relativedelta as rd +from dateutil.relativedelta import relativedelta import holidays @@ -125,7 +125,7 @@ def test_easter_monday(self): ]: self.assertIn(dt, self.holidays) self.assertEqual(self.holidays[dt], "Easter Monday") - self.assertNotIn(dt + rd(days=+1), self.holidays) + self.assertNotIn(dt + relativedelta(days=+1), self.holidays) def test_bank_holiday(self): for dt in [ @@ -328,7 +328,7 @@ def test_christmas_day(self): for year in range(1900, 2100): dt = date(year, 12, 25) self.assertIn(dt, self.holidays) - self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + relativedelta(days=-1), self.holidays) self.assertNotIn(date(2010, 12, 24), self.holidays) self.assertNotEqual( self.holidays[date(2011, 12, 26)], "Christmas Day (Observed)" @@ -372,7 +372,7 @@ def test_boxing_day(self): for year in range(1900, 2100): dt = date(year, 12, 26) self.assertIn(dt, self.holidays) - self.assertNotIn(dt + rd(days=+1), self.holidays) + self.assertNotIn(dt + relativedelta(days=+1), self.holidays) self.assertNotIn(date(2009, 12, 28), self.holidays) self.assertNotIn(date(2010, 12, 27), self.holidays) self.holidays.observed = True diff --git a/test/countries/test_austria.py b/test/countries/test_austria.py index 8c8c48d02..42c5da34c 100644 --- a/test/countries/test_austria.py +++ b/test/countries/test_austria.py @@ -12,7 +12,7 @@ import unittest from datetime import date -from dateutil.relativedelta import relativedelta as rd +from dateutil.relativedelta import relativedelta import holidays @@ -25,16 +25,16 @@ def test_new_years(self): for year in range(1900, 2100): dt = date(year, 1, 1) self.assertIn(dt, self.holidays) - self.assertNotIn(dt + rd(days=-1), self.holidays) - self.assertNotIn(dt + rd(days=+1), self.holidays) + self.assertNotIn(dt + relativedelta(days=-1), self.holidays) + self.assertNotIn(dt + relativedelta(days=+1), self.holidays) def test_christmas(self): for year in range(1900, 2100): dt = date(year, 12, 25) self.assertIn(dt, self.holidays) - self.assertIn(dt + rd(days=+1), self.holidays) - self.assertNotIn(dt + rd(days=-1), self.holidays) - self.assertNotIn(dt + rd(days=+2), self.holidays) + self.assertIn(dt + relativedelta(days=+1), self.holidays) + self.assertNotIn(dt + relativedelta(days=-1), self.holidays) + self.assertNotIn(dt + relativedelta(days=+2), self.holidays) def test_easter_monday(self): for dt in [ @@ -49,20 +49,20 @@ def test_easter_monday(self): date(2020, 4, 13), ]: self.assertIn(dt, self.holidays) - self.assertNotIn(dt + rd(days=-1), self.holidays) - self.assertNotIn(dt + rd(days=+1), self.holidays) + self.assertNotIn(dt + relativedelta(days=-1), self.holidays) + self.assertNotIn(dt + relativedelta(days=+1), self.holidays) def test_national_day(self): for year in range(1919, 1934): dt = date(year, 11, 12) self.assertIn(dt, self.holidays) - self.assertNotIn(dt + rd(days=-1), self.holidays) - self.assertNotIn(dt + rd(days=+1), self.holidays) + self.assertNotIn(dt + relativedelta(days=-1), self.holidays) + self.assertNotIn(dt + relativedelta(days=+1), self.holidays) for year in range(1967, 2100): dt = date(year, 10, 26) self.assertIn(dt, self.holidays) - self.assertNotIn(dt + rd(days=-1), self.holidays) - self.assertNotIn(dt + rd(days=+1), self.holidays) + self.assertNotIn(dt + relativedelta(days=-1), self.holidays) + self.assertNotIn(dt + relativedelta(days=+1), self.holidays) def test_all_holidays_present(self): at_2015 = holidays.AT(years=[2015]) diff --git a/test/countries/test_bulgaria.py b/test/countries/test_bulgaria.py index c9ce8fc48..c67d8c76e 100644 --- a/test/countries/test_bulgaria.py +++ b/test/countries/test_bulgaria.py @@ -10,9 +10,7 @@ # License: MIT (see LICENSE file) import unittest -from datetime import date - -from dateutil.relativedelta import relativedelta as rd +from datetime import date, timedelta import holidays @@ -89,9 +87,9 @@ def test_easter(self): (2022, 4, 24), ]: easter = date(year, month, day) - easter_friday = easter + rd(days=-2) - easter_saturday = easter + rd(days=-1) - easter_monday = easter + rd(days=+1) + easter_friday = easter - timedelta(days=2) + easter_saturday = easter - timedelta(days=1) + easter_monday = easter + timedelta(days=1) for holiday in [ easter_friday, easter_saturday, diff --git a/test/countries/test_canada.py b/test/countries/test_canada.py index 793856479..865c5e3cd 100644 --- a/test/countries/test_canada.py +++ b/test/countries/test_canada.py @@ -12,7 +12,7 @@ import unittest from datetime import date -from dateutil.relativedelta import relativedelta as rd +from dateutil.relativedelta import relativedelta import holidays @@ -34,8 +34,8 @@ def test_new_years(self): for year in range(1900, 2100): dt = date(year, 1, 1) self.assertIn(dt, self.holidays) - self.assertNotIn(dt + rd(days=-1), self.holidays) - self.assertNotIn(dt + rd(days=+1), self.holidays) + self.assertNotIn(dt + relativedelta(days=-1), self.holidays) + self.assertNotIn(dt + relativedelta(days=+1), self.holidays) def test_islander_day(self): pei_holidays = holidays.CA(subdiv="PE") @@ -55,8 +55,8 @@ def test_islander_day(self): elif dt.year == 2009: self.assertNotIn(dt, self.holidays) self.assertIn(dt, pei_holidays) - self.assertNotIn(dt + rd(days=-1), pei_holidays) - self.assertNotIn(dt + rd(days=+1), pei_holidays) + self.assertNotIn(dt + relativedelta(days=-1), pei_holidays) + self.assertNotIn(dt + relativedelta(days=+1), pei_holidays) def test_yukon_heritage_day(self): # https://www.timeanddate.com/holidays/canada/heritage-day-yukon @@ -70,8 +70,8 @@ def test_yukon_heritage_day(self): date(2022, 2, 25), ]: self.assertIn(dt, yt_holidays) - self.assertNotIn(dt + rd(days=-1), yt_holidays) - self.assertNotIn(dt + rd(days=+1), yt_holidays) + self.assertNotIn(dt + relativedelta(days=-1), yt_holidays) + self.assertNotIn(dt + relativedelta(days=+1), yt_holidays) def test_family_day(self): ab_holidays = holidays.CA(subdiv="AB") @@ -140,8 +140,8 @@ def test_st_patricks_day(self): ]: self.assertNotIn(dt, self.holidays) self.assertIn(dt, nl_holidays) - self.assertNotIn(dt + rd(days=-1), nl_holidays) - self.assertNotIn(dt + rd(days=+1), nl_holidays) + self.assertNotIn(dt + relativedelta(days=-1), nl_holidays) + self.assertNotIn(dt + relativedelta(days=+1), nl_holidays) def test_good_friday(self): for dt in [ @@ -156,8 +156,8 @@ def test_good_friday(self): date(2020, 4, 10), ]: self.assertIn(dt, self.holidays) - self.assertNotIn(dt + rd(days=-1), self.holidays) - self.assertNotIn(dt + rd(days=+1), self.holidays) + self.assertNotIn(dt + relativedelta(days=-1), self.holidays) + self.assertNotIn(dt + relativedelta(days=+1), self.holidays) def test_easter_monday(self): for dt in [ @@ -172,8 +172,8 @@ def test_easter_monday(self): date(2020, 4, 13), ]: self.assertIn(dt, self.holidays) - self.assertNotIn(dt + rd(days=-1), self.holidays) - self.assertNotIn(dt + rd(days=+1), self.holidays) + self.assertNotIn(dt + relativedelta(days=-1), self.holidays) + self.assertNotIn(dt + relativedelta(days=+1), self.holidays) def test_st_georges_day(self): nl_holidays = holidays.CA(subdiv="NL") @@ -186,8 +186,8 @@ def test_st_georges_day(self): ]: self.assertNotIn(dt, self.holidays) self.assertIn(dt, nl_holidays) - self.assertNotIn(dt + rd(days=-1), nl_holidays) - self.assertNotIn(dt + rd(days=+1), nl_holidays) + self.assertNotIn(dt + relativedelta(days=-1), nl_holidays) + self.assertNotIn(dt + relativedelta(days=+1), nl_holidays) def test_victoria_day(self): for dt in [ @@ -199,8 +199,8 @@ def test_victoria_day(self): date(2020, 5, 18), ]: self.assertIn(dt, self.holidays) - self.assertNotIn(dt + rd(days=-1), self.holidays) - self.assertNotIn(dt + rd(days=+1), self.holidays) + self.assertNotIn(dt + relativedelta(days=-1), self.holidays) + self.assertNotIn(dt + relativedelta(days=+1), self.holidays) def test_national_aboriginal_day(self): nt_holidays = holidays.CA(subdiv="NT") @@ -209,8 +209,8 @@ def test_national_aboriginal_day(self): dt = date(year, 6, 21) self.assertNotIn(dt, self.holidays) self.assertIn(dt, nt_holidays) - self.assertNotIn(dt + rd(days=-1), nt_holidays) - self.assertNotIn(dt + rd(days=+1), nt_holidays) + self.assertNotIn(dt + relativedelta(days=-1), nt_holidays) + self.assertNotIn(dt + relativedelta(days=+1), nt_holidays) def test_st_jean_baptiste_day(self): qc_holidays = holidays.CA(subdiv="QC", observed=False) @@ -219,8 +219,8 @@ def test_st_jean_baptiste_day(self): dt = date(year, 6, 24) self.assertNotIn(dt, self.holidays) self.assertIn(dt, qc_holidays) - self.assertNotIn(dt + rd(days=-1), qc_holidays) - self.assertNotIn(dt + rd(days=+1), qc_holidays) + self.assertNotIn(dt + relativedelta(days=-1), qc_holidays) + self.assertNotIn(dt + relativedelta(days=+1), qc_holidays) self.assertNotIn(date(2001, 6, 25), qc_holidays) qc_holidays.observed = True self.assertIn(date(2001, 6, 25), qc_holidays) @@ -255,8 +255,8 @@ def test_canada_day(self): for year in range(1900, 2100): dt = date(year, 7, 1) self.assertIn(dt, self.holidays) - self.assertNotIn(dt + rd(days=-1), self.holidays) - self.assertNotIn(dt + rd(days=+1), self.holidays) + self.assertNotIn(dt + relativedelta(days=-1), self.holidays) + self.assertNotIn(dt + relativedelta(days=+1), self.holidays) self.assertNotIn(date(2006, 7, 3), self.holidays) self.assertNotIn(date(2007, 7, 2), self.holidays) self.holidays.observed = True @@ -272,8 +272,8 @@ def test_nunavut_day(self): dt = date(year, 7, 9) self.assertNotIn(dt, self.holidays) self.assertIn(dt, nu_holidays) - self.assertNotIn(dt + rd(days=-1), nu_holidays) - self.assertNotIn(dt + rd(days=+1), nu_holidays) + self.assertNotIn(dt + relativedelta(days=-1), nu_holidays) + self.assertNotIn(dt + relativedelta(days=+1), nu_holidays) self.assertNotIn(date(2017, 7, 10), nu_holidays) nu_holidays.observed = True self.assertIn(date(2017, 7, 10), nu_holidays) @@ -305,8 +305,8 @@ def test_labour_day(self): date(2015, 9, 7), ]: self.assertIn(dt, self.holidays) - self.assertNotIn(dt + rd(days=-1), self.holidays) - self.assertNotIn(dt + rd(days=+1), self.holidays) + self.assertNotIn(dt + relativedelta(days=-1), self.holidays) + self.assertNotIn(dt + relativedelta(days=+1), self.holidays) def test_national_day_for_truth_and_reconciliation(self): for dt in [ @@ -314,14 +314,14 @@ def test_national_day_for_truth_and_reconciliation(self): date(2020, 9, 30), ]: self.assertNotIn(dt, self.holidays) - self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + relativedelta(days=-1), self.holidays) mb_holidays = holidays.CA(subdiv="MB") for dt in [ date(2021, 9, 30), date(2030, 9, 30), ]: self.assertIn(dt, mb_holidays) - self.assertNotIn(dt + rd(days=-1), mb_holidays) + self.assertNotIn(dt + relativedelta(days=-1), mb_holidays) self.assertNotIn(dt, self.holidays) def test_thanksgiving(self): @@ -335,8 +335,8 @@ def test_thanksgiving(self): date(2020, 10, 12), ]: self.assertIn(dt, self.holidays) - self.assertNotIn(dt + rd(days=-1), self.holidays) - self.assertNotIn(dt + rd(days=+1), self.holidays) + self.assertNotIn(dt + relativedelta(days=-1), self.holidays) + self.assertNotIn(dt + relativedelta(days=+1), self.holidays) self.assertNotIn(dt, ns_holidays) def test_remembrance_day(self): @@ -349,8 +349,8 @@ def test_remembrance_day(self): self.assertNotIn(dt, self.holidays) self.assertIn(dt, ab_holidays) self.assertIn(dt, nl_holidays) - self.assertNotIn(dt + rd(days=-1), nl_holidays) - self.assertNotIn(dt + rd(days=+1), nl_holidays) + self.assertNotIn(dt + relativedelta(days=-1), nl_holidays) + self.assertNotIn(dt + relativedelta(days=+1), nl_holidays) self.assertNotIn(date(2007, 11, 12), ab_holidays) self.assertNotIn(date(2007, 11, 12), nl_holidays) ab_holidays.observed = True @@ -363,7 +363,7 @@ def test_christmas_day(self): for year in range(1900, 2100): dt = date(year, 12, 25) self.assertIn(dt, self.holidays) - self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + relativedelta(days=-1), self.holidays) self.assertNotIn(date(2010, 12, 27), self.holidays) self.assertNotEqual( self.holidays[date(2011, 12, 26)], "Christmas Day (Observed)" @@ -378,7 +378,7 @@ def test_boxing_day(self): for year in range(1900, 2100): dt = date(year, 12, 26) self.assertIn(dt, self.holidays) - self.assertNotIn(dt + rd(days=+1), self.holidays) + self.assertNotIn(dt + relativedelta(days=+1), self.holidays) self.assertNotIn(date(2009, 12, 28), self.holidays) self.assertNotIn(date(2010, 12, 27), self.holidays) self.holidays.observed = True diff --git a/test/countries/test_colombia.py b/test/countries/test_colombia.py index 51eecb80b..41fcae245 100644 --- a/test/countries/test_colombia.py +++ b/test/countries/test_colombia.py @@ -10,9 +10,7 @@ # License: MIT (see LICENSE file) import unittest -from datetime import date - -from dateutil.relativedelta import relativedelta as rd +from datetime import date, timedelta import holidays from holidays.constants import APR, AUG, DEC, JAN, JUL, JUN, MAR, MAY, NOV, OCT @@ -25,7 +23,7 @@ def setUp(self): def _check_all_dates(self, year, expected_holidays): start_date = date(year, 1, 1) end_date = date(year, 12, 31) - delta = rd(days=+1) + delta = timedelta(days=1) while start_date <= end_date: if start_date in expected_holidays: diff --git a/test/countries/test_cuba.py b/test/countries/test_cuba.py index dc6eaa945..fb7137595 100644 --- a/test/countries/test_cuba.py +++ b/test/countries/test_cuba.py @@ -10,9 +10,7 @@ # License: MIT (see LICENSE file) import unittest -from datetime import date - -from dateutil.relativedelta import relativedelta as rd +from datetime import date, timedelta import holidays from holidays.constants import APR, DEC, JAN, JUL, MAR, MAY, OCT @@ -25,7 +23,7 @@ def setUp(self): def _check_all_dates(self, year, expected_holidays): start_date = date(year, 1, 1) end_date = date(year, 12, 31) - delta = rd(days=+1) + delta = timedelta(days=1) while start_date <= end_date: if start_date in expected_holidays: diff --git a/test/countries/test_ireland.py b/test/countries/test_ireland.py index 7ff344e35..b6986738f 100644 --- a/test/countries/test_ireland.py +++ b/test/countries/test_ireland.py @@ -12,7 +12,7 @@ import unittest from datetime import date -from dateutil.relativedelta import relativedelta as rd +from dateutil.relativedelta import relativedelta import holidays @@ -49,8 +49,8 @@ def test_may_day(self): date(2020, 5, 4), ]: self.assertIn(dt, self.holidays) - self.assertNotIn(dt + rd(days=-1), self.holidays) - self.assertNotIn(dt + rd(days=+1), self.holidays) + self.assertNotIn(dt + relativedelta(days=-1), self.holidays) + self.assertNotIn(dt + relativedelta(days=+1), self.holidays) def test_st_stephens_day(self): # St. Stephen's Day @@ -59,7 +59,7 @@ def test_st_stephens_day(self): for year in range(1900, 2100): dt = date(year, 12, 26) self.assertIn(dt, self.holidays) - self.assertNotIn(dt + rd(days=+1), self.holidays) + self.assertNotIn(dt + relativedelta(days=+1), self.holidays) self.assertNotIn(date(2009, 12, 28), self.holidays) self.assertNotIn(date(2010, 12, 27), self.holidays) self.holidays.observed = True diff --git a/test/countries/test_israel.py b/test/countries/test_israel.py index 8abacee4a..dfbcf36eb 100644 --- a/test/countries/test_israel.py +++ b/test/countries/test_israel.py @@ -12,7 +12,7 @@ import unittest from datetime import date -from dateutil.relativedelta import relativedelta as rd +from dateutil.relativedelta import relativedelta import holidays @@ -42,8 +42,12 @@ def _test_observed_holidays(self, holiday_name): # Postponed il_holidays = holidays.IL(years=[2017], observed=True) - official_memorial_day = date(2017, 4, 30) + rd(days=days_delta) - observed_memorial_day = date(2017, 5, 1) + rd(days=days_delta) + official_memorial_day = date(2017, 4, 30) + relativedelta( + days=days_delta + ) + observed_memorial_day = date(2017, 5, 1) + relativedelta( + days=days_delta + ) self.assertIn(official_memorial_day, il_holidays) self.assertIn(holiday_name, il_holidays[official_memorial_day]) self.assertIn(observed_memorial_day, il_holidays) @@ -53,8 +57,12 @@ def _test_observed_holidays(self, holiday_name): # Earlier il_holidays = holidays.IL(years=[2018], observed=True) - official_memorial_day = date(2018, 4, 19) + rd(days=days_delta) - observed_memorial_day = date(2018, 4, 18) + rd(days=days_delta) + official_memorial_day = date(2018, 4, 19) + relativedelta( + days=days_delta + ) + observed_memorial_day = date(2018, 4, 18) + relativedelta( + days=days_delta + ) self.assertIn(official_memorial_day, il_holidays) self.assertIn(holiday_name, il_holidays[official_memorial_day]) self.assertIn(observed_memorial_day, il_holidays) @@ -64,7 +72,9 @@ def _test_observed_holidays(self, holiday_name): # On time il_holidays = holidays.IL(years=[2020], observed=True) - official_memorial_day = date(2020, 4, 28) + rd(days=days_delta) + official_memorial_day = date(2020, 4, 28) + relativedelta( + days=days_delta + ) self.assertIn(official_memorial_day, il_holidays) self.assertIn(holiday_name, il_holidays[official_memorial_day]) @@ -76,23 +86,33 @@ def _test_nonobserved_holidays(self, holiday_name): # Postponed il_holidays = holidays.IL(years=[2017], observed=False) - official_memorial_day = date(2017, 4, 30) + rd(days=days_delta) - observed_memorial_day = date(2017, 5, 1) + rd(days=days_delta) + official_memorial_day = date(2017, 4, 30) + relativedelta( + days=days_delta + ) + observed_memorial_day = date(2017, 5, 1) + relativedelta( + days=days_delta + ) self.assertIn(official_memorial_day, il_holidays) self.assertIn(holiday_name, il_holidays[official_memorial_day]) self.assertNotEqual(il_holidays[observed_memorial_day], "Memorial Day") # Earlier il_holidays = holidays.IL(years=[2018], observed=False) - official_memorial_day = date(2018, 4, 19) + rd(days=days_delta) - observed_memorial_day = date(2018, 4, 18) + rd(days=days_delta) + official_memorial_day = date(2018, 4, 19) + relativedelta( + days=days_delta + ) + observed_memorial_day = date(2018, 4, 18) + relativedelta( + days=days_delta + ) self.assertIn(official_memorial_day, il_holidays) self.assertIn(holiday_name, il_holidays[official_memorial_day]) self.assertNotIn(observed_memorial_day, il_holidays) # On time il_holidays = holidays.IL(years=[2020], observed=False) - official_memorial_day = date(2020, 4, 28) + rd(days=days_delta) + official_memorial_day = date(2020, 4, 28) + relativedelta( + days=days_delta + ) self.assertIn(official_memorial_day, il_holidays) self.assertIn(holiday_name, il_holidays[official_memorial_day]) diff --git a/test/countries/test_mexico.py b/test/countries/test_mexico.py index 7ce118587..0a11cb9a7 100644 --- a/test/countries/test_mexico.py +++ b/test/countries/test_mexico.py @@ -12,7 +12,7 @@ import unittest from datetime import date -from dateutil.relativedelta import relativedelta as rd +from dateutil.relativedelta import relativedelta import holidays @@ -31,8 +31,8 @@ def test_new_years(self): for year in range(1900, 2100): dt = date(year, 1, 1) self.assertIn(dt, self.holidays) - self.assertNotIn(dt + rd(days=-1), self.holidays) - self.assertNotIn(dt + rd(days=+1), self.holidays) + self.assertNotIn(dt + relativedelta(days=-1), self.holidays) + self.assertNotIn(dt + relativedelta(days=+1), self.holidays) def test_constitution_day(self): for dt in [ @@ -48,8 +48,8 @@ def test_constitution_day(self): date(2022, 2, 5), ]: self.assertIn(dt, self.holidays) - self.assertNotIn(dt + rd(days=-1), self.holidays) - self.assertNotIn(dt + rd(days=+1), self.holidays) + self.assertNotIn(dt + relativedelta(days=-1), self.holidays) + self.assertNotIn(dt + relativedelta(days=+1), self.holidays) self.holidays.observed = True for dt in [ date(2005, 2, 5), @@ -89,8 +89,8 @@ def test_benito_juarez(self): date(2024, 3, 21), ]: self.assertIn(dt, self.holidays) - self.assertNotIn(dt + rd(days=-1), self.holidays) - self.assertNotIn(dt + rd(days=+1), self.holidays) + self.assertNotIn(dt + relativedelta(days=-1), self.holidays) + self.assertNotIn(dt + relativedelta(days=+1), self.holidays) self.holidays.observed = True for dt in [ date(2005, 3, 21), @@ -130,8 +130,8 @@ def test_labor_day(self): for year in range(1923, 2100): dt = date(year, 5, 1) self.assertIn(dt, self.holidays) - self.assertNotIn(dt + rd(days=-1), self.holidays) - self.assertNotIn(dt + rd(days=+1), self.holidays) + self.assertNotIn(dt + relativedelta(days=-1), self.holidays) + self.assertNotIn(dt + relativedelta(days=+1), self.holidays) def test_independence_day(self): self.assertNotIn(date(2006, 9, 15), self.holidays) @@ -143,8 +143,8 @@ def test_independence_day(self): for year in range(1900, 2100): dt = date(year, 9, 16) self.assertIn(dt, self.holidays) - self.assertNotIn(dt + rd(days=-1), self.holidays) - self.assertNotIn(dt + rd(days=+1), self.holidays) + self.assertNotIn(dt + relativedelta(days=-1), self.holidays) + self.assertNotIn(dt + relativedelta(days=+1), self.holidays) def test_revolution_day(self): for dt in [ @@ -162,8 +162,8 @@ def test_revolution_day(self): date(2023, 11, 20), ]: self.assertIn(dt, self.holidays) - self.assertNotIn(dt + rd(days=-1), self.holidays) - self.assertNotIn(dt + rd(days=+1), self.holidays) + self.assertNotIn(dt + relativedelta(days=-1), self.holidays) + self.assertNotIn(dt + relativedelta(days=+1), self.holidays) self.holidays.observed = True for dt in [ date(2005, 11, 20), @@ -190,8 +190,8 @@ def test_change_of_government(self): dt = date(year, 12, 1) if (year >= 1970) and ((2096 - year) % 6) == 0: self.assertIn(dt, self.holidays) - self.assertNotIn(dt + rd(days=-1), self.holidays) - self.assertNotIn(dt + rd(days=+1), self.holidays) + self.assertNotIn(dt + relativedelta(days=-1), self.holidays) + self.assertNotIn(dt + relativedelta(days=+1), self.holidays) else: self.assertNotIn(dt, self.holidays) @@ -199,8 +199,8 @@ def test_christmas(self): for year in range(1900, 2100): dt = date(year, 12, 25) self.assertIn(dt, self.holidays) - self.assertNotIn(dt + rd(days=-1), self.holidays) - self.assertNotIn(dt + rd(days=+1), self.holidays) + self.assertNotIn(dt + relativedelta(days=-1), self.holidays) + self.assertNotIn(dt + relativedelta(days=+1), self.holidays) self.assertNotIn(date(2010, 12, 24), self.holidays) self.assertNotIn(date(2016, 12, 26), self.holidays) self.holidays.observed = True diff --git a/test/countries/test_new_zealand.py b/test/countries/test_new_zealand.py index 821eb614d..4d20a5edc 100644 --- a/test/countries/test_new_zealand.py +++ b/test/countries/test_new_zealand.py @@ -12,7 +12,7 @@ import unittest from datetime import date -from dateutil.relativedelta import relativedelta as rd +from dateutil.relativedelta import relativedelta import holidays @@ -150,8 +150,8 @@ def test_good_friday(self): date(2020, 4, 10), ]: self.assertIn(dt, self.holidays) - self.assertNotIn(dt + rd(days=-1), self.holidays) - self.assertNotIn(dt + rd(days=+1), self.holidays) + self.assertNotIn(dt + relativedelta(days=-1), self.holidays) + self.assertNotIn(dt + relativedelta(days=+1), self.holidays) def test_easter_monday(self): for dt in [ @@ -165,8 +165,8 @@ def test_easter_monday(self): date(2020, 4, 13), ]: self.assertIn(dt, self.holidays) - self.assertNotIn(dt + rd(days=-1), self.holidays) - self.assertNotIn(dt + rd(days=+1), self.holidays) + self.assertNotIn(dt + relativedelta(days=-1), self.holidays) + self.assertNotIn(dt + relativedelta(days=+1), self.holidays) def test_anzac_day(self): for year in range(1900, 1921): @@ -284,8 +284,8 @@ def test_matariki(self): ]: self.assertIn(dt, self.holidays) self.assertEqual(self.holidays[dt], "Matariki") - self.assertNotIn(dt + rd(days=-1), self.holidays) - self.assertNotIn(dt + rd(days=+1), self.holidays) + self.assertNotIn(dt + relativedelta(days=-1), self.holidays) + self.assertNotIn(dt + relativedelta(days=+1), self.holidays) def test_labour_day(self): for year, day in enumerate( @@ -323,7 +323,7 @@ def test_christmas_day(self): for year in range(1900, 2100): dt = date(year, 12, 25) self.assertIn(dt, self.holidays) - self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + relativedelta(days=-1), self.holidays) self.assertNotIn(date(2010, 12, 24), self.holidays) self.assertNotEqual( self.holidays[date(2011, 12, 26)], "Christmas Day (Observed)" @@ -367,7 +367,7 @@ def test_boxing_day(self): for year in range(1900, 2100): dt = date(year, 12, 26) self.assertIn(dt, self.holidays) - self.assertNotIn(dt + rd(days=+1), self.holidays) + self.assertNotIn(dt + relativedelta(days=+1), self.holidays) self.assertNotIn(date(2009, 12, 28), self.holidays) self.assertNotIn(date(2010, 12, 27), self.holidays) self.holidays.observed = True diff --git a/test/countries/test_paraguay.py b/test/countries/test_paraguay.py index 01f57886e..745a11f40 100644 --- a/test/countries/test_paraguay.py +++ b/test/countries/test_paraguay.py @@ -10,9 +10,7 @@ # License: MIT (see LICENSE file) import unittest -from datetime import date - -from dateutil.relativedelta import relativedelta as rd +from datetime import date, timedelta import holidays @@ -154,7 +152,7 @@ def test_easter(self): (2022, 4, 17), ]: easter = date(year, month, day) - easter_thursday = easter + rd(days=-3) - easter_friday = easter + rd(days=-2) + easter_thursday = easter - timedelta(days=3) + easter_friday = easter - timedelta(days=2) for holiday in [easter_thursday, easter_friday, easter]: self.assertIn(holiday, self.holidays) diff --git a/test/countries/test_united_kingdom.py b/test/countries/test_united_kingdom.py index 664c61c26..d92617296 100644 --- a/test/countries/test_united_kingdom.py +++ b/test/countries/test_united_kingdom.py @@ -12,7 +12,7 @@ import unittest from datetime import date -from dateutil.relativedelta import relativedelta as rd +from dateutil.relativedelta import relativedelta import holidays @@ -44,9 +44,9 @@ def test_new_years(self): dt = date(year, 1, 1) self.assertIn(dt, self.holidays) if year == 2000: - self.assertIn(dt + rd(days=-1), self.holidays) + self.assertIn(dt + relativedelta(days=-1), self.holidays) else: - self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + relativedelta(days=-1), self.holidays) def test_good_friday(self): for dt in [ @@ -61,8 +61,8 @@ def test_good_friday(self): date(2020, 4, 10), ]: self.assertIn(dt, self.holidays) - self.assertNotIn(dt + rd(days=-1), self.holidays) - self.assertNotIn(dt + rd(days=+1), self.holidays) + self.assertNotIn(dt + relativedelta(days=-1), self.holidays) + self.assertNotIn(dt + relativedelta(days=+1), self.holidays) def test_easter_monday(self): for dt in [ @@ -77,14 +77,14 @@ def test_easter_monday(self): date(2020, 4, 13), ]: self.assertIn(dt, self.holidays) - self.assertNotIn(dt + rd(days=-1), self.holidays) - self.assertNotIn(dt + rd(days=+1), self.holidays) + self.assertNotIn(dt + relativedelta(days=-1), self.holidays) + self.assertNotIn(dt + relativedelta(days=+1), self.holidays) def test_royal_weddings(self): for dt in [date(1981, 7, 29), date(2011, 4, 29)]: self.assertIn(dt, self.holidays) - self.assertNotIn(dt + rd(years=-1), self.holidays) - self.assertNotIn(dt + rd(years=+1), self.holidays) + self.assertNotIn(dt + relativedelta(years=-1), self.holidays) + self.assertNotIn(dt + relativedelta(years=+1), self.holidays) def test_queens_jubilees(self): for dt in [ @@ -94,16 +94,16 @@ def test_queens_jubilees(self): date(2022, 6, 3), ]: self.assertIn(dt, self.holidays) - self.assertNotIn(dt + rd(years=-1), self.holidays) - self.assertNotIn(dt + rd(years=+1), self.holidays) + self.assertNotIn(dt + relativedelta(years=-1), self.holidays) + self.assertNotIn(dt + relativedelta(years=+1), self.holidays) def test_royal_funerals(self): for dt in [ date(2022, 9, 19), ]: self.assertIn(dt, self.holidays) - self.assertNotIn(dt + rd(years=-1), self.holidays) - self.assertNotIn(dt + rd(years=+1), self.holidays) + self.assertNotIn(dt + relativedelta(years=-1), self.holidays) + self.assertNotIn(dt + relativedelta(years=+1), self.holidays) def test_may_day(self): for dt in [ @@ -119,8 +119,8 @@ def test_may_day(self): date(2020, 5, 8), ]: self.assertIn(dt, self.holidays) - self.assertNotIn(dt + rd(days=-1), self.holidays) - self.assertNotIn(dt + rd(days=+1), self.holidays) + self.assertNotIn(dt + relativedelta(days=-1), self.holidays) + self.assertNotIn(dt + relativedelta(days=+1), self.holidays) self.assertNotIn(date(2020, 5, 4), self.holidays) def test_spring_bank_holiday(self): @@ -137,16 +137,16 @@ def test_spring_bank_holiday(self): date(2022, 6, 2), ]: self.assertIn(dt, self.holidays) - self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + relativedelta(days=-1), self.holidays) if dt != date(2022, 6, 2): - self.assertNotIn(dt + rd(days=+1), self.holidays) + self.assertNotIn(dt + relativedelta(days=+1), self.holidays) def test_christmas_day(self): self.holidays.observed = False for year in range(1900, 2100): dt = date(year, 12, 25) self.assertIn(dt, self.holidays) - self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + relativedelta(days=-1), self.holidays) self.assertNotIn(date(2010, 12, 24), self.holidays) self.assertNotEqual( self.holidays[date(2011, 12, 26)], "Christmas Day (Observed)" @@ -191,7 +191,7 @@ def test_boxing_day(self): for year in range(1900, 2100): dt = date(year, 12, 26) self.assertIn(dt, self.holidays) - self.assertNotIn(dt + rd(days=+1), self.holidays) + self.assertNotIn(dt + relativedelta(days=+1), self.holidays) self.assertNotIn(date(2009, 12, 28), self.holidays) self.assertNotIn(date(2010, 12, 27), self.holidays) self.holidays.observed = True diff --git a/test/countries/test_united_states.py b/test/countries/test_united_states.py index e35db4c93..60247998c 100644 --- a/test/countries/test_united_states.py +++ b/test/countries/test_united_states.py @@ -12,7 +12,7 @@ import unittest from datetime import date -from dateutil.relativedelta import relativedelta as rd +from dateutil.relativedelta import relativedelta import holidays from holidays.constants import SAT, SUN @@ -32,8 +32,8 @@ def test_new_years(self): for year in range(1900, 2100): dt = date(year, 1, 1) self.assertIn(dt, self.holidays) - self.assertNotIn(dt + rd(days=-1), self.holidays) - self.assertNotIn(dt + rd(days=+1), self.holidays) + self.assertNotIn(dt + relativedelta(days=-1), self.holidays) + self.assertNotIn(dt + relativedelta(days=+1), self.holidays) def test_Juneteenth_day(self): @@ -120,8 +120,8 @@ def test_martin_luther(self): date(2020, 1, 20), ]: self.assertIn(dt, self.holidays) - self.assertNotIn(dt + rd(days=-1), self.holidays) - self.assertNotIn(dt + rd(days=+1), self.holidays) + self.assertNotIn(dt + relativedelta(days=-1), self.holidays) + self.assertNotIn(dt + relativedelta(days=+1), self.holidays) self.assertNotIn( "Martin Luther King Jr. Day", holidays.US(years=[1985]).values() ) @@ -288,8 +288,8 @@ def test_washingtons_birthday(self): date(2020, 2, 17), ]: self.assertIn(dt, self.holidays) - self.assertNotIn(dt + rd(days=-1), self.holidays) - self.assertNotIn(dt + rd(days=+1), self.holidays) + self.assertNotIn(dt + relativedelta(days=-1), self.holidays) + self.assertNotIn(dt + relativedelta(days=+1), self.holidays) self.assertNotIn(dt, de_holidays) self.assertNotEqual(fl_holidays.get(dt), "Washington's Birthday") self.assertNotIn(dt, ga_holidays) @@ -622,8 +622,8 @@ def test_truman_day(self): dt = date(year, 5, 8) self.assertNotIn(dt, self.holidays) self.assertIn(dt, mo_holidays) - self.assertNotIn(dt + rd(days=-1), mo_holidays) - self.assertNotIn(dt + rd(days=+1), mo_holidays) + self.assertNotIn(dt + relativedelta(days=-1), mo_holidays) + self.assertNotIn(dt + relativedelta(days=+1), mo_holidays) self.assertNotIn(date(2004, 5, 7), mo_holidays) self.assertNotIn(date(2005, 5, 9), mo_holidays) mo_holidays.observed = True @@ -646,8 +646,8 @@ def test_memorial_day(self): date(2020, 5, 25), ]: self.assertIn(dt, self.holidays) - self.assertNotIn(dt + rd(days=-1), self.holidays) - self.assertNotIn(dt + rd(days=+1), self.holidays) + self.assertNotIn(dt + relativedelta(days=-1), self.holidays) + self.assertNotIn(dt + relativedelta(days=+1), self.holidays) def test_jefferson_davis_birthday(self): al_holidays = holidays.US(subdiv="AL") @@ -726,8 +726,8 @@ def test_independence_day(self): for year in range(1900, 2100): dt = date(year, 7, 4) self.assertIn(dt, self.holidays) - self.assertNotIn(dt + rd(days=-1), self.holidays) - self.assertNotIn(dt + rd(days=+1), self.holidays) + self.assertNotIn(dt + relativedelta(days=-1), self.holidays) + self.assertNotIn(dt + relativedelta(days=+1), self.holidays) self.assertNotIn(date(2010, 7, 5), self.holidays) self.assertNotIn(date(2020, 7, 3), self.holidays) self.holidays.observed = True @@ -843,8 +843,8 @@ def test_labor_day(self): date(2020, 9, 7), ]: self.assertIn(dt, self.holidays) - self.assertNotIn(dt + rd(days=-1), self.holidays) - self.assertNotIn(dt + rd(days=+1), self.holidays) + self.assertNotIn(dt + relativedelta(days=-1), self.holidays) + self.assertNotIn(dt + relativedelta(days=+1), self.holidays) def test_columbus_day(self): ak_holidays = holidays.US(subdiv="AK") @@ -869,8 +869,8 @@ def test_columbus_day(self): self.assertNotIn(dt, de_holidays) self.assertNotIn(dt, fl_holidays) self.assertNotIn(dt, hi_holidays) - self.assertNotIn(dt + rd(days=-1), self.holidays) - self.assertNotIn(dt + rd(days=+1), self.holidays) + self.assertNotIn(dt + relativedelta(days=-1), self.holidays) + self.assertNotIn(dt + relativedelta(days=+1), self.holidays) self.assertEqual(sd_holidays.get(dt), "Native American Day") self.assertEqual( vi_holidays.get(dt), @@ -988,8 +988,8 @@ def test_veterans_day(self): date(2020, 11, 11), ]: self.assertIn(dt, self.holidays) - self.assertNotIn(dt + rd(days=-1), self.holidays) - self.assertNotIn(dt + rd(days=+1), self.holidays) + self.assertNotIn(dt + relativedelta(days=-1), self.holidays) + self.assertNotIn(dt + relativedelta(days=+1), self.holidays) self.assertNotIn("Armistice Day", holidays.US(years=[1937]).values()) self.assertNotIn("Armistice Day", holidays.US(years=[1937]).values()) self.assertIn("Armistice Day", holidays.US(years=[1938]).values()) @@ -1036,64 +1036,66 @@ def test_thanksgiving_day(self): date(2020, 11, 26), ]: self.assertIn(dt, self.holidays) - self.assertNotIn(dt + rd(days=-1), self.holidays) - self.assertNotIn(dt + rd(days=+1), self.holidays) - self.assertIn(dt + rd(days=+1), de_holidays) + self.assertNotIn(dt + relativedelta(days=-1), self.holidays) + self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertIn(dt + relativedelta(days=+1), de_holidays) self.assertEqual( - ca_holidays.get(dt + rd(days=+1)), + ca_holidays.get(dt + relativedelta(days=+1)), "Day After Thanksgiving", ) self.assertEqual( - de_holidays.get(dt + rd(days=+1)), + de_holidays.get(dt + relativedelta(days=+1)), "Day After Thanksgiving", ) self.assertEqual( - nh_holidays.get(dt + rd(days=+1)), + nh_holidays.get(dt + relativedelta(days=+1)), "Day After Thanksgiving", ) self.assertEqual( - nc_holidays.get(dt + rd(days=+1)), + nc_holidays.get(dt + relativedelta(days=+1)), "Day After Thanksgiving", ) self.assertEqual( - ok_holidays.get(dt + rd(days=+1)), + ok_holidays.get(dt + relativedelta(days=+1)), "Day After Thanksgiving", ) self.assertEqual( - pa_holidays.get(dt + rd(days=+1)), + pa_holidays.get(dt + relativedelta(days=+1)), "Day After Thanksgiving", ) self.assertEqual( - wv_holidays.get(dt + rd(days=+1)), + wv_holidays.get(dt + relativedelta(days=+1)), "Day After Thanksgiving", ) - self.assertIn(dt + rd(days=+1), fl_holidays) + self.assertIn(dt + relativedelta(days=+1), fl_holidays) self.assertEqual( - fl_holidays.get(dt + rd(days=+1)), + fl_holidays.get(dt + relativedelta(days=+1)), "Friday After Thanksgiving", ) - self.assertIn(dt + rd(days=+1), tx_holidays) + self.assertIn(dt + relativedelta(days=+1), tx_holidays) self.assertEqual( - tx_holidays.get(dt + rd(days=+1)), + tx_holidays.get(dt + relativedelta(days=+1)), "Friday After Thanksgiving", ) - self.assertEqual(nv_holidays.get(dt + rd(days=+1)), "Family Day") self.assertEqual( - nm_holidays.get(dt + rd(days=+1)), "Presidents' Day" + nv_holidays.get(dt + relativedelta(days=+1)), "Family Day" + ) + self.assertEqual( + nm_holidays.get(dt + relativedelta(days=+1)), "Presidents' Day" ) if dt.year >= 2008: self.assertEqual( - md_holidays.get(dt + rd(days=+1)), + md_holidays.get(dt + relativedelta(days=1)), "American Indian Heritage Day", ) if dt.year >= 2010: self.assertEqual( - in_holidays.get(dt + rd(days=+1)), + in_holidays.get(dt + relativedelta(days=1)), "Lincoln's Birthday", ) else: self.assertNotEqual( - in_holidays.get(dt + rd(days=+1)), + in_holidays.get(dt + relativedelta(days=1)), "Lincoln's Birthday", ) @@ -1190,8 +1192,8 @@ def test_christmas_day(self): for year in range(1900, 2100): dt = date(year, 12, 25) self.assertIn(dt, self.holidays) - self.assertNotIn(dt + rd(days=-1), self.holidays) - self.assertNotIn(dt + rd(days=+1), self.holidays) + self.assertNotIn(dt + relativedelta(days=-1), self.holidays) + self.assertNotIn(dt + relativedelta(days=+1), self.holidays) self.assertNotIn(date(2010, 12, 24), self.holidays) self.assertNotIn(date(2016, 12, 26), self.holidays) self.holidays.observed = True diff --git a/test/countries/test_uruguay.py b/test/countries/test_uruguay.py index 2558f3bef..382e96d6a 100644 --- a/test/countries/test_uruguay.py +++ b/test/countries/test_uruguay.py @@ -12,7 +12,7 @@ import unittest from datetime import date -from dateutil.relativedelta import relativedelta as rd +from dateutil.relativedelta import relativedelta import holidays @@ -32,8 +32,8 @@ def test_new_years(self): for year in range(1900, 2100): dt = date(year, 1, 1) self.assertIn(dt, self.holidays) - self.assertNotIn(dt + rd(days=-1), self.holidays) - self.assertNotIn(dt + rd(days=+1), self.holidays) + self.assertNotIn(dt + relativedelta(days=-1), self.holidays) + self.assertNotIn(dt + relativedelta(days=+1), self.holidays) self.assertEqual(self.holidays[dt], "Año Nuevo [New Year's Day]") def test_labor_day(self): @@ -45,8 +45,8 @@ def test_labor_day(self): for year in range(1900, 2100): dt = date(year, 5, 1) self.assertIn(dt, self.holidays) - self.assertNotIn(dt + rd(days=-1), self.holidays) - self.assertNotIn(dt + rd(days=+1), self.holidays) + self.assertNotIn(dt + relativedelta(days=-1), self.holidays) + self.assertNotIn(dt + relativedelta(days=+1), self.holidays) self.assertEqual( self.holidays[dt], "Día de los Trabajadores [International Workers' Day]", @@ -56,8 +56,8 @@ def test_jura_de_la_constitucion_day(self): for year in range(1900, 2100): dt = date(year, 7, 18) self.assertIn(dt, self.holidays) - self.assertNotIn(dt + rd(days=-1), self.holidays) - self.assertNotIn(dt + rd(days=+1), self.holidays) + self.assertNotIn(dt + relativedelta(days=-1), self.holidays) + self.assertNotIn(dt + relativedelta(days=+1), self.holidays) self.assertEqual( self.holidays[dt], "Jura de la Constitución [Constitution Day]" ) @@ -66,8 +66,8 @@ def test_declaratoria_de_la_independencia_day(self): for year in range(1900, 2100): dt = date(year, 8, 25) self.assertIn(dt, self.holidays) - self.assertNotIn(dt + rd(days=-1), self.holidays) - self.assertNotIn(dt + rd(days=+1), self.holidays) + self.assertNotIn(dt + relativedelta(days=-1), self.holidays) + self.assertNotIn(dt + relativedelta(days=+1), self.holidays) self.assertEqual( self.holidays[dt], "Día de la Independencia [Independence Day]" ) @@ -76,8 +76,8 @@ def test_christmas(self): for year in range(1900, 2100): dt = date(year, 12, 25) self.assertIn(dt, self.holidays) - self.assertNotIn(dt + rd(days=-1), self.holidays) - self.assertNotIn(dt + rd(days=+1), self.holidays) + self.assertNotIn(dt + relativedelta(days=-1), self.holidays) + self.assertNotIn(dt + relativedelta(days=+1), self.holidays) self.assertEqual( self.holidays[dt], "Día de la Familia [Day of the Family]" ) @@ -97,8 +97,8 @@ def test_natalicio_artigas_day(self): for year in range(1900, 2100): dt = date(year, 6, 19) self.assertIn(dt, self.holidays) - self.assertNotIn(dt + rd(days=-1), self.holidays) - self.assertNotIn(dt + rd(days=+1), self.holidays) + self.assertNotIn(dt + relativedelta(days=-1), self.holidays) + self.assertNotIn(dt + relativedelta(days=+1), self.holidays) self.assertEqual( self.holidays[dt], "Natalicio de José Gervasio Artigas " @@ -109,8 +109,8 @@ def test_dia_de_los_difuntos_day(self): for year in range(1900, 2100): dt = date(year, 11, 2) self.assertIn(dt, self.holidays) - self.assertNotIn(dt + rd(days=-1), self.holidays) - self.assertNotIn(dt + rd(days=+1), self.holidays) + self.assertNotIn(dt + relativedelta(days=-1), self.holidays) + self.assertNotIn(dt + relativedelta(days=+1), self.holidays) self.assertEqual( self.holidays[dt], "Día de los Difuntos [All Souls' Day]" ) diff --git a/test/countries/test_venezuela.py b/test/countries/test_venezuela.py index dec4f1e21..1feeaf201 100644 --- a/test/countries/test_venezuela.py +++ b/test/countries/test_venezuela.py @@ -10,9 +10,7 @@ # License: MIT (see LICENSE file) import unittest -from datetime import date - -from dateutil.relativedelta import relativedelta as rd +from datetime import date, timedelta import holidays from holidays.constants import JAN, FEB, MAR, APR, MAY, JUN, JUL, OCT, DEC @@ -25,7 +23,7 @@ def setUp(self): def _check_all_dates(self, year, expected_holidays): start_date = date(year, 1, 1) end_date = date(year, 12, 31) - delta = rd(days=+1) + delta = timedelta(days=1) while start_date <= end_date: if start_date in expected_holidays: diff --git a/test/countries/test_vietnam.py b/test/countries/test_vietnam.py index 3889e6581..c1aace864 100644 --- a/test/countries/test_vietnam.py +++ b/test/countries/test_vietnam.py @@ -12,7 +12,7 @@ import unittest from datetime import date -from dateutil.relativedelta import relativedelta as rd +from dateutil.relativedelta import relativedelta import holidays @@ -51,27 +51,27 @@ def test_lunar_new_year(self): (2022, 2, 1), ): self.assertEqual( - self.holidays[date(year, month, day) + rd(days=-1)], + self.holidays[date(year, month, day) + relativedelta(days=-1)], "Vietnamese New Year's Eve", ) self.assertEqual( - self.holidays[date(year, month, day)], + self.holidays[date(year, month, day) + relativedelta(days=0)], "Vietnamese New Year", ) self.assertEqual( - self.holidays[date(year, month, day) + rd(days=+1)], + self.holidays[date(year, month, day) + relativedelta(days=+1)], "The second day of Tet Holiday", ) self.assertEqual( - self.holidays[date(year, month, day) + rd(days=+2)], + self.holidays[date(year, month, day) + relativedelta(days=+2)], "The third day of Tet Holiday", ) self.assertEqual( - self.holidays[date(year, month, day) + rd(days=+3)], + self.holidays[date(year, month, day) + relativedelta(days=+3)], "The forth day of Tet Holiday", ) self.assertEqual( - self.holidays[date(year, month, day) + rd(days=+4)], + self.holidays[date(year, month, day) + relativedelta(days=+4)], "The fifth day of Tet Holiday", ) diff --git a/test/financial/test_european_central_bank.py b/test/financial/test_european_central_bank.py index 262a06cb9..7294c621f 100644 --- a/test/financial/test_european_central_bank.py +++ b/test/financial/test_european_central_bank.py @@ -12,7 +12,7 @@ import unittest from datetime import date -from dateutil.relativedelta import relativedelta as rd +from dateutil.relativedelta import relativedelta import holidays @@ -25,7 +25,7 @@ def test_new_years(self): for year in range(1974, 2100): dt = date(year, 1, 1) self.assertIn(dt, self.holidays) - self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + relativedelta(days=-1), self.holidays) def test_good_friday(self): for dt in [ @@ -40,8 +40,8 @@ def test_good_friday(self): date(2020, 4, 10), ]: self.assertIn(dt, self.holidays) - self.assertNotIn(dt + rd(days=-1), self.holidays) - self.assertNotIn(dt + rd(days=+1), self.holidays) + self.assertNotIn(dt + relativedelta(days=-1), self.holidays) + self.assertNotIn(dt + relativedelta(days=+1), self.holidays) def test_easter_monday(self): for dt in [ @@ -56,27 +56,27 @@ def test_easter_monday(self): date(2020, 4, 13), ]: self.assertIn(dt, self.holidays) - self.assertNotIn(dt + rd(days=-1), self.holidays) - self.assertNotIn(dt + rd(days=+1), self.holidays) + self.assertNotIn(dt + relativedelta(days=-1), self.holidays) + self.assertNotIn(dt + relativedelta(days=+1), self.holidays) def test_labour_day(self): for year in range(1900, 2100): dt = date(year, 5, 1) self.assertIn(dt, self.holidays) - self.assertNotIn(dt + rd(days=-1), self.holidays) - self.assertNotIn(dt + rd(days=+1), self.holidays) + self.assertNotIn(dt + relativedelta(days=-1), self.holidays) + self.assertNotIn(dt + relativedelta(days=+1), self.holidays) def test_christmas_day(self): for year in range(1900, 2100): dt = date(year, 12, 25) self.assertIn(dt, self.holidays) - self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + relativedelta(days=-1), self.holidays) def test_26_december_day(self): for year in range(1900, 2100): dt = date(year, 12, 26) self.assertIn(dt, self.holidays) - self.assertNotIn(dt + rd(days=+1), self.holidays) + self.assertNotIn(dt + relativedelta(days=+1), self.holidays) def test_all_holidays_present(self): tar_2015 = holidays.TAR(years=[2015]) diff --git a/test/financial/test_ny_stock_exchange.py b/test/financial/test_ny_stock_exchange.py index b6eb09d8a..ff5c2a757 100644 --- a/test/financial/test_ny_stock_exchange.py +++ b/test/financial/test_ny_stock_exchange.py @@ -10,7 +10,7 @@ # License: MIT (see LICENSE file) import unittest -from datetime import date +from datetime import date, timedelta from dateutil.relativedelta import WE from dateutil.relativedelta import relativedelta as rd @@ -420,7 +420,8 @@ def test_special_holidays(self): def _make_special_holiday_list(begin, end, days=None, weekends=False): _list = [] for d in ( - begin + rd(days=n) for n in range((end - begin).days + 1) + begin + timedelta(days=n) + for n in range((end - begin).days + 1) ): if not weekends and d.weekday() in {SAT, SUN}: continue @@ -453,14 +454,14 @@ def _make_special_holiday_list(begin, end, days=None, weekends=False): date(1968, JUN, 12), # begin paper crisis holidays ]: self.assertIn(dt, self.holidays) - self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt - timedelta(days=1), self.holidays) for dt in [ date(1914, NOV, 27), # end WWI holidays date(1933, MAR, 14), # end oneoff bank holidays ]: self.assertIn(dt, self.holidays) - self.assertNotIn(dt + rd(days=+1), self.holidays) + self.assertNotIn(dt + timedelta(days=1), self.holidays) def test_all_modern_holidays_present(self): nyse_2021 = holidays.NewYorkStockExchange(years=[2021]) From 5b85fec60c40b5f78bf6cd12cc0fa9d9aaf59b91 Mon Sep 17 00:00:00 2001 From: Arkadii Yakovets Date: Mon, 16 Jan 2023 16:12:54 -0800 Subject: [PATCH 124/138] Clean up timedelta/relativedelta usage (tests): - Standardize `relativedelta` days usage - Replace `timedelta` with `relativedelta` --- test/countries/test_argentina.py | 46 +++++------ test/countries/test_australia.py | 8 +- test/countries/test_austria.py | 24 +++--- test/countries/test_bulgaria.py | 10 ++- test/countries/test_canada.py | 70 ++++++++--------- test/countries/test_colombia.py | 6 +- test/countries/test_cuba.py | 6 +- test/countries/test_ireland.py | 8 +- test/countries/test_israel.py | 42 +++------- test/countries/test_mexico.py | 34 ++++---- test/countries/test_new_zealand.py | 18 ++--- test/countries/test_paraguay.py | 8 +- test/countries/test_united_kingdom.py | 38 ++++----- test/countries/test_united_states.py | 82 ++++++++++---------- test/countries/test_uruguay.py | 30 +++---- test/countries/test_venezuela.py | 6 +- test/countries/test_vietnam.py | 14 ++-- test/financial/test_european_central_bank.py | 20 ++--- test/financial/test_ny_stock_exchange.py | 9 +-- 19 files changed, 233 insertions(+), 246 deletions(-) diff --git a/test/countries/test_argentina.py b/test/countries/test_argentina.py index bb3598c5d..d1e275124 100644 --- a/test/countries/test_argentina.py +++ b/test/countries/test_argentina.py @@ -11,7 +11,7 @@ from datetime import date -from dateutil.relativedelta import relativedelta +from dateutil.relativedelta import relativedelta as rd from holidays.constants import MAY, JUN, JUL, AUG, OCT from holidays.countries.argentina import AR, ARG, Argentina @@ -41,8 +41,8 @@ def test_new_years_day(self): dt = date(year, 1, 1) self.assertHoliday(dt) self.assertNoHoliday( - dt + relativedelta(days=-1), - dt + relativedelta(days=+1), + dt + rd(days=-1), + dt + rd(days=+1), ) def test_carnival_day(self): @@ -98,8 +98,8 @@ def test_labor_day(self): dt = date(year, MAY, 1) self.assertHoliday(dt) self.assertNoHoliday( - dt + relativedelta(days=-1), - dt + relativedelta(days=+1), + dt + rd(days=-1), + dt + rd(days=+1), ) def test_may_revolution_day(self): @@ -114,8 +114,8 @@ def test_may_revolution_day(self): dt = date(year, MAY, 25) self.assertHoliday(dt) self.assertNoHoliday( - dt + relativedelta(days=-1), - dt + relativedelta(days=+1), + dt + rd(days=-1), + dt + rd(days=+1), ) def test_guemes_day(self): @@ -123,8 +123,8 @@ def test_guemes_day(self): dt = date(year, JUN, 17) self.assertHoliday(dt) self.assertNoHoliday( - dt + relativedelta(days=-1), - dt + relativedelta(days=+1), + dt + rd(days=-1), + dt + rd(days=+1), ) def test_belgrano_day(self): @@ -132,8 +132,8 @@ def test_belgrano_day(self): dt = date(year, JUN, 20) self.assertHoliday(dt) self.assertNoHoliday( - dt + relativedelta(days=-1), - dt + relativedelta(days=+1), + dt + rd(days=-1), + dt + rd(days=+1), ) def test_independence_day(self): @@ -153,8 +153,8 @@ def test_independence_day(self): dt = date(year, JUL, 9) self.assertHoliday(dt) self.assertNoHoliday( - dt + relativedelta(days=-1), - dt + relativedelta(days=+1), + dt + rd(days=-1), + dt + rd(days=+1), ) def test_san_martin_day(self): @@ -169,8 +169,8 @@ def test_san_martin_day(self): dt = date(year, AUG, 17) self.assertHoliday(dt) self.assertNoHoliday( - dt + relativedelta(days=-1), - dt + relativedelta(days=+1), + dt + rd(days=-1), + dt + rd(days=+1), ) def test_cultural_day(self): @@ -185,8 +185,8 @@ def test_cultural_day(self): dt = date(year, OCT, 12) self.assertHoliday(dt) self.assertNoHoliday( - dt + relativedelta(days=-1), - dt + relativedelta(days=+1), + dt + rd(days=-1), + dt + rd(days=+1), ) def test_national_sovereignty_day(self): @@ -197,8 +197,8 @@ def test_national_sovereignty_day(self): else: self.assertHoliday(dt) self.assertNoHoliday( - dt + relativedelta(days=-1), - dt + relativedelta(days=+1), + dt + rd(days=-1), + dt + rd(days=+1), ) def test_immaculate_conception_day(self): @@ -213,8 +213,8 @@ def test_immaculate_conception_day(self): dt = date(year, 12, 8) self.assertHoliday(dt) self.assertNoHoliday( - dt + relativedelta(days=-1), - dt + relativedelta(days=+1), + dt + rd(days=-1), + dt + rd(days=+1), ) def test_christmas(self): @@ -222,8 +222,8 @@ def test_christmas(self): dt = date(year, 12, 25) self.assertHoliday(dt) self.assertNoHoliday( - dt + relativedelta(days=-1), - dt + relativedelta(days=+1), + dt + rd(days=-1), + dt + rd(days=+1), ) def test_2022(self): diff --git a/test/countries/test_australia.py b/test/countries/test_australia.py index b82be0d24..8a4df7950 100644 --- a/test/countries/test_australia.py +++ b/test/countries/test_australia.py @@ -12,7 +12,7 @@ import unittest from datetime import date -from dateutil.relativedelta import relativedelta +from dateutil.relativedelta import relativedelta as rd import holidays @@ -125,7 +125,7 @@ def test_easter_monday(self): ]: self.assertIn(dt, self.holidays) self.assertEqual(self.holidays[dt], "Easter Monday") - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) def test_bank_holiday(self): for dt in [ @@ -328,7 +328,7 @@ def test_christmas_day(self): for year in range(1900, 2100): dt = date(year, 12, 25) self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) self.assertNotIn(date(2010, 12, 24), self.holidays) self.assertNotEqual( self.holidays[date(2011, 12, 26)], "Christmas Day (Observed)" @@ -372,7 +372,7 @@ def test_boxing_day(self): for year in range(1900, 2100): dt = date(year, 12, 26) self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) self.assertNotIn(date(2009, 12, 28), self.holidays) self.assertNotIn(date(2010, 12, 27), self.holidays) self.holidays.observed = True diff --git a/test/countries/test_austria.py b/test/countries/test_austria.py index 42c5da34c..8c8c48d02 100644 --- a/test/countries/test_austria.py +++ b/test/countries/test_austria.py @@ -12,7 +12,7 @@ import unittest from datetime import date -from dateutil.relativedelta import relativedelta +from dateutil.relativedelta import relativedelta as rd import holidays @@ -25,16 +25,16 @@ def test_new_years(self): for year in range(1900, 2100): dt = date(year, 1, 1) self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) def test_christmas(self): for year in range(1900, 2100): dt = date(year, 12, 25) self.assertIn(dt, self.holidays) - self.assertIn(dt + relativedelta(days=+1), self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+2), self.holidays) + self.assertIn(dt + rd(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=+2), self.holidays) def test_easter_monday(self): for dt in [ @@ -49,20 +49,20 @@ def test_easter_monday(self): date(2020, 4, 13), ]: self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) def test_national_day(self): for year in range(1919, 1934): dt = date(year, 11, 12) self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) for year in range(1967, 2100): dt = date(year, 10, 26) self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) def test_all_holidays_present(self): at_2015 = holidays.AT(years=[2015]) diff --git a/test/countries/test_bulgaria.py b/test/countries/test_bulgaria.py index c67d8c76e..c9ce8fc48 100644 --- a/test/countries/test_bulgaria.py +++ b/test/countries/test_bulgaria.py @@ -10,7 +10,9 @@ # License: MIT (see LICENSE file) import unittest -from datetime import date, timedelta +from datetime import date + +from dateutil.relativedelta import relativedelta as rd import holidays @@ -87,9 +89,9 @@ def test_easter(self): (2022, 4, 24), ]: easter = date(year, month, day) - easter_friday = easter - timedelta(days=2) - easter_saturday = easter - timedelta(days=1) - easter_monday = easter + timedelta(days=1) + easter_friday = easter + rd(days=-2) + easter_saturday = easter + rd(days=-1) + easter_monday = easter + rd(days=+1) for holiday in [ easter_friday, easter_saturday, diff --git a/test/countries/test_canada.py b/test/countries/test_canada.py index 865c5e3cd..793856479 100644 --- a/test/countries/test_canada.py +++ b/test/countries/test_canada.py @@ -12,7 +12,7 @@ import unittest from datetime import date -from dateutil.relativedelta import relativedelta +from dateutil.relativedelta import relativedelta as rd import holidays @@ -34,8 +34,8 @@ def test_new_years(self): for year in range(1900, 2100): dt = date(year, 1, 1) self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) def test_islander_day(self): pei_holidays = holidays.CA(subdiv="PE") @@ -55,8 +55,8 @@ def test_islander_day(self): elif dt.year == 2009: self.assertNotIn(dt, self.holidays) self.assertIn(dt, pei_holidays) - self.assertNotIn(dt + relativedelta(days=-1), pei_holidays) - self.assertNotIn(dt + relativedelta(days=+1), pei_holidays) + self.assertNotIn(dt + rd(days=-1), pei_holidays) + self.assertNotIn(dt + rd(days=+1), pei_holidays) def test_yukon_heritage_day(self): # https://www.timeanddate.com/holidays/canada/heritage-day-yukon @@ -70,8 +70,8 @@ def test_yukon_heritage_day(self): date(2022, 2, 25), ]: self.assertIn(dt, yt_holidays) - self.assertNotIn(dt + relativedelta(days=-1), yt_holidays) - self.assertNotIn(dt + relativedelta(days=+1), yt_holidays) + self.assertNotIn(dt + rd(days=-1), yt_holidays) + self.assertNotIn(dt + rd(days=+1), yt_holidays) def test_family_day(self): ab_holidays = holidays.CA(subdiv="AB") @@ -140,8 +140,8 @@ def test_st_patricks_day(self): ]: self.assertNotIn(dt, self.holidays) self.assertIn(dt, nl_holidays) - self.assertNotIn(dt + relativedelta(days=-1), nl_holidays) - self.assertNotIn(dt + relativedelta(days=+1), nl_holidays) + self.assertNotIn(dt + rd(days=-1), nl_holidays) + self.assertNotIn(dt + rd(days=+1), nl_holidays) def test_good_friday(self): for dt in [ @@ -156,8 +156,8 @@ def test_good_friday(self): date(2020, 4, 10), ]: self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) def test_easter_monday(self): for dt in [ @@ -172,8 +172,8 @@ def test_easter_monday(self): date(2020, 4, 13), ]: self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) def test_st_georges_day(self): nl_holidays = holidays.CA(subdiv="NL") @@ -186,8 +186,8 @@ def test_st_georges_day(self): ]: self.assertNotIn(dt, self.holidays) self.assertIn(dt, nl_holidays) - self.assertNotIn(dt + relativedelta(days=-1), nl_holidays) - self.assertNotIn(dt + relativedelta(days=+1), nl_holidays) + self.assertNotIn(dt + rd(days=-1), nl_holidays) + self.assertNotIn(dt + rd(days=+1), nl_holidays) def test_victoria_day(self): for dt in [ @@ -199,8 +199,8 @@ def test_victoria_day(self): date(2020, 5, 18), ]: self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) def test_national_aboriginal_day(self): nt_holidays = holidays.CA(subdiv="NT") @@ -209,8 +209,8 @@ def test_national_aboriginal_day(self): dt = date(year, 6, 21) self.assertNotIn(dt, self.holidays) self.assertIn(dt, nt_holidays) - self.assertNotIn(dt + relativedelta(days=-1), nt_holidays) - self.assertNotIn(dt + relativedelta(days=+1), nt_holidays) + self.assertNotIn(dt + rd(days=-1), nt_holidays) + self.assertNotIn(dt + rd(days=+1), nt_holidays) def test_st_jean_baptiste_day(self): qc_holidays = holidays.CA(subdiv="QC", observed=False) @@ -219,8 +219,8 @@ def test_st_jean_baptiste_day(self): dt = date(year, 6, 24) self.assertNotIn(dt, self.holidays) self.assertIn(dt, qc_holidays) - self.assertNotIn(dt + relativedelta(days=-1), qc_holidays) - self.assertNotIn(dt + relativedelta(days=+1), qc_holidays) + self.assertNotIn(dt + rd(days=-1), qc_holidays) + self.assertNotIn(dt + rd(days=+1), qc_holidays) self.assertNotIn(date(2001, 6, 25), qc_holidays) qc_holidays.observed = True self.assertIn(date(2001, 6, 25), qc_holidays) @@ -255,8 +255,8 @@ def test_canada_day(self): for year in range(1900, 2100): dt = date(year, 7, 1) self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) self.assertNotIn(date(2006, 7, 3), self.holidays) self.assertNotIn(date(2007, 7, 2), self.holidays) self.holidays.observed = True @@ -272,8 +272,8 @@ def test_nunavut_day(self): dt = date(year, 7, 9) self.assertNotIn(dt, self.holidays) self.assertIn(dt, nu_holidays) - self.assertNotIn(dt + relativedelta(days=-1), nu_holidays) - self.assertNotIn(dt + relativedelta(days=+1), nu_holidays) + self.assertNotIn(dt + rd(days=-1), nu_holidays) + self.assertNotIn(dt + rd(days=+1), nu_holidays) self.assertNotIn(date(2017, 7, 10), nu_holidays) nu_holidays.observed = True self.assertIn(date(2017, 7, 10), nu_holidays) @@ -305,8 +305,8 @@ def test_labour_day(self): date(2015, 9, 7), ]: self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) def test_national_day_for_truth_and_reconciliation(self): for dt in [ @@ -314,14 +314,14 @@ def test_national_day_for_truth_and_reconciliation(self): date(2020, 9, 30), ]: self.assertNotIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) mb_holidays = holidays.CA(subdiv="MB") for dt in [ date(2021, 9, 30), date(2030, 9, 30), ]: self.assertIn(dt, mb_holidays) - self.assertNotIn(dt + relativedelta(days=-1), mb_holidays) + self.assertNotIn(dt + rd(days=-1), mb_holidays) self.assertNotIn(dt, self.holidays) def test_thanksgiving(self): @@ -335,8 +335,8 @@ def test_thanksgiving(self): date(2020, 10, 12), ]: self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) self.assertNotIn(dt, ns_holidays) def test_remembrance_day(self): @@ -349,8 +349,8 @@ def test_remembrance_day(self): self.assertNotIn(dt, self.holidays) self.assertIn(dt, ab_holidays) self.assertIn(dt, nl_holidays) - self.assertNotIn(dt + relativedelta(days=-1), nl_holidays) - self.assertNotIn(dt + relativedelta(days=+1), nl_holidays) + self.assertNotIn(dt + rd(days=-1), nl_holidays) + self.assertNotIn(dt + rd(days=+1), nl_holidays) self.assertNotIn(date(2007, 11, 12), ab_holidays) self.assertNotIn(date(2007, 11, 12), nl_holidays) ab_holidays.observed = True @@ -363,7 +363,7 @@ def test_christmas_day(self): for year in range(1900, 2100): dt = date(year, 12, 25) self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) self.assertNotIn(date(2010, 12, 27), self.holidays) self.assertNotEqual( self.holidays[date(2011, 12, 26)], "Christmas Day (Observed)" @@ -378,7 +378,7 @@ def test_boxing_day(self): for year in range(1900, 2100): dt = date(year, 12, 26) self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) self.assertNotIn(date(2009, 12, 28), self.holidays) self.assertNotIn(date(2010, 12, 27), self.holidays) self.holidays.observed = True diff --git a/test/countries/test_colombia.py b/test/countries/test_colombia.py index 41fcae245..51eecb80b 100644 --- a/test/countries/test_colombia.py +++ b/test/countries/test_colombia.py @@ -10,7 +10,9 @@ # License: MIT (see LICENSE file) import unittest -from datetime import date, timedelta +from datetime import date + +from dateutil.relativedelta import relativedelta as rd import holidays from holidays.constants import APR, AUG, DEC, JAN, JUL, JUN, MAR, MAY, NOV, OCT @@ -23,7 +25,7 @@ def setUp(self): def _check_all_dates(self, year, expected_holidays): start_date = date(year, 1, 1) end_date = date(year, 12, 31) - delta = timedelta(days=1) + delta = rd(days=+1) while start_date <= end_date: if start_date in expected_holidays: diff --git a/test/countries/test_cuba.py b/test/countries/test_cuba.py index fb7137595..dc6eaa945 100644 --- a/test/countries/test_cuba.py +++ b/test/countries/test_cuba.py @@ -10,7 +10,9 @@ # License: MIT (see LICENSE file) import unittest -from datetime import date, timedelta +from datetime import date + +from dateutil.relativedelta import relativedelta as rd import holidays from holidays.constants import APR, DEC, JAN, JUL, MAR, MAY, OCT @@ -23,7 +25,7 @@ def setUp(self): def _check_all_dates(self, year, expected_holidays): start_date = date(year, 1, 1) end_date = date(year, 12, 31) - delta = timedelta(days=1) + delta = rd(days=+1) while start_date <= end_date: if start_date in expected_holidays: diff --git a/test/countries/test_ireland.py b/test/countries/test_ireland.py index b6986738f..7ff344e35 100644 --- a/test/countries/test_ireland.py +++ b/test/countries/test_ireland.py @@ -12,7 +12,7 @@ import unittest from datetime import date -from dateutil.relativedelta import relativedelta +from dateutil.relativedelta import relativedelta as rd import holidays @@ -49,8 +49,8 @@ def test_may_day(self): date(2020, 5, 4), ]: self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) def test_st_stephens_day(self): # St. Stephen's Day @@ -59,7 +59,7 @@ def test_st_stephens_day(self): for year in range(1900, 2100): dt = date(year, 12, 26) self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) self.assertNotIn(date(2009, 12, 28), self.holidays) self.assertNotIn(date(2010, 12, 27), self.holidays) self.holidays.observed = True diff --git a/test/countries/test_israel.py b/test/countries/test_israel.py index dfbcf36eb..8abacee4a 100644 --- a/test/countries/test_israel.py +++ b/test/countries/test_israel.py @@ -12,7 +12,7 @@ import unittest from datetime import date -from dateutil.relativedelta import relativedelta +from dateutil.relativedelta import relativedelta as rd import holidays @@ -42,12 +42,8 @@ def _test_observed_holidays(self, holiday_name): # Postponed il_holidays = holidays.IL(years=[2017], observed=True) - official_memorial_day = date(2017, 4, 30) + relativedelta( - days=days_delta - ) - observed_memorial_day = date(2017, 5, 1) + relativedelta( - days=days_delta - ) + official_memorial_day = date(2017, 4, 30) + rd(days=days_delta) + observed_memorial_day = date(2017, 5, 1) + rd(days=days_delta) self.assertIn(official_memorial_day, il_holidays) self.assertIn(holiday_name, il_holidays[official_memorial_day]) self.assertIn(observed_memorial_day, il_holidays) @@ -57,12 +53,8 @@ def _test_observed_holidays(self, holiday_name): # Earlier il_holidays = holidays.IL(years=[2018], observed=True) - official_memorial_day = date(2018, 4, 19) + relativedelta( - days=days_delta - ) - observed_memorial_day = date(2018, 4, 18) + relativedelta( - days=days_delta - ) + official_memorial_day = date(2018, 4, 19) + rd(days=days_delta) + observed_memorial_day = date(2018, 4, 18) + rd(days=days_delta) self.assertIn(official_memorial_day, il_holidays) self.assertIn(holiday_name, il_holidays[official_memorial_day]) self.assertIn(observed_memorial_day, il_holidays) @@ -72,9 +64,7 @@ def _test_observed_holidays(self, holiday_name): # On time il_holidays = holidays.IL(years=[2020], observed=True) - official_memorial_day = date(2020, 4, 28) + relativedelta( - days=days_delta - ) + official_memorial_day = date(2020, 4, 28) + rd(days=days_delta) self.assertIn(official_memorial_day, il_holidays) self.assertIn(holiday_name, il_holidays[official_memorial_day]) @@ -86,33 +76,23 @@ def _test_nonobserved_holidays(self, holiday_name): # Postponed il_holidays = holidays.IL(years=[2017], observed=False) - official_memorial_day = date(2017, 4, 30) + relativedelta( - days=days_delta - ) - observed_memorial_day = date(2017, 5, 1) + relativedelta( - days=days_delta - ) + official_memorial_day = date(2017, 4, 30) + rd(days=days_delta) + observed_memorial_day = date(2017, 5, 1) + rd(days=days_delta) self.assertIn(official_memorial_day, il_holidays) self.assertIn(holiday_name, il_holidays[official_memorial_day]) self.assertNotEqual(il_holidays[observed_memorial_day], "Memorial Day") # Earlier il_holidays = holidays.IL(years=[2018], observed=False) - official_memorial_day = date(2018, 4, 19) + relativedelta( - days=days_delta - ) - observed_memorial_day = date(2018, 4, 18) + relativedelta( - days=days_delta - ) + official_memorial_day = date(2018, 4, 19) + rd(days=days_delta) + observed_memorial_day = date(2018, 4, 18) + rd(days=days_delta) self.assertIn(official_memorial_day, il_holidays) self.assertIn(holiday_name, il_holidays[official_memorial_day]) self.assertNotIn(observed_memorial_day, il_holidays) # On time il_holidays = holidays.IL(years=[2020], observed=False) - official_memorial_day = date(2020, 4, 28) + relativedelta( - days=days_delta - ) + official_memorial_day = date(2020, 4, 28) + rd(days=days_delta) self.assertIn(official_memorial_day, il_holidays) self.assertIn(holiday_name, il_holidays[official_memorial_day]) diff --git a/test/countries/test_mexico.py b/test/countries/test_mexico.py index 0a11cb9a7..7ce118587 100644 --- a/test/countries/test_mexico.py +++ b/test/countries/test_mexico.py @@ -12,7 +12,7 @@ import unittest from datetime import date -from dateutil.relativedelta import relativedelta +from dateutil.relativedelta import relativedelta as rd import holidays @@ -31,8 +31,8 @@ def test_new_years(self): for year in range(1900, 2100): dt = date(year, 1, 1) self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) def test_constitution_day(self): for dt in [ @@ -48,8 +48,8 @@ def test_constitution_day(self): date(2022, 2, 5), ]: self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) self.holidays.observed = True for dt in [ date(2005, 2, 5), @@ -89,8 +89,8 @@ def test_benito_juarez(self): date(2024, 3, 21), ]: self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) self.holidays.observed = True for dt in [ date(2005, 3, 21), @@ -130,8 +130,8 @@ def test_labor_day(self): for year in range(1923, 2100): dt = date(year, 5, 1) self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) def test_independence_day(self): self.assertNotIn(date(2006, 9, 15), self.holidays) @@ -143,8 +143,8 @@ def test_independence_day(self): for year in range(1900, 2100): dt = date(year, 9, 16) self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) def test_revolution_day(self): for dt in [ @@ -162,8 +162,8 @@ def test_revolution_day(self): date(2023, 11, 20), ]: self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) self.holidays.observed = True for dt in [ date(2005, 11, 20), @@ -190,8 +190,8 @@ def test_change_of_government(self): dt = date(year, 12, 1) if (year >= 1970) and ((2096 - year) % 6) == 0: self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) else: self.assertNotIn(dt, self.holidays) @@ -199,8 +199,8 @@ def test_christmas(self): for year in range(1900, 2100): dt = date(year, 12, 25) self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) self.assertNotIn(date(2010, 12, 24), self.holidays) self.assertNotIn(date(2016, 12, 26), self.holidays) self.holidays.observed = True diff --git a/test/countries/test_new_zealand.py b/test/countries/test_new_zealand.py index 4d20a5edc..821eb614d 100644 --- a/test/countries/test_new_zealand.py +++ b/test/countries/test_new_zealand.py @@ -12,7 +12,7 @@ import unittest from datetime import date -from dateutil.relativedelta import relativedelta +from dateutil.relativedelta import relativedelta as rd import holidays @@ -150,8 +150,8 @@ def test_good_friday(self): date(2020, 4, 10), ]: self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) def test_easter_monday(self): for dt in [ @@ -165,8 +165,8 @@ def test_easter_monday(self): date(2020, 4, 13), ]: self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) def test_anzac_day(self): for year in range(1900, 1921): @@ -284,8 +284,8 @@ def test_matariki(self): ]: self.assertIn(dt, self.holidays) self.assertEqual(self.holidays[dt], "Matariki") - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) def test_labour_day(self): for year, day in enumerate( @@ -323,7 +323,7 @@ def test_christmas_day(self): for year in range(1900, 2100): dt = date(year, 12, 25) self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) self.assertNotIn(date(2010, 12, 24), self.holidays) self.assertNotEqual( self.holidays[date(2011, 12, 26)], "Christmas Day (Observed)" @@ -367,7 +367,7 @@ def test_boxing_day(self): for year in range(1900, 2100): dt = date(year, 12, 26) self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) self.assertNotIn(date(2009, 12, 28), self.holidays) self.assertNotIn(date(2010, 12, 27), self.holidays) self.holidays.observed = True diff --git a/test/countries/test_paraguay.py b/test/countries/test_paraguay.py index 745a11f40..01f57886e 100644 --- a/test/countries/test_paraguay.py +++ b/test/countries/test_paraguay.py @@ -10,7 +10,9 @@ # License: MIT (see LICENSE file) import unittest -from datetime import date, timedelta +from datetime import date + +from dateutil.relativedelta import relativedelta as rd import holidays @@ -152,7 +154,7 @@ def test_easter(self): (2022, 4, 17), ]: easter = date(year, month, day) - easter_thursday = easter - timedelta(days=3) - easter_friday = easter - timedelta(days=2) + easter_thursday = easter + rd(days=-3) + easter_friday = easter + rd(days=-2) for holiday in [easter_thursday, easter_friday, easter]: self.assertIn(holiday, self.holidays) diff --git a/test/countries/test_united_kingdom.py b/test/countries/test_united_kingdom.py index d92617296..664c61c26 100644 --- a/test/countries/test_united_kingdom.py +++ b/test/countries/test_united_kingdom.py @@ -12,7 +12,7 @@ import unittest from datetime import date -from dateutil.relativedelta import relativedelta +from dateutil.relativedelta import relativedelta as rd import holidays @@ -44,9 +44,9 @@ def test_new_years(self): dt = date(year, 1, 1) self.assertIn(dt, self.holidays) if year == 2000: - self.assertIn(dt + relativedelta(days=-1), self.holidays) + self.assertIn(dt + rd(days=-1), self.holidays) else: - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) def test_good_friday(self): for dt in [ @@ -61,8 +61,8 @@ def test_good_friday(self): date(2020, 4, 10), ]: self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) def test_easter_monday(self): for dt in [ @@ -77,14 +77,14 @@ def test_easter_monday(self): date(2020, 4, 13), ]: self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) def test_royal_weddings(self): for dt in [date(1981, 7, 29), date(2011, 4, 29)]: self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(years=-1), self.holidays) - self.assertNotIn(dt + relativedelta(years=+1), self.holidays) + self.assertNotIn(dt + rd(years=-1), self.holidays) + self.assertNotIn(dt + rd(years=+1), self.holidays) def test_queens_jubilees(self): for dt in [ @@ -94,16 +94,16 @@ def test_queens_jubilees(self): date(2022, 6, 3), ]: self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(years=-1), self.holidays) - self.assertNotIn(dt + relativedelta(years=+1), self.holidays) + self.assertNotIn(dt + rd(years=-1), self.holidays) + self.assertNotIn(dt + rd(years=+1), self.holidays) def test_royal_funerals(self): for dt in [ date(2022, 9, 19), ]: self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(years=-1), self.holidays) - self.assertNotIn(dt + relativedelta(years=+1), self.holidays) + self.assertNotIn(dt + rd(years=-1), self.holidays) + self.assertNotIn(dt + rd(years=+1), self.holidays) def test_may_day(self): for dt in [ @@ -119,8 +119,8 @@ def test_may_day(self): date(2020, 5, 8), ]: self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) self.assertNotIn(date(2020, 5, 4), self.holidays) def test_spring_bank_holiday(self): @@ -137,16 +137,16 @@ def test_spring_bank_holiday(self): date(2022, 6, 2), ]: self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) if dt != date(2022, 6, 2): - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) def test_christmas_day(self): self.holidays.observed = False for year in range(1900, 2100): dt = date(year, 12, 25) self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) self.assertNotIn(date(2010, 12, 24), self.holidays) self.assertNotEqual( self.holidays[date(2011, 12, 26)], "Christmas Day (Observed)" @@ -191,7 +191,7 @@ def test_boxing_day(self): for year in range(1900, 2100): dt = date(year, 12, 26) self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) self.assertNotIn(date(2009, 12, 28), self.holidays) self.assertNotIn(date(2010, 12, 27), self.holidays) self.holidays.observed = True diff --git a/test/countries/test_united_states.py b/test/countries/test_united_states.py index 60247998c..e35db4c93 100644 --- a/test/countries/test_united_states.py +++ b/test/countries/test_united_states.py @@ -12,7 +12,7 @@ import unittest from datetime import date -from dateutil.relativedelta import relativedelta +from dateutil.relativedelta import relativedelta as rd import holidays from holidays.constants import SAT, SUN @@ -32,8 +32,8 @@ def test_new_years(self): for year in range(1900, 2100): dt = date(year, 1, 1) self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) def test_Juneteenth_day(self): @@ -120,8 +120,8 @@ def test_martin_luther(self): date(2020, 1, 20), ]: self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) self.assertNotIn( "Martin Luther King Jr. Day", holidays.US(years=[1985]).values() ) @@ -288,8 +288,8 @@ def test_washingtons_birthday(self): date(2020, 2, 17), ]: self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) self.assertNotIn(dt, de_holidays) self.assertNotEqual(fl_holidays.get(dt), "Washington's Birthday") self.assertNotIn(dt, ga_holidays) @@ -622,8 +622,8 @@ def test_truman_day(self): dt = date(year, 5, 8) self.assertNotIn(dt, self.holidays) self.assertIn(dt, mo_holidays) - self.assertNotIn(dt + relativedelta(days=-1), mo_holidays) - self.assertNotIn(dt + relativedelta(days=+1), mo_holidays) + self.assertNotIn(dt + rd(days=-1), mo_holidays) + self.assertNotIn(dt + rd(days=+1), mo_holidays) self.assertNotIn(date(2004, 5, 7), mo_holidays) self.assertNotIn(date(2005, 5, 9), mo_holidays) mo_holidays.observed = True @@ -646,8 +646,8 @@ def test_memorial_day(self): date(2020, 5, 25), ]: self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) def test_jefferson_davis_birthday(self): al_holidays = holidays.US(subdiv="AL") @@ -726,8 +726,8 @@ def test_independence_day(self): for year in range(1900, 2100): dt = date(year, 7, 4) self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) self.assertNotIn(date(2010, 7, 5), self.holidays) self.assertNotIn(date(2020, 7, 3), self.holidays) self.holidays.observed = True @@ -843,8 +843,8 @@ def test_labor_day(self): date(2020, 9, 7), ]: self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) def test_columbus_day(self): ak_holidays = holidays.US(subdiv="AK") @@ -869,8 +869,8 @@ def test_columbus_day(self): self.assertNotIn(dt, de_holidays) self.assertNotIn(dt, fl_holidays) self.assertNotIn(dt, hi_holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) self.assertEqual(sd_holidays.get(dt), "Native American Day") self.assertEqual( vi_holidays.get(dt), @@ -988,8 +988,8 @@ def test_veterans_day(self): date(2020, 11, 11), ]: self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) self.assertNotIn("Armistice Day", holidays.US(years=[1937]).values()) self.assertNotIn("Armistice Day", holidays.US(years=[1937]).values()) self.assertIn("Armistice Day", holidays.US(years=[1938]).values()) @@ -1036,66 +1036,64 @@ def test_thanksgiving_day(self): date(2020, 11, 26), ]: self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) - self.assertIn(dt + relativedelta(days=+1), de_holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) + self.assertIn(dt + rd(days=+1), de_holidays) self.assertEqual( - ca_holidays.get(dt + relativedelta(days=+1)), + ca_holidays.get(dt + rd(days=+1)), "Day After Thanksgiving", ) self.assertEqual( - de_holidays.get(dt + relativedelta(days=+1)), + de_holidays.get(dt + rd(days=+1)), "Day After Thanksgiving", ) self.assertEqual( - nh_holidays.get(dt + relativedelta(days=+1)), + nh_holidays.get(dt + rd(days=+1)), "Day After Thanksgiving", ) self.assertEqual( - nc_holidays.get(dt + relativedelta(days=+1)), + nc_holidays.get(dt + rd(days=+1)), "Day After Thanksgiving", ) self.assertEqual( - ok_holidays.get(dt + relativedelta(days=+1)), + ok_holidays.get(dt + rd(days=+1)), "Day After Thanksgiving", ) self.assertEqual( - pa_holidays.get(dt + relativedelta(days=+1)), + pa_holidays.get(dt + rd(days=+1)), "Day After Thanksgiving", ) self.assertEqual( - wv_holidays.get(dt + relativedelta(days=+1)), + wv_holidays.get(dt + rd(days=+1)), "Day After Thanksgiving", ) - self.assertIn(dt + relativedelta(days=+1), fl_holidays) + self.assertIn(dt + rd(days=+1), fl_holidays) self.assertEqual( - fl_holidays.get(dt + relativedelta(days=+1)), + fl_holidays.get(dt + rd(days=+1)), "Friday After Thanksgiving", ) - self.assertIn(dt + relativedelta(days=+1), tx_holidays) + self.assertIn(dt + rd(days=+1), tx_holidays) self.assertEqual( - tx_holidays.get(dt + relativedelta(days=+1)), + tx_holidays.get(dt + rd(days=+1)), "Friday After Thanksgiving", ) + self.assertEqual(nv_holidays.get(dt + rd(days=+1)), "Family Day") self.assertEqual( - nv_holidays.get(dt + relativedelta(days=+1)), "Family Day" - ) - self.assertEqual( - nm_holidays.get(dt + relativedelta(days=+1)), "Presidents' Day" + nm_holidays.get(dt + rd(days=+1)), "Presidents' Day" ) if dt.year >= 2008: self.assertEqual( - md_holidays.get(dt + relativedelta(days=1)), + md_holidays.get(dt + rd(days=+1)), "American Indian Heritage Day", ) if dt.year >= 2010: self.assertEqual( - in_holidays.get(dt + relativedelta(days=1)), + in_holidays.get(dt + rd(days=+1)), "Lincoln's Birthday", ) else: self.assertNotEqual( - in_holidays.get(dt + relativedelta(days=1)), + in_holidays.get(dt + rd(days=+1)), "Lincoln's Birthday", ) @@ -1192,8 +1190,8 @@ def test_christmas_day(self): for year in range(1900, 2100): dt = date(year, 12, 25) self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) self.assertNotIn(date(2010, 12, 24), self.holidays) self.assertNotIn(date(2016, 12, 26), self.holidays) self.holidays.observed = True diff --git a/test/countries/test_uruguay.py b/test/countries/test_uruguay.py index 382e96d6a..2558f3bef 100644 --- a/test/countries/test_uruguay.py +++ b/test/countries/test_uruguay.py @@ -12,7 +12,7 @@ import unittest from datetime import date -from dateutil.relativedelta import relativedelta +from dateutil.relativedelta import relativedelta as rd import holidays @@ -32,8 +32,8 @@ def test_new_years(self): for year in range(1900, 2100): dt = date(year, 1, 1) self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) self.assertEqual(self.holidays[dt], "Año Nuevo [New Year's Day]") def test_labor_day(self): @@ -45,8 +45,8 @@ def test_labor_day(self): for year in range(1900, 2100): dt = date(year, 5, 1) self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) self.assertEqual( self.holidays[dt], "Día de los Trabajadores [International Workers' Day]", @@ -56,8 +56,8 @@ def test_jura_de_la_constitucion_day(self): for year in range(1900, 2100): dt = date(year, 7, 18) self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) self.assertEqual( self.holidays[dt], "Jura de la Constitución [Constitution Day]" ) @@ -66,8 +66,8 @@ def test_declaratoria_de_la_independencia_day(self): for year in range(1900, 2100): dt = date(year, 8, 25) self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) self.assertEqual( self.holidays[dt], "Día de la Independencia [Independence Day]" ) @@ -76,8 +76,8 @@ def test_christmas(self): for year in range(1900, 2100): dt = date(year, 12, 25) self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) self.assertEqual( self.holidays[dt], "Día de la Familia [Day of the Family]" ) @@ -97,8 +97,8 @@ def test_natalicio_artigas_day(self): for year in range(1900, 2100): dt = date(year, 6, 19) self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) self.assertEqual( self.holidays[dt], "Natalicio de José Gervasio Artigas " @@ -109,8 +109,8 @@ def test_dia_de_los_difuntos_day(self): for year in range(1900, 2100): dt = date(year, 11, 2) self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) self.assertEqual( self.holidays[dt], "Día de los Difuntos [All Souls' Day]" ) diff --git a/test/countries/test_venezuela.py b/test/countries/test_venezuela.py index 1feeaf201..dec4f1e21 100644 --- a/test/countries/test_venezuela.py +++ b/test/countries/test_venezuela.py @@ -10,7 +10,9 @@ # License: MIT (see LICENSE file) import unittest -from datetime import date, timedelta +from datetime import date + +from dateutil.relativedelta import relativedelta as rd import holidays from holidays.constants import JAN, FEB, MAR, APR, MAY, JUN, JUL, OCT, DEC @@ -23,7 +25,7 @@ def setUp(self): def _check_all_dates(self, year, expected_holidays): start_date = date(year, 1, 1) end_date = date(year, 12, 31) - delta = timedelta(days=1) + delta = rd(days=+1) while start_date <= end_date: if start_date in expected_holidays: diff --git a/test/countries/test_vietnam.py b/test/countries/test_vietnam.py index c1aace864..3889e6581 100644 --- a/test/countries/test_vietnam.py +++ b/test/countries/test_vietnam.py @@ -12,7 +12,7 @@ import unittest from datetime import date -from dateutil.relativedelta import relativedelta +from dateutil.relativedelta import relativedelta as rd import holidays @@ -51,27 +51,27 @@ def test_lunar_new_year(self): (2022, 2, 1), ): self.assertEqual( - self.holidays[date(year, month, day) + relativedelta(days=-1)], + self.holidays[date(year, month, day) + rd(days=-1)], "Vietnamese New Year's Eve", ) self.assertEqual( - self.holidays[date(year, month, day) + relativedelta(days=0)], + self.holidays[date(year, month, day)], "Vietnamese New Year", ) self.assertEqual( - self.holidays[date(year, month, day) + relativedelta(days=+1)], + self.holidays[date(year, month, day) + rd(days=+1)], "The second day of Tet Holiday", ) self.assertEqual( - self.holidays[date(year, month, day) + relativedelta(days=+2)], + self.holidays[date(year, month, day) + rd(days=+2)], "The third day of Tet Holiday", ) self.assertEqual( - self.holidays[date(year, month, day) + relativedelta(days=+3)], + self.holidays[date(year, month, day) + rd(days=+3)], "The forth day of Tet Holiday", ) self.assertEqual( - self.holidays[date(year, month, day) + relativedelta(days=+4)], + self.holidays[date(year, month, day) + rd(days=+4)], "The fifth day of Tet Holiday", ) diff --git a/test/financial/test_european_central_bank.py b/test/financial/test_european_central_bank.py index 7294c621f..262a06cb9 100644 --- a/test/financial/test_european_central_bank.py +++ b/test/financial/test_european_central_bank.py @@ -12,7 +12,7 @@ import unittest from datetime import date -from dateutil.relativedelta import relativedelta +from dateutil.relativedelta import relativedelta as rd import holidays @@ -25,7 +25,7 @@ def test_new_years(self): for year in range(1974, 2100): dt = date(year, 1, 1) self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) def test_good_friday(self): for dt in [ @@ -40,8 +40,8 @@ def test_good_friday(self): date(2020, 4, 10), ]: self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) def test_easter_monday(self): for dt in [ @@ -56,27 +56,27 @@ def test_easter_monday(self): date(2020, 4, 13), ]: self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) def test_labour_day(self): for year in range(1900, 2100): dt = date(year, 5, 1) self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) def test_christmas_day(self): for year in range(1900, 2100): dt = date(year, 12, 25) self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=-1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) def test_26_december_day(self): for year in range(1900, 2100): dt = date(year, 12, 26) self.assertIn(dt, self.holidays) - self.assertNotIn(dt + relativedelta(days=+1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) def test_all_holidays_present(self): tar_2015 = holidays.TAR(years=[2015]) diff --git a/test/financial/test_ny_stock_exchange.py b/test/financial/test_ny_stock_exchange.py index ff5c2a757..b6eb09d8a 100644 --- a/test/financial/test_ny_stock_exchange.py +++ b/test/financial/test_ny_stock_exchange.py @@ -10,7 +10,7 @@ # License: MIT (see LICENSE file) import unittest -from datetime import date, timedelta +from datetime import date from dateutil.relativedelta import WE from dateutil.relativedelta import relativedelta as rd @@ -420,8 +420,7 @@ def test_special_holidays(self): def _make_special_holiday_list(begin, end, days=None, weekends=False): _list = [] for d in ( - begin + timedelta(days=n) - for n in range((end - begin).days + 1) + begin + rd(days=n) for n in range((end - begin).days + 1) ): if not weekends and d.weekday() in {SAT, SUN}: continue @@ -454,14 +453,14 @@ def _make_special_holiday_list(begin, end, days=None, weekends=False): date(1968, JUN, 12), # begin paper crisis holidays ]: self.assertIn(dt, self.holidays) - self.assertNotIn(dt - timedelta(days=1), self.holidays) + self.assertNotIn(dt + rd(days=-1), self.holidays) for dt in [ date(1914, NOV, 27), # end WWI holidays date(1933, MAR, 14), # end oneoff bank holidays ]: self.assertIn(dt, self.holidays) - self.assertNotIn(dt + timedelta(days=1), self.holidays) + self.assertNotIn(dt + rd(days=+1), self.holidays) def test_all_modern_holidays_present(self): nyse_2021 = holidays.NewYorkStockExchange(years=[2021]) From dd64101f3531b51dc5ed9eea10e0cb2aa8d2a709 Mon Sep 17 00:00:00 2001 From: dr-prodigy <28216945+dr-prodigy@users.noreply.github.com> Date: Tue, 17 Jan 2023 09:10:57 +0100 Subject: [PATCH 125/138] File headers updates (copyright 2023, reference email) updates --- holidays/countries/bahrain.py | 2 +- holidays/countries/kyrgyzstan.py | 2 +- holidays/countries/monaco.py | 2 +- holidays/countries/philippines.py | 2 +- holidays/countries/thailand.py | 2 +- test/countries/test_bahrain.py | 2 +- test/countries/test_kyrgyzstan.py | 2 +- test/countries/test_monaco.py | 2 +- test/countries/test_philippines.py | 2 +- test/countries/test_thailand.py | 2 +- test/test_docs.py | 2 +- 11 files changed, 11 insertions(+), 11 deletions(-) diff --git a/holidays/countries/bahrain.py b/holidays/countries/bahrain.py index 807c7e396..a47b796f7 100644 --- a/holidays/countries/bahrain.py +++ b/holidays/countries/bahrain.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/countries/kyrgyzstan.py b/holidays/countries/kyrgyzstan.py index 75652c9cc..33dd4829d 100644 --- a/holidays/countries/kyrgyzstan.py +++ b/holidays/countries/kyrgyzstan.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/countries/monaco.py b/holidays/countries/monaco.py index e4eeaee1c..95b28a7bc 100644 --- a/holidays/countries/monaco.py +++ b/holidays/countries/monaco.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/countries/philippines.py b/holidays/countries/philippines.py index d02017cc8..ee7bd8232 100644 --- a/holidays/countries/philippines.py +++ b/holidays/countries/philippines.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/holidays/countries/thailand.py b/holidays/countries/thailand.py index 28e97c863..35bf901cf 100644 --- a/holidays/countries/thailand.py +++ b/holidays/countries/thailand.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/countries/test_bahrain.py b/test/countries/test_bahrain.py index 056b4b9ee..346d2681a 100644 --- a/test/countries/test_bahrain.py +++ b/test/countries/test_bahrain.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/countries/test_kyrgyzstan.py b/test/countries/test_kyrgyzstan.py index 0185be48d..c3341c4b7 100644 --- a/test/countries/test_kyrgyzstan.py +++ b/test/countries/test_kyrgyzstan.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/countries/test_monaco.py b/test/countries/test_monaco.py index 89b1ddeb5..6b25b847d 100644 --- a/test/countries/test_monaco.py +++ b/test/countries/test_monaco.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/countries/test_philippines.py b/test/countries/test_philippines.py index 77fdf119b..fe60c7cb6 100644 --- a/test/countries/test_philippines.py +++ b/test/countries/test_philippines.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/countries/test_thailand.py b/test/countries/test_thailand.py index bca54cdf3..c58c5726d 100644 --- a/test/countries/test_thailand.py +++ b/test/countries/test_thailand.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) diff --git a/test/test_docs.py b/test/test_docs.py index 78922fe3a..9caf89fec 100644 --- a/test/test_docs.py +++ b/test/test_docs.py @@ -4,7 +4,7 @@ # 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 (c) 2017-2022 +# Authors: dr-prodigy (c) 2017-2023 # ryanss (c) 2014-2017 # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) From e37767ef070d4eb61aa65912d7d1b026d986ee73 Mon Sep 17 00:00:00 2001 From: Arkadii Yakovets Date: Tue, 17 Jan 2023 09:20:43 -0800 Subject: [PATCH 126/138] Rename test holidays name method. --- test/common.py | 14 +++++++------- test/countries/test_vietnam.py | 24 ++++++++++++------------ 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/test/common.py b/test/common.py index de2b81d9e..c47c7ecdc 100644 --- a/test/common.py +++ b/test/common.py @@ -115,13 +115,6 @@ def assertHolidayName(self, *args): for name in names: self.assertTrue(holidays.get_named(name)) - def assertHolidayNames(self, name, *args): - """Assert each holiday name matches an expected one.""" - - holidays, dates = self.parse_arguments(args) - for dt in dates: - self.assertEqual(name, holidays.get(dt), f"{dt}") - def assertHolidaysEqual(self, holidays, *expected_holidays): """Assert holidays exactly match expected holidays.""" @@ -133,6 +126,13 @@ def assertHolidaysEqual(self, holidays, *expected_holidays): self.assertIn(dt, holidays) self.assertEqual(name, holidays[dt], f"{dt}") + def assertHolidaysName(self, name, *args): + """Assert each holiday name matches an expected one.""" + + holidays, dates = self.parse_arguments(args) + for dt in dates: + self.assertEqual(name, holidays.get(dt), f"{dt}") + def assertNoHoliday(self, *args): """Assert each date is not a holiday.""" diff --git a/test/countries/test_vietnam.py b/test/countries/test_vietnam.py index c6fe5a0e1..971fbb93e 100644 --- a/test/countries/test_vietnam.py +++ b/test/countries/test_vietnam.py @@ -25,13 +25,13 @@ def test_country_aliases(self): self.assertCountryAliases(Vietnam, VN, VNM) def test_common(self): - self.assertHolidayNames( + self.assertHolidaysName( "International New Year's Day", "2020-01-01", ) def test_first_day_of_january(self): - self.assertHolidayNames( + self.assertHolidaysName( "International New Year's Day", (f"{year}-01-01" for year in range(1979, 2050)), ) @@ -54,33 +54,33 @@ def test_lunar_new_year(self): (2021, 2, 12), (2022, 2, 1), ): - self.assertHolidayNames( + self.assertHolidaysName( "Vietnamese New Year's Eve", date(*dt) + rd(days=-1), ) - self.assertHolidayNames( + self.assertHolidaysName( "Vietnamese New Year", date(*dt), ) - self.assertHolidayNames( + self.assertHolidaysName( "The second day of Tet Holiday", date(*dt) + rd(days=+1), ) - self.assertHolidayNames( + self.assertHolidaysName( "The third day of Tet Holiday", date(*dt) + rd(days=+2), ) - self.assertHolidayNames( + self.assertHolidaysName( "The forth day of Tet Holiday", date(*dt) + rd(days=+3), ) - self.assertHolidayNames( + self.assertHolidaysName( "The fifth day of Tet Holiday", date(*dt) + rd(days=+4), ) def test_king_hung_day(self): - self.assertHolidayNames( + self.assertHolidaysName( "Hung Kings Commemoration Day", "2020-04-02", "2021-04-21", @@ -88,19 +88,19 @@ def test_king_hung_day(self): ) def test_liberation_day(self): - self.assertHolidayNames( + self.assertHolidaysName( "Liberation Day/Reunification Day", (f"{year}-04-30" for year in range(1979, 2050)), ) def test_international_labor_day(self): - self.assertHolidayNames( + self.assertHolidaysName( "International Labor Day", (f"{year}-05-01" for year in range(1979, 2050)), ) def test_independence_day(self): - self.assertHolidayNames( + self.assertHolidaysName( "Independence Day", (f"{year}-09-02" for year in range(1979, 2050)), ) From 78c6045269928243f41a7bda3339d8ef3ae16c18 Mon Sep 17 00:00:00 2001 From: Arkadii Yakovets Date: Tue, 17 Jan 2023 14:03:11 -0800 Subject: [PATCH 127/138] Add Albania initial support. --- README.rst | 5 +- holidays/countries/__init__.py | 1 + holidays/countries/albania.py | 100 +++++++++++++++++++++++++++++++++ test/countries/test_albania.py | 67 ++++++++++++++++++++++ 4 files changed, 172 insertions(+), 1 deletion(-) create mode 100644 holidays/countries/albania.py create mode 100644 test/countries/test_albania.py diff --git a/README.rst b/README.rst index 5ca95a0d2..a37043d61 100644 --- a/README.rst +++ b/README.rst @@ -106,7 +106,7 @@ Available Countries .. _ISO 3166-1 alpha-2 code: https://en.wikipedia.org/wiki/List_of_ISO_3166_country_codes -We currently support 106 countries. The standard way to refer to a country is by +We currently support 107 countries. The standard way to refer to a country is by using its `ISO 3166-1 alpha-2 code`_, the same used for domain names. The following countries and their subdivisions are available: @@ -118,6 +118,9 @@ following countries and their subdivisions are available: * - Country - Code - Subdivisions Available + * - Albania + - AL + - None * - Angola - AO - None diff --git a/holidays/countries/__init__.py b/holidays/countries/__init__.py index 5a0f388b1..6de2e92a0 100644 --- a/holidays/countries/__init__.py +++ b/holidays/countries/__init__.py @@ -9,6 +9,7 @@ # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) +from .albania import AL, ALB, Albania from .angola import AO, AGO, Angola from .argentina import AR, ARG, Argentina from .armenia import AM, ARM, Armenia diff --git a/holidays/countries/albania.py b/holidays/countries/albania.py new file mode 100644 index 000000000..a825ee48b --- /dev/null +++ b/holidays/countries/albania.py @@ -0,0 +1,100 @@ +# 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 (c) 2017-2022 +# ryanss (c) 2014-2017 +# Website: https://github.com/dr-prodigy/python-holidays +# License: MIT (see LICENSE file) + +from datetime import date + +from dateutil.easter import EASTER_ORTHODOX, EASTER_WESTERN, easter +from dateutil.relativedelta import MO +from dateutil.relativedelta import relativedelta as rd + +from holidays.constants import JAN, MAR, MAY, SEP, NOV, DEC +from holidays.holiday_base import HolidayBase +from holidays.utils import _islamic_to_gre + + +class Albania(HolidayBase): + """ + References: + - https://en.wikipedia.org/wiki/Public_holidays_in_Albania + """ + + country = "AL" + + def _add_holiday(self, holiday_date: date, holiday_name: str) -> date: + dt = holiday_date + + self[dt] = holiday_name + if self.observed and self._is_weekend(dt): + dt += rd(weekday=MO(+1)) + while dt.year == holiday_date.year and dt in self: + dt += rd(days=+1) + self[dt] = f"{holiday_name} (Observed)" + + return dt + + def _populate(self, year: int) -> None: + super()._populate(year) + + # New Year's Day. + name = "New Year's Day" + self._add_holiday(date(year, JAN, 1), name) + self._add_holiday(date(year, JAN, 2), name) + + # Summer Day. + self[date(year, MAR, 14)] = "Summer Day" + + # Nevruz. + self[date(year, MAR, 22)] = "Nevruz" + + # Easter. + easter_holidays_mapping = { + EASTER_ORTHODOX: "Orthodox Easter", + EASTER_WESTERN: "Catholic Easter", + } + for method, holiday_name in easter_holidays_mapping.items(): + self._add_holiday( + easter(year, method=method), # type: ignore[arg-type] + holiday_name, + ) + + # May Day. + self._add_holiday(date(year, MAY, 1), "May Day") + + # Eid al-Fitr. + for dt in _islamic_to_gre(year, 10, 1): + self._add_holiday(dt, "Eid al-Fitr* (*estimated)") + + # Eid al-Adha. + for dt in _islamic_to_gre(year, 12, 10): + self._add_holiday(dt, "Eid al-Adha* (*estimated)") + + # Mother Teresa Day. + self._add_holiday(date(year, SEP, 5), "Mother Teresa Day") + + # Independence Day. + self._add_holiday(date(year, NOV, 28), "Independence Day") + + # Liberation Day. + self._add_holiday(date(year, NOV, 29), "Liberation Day") + + # National Youth Day. + self._add_holiday(date(year, DEC, 8), "National Youth Day") + + # Christmas Day. + self._add_holiday(date(year, DEC, 25), "Christmas Day") + + +class AL(Albania): + pass + + +class ALB(Albania): + pass diff --git a/test/countries/test_albania.py b/test/countries/test_albania.py new file mode 100644 index 000000000..b92e8139f --- /dev/null +++ b/test/countries/test_albania.py @@ -0,0 +1,67 @@ +# 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 (c) 2017-2022 +# ryanss (c) 2014-2017 +# Website: https://github.com/dr-prodigy/python-holidays +# License: MIT (see LICENSE file) + +from holidays.countries.albania import AL, ALB, Albania +from test.common import TestCase + + +class TestAlbania(TestCase): + def setUp(self): + self.holidays = Albania() + + def test_country_aliases(self): + self.assertCountryAliases(Albania, AL, ALB) + + def test_2022(self): + self.assertHolidaysEqual( + Albania(years=2022), + ("2022-01-01", "New Year's Day"), + ("2022-01-02", "New Year's Day"), + ("2022-01-03", "New Year's Day (Observed)"), + ("2022-01-04", "New Year's Day (Observed)"), + ("2022-03-14", "Summer Day"), + ("2022-03-22", "Nevruz"), + ("2022-04-17", "Catholic Easter"), + ("2022-04-18", "Catholic Easter (Observed)"), + ("2022-04-24", "Orthodox Easter"), + ("2022-04-25", "Orthodox Easter (Observed)"), + ("2022-05-01", "May Day"), + ("2022-05-02", "Eid al-Fitr* (*estimated), May Day (Observed)"), + ("2022-07-09", "Eid al-Adha* (*estimated)"), + ("2022-07-11", "Eid al-Adha* (*estimated) (Observed)"), + ("2022-09-05", "Mother Teresa Day"), + ("2022-11-28", "Independence Day"), + ("2022-11-29", "Liberation Day"), + ("2022-12-08", "National Youth Day"), + ("2022-12-25", "Christmas Day"), + ("2022-12-26", "Christmas Day (Observed)"), + ) + + def test_2023(self): + self.assertHolidaysEqual( + Albania(years=2023), + ("2023-01-01", "New Year's Day"), + ("2023-01-02", "New Year's Day, New Year's Day (Observed)"), + ("2023-03-14", "Summer Day"), + ("2023-03-22", "Nevruz"), + ("2023-04-09", "Catholic Easter"), + ("2023-04-10", "Catholic Easter (Observed)"), + ("2023-04-16", "Orthodox Easter"), + ("2023-04-17", "Orthodox Easter (Observed)"), + ("2023-04-21", "Eid al-Fitr* (*estimated)"), + ("2023-05-01", "May Day"), + ("2023-06-28", "Eid al-Adha* (*estimated)"), + ("2023-09-05", "Mother Teresa Day"), + ("2023-11-28", "Independence Day"), + ("2023-11-29", "Liberation Day"), + ("2023-12-08", "National Youth Day"), + ("2023-12-25", "Christmas Day"), + ) From 04b7e7bd2f811ec4e2ee90cc783ba6a8fe13d354 Mon Sep 17 00:00:00 2001 From: Arkadii Yakovets Date: Wed, 18 Jan 2023 08:07:00 -0800 Subject: [PATCH 128/138] Add Andorra initial support. --- README.rst | 5 +- holidays/countries/__init__.py | 1 + holidays/countries/andorra.py | 133 +++++++++++++++++++++++++++++ test/countries/test_andorra.py | 151 +++++++++++++++++++++++++++++++++ 4 files changed, 289 insertions(+), 1 deletion(-) create mode 100644 holidays/countries/andorra.py create mode 100644 test/countries/test_andorra.py diff --git a/README.rst b/README.rst index 5ca95a0d2..78bd8a7b7 100644 --- a/README.rst +++ b/README.rst @@ -106,7 +106,7 @@ Available Countries .. _ISO 3166-1 alpha-2 code: https://en.wikipedia.org/wiki/List_of_ISO_3166_country_codes -We currently support 106 countries. The standard way to refer to a country is by +We currently support 107 countries. The standard way to refer to a country is by using its `ISO 3166-1 alpha-2 code`_, the same used for domain names. The following countries and their subdivisions are available: @@ -118,6 +118,9 @@ following countries and their subdivisions are available: * - Country - Code - Subdivisions Available + * - Andorra + - AD + - Parishes: AD-02, AD-03, AD-04, AD-05, AD-06, AD-07, AD-08 * - Angola - AO - None diff --git a/holidays/countries/__init__.py b/holidays/countries/__init__.py index 5a0f388b1..c4766ad1e 100644 --- a/holidays/countries/__init__.py +++ b/holidays/countries/__init__.py @@ -9,6 +9,7 @@ # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) +from .andorra import AD, AND, Andorra from .angola import AO, AGO, Angola from .argentina import AR, ARG, Argentina from .armenia import AM, ARM, Armenia diff --git a/holidays/countries/andorra.py b/holidays/countries/andorra.py new file mode 100644 index 000000000..9c15dc821 --- /dev/null +++ b/holidays/countries/andorra.py @@ -0,0 +1,133 @@ +# 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 (c) 2017-2022 +# ryanss (c) 2014-2017 +# Website: https://github.com/dr-prodigy/python-holidays +# License: MIT (see LICENSE file) + +from datetime import date + +from dateutil.easter import easter +from dateutil.relativedelta import relativedelta as rd + +from holidays.constants import JAN, MAR, MAY, JUL, AUG, SEP, NOV, DEC +from holidays.holiday_base import HolidayBase + + +class Andorra(HolidayBase): + """ + References: + - https://en.wikipedia.org/wiki/Public_holidays_in_Andorra + """ + + country = "AD" + subdivisions = [ + "AD-02", # Canillo. + "AD-03", # Encamp. + "AD-04", # La Massana. + "AD-05", # Ordino. + "AD-06", # Sant Julià de Lòria. + "AD-07", # Andorra la Vella. + "AD-08", # Escaldes-Engordany. + ] + + def _populate(self, year: int) -> None: + super()._populate(year) + + # New Year's Day. + self[date(year, JAN, 1)] = "New Year's Day" + + # Epiphany. + self[date(year, JAN, 6)] = "Epiphany" + + easter_sunday = easter(year) + + # Carnival. + self[easter_sunday + rd(days=-47)] = "Carnival" + + # Constitution Day. + self[date(year, MAR, 14)] = "Constitution Day" + + # Good Friday. + self[easter_sunday + rd(days=-2)] = "Good Friday" + + # Easter Sunday. + self[easter_sunday + rd(days=+1)] = "Easter Monday" + + # Labour Day. + self[date(year, MAY, 1)] = "Labour Day" + + # Whit Monday. + self[easter_sunday + rd(days=+50)] = "Whit Monday" + + # Assumption Day. + self[date(year, AUG, 15)] = "Assumption Day" + + # National Day. + self[date(year, SEP, 8)] = "National Day" + + # All Saints' Day. + self[date(year, NOV, 1)] = "All Saints' Day" + + # Immaculate Conception Day. + self[date(year, DEC, 8)] = "Immaculate Conception Day" + + # Christmas Day. + self[date(year, DEC, 25)] = "Christmas Day" + + # Saint Stephen's Day. + self[date(year, DEC, 26)] = "Saint Stephen's Day" + + # Parish local holidays. + parish_holidays_mapping = { + "AD-02": ( + (date(year, JUL, 21), "Canillo Annual Festival"), + (date(year, JUL, 22), "Canillo Annual Festival"), + (date(year, JUL, 23), "Canillo Annual Festival"), + ), + "AD-03": ( + (date(year, AUG, 15), "Encamp Annual Festival"), + (date(year, AUG, 16), "Encamp Annual Festival"), + ), + "AD-04": ( + (date(year, AUG, 15), "La Massana Annual Festival"), + (date(year, AUG, 16), "La Massana Annual Festival"), + ), + "AD-05": ( + (date(year, AUG, 15), "Ordino Annual Festival"), + (date(year, AUG, 16), "Ordino Annual Festival"), + ), + "AD-06": ( + (date(year, JUL, 27), "Sant Julià de Lòria Annual Festival"), + (date(year, JUL, 28), "Sant Julià de Lòria Annual Festival"), + (date(year, JUL, 29), "Sant Julià de Lòria Annual Festival"), + (date(year, JUL, 30), "Sant Julià de Lòria Annual Festival"), + ), + "AD-07": ( + (date(year, AUG, 4), "Andorra la Vella Annual Festival"), + (date(year, AUG, 5), "Andorra la Vella Annual Festival"), + (date(year, AUG, 6), "Andorra la Vella Annual Festival"), + ), + "AD-08": ( + (date(year, JUL, 25), "Escaldes–Engordany Annual Festival"), + (date(year, JUL, 26), "Escaldes–Engordany Annual Festival"), + ), + } + + if self.subdiv: + for holiday_date, holiday_name in parish_holidays_mapping[ + self.subdiv + ]: + self[holiday_date] = holiday_name + + +class AD(Andorra): + pass + + +class AND(Andorra): + pass diff --git a/test/countries/test_andorra.py b/test/countries/test_andorra.py new file mode 100644 index 000000000..cd60ae403 --- /dev/null +++ b/test/countries/test_andorra.py @@ -0,0 +1,151 @@ +# 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 (c) 2017-2022 +# ryanss (c) 2014-2017 +# Website: https://github.com/dr-prodigy/python-holidays +# License: MIT (see LICENSE file) + +from holidays.countries.andorra import AD, AND, Andorra +from test.common import TestCase + + +class TestAndorra(TestCase): + def setUp(self): + self.holidays = Andorra() + + def test_country_aliases(self): + self.assertCountryAliases(Andorra, AD, AND) + + def test_2022(self): + self.assertHolidaysEqual( + Andorra(years=2022), + ("2022-01-01", "New Year's Day"), + ("2022-01-06", "Epiphany"), + ("2022-03-01", "Carnival"), + ("2022-03-14", "Constitution Day"), + ("2022-04-15", "Good Friday"), + ("2022-04-18", "Easter Monday"), + ("2022-05-01", "Labour Day"), + ("2022-06-06", "Whit Monday"), + ("2022-08-15", "Assumption Day"), + ("2022-09-08", "National Day"), + ("2022-11-01", "All Saints' Day"), + ("2022-12-08", "Immaculate Conception Day"), + ("2022-12-25", "Christmas Day"), + ("2022-12-26", "Saint Stephen's Day"), + ) + + # AD-02, Canillo. + self.assertHoliday( + Andorra(subdiv="AD-02", years=2022), + "2022-07-21", + "2022-07-22", + "2022-07-23", + ) + + # AD-03, Encamp. + self.assertHoliday( + Andorra(subdiv="AD-03", years=2022), + "2022-08-15", + "2022-08-16", + ) + + # AD-04, La Massana. + self.assertHoliday( + Andorra(subdiv="AD-04", years=2022), + "2022-08-15", + "2022-08-16", + ) + + # AD-05, Ordino. + self.assertHoliday( + Andorra(subdiv="AD-05", years=2022), + "2022-08-15", + "2022-08-16", + ) + + # AD-06, Sant Julià de Lòria. + self.assertHoliday( + Andorra(subdiv="AD-06", years=2022), + "2022-07-27", + "2022-07-28", + "2022-07-29", + "2022-07-30", + ) + + # AD-07, Andorra la Vella. + self.assertHoliday( + Andorra(subdiv="AD-07", years=2022), + "2022-08-04", + "2022-08-05", + "2022-08-06", + ) + + def test_2023(self): + self.assertHolidaysEqual( + Andorra(years=2023), + ("2023-01-01", "New Year's Day"), + ("2023-01-06", "Epiphany"), + ("2023-02-21", "Carnival"), + ("2023-03-14", "Constitution Day"), + ("2023-04-07", "Good Friday"), + ("2023-04-10", "Easter Monday"), + ("2023-05-01", "Labour Day"), + ("2023-05-29", "Whit Monday"), + ("2023-08-15", "Assumption Day"), + ("2023-09-08", "National Day"), + ("2023-11-01", "All Saints' Day"), + ("2023-12-08", "Immaculate Conception Day"), + ("2023-12-25", "Christmas Day"), + ("2023-12-26", "Saint Stephen's Day"), + ) + + # AD-02, Canillo. + self.assertHoliday( + Andorra(subdiv="AD-02", years=2023), + "2023-07-21", + "2023-07-22", + "2023-07-23", + ) + + # AD-03, Encamp. + self.assertHoliday( + Andorra(subdiv="AD-03", years=2023), + "2023-08-15", + "2023-08-16", + ) + + # AD-04, La Massana. + self.assertHoliday( + Andorra(subdiv="AD-04", years=2023), + "2023-08-15", + "2023-08-16", + ) + + # AD-05, Ordino. + self.assertHoliday( + Andorra(subdiv="AD-05", years=2023), + "2023-08-15", + "2023-08-16", + ) + + # AD-06, Sant Julià de Lòria. + self.assertHoliday( + Andorra(subdiv="AD-06", years=2023), + "2023-07-27", + "2023-07-28", + "2023-07-29", + "2023-07-30", + ) + + # AD-07, Andorra la Vella. + self.assertHoliday( + Andorra(subdiv="AD-07", years=2023), + "2023-08-04", + "2023-08-05", + "2023-08-06", + ) From c4ee6612d33867dfe172de04c2f871af4955c282 Mon Sep 17 00:00:00 2001 From: Arkadii Yakovets Date: Thu, 19 Jan 2023 10:53:04 -0800 Subject: [PATCH 129/138] Add Montenegro initial support. --- README.rst | 5 +- holidays/countries/__init__.py | 1 + holidays/countries/montenegro.py | 99 +++++++++++++++++++++++++++++++ test/countries/test_montenegro.py | 79 ++++++++++++++++++++++++ 4 files changed, 183 insertions(+), 1 deletion(-) create mode 100644 holidays/countries/montenegro.py create mode 100644 test/countries/test_montenegro.py diff --git a/README.rst b/README.rst index 5ca95a0d2..b3ab5ad7a 100644 --- a/README.rst +++ b/README.rst @@ -106,7 +106,7 @@ Available Countries .. _ISO 3166-1 alpha-2 code: https://en.wikipedia.org/wiki/List_of_ISO_3166_country_codes -We currently support 106 countries. The standard way to refer to a country is by +We currently support 107 countries. The standard way to refer to a country is by using its `ISO 3166-1 alpha-2 code`_, the same used for domain names. The following countries and their subdivisions are available: @@ -313,6 +313,9 @@ following countries and their subdivisions are available: * - Monaco - MC - None + * - Montenegro + - ME + - None * - Morocco - MA - None diff --git a/holidays/countries/__init__.py b/holidays/countries/__init__.py index 5a0f388b1..686fb06b4 100644 --- a/holidays/countries/__init__.py +++ b/holidays/countries/__init__.py @@ -74,6 +74,7 @@ from .mexico import MX, MEX, Mexico from .moldova import MD, MDA, Moldova from .monaco import MC, MCO, Monaco +from .montenegro import ME, MNE, Montenegro from .morocco import MA, MOR, Morocco from .mozambique import MZ, MOZ, Mozambique from .namibia import NA, NAM, Namibia diff --git a/holidays/countries/montenegro.py b/holidays/countries/montenegro.py new file mode 100644 index 000000000..677a4b467 --- /dev/null +++ b/holidays/countries/montenegro.py @@ -0,0 +1,99 @@ +# 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 (c) 2017-2022 +# ryanss (c) 2014-2017 +# Website: https://github.com/dr-prodigy/python-holidays +# License: MIT (see LICENSE file) + +from datetime import date + +from dateutil.easter import EASTER_ORTHODOX, easter +from dateutil.relativedelta import relativedelta as rd + +from holidays.constants import JAN, MAY, JUL, SUN +from holidays.holiday_base import HolidayBase + + +class Montenegro(HolidayBase): + """ + References: + - https://en.wikipedia.org/wiki/Public_holidays_in_Montenegro + - https://me.usembassy.gov/holiday-calendar/ + - https://publicholidays.eu/montenegro/2023-dates/ + - https://www.officeholidays.com/countries/montenegro/2023 + """ + + country = "ME" + + def _add_holiday_observed( + self, holiday_name: str, holiday_date_1: date, holiday_date_2: date + ) -> None: + if holiday_date_1.weekday() == SUN: + self[holiday_date_1] = holiday_name + self[holiday_date_1 + rd(days=+1)] = f"{holiday_name} (Observed)" + self[holiday_date_1 + rd(days=+2)] = f"{holiday_name} (Observed)" + elif holiday_date_2.weekday() == SUN: + self[holiday_date_1] = holiday_name + self[holiday_date_2] = holiday_name + self[holiday_date_2 + rd(days=+1)] = f"{holiday_name} (Observed)" + else: + self[holiday_date_1] = holiday_name + self[holiday_date_2] = holiday_name + + def _populate(self, year: int) -> None: + super()._populate(year) + + # New Year's Day. + self._add_holiday_observed( + "New Year's Day", + date(year, JAN, 1), + date(year, JAN, 2), + ) + + # Orthodox Christmas Eve. + self[date(year, JAN, 6)] = "Orthodox Christmas Eve" + + # Orthodox Christmas. + self[date(year, JAN, 7)] = "Orthodox Christmas" + + easter_sunday = easter(year, method=EASTER_ORTHODOX) + + # Good Friday. + self[easter_sunday + rd(days=-2)] = "Orthodox Good Friday" + + # Easter Sunday. + self[easter_sunday] = "Orthodox Easter Sunday" + + # Easter Monday. + self[easter_sunday + rd(days=+1)] = "Orthodox Easter Monday" + + # Labour Day. + self._add_holiday_observed( + "Labour Day", date(year, MAY, 1), date(year, MAY, 2) + ) + + # Independence Day. + self._add_holiday_observed( + "Independence Day", + date(year, MAY, 21), + date(year, MAY, 22), + ) + + # Statehood Day. + self._add_holiday_observed( + "Statehood Day", + date(year, JUL, 13), + date(year, JUL, 14), + ) + + +class ME(Montenegro): + pass + + +class MNE(Montenegro): + pass diff --git a/test/countries/test_montenegro.py b/test/countries/test_montenegro.py new file mode 100644 index 000000000..9aa86e753 --- /dev/null +++ b/test/countries/test_montenegro.py @@ -0,0 +1,79 @@ +# 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 (c) 2017-2022 +# ryanss (c) 2014-2017 +# Website: https://github.com/dr-prodigy/python-holidays +# License: MIT (see LICENSE file) + +from holidays.countries.montenegro import ME, MNE, Montenegro +from test.common import TestCase + + +class TestMontenegro(TestCase): + def setUp(self): + self.holidays = Montenegro() + + def test_country_aliases(self): + self.assertCountryAliases(Montenegro, ME, MNE) + + def test_2021(self): + self.assertHolidaysEqual( + Montenegro(years=2021), + ("2021-01-01", "New Year's Day"), + ("2021-01-02", "New Year's Day"), + ("2021-01-06", "Orthodox Christmas Eve"), + ("2021-01-07", "Orthodox Christmas"), + ("2021-04-30", "Orthodox Good Friday"), + ("2021-05-01", "Labour Day"), + ("2021-05-02", "Labour Day, Orthodox Easter Sunday"), + ("2021-05-03", "Labour Day (Observed), Orthodox Easter Monday"), + ("2021-05-21", "Independence Day"), + ("2021-05-22", "Independence Day"), + ("2021-07-13", "Statehood Day"), + ("2021-07-14", "Statehood Day"), + ) + + def test_2022(self): + self.assertHolidaysEqual( + Montenegro(years=2022), + ("2022-01-01", "New Year's Day"), + ("2022-01-02", "New Year's Day"), + ("2022-01-03", "New Year's Day (Observed)"), + ("2022-01-06", "Orthodox Christmas Eve"), + ("2022-01-07", "Orthodox Christmas"), + ("2022-04-22", "Orthodox Good Friday"), + ("2022-04-24", "Orthodox Easter Sunday"), + ("2022-04-25", "Orthodox Easter Monday"), + ("2022-05-01", "Labour Day"), + ("2022-05-02", "Labour Day (Observed)"), + ("2022-05-03", "Labour Day (Observed)"), + ("2022-05-21", "Independence Day"), + ("2022-05-22", "Independence Day"), + ("2022-05-23", "Independence Day (Observed)"), + ("2022-07-13", "Statehood Day"), + ("2022-07-14", "Statehood Day"), + ) + + def test_2023(self): + self.assertHolidaysEqual( + Montenegro(years=2023), + ("2023-01-01", "New Year's Day"), + ("2023-01-02", "New Year's Day (Observed)"), + ("2023-01-03", "New Year's Day (Observed)"), + ("2023-01-06", "Orthodox Christmas Eve"), + ("2023-01-07", "Orthodox Christmas"), + ("2023-04-14", "Orthodox Good Friday"), + ("2023-04-16", "Orthodox Easter Sunday"), + ("2023-04-17", "Orthodox Easter Monday"), + ("2023-05-01", "Labour Day"), + ("2023-05-02", "Labour Day"), + ("2023-05-21", "Independence Day"), + ("2023-05-22", "Independence Day (Observed)"), + ("2023-05-23", "Independence Day (Observed)"), + ("2023-07-13", "Statehood Day"), + ("2023-07-14", "Statehood Day"), + ) From 1a08578d8698ac75365477426f47d3ab53379b15 Mon Sep 17 00:00:00 2001 From: Arkadii Yakovets Date: Thu, 19 Jan 2023 18:38:18 -0800 Subject: [PATCH 130/138] Update `common.TestCase`: - Change internal methods visibility (`_parse_arguments`, `_verify_type`) - Unify method nemaes and signatures (`assertHolidayDates`, `assertHolidays`) - Make failing tests error messages more informative - Update tests --- test/common.py | 73 +++++++++++++++++++----------- test/countries/test_angola.py | 5 +- test/countries/test_argentina.py | 48 +++++++++++++++++--- test/countries/test_azerbaijan.py | 6 +-- test/countries/test_honduras.py | 15 ++---- test/countries/test_kazakhstan.py | 3 +- test/countries/test_kyrgyzstan.py | 6 +-- test/countries/test_monaco.py | 12 ++--- test/countries/test_norway.py | 3 +- test/countries/test_philippines.py | 3 +- test/countries/test_sweden.py | 3 +- test/countries/test_thailand.py | 3 +- 12 files changed, 110 insertions(+), 70 deletions(-) diff --git a/test/common.py b/test/common.py index e0949a013..d72825c32 100644 --- a/test/common.py +++ b/test/common.py @@ -21,7 +21,7 @@ class TestCase(unittest.TestCase): """Base class for python-holiday test cases.""" - def parse_arguments(self, args): + def _parse_arguments(self, args, expand_items=True): item_args = args instance = None @@ -43,17 +43,20 @@ def parse_arguments(self, args): ) items = [] - for item_arg in item_args: - if type(item_arg) in {list, tuple}: - items.extend(item_arg) - elif isinstance(item_arg, Generator): - items.extend(tuple(item_arg)) - else: - items.append(item_arg) + if expand_items: + for item_arg in item_args: + if type(item_arg) in {list, tuple}: + items.extend(item_arg) + elif expand_items and isinstance(item_arg, Generator): + items.extend(tuple(item_arg)) + else: + items.append(item_arg) + else: + items.extend(item_args) return instance, items - def verify_type(self, holidays): + def _verify_type(self, holidays): self.assertTrue( issubclass(holidays.__class__, HolidayBase), "`holidays` object must be a subclass of `HolidayBase`", @@ -95,61 +98,79 @@ def assertCountryAliases(self, cls, alpha_2, alpha_3): def assertHoliday(self, *args): """Assert each date is a holiday.""" - holidays, dates = self.parse_arguments(args) + holidays, dates = self._parse_arguments(args) for dt in dates: - self.assertIn(dt, holidays, f"{dt}") + self.assertIn(dt, holidays, dt) - def assertHolidayDatesEqual(self, holidays, *dates): + def assertHolidayDates(self, *args): """Assert holiday dates exactly match expected dates.""" - self.verify_type(holidays) + holidays, dates = self._parse_arguments(args) + self._verify_type(holidays) - self.assertEqual(len(dates), len(holidays.keys())) for dt in dates: # Check one by one for descriptive error messages. - self.assertIn(dt, holidays, f"{dt}") + self.assertIn(dt, holidays, dt) + + self.assertEqual( + len(dates), + len(holidays.keys()), + set(dates).difference(holidays.keys()), + ) def assertHolidayName(self, *args): """Assert a holiday with a specific name exists.""" - holidays, names = self.parse_arguments(args) + holidays, names = self._parse_arguments(args) for name in names: self.assertTrue(holidays.get_named(name)) - def assertHolidaysEqual(self, holidays, *expected_holidays): - """Assert holidays exactly match expected holidays.""" + def assertHolidays(self, *args): + """Asserts holidays exactly match expected holidays.""" - self.verify_type(holidays) + holidays, expected_holidays = self._parse_arguments( + args, expand_items=False + ) + self._verify_type(holidays) # Check one by one for descriptive error messages. for dt, name in expected_holidays: self.assertIn(dt, holidays) - self.assertEqual(name, holidays[dt], f"{dt}") + self.assertEqual(name, holidays.get(dt), dt) + + self.assertEqual( + len(holidays), + len(expected_holidays), + set( + (dt.strftime("%Y-%m-%d"), name) + for dt, name in holidays.items() + ).difference((dt, name) for dt, name in expected_holidays), + ) def assertHolidaysName(self, name, *args): """Assert each holiday name matches an expected one.""" - holidays, dates = self.parse_arguments(args) + holidays, dates = self._parse_arguments(args) for dt in dates: - self.assertEqual(name, holidays.get(dt), f"{dt}") + self.assertEqual(name, holidays.get(dt), dt) def assertNoHoliday(self, *args): """Assert each date is not a holiday.""" - holidays, dates = self.parse_arguments(args) + holidays, dates = self._parse_arguments(args) for dt in dates: - self.assertNotIn(dt, holidays, f"{dt}") + self.assertNotIn(dt, holidays, dt) def assertNoHolidayName(self, *args): """Assert a holiday with a specific name doesn't exist.""" - holidays, names = self.parse_arguments(args) + holidays, names = self._parse_arguments(args) for name in names: self.assertFalse(holidays.get_named(name)) def assertNoHolidays(self, holidays): """Assert holidays dict is empty.""" - self.verify_type(holidays) + self._verify_type(holidays) self.assertFalse(holidays) self.assertEqual(0, len(holidays)) diff --git a/test/countries/test_angola.py b/test/countries/test_angola.py index 4774704e3..1356278eb 100644 --- a/test/countries/test_angola.py +++ b/test/countries/test_angola.py @@ -77,11 +77,12 @@ def test_pre_1975(self): self.assertNoHolidays(Angola(years=1974)) def test_2022(self): - self.assertHolidaysEqual( - Angola(observed=False, years=2022), + self.assertHolidays( ("2022-01-01", "Ano novo"), ("2022-02-04", "Dia do Início da Luta Armada"), + ("2022-02-28", "Carnaval (Day off)"), ("2022-03-01", "Carnaval"), + ("2022-03-07", "Dia Internacional da Mulher (Day off)"), ("2022-03-08", "Dia Internacional da Mulher"), ("2022-03-23", "Dia da Libertação da África Austral"), ("2022-04-04", "Dia da Paz e Reconciliação"), diff --git a/test/countries/test_argentina.py b/test/countries/test_argentina.py index d1e275124..1bcff74a3 100644 --- a/test/countries/test_argentina.py +++ b/test/countries/test_argentina.py @@ -227,15 +227,29 @@ def test_christmas(self): ) def test_2022(self): - self.assertHolidaysEqual( - Argentina(observed=False, years=2022), - ("2022-02-28", "Día de Carnaval [Carnival's Day]"), - ("2022-03-01", "Día de Carnaval [Carnival's Day]"), + self.assertHolidays( + ( + "2022-01-01", + "Año Nuevo [New Year's Day]", + ), + ( + "2022-02-28", + "Día de Carnaval [Carnival's Day]", + ), + ( + "2022-03-01", + "Día de Carnaval [Carnival's Day]", + ), ( "2022-03-24", "Día Nacional de la Memoria por la Verdad y la Justicia " "[Memory's National Day for the Truth and Justice]", ), + ( + "2022-04-02", + "Día del Veterano y de los Caidos en la Guerra de Malvinas " + "[Veterans Day and the Fallen in the Malvinas War]", + ), ( "2022-04-14", "Semana Santa (Jueves Santo) [Holy day (Holy Thursday)]", @@ -244,6 +258,14 @@ def test_2022(self): "2022-04-15", "Semana Santa (Viernes Santo) [Holy day (Holy Friday)]", ), + ( + "2022-04-17", + "Día de Pascuas [Easter Day]", + ), + ( + "2022-05-01", + "Día del Trabajo [Labour Day]", + ), ( "2022-05-25", "Día de la Revolucion de Mayo [May Revolution Day]", @@ -259,6 +281,10 @@ def test_2022(self): "Día Pase a la Inmortalidad del General D. Manuel Belgrano " "[Day Pass to the Immortality of General D. Manuel Belgrano]", ), + ( + "2022-07-09", + "Día de la Independencia [Independence Day]", + ), ( "2022-08-17", "Día Pase a la Inmortalidad del General D. José de San Martin " @@ -270,6 +296,16 @@ def test_2022(self): "Día del Respeto a la Diversidad Cultural " "[Respect for Cultural Diversity Day]", ), - ("2022-12-08", "La Inmaculada Concepción [Immaculate Conception]"), - ("2022-12-25", "Navidad [Christmas]"), + ( + "2022-11-20", + "Día Nacional de la Soberanía [National Sovereignty Day]", + ), + ( + "2022-12-08", + "La Inmaculada Concepción [Immaculate Conception]", + ), + ( + "2022-12-25", + "Navidad [Christmas]", + ), ) diff --git a/test/countries/test_azerbaijan.py b/test/countries/test_azerbaijan.py index 6d39ebad3..32b6fd712 100644 --- a/test/countries/test_azerbaijan.py +++ b/test/countries/test_azerbaijan.py @@ -145,8 +145,7 @@ def test_observed_days(self): self.assertNoHoliday(Azerbaijan(observed=False), observed_holidays) def test_2020(self): - self.assertHolidayDatesEqual( - Azerbaijan(years=2020), + self.assertHolidayDates( "2020-01-01", "2020-01-02", "2020-01-20", @@ -175,8 +174,7 @@ def test_2020(self): ) def test_2022(self): - self.assertHolidayDatesEqual( - Azerbaijan(years=2022), + self.assertHolidayDates( "2022-01-01", "2022-01-02", "2022-01-03", diff --git a/test/countries/test_honduras.py b/test/countries/test_honduras.py index 196e43fbb..22ec3790b 100644 --- a/test/countries/test_honduras.py +++ b/test/countries/test_honduras.py @@ -21,8 +21,7 @@ def test_aliases(self): self.assertCountryAliases(Honduras, HN, HND) def test_2014(self): - self.assertHolidayDatesEqual( - Honduras(years=2014), + self.assertHolidayDates( "2014-01-01", "2014-04-14", "2014-04-17", @@ -38,8 +37,7 @@ def test_2014(self): def test_2016(self): # https://www.officeholidays.com/countries/honduras/2016 - self.assertHolidayDatesEqual( - Honduras(years=2016), + self.assertHolidayDates( "2016-01-01", "2016-03-24", "2016-03-25", @@ -55,8 +53,7 @@ def test_2016(self): def test_2021(self): # https://www.officeholidays.com/countries/honduras/2021 - self.assertHolidayDatesEqual( - Honduras(years=2021), + self.assertHolidayDates( "2021-01-01", "2021-04-01", "2021-04-02", @@ -71,8 +68,7 @@ def test_2021(self): ) def test_2022(self): - self.assertHolidaysEqual( - Honduras(observed=False, years=2022), + self.assertHolidays( ("2022-01-01", "Año Nuevo [New Year's Day]"), ( "2022-04-14", @@ -90,8 +86,7 @@ def test_2022(self): ) def test_2025(self): - self.assertHolidayDatesEqual( - Honduras(years=2025), + self.assertHolidayDates( "2025-01-01", "2025-04-14", "2025-04-17", diff --git a/test/countries/test_kazakhstan.py b/test/countries/test_kazakhstan.py index 937945e54..9fe3feecd 100644 --- a/test/countries/test_kazakhstan.py +++ b/test/countries/test_kazakhstan.py @@ -21,8 +21,7 @@ def test_country_aliases(self): self.assertCountryAliases(Kazakhstan, KZ, KAZ) def test2020(self): - self.assertHolidayDatesEqual( - Kazakhstan(years=2020), + self.assertHolidayDates( "2020-01-01", "2020-01-02", "2020-01-07", diff --git a/test/countries/test_kyrgyzstan.py b/test/countries/test_kyrgyzstan.py index c3341c4b7..f4714798a 100644 --- a/test/countries/test_kyrgyzstan.py +++ b/test/countries/test_kyrgyzstan.py @@ -21,8 +21,7 @@ def test_country_aliases(self): self.assertCountryAliases(Kyrgyzstan, KG, KGZ) def test_2022(self): - self.assertHolidaysEqual( - Kyrgyzstan(years=2022), + self.assertHolidays( ("2022-01-01", "New Year's Day"), ("2022-01-07", "Christmas Day"), ("2022-02-23", "Fatherland Defender's Day"), @@ -42,8 +41,7 @@ def test_2022(self): ) def test_2023(self): - self.assertHolidaysEqual( - Kyrgyzstan(years=2023), + self.assertHolidays( ("2023-01-01", "New Year's Day"), ("2023-01-07", "Christmas Day"), ("2023-02-23", "Fatherland Defender's Day"), diff --git a/test/countries/test_monaco.py b/test/countries/test_monaco.py index 6b25b847d..f3b5d8aff 100644 --- a/test/countries/test_monaco.py +++ b/test/countries/test_monaco.py @@ -53,8 +53,7 @@ def test_observed(self): self.assertNoHoliday(Monaco(observed=False), observed_holidays) def test_2020(self): - self.assertHolidayDatesEqual( - Monaco(years=2020), + self.assertHolidayDates( "2020-01-01", "2020-01-27", "2020-04-13", @@ -71,8 +70,7 @@ def test_2020(self): ) def test_2021(self): - self.assertHolidayDatesEqual( - Monaco(years=2021), + self.assertHolidayDates( "2021-01-01", "2021-01-27", "2021-04-05", @@ -89,8 +87,7 @@ def test_2021(self): ) def test_2022(self): - self.assertHolidayDatesEqual( - Monaco(years=2022), + self.assertHolidayDates( "2022-01-01", "2022-01-27", "2022-04-18", @@ -108,8 +105,7 @@ def test_2022(self): ) def test_2023(self): - self.assertHolidayDatesEqual( - Monaco(years=2023), + self.assertHolidayDates( "2023-01-01", "2023-01-02", "2023-01-27", diff --git a/test/countries/test_norway.py b/test/countries/test_norway.py index 9db4ec856..313d85ec6 100644 --- a/test/countries/test_norway.py +++ b/test/countries/test_norway.py @@ -122,8 +122,7 @@ def test_not_holiday(self): ) def test_2022(self): - self.assertHolidaysEqual( - Norway(observed=False, years=2022), + self.assertHolidays( ("2022-01-01", "Første nyttårsdag"), ("2022-04-14", "Skjærtorsdag"), ("2022-04-15", "Langfredag"), diff --git a/test/countries/test_philippines.py b/test/countries/test_philippines.py index fe60c7cb6..b5e7d5df8 100644 --- a/test/countries/test_philippines.py +++ b/test/countries/test_philippines.py @@ -21,8 +21,7 @@ def test_country_aliases(self): self.assertCountryAliases(Philippines, PH, PHL) def test_2022(self): - self.assertHolidaysEqual( - Philippines(years=2022), + self.assertHolidays( ("2022-01-01", "New Year's Day"), ("2022-02-01", "Chinese New Year"), ("2022-02-25", "EDSA Revolution Anniversary"), diff --git a/test/countries/test_sweden.py b/test/countries/test_sweden.py index 779bf5c93..b96bbd229 100644 --- a/test/countries/test_sweden.py +++ b/test/countries/test_sweden.py @@ -145,8 +145,7 @@ def test_not_holiday(self): ) def test_2022(self): - self.assertHolidaysEqual( - Sweden(include_sundays=False, observed=False, years=2022), + self.assertHolidays( ("2022-01-01", "Nyårsdagen"), ("2022-01-06", "Trettondedag jul"), ("2022-04-15", "Långfredagen"), diff --git a/test/countries/test_thailand.py b/test/countries/test_thailand.py index c58c5726d..51559c3a4 100644 --- a/test/countries/test_thailand.py +++ b/test/countries/test_thailand.py @@ -21,8 +21,7 @@ def test_country_aliases(self): self.assertCountryAliases(Thailand, TH, THA) def test_2022(self): - self.assertHolidaysEqual( - Thailand(years=2022), + self.assertHolidays( ("2022-01-01", "New Year's Day"), ("2022-01-03", "New Year's Day (in lieu)"), ("2022-02-16", "Makha Bucha"), From f5f6d9171b82b6ab1cc31bd605bd9137212e62c1 Mon Sep 17 00:00:00 2001 From: Arkadii Yakovets Date: Fri, 20 Jan 2023 08:40:08 -0800 Subject: [PATCH 131/138] Add San Marino initial support. --- README.rst | 5 +- holidays/countries/__init__.py | 1 + holidays/countries/san_marino.py | 94 +++++++++++++++++++++++++++++++ test/countries/test_san_marino.py | 67 ++++++++++++++++++++++ 4 files changed, 166 insertions(+), 1 deletion(-) create mode 100644 holidays/countries/san_marino.py create mode 100644 test/countries/test_san_marino.py diff --git a/README.rst b/README.rst index 5ca95a0d2..f2c2df186 100644 --- a/README.rst +++ b/README.rst @@ -106,7 +106,7 @@ Available Countries .. _ISO 3166-1 alpha-2 code: https://en.wikipedia.org/wiki/List_of_ISO_3166_country_codes -We currently support 106 countries. The standard way to refer to a country is by +We currently support 107 countries. The standard way to refer to a country is by using its `ISO 3166-1 alpha-2 code`_, the same used for domain names. The following countries and their subdivisions are available: @@ -364,6 +364,9 @@ following countries and their subdivisions are available: * - Russia - RU - None + * - San Marino + - SM + - None * - Saudi Arabia - SA - None diff --git a/holidays/countries/__init__.py b/holidays/countries/__init__.py index 5a0f388b1..c041ae5fd 100644 --- a/holidays/countries/__init__.py +++ b/holidays/countries/__init__.py @@ -91,6 +91,7 @@ from .portugal import PT, PRT, Portugal from .romania import RO, ROU, Romania from .russia import RU, RUS, Russia +from .san_marino import SM, SMR, SanMarino from .saudi_arabia import SA, SAU, SaudiArabia from .serbia import RS, SRB, Serbia from .singapore import SG, SGP, Singapore diff --git a/holidays/countries/san_marino.py b/holidays/countries/san_marino.py new file mode 100644 index 000000000..ac0afe078 --- /dev/null +++ b/holidays/countries/san_marino.py @@ -0,0 +1,94 @@ +# 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 (c) 2017-2022 +# ryanss (c) 2014-2017 +# Website: https://github.com/dr-prodigy/python-holidays +# License: MIT (see LICENSE file) + +from datetime import date + +from dateutil.easter import easter +from dateutil.relativedelta import relativedelta as rd + +from holidays.constants import JAN, FEB, MAR, MAY, JUL, AUG, SEP, NOV, DEC +from holidays.holiday_base import HolidayBase + + +class SanMarino(HolidayBase): + """ + References: + - https://en.wikipedia.org/wiki/Public_holidays_in_San_Marino + """ + + country = "SM" + + def _populate(self, year: int) -> None: + super()._populate(year) + + # New Year's Day. + self[date(year, JAN, 1)] = "New Year's Day" + + # Epiphany. + self[date(year, JAN, 6)] = "Epiphany" + + # Feast of Saint Agatha. + self[date(year, FEB, 5)] = "Feast of Saint Agatha" + + # Anniversary of the Arengo. + self[date(year, MAR, 25)] = "Anniversary of the Arengo" + + easter_sunday = easter(year) + + # Easter Sunday. + self[easter_sunday] = "Easter Sunday" + + # Easter Monday. + self[easter_sunday + rd(days=+1)] = "Easter Monday" + + # Labour Day. + self[date(year, MAY, 1)] = "Labour Day" + + # Corpus Cristi. + self[easter_sunday + rd(days=+60)] = "Corpus Cristi" + + # Liberation from Fascism Day. + self[date(year, JUL, 28)] = "Liberation from Fascism Day" + + # Assumption of Mary. + self[date(year, AUG, 15)] = "Assumption Day" + + # The Feast of Saint Marinus and the Republic. + self[date(year, SEP, 3)] = "Foundation Day" + + # All Saints' Day. + self[date(year, NOV, 1)] = "All Saints' Day" + + # Commemoration of the Dead. + self[date(year, NOV, 2)] = "Commemoration of the Dead" + + # Immaculate Conception. + self[date(year, DEC, 8)] = "Immaculate Conception Day" + + # Christmas Eve. + self[date(year, DEC, 24)] = "Christmas Eve" + + # Christmas Day. + self[date(year, DEC, 25)] = "Christmas Day" + + # Saint Stephen's Day. + self[date(year, DEC, 26)] = "Saint Stephen's Day" + + # New Year's Eve. + self[date(year, DEC, 31)] = "New Year's Eve" + + +class SM(SanMarino): + pass + + +class SMR(SanMarino): + pass diff --git a/test/countries/test_san_marino.py b/test/countries/test_san_marino.py new file mode 100644 index 000000000..21a000895 --- /dev/null +++ b/test/countries/test_san_marino.py @@ -0,0 +1,67 @@ +# 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 (c) 2017-2022 +# ryanss (c) 2014-2017 +# Website: https://github.com/dr-prodigy/python-holidays +# License: MIT (see LICENSE file) + +from holidays.countries.san_marino import SM, SMR, SanMarino +from test.common import TestCase + + +class TestSanMarino(TestCase): + def setUp(self): + self.holidays = SanMarino() + + def test_country_aliases(self): + self.assertCountryAliases(SanMarino, SM, SMR) + + def test_2022(self): + self.assertHolidaysEqual( + SanMarino(years=2022), + ("2022-01-01", "New Year's Day"), + ("2022-01-06", "Epiphany"), + ("2022-02-05", "Feast of Saint Agatha"), + ("2022-03-25", "Anniversary of the Arengo"), + ("2022-04-17", "Easter Sunday"), + ("2022-04-18", "Easter Monday"), + ("2022-05-01", "Labour Day"), + ("2022-06-16", "Corpus Cristi"), + ("2022-07-28", "Liberation from Fascism Day"), + ("2022-08-15", "Assumption Day"), + ("2022-09-03", "Foundation Day"), + ("2022-11-01", "All Saints' Day"), + ("2022-11-02", "Commemoration of the Dead"), + ("2022-12-08", "Immaculate Conception Day"), + ("2022-12-24", "Christmas Eve"), + ("2022-12-25", "Christmas Day"), + ("2022-12-26", "Saint Stephen's Day"), + ("2022-12-31", "New Year's Eve"), + ) + + def test_2023(self): + self.assertHolidaysEqual( + SanMarino(years=2023), + ("2023-01-01", "New Year's Day"), + ("2023-01-06", "Epiphany"), + ("2023-02-05", "Feast of Saint Agatha"), + ("2023-03-25", "Anniversary of the Arengo"), + ("2023-04-09", "Easter Sunday"), + ("2023-04-10", "Easter Monday"), + ("2023-05-01", "Labour Day"), + ("2023-06-08", "Corpus Cristi"), + ("2023-07-28", "Liberation from Fascism Day"), + ("2023-08-15", "Assumption Day"), + ("2023-09-03", "Foundation Day"), + ("2023-11-01", "All Saints' Day"), + ("2023-11-02", "Commemoration of the Dead"), + ("2023-12-08", "Immaculate Conception Day"), + ("2023-12-24", "Christmas Eve"), + ("2023-12-25", "Christmas Day"), + ("2023-12-26", "Saint Stephen's Day"), + ("2023-12-31", "New Year's Eve"), + ) From 1b2bd801716b687b5f319ab60bc1c55d9b519020 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 20 Jan 2023 22:00:37 +0000 Subject: [PATCH 132/138] Bump actions/setup-python from 4.4.0 to 4.5.0 Bumps [actions/setup-python](https://github.com/actions/setup-python) from 4.4.0 to 4.5.0. - [Release notes](https://github.com/actions/setup-python/releases) - [Commits](https://github.com/actions/setup-python/compare/v4.4.0...v4.5.0) --- updated-dependencies: - dependency-name: actions/setup-python dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- .github/workflows/ci-cd.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml index d99560a66..409008369 100644 --- a/.github/workflows/ci-cd.yml +++ b/.github/workflows/ci-cd.yml @@ -12,7 +12,7 @@ jobs: - name: Check out repo uses: actions/checkout@v3 - name: Set up Python - uses: actions/setup-python@v4.4.0 + uses: actions/setup-python@v4.5.0 - name: Run pre-commit uses: pre-commit/action@v3.0.0 @@ -28,7 +28,7 @@ jobs: steps: - uses: actions/checkout@v3 - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v4.4.0 + uses: actions/setup-python@v4.5.0 with: python-version: ${{ matrix.python-version }} cache: pip @@ -68,7 +68,7 @@ jobs: steps: - uses: actions/checkout@v3 - name: Set up Python 3.9 - uses: actions/setup-python@v4.4.0 + uses: actions/setup-python@v4.5.0 with: python-version: "3.10" - name: Install dependencies From 83e2a4624501b5af986e3d71aa04e42aab4ceef9 Mon Sep 17 00:00:00 2001 From: Arkadii Yakovets Date: Mon, 23 Jan 2023 08:14:28 -0800 Subject: [PATCH 133/138] Add Vatican City initial support. --- README.rst | 5 +- holidays/countries/__init__.py | 1 + holidays/countries/vatican_city.py | 90 +++++++++++++++++++++++++++++ test/countries/test_vatican_city.py | 63 ++++++++++++++++++++ 4 files changed, 158 insertions(+), 1 deletion(-) create mode 100644 holidays/countries/vatican_city.py create mode 100644 test/countries/test_vatican_city.py diff --git a/README.rst b/README.rst index 5ca95a0d2..c9291e23c 100644 --- a/README.rst +++ b/README.rst @@ -106,7 +106,7 @@ Available Countries .. _ISO 3166-1 alpha-2 code: https://en.wikipedia.org/wiki/List_of_ISO_3166_country_codes -We currently support 106 countries. The standard way to refer to a country is by +We currently support 107 countries. The standard way to refer to a country is by using its `ISO 3166-1 alpha-2 code`_, the same used for domain names. The following countries and their subdivisions are available: @@ -424,6 +424,9 @@ following countries and their subdivisions are available: * - Uzbekistan - UZ - None + * - Vatican City + - VA + - None * - Venezuela - VE - None diff --git a/holidays/countries/__init__.py b/holidays/countries/__init__.py index 5a0f388b1..df1ee5f8a 100644 --- a/holidays/countries/__init__.py +++ b/holidays/countries/__init__.py @@ -111,6 +111,7 @@ from .united_states import US, USA, UnitedStates from .uruguay import UY, URY, Uruguay from .uzbekistan import UZ, UZB, Uzbekistan +from .vatican_city import VA, VAT, VaticanCity from .venezuela import VE, VEN, Venezuela from .vietnam import VN, VNM, Vietnam from .zambia import ZM, ZMB, Zambia diff --git a/holidays/countries/vatican_city.py b/holidays/countries/vatican_city.py new file mode 100644 index 000000000..7b6848b54 --- /dev/null +++ b/holidays/countries/vatican_city.py @@ -0,0 +1,90 @@ +# 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 (c) 2017-2022 +# ryanss (c) 2014-2017 +# Website: https://github.com/dr-prodigy/python-holidays +# License: MIT (see LICENSE file) + +from datetime import date + +from dateutil.easter import easter +from dateutil.relativedelta import relativedelta as rd + +from holidays.constants import JAN, FEB, MAR, APR, MAY, JUN, AUG, SEP, NOV, DEC +from holidays.holiday_base import HolidayBase + + +class VaticanCity(HolidayBase): + """ + References: + - https://en.wikipedia.org/wiki/Public_holidays_in_Vatican_City + """ + + country = "VA" + + def _populate(self, year: int) -> None: + super()._populate(year) + + # Solemnity of Mary Day. + self[date(year, JAN, 1)] = "Solemnity of Mary Day" + + # Epiphany. + self[date(year, JAN, 6)] = "Epiphany" + + # Lateran Treaty Day. + self[date(year, FEB, 11)] = "Lateran Treaty Day" + + # Anniversary of the election of Pope Francis. + self[ + date(year, MAR, 13) + ] = "Anniversary of the election of Pope Francis" + + # Saint Joseph's Day. + self[date(year, MAR, 19)] = "Saint Joseph's Day" + + easter_sunday = easter(year) + + # Easter Sunday. + self[easter_sunday] = "Easter Sunday" + + # Easter Monday. + self[easter_sunday + rd(days=+1)] = "Easter Monday" + + # Saint George's Day. + self[date(year, APR, 23)] = "Saint George's Day" + + # Saint Joseph the Worker's Day. + self[date(year, MAY, 1)] = "Saint Joseph the Worker's Day" + + # Saints Peter and Paul. + self[date(year, JUN, 29)] = "Saint Peter and Saint Paul's Day" + + # Assumption of Mary Day. + self[date(year, AUG, 15)] = "Assumption Day" + + # Nativity Of Mary Day. + self[date(year, SEP, 8)] = "Nativity of Mary Day" + + # All Saints' Day. + self[date(year, NOV, 1)] = "All Saints' Day" + + # Immaculate Conception. + self[date(year, DEC, 8)] = "Immaculate Conception Day" + + # Christmas Day. + self[date(year, DEC, 25)] = "Christmas Day" + + # Saint Stephen's Day. + self[date(year, DEC, 26)] = "Saint Stephen's Day" + + +class VA(VaticanCity): + pass + + +class VAT(VaticanCity): + pass diff --git a/test/countries/test_vatican_city.py b/test/countries/test_vatican_city.py new file mode 100644 index 000000000..9a2bc14c5 --- /dev/null +++ b/test/countries/test_vatican_city.py @@ -0,0 +1,63 @@ +# 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 (c) 2017-2022 +# ryanss (c) 2014-2017 +# Website: https://github.com/dr-prodigy/python-holidays +# License: MIT (see LICENSE file) + +from holidays.countries.vatican_city import VA, VAT, VaticanCity +from test.common import TestCase + + +class TestVaticanCity(TestCase): + def setUp(self): + self.holidays = VaticanCity() + + def test_country_aliases(self): + self.assertCountryAliases(VaticanCity, VA, VAT) + + def test_2022(self): + self.assertHolidaysEqual( + VaticanCity(years=2022), + ("2022-01-01", "Solemnity of Mary Day"), + ("2022-01-06", "Epiphany"), + ("2022-02-11", "Lateran Treaty Day"), + ("2022-03-13", "Anniversary of the election of Pope Francis"), + ("2022-03-19", "Saint Joseph's Day"), + ("2022-04-17", "Easter Sunday"), + ("2022-04-18", "Easter Monday"), + ("2022-04-23", "Saint George's Day"), + ("2022-05-01", "Saint Joseph the Worker's Day"), + ("2022-06-29", "Saint Peter and Saint Paul's Day"), + ("2022-08-15", "Assumption Day"), + ("2022-09-08", "Nativity of Mary Day"), + ("2022-11-01", "All Saints' Day"), + ("2022-12-08", "Immaculate Conception Day"), + ("2022-12-25", "Christmas Day"), + ("2022-12-26", "Saint Stephen's Day"), + ) + + def test_2023(self): + self.assertHolidaysEqual( + VaticanCity(years=2023), + ("2023-01-01", "Solemnity of Mary Day"), + ("2023-01-06", "Epiphany"), + ("2023-02-11", "Lateran Treaty Day"), + ("2023-03-13", "Anniversary of the election of Pope Francis"), + ("2023-03-19", "Saint Joseph's Day"), + ("2023-04-09", "Easter Sunday"), + ("2023-04-10", "Easter Monday"), + ("2023-04-23", "Saint George's Day"), + ("2023-05-01", "Saint Joseph the Worker's Day"), + ("2023-06-29", "Saint Peter and Saint Paul's Day"), + ("2023-08-15", "Assumption Day"), + ("2023-09-08", "Nativity of Mary Day"), + ("2023-11-01", "All Saints' Day"), + ("2023-12-08", "Immaculate Conception Day"), + ("2023-12-25", "Christmas Day"), + ("2023-12-26", "Saint Stephen's Day"), + ) From 098b9635b0c8f8246e3c3038246358776c26a8fe Mon Sep 17 00:00:00 2001 From: ~Jhellico Date: Wed, 28 Dec 2022 13:07:15 +0200 Subject: [PATCH 134/138] Dominican Republic fix Corpus Christi holiday, tests refactoring --- holidays/countries/dominican_republic.py | 20 ++-- test/countries/test_dominican_republic.py | 137 ++++++++++++---------- 2 files changed, 89 insertions(+), 68 deletions(-) diff --git a/holidays/countries/dominican_republic.py b/holidays/countries/dominican_republic.py index a12546d6c..5863eb264 100644 --- a/holidays/countries/dominican_republic.py +++ b/holidays/countries/dominican_republic.py @@ -16,7 +16,7 @@ from dateutil.relativedelta import relativedelta as rd from holidays.constants import JAN, FEB, MAY, JUN, AUG, SEP, NOV, DEC, TUE -from holidays.constants import WED, THU, FRI +from holidays.constants import WED, THU, FRI, SUN from holidays.holiday_base import HolidayBase @@ -31,9 +31,9 @@ class DominicanRepublic(HolidayBase): @staticmethod def __change_day_by_law(holiday, latest_days=(THU, FRI)): # Law No. 139-97 - Holidays Dominican Republic - Jun 27, 1997 - if holiday >= date(1997, 6, 27): + if holiday >= date(1997, JUN, 27): if holiday.weekday() in {TUE, WED}: - holiday -= rd(weekday=MO(-1)) + holiday += rd(weekday=MO(-1)) elif holiday.weekday() in latest_days: holiday += rd(weekday=MO(1)) return holiday @@ -58,21 +58,27 @@ def _populate(self, year): # Independence Day self[date(year, FEB, 27)] = "Día de Independencia [Independence Day]" + easter_date = easter(year) + # Good Friday - self[easter(year) + rd(days=-2)] = "Viernes Santo [Good Friday]" + self[easter_date + rd(days=-2)] = "Viernes Santo [Good Friday]" # Labor Day - labor_day = self.__change_day_by_law(date(year, MAY, 1), (3, 4, 6)) + labor_day = self.__change_day_by_law( + date(year, MAY, 1), (THU, FRI, SUN) + ) self[labor_day] = "Día del Trabajo [Labor Day]" # Feast of Corpus Christi - self[date(year, JUN, 11)] = "Corpus Christi [Feast of Corpus Christi]" + self[ + easter_date + rd(days=+60) + ] = "Corpus Christi [Feast of Corpus Christi]" # Restoration Day # Judgment No. 14 of Feb 20, 2008 of the Supreme Court of Justice restoration_day = ( date(year, AUG, 16) - if ((year - 2000) % 4 == 0) and year < 2008 + if year <= 2007 and year % 4 == 0 else self.__change_day_by_law(date(year, AUG, 16)) ) self[restoration_day] = "Día de la Restauración [Restoration Day]" diff --git a/test/countries/test_dominican_republic.py b/test/countries/test_dominican_republic.py index a6a670577..053638af4 100644 --- a/test/countries/test_dominican_republic.py +++ b/test/countries/test_dominican_republic.py @@ -9,72 +9,87 @@ # Website: https://github.com/dr-prodigy/python-holidays # License: MIT (see LICENSE file) -import unittest -from datetime import date +from holidays.countries.dominican_republic import DO, DOM, DominicanRepublic +from test.common import TestCase -import holidays - -class TestDominicanRepublic(unittest.TestCase): +class TestDominicanRepublic(TestCase): def setUp(self): - self.do_holidays = holidays.DO() + self.holidays = DominicanRepublic() + + def test_country_aliases(self): + self.assertCountryAliases(DominicanRepublic, DO, DOM) - def test_do_holidays_2020(self): - year = 2020 + def test_2020(self): + self.assertHolidaysEqual( + DominicanRepublic(years=2020), + ("2020-01-01", "Año Nuevo [New Year's Day]"), + ("2020-01-06", "Día de los Santos Reyes [Epiphany]"), + ("2020-01-21", "Día de la Altagracia [Lady of Altagracia]"), + ("2020-01-26", "Día de Duarte [Juan Pablo Duarte Day]"), + ("2020-02-27", "Día de Independencia [Independence Day]"), + ("2020-04-10", "Viernes Santo [Good Friday]"), + ("2020-05-04", "Día del Trabajo [Labor Day]"), + ("2020-06-11", "Corpus Christi [Feast of Corpus Christi]"), + ("2020-08-16", "Día de la Restauración [Restoration Day]"), + ("2020-09-24", "Día de las Mercedes [Our Lady of Mercedes Day]"), + ("2020-11-09", "Día de la Constitución [Constitution Day]"), + ("2020-12-25", "Día de Navidad [Christmas Day]"), + ) - # New Year's Day - self.assertIn(date(year, 1, 1), self.do_holidays) - # Epiphany - self.assertIn(date(year, 1, 6), self.do_holidays) - # Lady of Altagracia - self.assertIn(date(year, 1, 21), self.do_holidays) - # Juan Pablo Duarte Day - self.assertIn(date(year, 1, 26), self.do_holidays) - # Independence Day - self.assertIn(date(year, 2, 27), self.do_holidays) - # Good Friday - self.assertIn(date(year, 4, 10), self.do_holidays) - # Labor Day - self.assertIn(date(year, 5, 4), self.do_holidays) - # Feast of Corpus Christi - self.assertIn(date(year, 6, 11), self.do_holidays) - # Restoration Day - self.assertIn(date(year, 8, 16), self.do_holidays) - # Our Lady of Mercedes Day - self.assertIn(date(year, 9, 24), self.do_holidays) - # Constitution Day - self.assertIn(date(year, 11, 9), self.do_holidays) - # Christmas Day - self.assertIn(date(year, 12, 25), self.do_holidays) + def test_2021(self): + self.assertHolidaysEqual( + DominicanRepublic(years=2021), + ("2021-01-01", "Año Nuevo [New Year's Day]"), + ("2021-01-04", "Día de los Santos Reyes [Epiphany]"), + ("2021-01-21", "Día de la Altagracia [Lady of Altagracia]"), + ("2021-01-25", "Día de Duarte [Juan Pablo Duarte Day]"), + ("2021-02-27", "Día de Independencia [Independence Day]"), + ("2021-04-02", "Viernes Santo [Good Friday]"), + ("2021-05-01", "Día del Trabajo [Labor Day]"), + ("2021-06-03", "Corpus Christi [Feast of Corpus Christi]"), + ("2021-08-16", "Día de la Restauración [Restoration Day]"), + ("2021-09-24", "Día de las Mercedes [Our Lady of Mercedes Day]"), + ("2021-11-06", "Día de la Constitución [Constitution Day]"), + ("2021-12-25", "Día de Navidad [Christmas Day]"), + ) - # Change day by law test - # New Year's Day - self.assertIn(date(2019, 1, 1), self.do_holidays) + def test_2022(self): + self.assertHolidaysEqual( + DominicanRepublic(years=2022), + ("2022-01-01", "Año Nuevo [New Year's Day]"), + ("2022-01-10", "Día de los Santos Reyes [Epiphany]"), + ("2022-01-21", "Día de la Altagracia [Lady of Altagracia]"), + ("2022-01-24", "Día de Duarte [Juan Pablo Duarte Day]"), + ("2022-02-27", "Día de Independencia [Independence Day]"), + ("2022-04-15", "Viernes Santo [Good Friday]"), + ("2022-05-02", "Día del Trabajo [Labor Day]"), + ("2022-06-16", "Corpus Christi [Feast of Corpus Christi]"), + ("2022-08-15", "Día de la Restauración [Restoration Day]"), + ("2022-09-24", "Día de las Mercedes [Our Lady of Mercedes Day]"), + ("2022-11-06", "Día de la Constitución [Constitution Day]"), + ("2022-12-25", "Día de Navidad [Christmas Day]"), + ) def test_change_day_by_law(self): - year = 1996 - self.do_holidays = holidays.DO(years=[year]) - # New Year's Day - self.assertIn(date(year, 1, 1), self.do_holidays) - # Epiphany - self.assertIn(date(year, 1, 6), self.do_holidays) - # Lady of Altagracia - self.assertIn(date(year, 1, 21), self.do_holidays) - # Juan Pablo Duarte Day - self.assertIn(date(year, 1, 26), self.do_holidays) - # Independence Day - self.assertIn(date(year, 2, 27), self.do_holidays) - # Good Friday - self.assertIn(date(year, 4, 5), self.do_holidays) - # Labor Day - self.assertIn(date(year, 5, 1), self.do_holidays) - # Feast of Corpus Christi - self.assertIn(date(year, 6, 11), self.do_holidays) - # Restoration Day - self.assertIn(date(year, 8, 16), self.do_holidays) - # Our Lady of Mercedes Day - self.assertIn(date(year, 9, 24), self.do_holidays) - # Constitution Day - self.assertIn(date(year, 11, 6), self.do_holidays) - # Christmas Day - self.assertIn(date(year, 12, 25), self.do_holidays) + self.assertHoliday( + "1996-01-06", + "1997-01-06", + "1998-01-05", + "1998-01-26", + "1999-01-25", + "1996-05-01", + "1998-05-04", + "1996-11-06", + "1997-11-10", + "2000-08-16", + "2001-08-20", + ) + + self.assertNoHoliday( + "1998-01-06", + "1999-01-26", + "1998-05-01", + "1997-11-06", + "2001-08-16", + ) From ca11855094db0bc708b82a45137ce174c7c03733 Mon Sep 17 00:00:00 2001 From: ~Jhellico Date: Tue, 24 Jan 2023 20:08:52 +0200 Subject: [PATCH 135/138] fix Co-authored-by: Arkadii Yakovets --- holidays/countries/dominican_republic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/holidays/countries/dominican_republic.py b/holidays/countries/dominican_republic.py index 5863eb264..1c508a17f 100644 --- a/holidays/countries/dominican_republic.py +++ b/holidays/countries/dominican_republic.py @@ -35,7 +35,7 @@ def __change_day_by_law(holiday, latest_days=(THU, FRI)): if holiday.weekday() in {TUE, WED}: holiday += rd(weekday=MO(-1)) elif holiday.weekday() in latest_days: - holiday += rd(weekday=MO(1)) + holiday += rd(weekday=MO(+1)) return holiday def _populate(self, year): From 062fd5a6474b68fda4a941bd2dec33df754b03d0 Mon Sep 17 00:00:00 2001 From: Arkadii Yakovets Date: Tue, 24 Jan 2023 13:53:34 -0800 Subject: [PATCH 136/138] Update tests. --- test/countries/test_albania.py | 6 ++---- test/countries/test_andorra.py | 6 ++---- test/countries/test_dominican_republic.py | 9 +++------ test/countries/test_montenegro.py | 9 +++------ test/countries/test_san_marino.py | 6 ++---- test/countries/test_vatican_city.py | 6 ++---- 6 files changed, 14 insertions(+), 28 deletions(-) diff --git a/test/countries/test_albania.py b/test/countries/test_albania.py index b92e8139f..3d6ffa496 100644 --- a/test/countries/test_albania.py +++ b/test/countries/test_albania.py @@ -21,8 +21,7 @@ def test_country_aliases(self): self.assertCountryAliases(Albania, AL, ALB) def test_2022(self): - self.assertHolidaysEqual( - Albania(years=2022), + self.assertHolidays( ("2022-01-01", "New Year's Day"), ("2022-01-02", "New Year's Day"), ("2022-01-03", "New Year's Day (Observed)"), @@ -46,8 +45,7 @@ def test_2022(self): ) def test_2023(self): - self.assertHolidaysEqual( - Albania(years=2023), + self.assertHolidays( ("2023-01-01", "New Year's Day"), ("2023-01-02", "New Year's Day, New Year's Day (Observed)"), ("2023-03-14", "Summer Day"), diff --git a/test/countries/test_andorra.py b/test/countries/test_andorra.py index cd60ae403..8277dcaed 100644 --- a/test/countries/test_andorra.py +++ b/test/countries/test_andorra.py @@ -21,8 +21,7 @@ def test_country_aliases(self): self.assertCountryAliases(Andorra, AD, AND) def test_2022(self): - self.assertHolidaysEqual( - Andorra(years=2022), + self.assertHolidays( ("2022-01-01", "New Year's Day"), ("2022-01-06", "Epiphany"), ("2022-03-01", "Carnival"), @@ -86,8 +85,7 @@ def test_2022(self): ) def test_2023(self): - self.assertHolidaysEqual( - Andorra(years=2023), + self.assertHolidays( ("2023-01-01", "New Year's Day"), ("2023-01-06", "Epiphany"), ("2023-02-21", "Carnival"), diff --git a/test/countries/test_dominican_republic.py b/test/countries/test_dominican_republic.py index 053638af4..3108cb792 100644 --- a/test/countries/test_dominican_republic.py +++ b/test/countries/test_dominican_republic.py @@ -21,8 +21,7 @@ def test_country_aliases(self): self.assertCountryAliases(DominicanRepublic, DO, DOM) def test_2020(self): - self.assertHolidaysEqual( - DominicanRepublic(years=2020), + self.assertHolidays( ("2020-01-01", "Año Nuevo [New Year's Day]"), ("2020-01-06", "Día de los Santos Reyes [Epiphany]"), ("2020-01-21", "Día de la Altagracia [Lady of Altagracia]"), @@ -38,8 +37,7 @@ def test_2020(self): ) def test_2021(self): - self.assertHolidaysEqual( - DominicanRepublic(years=2021), + self.assertHolidays( ("2021-01-01", "Año Nuevo [New Year's Day]"), ("2021-01-04", "Día de los Santos Reyes [Epiphany]"), ("2021-01-21", "Día de la Altagracia [Lady of Altagracia]"), @@ -55,8 +53,7 @@ def test_2021(self): ) def test_2022(self): - self.assertHolidaysEqual( - DominicanRepublic(years=2022), + self.assertHolidays( ("2022-01-01", "Año Nuevo [New Year's Day]"), ("2022-01-10", "Día de los Santos Reyes [Epiphany]"), ("2022-01-21", "Día de la Altagracia [Lady of Altagracia]"), diff --git a/test/countries/test_montenegro.py b/test/countries/test_montenegro.py index 9aa86e753..a06f77e2e 100644 --- a/test/countries/test_montenegro.py +++ b/test/countries/test_montenegro.py @@ -21,8 +21,7 @@ def test_country_aliases(self): self.assertCountryAliases(Montenegro, ME, MNE) def test_2021(self): - self.assertHolidaysEqual( - Montenegro(years=2021), + self.assertHolidays( ("2021-01-01", "New Year's Day"), ("2021-01-02", "New Year's Day"), ("2021-01-06", "Orthodox Christmas Eve"), @@ -38,8 +37,7 @@ def test_2021(self): ) def test_2022(self): - self.assertHolidaysEqual( - Montenegro(years=2022), + self.assertHolidays( ("2022-01-01", "New Year's Day"), ("2022-01-02", "New Year's Day"), ("2022-01-03", "New Year's Day (Observed)"), @@ -59,8 +57,7 @@ def test_2022(self): ) def test_2023(self): - self.assertHolidaysEqual( - Montenegro(years=2023), + self.assertHolidays( ("2023-01-01", "New Year's Day"), ("2023-01-02", "New Year's Day (Observed)"), ("2023-01-03", "New Year's Day (Observed)"), diff --git a/test/countries/test_san_marino.py b/test/countries/test_san_marino.py index 21a000895..4bbeaf2d4 100644 --- a/test/countries/test_san_marino.py +++ b/test/countries/test_san_marino.py @@ -21,8 +21,7 @@ def test_country_aliases(self): self.assertCountryAliases(SanMarino, SM, SMR) def test_2022(self): - self.assertHolidaysEqual( - SanMarino(years=2022), + self.assertHolidays( ("2022-01-01", "New Year's Day"), ("2022-01-06", "Epiphany"), ("2022-02-05", "Feast of Saint Agatha"), @@ -44,8 +43,7 @@ def test_2022(self): ) def test_2023(self): - self.assertHolidaysEqual( - SanMarino(years=2023), + self.assertHolidays( ("2023-01-01", "New Year's Day"), ("2023-01-06", "Epiphany"), ("2023-02-05", "Feast of Saint Agatha"), diff --git a/test/countries/test_vatican_city.py b/test/countries/test_vatican_city.py index 9a2bc14c5..bd1f16c79 100644 --- a/test/countries/test_vatican_city.py +++ b/test/countries/test_vatican_city.py @@ -21,8 +21,7 @@ def test_country_aliases(self): self.assertCountryAliases(VaticanCity, VA, VAT) def test_2022(self): - self.assertHolidaysEqual( - VaticanCity(years=2022), + self.assertHolidays( ("2022-01-01", "Solemnity of Mary Day"), ("2022-01-06", "Epiphany"), ("2022-02-11", "Lateran Treaty Day"), @@ -42,8 +41,7 @@ def test_2022(self): ) def test_2023(self): - self.assertHolidaysEqual( - VaticanCity(years=2023), + self.assertHolidays( ("2023-01-01", "Solemnity of Mary Day"), ("2023-01-06", "Epiphany"), ("2023-02-11", "Lateran Treaty Day"), From 2384bcc70618fccb41d047580abb9e8925bfba6b Mon Sep 17 00:00:00 2001 From: Arkadii Yakovets Date: Wed, 25 Jan 2023 08:58:40 -0800 Subject: [PATCH 137/138] Update changes file. --- CHANGES | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/CHANGES b/CHANGES index 64e05689f..d66f0194e 100644 --- a/CHANGES +++ b/CHANGES @@ -4,10 +4,22 @@ Version 0.19 Released ???????? ??, ???? - Copyright update 2023 -- Added Arkadii Yakovets (arkid15r) to project collaborators / maintainers - welcome! -- Support for Monaco #877 (KJhellico) -- Support for Bahrain #888 (arkid15r) -- Japan: optimizations and refactoring #879 (KJhellico) +- Added Arkadii Yakovets (@arkid15r) to project collaborators / maintainers - welcome! +- Add supported countries tests #878 (@arkid15r) +- Update tox configuration #881 (@arkid15r) +- Use augmented assignment statements #890 (@arkid15r) +- Clean up timedelta/relativedelta usage #892, #894 (@arkid15r) +- Add Albania initial support #895 (@arkid15r) +- Add Andorra initial support #896 (@arkid15r) +- Add Bahrain initial support #888 (@arkid15r) +- Add Montenegro initial support #897 (@arkid15r) +- Add San Marino initial support #898 (@arkid15r) +- Add Vatican City initial support #904 (@arkid15r) +- Add Monaco holidays #877 (@KJhellico) +- Migrate prophet.hdays countries #887 (@arkid15r) +- Dominican Republic fix Corpus Christi holiday, tests refactoring #906 (@KJhellico) +- Japan: substitute holidays and citizens' holidays calculation #879 (@KJhellico) +- Singapore holidays update #880 (@KJhellico) Version 0.18 ============ From 8004eb091d3ec9bbfa6f5b6abd09a382a58daf3e Mon Sep 17 00:00:00 2001 From: Arkadii Yakovets Date: Mon, 30 Jan 2023 13:23:12 -0800 Subject: [PATCH 138/138] Update the release date. --- CHANGES | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index d66f0194e..1c8c318c0 100644 --- a/CHANGES +++ b/CHANGES @@ -1,7 +1,7 @@ Version 0.19 ============ -Released ???????? ??, ???? +Released January 30, 2023 - Copyright update 2023 - Added Arkadii Yakovets (@arkid15r) to project collaborators / maintainers - welcome!