From 9b55aac21fd8fba1365c7071451be5744ff3dd55 Mon Sep 17 00:00:00 2001 From: Kate Date: Sat, 27 Jul 2024 15:47:58 -0700 Subject: [PATCH 1/2] Add Mauritania holidys --- README.rst | 7 ++- holidays/countries/__init__.py | 1 + holidays/countries/mauritania.py | 82 ++++++++++++++++++++++++++++++ holidays/registry.py | 1 + tests/countries/test_mauritania.py | 78 ++++++++++++++++++++++++++++ 5 files changed, 168 insertions(+), 1 deletion(-) create mode 100644 holidays/countries/mauritania.py create mode 100644 tests/countries/test_mauritania.py diff --git a/README.rst b/README.rst index b29807a85..b113e9944 100644 --- a/README.rst +++ b/README.rst @@ -146,7 +146,7 @@ Available Countries .. _ISO 639-1 code: https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes .. _ISO 639-2 code: https://en.wikipedia.org/wiki/List_of_ISO_639-2_codes -We currently support 148 country codes. The standard way to refer to a country +We currently support 149 country codes. The standard way to refer to a country is by using its `ISO 3166-1 alpha-2 code`_, the same used for domain names, and for a subdivision its `ISO 3166-2 code`_. Some countries have common or foreign names or abbreviations as aliases for their subdivisions. These are defined in @@ -625,6 +625,11 @@ All other default values are highlighted with bold: - - - + * - Mauritania + - MR + - + - + - * - Mexico - MX - diff --git a/holidays/countries/__init__.py b/holidays/countries/__init__.py index 725878725..6976eff7d 100644 --- a/holidays/countries/__init__.py +++ b/holidays/countries/__init__.py @@ -101,6 +101,7 @@ from .maldives import Maldives, MV, MDV from .malta import Malta, MT, MLT from .marshall_islands import MarshallIslands, MH, MHL, HolidaysMH +from .mauritania import Mauritania, MR, MRT from .mexico import Mexico, MX, MEX from .moldova import Moldova, MD, MDA from .monaco import Monaco, MC, MCO diff --git a/holidays/countries/mauritania.py b/holidays/countries/mauritania.py new file mode 100644 index 000000000..9be780aed --- /dev/null +++ b/holidays/countries/mauritania.py @@ -0,0 +1,82 @@ +# 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: Vacanza Team and individual contributors (see AUTHORS file) +# dr-prodigy (c) 2017-2023 +# ryanss (c) 2014-2017 +# Website: https://github.com/vacanza/python-holidays +# License: MIT (see LICENSE file) + +# 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.calendars.gregorian import FRI, SAT +from holidays.groups import InternationalHolidays, IslamicHolidays +from holidays.holiday_base import HolidayBase + + +class Mauritania(HolidayBase, InternationalHolidays, IslamicHolidays): + """ + References: + - https://en.wikipedia.org/wiki/Public_holidays_in_Mauritania + - https://www.timeanddate.com/holidays/mauritania/ + """ + + country = "MR" + weekend = {FRI, SAT} + + def __init__(self, *args, **kwargs): + InternationalHolidays.__init__(self) + IslamicHolidays.__init__(self) + + super().__init__(*args, **kwargs) + + def _populate(self, year): + super()._populate(year) + + # New Year's Day. + self._add_new_years_day("New Year's Day") + + # Labor Day. + self._add_labor_day("Labor Day") + + # Africa Day. + self._add_holiday_may_25("Africa Day") + + # Independence Day. + if year >= 1960: + self._add_holiday_nov_28("Independence Day") + + # Islamic holidays. + # Eid al-Fitr. + self._add_eid_al_fitr_day("Eid al-Fitr") + self._add_eid_al_fitr_day_two("Eid al-Fitr") + + # Eid al-Adha. + self._add_eid_al_adha_day("Eid al-Adha") + self._add_eid_al_adha_day_two("Eid al-Adha") + + # Muharram/Islamic New Year. + self._add_islamic_new_year_day("Islamic New Year") + + # Prophet Muhammad's Birthday. + self._add_mawlid_day("Mawlid al-Nabi") + + +class MR(Mauritania): + pass + + +class MRT(Mauritania): + pass diff --git a/holidays/registry.py b/holidays/registry.py index 0bb9efc25..9412870e2 100644 --- a/holidays/registry.py +++ b/holidays/registry.py @@ -108,6 +108,7 @@ "maldives": ("Maldives", "MV", "MDV"), "malta": ("Malta", "MT", "MLT"), "marshall_islands": ("MarshallIslands", "MH", "MHL", "HolidaysMH"), + "mauritania": ("Mauritania", "MR", "MRT"), "mexico": ("Mexico", "MX", "MEX"), "moldova": ("Moldova", "MD", "MDA"), "monaco": ("Monaco", "MC", "MCO"), diff --git a/tests/countries/test_mauritania.py b/tests/countries/test_mauritania.py new file mode 100644 index 000000000..09fae07ee --- /dev/null +++ b/tests/countries/test_mauritania.py @@ -0,0 +1,78 @@ +# 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: Vacanza Team and individual contributors (see AUTHORS file) +# dr-prodigy (c) 2017-2023 +# ryanss (c) 2014-2017 +# Website: https://github.com/vacanza/python-holidays +# License: MIT (see LICENSE file) + +# 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 unittest import TestCase + +from holidays.countries.mauritania import Mauritania, MR, MRT +from tests.common import CommonCountryTests + + +class TestMauritania(CommonCountryTests, TestCase): + @classmethod + def setUpClass(cls): + super().setUpClass(Mauritania, years=range(1950, 2050)) + + def test_country_aliases(self): + self.assertAliases(Mauritania, MR, MRT) + + def test_new_years_day(self): + self.assertHolidayName("New Year's Day", (f"{year}-01-01" for year in range(1950, 2050))) + + def test_labor_day(self): + self.assertHolidayName("Labor Day", (f"{year}-05-01" for year in range(1950, 2050))) + + def test_africa_day(self): + self.assertHolidayName("Africa Day", (f"{year}-05-25" for year in range(1950, 2050))) + + def test_independence_day(self): + self.assertHolidayName("Independence Day", (f"{year}-11-28" for year in range(1960, 2050))) + + def test_2023(self): + self.assertHolidays( + Mauritania(years=2023), + ("2023-01-01", "New Year's Day"), + ("2023-04-21", "Eid al-Fitr (estimated)"), + ("2023-04-22", "Eid al-Fitr (estimated)"), + ("2023-05-01", "Labor Day"), + ("2023-05-25", "Africa Day"), + ("2023-06-28", "Eid al-Adha (estimated)"), + ("2023-06-29", "Eid al-Adha (estimated)"), + ("2023-07-19", "Islamic New Year (estimated)"), + ("2023-09-27", "Mawlid al-Nabi (estimated)"), + ("2023-11-28", "Independence Day"), + ) + + def test_2024(self): + self.assertHolidays( + Mauritania(years=2024), + ("2024-01-01", "New Year's Day"), + ("2024-04-10", "Eid al-Fitr (estimated)"), + ("2024-04-11", "Eid al-Fitr (estimated)"), + ("2024-05-01", "Labor Day"), + ("2024-05-25", "Africa Day"), + ("2024-06-16", "Eid al-Adha (estimated)"), + ("2024-06-17", "Eid al-Adha (estimated)"), + ("2024-07-07", "Islamic New Year (estimated)"), + ("2024-09-15", "Mawlid al-Nabi (estimated)"), + ("2024-11-28", "Independence Day"), + ) From 5494437eba0e92760fd4a10c804f8f5be2a93542 Mon Sep 17 00:00:00 2001 From: Kate Golovanova Date: Sun, 28 Jul 2024 09:48:52 -0700 Subject: [PATCH 2/2] Apply suggestions from code review Co-authored-by: ~Jhellico --- holidays/countries/mauritania.py | 2 +- tests/countries/test_mauritania.py | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/holidays/countries/mauritania.py b/holidays/countries/mauritania.py index 9be780aed..50621357a 100644 --- a/holidays/countries/mauritania.py +++ b/holidays/countries/mauritania.py @@ -52,7 +52,7 @@ def _populate(self, year): self._add_labor_day("Labor Day") # Africa Day. - self._add_holiday_may_25("Africa Day") + self._add_africa_day("Africa Day") # Independence Day. if year >= 1960: diff --git a/tests/countries/test_mauritania.py b/tests/countries/test_mauritania.py index 09fae07ee..1d9166aec 100644 --- a/tests/countries/test_mauritania.py +++ b/tests/countries/test_mauritania.py @@ -45,7 +45,9 @@ def test_africa_day(self): self.assertHolidayName("Africa Day", (f"{year}-05-25" for year in range(1950, 2050))) def test_independence_day(self): - self.assertHolidayName("Independence Day", (f"{year}-11-28" for year in range(1960, 2050))) + name = "Independence Day" + self.assertHolidayName(name, (f"{year}-11-28" for year in range(1960, 2050))) + self.assertNoHolidayName(name, range(1950, 1960)) def test_2023(self): self.assertHolidays(