def round_down(dt, timeframe):
    """Round a datetime object down based on the given timeframe."""
    day = 1 if timeframe == "year" else dt.day
    hour = 0 if timeframe in ["year", "month", "week"] else dt.hour

    return dt.replace(day=day, hour=hour, minute=0, second=0, microsecond=0)