Skip to content

Commit

Permalink
Merge pull request #532 from peopledoc/467-worldwide-labour-day
Browse files Browse the repository at this point in the history
Migrating Labour Day as a worldwide holiday
  • Loading branch information
brunobord committed Jul 17, 2020
2 parents b6978e7 + 7e9c79c commit abee8bb
Show file tree
Hide file tree
Showing 58 changed files with 259 additions and 64 deletions.
3 changes: 2 additions & 1 deletion Changelog.md
Expand Up @@ -2,7 +2,8 @@

## master (unreleased)

- Small refactoring for the Colombia / added docstrings & comments to explain why we're not using stock options. Added tests for year 2020 and handling shift exceptions. (#509).
- Small refactoring for the Colombia / added docstrings & comments to explain why we're not using stock options. Added tests for year 2020 and handling shift exceptions (#509).
- Migrating Labour Day as a worldwide holiday, disabled by default, but activated (to date) for about 50 countries (including label change when necessary), `contributing.md` documentation amended (#467).

## v10.3.0 (2020-07-10)

Expand Down
10 changes: 7 additions & 3 deletions contributing.md
Expand Up @@ -123,14 +123,18 @@ With the `WesternCalendar` base class you have at least one holiday as a bonus:

```python
class Zhraa(WesternCalendar):

include_labour_day = True
FIXED_HOLIDAYS = WesternCalendar.FIXED_HOLIDAYS + (
(5, 1, "Labour Day"),
(8, 2, "King Birthday"),
)
```

The `include_labour_day` is a flag common to all subclasses of `workalendar.core.Calendar`. Setting it to `True` activates the Labour Day for this calendar. Please note that there's a way to overwrite its label, using the `labour_day_label` class property.

Now we've got 3 holidays out of 6.


#### Add religious holidays

Since we're using `WesternCalendar` (it inherits from `ChristianMixin`) as a base to our `Zhraa` class, it automatically adds Christmas Day as a holiday. Now we can add Easter monday just by switching the correct flag.
Expand All @@ -140,8 +144,8 @@ from ..core import WesternCalendar

class Zhraa(WesternCalendar):
include_easter_monday = True
include_labour_day = True
FIXED_HOLIDAYS = WesternCalendar.FIXED_HOLIDAYS + (
(5, 1, "Labour Day"),
(8, 2, "King Birthday"),
)
```
Expand All @@ -154,8 +158,8 @@ There are many static methods that will grant you a clean access to variable day
```python
class Zhraa(WesternCalendar):
include_easter_monday = True
include_labour_day = True
FIXED_HOLIDAYS = WesternCalendar.FIXED_HOLIDAYS + (
(5, 1, "Labour Day"),
(8, 2, "King Birthday"),
)

Expand Down
3 changes: 2 additions & 1 deletion workalendar/africa/algeria.py
Expand Up @@ -5,14 +5,15 @@
@iso_register('DZ')
class Algeria(IslamicCalendar):
"Algeria"
# Civil holidays
include_labour_day = True
# Islamic holidays
include_prophet_birthday = True
include_eid_al_fitr = True
include_day_of_sacrifice = True
include_islamic_new_year = True

FIXED_HOLIDAYS = IslamicCalendar.FIXED_HOLIDAYS + (
(5, 1, "Labour Day"),
(7, 5, "Independence Day"),
(11, 1, "Anniversary of the revolution"),
)
Expand Down
5 changes: 4 additions & 1 deletion workalendar/africa/angola.py
Expand Up @@ -5,6 +5,10 @@
@iso_register('AO')
class Angola(WesternCalendar):
"Angola"
# Civil holiday
include_labour_day = True
labour_day_label = "Dia Internacional do Trabalhador"
# Christian holidays
include_fat_tuesday = True
fat_tuesday_label = "Dia de Carnaval"
include_good_friday = True
Expand All @@ -16,7 +20,6 @@ class Angola(WesternCalendar):
(2, 4, "Dia do Inicio da Luta Armada"),
(3, 8, "Dia Internacional da Mulher"),
(4, 4, "Dia da Paz"),
(5, 1, "Dia Internacional do Trabalhador"),
(9, 17, "Dia do Fundador da Nação e do Herói Nacional"),
(11, 11, "Dia da Independência Nacional"),
)
3 changes: 2 additions & 1 deletion workalendar/africa/benin.py
Expand Up @@ -5,6 +5,8 @@
@iso_register('BJ')
class Benin(IslamoWesternCalendar):
"Benin"
# Civil holidays
include_labour_day = True
# Christian holidays
include_easter_monday = True
include_ascension = True
Expand All @@ -19,7 +21,6 @@ class Benin(IslamoWesternCalendar):

FIXED_HOLIDAYS = IslamoWesternCalendar.FIXED_HOLIDAYS + (
(1, 10, "Traditional Day"),
(5, 1, "Labour Day"),
(8, 1, "Independence Day"),
(10, 26, "Armed Forces Day"),
(11, 30, "National Day"),
Expand Down
3 changes: 2 additions & 1 deletion workalendar/africa/ivory_coast.py
Expand Up @@ -5,6 +5,8 @@
@iso_register('CI')
class IvoryCoast(IslamoWesternCalendar):
"Ivory Coast"
# Civil holidays
include_labour_day = True
# Christian holidays
include_easter_monday = True
include_ascension = True
Expand All @@ -18,7 +20,6 @@ class IvoryCoast(IslamoWesternCalendar):
include_day_of_sacrifice_label = "Feast of the Sacrifice"

FIXED_HOLIDAYS = IslamoWesternCalendar.FIXED_HOLIDAYS + (
(5, 1, "Labour Day"),
(8, 7, "Independence Day"),
(11, 15, "National Peace Day"),
)
Expand Down
3 changes: 2 additions & 1 deletion workalendar/africa/kenya.py
Expand Up @@ -8,6 +8,8 @@
@iso_register('KE')
class Kenya(IslamoWesternCalendar):
"Kenya"
# Civil holidays
include_labour_day = True
# Christian holidays
include_good_friday = True
include_easter_monday = True
Expand All @@ -20,7 +22,6 @@ class Kenya(IslamoWesternCalendar):
WEEKEND_DAYS = (SAT, SUN)

FIXED_HOLIDAYS = IslamoWesternCalendar.FIXED_HOLIDAYS + (
(5, 1, "Labour Day"),
(6, 1, "Madaraka Day"),
(10, 20, "Mashujaa Day"),
(12, 12, "Jamhuri Day"),
Expand Down
4 changes: 3 additions & 1 deletion workalendar/africa/madagascar.py
Expand Up @@ -7,9 +7,11 @@ class Madagascar(WesternCalendar):
"Madagascar"
FIXED_HOLIDAYS = WesternCalendar.FIXED_HOLIDAYS + (
(3, 29, "Martyrs' Day"),
(5, 1, "Labour Day"),
(6, 26, "Independence Day"),
)
# Civil holidays
include_labour_day = True
# Christian holidays
include_easter_monday = True
include_ascension = True
include_whit_monday = True
Expand Down
4 changes: 3 additions & 1 deletion workalendar/africa/sao_tome.py
Expand Up @@ -7,10 +7,12 @@ class SaoTomeAndPrincipe(WesternCalendar):
"São Tomé and Príncipe"
FIXED_HOLIDAYS = WesternCalendar.FIXED_HOLIDAYS + (
(2, 3, "Martyr's Day"),
(5, 1, "Labour Day"),
(7, 12, "Independence Day"),
(9, 6, "Armed Forces Day"),
(9, 30, "Agricultural Reform Day"),
(12, 21, "São Tomé Day"),
)
# Civil holidays
include_labour_day = True
# Christian holidays
include_all_saints = True
6 changes: 4 additions & 2 deletions workalendar/america/argentina.py
Expand Up @@ -6,7 +6,10 @@
@iso_register('AR')
class Argentina(WesternCalendar):
'Argentina'

# Civil holidays
include_labour_day = True
labour_day_label = "Día del Trabajador"
# Christian holidays
include_fat_tuesday = True
fat_tuesday_label = "Carnival"
include_good_friday = True
Expand All @@ -16,7 +19,6 @@ class Argentina(WesternCalendar):

FIXED_HOLIDAYS = WesternCalendar.FIXED_HOLIDAYS + (
(3, 24, "Día Nacional de la Memoria por la Verdad y la Justicia"),
(5, 1, "Día del Trabajador"),
(5, 25, "Día de la Revolución de Mayo"),
(6, 20, "Día Paso a la Inmortalidad del General Manuel Belgrano"),
(7, 9, "Día de la Independencia"),
Expand Down
5 changes: 3 additions & 2 deletions workalendar/america/barbados.py
Expand Up @@ -8,7 +8,9 @@
@iso_register("BB")
class Barbados(WesternCalendar):
"Barbados"

# Civil holidays
include_labour_day = True
# Christian holidays
include_good_friday = True
include_easter_sunday = True
include_easter_monday = True
Expand All @@ -19,7 +21,6 @@ class Barbados(WesternCalendar):
FIXED_HOLIDAYS = WesternCalendar.FIXED_HOLIDAYS + (
(1, 21, "Errol Barrow Day"),
(4, 28, "National Heroes Day"),
(5, 1, "Labour Day"),
(8, 1, "Emancipation Day"),
(11, 30, "Independance Day"),
)
Expand Down
4 changes: 3 additions & 1 deletion workalendar/america/brazil.py
Expand Up @@ -9,7 +9,6 @@ class Brazil(WesternCalendar):
"Brazil"
FIXED_HOLIDAYS = WesternCalendar.FIXED_HOLIDAYS + (
(4, 21, "Tiradentes' Day"),
(5, 1, "Labour Day"),
(9, 7, "Independence Day"),
(10, 12, "Our Lady of Aparecida"),
(11, 2, "All Souls' Day"),
Expand All @@ -21,6 +20,8 @@ class Brazil(WesternCalendar):
sao_pedro_label = "São Pedro"
include_sao_joao = False
sao_joao_label = "São João"
# Civil holidays
include_labour_day = True
include_servidor_publico = False
servidor_publico_label = "Dia do Servidor Público"
# Consciência Negra day
Expand All @@ -30,6 +31,7 @@ class Brazil(WesternCalendar):
consciencia_negra_day = (11, 20)
consciencia_negra_label = "Consciência Negra"
include_nossa_senhora_conceicao = False
# Christian holidays
include_easter_sunday = True

def get_variable_days(self, year):
Expand Down
4 changes: 3 additions & 1 deletion workalendar/america/chile.py
Expand Up @@ -8,7 +8,6 @@
class Chile(WesternCalendar):
"Chile"
FIXED_HOLIDAYS = WesternCalendar.FIXED_HOLIDAYS + (
(5, 1, "Labour Day"),
(5, 21, "Navy Day"),
(6, 29, "Saint Peter and Saint Paul"),
(7, 16, "Our Lady of Mount Carmel"),
Expand All @@ -17,6 +16,9 @@ class Chile(WesternCalendar):
(10, 12, "Columbus Day"),
(12, 31, "Banking Holiday"),
)
# Civil holidays
include_labour_day = True
# Christian holidays
include_good_friday = True
include_easter_saturday = True
include_assumption = True
Expand Down
4 changes: 3 additions & 1 deletion workalendar/america/colombia.py
Expand Up @@ -8,10 +8,12 @@
class Colombia(WesternCalendar):
"Colombia"
FIXED_HOLIDAYS = WesternCalendar.FIXED_HOLIDAYS + (
(5, 1, "Labour Day"),
(7, 20, "Independence Day"),
(8, 7, "Boyacá Battle"),
)
# Civil holidays
include_labour_day = True
# Christian holidays
include_palm_sunday = True
include_holy_thursday = True
include_good_friday = True
Expand Down
3 changes: 2 additions & 1 deletion workalendar/america/mexico.py
Expand Up @@ -8,9 +8,10 @@
class Mexico(WesternCalendar):
"Mexico"
FIXED_HOLIDAYS = WesternCalendar.FIXED_HOLIDAYS + (
(5, 1, "Labour Day"),
(9, 16, "Independence Day"),
)
# Civil holidays
include_labour_day = True

def get_variable_days(self, year):
days = super().get_variable_days(year)
Expand Down
4 changes: 3 additions & 1 deletion workalendar/america/panama.py
Expand Up @@ -7,13 +7,15 @@
@iso_register('PA')
class Panama(WesternCalendar):
"Panama"
# Civil holidays
include_labour_day = True
# Christian holidays
include_good_friday = True
include_easter_saturday = True
include_easter_sunday = True

FIXED_HOLIDAYS = WesternCalendar.FIXED_HOLIDAYS + (
(1, 9, "Martyrs' Day"),
(5, 1, "Labour Day"),
(11, 3, "Independence Day"),
(11, 5, "Colon Day"),
(11, 10, "Shout in Villa de los Santos"),
Expand Down
4 changes: 3 additions & 1 deletion workalendar/america/paraguay.py
Expand Up @@ -8,12 +8,14 @@
class Paraguay(WesternCalendar):
"Paraguay"
FIXED_HOLIDAYS = WesternCalendar.FIXED_HOLIDAYS + (
(5, 1, "Labour Day"),
(5, 14, "Independence Day"),
(6, 12, "Chaco Armistice"),
(9, 19, "Army holiday"),
(12, 8, "Virgin of Caacupé Day"),
)
# Civil holidays
include_labour_day = True
# Christian holidays
include_holy_thursday = True
include_good_friday = True
include_easter_saturday = True
Expand Down
4 changes: 3 additions & 1 deletion workalendar/asia/hong_kong.py
Expand Up @@ -11,6 +11,9 @@
@iso_register('HK')
class HongKong(WesternMixin, ChineseNewYearCalendar):
"Hong Kong"
# Civil holidays
include_labour_day = True
# Christian holidays
include_good_friday = True
include_easter_saturday = True
include_easter_monday = True
Expand All @@ -19,7 +22,6 @@ class HongKong(WesternMixin, ChineseNewYearCalendar):
WEEKEND_DAYS = (SUN,)

FIXED_HOLIDAYS = ChineseNewYearCalendar.FIXED_HOLIDAYS + (
(5, 1, "Labour Day"),
(7, 1, "SAR Establishment Day"),
(10, 1, "National Day"),
)
Expand Down
6 changes: 5 additions & 1 deletion workalendar/asia/malaysia.py
Expand Up @@ -10,6 +10,11 @@
@iso_register('MY')
class Malaysia(IslamicMixin, ChineseNewYearCalendar):
"Malaysia"
# Civil holidays
include_labour_day = True
labour_day_label = "Workers' Day"

# Islamic holidays
include_nuzul_al_quran = True
include_eid_al_fitr = True
length_eid_al_fitr = 2
Expand All @@ -25,7 +30,6 @@ class Malaysia(IslamicMixin, ChineseNewYearCalendar):

FIXED_HOLIDAYS = ChineseNewYearCalendar.FIXED_HOLIDAYS + (
(2, 1, "Federal Territory Day"),
(5, 1, "Workers' Day"),
(8, 31, "National Day"),
(9, 16, "Malaysia Day"),
(12, 25, "Christmas Day"),
Expand Down
8 changes: 5 additions & 3 deletions workalendar/asia/singapore.py
Expand Up @@ -10,6 +10,9 @@
@iso_register('SG')
class Singapore(WesternMixin, IslamicMixin, ChineseNewYearCalendar):
"Singapore"
# Civil holidays
include_labour_day = True

# Christian holiday
include_good_friday = True

Expand All @@ -20,7 +23,6 @@ class Singapore(WesternMixin, IslamicMixin, ChineseNewYearCalendar):
day_of_sacrifice_label = "Hari Raya Haji"

FIXED_HOLIDAYS = ChineseNewYearCalendar.FIXED_HOLIDAYS + (
(5, 1, "Labour Day"),
(8, 9, "National Day"),
)

Expand Down Expand Up @@ -50,8 +52,8 @@ class Singapore(WesternMixin, IslamicMixin, ChineseNewYearCalendar):
2017: date(2017, 10, 18),
2018: date(2018, 11, 6),
2019: date(2019, 10, 27),
2020: date(2020, 11, 14), # This might change
2021: date(2021, 11, 4),
2020: date(2020, 11, 14),
2021: date(2021, 11, 4), # This might change
}
chinese_new_year_label = "Chinese Lunar New Year's Day"
include_chinese_second_day = True
Expand Down
7 changes: 7 additions & 0 deletions workalendar/core.py
Expand Up @@ -802,13 +802,20 @@ class Calendar(CoreCalendar):
"""
include_new_years_day = True
shift_new_years_day = False
include_labour_day = False
labour_day_label = "Labour Day"

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")
)

if self.include_labour_day:
days.append(
(date(year, 5, 1), self.labour_day_label)
)
return days

def get_variable_days(self, year):
Expand Down

0 comments on commit abee8bb

Please sign in to comment.