34 lines
1 KiB
Python
34 lines
1 KiB
Python
"""Calculate the date for carnival."""
|
|
|
|
from datetime import date, timedelta
|
|
|
|
from dateutil.easter import easter
|
|
|
|
from .types import Event
|
|
|
|
|
|
def rio_carnival_events(start_date: date, end_date: date) -> list[Event]:
|
|
"""List of events for Rio Carnival for each year between start_date and end_date."""
|
|
events = []
|
|
for year in range(start_date.year, end_date.year + 1):
|
|
easter_date = easter(year)
|
|
carnival_start = easter_date - timedelta(days=51)
|
|
carnival_end = easter_date - timedelta(days=46)
|
|
|
|
# Only include the carnival if it falls within the specified date range
|
|
if (
|
|
start_date <= carnival_start <= end_date
|
|
or start_date <= carnival_end <= end_date
|
|
):
|
|
events.append(
|
|
Event(
|
|
name="carnival",
|
|
title="Rio Carnival",
|
|
date=carnival_start,
|
|
end_date=carnival_end,
|
|
url="https://en.wikipedia.org/wiki/Rio_Carnival",
|
|
)
|
|
)
|
|
|
|
return events
|