Skip to content

Commit

Permalink
Merge pull request #1 from edyarm/feature/add_jamaica_holidays
Browse files Browse the repository at this point in the history
Added Jamaica holidays.
  • Loading branch information
edyarm committed Feb 15, 2021
2 parents ff1a39c + d67229b commit 55a27b6
Show file tree
Hide file tree
Showing 4 changed files with 185 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ Israel IL/ISR None
Italy IT/ITA prov = AN, AO, BA, BL, BO, BS, BZ, CB, Cesena, CH, CS, CT,
EN, FC, FE, FI, Forlì, FR, GE, GO, IS, KR, LT, MB, MI, MO,
MN, MS, NA, PA, PC, PD, PG, PR, RM, SP, TS, VI
Jamaica JM/JAM None
Japan JP/JPN None
Kenya KE/KEN None
Korea KR/KOR None
Expand Down
1 change: 1 addition & 0 deletions holidays/countries/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
from .ireland import Ireland, IE, IRL
from .italy import Italy, IT, ITA
from .israel import Israel, IL, ISR
from .jamaica import Jamaica, JM, JAM
from .japan import Japan, JP, JPN
from .kenya import Kenya, KE, KEN
from .korea import Korea, KR, KOR
Expand Down
105 changes: 105 additions & 0 deletions holidays/countries/jamaica.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
# -*- coding: utf-8 -*-

# 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.
#
# Author: ryanss <ryanssdev@icloud.com> (c) 2014-2017
# dr-prodigy <maurizio.montel@gmail.com> (c) 2017-2020
# 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 FR, MO, SU, WE
from dateutil.relativedelta import relativedelta as rd
from holidays.constants import AUG, DEC, FEB, JAN, JUN, MAY, OCT, SUN, WEEKEND
from holidays.holiday_base import HolidayBase


class Jamaica(HolidayBase):
# https://en.wikipedia.org/wiki/Public_holidays_in_Jamaica

def __init__(self, **kwargs):
self.country = 'JM'
HolidayBase.__init__(self, **kwargs)

def _populate(self, year):

# New Year's Day
name = "New Year's Day"
_date = date(year, JAN, 1)
if self.observed and _date.weekday() == SUN:
self[_date + rd(weekday=MO(+1))] = name + ' (Observed)'
else:
self[_date] = name

# Valentine's Day
self[date(year, FEB, 14)] = "Valentine's Day"

# Mother's Day
self[date(year, MAY, 1) + rd(weekday=SU(+2))] = "Mother's Day"

# Labour Day
name = "Labour Day"
_date = date(year, MAY, 23)
if self.observed and _date.weekday() == SUN:
self[_date + rd(weekday=MO)] = name + ' (Observed)'
else:
self[_date] = name

# Father's Day
self[date(year, JUN, 1) + rd(weekday=SU(+3))] = "Father's Day"

# Emancipation Day
name = "Emancipation Day"
_date = date(year, AUG, 1)
if self.observed and _date.weekday() == SUN:
self[_date + rd(weekday=MO)] = name + ' (Observed)'
else:
self[_date] = name

# Independence Day
name = "Independence Day"
_date = date(year, AUG, 6)
if self.observed and _date.weekday() in WEEKEND:
self[_date + rd(weekday=MO)] = name
else:
self[_date] = name

# National Heroes Day
self[date(year, OCT, 1) + rd(weekday=MO(+3))] = "National Heroes Day"

# Christmas
self[date(year, DEC, 25)] = "Christmas day"

# Boxing day
self[date(year, DEC, 26)] = "Boxing day"

# New Year Eve
# self[date(year, DEC, 31)] = "New Year Eve"

# Holidays based on Easter

# Ash Wednesday
self[easter(year) + rd(days=-40, weekday=WE(-1))] = "Ash Wednesday"

# Good Friday
self[easter(year) + rd(weekday=FR(-1))] = "Good Friday"

# Easter
self[easter(year)] = "Easter"

# Easter
self[easter(year) + rd(weekday=MO(+1))] = "Easter Monday"


class JM(Jamaica):
pass


class JAM(Jamaica):
pass
78 changes: 78 additions & 0 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -3920,6 +3920,84 @@ def test_not_holiday(self):
self.assertNotIn('2016-12-28', self.holidays_with_sundays)


class TestJamaica(unittest.TestCase):
def setUp(self):
self.holidays = holidays.Jamaica()

def test_new_years_day(self):
self.assertIn(date(2021, 1, 1), self.holidays)
self.assertIn(date(2023, 1, 2), self.holidays)
self.assertIn(date(2024, 1, 1), self.holidays)

def test_valentines_day(self):
for year in range(1948, 2050):
self.assertIn(
date(year, 2, 14), self.holidays
)

def test_mothers_day(self):
self.assertIn(date(2021, 5, 9), self.holidays)
self.assertIn(date(2023, 5, 14), self.holidays)
self.assertIn(date(2024, 5, 12), self.holidays)

def test_labour_day(self):
self.assertIn(date(2021, 5, 24), self.holidays)
self.assertIn(date(2023, 5, 23), self.holidays)
self.assertIn(date(2024, 5, 23), self.holidays)

def test_fathers_day(self):
self.assertIn(date(2021, 6, 20), self.holidays)
self.assertIn(date(2023, 6, 18), self.holidays)
self.assertIn(date(2024, 6, 16), self.holidays)

def test_emancipation_day(self):
self.assertIn(date(2021, 8, 2), self.holidays)
self.assertIn(date(2023, 8, 1), self.holidays)
self.assertIn(date(2024, 8, 1), self.holidays)

def test_independence_day(self):
self.assertIn(date(2021, 8, 6), self.holidays)
self.assertIn(date(2023, 8, 7), self.holidays)
self.assertIn(date(2024, 8, 6), self.holidays)

def test_national_heroes_day(self):
self.assertIn(date(2021, 10, 18), self.holidays)
self.assertIn(date(2023, 10, 16), self.holidays)
self.assertIn(date(2024, 10, 21), self.holidays)

def test_christmas_day(self):
for year in range(1948, 2050):
self.assertIn(
date(year, 12, 25), self.holidays
)

def test_boxing_day(self):
for year in range(1948, 2050):
self.assertIn(
date(year, 12, 26), self.holidays
)

def test_ash_wednesday(self):
self.assertIn(date(2021, 2, 17), self.holidays)
self.assertIn(date(2022, 3, 2), self.holidays)
self.assertIn(date(2024, 2, 14), self.holidays)

def test_good_friday(self):
self.assertIn(date(2021, 4, 2), self.holidays)
self.assertIn(date(2022, 4, 15), self.holidays)
self.assertIn(date(2024, 3, 29), self.holidays)

def test_easter(self):
self.assertIn(date(2021, 4, 4), self.holidays)
self.assertIn(date(2022, 4, 17), self.holidays)
self.assertIn(date(2024, 3, 31), self.holidays)

def test_easter_monday(self):
self.assertIn(date(2021, 4, 5), self.holidays)
self.assertIn(date(2022, 4, 18), self.holidays)
self.assertIn(date(2024, 4, 1), self.holidays)


class TestJapan(unittest.TestCase):
def setUp(self):
self.holidays = holidays.Japan(observed=False)
Expand Down

0 comments on commit 55a27b6

Please sign in to comment.