From 760ebc698027d6b0f10532a26fc6a5dbd2830a9c Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Tue, 3 Oct 2023 09:46:05 +0100 Subject: [PATCH] Add end of financial year: 5 April Closes: #3 --- agenda/__init__.py | 17 +++++++++++++++++ templates/index.html | 4 ++++ 2 files changed, 21 insertions(+) diff --git a/agenda/__init__.py b/agenda/__init__.py index 021fdba..d53174e 100644 --- a/agenda/__init__.py +++ b/agenda/__init__.py @@ -181,6 +181,22 @@ def next_economist(input_date: date) -> date: return next_thursday_date +def uk_financial_year_end(input_date: date) -> date: + """Next date of the end of the UK financial year, April 5th.""" + # Determine the year of the input date + year = input_date.year + + # Calculate the UK financial year end date (April 5th) + uk_financial_year_end = date(year, 4, 5) + + # If the input date is on or after the UK financial year end date, + # move to the next year + if input_date > uk_financial_year_end: + uk_financial_year_end = date(year + 1, 4, 5) + + return uk_financial_year_end + + def timedelta_display(delta: timedelta) -> str: """Format timedelta as a human readable string.""" total_seconds = int(delta.total_seconds()) @@ -259,6 +275,7 @@ def get_data() -> dict[str, str | object]: "us_clock_change": get_next_timezone_transition("America/New_York"), "mothers_day": next_uk_mothers_day(today), "fathers_day": next_uk_fathers_day(today), + "uk_financial_year_end": uk_financial_year_end(today), } return reply diff --git a/templates/index.html b/templates/index.html index c625c03..a0f4165 100644 --- a/templates/index.html +++ b/templates/index.html @@ -28,6 +28,10 @@ {{days(fathers_day)}} {{fathers_day.strftime("%a, %d %b %Y")}} +
  • End of financial year: + {{days(uk_financial_year_end)}} + {{uk_financial_year_end.strftime("%a, %d %b %Y")}}
  • +
  • UK bank holiday: {{days(bank_holiday["date"])}} {{bank_holiday["date"].strftime("%a, %d %b")}}