parent
b2b2291664
commit
aaa3d71665
|
@ -307,6 +307,48 @@ def get_us_holidays(input_date: date) -> list[Event]:
|
|||
]
|
||||
|
||||
|
||||
def critical_mass(start_date: date) -> list[Event]:
|
||||
"""
|
||||
Return a list of the next 12 dates of the last Friday of the month on or after a given date.
|
||||
|
||||
:param start_date: The date from which to start looking for last Fridays.
|
||||
:type start_date: date
|
||||
:return: List of next 12 last Fridays on or after the start_date.
|
||||
:rtype: List[date]
|
||||
"""
|
||||
events: list[Event] = []
|
||||
|
||||
# Set current month and year based on the start_date
|
||||
current_month = start_date.month
|
||||
current_year = start_date.year
|
||||
|
||||
for _ in range(12):
|
||||
# Calculate the last day of the current month
|
||||
if current_month == 12:
|
||||
last_day_of_month = date(current_year + 1, 1, 1) - timedelta(days=1)
|
||||
else:
|
||||
last_day_of_month = date(current_year, current_month + 1, 1) - timedelta(
|
||||
days=1
|
||||
)
|
||||
|
||||
# Find the last Friday of the current month
|
||||
last_friday = last_day_of_month
|
||||
while last_friday.weekday() != 4: # Monday is 0 and Sunday is 6
|
||||
last_friday -= timedelta(days=1)
|
||||
|
||||
# Include it in the list only if it's on or after the start_date
|
||||
if last_friday >= start_date:
|
||||
events.append(Event(name="critical_mass", date=last_friday))
|
||||
|
||||
# Move to the next month
|
||||
current_month += 1
|
||||
if current_month == 13:
|
||||
current_month = 1
|
||||
current_year += 1
|
||||
|
||||
return events
|
||||
|
||||
|
||||
def as_date(d: date | datetime) -> date:
|
||||
return d.date() if isinstance(d, datetime) else d
|
||||
|
||||
|
@ -478,6 +520,7 @@ def get_data(now: datetime) -> typing.Mapping[str, str | object]:
|
|||
"uk_financial_year_end": uk_financial_year_end(today),
|
||||
"xmas_last_posting_dates": xmas_last_posting_dates,
|
||||
"gwr_advance_tickets": find_gwr_advance_ticket_date(),
|
||||
"critical_mass": critical_mass(today),
|
||||
"rockets": thespacedevs.get_launches(rocket_dir, limit=40),
|
||||
}
|
||||
|
||||
|
@ -486,8 +529,7 @@ def get_data(now: datetime) -> typing.Mapping[str, str | object]:
|
|||
for key, value in reply.items():
|
||||
if key in skip:
|
||||
continue
|
||||
if "holiday" in key:
|
||||
assert isinstance(value, list)
|
||||
if isinstance(value, list):
|
||||
events += value
|
||||
else:
|
||||
assert isinstance(value, date)
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
"next_up_series": "Next Up documentary",
|
||||
"waste_schedule": "Waste schedule",
|
||||
"gwr_advance_tickets": "GWR advance tickets",
|
||||
"critical_mass": "Critical Mass",
|
||||
}
|
||||
%}
|
||||
|
||||
|
|
Loading…
Reference in a new issue