|
|
@@ -340,10 +340,36 @@ def get_range_data(symbol):
|
|
|
"""获取指定时间点前后各1800条数据(约1小时)"""
|
|
|
try:
|
|
|
# 获取中心时间戳参数
|
|
|
- center_time = request.args.get('timestamp') # ISO格式时间字符串
|
|
|
- if not center_time:
|
|
|
+ center_time_str = request.args.get('timestamp') # ISO格式时间字符串
|
|
|
+ if not center_time_str:
|
|
|
return jsonify({"error": "缺少timestamp参数"}), 400
|
|
|
|
|
|
+ # 解析ISO格式时间字符串
|
|
|
+ try:
|
|
|
+ center_time_str = center_time_str.strip()
|
|
|
+ # 检查并替换时间与时区之间的空格
|
|
|
+ if 'T' in center_time_str and ' ' in center_time_str:
|
|
|
+ parts = center_time_str.split(' ')
|
|
|
+ # 确认格式为 '...T... HH:MM'
|
|
|
+ if len(parts) == 2 and ':' in parts[1] and parts[1].replace(':', '').isdigit():
|
|
|
+ center_time_str = parts[0] + '+' + parts[1]
|
|
|
+
|
|
|
+ # 如果没有时区信息,默认添加东八区
|
|
|
+ if '+' not in center_time_str and '-' not in center_time_str and 'Z' not in center_time_str:
|
|
|
+ center_time_str += '+08:00'
|
|
|
+
|
|
|
+ # fromisoformat 可以处理带':'和不带':'的时区, e.g. +08:00 and +0800
|
|
|
+ center_dt = datetime.fromisoformat(center_time_str)
|
|
|
+
|
|
|
+ # 转换为UTC时间
|
|
|
+ center_dt = center_dt.astimezone(pytz.utc)
|
|
|
+
|
|
|
+ # 格式化为QuestDB接受的格式
|
|
|
+ center_time = center_dt.strftime('%Y-%m-%dT%H:%M:%S.%f')[:-3] + 'Z'
|
|
|
+ except Exception as e:
|
|
|
+ logger.error(f"时间格式解析失败: {str(e)}")
|
|
|
+ return jsonify({"error": f"无效的时间格式: {str(e)}"}), 400
|
|
|
+
|
|
|
conn = get_db_connection()
|
|
|
if not conn:
|
|
|
return jsonify({"error": "数据库连接失败"}), 500
|