Skip to content

Commit

Permalink
Add Kenyan calendar
Browse files Browse the repository at this point in the history
  • Loading branch information
KidkArolis committed Apr 17, 2020
1 parent 469ac92 commit 620f77a
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## master (unreleased)

Nothing here yet.
- Added Kenyan calendar, by @KidkArolis (#484)

## v8.3.0 (2020-04-14)

Expand Down
1 change: 1 addition & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ Africa
* Angola
* Benin
* Ivory Coast
* Kenya
* Madagascar
* São Tomé
* South Africa
Expand Down
2 changes: 2 additions & 0 deletions workalendar/africa/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from .algeria import Algeria
from .benin import Benin
from .ivory_coast import IvoryCoast
from .kenya import Kenya
from .madagascar import Madagascar
from .sao_tome import SaoTomeAndPrincipe
from .south_africa import SouthAfrica
Expand All @@ -11,6 +12,7 @@
'Algeria',
'Benin',
'IvoryCoast',
'Kenya',
'Madagascar',
'SaoTomeAndPrincipe',
'SouthAfrica',
Expand Down
71 changes: 71 additions & 0 deletions workalendar/africa/kenya.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
from copy import copy
from datetime import timedelta, date

from ..core import WesternCalendar, IslamicMixin, ChristianMixin, SUN
from ..registry_tools import iso_register


@iso_register('KE')
class Kenya(WesternCalendar, IslamicMixin, ChristianMixin):
"Kenya"
include_good_friday = True
include_easter_monday = True
# Islamic holidays
include_eid_al_fitr = True
include_day_of_sacrifice = True
shift_sunday_holidays = True

FIXED_HOLIDAYS = WesternCalendar.FIXED_HOLIDAYS + (
(5, 1, "Labour Day"),
(6, 1, "Madaraka Day"),
(10, 20, "Mashujaa Day"),
(12, 12, "Jamhuri Day"),
(12, 31, "New Years Eve"),
)

def get_fixed_holidays(self, year):
days = super().get_fixed_holidays(year)

if year >= 2020:
days.append((date(year, 2, 11), 'Moi Memorial Day'))

# Moi Day renamed
huduma_day_label = "Moi Day"
if year >= 2020:
huduma_day_label = "Huduma Day"
days.append((date(year, 10, 10), huduma_day_label))

# Boxing day renamed
boxing_day_label = "Boxing Day"
if year >= 2020:
boxing_day_label = "Utamaduni Day"
days.append((date(year, 12, 26), boxing_day_label))

return days

def get_shifted_holidays(self, dates):
"""
Taking a list of existing holidays, yield a list of 'shifted' days if
the holiday falls on SUN, excluding the Islamic holidays.
"""
for holiday, label in dates:
if (holiday.weekday() == SUN and
label != self.eid_al_fitr_label and
label != self.day_of_sacrifice_label):
yield (
holiday + timedelta(days=1),
label + ' Shift'
)

def get_calendar_holidays(self, year):
"""
Take into account the eventual shift to the next MON if any holiday
falls on SUN.
"""
# Unshifted days are here:
days = super().get_calendar_holidays(year)
if self.shift_sunday_holidays:
days_to_inspect = copy(days)
for day_shifted in self.get_shifted_holidays(days_to_inspect):
days.append(day_shifted)
return days
41 changes: 41 additions & 0 deletions workalendar/tests/test_africa.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Angola,
Benin,
IvoryCoast,
Kenya,
Madagascar,
SaoTomeAndPrincipe,
SouthAfrica,
Expand Down Expand Up @@ -547,3 +548,43 @@ def test_year_2018(self):
self.assertIn(date(2018, 11, 11), holidays)
# Dia do Natal – 25 de Dezembro
self.assertIn(date(2018, 12, 25), holidays) # Natal


class KenyaTest(GenericCalendarTest):
cal_class = Kenya

def test_year_2019(self):
holidays = self.cal.holidays_set(2019)
self.assertIn(date(2019, 1, 1), holidays) # New Year
self.assertIn(date(2019, 4, 19), holidays) # Good Friday
self.assertIn(date(2019, 4, 22), holidays) # Easter Monday
self.assertIn(date(2019, 5, 1), holidays) # Labour Day
self.assertIn(date(2019, 6, 1), holidays) # Madaraka Day
self.assertIn(date(2019, 6, 5), holidays) # Eid al-Fitr
self.assertIn(date(2019, 8, 12), holidays) # Eid al-Adha
self.assertIn(date(2019, 10, 10), holidays) # Moi Day (old name)
self.assertIn(date(2019, 10, 20), holidays) # Mashujaa Day
self.assertIn(date(2019, 10, 21), holidays) # Mashujaa Day shift
self.assertIn(date(2019, 12, 12), holidays) # Jamhuri Day
self.assertIn(date(2019, 12, 25), holidays) # Christmas Day
self.assertIn(date(2019, 12, 26), holidays) # Boxing Day (old name)
self.assertIn(date(2019, 12, 31), holidays) # New Years Eve
self.assertEquals(len(holidays), 14)

def test_year_2020(self):
holidays = self.cal.holidays_set(2020)
self.assertIn(date(2020, 1, 1), holidays) # New Year
self.assertIn(date(2020, 2, 11), holidays) # Moi Memorial (as of 2020)
self.assertIn(date(2020, 4, 10), holidays) # Good Friday
self.assertIn(date(2020, 4, 13), holidays) # Easter Monday
self.assertIn(date(2020, 5, 1), holidays) # Labour Day
self.assertIn(date(2020, 5, 24), holidays) # Eid al-Fitr
self.assertIn(date(2020, 6, 1), holidays) # Madaraka Day
self.assertIn(date(2020, 7, 31), holidays) # Eid al-Adha
self.assertIn(date(2020, 10, 10), holidays) # Huduma Day
self.assertIn(date(2020, 10, 20), holidays) # Mashujaa Day
self.assertIn(date(2020, 12, 12), holidays) # Jamhuri Day
self.assertIn(date(2020, 12, 25), holidays) # Christmas Day
self.assertIn(date(2020, 12, 26), holidays) # Utamaduni Day
self.assertIn(date(2020, 12, 31), holidays) # New Years Eve
self.assertEquals(len(holidays), 14)

0 comments on commit 620f77a

Please sign in to comment.