Add mothers' day and fathers' day

Closes: #8
This commit is contained in:
Edward Betts 2023-10-03 09:06:46 +01:00
parent c6861c7d51
commit a3f455d1de
2 changed files with 61 additions and 0 deletions

View file

@ -14,6 +14,7 @@ import holidays
import pandas import pandas
import pytz import pytz
import requests import requests
from dateutil.easter import easter
# from agenda import spacexdata # from agenda import spacexdata
@ -48,6 +49,55 @@ access_key = config.get("exchangerate", "access_key")
data_dir = config.get("data", "dir") 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: def get_next_timezone_transition(tz_name: str) -> datetime:
"""Datetime of the next time the clocks change.""" """Datetime of the next time the clocks change."""
tz = pytz.timezone(tz_name) tz = pytz.timezone(tz_name)
@ -188,6 +238,8 @@ def get_data() -> dict[str, str | object]:
"stock_markets": stock_markets(), "stock_markets": stock_markets(),
"uk_clock_change": get_next_timezone_transition("Europe/London"), "uk_clock_change": get_next_timezone_transition("Europe/London"),
"us_clock_change": get_next_timezone_transition("America/New_York"), "us_clock_change": get_next_timezone_transition("America/New_York"),
"mothers_day": next_uk_mothers_day(),
"fathers_day": next_uk_fathers_day(),
} }
return reply return reply

View file

@ -19,6 +19,15 @@
{{"{:.1f}".format(lockdown_days)}} days {{"{:.1f}".format(lockdown_days)}} days
({{"{:.2f}".format(lockdown_days / 7)}} weeks) so far</li> #} ({{"{:.2f}".format(lockdown_days / 7)}} weeks) so far</li> #}
<li>The Economist: {{days(next_economist)}} (Thursday)</li> <li>The Economist: {{days(next_economist)}} (Thursday)</li>
<li>Mothers' day:
{{days(mothers_day)}}
{{mothers_day.strftime("%a, %d %b %Y")}}</li>
<li>Fathers' day:
{{days(fathers_day)}}
{{fathers_day.strftime("%a, %d %b %Y")}}</li>
<li>UK bank holiday: <li>UK bank holiday:
{{days(bank_holiday["date"])}} {{days(bank_holiday["date"])}}
{{bank_holiday["date"].strftime("%a, %d %b")}} {{bank_holiday["date"].strftime("%a, %d %b")}}