Skip to content

Commit

Permalink
Merge branch 'ludsoft / FederalReserveSystem'
Browse files Browse the repository at this point in the history
  • Loading branch information
brunobord committed Feb 22, 2022
2 parents ac710ad + 39052a4 commit 45c0b8a
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 3 deletions.
1 change: 1 addition & 0 deletions Changelog.md
Expand Up @@ -8,6 +8,7 @@
- Added conditional holidays on 26th December and 2nd January in Neuchatel (Switzerland) (#697).
- Added Federal Thanksgiving Monday and two conditional holidays on 26th December and 2nd January in Neuchatel (Switzerland) (#697).
- Documentation: Fix the ``keep_datetime`` usage example in the "basic" doc (#690).
- New calendar: Added USA Federal Reserve System calendar by @ludsoft (#695)

## v16.2.0 (2021-12-10)

Expand Down
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -166,6 +166,7 @@ from the command line.
- Suffolk County, Massachusetts
- California Education, Berkeley, San Francisco, West Hollywood
- Florida Legal and Florida Circuit Courts, Miami-Dade
- Federal Reserve System

### Asia

Expand Down
31 changes: 31 additions & 0 deletions workalendar/tests/test_usa.py
Expand Up @@ -21,6 +21,7 @@
Utah, Vermont, Virginia, Washington, WestVirginia, Wisconsin, Wyoming,
# Other territories, cities...
AmericanSamoa, ChicagoIllinois, Guam, SuffolkCountyMassachusetts,
FederalReserveSystem,
)


Expand Down Expand Up @@ -1931,3 +1932,33 @@ def test_shift_2021(self):
# January 1st is a non-shift, Dec 31st should be a working day
self.assertNotIn(date(2021, 12, 31), holidays)
self.assertTrue(self.cal.is_working_day(date(2021, 12, 31)))


class FederalReserveSystemTest(UnitedStatesTest):

cal_class = FederalReserveSystem

def test_juneteenth_day(self):

holidays = self.cal.holidays_set(2021)
juneteenth, _ = self.cal.get_juneteenth_day(2021)
self.assertEqual(date(2021, 6, 19), juneteenth)
# 2021-06-19 is a Saturday so holiday is shifted
self.assertIn(date(2021, 6, 18), holidays)

holidays = self.cal.holidays_set(2022)
juneteenth, _ = self.cal.get_juneteenth_day(2022)
self.assertEqual(date(2022, 6, 19), juneteenth)
# 2022-06-19 is a Sunday so holiday is shifted
self.assertIn(date(2022, 6, 20), holidays)

holidays = self.cal.holidays_set(2023)
juneteenth, _ = self.cal.get_juneteenth_day(2023)
self.assertEqual(date(2023, 6, 19), juneteenth)
self.assertIn(juneteenth, holidays)

# No JuneTeeth before 2021
holidays = self.cal.holidays_set(2020)
self.assertNotIn(date(2020, 6, 20), holidays)
with self.assertRaises(ValueError):
self.cal.get_juneteenth_day(2020)
3 changes: 2 additions & 1 deletion workalendar/usa/__init__.py
@@ -1,4 +1,4 @@
from .core import UnitedStates
from .core import UnitedStates, FederalReserveSystem

from .alabama import (
Alabama, AlabamaBaldwinCounty, AlabamaMobileCounty, AlabamaPerryCounty)
Expand Down Expand Up @@ -122,4 +122,5 @@
# Non-State territories
'AmericanSamoa',
'Guam',
'FederalReserveSystem'
]
24 changes: 22 additions & 2 deletions workalendar/usa/core.py
@@ -1,7 +1,6 @@
from datetime import date, timedelta

from ..core import WesternCalendar
from ..core import SUN, MON, TUE, THU, SAT
from ..core import MON, SAT, SUN, THU, TUE, WesternCalendar
from ..registry_tools import iso_register


Expand Down Expand Up @@ -62,6 +61,9 @@ class UnitedStates(WesternCalendar):
include_fat_tuesday = False
fat_tuesday_label = "Mardi Gras"

# Juneteenth
include_juneteenth = False

# Shift day mechanism
# These days won't be shifted to next MON or previous FRI
shift_exceptions = (
Expand Down Expand Up @@ -259,6 +261,15 @@ def get_national_memorial_day(self, year):
self.national_memorial_day_label
)

def get_juneteenth_day(self, year):
"""
Return Juneteenth Day
"""
# Juneteenth started to be a federal holiday in 2021
if year < 2021:
raise ValueError("Juneteenth became a federal holiday in 2021")
return (date(year, 6, 19), "Juneteenth National Independence Day")

def get_variable_days(self, year):
# usual variable days
days = super().get_variable_days(year)
Expand Down Expand Up @@ -314,6 +325,9 @@ def get_variable_days(self, year):
self.get_thanksgiving_friday(year)
)

if self.include_juneteenth and year >= 2021:
days.append(self.get_juneteenth_day(year))

return days

def get_veterans_day(self, year):
Expand All @@ -337,3 +351,9 @@ def get_calendar_holidays(self, year):
days = super().get_calendar_holidays(year)
days = self.shift(days, year)
return days


class FederalReserveSystem(UnitedStates):
"Board of Governors of the Federal Reserve System of the USA"

include_juneteenth = True

0 comments on commit 45c0b8a

Please sign in to comment.