Skip to content

Instantly share code, notes, and snippets.

@pyrtsa
Last active October 9, 2015 14:48
Show Gist options
  • Save pyrtsa/3525697 to your computer and use it in GitHub Desktop.
Save pyrtsa/3525697 to your computer and use it in GitHub Desktop.
Finnish holidays
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