Python Notes: Easter calculation
- The information presented here is intended for educational use.
- The information presented here is provided free of charge, as-is, with no warranty of any kind.
- Edit: 2021-08-24
Calculating the date of Easter
#!/usr/bin/python3
'''
===================================================================================
title : easter.py
author : Neil Rieck
history: 2021-01-28 original effort
purpose: employ python3 to compute the day of Easter
notes :
1) I used vim8 along with the pymode plugin
2) my .vimrc contains these custom settings:
max width at 119, disabled PEP-008 messages: E305,E501
3) the phrase "noqa: E741" below only disables an editor rule in pymode
===================================================================================
References: Decreed by the first "Council of Nicaea", 325 AD, Easter should be
celebrated on the same day by all Christians using this rule: Easter is the first
Sunday, following the full moon on, or after, the vernal equinox
===================================================================================
Caveats:
1a The Gregorian Calendar (1582) corrects the Julian Calendar (45 BC) like so:
"Thursday 4 October 1582 was followed by Friday 15 October 1582".
1b Years evenly divisible by 4 are leap years (so add a day to February)
1c Except years evenly divisible by 100 (which are not)
1d Except years evenly divisible by 400 (which are; this caused confusion in y2k)
2) Many countries did not adopt this calendar reform for almost 100 years.
3) The Eastern Orthodox church never adopted it for religious purposes
4) All these issues mean that algorithms are calendar specific
5) the algorithm used here is named "Meeus's Julian algorithm" which is a variation
on the algorithm created by Carl Friedrich Gauss
===================================================================================
! Algorithm by Jean Baptiste Joseph Delambre
! ------------------------------------------
! A = Mod(Year / 19)
! B = Int(Year / 100)
! C = Mod(Year / 100)
! D = Int(B / 4)
! E = Mod(B / 4)
! F = Int[(B + 8) / 25]
! G = Int[(B - F + 1) / 3]
! H = Mod[(19xA + B - D - G + 15) / 30]
! I = Int(C / 4)
! K = Mod(C / 4)
! L = Mod[(32 + 2xE + 2xI - H - K) / 7]
! M = Int[(A + 11xH + 22xL) / 451]
! P = Int[(H + L - 7xM + 114) / 31]
! Q = Mod[(H + L - 7xM + 114) / 31]
!
! note: some algorithms mess up years like: 1974, 1984, 1994, etc. so
! you must always test these
===================================================================================
'''
def calc(year): #
A = year % 19 # golden number (Metonic cycle)
B = int(year / 100) # LY-test (century)
C = year % 100 # LY-test (century)
D = int(B / 4) # LY-test (general)
E = B % 4 # LY-test (general)
F = int((B + 8) / 25) #
G = int((B - F + 1) / 3) # 3 of 4 centuries are leap years
H = ((19 * A + B - D - G + 15) % 30) #
I = int(C / 4) # noqa: E741
K = (C % 4) #
L = ((32 + 2 * E + 2 * I - H - K) % 7) #
M = int((A + 11 * H + 22 * L) / 451) #
P = int((H + L - 7 * M + 114) / 31) # month number (starts at 1)
Q = ((H + L - 7 * M + 114) % 31) # day number (starts at zero)
#
mon = P #
day = Q + 1 #
#
# if doing a GOOD FRIDAY calc slide back two days here
#
if mon == 3:
month = "March"
else:
month = "April"
rslt = month + " " + str(day)
return(rslt)
def main():
print('Calculate Easter (1583-3999)')
print('For which year? ', end='')
s = input()
try:
y = 0
y = int(s)
if (y < 1583) or (y > 3999):
print('this algorithm is only useful from 1583-3999')
exit()
except Exception:
print(f'Input error: "{s}" is not a valid number')
exit()
easter = calc(y)
print(f'For year {y} the date of Easter is {easter}')
main()
Links
Back to
Home
Neil Rieck
Waterloo, Ontario, Canada.