annotate CSP2/CSP2_env/env-d9b9114564458d9d-741b3de822f2aaca6c6caa4325c4afce/lib/python3.8/site-packages/dateutil/easter.py @ 68:5028fdace37b

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