Repository: peopledoc/workalendar
Pull request #325 (2019-02-14 13:40:37)

Added Chicago, Illinois calendar
refs #220


- [x] Tests with a significant number of years to be tested for your calendar.
- [x] Docstrings for the Calendar class and specific methods.
- [x] Calendar country / label added to the README.rst file,
- [x] Changelog amended with a mention like: "Added ``<country>`` by ``@pseudo`` (#)"



Patch:
diff --git a/Changelog.md b/Changelog.md
index e77e30d..385139b 100644
--- a/Changelog.md
+++ b/Changelog.md
@@ -3,6 +3,7 @@
 ## master (unreleased)
 
 - Added the American Samoa territory to the USA calendars (#218).
+- Added Chicago, Illinois calendar (#220).
 
 ## v4.1.0 (2019-02-07)
 
diff --git a/README.rst b/README.rst
index 40212f4..cb9e053 100644
--- a/README.rst
+++ b/README.rst
@@ -122,7 +122,10 @@ America
 * Mexico
 * Panama
 * Paraguay
-* United States of America (including State holidays for all the 50 States, and American Samoa)
+* United States of America
+  * State holidays for all the 50 States
+  * American Samoa
+  * Chicago, Illinois
 * Canada (including provincial and territory holidays)
 
 Asia
diff --git a/workalendar/usa/__init__.py b/workalendar/usa/__init__.py
index 9b6d8b1..566681c 100644
--- a/workalendar/usa/__init__.py
+++ b/workalendar/usa/__init__.py
@@ -17,7 +17,7 @@ from .florida import Florida
 from .georgia import Georgia
 from .hawaii import Hawaii
 from .idaho import Idaho
-from .illinois import Illinois
+from .illinois import Illinois, ChicagoIllinois
 from .indiana import Indiana
 from .iowa import Iowa
 from .kansas import Kansas
@@ -75,7 +75,7 @@ __all__ = [
     'Georgia',
     'Hawaii',
     'Idaho',
-    'Illinois',
+    'Illinois', 'ChicagoIllinois',
     'Indiana',
     'Iowa',
     'Kansas',
diff --git a/workalendar/usa/illinois.py b/workalendar/usa/illinois.py
index c9739bd..a83fd57 100644
--- a/workalendar/usa/illinois.py
+++ b/workalendar/usa/illinois.py
@@ -4,6 +4,7 @@ from __future__ import (absolute_import, division, print_function,
 
 from .core import UnitedStates
 from ..registry import iso_register
+from ..core import MON
 
 
 @iso_register('US-IL')
@@ -12,3 +13,26 @@ class Illinois(UnitedStates):
     include_thanksgiving_friday = True
     include_lincoln_birthday = True
     include_election_day_even = True
+
+
+class ChicagoIllinois(Illinois):
+    "Chicago, Illinois"
+    include_thanksgiving_friday = False
+
+    def get_pulaski_day(self, year):
+        """
+        Return Casimir Pulaski Day.
+
+        Defined on the first MON of March.
+        ref: https://en.wikipedia.org/wiki/Casimir_Pulaski_Day
+        """
+        day = self.get_nth_weekday_in_month(year, 3, MON)
+        return (
+            day,
+            "Casimir Pulaski Day"
+        )
+
+    def get_variable_days(self, year):
+        days = super(ChicagoIllinois, self).get_variable_days(year)
+        days.append(self.get_pulaski_day(year))
+        return days


Test patch:
diff --git a/workalendar/tests/test_usa.py b/workalendar/tests/test_usa.py
index 56b111a..c91b961 100644
--- a/workalendar/tests/test_usa.py
+++ b/workalendar/tests/test_usa.py
@@ -13,8 +13,8 @@ from workalendar.usa import (
     NorthCarolina, NorthDakota, Ohio, Oklahoma, Oregon, Pennsylvania,
     RhodeIsland, SouthCarolina, SouthDakota, Tennessee, TexasBase, Texas,
     Utah, Vermont, Virginia, Washington, WestVirginia, Wisconsin, Wyoming,
-    # Not a state, but an American territory
-    AmericanSamoa,
+    # Other territories, cities...
+    AmericanSamoa, ChicagoIllinois,
 )
 
 
@@ -609,6 +609,34 @@ class IllinoisTest(ElectionDayEvenYears, UnitedStatesTest):
         self.assertIn(date(2015, 11, 27), holidays)  # Thanksgiving Friday
 
 
+class ChicagoIllinoisTest(ElectionDayEvenYears, UnitedStatesTest):
+    cal_class = ChicagoIllinois
+
+    def test_state_year_2014(self):
+        holidays = self.cal.holidays_set(2014)
+        self.assertIn(date(2014, 2, 12), holidays)  # Lincoln's Birthday
+        # Thanksgiving Friday is NOT a holiday in Chicago.
+        self.assertNotIn(date(2014, 11, 28), holidays)
+
+    def test_state_year_2015(self):
+        holidays = self.cal.holidays_set(2015)
+        self.assertIn(date(2015, 2, 12), holidays)  # Lincoln's Birthday
+        # Thanksgiving Friday is NOT a holiday in Chicago.
+        self.assertNotIn(date(2015, 11, 27), holidays)
+
+    def test_pulaski_day(self):
+        # Pulaski day is on the first MON in March.
+        # Source: https://en.wikipedia.org/wiki/Casimir_Pulaski_Day
+        holidays = self.cal.holidays_set(2018)
+        self.assertIn(date(2018, 3, 5), holidays)
+        holidays = self.cal.holidays_set(2019)
+        self.assertIn(date(2019, 3, 4), holidays)
+        holidays = self.cal.holidays_set(2020)
+        self.assertIn(date(2020, 3, 2), holidays)
+        holidays = self.cal.holidays_set(2021)
+        self.assertIn(date(2021, 3, 1), holidays)
+
+
 class IndianaTest(ElectionDayEvenYears, NoPresidentialDay, UnitedStatesTest):
     cal_class = Indiana