Compare commits

..

No commits in common. "cc47762e9da6681ad9fb3a41aa10d5470efdf8ee" and "4f2b9f7fae73004b3dc0417b8bb4b0eddd4b9250" have entirely different histories.

View file

@ -107,16 +107,12 @@ def next_uk_fathers_day(input_date: date) -> date:
return fathers_day
def timezone_transition(
start_dt: datetime, end_dt: datetime, key: str, tz_name: str
) -> list[Event]:
"""Clocks changes."""
def get_next_timezone_transition(from_dt: datetime, tz_name: str) -> date:
"""Datetime of the next time the clocks change."""
tz = pytz.timezone(tz_name)
return [
Event(name=key, date=pytz.utc.localize(t).astimezone(tz))
for t in tz._utc_transition_times # type: ignore
if start_dt <= t <= end_dt
]
dt = next(t for t in tz._utc_transition_times if t > from_dt)
return typing.cast(date, dt.date())
async def get_next_bank_holiday(input_date: date) -> list[Event]:
@ -124,7 +120,7 @@ async def get_next_bank_holiday(input_date: date) -> list[Event]:
url = "https://www.gov.uk/bank-holidays.json"
filename = os.path.join(data_dir, "bank-holidays.json")
mtime = os.path.getmtime(filename)
if (unixtime() - mtime) > 60 * 60 * 6: # six hours
if (unixtime() - mtime) > 3600: # one hour
async with httpx.AsyncClient() as client:
r = await client.get(url)
open(filename, "w").write(r.text)
@ -301,9 +297,6 @@ async def get_data(now: datetime) -> typing.Mapping[str, str | object]:
last_year = today - timedelta(days=365)
next_year = today + timedelta(days=365)
minus_365 = now - timedelta(days=365)
plus_365 = now + timedelta(days=365)
(
gbpusd,
gwr_advance_tickets,
@ -324,12 +317,8 @@ async def get_data(now: datetime) -> typing.Mapping[str, str | object]:
"us_holiday": get_us_holidays(today),
"next_us_presidential_election": next_us_presidential_election,
"stock_markets": stock_markets(),
"uk_clock_change": timezone_transition(
minus_365, plus_365, "uk_clock_change", "Europe/London"
),
"us_clock_change": timezone_transition(
minus_365, plus_365, "us_clock_change", "America/New_York"
),
"uk_clock_change": get_next_timezone_transition(now, "Europe/London"),
"us_clock_change": get_next_timezone_transition(now, "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),