Compare commits

..

No commits in common. "14133f591c2d35389f7ba7fbaf305c2d61db2be6" and "a3f455d1de04d63374e229fde6023ba65b195bb3" have entirely different histories.

View file

@ -49,9 +49,9 @@ access_key = config.get("exchangerate", "access_key")
data_dir = config.get("data", "dir") data_dir = config.get("data", "dir")
def next_uk_mothers_day(input_date: date) -> date: def next_uk_mothers_day() -> date:
"""Calculate the date of the next UK Mother's Day from the current date.""" """Calculate the date of the next UK Mother's Day from the current date."""
current_year = input_date.year current_year = date.today().year
easter_date = easter(current_year) easter_date = easter(current_year)
@ -59,19 +59,23 @@ def next_uk_mothers_day(input_date: date) -> date:
mothers_day = easter_date + timedelta(weeks=3) mothers_day = easter_date + timedelta(weeks=3)
# Check if Mother's Day has already passed this year # Check if Mother's Day has already passed this year
if input_date > mothers_day: today = date.today()
if today > mothers_day:
# If it has passed, calculate for the next year # If it has passed, calculate for the next year
easter_date = easter(current_year + 1) current_year += 1
easter_date = easter(current_year)
mothers_day = easter_date + timedelta(weeks=3) mothers_day = easter_date + timedelta(weeks=3)
return mothers_day return mothers_day
def next_uk_fathers_day(input_date: date) -> date: def next_uk_fathers_day() -> date:
"""Calculate the date of the next UK Father's Day from the current date.""" """Calculate the date of the next UK Father's Day from the current date."""
# Get the current date # Get the current date
today = date.today()
# Calculate the day of the week for the current date (0 = Monday, 6 = Sunday) # Calculate the day of the week for the current date (0 = Monday, 6 = Sunday)
current_day_of_week = input_date.weekday() current_day_of_week = today.weekday()
# Calculate the number of days until the next Sunday # Calculate the number of days until the next Sunday
days_until_sunday = (6 - current_day_of_week) % 7 days_until_sunday = (6 - current_day_of_week) % 7
@ -152,33 +156,10 @@ def get_gbpusd() -> Decimal:
return typing.cast(Decimal, 1 / data["quotes"]["USDGBP"]) return typing.cast(Decimal, 1 / data["quotes"]["USDGBP"])
def next_economist(input_date: date) -> date: def next_economist() -> date:
"""Next date that the Economist is published.""" """Next date that the Economist is published."""
# Define the publication day (Thursday) and the day of the week of the input date # TODO: handle the Christmas double issue correctly
publication_day = 3 # Thursday (0 - Monday, 1 - Tuesday, ..., 6 - Sunday) return today + timedelta((3 - today.weekday()) % 7)
current_day_of_week = input_date.weekday()
current_week_number = today.isocalendar().week
# Define the list of weeks when The Economist is not published
non_publication_weeks = [26, 56]
# Check if the input date is a publication day (Thursday)
if (
current_day_of_week == publication_day
and current_week_number not in non_publication_weeks
):
return input_date
# Calculate the date for the next Thursday after the input date
days_until_next_thursday = (publication_day - current_day_of_week + 7) % 7
next_thursday_date = input_date + timedelta(days=days_until_next_thursday)
# Check if the next Thursday falls in a non-publication week
while next_thursday_date.isocalendar().week in non_publication_weeks:
# If it does, add 7 days to find the next Thursday
next_thursday_date += timedelta(days=7)
return next_thursday_date
def timedelta_display(delta: timedelta) -> str: def timedelta_display(delta: timedelta) -> str:
@ -248,7 +229,7 @@ def get_data() -> dict[str, str | object]:
reply = { reply = {
"now": now, "now": now,
"gbpusd": get_gbpusd(), "gbpusd": get_gbpusd(),
"next_economist": next_economist(today), "next_economist": next_economist(),
"bank_holiday": get_next_bank_holiday(), "bank_holiday": get_next_bank_holiday(),
"us_holiday": get_us_holiday(), "us_holiday": get_us_holiday(),
"next_uk_general_election": next_uk_general_election, "next_uk_general_election": next_uk_general_election,
@ -257,8 +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(today), "mothers_day": next_uk_mothers_day(),
"fathers_day": next_uk_fathers_day(today), "fathers_day": next_uk_fathers_day(),
} }
return reply return reply