Skip to content

Commit

Permalink
Add _add_childrens_day(...) to InternationalHolidays (#1300)
Browse files Browse the repository at this point in the history
* [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 <[email protected]>

---------

Co-authored-by: Arkadii Yakovets <[email protected]>
  • Loading branch information
PPsyrius and arkid15r authored Jun 16, 2023
1 parent bf54ecd commit acc537f
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 6 deletions.
4 changes: 2 additions & 2 deletions holidays/countries/moldova.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions holidays/countries/romania.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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")
Expand Down
24 changes: 23 additions & 1 deletion holidays/groups/international.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)
Expand Down
23 changes: 22 additions & 1 deletion tests/test_holiday_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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"
),
)

0 comments on commit acc537f

Please sign in to comment.