Repository: peopledoc/workalendar
Pull request #472 (2020-03-04 13:26:06)

Adding holidays for Belarus
refs #

<!-- if your contribution is a new calendar -->

For information, read and make sure you're okay with the [Contributing guidelines](https://github.com/novafloss/workalendar/blob/master/contributing.md#adding-new-calendars).

- [x] Tests with a significant number of years to be tested for your calendar.
- [x] Docstrings for the Calendar class and specific methods.
- [x] Use the ``workalendar.registry_tools.iso_register`` decorator to register your new calendar using ISO codes (optional).
- [x] Calendar country / label added to the README.rst file.
- [x] Changelog amended with a mention like: "Added ``<country>`` by ``@pseudo`` (#)". **Note** *Please do NOT change the version number here. It's the project maintainers' duty.*

<!-- if your contribution is a fix -->

- [x] Tests with a significant number of years to be tested for your calendar.
- [x] Changelog amended with a mention describing your changes. **Note** *Please do NOT change the version number here. It's the project maintainers' duty.*

<!-- Release management

- Commit for the tag:
    - [ ] Edit version in setup.py
    - [ ] Add version in Changelog.md ; trim things
    - [ ] Push & wait for the tests to be green
    - [ ] tag me.
    - [ ] build sdist + wheel packages (``make package``)
- Back to dev commit:
    - [ ] Edit version in setup.py
    - [ ] Add the "master / nothing to see here" in Changelog.md
    - [ ] Push & wait for the tests to be green
- [ ] Merge --ff
- Github stuff
    - [ ] Push tag in Github
    - [ ] Edit release on Github using the changelog.
    - [ ] Delete branch
- [ ] upload release on PyPI using ``twine``
- [ ] (*optional*) Make feeback on the various PR or issues.

 -->



Patch:
diff --git a/Changelog.md b/Changelog.md
index e5031b4..6bc9ffd 100644
--- a/Changelog.md
+++ b/Changelog.md
@@ -2,7 +2,7 @@
 
 ## master (unreleased)
 
-Nothing here yet.
+- Added Belarus calendar, by @alexdoesstuff.
 
 ## v8.1.0 (2020-02-07)
 
diff --git a/README.rst b/README.rst
index 8bbcdf8..5215290 100644
--- a/README.rst
+++ b/README.rst
@@ -78,6 +78,7 @@ Europe
 ------
 
 * Austria
+* Belarus
 * Belgium
 * Bulgaria
 * Cayman Islands
diff --git a/workalendar/europe/__init__.py b/workalendar/europe/__init__.py
index d1322e6..bc7415f 100644
--- a/workalendar/europe/__init__.py
+++ b/workalendar/europe/__init__.py
@@ -1,4 +1,5 @@
 from .austria import Austria
+from .belarus import Belarus
 from .belgium import Belgium
 from .bulgaria import Bulgaria
 from .cayman_islands import CaymanIslands
@@ -54,6 +55,7 @@ from .scotland import (
 
 __all__ = (
     'Austria',
+    'Belarus',
     'Belgium',
     'Bulgaria',
     'Catalonia',
diff --git a/workalendar/europe/belarus.py b/workalendar/europe/belarus.py
new file mode 100644
index 0000000..37a83cd
--- /dev/null
+++ b/workalendar/europe/belarus.py
@@ -0,0 +1,38 @@
+from datetime import timedelta
+from ..core import WesternCalendar, OrthodoxMixin
+from ..registry_tools import iso_register
+
+
+@iso_register('BY')
+class Belarus(WesternCalendar, OrthodoxMixin):
+    'Belarus'
+    "as of http://president.gov.by/en/holidays_en/"
+
+    include_christmas = False
+
+    FIXED_HOLIDAYS = WesternCalendar.FIXED_HOLIDAYS + (
+        (1, 2, "Day After New Year"),
+        (1, 7, "Christmas (Orthodox)"),
+        (3, 8, "International Women's Day"),
+        (5, 1, "Labour Day"),
+        (5, 9, "Victory Day"),
+        (7, 3, "Republic Day"),
+        (11, 7, "October Revolution Day"),
+        (12, 25, "Christmas (Catholic)"),
+    )
+    # Radonitsa
+    # https://en.wikipedia.org/wiki/Radonitsa
+
+    def get_radonitsa(self, year):
+        # Second Monday after easter sunday
+        return self.get_easter_sunday(year) + timedelta(days=15)
+
+    def get_day_after_radonitsa(self, year):
+        # one day after the Radonsista Monday
+        return self.get_radonitsa(year) + timedelta(days=1)
+
+    def get_variable_days(self, year):
+        days = super().get_variable_days(year)
+        days.append((self.get_radonitsa(year), "Radonista"))
+        days.append((self.get_day_after_radonitsa(year), "Radonista Holiday"))
+        return days


Test patch:
diff --git a/workalendar/tests/test_europe.py b/workalendar/tests/test_europe.py
index f435762..73b23c3 100644
--- a/workalendar/tests/test_europe.py
+++ b/workalendar/tests/test_europe.py
@@ -5,6 +5,7 @@ from . import GenericCalendarTest
 from ..europe import (
     Austria,
     Bulgaria,
+    Belarus,
     Belgium,
     CaymanIslands,
     Croatia,
@@ -62,6 +63,38 @@ class AustriaTest(GenericCalendarTest):
         self.assertIn(date(2016, 12, 26), holidays)  # St Stephens
 
 
+class BelarusTest(GenericCalendarTest):
+    cal_class = Belarus
+
+    def test_year_2019(self):
+        holidays = self.cal.holidays_set(2019)
+        self.assertIn(date(2019, 1, 1), holidays)  # New Years day
+        self.assertIn(date(2019, 1, 2), holidays)  # Day after NYE
+        self.assertIn(date(2019, 1, 7), holidays)  # Christmas (Orthodox)
+        self.assertIn(date(2019, 3, 8), holidays)  # International Women's Day
+        self.assertIn(date(2019, 5, 1), holidays)  # Labour Day
+        self.assertIn(date(2019, 5, 6), holidays)  # Radonista
+        self.assertIn(date(2019, 5, 7), holidays)  # Radonista Holiday
+        self.assertIn(date(2019, 5, 9), holidays)  # Victory Day
+        self.assertIn(date(2019, 7, 3), holidays)  # Republic Day
+        self.assertIn(date(2019, 11, 7), holidays)  # October Revolution Day
+        self.assertIn(date(2019, 12, 25), holidays)  # Christmas (Catholic)
+
+    def test_year_2020(self):
+        holidays = self.cal.holidays_set(2020)
+        self.assertIn(date(2020, 1, 1), holidays)  # New Years day
+        self.assertIn(date(2020, 1, 2), holidays)  # Day after NYE
+        self.assertIn(date(2020, 1, 7), holidays)  # Christmas (Orthodox)
+        self.assertIn(date(2020, 3, 8), holidays)  # International Women's Day
+        self.assertIn(date(2020, 4, 27), holidays)  # Radonista
+        self.assertIn(date(2020, 4, 28), holidays)  # Radonista Holiday
+        self.assertIn(date(2020, 5, 1), holidays)  # Labour Day
+        self.assertIn(date(2020, 5, 9), holidays)  # Victory Day
+        self.assertIn(date(2020, 7, 3), holidays)  # Republic Day
+        self.assertIn(date(2020, 11, 7), holidays)  # October Revolution Day
+        self.assertIn(date(2020, 12, 25), holidays)  # Christmas (Catholic)
+
+
 class BulgariaTest(GenericCalendarTest):
     cal_class = Bulgaria