Last active
October 9, 2015 14:48
-
-
Save pyrtsa/3525697 to your computer and use it in GitHub Desktop.
Finnish holidays
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def is_holiday(d): | |
"""Check whether the given dateutil.date is a Finnish national holiday""" | |
import dateutil.easter | |
from datetime import date, timedelta as td | |
assert isinstance(d, date) | |
md = '{}.{}'.format(d.day, d.month) | |
y = d.year | |
# Fixed-date holidays | |
if md in '1.1 6.1 1.5 6.12 24.12 25.12 26.12'.split(): return True | |
# Finnish midsummer (eve on Fri the 19..25th, day on Sat the 20..26th) | |
if date(y,6,19) <= d <= date(y,6,25) and d.weekday() == 4: return True | |
if date(y,6,20) <= d <= date(y,6,26) and d.weekday() == 5: return True | |
# All Saints (Saturday) | |
if date(y,10,31) <= d <= date(y,11,6) and d.weekday() == 5: return True | |
# Easter etc. | |
e = dateutil.easter.easter(d.year) | |
if d in [e - td(2), e, e + td(1), e + td(39), e + td(49)]: return True | |
return False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment