Skip to content

Commit

Permalink
refs #31 -- Edinburgh and Perth Victoria Day
Browse files Browse the repository at this point in the history
  • Loading branch information
brunobord committed May 17, 2014
1 parent 29bade5 commit b7236a9
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 3 deletions.
39 changes: 38 additions & 1 deletion workalendar/scotland.py
Expand Up @@ -4,6 +4,7 @@
"""
# Since Scotland territories have a lot of different variations, it has become
# necessary to split this module and associated tests
from datetime import timedelta, date
from workalendar.core import WesternCalendar, ChristianMixin
from workalendar.core import MON

Expand Down Expand Up @@ -33,6 +34,17 @@ def get_spring_holiday(self, year):
)


class SpringHolidayTuesdayMondayMayMixin(object):
def get_spring_holiday(self, year):
first_monday = Scotland.get_nth_weekday_in_month(year, 5, MON)
return (
first_monday + timedelta(days=1),
"Spring Holiday",
)


# -----------------------------------------------------------------------------

class Scotland(WesternCalendar, ChristianMixin):
"Scotland"
FIXED_HOLIDAYS = WesternCalendar.FIXED_HOLIDAYS + (
Expand Down Expand Up @@ -83,6 +95,8 @@ def get_variable_days(self, year):
days.append(self.get_may_day(year))
days.append(self.get_spring_holiday(year))
days.append(self.get_summer_holiday(year))
if hasattr(self, 'get_victoria_day'):
days.append(self.get_victoria_day(year))
return days


Expand Down Expand Up @@ -115,6 +129,10 @@ class ScotlandCarnoustie(SpringHolidayFirstMondayAprilMixin, Scotland):
"Carnoustie (Scotland)"


class ScotlandClydebank(SpringHolidayTuesdayMondayMayMixin, Scotland):
"Clydebank (Scotland)"


class ScotlandDumfriesGalloway(GoodFridayMixin, Scotland):
"Dumfries and Galloway (Scotland)"

Expand Down Expand Up @@ -149,6 +167,16 @@ def get_spring_holiday(self, year):
"Spring Holiday"
)

def get_victoria_day(self, year):
"Last Monday strictly before May 24th"
victoria_day = date(year, 5, 23)
while victoria_day.weekday() != MON:
victoria_day = victoria_day - timedelta(days=1)
return (
victoria_day,
"Victoria Day",
)


class ScotlandFalkirk(GoodFridayMixin, EasterMondayMixin, Scotland):
"Falkirk (Scotland)"
Expand Down Expand Up @@ -187,12 +215,21 @@ class ScotlandPaisley(GoodFridayMixin, EasterMondayMixin, Scotland):
class ScotlandPerth(SpringHolidayFirstMondayAprilMixin, Scotland):
"Perth (Scotland)"

def get_victoria_day(self, year):
"4th Monday in May"
return (
Scotland.get_nth_weekday_in_month(2014, 5, MON, 4),
"Victoria Day",
)


class ScotlandScottishBorders(SpringHolidayFirstMondayAprilMixin, Scotland):
"Scottish Borders (Scotland)"


class ScotlandStirling(GoodFridayMixin, EasterMondayMixin, Scotland):
class ScotlandStirling(
GoodFridayMixin, EasterMondayMixin, SpringHolidayTuesdayMondayMayMixin,
Scotland):
"Stirling (Scotland)"


Expand Down
42 changes: 40 additions & 2 deletions workalendar/tests/test_scotland.py
Expand Up @@ -6,6 +6,7 @@
ScotlandAngus,
ScotlandAyr,
ScotlandCarnoustie,
ScotlandClydebank,
ScotlandDumfriesGalloway,
ScotlandDundee,
ScotlandEastDunbartonshire,
Expand Down Expand Up @@ -59,6 +60,30 @@ def test_spring_holiday_2014(self):
self.assertIn(date(2014, 4, 14), holidays) # Spring holiday


class SpringHolidayTuesdayMondayMayMixin(object):
"Test the 'Tuesday after 1st Monday in May' rule"
def test_spring_holiday_2014(self):
holidays = self.cal.holidays_set(2014)
self.assertIn(date(2014, 5, 5), holidays)

def test_spring_holiday_2012(self):
# Special case: since May 1st is a Tuesday, it's not the 1st Tuesday
holidays = self.cal.holidays_set(2012)
self.assertIn(date(2012, 5, 8), holidays)


class VictoriaDayLastMondayBefore24MayMixin(object):
"Test the 'Last Monday strictly before 24 May' rule"
def test_victoria_day_2014(self):
holidays = self.cal.holidays_set(2014)
self.assertIn(date(2014, 5, 19), holidays)

def test_victoria_day_2010(self):
# Special case: May 24th is a Monday, but it's *strictly* this day
holidays = self.cal.holidays_set(2010)
self.assertIn(date(2010, 5, 17), holidays)


class ScotlandTest(GenericCalendarTest):
cal_class = Scotland

Expand Down Expand Up @@ -106,6 +131,10 @@ class ScotlandCarnoustieTest(SpringHolidayFirstMondayAprilMixin, ScotlandTest):
cal_class = ScotlandCarnoustie


class ScotlandClydebankTest(SpringHolidayTuesdayMondayMayMixin, ScotlandTest):
cal_class = ScotlandClydebank


class ScotlandDumfriesGallowayTest(GoodFridayMixin, ScotlandTest):
cal_class = ScotlandDumfriesGalloway

Expand All @@ -124,7 +153,10 @@ class ScotlandFifeTest(SpringHolidayFirstMondayAprilMixin, ScotlandTest):
cal_class = ScotlandFife


class ScotlandEdinburghTest(GoodFridayMixin, EasterMondayMixin, ScotlandTest):
class ScotlandEdinburghTest(
GoodFridayMixin, EasterMondayMixin,
VictoriaDayLastMondayBefore24MayMixin,
ScotlandTest):
cal_class = ScotlandEdinburgh

def test_spring_holiday_2014(self):
Expand Down Expand Up @@ -175,14 +207,20 @@ class ScotlandPaisleyTest(GoodFridayMixin, EasterMondayMixin, ScotlandTest):
class ScotlandPerthTest(SpringHolidayFirstMondayAprilMixin, ScotlandTest):
cal_class = ScotlandPerth

def test_victoria_day_2014(self):
holidays = self.cal.holidays_set(2014)
self.assertIn(date(2014, 5, 26), holidays)


class ScotlandScottishBordersTest(
SpringHolidayFirstMondayAprilMixin,
ScotlandTest):
cal_class = ScotlandScottishBorders


class ScotlandStirlingTest(GoodFridayMixin, EasterMondayMixin, ScotlandTest):
class ScotlandStirlingTest(
GoodFridayMixin, EasterMondayMixin, SpringHolidayTuesdayMondayMayMixin,
ScotlandTest):
cal_class = ScotlandStirling


Expand Down

0 comments on commit b7236a9

Please sign in to comment.