Make more functions take a date argument.
This commit is contained in:
		
							parent
							
								
									c702dcf7e5
								
							
						
					
					
						commit
						f19a855532
					
				| 
						 | 
					@ -98,15 +98,15 @@ def next_uk_fathers_day(input_date: date) -> date:
 | 
				
			||||||
    return fathers_day
 | 
					    return fathers_day
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def get_next_timezone_transition(tz_name: str) -> date:
 | 
					def get_next_timezone_transition(from_dt: datetime, tz_name: str) -> date:
 | 
				
			||||||
    """Datetime of the next time the clocks change."""
 | 
					    """Datetime of the next time the clocks change."""
 | 
				
			||||||
    tz = pytz.timezone(tz_name)
 | 
					    tz = pytz.timezone(tz_name)
 | 
				
			||||||
    dt = next(t for t in tz._utc_transition_times if t > now)
 | 
					    dt = next(t for t in tz._utc_transition_times if t > from_dt)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return typing.cast(date, dt.date())
 | 
					    return typing.cast(date, dt.date())
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def get_next_bank_holiday() -> dict[str, date | str]:
 | 
					def get_next_bank_holiday(input_date: date) -> dict[str, date | str]:
 | 
				
			||||||
    """Date and name of the next UK bank holiday."""
 | 
					    """Date and name of the next UK bank holiday."""
 | 
				
			||||||
    url = "https://www.gov.uk/bank-holidays.json"
 | 
					    url = "https://www.gov.uk/bank-holidays.json"
 | 
				
			||||||
    filename = os.path.join(data_dir, "bank-holidays.json")
 | 
					    filename = os.path.join(data_dir, "bank-holidays.json")
 | 
				
			||||||
| 
						 | 
					@ -119,7 +119,7 @@ def get_next_bank_holiday() -> dict[str, date | str]:
 | 
				
			||||||
    next_holiday = None
 | 
					    next_holiday = None
 | 
				
			||||||
    for event in events:
 | 
					    for event in events:
 | 
				
			||||||
        event_date = datetime.strptime(event["date"], "%Y-%m-%d").date()
 | 
					        event_date = datetime.strptime(event["date"], "%Y-%m-%d").date()
 | 
				
			||||||
        if event_date < today:
 | 
					        if event_date < input_date:
 | 
				
			||||||
            continue
 | 
					            continue
 | 
				
			||||||
        next_holiday = {"date": event_date, "title": event["title"]}
 | 
					        next_holiday = {"date": event_date, "title": event["title"]}
 | 
				
			||||||
        break
 | 
					        break
 | 
				
			||||||
| 
						 | 
					@ -260,10 +260,10 @@ def stock_markets() -> list[str]:
 | 
				
			||||||
    return reply
 | 
					    return reply
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def get_us_holiday() -> dict[str, date | str]:
 | 
					def get_us_holiday(input_date: date) -> dict[str, date | str]:
 | 
				
			||||||
    """Date and name of next US holiday."""
 | 
					    """Date and name of next US holiday."""
 | 
				
			||||||
    hols = holidays.UnitedStates(years=[today.year, today.year + 1])
 | 
					    hols = holidays.UnitedStates(years=[input_date.year, input_date.year + 1])
 | 
				
			||||||
    next_hol = next(x for x in sorted(hols.items()) if x[0] >= today)
 | 
					    next_hol = next(x for x in sorted(hols.items()) if x[0] >= input_date)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return {"date": next_hol[0], "title": next_hol[1]}
 | 
					    return {"date": next_hol[0], "title": next_hol[1]}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -276,13 +276,13 @@ def get_data() -> dict[str, str | object]:
 | 
				
			||||||
        "now": now,
 | 
					        "now": now,
 | 
				
			||||||
        "gbpusd": get_gbpusd(),
 | 
					        "gbpusd": get_gbpusd(),
 | 
				
			||||||
        "next_economist": next_economist(today),
 | 
					        "next_economist": next_economist(today),
 | 
				
			||||||
        "bank_holiday": get_next_bank_holiday(),
 | 
					        "bank_holiday": get_next_bank_holiday(today),
 | 
				
			||||||
        "us_holiday": get_us_holiday(),
 | 
					        "us_holiday": get_us_holiday(today),
 | 
				
			||||||
        # "next_uk_general_election": next_uk_general_election,
 | 
					        # "next_uk_general_election": next_uk_general_election,
 | 
				
			||||||
        "next_us_presidential_election": next_us_presidential_election,
 | 
					        "next_us_presidential_election": next_us_presidential_election,
 | 
				
			||||||
        "stock_markets": stock_markets(),
 | 
					        "stock_markets": stock_markets(),
 | 
				
			||||||
        "uk_clock_change": get_next_timezone_transition("Europe/London"),
 | 
					        "uk_clock_change": get_next_timezone_transition(now, "Europe/London"),
 | 
				
			||||||
        "us_clock_change": get_next_timezone_transition("America/New_York"),
 | 
					        "us_clock_change": get_next_timezone_transition(now, "America/New_York"),
 | 
				
			||||||
        "mothers_day": next_uk_mothers_day(today),
 | 
					        "mothers_day": next_uk_mothers_day(today),
 | 
				
			||||||
        "fathers_day": next_uk_fathers_day(today),
 | 
					        "fathers_day": next_uk_fathers_day(today),
 | 
				
			||||||
        "uk_financial_year_end": uk_financial_year_end(today),
 | 
					        "uk_financial_year_end": uk_financial_year_end(today),
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue