feat(normalizer): Easter computus
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
21
tools/import-normalizer/dates.py
Normal file
21
tools/import-normalizer/dates.py
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
"""Tolerant historical date parsing for the family archive."""
|
||||||
|
import datetime
|
||||||
|
|
||||||
|
|
||||||
|
def easter(year: int) -> datetime.date:
|
||||||
|
"""Easter Sunday (Gregorian) via the Anonymous Gregorian / Butcher 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
|
||||||
|
month = (h + l - 7 * m + 114) // 31
|
||||||
|
day = ((h + l - 7 * m + 114) % 31) + 1
|
||||||
|
return datetime.date(year, month, day)
|
||||||
9
tools/import-normalizer/tests/test_dates.py
Normal file
9
tools/import-normalizer/tests/test_dates.py
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
import datetime
|
||||||
|
import dates
|
||||||
|
|
||||||
|
def test_easter_known_years():
|
||||||
|
# Anonymous Gregorian algorithm — verified against published tables
|
||||||
|
assert dates.easter(2024) == datetime.date(2024, 3, 31)
|
||||||
|
assert dates.easter(2000) == datetime.date(2000, 4, 23)
|
||||||
|
assert dates.easter(1922) == datetime.date(1922, 4, 16)
|
||||||
|
assert dates.easter(1888) == datetime.date(1888, 4, 1)
|
||||||
Reference in New Issue
Block a user