Calculating the date of Easter Sunday

If anyone has ever tried to do this, you know it can be a pain in the ass. Here’s a template that will return true when today is Easter Sunday

{# calculation algorithm from http://www.oremus.org/liturgy/etc/ktf/app/easter.html #}
{%- set now = now() -%}
{%- set year = now.year -%}
{%- set golden_number = (year % 19) + 1 -%}
{%- set solar_correction = ((year - 1600) / 100) | int - ((year - 1600) / 400) | int -%}
{%- set lunar_correction = ((((year - 1400) / 100) * 8) / 25) |int -%}
{%- set paschal_full_moon = (3 - (11 * golden_number) + solar_correction - lunar_correction) % 30 -%}
{%- if (paschal_full_moon == 29) or ((paschal_full_moon == 28) and (golden_number > 11)) -%}
{%- set paschal_full_moon = paschal_full_moon - 1 -%}
{%- endif -%}
{%- set dominical_number = (year + (year / 4) | int - (year / 100) | int + (year / 400) | int) % 7 -%}
{%- set first_sunday = (8 - dominical_number) % 7 -%}
{%- set days_between_easter_and_pfm = (4 - dominical_number - paschal_full_moon) % 7 + 1 -%}
{%- set easter_after_march21 = paschal_full_moon + days_between_easter_and_pfm -%}
{%- set easter = now.replace(month=3, day=21) + timedelta(days=easter_after_march21) -%}
{{ (now.month == easter.month) and (now.day == easter.day) }}
6 Likes

:exploding_head:

I wonder why they made it so complicated compared to his birthday.

Is this for Western or Orthodox Easter? :upside_down_face:

2 Likes

Isn’t this possible with GitHub - dr-prodigy/python-holidays: Generate and work with holidays in Python which is installed by the workday integration?

Maybe? But how do you do it? I know I can tell that Easter would not be a workday with that integration. But how would I know it was actually “Easter”?

Anyway, I spent 30 minutes working on that, so don’t take this away from me :sweat_smile:

1 Like

Not sure you can do it with the workday sensor, but I feel the underlying library should be able to do it.

Not to burst your bubble, but Petro built it into his easy time macros in April…

1 Like

And here

for easy time macros, just install it and then it’s simply

{% from 'easy_time.jinja' import easter %}
{{ easter() }}
2 Likes