From acc537f6cc2f5bfb26351c0f70556a0b6a05b40b Mon Sep 17 00:00:00 2001 From: PPsyrius <19505219+PPsyrius@users.noreply.github.com> Date: Fri, 16 Jun 2023 20:11:34 +0700 Subject: [PATCH] Add `_add_childrens_day(...)` to `InternationalHolidays` (#1300) * [group] Add `_add_childrens_day_jun1(...)`` * [group] forgot these * [group] Readd `_add_childrens_day_jun1(...)` again * [group] oof * [group] implementing suggestions * [group] switch from checking constant to string Co-Authored-By: Arkadii Yakovets <2201626+arkid15r@users.noreply.github.com> --------- Co-authored-by: Arkadii Yakovets <2201626+arkid15r@users.noreply.github.com> --- holidays/countries/moldova.py | 4 ++-- holidays/countries/romania.py | 4 ++-- holidays/groups/international.py | 24 +++++++++++++++++++++++- tests/test_holiday_groups.py | 23 ++++++++++++++++++++++- 4 files changed, 49 insertions(+), 6 deletions(-) diff --git a/holidays/countries/moldova.py b/holidays/countries/moldova.py index 428a685cd..f278ace19 100644 --- a/holidays/countries/moldova.py +++ b/holidays/countries/moldova.py @@ -13,7 +13,7 @@ from gettext import gettext as tr from holidays.calendars import GREGORIAN_CALENDAR, JULIAN_CALENDAR -from holidays.constants import JUN, AUG +from holidays.constants import AUG from holidays.holiday_base import HolidayBase from holidays.holiday_groups import ChristianHolidays, InternationalHolidays @@ -85,7 +85,7 @@ def _populate(self, year): if year >= 2016: # International Children's Day - self._add_holiday(tr("Ziua Ocrotirii Copilului"), JUN, 1) + self._add_childrens_day(tr("Ziua Ocrotirii Copilului")) # Republic of Moldova Independence Day self._add_holiday(tr("Ziua independenţei Republicii Moldova"), AUG, 27) diff --git a/holidays/countries/romania.py b/holidays/countries/romania.py index c6493e83d..0db9d6b95 100644 --- a/holidays/countries/romania.py +++ b/holidays/countries/romania.py @@ -12,7 +12,7 @@ from gettext import gettext as tr from holidays.calendars import GREGORIAN_CALENDAR, JULIAN_CALENDAR -from holidays.constants import JAN, JUN, NOV, DEC +from holidays.constants import JAN, NOV, DEC from holidays.holiday_base import HolidayBase from holidays.holiday_groups import ChristianHolidays, InternationalHolidays @@ -64,7 +64,7 @@ def _populate(self, year): if year >= 2017: # Children's Day. - self._add_holiday(tr("Ziua Copilului"), JUN, 1) + self._add_childrens_day(tr("Ziua Copilului")) # Pentecost. name = tr("Rusaliile") diff --git a/holidays/groups/international.py b/holidays/groups/international.py index 21b3f83b2..66ef37b65 100644 --- a/holidays/groups/international.py +++ b/holidays/groups/international.py @@ -11,7 +11,7 @@ from datetime import date -from holidays.constants import JAN, MAR, MAY, OCT, NOV, DEC +from holidays.constants import JAN, MAR, MAY, JUN, OCT, NOV, DEC class InternationalHolidays: @@ -30,6 +30,28 @@ def _add_africa_day(self, name): """ return self._add_holiday(name, MAY, 25) + def _add_childrens_day(self, name, variation="JUN"): + """ + Add International Children's Day (June 1). + + In 1925, International Children's Day was first proclaimed in Geneva + during the World Conference on Child Welfare. Since 1950, it is + celebrated on June 1 in many countries. + + As such, this entry currently defaults to June 1, though this also + supports another internationally adopted variant, November 20th. + https://en.wikipedia.org/wiki/Children's_Day + """ + if variation == "JUN": + return self._add_holiday(name, JUN, 1) + elif variation == "NOV": + return self._add_holiday(name, NOV, 20) + else: + raise ValueError( + f"Unknown variaton name: {variation}. " + "This entry currently supports `JUN` and `NOV` variation only." + ) + def _add_columbus_day(self, name): """ Add Columbus Day (October 12th) diff --git a/tests/test_holiday_groups.py b/tests/test_holiday_groups.py index 470d8c835..37f437f4a 100644 --- a/tests/test_holiday_groups.py +++ b/tests/test_holiday_groups.py @@ -12,7 +12,7 @@ from unittest import TestCase from holidays.holiday_base import HolidayBase -from holidays.holiday_groups import ChristianHolidays +from holidays.holiday_groups import ChristianHolidays, InternationalHolidays class TestChristianHolidays(TestCase): @@ -37,3 +37,24 @@ def _populate(self, year): test_holidays._add_christmas_day_three("Third day") self.assertIn("2022-12-27", test_holidays) self.assertEqual(1, len(test_holidays)) + + +class TestInternationalHolidays(TestCase): + def test_add_childrens_day(self): + class TestHolidays(HolidayBase, InternationalHolidays): + def __init__(self, *args, **kwargs): + InternationalHolidays.__init__(self) + super().__init__(*args, **kwargs) + + test_holidays = TestHolidays() + + test_holidays._populate(2022) + test_holidays._add_childrens_day("Children's Day (November 20)", "NOV") + self.assertIn("2022-11-20", test_holidays) + self.assertEqual(1, len(test_holidays)) + self.assertRaises( + ValueError, + lambda: test_holidays._add_childrens_day( + "Invalid", "INVALID_TYPE" + ), + )