Last active
December 17, 2015 18:29
-
-
Save oschuett/5653243 to your computer and use it in GitHub Desktop.
The Sechseläuten is a traditional spring holiday in the Swiss city of Zürich.
This python function calculates for a given year the holiday's date.
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 sechselaeuten(year): | |
from datetime import date, timedelta | |
from dateutil.easter import easter | |
april_mondays = [date(year,4,d) for d in range(1,31) if date(year,4,d).weekday()==0] | |
holy_monday = easter(year) - timedelta(days=6) | |
easter_monday = easter(year) + timedelta(days=1) | |
if(april_mondays[2].isocalendar()[1] in (17, 18)): # avoid school holidays... | |
if(april_mondays[1] not in (holy_monday, easter_monday)): #...unless there's s.th. else | |
return(april_mondays[1]) | |
if(april_mondays[2] == holy_monday): # avoid holy week | |
return(april_mondays[1]) | |
if(april_mondays[2] == easter_monday): # avoid easter | |
return(april_mondays[3]) | |
return(april_mondays[2]) # default date |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment