-
Notifications
You must be signed in to change notification settings - Fork 219
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Kenyan calendar #484
Merged
Merged
Add Kenyan calendar #484
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -171,6 +171,7 @@ Africa | |
* Angola | ||
* Benin | ||
* Ivory Coast | ||
* Kenya | ||
* Madagascar | ||
* São Tomé | ||
* South Africa | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added these next two methods to shift Sundays to Mondays, but I've excluded the Islamic days from being shifted. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. excellent! |
||
""" | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added this to dynamically introduce 'Moi Memorial Day' in 2020 and to rename some things based on year.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's the right way to go!