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 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 5ce1a4e83..6ab43cd59 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: @@ -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 eb1c2d243..1c8c318c0 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,26 @@ +Version 0.19 +============ + +Released January 30, 2023 + +- Copyright update 2023 +- 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 ============ 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/README.rst b/README.rst index 4f249dee7..e354dba0e 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 111 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,12 @@ following countries and their subdivisions are available: * - Country - Code - Subdivisions Available + * - Albania + - AL + - None + * - Andorra + - AD + - Parishes: AD-02, AD-03, AD-04, AD-05, AD-06, AD-07, AD-08 * - Angola - AO - None @@ -139,6 +145,9 @@ following countries and their subdivisions are available: * - Azerbaijan - AZ - None + * - Bahrain + - BH + - None * - Bangladesh - BD - None @@ -153,13 +162,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 +177,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 +193,7 @@ following countries and their subdivisions are available: * - Cuba - CU - None - * - Curaçao + * - Curacao - CW - None * - Cyprus @@ -208,6 +217,9 @@ following countries and their subdivisions are available: * - Estonia - EE - None + * - Eswatini + - SZ + - None * - Ethiopia - ET - None @@ -216,7 +228,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 @@ -255,7 +267,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 @@ -268,6 +280,9 @@ following countries and their subdivisions are available: * - Kenya - KE - None + * - Kyrgyzstan + - KG + - None * - Latvia - LV - None @@ -286,12 +301,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 @@ -301,21 +316,27 @@ following countries and their subdivisions are available: * - Moldova - MD - None + * - Monaco + - MC + - None + * - Montenegro + - ME + - None * - Morocco - MA - None * - 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) @@ -337,18 +358,24 @@ following countries and their subdivisions are available: * - Peru - PE - None + * - Philippines + - PH + - None * - Poland - PL - 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 * - Russia - RU - None + * - San Marino + - SM + - None * - Saudi Arabia - SA - None @@ -372,10 +399,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 +409,15 @@ following countries and their subdivisions are available: * - Taiwan - TW - None - * - Turkey - - TR + * - Thailand + - TH - None * - Tunisia - TN - None + * - Turkey + - TR + - None * - Ukraine - UA - None @@ -399,7 +426,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 @@ -409,6 +436,9 @@ following countries and their subdivisions are available: * - Uzbekistan - UZ - None + * - Vatican City + - VA + - None * - Venezuela - VE - None 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..2576446b2 100644 --- a/holidays/countries/__init__.py +++ b/holidays/countries/__init__.py @@ -4,11 +4,13 @@ # specific sets of holidays on the fly. 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 .albania import AL, ALB, Albania +from .andorra import AD, AND, Andorra from .angola import AO, AGO, Angola from .argentina import AR, ARG, Argentina from .armenia import AM, ARM, Armenia @@ -16,6 +18,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 @@ -60,6 +63,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 @@ -71,6 +75,8 @@ 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 .montenegro import ME, MNE, Montenegro from .morocco import MA, MOR, Morocco from .mozambique import MZ, MOZ, Mozambique from .namibia import NA, NAM, Namibia @@ -83,10 +89,12 @@ 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 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 @@ -98,6 +106,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 @@ -106,6 +115,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/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/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/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..f779b1229 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) @@ -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/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/bahrain.py b/holidays/countries/bahrain.py new file mode 100644 index 000000000..a47b796f7 --- /dev/null +++ b/holidays/countries/bahrain.py @@ -0,0 +1,136 @@ +# 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-2023 +# 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, MAY, JUL, AUG, OCT, DEC +from holidays.holiday_base import HolidayBase +from holidays.utils import _islamic_to_gre + + +class Bahrain(HolidayBase): + """ + 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) + + # New Year's Day. + self[date(year, JAN, 1)] = "New Year's Day" + + # Labour day. + self[date(year, MAY, 1)] = "Labour Day" + + # 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 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 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 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 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" + 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): + pass + + +class BAH(Bahrain): + pass 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..1677465bc 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) @@ -27,32 +27,31 @@ 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)] = "День женщин" # 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)] = "Праздник труда" @@ -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/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..b679a06b1 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) @@ -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/brazil.py b/holidays/countries/brazil.py index 95315a324..cee6e5f58 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) @@ -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/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..ffd0cb18d 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) @@ -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..eede8eea0 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) @@ -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/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..53c684482 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) @@ -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/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..a855ceefc 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) @@ -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/dominican_republic.py b/holidays/countries/dominican_republic.py index 64a314cd8..1c508a17f 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) @@ -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,11 +31,11 @@ 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)) + holiday += rd(weekday=MO(+1)) return holiday def _populate(self, year): @@ -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/holidays/countries/egypt.py b/holidays/countries/egypt.py index 8ddc3990c..802d831dc 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) @@ -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/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..9eef373b4 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) @@ -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/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..97e03273e 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) @@ -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", diff --git a/holidays/countries/georgia.py b/holidays/countries/georgia.py index f223ece7d..525fa6541 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) @@ -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/germany.py b/holidays/countries/germany.py index 75b1b608a..b8b6f5716 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) @@ -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/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..58ec54ecd 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) @@ -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/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..1529dbc2c 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) @@ -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, 1, 10): + 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, 3, 12): + self[dt] = 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..4eefa7438 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) @@ -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/ireland.py b/holidays/countries/ireland.py index b8a330ebe..257855acc 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) @@ -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/isle_of_man.py b/holidays/countries/isle_of_man.py index 30377dd6f..8a9d23769 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) @@ -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/israel.py b/holidays/countries/israel.py index 7da13450c..3596d2a38 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) @@ -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/italy.py b/holidays/countries/italy.py index b7eaf4782..5b01f45e3 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 @@ -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/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..5faa325f9 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) @@ -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/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/kyrgyzstan.py b/holidays/countries/kyrgyzstan.py new file mode 100644 index 000000000..33dd4829d --- /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-2023 +# 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/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..1eaf4408e 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) @@ -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/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/monaco.py b/holidays/countries/monaco.py new file mode 100644 index 000000000..95b28a7bc --- /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-2023 +# 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/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/holidays/countries/morocco.py b/holidays/countries/morocco.py index 0d4bf8f8b..b6296da1f 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) @@ -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/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..72f92ef48 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) @@ -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/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..067f4180b 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) @@ -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/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/philippines.py b/holidays/countries/philippines.py new file mode 100644 index 000000000..ee7bd8232 --- /dev/null +++ b/holidays/countries/philippines.py @@ -0,0 +1,104 @@ +# 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-2023 +# 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 MO +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_the_Philippines + """ + + 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, 31) + rd(weekday=MO(-1))] = "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/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..376c1d425 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) @@ -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): @@ -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/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..3cb00931b 100644 --- a/holidays/countries/russia.py +++ b/holidays/countries/russia.py @@ -4,14 +4,14 @@ # specific sets of holidays on the fly. 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 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/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/holidays/countries/saudi_arabia.py b/holidays/countries/saudi_arabia.py index a07a53aeb..4bdf57f0c 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) @@ -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/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..2dc63ff50 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) @@ -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/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..8b10d10f3 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) @@ -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] 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..31eaa24f9 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) @@ -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/thailand.py b/holidays/countries/thailand.py new file mode 100644 index 000000000..35bf901cf --- /dev/null +++ b/holidays/countries/thailand.py @@ -0,0 +1,173 @@ +# 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-2023 +# 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, 5), "Coronation Day") + elif year >= 2020: + 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/holidays/countries/tunisia.py b/holidays/countries/tunisia.py index 7cebd090e..ae15a9955 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) @@ -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..c68a62c87 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) @@ -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/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..ba4df710f 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) @@ -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/united_kingdom.py b/holidays/countries/united_kingdom.py index 634348fb8..0f020e773 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) @@ -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/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/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/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..4e59f4ed3 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) @@ -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..44580274f 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) @@ -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/__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..ec10bdb07 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) @@ -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..9de054e46 100644 --- a/holidays/financial/ny_stock_exchange.py +++ b/holidays/financial/ny_stock_exchange.py @@ -4,12 +4,12 @@ # specific sets of holidays on the fly. 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 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..88587eaab 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) @@ -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..f5b4be865 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) @@ -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 @@ -272,7 +273,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 +282,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 +297,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) } @@ -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/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..d72825c32 100644 --- a/test/common.py +++ b/test/common.py @@ -4,11 +4,10 @@ # specific sets of holidays on the fly. 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) -# Copyright: Arkadii Yakovets , 2022 import unittest from typing import Generator @@ -22,13 +21,13 @@ class TestCase(unittest.TestCase): """Base class for python-holiday test cases.""" - def parse_arguments(self, args): - date_args = args + def _parse_arguments(self, args, expand_items=True): + 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,25 +42,28 @@ 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)) - else: - dates.append(date_arg) + items = [] + 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, dates + 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`", ) def assertCountryAliases(self, cls, alpha_2, alpha_3): - """Asserts country aliases match.""" + """Assert country aliases match.""" self.assertTrue( issubclass(cls, HolidayBase), @@ -74,7 +76,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,47 +95,85 @@ 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.""" - self.verify_type(holidays) + holidays, dates = self._parse_arguments(args) + for dt in dates: + self.assertIn(dt, holidays, dt) - self.assertEqual(0, len(holidays)) - self.assertFalse(holidays) + def assertHolidayDates(self, *args): + """Assert holiday dates exactly match expected dates.""" + + holidays, dates = self._parse_arguments(args) + self._verify_type(holidays) - def assertHolidaysEqual(self, holidays, *expected_holidays): + for dt in dates: # Check one by one for descriptive error messages. + 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) + for name in names: + self.assertTrue(holidays.get_named(name)) + + 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) - 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) + 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 assertHoliday(self, *args): - """Asserts each date is a holiday.""" + 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.assertIn(dt, holidays) + self.assertEqual(name, holidays.get(dt), dt) def assertNoHoliday(self, *args): - """Asserts each date is not a holiday.""" + """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) + 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) + for name in names: + self.assertFalse(holidays.get_named(name)) + + def assertNoHolidays(self, holidays): + """Assert holidays dict is empty.""" + + self._verify_type(holidays) + + self.assertFalse(holidays) + self.assertEqual(0, len(holidays)) class SundayHolidays(TestCase): 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_albania.py b/test/countries/test_albania.py new file mode 100644 index 000000000..3d6ffa496 --- /dev/null +++ b/test/countries/test_albania.py @@ -0,0 +1,65 @@ +# 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.assertHolidays( + ("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.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"), + ("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"), + ) diff --git a/test/countries/test_andorra.py b/test/countries/test_andorra.py new file mode 100644 index 000000000..8277dcaed --- /dev/null +++ b/test/countries/test_andorra.py @@ -0,0 +1,149 @@ +# 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.assertHolidays( + ("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.assertHolidays( + ("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", + ) diff --git a/test/countries/test_angola.py b/test/countries/test_angola.py index 23ee4a07a..1356278eb 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) @@ -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 ea93271d9..1bcff74a3 100644 --- a/test/countries/test_argentina.py +++ b/test/countries/test_argentina.py @@ -4,14 +4,14 @@ # specific sets of holidays on the fly. 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 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,20 +222,34 @@ 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): - 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_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..8a4df7950 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) @@ -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..8c8c48d02 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) @@ -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_azerbaijan.py b/test/countries/test_azerbaijan.py index c237574fd..32b6fd712 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) @@ -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_bahrain.py b/test/countries/test_bahrain.py new file mode 100644 index 000000000..346d2681a --- /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-2023 +# 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", + ) 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..d83e92a8d 100644 --- a/test/countries/test_belarus.py +++ b/test/countries/test_belarus.py @@ -4,63 +4,71 @@ # specific sets of holidays on the fly. 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) -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_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..c9ce8fc48 100644 --- a/test/countries/test_bulgaria.py +++ b/test/countries/test_bulgaria.py @@ -4,13 +4,15 @@ # specific sets of holidays on the fly. 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) 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_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..793856479 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) @@ -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_chile.py b/test/countries/test_chile.py index fc82da92e..9641ae683 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) @@ -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_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..51eecb80b 100644 --- a/test/countries/test_colombia.py +++ b/test/countries/test_colombia.py @@ -4,13 +4,15 @@ # specific sets of holidays on the fly. 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) 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_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..dc6eaa945 100644 --- a/test/countries/test_cuba.py +++ b/test/countries/test_cuba.py @@ -4,13 +4,15 @@ # specific sets of holidays on the fly. 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) 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_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..3108cb792 100644 --- a/test/countries/test_dominican_republic.py +++ b/test/countries/test_dominican_republic.py @@ -4,77 +4,89 @@ # specific sets of holidays on the fly. 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) -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.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]"), + ("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.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]"), + ("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.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]"), + ("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", + ) 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..a7c45abac 100644 --- a/test/countries/test_georgia.py +++ b/test/countries/test_georgia.py @@ -4,42 +4,49 @@ # specific sets of holidays on the fly. 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) -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_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..22ec3790b 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) @@ -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_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..4873ff482 100644 --- a/test/countries/test_india.py +++ b/test/countries/test_india.py @@ -4,183 +4,188 @@ # specific sets of holidays on the fly. 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) -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) - 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 = 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") - - 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 - holidays.IN(years=2000) - - with self.assertWarns(Warning): - # Diwali and Holi out of range - holidays.IN(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( + "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..335965c3d 100644 --- a/test/countries/test_indonesia.py +++ b/test/countries/test_indonesia.py @@ -4,20 +4,23 @@ # specific sets of holidays on the fly. 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) -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_ireland.py b/test/countries/test_ireland.py index 067c08863..7ff344e35 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) @@ -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_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..8abacee4a 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) @@ -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_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..6d2bff6e3 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) @@ -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) diff --git a/test/countries/test_kazakhstan.py b/test/countries/test_kazakhstan.py index e14a44dcb..9fe3feecd 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) @@ -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_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_kyrgyzstan.py b/test/countries/test_kyrgyzstan.py new file mode 100644 index 000000000..f4714798a --- /dev/null +++ b/test/countries/test_kyrgyzstan.py @@ -0,0 +1,65 @@ +# 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-2023 +# 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.assertHolidays( + ("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.assertHolidays( + ("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") 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..7ce118587 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) @@ -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_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_monaco.py b/test/countries/test_monaco.py new file mode 100644 index 000000000..f3b5d8aff --- /dev/null +++ b/test/countries/test_monaco.py @@ -0,0 +1,123 @@ +# 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-2023 +# 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.assertHolidayDates( + "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.assertHolidayDates( + "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.assertHolidayDates( + "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.assertHolidayDates( + "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", + ) diff --git a/test/countries/test_montenegro.py b/test/countries/test_montenegro.py new file mode 100644 index 000000000..a06f77e2e --- /dev/null +++ b/test/countries/test_montenegro.py @@ -0,0 +1,76 @@ +# 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.assertHolidays( + ("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.assertHolidays( + ("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.assertHolidays( + ("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"), + ) 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..821eb614d 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) @@ -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_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..313d85ec6 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) @@ -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_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..01f57886e 100644 --- a/test/countries/test_paraguay.py +++ b/test/countries/test_paraguay.py @@ -4,13 +4,15 @@ # specific sets of holidays on the fly. 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) 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_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_philippines.py b/test/countries/test_philippines.py new file mode 100644 index 000000000..b5e7d5df8 --- /dev/null +++ b/test/countries/test_philippines.py @@ -0,0 +1,44 @@ +# 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-2023 +# 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.assertHolidays( + ("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-29", "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_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..a0b500d7b 100644 --- a/test/countries/test_russia.py +++ b/test/countries/test_russia.py @@ -4,40 +4,45 @@ # specific sets of holidays on the fly. 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) -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_san_marino.py b/test/countries/test_san_marino.py new file mode 100644 index 000000000..4bbeaf2d4 --- /dev/null +++ b/test/countries/test_san_marino.py @@ -0,0 +1,65 @@ +# 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.assertHolidays( + ("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.assertHolidays( + ("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"), + ) 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..e505c4ddd 100644 --- a/test/countries/test_singapore.py +++ b/test/countries/test_singapore.py @@ -4,17 +4,15 @@ # specific sets of holidays on the fly. 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) -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() 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..b96bbd229 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) @@ -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_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_thailand.py b/test/countries/test_thailand.py new file mode 100644 index 000000000..51559c3a4 --- /dev/null +++ b/test/countries/test_thailand.py @@ -0,0 +1,81 @@ +# 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-2023 +# 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 TestThailand(TestCase): + def setUp(self): + self.holidays = Thailand() + + def test_country_aliases(self): + self.assertCountryAliases(Thailand, TH, THA) + + def test_2022(self): + self.assertHolidays( + ("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-04", "Coronation Day"), + ("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_coronation_day(self): + self.assertHoliday("2016-05-05", "2020-05-04") + self.assertNoHoliday("2017-05-04", "2017-05-05") 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..664c61c26 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) @@ -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..e35db4c93 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) @@ -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..2558f3bef 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) @@ -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_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_vatican_city.py b/test/countries/test_vatican_city.py new file mode 100644 index 000000000..bd1f16c79 --- /dev/null +++ b/test/countries/test_vatican_city.py @@ -0,0 +1,61 @@ +# 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.assertHolidays( + ("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.assertHolidays( + ("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"), + ) diff --git a/test/countries/test_venezuela.py b/test/countries/test_venezuela.py index 515840dea..dec4f1e21 100644 --- a/test/countries/test_venezuela.py +++ b/test/countries/test_venezuela.py @@ -4,13 +4,15 @@ # specific sets of holidays on the fly. 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) 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..039c83f3c 100644 --- a/test/countries/test_vietnam.py +++ b/test/countries/test_vietnam.py @@ -4,36 +4,40 @@ # specific sets of holidays on the fly. 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) -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.assertHolidaysName( + "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.assertHolidaysName( + "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.assertHolidaysName( "Vietnamese New Year's Eve", + date(*dt) + rd(days=-1), ) - self.assertEqual( - self.holidays[date(year, month, day) + relativedelta(days=0)], + self.assertHolidaysName( "Vietnamese New Year", + date(*dt), ) - self.assertEqual( - self.holidays[date(year, month, day) + relativedelta(days=+1)], + self.assertHolidaysName( "The second day of Tet Holiday", + date(*dt) + rd(days=+1), ) - self.assertEqual( - self.holidays[date(year, month, day) + relativedelta(days=+2)], + self.assertHolidaysName( "The third day of Tet Holiday", + date(*dt) + rd(days=+2), ) - self.assertEqual( - self.holidays[date(year, month, day) + relativedelta(days=+3)], + self.assertHolidaysName( "The forth day of Tet Holiday", + date(*dt) + rd(days=+3), ) - self.assertEqual( - self.holidays[date(year, month, day) + relativedelta(days=+4)], + self.assertHolidaysName( "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.assertHolidaysName( + "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.assertHolidaysName( + "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.assertHolidaysName( + "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.assertHolidaysName( + "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", + ) 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..262a06cb9 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) @@ -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..b6eb09d8a 100644 --- a/test/financial/test_ny_stock_exchange.py +++ b/test/financial/test_ny_stock_exchange.py @@ -4,13 +4,13 @@ # specific sets of holidays on the fly. 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) 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]) diff --git a/test/test_docs.py b/test/test_docs.py new file mode 100644 index 000000000..9caf89fec --- /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-2023 +# 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", encoding="utf-8") 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..c9d040851 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) @@ -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 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) 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