Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/dateutil/easter.py: 26%
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1# -*- coding: utf-8 -*-
2"""
3This module offers a generic Easter computing method for any given year, using
4Western, Orthodox or Julian algorithms.
5"""
7import datetime
9__all__ = ["easter", "EASTER_JULIAN", "EASTER_ORTHODOX", "EASTER_WESTERN"]
11EASTER_JULIAN = 1
12EASTER_ORTHODOX = 2
13EASTER_WESTERN = 3
16def easter(year, method=EASTER_WESTERN):
17 """
18 This method was ported from the work done by GM Arts,
19 on top of the algorithm by Claus Tondering, which was
20 based in part on the algorithm of Ouding (1940), as
21 quoted in "Explanatory Supplement to the Astronomical
22 Almanac", P. Kenneth Seidelmann, editor.
24 This algorithm implements three different Easter
25 calculation methods:
27 1. Original calculation in Julian calendar, valid in
28 dates after 326 AD
29 2. Original method, with date converted to Gregorian
30 calendar, valid in years 1583 to 4099
31 3. Revised method, in Gregorian calendar, valid in
32 years 1583 to 4099 as well
34 These methods are represented by the constants:
36 * ``EASTER_JULIAN = 1``
37 * ``EASTER_ORTHODOX = 2``
38 * ``EASTER_WESTERN = 3``
40 The default method is method 3.
42 More about the algorithm may be found at:
44 `GM Arts: Easter Algorithms <http://www.gmarts.org/index.php?go=415>`_
46 and
48 `The Calendar FAQ: Easter <https://www.tondering.dk/claus/cal/easter.php>`_
50 """
52 if not (1 <= method <= 3):
53 raise ValueError("invalid method")
55 # g - Golden year - 1
56 # c - Century
57 # h - (23 - Epact) mod 30
58 # i - Number of days from March 21 to Paschal Full Moon
59 # j - Weekday for PFM (0=Sunday, etc)
60 # p - Number of days from March 21 to Sunday on or before PFM
61 # (-6 to 28 methods 1 & 3, to 56 for method 2)
62 # e - Extra days to add for method 2 (converting Julian
63 # date to Gregorian date)
65 y = year
66 g = y % 19
67 e = 0
68 if method < 3:
69 # Old method
70 i = (19*g + 15) % 30
71 j = (y + y//4 + i) % 7
72 if method == 2:
73 # Extra dates to convert Julian to Gregorian date
74 e = 10
75 if y > 1600:
76 e = e + y//100 - 16 - (y//100 - 16)//4
77 else:
78 # New method
79 c = y//100
80 h = (c - c//4 - (8*c + 13)//25 + 19*g + 15) % 30
81 i = h - (h//28)*(1 - (h//28)*(29//(h + 1))*((21 - g)//11))
82 j = (y + y//4 + i + 2 - c + c//4) % 7
84 # p can be from -6 to 56 corresponding to dates 22 March to 23 May
85 # (later dates apply to method 2, although 23 May never actually occurs)
86 p = i - j + e
87 d = 1 + (p + 27 + (p + 6)//40) % 31
88 m = 3 + (p + 26)//30
89 return datetime.date(int(y), int(m), int(d))