Easter Sunday calculation in Python

Script to calculate Easter Sunday.

from datetime import datetime
# Create service
@service
def update_easter_date():
    Year = datetime.today().year
    Special_Years = ['1954', '1981', '2049', '2076']
    SpecYr_Sub = 7
    A = Year % 19
    B = Year % 4
    C = Year % 7
    D = (19 * A + 24) % 30
    E = ((2 * B) + (4 * C) + (6 * D) + 5) % 7
    if Year in Special_Years:
        DateOfEaster = (22 + D + E) - SpecYr_Sub
    else:
        DateOfEaster = 22 + D + E
    if DateOfEaster > 31:
        variable.easter_sunday = datetime.strptime(str(datetime.today().year) + "-04-" + str(DateOfEaster - 31), "%Y-%m-%d")
    else:
        variable.easter_sunday = datetime.strptime(str(datetime.today().year) + "-03-" + str(DateOfEaster), "%Y-%m-%d")
1 Like