diff --git a/agenda/__init__.py b/agenda/__init__.py index bdf2b5e..d4c025e 100644 --- a/agenda/__init__.py +++ b/agenda/__init__.py @@ -214,14 +214,31 @@ def stock_markets() -> list[str]: return reply -def get_us_holidays(input_date: date) -> list[Event]: +def get_us_holidays(start_date: date, end_date: date) -> list[Event]: """Date and name of next US holiday.""" - hols = holidays.UnitedStates(years=[input_date.year, input_date.year + 1]) - return [ - Event(name="us_holiday", date=hol_date, title=title) - for hol_date, title in sorted(hols.items()) - if hol_date >= input_date - ] + found: list[Event] = [] + for year in range(start_date.year, end_date.year + 1): + hols = holidays.UnitedStates(years=year) + found += [ + Event(name="us_holiday", date=hol_date, title=title) + for hol_date, title in hols.items() + if start_date < hol_date < end_date + ] + + extra = [] + for e in found: + if e.title != "Thanksgiving": + continue + extra += [ + Event( + name="us_holiday", date=e.date + timedelta(days=1), title="Black Friday" + ), + Event( + name="us_holiday", date=e.date + timedelta(days=4), title="Cyber Monday" + ), + ] + + return found + extra def critical_mass(start_date: date, limit: int = 12) -> list[Event]: @@ -321,7 +338,7 @@ async def get_data(now: datetime) -> typing.Mapping[str, str | object]: "gbpusd": gbpusd, "next_economist": economist.next_pub_date(today), "bank_holiday": bank_holiday, - "us_holiday": get_us_holidays(today), + "us_holiday": get_us_holidays(last_year, next_year), "next_us_presidential_election": next_us_presidential_election, "stock_markets": stock_markets(), "uk_clock_change": timezone_transition(