Skip to content

Commit

Permalink
Fix Russia calendar: non-working days shifted to MON when they happen…
Browse files Browse the repository at this point in the history
… on the week-end

refs #589
  • Loading branch information
brunobord committed Nov 13, 2020
1 parent ff5b266 commit 9c3a9a2
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## master (unreleased)

Nothing here yet.
- Fix Russia calendar: non-working days are shifted to the next MON when they happen on the week-end (#589).

## v13.0.0 (2020-11-13)

Expand Down
15 changes: 13 additions & 2 deletions workalendar/europe/russia.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
from ..core import OrthodoxCalendar
from ..core import OrthodoxCalendar, MON
from ..registry_tools import iso_register


@iso_register('RU')
class Russia(OrthodoxCalendar):
'Russia'

shift_new_years_day = True

# Civil holidays
Expand All @@ -20,3 +19,15 @@ class Russia(OrthodoxCalendar):
(6, 12, "National Day"),
(11, 4, "Day of Unity"),
)

def get_calendar_holidays(self, year):
holidays = super().get_calendar_holidays(year)
shifts = []
for day, label in holidays:
if day.weekday() in self.get_weekend_days():
shifts.append((
self.get_first_weekday_after(day, MON),
label + " shift"
))
holidays.extend(shifts)
return holidays
27 changes: 27 additions & 0 deletions workalendar/tests/test_europe.py
Original file line number Diff line number Diff line change
Expand Up @@ -1410,6 +1410,33 @@ def test_year_2018(self):
self.assertIn(date(2018, 6, 12), holidays) # National Day
self.assertIn(date(2018, 11, 4), holidays) # Independence Day

def test_year_2020_shift(self):
holidays = dict(self.cal.holidays(2020))
# Defender of the Fatherland Day
self.assertIn(date(2020, 2, 23), holidays)
# SUN => Shift to MON
self.assertIn(date(2020, 2, 24), holidays)
self.assertEqual(
holidays[date(2020, 2, 24)],
"Defendence of the Fatherland shift"
)
# International Women's Day
self.assertIn(date(2020, 3, 8), holidays)
# SUN => Shift to MON
self.assertIn(date(2020, 3, 9), holidays)
self.assertEqual(
holidays[date(2020, 3, 9)],
"International Women's Day shift"
)
# Victory Day
self.assertIn(date(2020, 5, 9), holidays)
# SAT => Shift to MON
self.assertIn(date(2020, 5, 11), holidays)
self.assertEqual(
holidays[date(2020, 5, 11)],
"Victory Day shift"
)


class UkraineTest(GenericCalendarTest):
cal_class = Ukraine
Expand Down

0 comments on commit 9c3a9a2

Please sign in to comment.