Move the Sunday check into the calculation function
This commit is contained in:
parent
04baff10a6
commit
9652429839
13
main.py
13
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
|
||||
|
|
Loading…
Reference in a new issue