add a better method to calculate easter sunday

This commit is contained in:
2021-02-09 14:06:18 +01:00
parent bba60a00a4
commit b08728f54c

View File

@@ -10,15 +10,57 @@
.. moduleauthor:: Daniel Weschke <daniel.weschke@directbox.de>
"""
import datetime
def computus_anonymous_gregorian(year):
"""Computus anonymous Gregorian algorithm or Meeus/Jones/Butcher
algorithm.
:param year: the year to calculate the Easter Sunday
:type year: int
:returns: the day of Easter Sunday
:rtype: datetime.date
For Gregorian calendar (1583 and onward)
Works without exeptions.
Published
1876 by Anonymous in Nature
1877 by Samuel Butcher in The Ecclesiastical Calendar
1916 by Arthur Downing in The Observatory
1922 by Harold Spencer Jones in General Astronomy
1988 by Peter Duffett-Smith in Practical Astronomy with your Calculator
1991 by Jean Meeus in Astronomical Algorithms
source: https://de.wikipedia.org/wiki/Spencers_Osterformel
source: https://en.wikipedia.org/wiki/Computus#Anonymous_Gregorian_algorithm
"""
a = year % 19
b = year // 100
c = year % 100
d = b // 4
e = b % 4
f = (b + 8) // 25
g = (b - f + 1) // 3
h = (19 * a + b - d - g + 15) % 30
i = c // 4
k = c % 4
l = (32 + 2 * e + 2 * i - h - k) % 7
m = (a + 11 * h + 22 * l) // 451
n = (h + l - 7 * m + 114) // 31
o = (h + l - 7 * m + 114) % 31
return datetime.date(year, n, o + 1)
# was not correct for 2020
def gaußsche_osterformel(year):
"""Gaußsche Osterformel.
:param year: the year to calculate the Easter Sunday
:type year: int
:returns: the day of Easter Sunday as a day in march.
:rtype: int
:returns: the day of Easter Sunday (computed as a day in march).
:rtype: datetime.date
:ivar X: Das Jahr / year
:vartype X: int
@@ -58,7 +100,10 @@ def gaußsche_osterformel(year):
sz = 7 - (x + x // 4 + s) % 7
oe = 7 - (og - sz) % 7
os = og + oe
return os
march = datetime.date(year, 3, 1)
day = march + datetime.timedelta(days=os)
return day
def easter_sunday(year):
"""Easter Sunday.
@@ -68,10 +113,7 @@ def easter_sunday(year):
:returns: the day of Easter Sunday
:rtype: datetime.date"""
import datetime
march = datetime.date(year, 3, 1)
day = march + datetime.timedelta(days=gaußsche_osterformel(year))
return day
return computus_anonymous_gregorian(year)
def easter_friday(year):
"""Easter Friday.
@@ -81,7 +123,6 @@ def easter_friday(year):
:returns: the day of Easter Friday
:rtype: datetime.date"""
import datetime
day = easter_sunday(year) + datetime.timedelta(days=-2)
return day
@@ -93,7 +134,6 @@ def easter_monday(year):
:returns: the day of Easter Monday
:rtype: datetime.date"""
import datetime
day = easter_sunday(year) + datetime.timedelta(days=+1)
return day
@@ -105,7 +145,6 @@ def ascension_of_jesus(year):
:returns: the day of ascension of Jesus
:rtype: datetime.date"""
import datetime
day = easter_sunday(year) + datetime.timedelta(days=+39)
return day
@@ -117,6 +156,5 @@ def pentecost(year):
:returns: the day of Pentecost
:rtype: datetime.date"""
import datetime
day = easter_sunday(year) + datetime.timedelta(days=+49)
return day