This commit is contained in:
薇薇安 2026-01-17 12:26:02 +08:00
parent bbae52c15f
commit 1d0f445ed7

View File

@ -30,18 +30,28 @@ def get_date_range(period: Optional[str] = None):
Returns:
(start_date, end_date) 元组格式为 'YYYY-MM-DD HH:MM:SS'
"""
# 使用当前时间作为结束时间,确保包含最新的单子
end_date = datetime.now()
if period == '1d':
start_date = end_date - timedelta(days=1)
# 最近1天从今天00:00:00到现在确保包含今天的所有单子
# 这样即使查询时已经是晚上,也能查到今天早上开的单子
start_date = end_date.replace(hour=0, minute=0, second=0, microsecond=0)
elif period == '7d':
start_date = end_date - timedelta(days=7)
# 最近7天从7天前00:00:00到现在
start_date = (end_date - timedelta(days=7)).replace(hour=0, minute=0, second=0, microsecond=0)
elif period == '30d':
start_date = end_date - timedelta(days=30)
# 最近30天从30天前00:00:00到现在
start_date = (end_date - timedelta(days=30)).replace(hour=0, minute=0, second=0, microsecond=0)
else:
return None, None
return start_date.strftime('%Y-%m-%d 00:00:00'), end_date.strftime('%Y-%m-%d %H:%M:%S')
# 开始时间使用计算出的开始日期的00:00:00
start_date_str = start_date.strftime('%Y-%m-%d %H:%M:%S')
# 结束时间:使用当前时间,确保包含最新单子
end_date_str = end_date.strftime('%Y-%m-%d %H:%M:%S')
return start_date_str, end_date_str
@router.get("")