Skip to content
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

Added philippines calendar #678

Merged
merged 3 commits into from
Sep 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ dist/
build/
.coverage
.tox/
Pipfile
Pipfile.lock
pyproject.toml
# py.test cache
.cache/
.pytest-cache/
Expand Down
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- Added new badges (pypi, conda, license) and installation instructions (pip, conda) to readme file @sugatoray (#673).
- Replace `pyCalverter` with `convertdate` (#536)
- Remove unused `JalaliMixin`
- New calendar: Added Philippines calendar by @micodls (#396)

## v15.4.0 (2021-07-12)

Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[![license](http://img.shields.io/pypi/l/workalendar.svg)](https://github.com/workalendar/workalendar/blob/master/LICENSE)
[![pypi](http://img.shields.io/pypi/v/workalendar.svg)](https://pypi.python.org/pypi/workalendar)
[![conda](https://img.shields.io/conda/v/conda-forge/workalendar?color=blue&logo=anaconda)](https://anaconda.org/conda-forge/workalendar)

## Overview

Workalendar is a Python module that offers classes able to handle calendars, list legal / religious holidays and gives working-day-related computation functions.
Expand Down Expand Up @@ -159,6 +159,7 @@ from the command line.
- Japan
- JapanBank
- Malaysia
- Philippines
- Qatar
- Singapore
- South Korea
Expand Down
2 changes: 2 additions & 0 deletions workalendar/asia/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from .south_korea import SouthKorea
from .taiwan import Taiwan
from .israel import Israel
from .philippines import Philippines


__all__ = (
Expand All @@ -21,4 +22,5 @@
'SouthKorea',
'Taiwan',
'Israel',
'Philippines'
)
43 changes: 43 additions & 0 deletions workalendar/asia/philippines.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from ..core import (
WesternMixin, IslamicMixin, ChineseNewYearCalendar,
SAT, SUN
)
from ..registry_tools import iso_register


@iso_register('PH')
class Philippines(WesternMixin, IslamicMixin, ChineseNewYearCalendar):
"Philippines"
# Civil holidays
include_labour_day = True
include_new_years_eve = True

# Christian holiday
include_holy_thursday = True
holy_thursday_label = "Maundy Thursday"
include_good_friday = True
include_easter_saturday = True
include_easter_sunday = True
easter_saturday_label = "Black Saturday"
include_all_saints = True
include_all_souls = True
include_immaculate_conception = True
include_christmas_eve = True

# Islamic holidays
include_eid_al_fitr = True
eid_al_fitr_label = "Eid'l Fitr"
include_eid_al_adha = True
day_of_sacrifice_label = "Eid'l Adha"

WEEKEND_DAYS = (SAT, SUN)

FIXED_HOLIDAYS = ChineseNewYearCalendar.FIXED_HOLIDAYS + (
(2, 25, "EDSA Revolution Anniversary"),
(4, 9, "Araw ng Kagitingan"),
(6, 12, "Independence Day"),
(8, 21, "Ninoy Aquino Day"),
(8, 30, "National Heroes' Day"),
(11, 30, "Bonifacio Day"),
(12, 30, "Rizal Day"),
)
25 changes: 15 additions & 10 deletions workalendar/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,12 @@ class ChristianMixin:
ash_wednesday_label = "Ash Wednesday"
include_palm_sunday = False
include_holy_thursday = False
holy_thursday_label = "Holy Thursday"
include_good_friday = False
good_friday_label = "Good Friday"
include_easter_monday = False
include_easter_saturday = False
easter_saturday_label = "Easter Saturday"
include_easter_sunday = False
include_all_saints = False
include_immaculate_conception = False
Expand Down Expand Up @@ -197,11 +199,15 @@ def get_variable_days(self, year): # noqa
if self.include_palm_sunday:
days.append((self.get_palm_sunday(year), "Palm Sunday"))
if self.include_holy_thursday:
days.append((self.get_holy_thursday(year), "Holy Thursday"))
days.append(
(self.get_holy_thursday(year), self.holy_thursday_label)
)
if self.include_good_friday:
days.append((self.get_good_friday(year), self.good_friday_label))
if self.include_easter_saturday:
days.append((self.get_easter_saturday(year), "Easter Saturday"))
days.append(
(self.get_easter_saturday(year), self.easter_saturday_label)
)
if self.include_easter_sunday:
days.append((self.get_easter_sunday(year), "Easter Sunday"))
if self.include_easter_monday:
Expand Down Expand Up @@ -458,6 +464,7 @@ class IslamicMixin(CalverterMixin):
length_eid_al_fitr = 1
eid_al_fitr_label = "Eid al-Fitr"
include_eid_al_adha = False
eid_al_adha_label = "Eid al-Adha"
length_eid_al_adha = 1
include_day_of_sacrifice = False
day_of_sacrifice_label = "Eid al-Adha"
Expand Down Expand Up @@ -486,7 +493,7 @@ def get_islamic_holidays(self):
days.append((10, x + 1, self.eid_al_fitr_label))
if self.include_eid_al_adha:
for x in range(self.length_eid_al_adha):
days.append((12, x + 10, "Eid al-Adha"))
days.append((12, x + 10, self.eid_al_adha_label))
if self.include_day_of_sacrifice:
days.append((12, 10, self.day_of_sacrifice_label))
if self.include_laylat_al_qadr:
Expand Down Expand Up @@ -1000,6 +1007,7 @@ class Calendar(CoreCalendar):
Take care of the New Years Day, which is almost a worldwide holiday.
"""
include_new_years_day = True
include_new_years_eve = False
shift_new_years_day = False
include_labour_day = False
labour_day_label = "Labour Day"
Expand All @@ -1010,14 +1018,11 @@ def __init__(self, **kwargs):
def get_fixed_holidays(self, year):
days = super().get_fixed_holidays(year)
if self.include_new_years_day:
days.insert(
0, (date(year, 1, 1), "New year")
)

days.insert(0, (date(year, 1, 1), "New year"))
if self.include_new_years_eve:
days.append((date(year, 12, 31), "New Year's eve"))
if self.include_labour_day:
days.append(
(date(year, 5, 1), self.labour_day_label)
)
days.append((date(year, 5, 1), self.labour_day_label))
return days

def get_variable_days(self, year):
Expand Down
57 changes: 56 additions & 1 deletion workalendar/tests/test_asia.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from ..asia import (
HongKong, HongKongBank,
Japan, JapanBank, Qatar, Singapore,
SouthKorea, Taiwan, Malaysia, China, Israel
SouthKorea, Taiwan, Malaysia, China, Israel, Philippines
)
from ..asia.china import holidays as china_holidays
from ..exceptions import CalendarError
Expand Down Expand Up @@ -788,3 +788,58 @@ def test_is_holiday_performance(self):
self.cal.is_holiday(random_date)
israel_time = time.time() - timer
self.assertGreater(japan_time * 3, israel_time)


class Philippines(GenericCalendarTest):

cal_class = Philippines

def test_year_2021(self):
brunobord marked this conversation as resolved.
Show resolved Hide resolved
holidays = self.cal.holidays_set(2021)
self.assertIn(date(2021, 1, 1), holidays) # New Year
self.assertIn(date(2021, 2, 12), holidays) # Chinese New Year
self.assertIn(date(2021, 2, 25), holidays) # EDSA Revolution
self.assertIn(date(2021, 4, 1), holidays) # Maundy Thursday
self.assertIn(date(2021, 4, 2), holidays) # Good Friday
self.assertIn(date(2021, 4, 3), holidays) # Black Saturday
self.assertIn(date(2021, 4, 4), holidays) # Easter Sunday
self.assertIn(date(2021, 4, 9), holidays) # Araw ng Kagitingan
self.assertIn(date(2021, 5, 1), holidays) # Labor Day
self.assertIn(date(2021, 5, 13), holidays) # Eid'l Fitr
self.assertIn(date(2021, 6, 12), holidays) # Independence Day
self.assertIn(date(2021, 7, 20), holidays) # Eid'l Adha
self.assertIn(date(2021, 8, 21), holidays) # Ninoy Aquino Day
self.assertIn(date(2021, 8, 30), holidays) # National Heroes' Day
self.assertIn(date(2021, 11, 1), holidays) # All Saints' Day
self.assertIn(date(2021, 11, 2), holidays) # All Souls Day
self.assertIn(date(2021, 11, 30), holidays) # Bonifacio Day
self.assertIn(date(2021, 12, 8), holidays) # Immaculate Conception
self.assertIn(date(2021, 12, 24), holidays) # Christmas Eve
self.assertIn(date(2021, 12, 25), holidays) # Christmas Day
self.assertIn(date(2021, 12, 30), holidays) # Rizal Day
self.assertIn(date(2021, 12, 31), holidays) # New Year's Eve

def test_year_2020(self):
holidays = self.cal.holidays_set(2020)
self.assertIn(date(2020, 1, 1), holidays) # New Year
self.assertIn(date(2020, 1, 25), holidays) # Chinese New Year
self.assertIn(date(2020, 2, 25), holidays) # EDSA Revolution
self.assertIn(date(2020, 4, 9), holidays) # Araw ng Kagitingan
self.assertIn(date(2020, 4, 9), holidays) # Maundy Thursday
self.assertIn(date(2020, 4, 10), holidays) # Good Friday
self.assertIn(date(2020, 4, 11), holidays) # Black Saturday
self.assertIn(date(2020, 4, 12), holidays) # Easter Sunday
self.assertIn(date(2020, 5, 1), holidays) # Labor Day
self.assertIn(date(2020, 5, 24), holidays) # Eid'l Fitr
self.assertIn(date(2020, 6, 12), holidays) # Independence Day
self.assertIn(date(2020, 7, 31), holidays) # Eid'l Adha
self.assertIn(date(2020, 8, 21), holidays) # Ninoy Aquino Day
self.assertIn(date(2020, 8, 30), holidays) # National Heroes' Day
self.assertIn(date(2020, 11, 1), holidays) # All Saints' Day
self.assertIn(date(2020, 11, 2), holidays) # All Souls Day
self.assertIn(date(2020, 11, 30), holidays) # Bonifacio Day
self.assertIn(date(2020, 12, 8), holidays) # Immaculate Conception
self.assertIn(date(2020, 12, 24), holidays) # Christmas Eve
self.assertIn(date(2020, 12, 25), holidays) # Christmas Day
self.assertIn(date(2020, 12, 30), holidays) # Rizal Day
self.assertIn(date(2020, 12, 31), holidays) # New Year's Eve