Created
December 13, 2017 12:51
-
-
Save datiti/ac8598e7a54e9d40d9758e533d79dc5b to your computer and use it in GitHub Desktop.
Compute easter/ascension/pentecost dates
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
from datetime import date | |
from datetime import timedelta | |
def calc_easter_sunday(year: int) -> date: | |
""" | |
Returns Easter as a date object. | |
An implementation of Butcher's Algorithm for determining the date of Easter for the Western church. | |
Works for any date in the Gregorian calendar (1583 and onward). | |
Reference: http://code.activestate.com/recipes/576517-calculate-easter-western-given-a-year/ | |
""" | |
a = year % 19 | |
b = year // 100 | |
c = year % 100 | |
d = (19 * a + b - b // 4 - ((b - (b + 8) // 25 + 1) // 3) + 15) % 30 | |
e = (32 + 2 * (b % 4) + 2 * (c // 4) - d - (c % 4)) % 7 | |
f = d + e - 7 * ((a + 11 * d + 22 * e) // 451) + 114 | |
month = f // 31 | |
day = f % 31 + 1 | |
return date(year, month, day) | |
def calc_easter_monday(year: int) -> date: | |
"Returns Easter Monday as a date object." | |
return calc_easter_sunday(year)+timedelta(days=1) | |
def calc_ascension_thursday(year: int) -> date: | |
"Returns Ascension day as a date object." | |
return calc_easter_sunday(year)+timedelta(days=39) | |
def calc_pentecost_sunday(year: int) -> date: | |
"Returns Pentecost Sunday as a date object." | |
return calc_easter_sunday(year)+timedelta(days=49) | |
def calc_pentecost_monday(year: int) -> date: | |
"Returns Pentecost Monday as a date object." | |
return calc_easter_sunday(year)+timedelta(days=50) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment