diff --git a/agenda/__init__.py b/agenda/__init__.py index e12de12..74770dd 100644 --- a/agenda/__init__.py +++ b/agenda/__init__.py @@ -14,6 +14,7 @@ import holidays import pandas import pytz import requests +from dateutil.easter import easter # from agenda import spacexdata @@ -48,6 +49,55 @@ access_key = config.get("exchangerate", "access_key") data_dir = config.get("data", "dir") +def next_uk_mothers_day() -> date: + """Calculate the date of the next UK Mother's Day from the current date.""" + current_year = date.today().year + + easter_date = easter(current_year) + + # Calculate the date of Mother's Day, which is the fourth Sunday of Lent + mothers_day = easter_date + timedelta(weeks=3) + + # Check if Mother's Day has already passed this year + today = date.today() + if today > mothers_day: + # If it has passed, calculate for the next year + current_year += 1 + easter_date = easter(current_year) + mothers_day = easter_date + timedelta(weeks=3) + + return mothers_day + + +def next_uk_fathers_day() -> date: + """Calculate the date of the next UK Father's Day from the current date.""" + # Get the current date + today = date.today() + + # Calculate the day of the week for the current date (0 = Monday, 6 = Sunday) + current_day_of_week = today.weekday() + + # Calculate the number of days until the next Sunday + days_until_sunday = (6 - current_day_of_week) % 7 + + # Calculate the date of the next Sunday + next_sunday = today + timedelta(days=days_until_sunday) + + # Calculate the date of Father's Day, which is the third Sunday of June + fathers_day = date(next_sunday.year, 6, 1) + timedelta( + weeks=2, days=next_sunday.weekday() + ) + + # Check if Father's Day has already passed this year + if today > fathers_day: + # If it has passed, calculate for the next year + fathers_day = date(fathers_day.year + 1, 6, 1) + timedelta( + weeks=2, days=next_sunday.weekday() + ) + + return fathers_day + + def get_next_timezone_transition(tz_name: str) -> datetime: """Datetime of the next time the clocks change.""" tz = pytz.timezone(tz_name) @@ -188,6 +238,8 @@ def get_data() -> dict[str, str | object]: "stock_markets": stock_markets(), "uk_clock_change": get_next_timezone_transition("Europe/London"), "us_clock_change": get_next_timezone_transition("America/New_York"), + "mothers_day": next_uk_mothers_day(), + "fathers_day": next_uk_fathers_day(), } return reply diff --git a/templates/index.html b/templates/index.html index 0b99c5d..c625c03 100644 --- a/templates/index.html +++ b/templates/index.html @@ -19,6 +19,15 @@ {{"{:.1f}".format(lockdown_days)}} days ({{"{:.2f}".format(lockdown_days / 7)}} weeks) so far #}
  • The Economist: {{days(next_economist)}} (Thursday)
  • + +
  • Mothers' day: + {{days(mothers_day)}} + {{mothers_day.strftime("%a, %d %b %Y")}}
  • + +
  • Fathers' day: + {{days(fathers_day)}} + {{fathers_day.strftime("%a, %d %b %Y")}}
  • +
  • UK bank holiday: {{days(bank_holiday["date"])}} {{bank_holiday["date"].strftime("%a, %d %b")}}