MCPcopy Index your code
hub / github.com/TheAlgorithms/Python / gauss_easter

Function gauss_easter

other/gauss_easter.py:9–54  ·  view source on GitHub ↗

Calculation Gregorian easter date for given year >>> gauss_easter(2007) datetime.datetime(2007, 4, 8, 0, 0, tzinfo=datetime.timezone.utc) >>> gauss_easter(2008) datetime.datetime(2008, 3, 23, 0, 0, tzinfo=datetime.timezone.utc) >>> gauss_easter(2020) datetime.datetime

(year: int)

Source from the content-addressed store, hash-verified

7
8
9def gauss_easter(year: int) -> datetime:
10 """
11 Calculation Gregorian easter date for given year
12
13 >>> gauss_easter(2007)
14 datetime.datetime(2007, 4, 8, 0, 0, tzinfo=datetime.timezone.utc)
15
16 >>> gauss_easter(2008)
17 datetime.datetime(2008, 3, 23, 0, 0, tzinfo=datetime.timezone.utc)
18
19 >>> gauss_easter(2020)
20 datetime.datetime(2020, 4, 12, 0, 0, tzinfo=datetime.timezone.utc)
21
22 >>> gauss_easter(2021)
23 datetime.datetime(2021, 4, 4, 0, 0, tzinfo=datetime.timezone.utc)
24 """
25 metonic_cycle = year % 19
26 julian_leap_year = year % 4
27 non_leap_year = year % 7
28 leap_day_inhibits = math.floor(year / 100)
29 lunar_orbit_correction = math.floor((13 + 8 * leap_day_inhibits) / 25)
30 leap_day_reinstall_number = leap_day_inhibits / 4
31 secular_moon_shift = (
32 15 - lunar_orbit_correction + leap_day_inhibits - leap_day_reinstall_number
33 ) % 30
34 century_starting_point = (4 + leap_day_inhibits - leap_day_reinstall_number) % 7
35
36 # days to be added to March 21
37 days_to_add = (19 * metonic_cycle + secular_moon_shift) % 30
38
39 # PHM -> Paschal Full Moon
40 days_from_phm_to_sunday = (
41 2 * julian_leap_year
42 + 4 * non_leap_year
43 + 6 * days_to_add
44 + century_starting_point
45 ) % 7
46
47 if days_to_add == 29 and days_from_phm_to_sunday == 6:
48 return datetime(year, 4, 19, tzinfo=UTC)
49 elif days_to_add == 28 and days_from_phm_to_sunday == 6:
50 return datetime(year, 4, 18, tzinfo=UTC)
51 else:
52 return datetime(year, 3, 22, tzinfo=UTC) + timedelta(
53 days=int(days_to_add + days_from_phm_to_sunday)
54 )
55
56
57if __name__ == "__main__":

Callers 1

gauss_easter.pyFile · 0.85

Calls 1

floorMethod · 0.80

Tested by

no test coverage detected