Skip to content

Commit

Permalink
Implement US federal holidays
Browse files Browse the repository at this point in the history
As defined in federal law (5 U.S.C. 6103) according to https://www.opm.gov/policy-data-oversight/pay-leave/federal-holidays/

Closes #114

Signed-off-by: Thomas Lauf <[email protected]>
  • Loading branch information
lauft committed Nov 14, 2024
1 parent 37b41c7 commit 1920935
Show file tree
Hide file tree
Showing 26 changed files with 472 additions and 3 deletions.
3 changes: 3 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
- #115 US: Implement federal holidays
(thanks to J. David Stark)

2024.11.0
- hu-HU: Add non-working days for 2025 in Hungary

Expand Down
132 changes: 131 additions & 1 deletion src/holidata/holidays/US.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from dateutil.easter import EASTER_WESTERN

from holidata.holiday import Country
from holidata.utils import first, third, last, second, fourth, day
from holidata.utils import SmartDayArrow, first, second, third, fourth, last, day


class US(Country):
Expand All @@ -21,6 +21,53 @@ def __init__(self):
.on(month=1, day=1) \
.with_flags("NF")

self.define_holiday() \
.with_names({
"en": "New Year's Day (in lieu of)",
"es": "Año Neuvo (en lugar de)",
}) \
.on(month=12, day=31) \
.on_condition(US.date_is_friday(month=12, day=31)) \
.with_flags("NF")

self.define_holiday() \
.with_names({
"en": "New Year's Day (in lieu of)",
"es": "Año Neuvo (en lugar de)",
}) \
.on(month=1, day=2) \
.on_condition(US.date_is_sunday(month=1, day=1)) \
.with_flags("NF")

self.define_holiday() \
.with_names({
"en": "Juneteenth National Independence Day",
"es": "Juneteenth – Día de la Emancipación",
}) \
.since(2021) \
.on(month=6, day=19) \
.with_flags("NF")

self.define_holiday() \
.with_names({
"en": "Juneteenth National Independence Day (in lieu of)",
"es": "Juneteenth – Día de la Emancipación (en lugar de)",
}) \
.since(2021) \
.on(month=6, day=18) \
.on_condition(US.date_is_saturday(month=6, day=19)) \
.with_flags("NF")

self.define_holiday() \
.with_names({
"en": "Juneteenth National Independence Day (in lieu of)",
"es": "Juneteenth – Día de la Emancipación (en lugar de)",
}) \
.since(2021) \
.on(month=6, day=20) \
.on_condition(US.date_is_sunday(month=6, day=19)) \
.with_flags("NF")

self.define_holiday() \
.with_names({
"en": "Independence Day",
Expand All @@ -29,6 +76,24 @@ def __init__(self):
.on(month=7, day=4) \
.with_flags("NF")

self.define_holiday() \
.with_names({
"en": "Independence Day (in lieu of)",
"es": "Día de la Independiencia (en lugar de)",
}) \
.on(month=7, day=3) \
.on_condition(US.date_is_saturday(month=7, day=4)) \
.with_flags("NF")

self.define_holiday() \
.with_names({
"en": "Independence Day (in lieu of)",
"es": "Día de la Independiencia (en lugar de)",
}) \
.on(month=7, day=5) \
.on_condition(US.date_is_sunday(month=7, day=4)) \
.with_flags("NF")

self.define_holiday() \
.with_names({
"en": "Veterans Day",
Expand All @@ -37,12 +102,31 @@ def __init__(self):
.on(month=11, day=11) \
.with_flags("NF")

self.define_holiday() \
.with_names({
"en": "Veterans Day (in lieu of)",
"es": "Día de los Veteranos (en lugar de)",
}) \
.on(month=11, day=10) \
.on_condition(US.date_is_saturday(month=11, day=11)) \
.with_flags("NF")

self.define_holiday() \
.with_names({
"en": "Veterans Day (in lieu of)",
"es": "Día de los Veteranos (en lugar de)",
}) \
.on(month=11, day=12) \
.on_condition(US.date_is_sunday(month=11, day=11)) \
.with_flags("NF")

self.define_holiday() \
.with_names({
"en": "Christmas Eve",
"es": "Nochebuena",
}) \
.on(month=12, day=24) \
.on_condition(US.date_is_not_saturday(month=12, day=25)) \
.with_flags("NRF")

self.define_holiday() \
Expand All @@ -53,6 +137,24 @@ def __init__(self):
.on(month=12, day=25) \
.with_flags("NRF")

self.define_holiday() \
.with_names({
"en": "Christmas Day (in lieu of)",
"es": "Navidad (en lugar de)",
}) \
.on(month=12, day=24) \
.on_condition(US.date_is_saturday(month=12, day=25)) \
.with_flags("NRF")

self.define_holiday() \
.with_names({
"en": "Christmas Day (in lieu of)",
"es": "Navidad (en lugar de)",
}) \
.on(month=12, day=26) \
.on_condition(US.date_is_sunday(month=12, day=25)) \
.with_flags("NRF")

self.define_holiday() \
.with_names({
"en": "Birthday of Martin Luther King, Jr.",
Expand Down Expand Up @@ -117,3 +219,31 @@ def __init__(self):
}) \
.on(day(1).after(fourth("thursday").of("november"))) \
.with_flags("NV")

@staticmethod
def date_is_not_saturday(month, day):
def wrapper(year):
return SmartDayArrow(year, month, day).weekday() != "saturday"

return wrapper

@staticmethod
def date_is_friday(month, day):
def wrapper(year):
return SmartDayArrow(year, month, day).weekday() == "friday"

return wrapper

@staticmethod
def date_is_saturday(month, day):
def wrapper(year):
return SmartDayArrow(year, month, day).weekday() == "saturday"

return wrapper

@staticmethod
def date_is_sunday(month, day):
def wrapper(year):
return SmartDayArrow(year, month, day).weekday() == "sunday"

return wrapper
Original file line number Diff line number Diff line change
Expand Up @@ -110,5 +110,13 @@
"notes": "",
"region": "",
"type": "NRF"
},
{
"date": "2011-12-26",
"description": "Christmas Day (in lieu of)",
"locale": "en-US",
"notes": "",
"region": "",
"type": "NRF"
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@
"region": "",
"type": "NF"
},
{
"date": "2012-01-02",
"description": "New Year's Day (in lieu of)",
"locale": "en-US",
"notes": "",
"region": "",
"type": "NF"
},
{
"date": "2012-01-16",
"description": "Birthday of Martin Luther King, Jr.",
Expand Down Expand Up @@ -79,6 +87,14 @@
"region": "",
"type": "NF"
},
{
"date": "2012-11-12",
"description": "Veterans Day (in lieu of)",
"locale": "en-US",
"notes": "",
"region": "",
"type": "NF"
},
{
"date": "2012-11-22",
"description": "Thanksgiving Day",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@
"region": "",
"type": "NV"
},
{
"date": "2015-07-03",
"description": "Independence Day (in lieu of)",
"locale": "en-US",
"notes": "",
"region": "",
"type": "NF"
},
{
"date": "2015-07-04",
"description": "Independence Day",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,5 +110,13 @@
"notes": "",
"region": "",
"type": "NRF"
},
{
"date": "2016-12-26",
"description": "Christmas Day (in lieu of)",
"locale": "en-US",
"notes": "",
"region": "",
"type": "NRF"
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@
"region": "",
"type": "NF"
},
{
"date": "2017-01-02",
"description": "New Year's Day (in lieu of)",
"locale": "en-US",
"notes": "",
"region": "",
"type": "NF"
},
{
"date": "2017-01-16",
"description": "Birthday of Martin Luther King, Jr.",
Expand Down Expand Up @@ -71,6 +79,14 @@
"region": "",
"type": "NV"
},
{
"date": "2017-11-10",
"description": "Veterans Day (in lieu of)",
"locale": "en-US",
"notes": "",
"region": "",
"type": "NF"
},
{
"date": "2017-11-11",
"description": "Veterans Day",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@
"region": "",
"type": "NF"
},
{
"date": "2018-11-12",
"description": "Veterans Day (in lieu of)",
"locale": "en-US",
"notes": "",
"region": "",
"type": "NF"
},
{
"date": "2018-11-22",
"description": "Thanksgiving Day",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@
"region": "",
"type": "NV"
},
{
"date": "2020-07-03",
"description": "Independence Day (in lieu of)",
"locale": "en-US",
"notes": "",
"region": "",
"type": "NF"
},
{
"date": "2020-07-04",
"description": "Independence Day",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,22 @@
"region": "",
"type": "NV"
},
{
"date": "2021-06-18",
"description": "Juneteenth National Independence Day (in lieu of)",
"locale": "en-US",
"notes": "",
"region": "",
"type": "NF"
},
{
"date": "2021-06-19",
"description": "Juneteenth National Independence Day",
"locale": "en-US",
"notes": "",
"region": "",
"type": "NF"
},
{
"date": "2021-07-04",
"description": "Independence Day",
Expand All @@ -55,6 +71,14 @@
"region": "",
"type": "NF"
},
{
"date": "2021-07-05",
"description": "Independence Day (in lieu of)",
"locale": "en-US",
"notes": "",
"region": "",
"type": "NF"
},
{
"date": "2021-09-06",
"description": "Labor Day",
Expand Down Expand Up @@ -97,7 +121,7 @@
},
{
"date": "2021-12-24",
"description": "Christmas Eve",
"description": "Christmas Day (in lieu of)",
"locale": "en-US",
"notes": "",
"region": "",
Expand All @@ -110,5 +134,13 @@
"notes": "",
"region": "",
"type": "NRF"
},
{
"date": "2021-12-31",
"description": "New Year's Day (in lieu of)",
"locale": "en-US",
"notes": "",
"region": "",
"type": "NF"
}
]
Loading

0 comments on commit 1920935

Please sign in to comment.