Skip to content

Commit

Permalink
Add Samoa holidays
Browse files Browse the repository at this point in the history
  • Loading branch information
kasya committed Aug 13, 2024
1 parent fa3feb8 commit 912d980
Show file tree
Hide file tree
Showing 4 changed files with 175 additions and 1 deletion.
7 changes: 6 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -755,6 +755,11 @@ All other default values are highlighted with bold:
-
- en_US, **ru**
-
* - Samoa
- WS
-
-
-
* - San Marino
- SM
-
Expand Down
83 changes: 83 additions & 0 deletions holidays/countries/samoa.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# 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 <[email protected]> (c) 2017-2023
# ryanss <[email protected]> (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 <[email protected]> (c) 2017-2023
# ryanss <[email protected]> (c) 2014-2017
# Website: https://github.com/dr-prodigy/python-holidays
# License: MIT (see LICENSE file)

from holidays.calendars.gregorian import SAT, SUN
from holidays.groups import InternationalHolidays, ChristianHolidays
from holidays.holiday_base import HolidayBase


class Samoa(HolidayBase, InternationalHolidays, ChristianHolidays):
"""
References:
- https://en.wikipedia.org/wiki/Public_holidays_in_Samoa
- https://www.timeanddate.com/holidays/samoa/
"""

country = "WS"
weekend = {SAT, SUN}

def __init__(self, *args, **kwargs):
ChristianHolidays.__init__(self)
InternationalHolidays.__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")
self._add_new_years_day_two("Day After New Year's Day")

# Good Friday.
self._add_good_friday("Good Friday")
self._add_holy_saturday("Day After Good Friday")

# Easter Monday.
self._add_easter_monday("Easter Monday")

# Mother's Day.
self._add_holiday_2nd_mon_of_may("Mother's Day")

# Independence Day.
self._add_holiday_jun_1("Independence Day")

# Father's Day.
self._add_holiday_2nd_mon_of_aug("Father's Day")

# Lotu a Tamaiti (White Monday).
self._add_holiday_2nd_mon_of_oct("Lotu a Tamaiti (White Monday)")

# Christmas Day.
self._add_christmas_day("Christmas Day")

# Boxing Day.
self._add_christmas_day_two("Boxing Day")


class WS(Samoa):
pass


class WSM(Samoa):
pass
1 change: 1 addition & 0 deletions holidays/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@
"puerto_rico": ("PuertoRico", "PR", "PRI", "HolidaysPR"),
"romania": ("Romania", "RO", "ROU"),
"russia": ("Russia", "RU", "RUS"),
"samoa": ("Samoa", "WS", "WSM"),
"san_marino": ("SanMarino", "SM", "SMR"),
"saudi_arabia": ("SaudiArabia", "SA", "SAU"),
"serbia": ("Serbia", "RS", "SRB"),
Expand Down
85 changes: 85 additions & 0 deletions tests/countries/test_samoa.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# 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 <[email protected]> (c) 2017-2023
# ryanss <[email protected]> (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 <[email protected]> (c) 2017-2023
# ryanss <[email protected]> (c) 2014-2017
# Website: https://github.com/dr-prodigy/python-holidays
# License: MIT (see LICENSE file)

from unittest import TestCase

from holidays.countries.samoa import Samoa, WS, WSM
from tests.common import CommonCountryTests


class TestSamoa(CommonCountryTests, TestCase):
@classmethod
def setUpClass(cls):
super().setUpClass(Samoa, years=range(1950, 2050))

def test_country_aliases(self):
self.assertAliases(Samoa, WS, WSM)

def test_new_years_day(self):
self.assertHolidayName("New Year's Day", (f"{year}-01-01" for year in range(1950, 2050)))

def test_new_years_second_day(self):
self.assertHolidayName(
"Day After New Year's Day", (f"{year}-01-02" for year in range(1950, 2050))
)

def test_independence_day(self):
self.assertHolidayName("Independence Day", (f"{year}-06-01" for year in range(1950, 2050)))

def test_christmas_day(self):
self.assertHolidayName("Christmas Day", (f"{year}-12-25" for year in range(1950, 2050)))

def test_boxing_day(self):
self.assertHolidayName("Boxing Day", (f"{year}-12-26" for year in range(1950, 2050)))

def test_2023(self):
self.assertHolidays(
Samoa(years=2023),
("2023-01-01", "New Year's Day"),
("2023-01-02", "Day After New Year's Day"),
("2023-04-07", "Good Friday"),
("2023-12-26", "Boxing Day"),
("2023-10-09", "Lotu a Tamaiti (White Monday)"),
("2023-05-08", "Mother's Day"),
("2023-06-01", "Independence Day"),
("2023-12-25", "Christmas Day"),
("2023-08-14", "Father's Day"),
("2023-04-10", "Easter Monday"),
("2023-04-08", "Day After Good Friday"),
)

def test_2024(self):
self.assertHolidays(
Samoa(years=2024),
("2024-01-01", "New Year's Day"),
("2024-01-02", "Day After New Year's Day"),
("2024-12-25", "Christmas Day"),
("2024-04-01", "Easter Monday"),
("2024-12-26", "Boxing Day"),
("2024-05-13", "Mother's Day"),
("2024-03-30", "Day After Good Friday"),
("2024-08-12", "Father's Day"),
("2024-03-29", "Good Friday"),
("2024-06-01", "Independence Day"),
("2024-10-14", "Lotu a Tamaiti (White Monday)"),
)

0 comments on commit 912d980

Please sign in to comment.