diff --git a/main.py b/main.py index e5981e8..1be06c5 100644 --- a/main.py +++ b/main.py @@ -36,8 +36,13 @@ def mothering_sunday(year: int) -> datetime: # pylint: disable=too-many-locals easter_sunday = datetime(year, month, day) # Calculate Mothering Sunday - final_day = easter_sunday - timedelta(weeks=3) - return final_day + mothers_day = easter_sunday - timedelta(weeks=3) + + # Ensure Mothering Sunday falls on a Sunday + if mothers_day.weekday() != 6: # 6 corresponds to Sunday + mothers_day += timedelta(days=6 - mothers_day.weekday()) + + return mothers_day def generate_ical() -> None: @@ -48,9 +53,7 @@ def generate_ical() -> None: for year in range(datetime.now().year, datetime.now().year + 10): date = mothering_sunday(year) - # Ensure Mothering Sunday falls on a Sunday - if date.weekday() != 6: # 6 corresponds to Sunday - date += timedelta(days=6 - date.weekday()) + event = Event() event.name = "Mothering Sunday" event.begin = date