Skip to content

Instantly share code, notes, and snippets.

@dankkom
Created January 8, 2023 20:51
Show Gist options
  • Select an option

  • Save dankkom/ced05ff691065dd33b535966252526ff to your computer and use it in GitHub Desktop.

Select an option

Save dankkom/ced05ff691065dd33b535966252526ff to your computer and use it in GitHub Desktop.
Calculate Easter and Carnaval dates
import datetime as dt
def carnaval_date(year: int) -> tuple[dt.date]:
# https://www.vivaolinux.com.br/script/Calcular-a-data-do-Carnaval-e-da-Pascoa
x = 24
y = 5
a = year % 19
b = year % 4
c = year % 7
d = (19 * a + x) % 30
e = (2 * b + 4 * c + 6 * d + y) % 7
if (d + e) > 9:
day = d + e - 9
pascoa = dt.date(year, 4, day)
month = 4
data1 = dt.date(year, month, day)
# O carnaval sera a subtração de 47 dias da data da pascoa
carnaval = dt.date.fromordinal(data1.toordinal() - 47)
else:
day = d + e + 22
pascoa = dt.date(year, 3, day)
month = 3
data1 = dt.date(year, month, day)
carnaval = dt.date.fromordinal(data1.toordinal() - 47)
return carnaval, pascoa
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment