sansan0/TrendRadar · error · InvalidParameterError
不能查询未来的日期: {date.strftime('%Y-%m-%d')}
Error message
不能查询未来的日期: {date.strftime('%Y-%m-%d')} What it means
Thrown by DateParser.validate_date_not_future when the parsed date's calendar day is strictly after today. The underlying dataset is historical news, so future dates can never return data and are rejected up front.
Source
Thrown at mcp_server/utils/date_parser.py:306
Examples:
>>> DateParser.format_date_folder(datetime(2025, 10, 11))
'2025-10-11'
"""
return date.strftime("%Y-%m-%d")
@staticmethod
def validate_date_not_future(date: datetime) -> None:
"""
验证日期不在未来
Args:
date: 待验证的日期
Raises:
InvalidParameterError: 日期在未来
"""
if date.date() > datetime.now().date():
raise InvalidParameterError(
f"不能查询未来的日期: {date.strftime('%Y-%m-%d')}",
suggestion="请使用今天或过去的日期"
)
@staticmethod
def validate_date_not_too_old(date: datetime, max_days: int = 365) -> None:
"""
验证日期不太久远
Args:
date: 待验证的日期
max_days: 最大天数
Raises:
InvalidParameterError: 日期太久远
"""
days_ago = (datetime.now().date() - date.date()).days
if days_ago > max_days:View on GitHub (pinned to 8ee26026ba)
Solutions
- Use today or a past date
- Fix timezone handling: derive dates in the server's local timezone or pass explicit absolute dates
- Clamp parsed dates: if date > today, use today
Example fix
# before DateParser.validate_date_not_future(datetime(2026, 1, 1)) # raises # after q = min(datetime.now(), datetime(2026, 1, 1)) DateParser.validate_date_not_future(q)
Defensive patterns
Strategy: validation
Validate before calling
from datetime import datetime
def clamp_to_present(d: datetime) -> datetime:
return min(d, datetime.now()) Type guard
def is_not_future(d) -> bool:
from datetime import datetime
return d.date() <= datetime.now().date() Try / catch
try:
DateParser.validate_date_not_future(d)
except InvalidParameterError as e:
if "未来的日期" in str(e):
d = datetime.now() # clamp to today and continue
else:
raise Prevention
- Generate all query dates in the server's timezone
- Clamp caller-supplied dates to today before validation
- Watch year typos (off-by-one in the year component)
When it happens
Trigger: Any flow that parses a date then calls validate_date_not_future with tomorrow-or-later: explicit future ISO dates, or relative math that overshoots (none built in, but caller-computed datetimes do); note equality with today is allowed.
Common situations: Timezone skew — a client ahead of server-local time passing 'today' that lands tomorrow server-side; typos in the year (2026 vs 2025); scheduled/future-dated content being queried against a historical index.
Related errors
- INVALID_PARAMETER
- 日期太久远: {date.strftime('%Y-%m-%d')} ({days_ago}天前)
- 日期表达式不能为空
- 日期格式错误: {date_str}
- 日期格式错误: {stripped}
AI-assisted analysis of sansan0/TrendRadar@8ee26026ba (2026-08-15).
Data as JSON: /api/errors/9ac35f1ffa39181a.
Report an issue: GitHub.