-
-
Notifications
You must be signed in to change notification settings - Fork 46.8k
Easter date gauss algorithm #2010
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a707973
Added gauss easter algorithm
l3str4nge c79682b
Fixes in easter algorithm
l3str4nge 13f9cd6
Merge remote-tracking branch 'upstream/master' into easter_date
l3str4nge 992b64f
Merge remote-tracking branch 'upstream/master' into easter_date
l3str4nge 46a3748
Commit suggestions
l3str4nge File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,48 @@ | ||||||||||||||||||
""" | ||||||||||||||||||
https://en.wikipedia.org/wiki/Computus#Gauss'_Easter_algorithm | ||||||||||||||||||
""" | ||||||||||||||||||
import math | ||||||||||||||||||
from datetime import datetime, timedelta | ||||||||||||||||||
|
||||||||||||||||||
|
||||||||||||||||||
def gauss_easter(year: int) -> datetime: | ||||||||||||||||||
""" | ||||||||||||||||||
Calculation Gregorian easter date for given year | ||||||||||||||||||
|
||||||||||||||||||
>>> gauss_easter(2007) | ||||||||||||||||||
datetime.datetime(2007, 4, 8, 0, 0) | ||||||||||||||||||
|
||||||||||||||||||
>>> gauss_easter(2008) | ||||||||||||||||||
datetime.datetime(2008, 3, 23, 0, 0) | ||||||||||||||||||
|
||||||||||||||||||
>>> gauss_easter(2020) | ||||||||||||||||||
datetime.datetime(2020, 4, 12, 0, 0) | ||||||||||||||||||
|
||||||||||||||||||
>>> gauss_easter(2021) | ||||||||||||||||||
datetime.datetime(2021, 4, 4, 0, 0) | ||||||||||||||||||
""" | ||||||||||||||||||
a = year % 19 | ||||||||||||||||||
b = year % 4 | ||||||||||||||||||
c = year % 7 | ||||||||||||||||||
k = math.floor(year / 100) | ||||||||||||||||||
p = math.floor((13 + 8 * k) / 25) | ||||||||||||||||||
q = k / 4 | ||||||||||||||||||
M = (15 - p + k - q) % 30 | ||||||||||||||||||
N = (4 + k - q) % 7 | ||||||||||||||||||
d = (19 * a + M) % 30 | ||||||||||||||||||
e = (2 * b + 4 * c + 6 * d + N) % 7 | ||||||||||||||||||
|
||||||||||||||||||
if d == 29 and e == 6: | ||||||||||||||||||
return datetime(year, 4, 19) | ||||||||||||||||||
elif d == 28 and e == 6: | ||||||||||||||||||
return datetime(year, 4, 18) | ||||||||||||||||||
else: | ||||||||||||||||||
return datetime(year, 3, 22) + timedelta(days=int(d + e)) | ||||||||||||||||||
|
||||||||||||||||||
|
||||||||||||||||||
if __name__ == '__main__': | ||||||||||||||||||
print(f"Easter in 2023 will be {gauss_easter(2023)}") | ||||||||||||||||||
print(f"Easter in 2021 will be {gauss_easter(2021)}") | ||||||||||||||||||
print(f"Easter in 2010 was {gauss_easter(2010)}") | ||||||||||||||||||
print(f"Easter in 1994 was {gauss_easter(1994)}") | ||||||||||||||||||
print(f"Easter in 2000 was {gauss_easter(2000)}") | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Single letter variable names are old school and they force the reader to guess a lot to make sense of this algorithm.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be better now.