Skip to content

Commit

Permalink
Merge pull request #182 from brutasse/feature/ch-vd
Browse files Browse the repository at this point in the history
Switzerland: add rules for canton of Vaud
  • Loading branch information
brunobord committed Feb 28, 2017
2 parents dbe1177 + 485b79a commit 8df076f
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 3 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ master (unreleased)
- Add Latvia. thx @gregn610 (#178).
- Add Malta. thx @gregn610 (#179).
- Add Romania. thx @gregn610 (#180).

- Add Canton of Vaud (Switzerland) - @brutasse (#182)

1.0.0 (2016-12-12)
------------------
Expand Down
1 change: 1 addition & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ Europe
* Spain (incl. Catalonia)
* Slovenia
* Switzerland
* Vaud

America
-------
Expand Down
3 changes: 2 additions & 1 deletion workalendar/europe/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from .slovenia import Slovenia
from .spain import Spain, Catalonia
from .sweden import Sweden
from .switzerland import Switzerland
from .switzerland import Switzerland, Vaud
from .united_kingdom import UnitedKingdom, UnitedKingdomNorthernIreland

# Germany
Expand Down Expand Up @@ -71,6 +71,7 @@
Spain,
Sweden,
Switzerland,
Vaud,
UnitedKingdom,
UnitedKingdomNorthernIreland,

Expand Down
29 changes: 29 additions & 0 deletions workalendar/europe/switzerland.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# -*- coding: utf-8 -*-
from datetime import date, timedelta

from workalendar.core import WesternCalendar, ChristianMixin


Expand All @@ -19,3 +21,30 @@ class Switzerland(WesternCalendar, ChristianMixin):
(5, 1, "Labour Day"),
(8, 1, "National Holiday"),
)


class Vaud(Switzerland):
"""Canton of Vaud"""
include_boxing_day = False
include_federal_thanksgiving_monday = True

FIXED_HOLIDAYS = WesternCalendar.FIXED_HOLIDAYS + (
(1, 2, "Berchtold's Day"),
(8, 1, "National Holiday"),
)

def get_federal_thanksgiving_monday(self, year):
"Monday following the 3rd sunday of September"
september_1st = date(year, 9, 1)
return (
september_1st +
(6 - september_1st.weekday()) * timedelta(days=1) + # 1st sunday
timedelta(days=15) # Monday following 3rd sunday
)

def get_variable_days(self, year):
days = super(Vaud, self).get_variable_days(year)
if self.include_federal_thanksgiving_monday:
days.append((self.get_federal_thanksgiving_monday(year),
"Federal Thanksgiving Monday"))
return days
18 changes: 17 additions & 1 deletion workalendar/tests/test_europe.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from workalendar.europe import Romania
from workalendar.europe import Spain, Catalonia
from workalendar.europe import Slovenia
from workalendar.europe import Switzerland
from workalendar.europe import Switzerland, Vaud
from workalendar.europe import UnitedKingdom
from workalendar.europe import UnitedKingdomNorthernIreland
from workalendar.europe import EuropeanCentralBank
Expand Down Expand Up @@ -1159,6 +1159,22 @@ def test_year_2016(self):
self.assertIn(date(2016, 12, 26), holidays)


class VaudTest(GenericCalendarTest):
cal_class = Vaud

def test_year_2016(self):
holidays = self.cal.holidays_set(2016)
self.assertIn(date(2016, 9, 19), holidays)
self.assertNotIn(date(2016, 5, 1), holidays)
self.assertNotIn(date(2016, 12, 26), holidays)

def test_year_2017(self):
holidays = self.cal.holidays_set(2017)
self.assertIn(date(2017, 9, 18), holidays)
self.assertNotIn(date(2017, 5, 1), holidays)
self.assertNotIn(date(2017, 12, 26), holidays)


class EstoniaTest(GenericCalendarTest):
cal_class = Estonia

Expand Down

0 comments on commit 8df076f

Please sign in to comment.