fix: 上次同步时间转为本地时区显示,修正时区混淆问题
AppConfig 存储 UTC 时间,模板直接输出导致用户在上海(UTC+8)看到错误时刻。 新增 get_last_sync_at_local() 转本地时区,logs_view 采用本地时间显示。
This commit is contained in:
@@ -1020,7 +1020,7 @@ def logs_view():
|
|||||||
"start_time": f_start, "end_time": f_end,
|
"start_time": f_start, "end_time": f_end,
|
||||||
},
|
},
|
||||||
cfg=cfg,
|
cfg=cfg,
|
||||||
last_sync=log_storage.get_last_sync_at(),
|
last_sync=log_storage.get_last_sync_at_local(),
|
||||||
last_sync_path=log_storage.get_last_sync_path(),
|
last_sync_path=log_storage.get_last_sync_path(),
|
||||||
use_persistent=use_persistent,
|
use_persistent=use_persistent,
|
||||||
format_bytes=log_parser.format_bytes,
|
format_bytes=log_parser.format_bytes,
|
||||||
|
|||||||
@@ -797,6 +797,23 @@ def get_last_sync_path() -> str | None:
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def get_last_sync_at_local() -> str | None:
|
||||||
|
"""Return the last-sync timestamp formatted in local time (not UTC).
|
||||||
|
|
||||||
|
:class:`~app.AppConfig` stores the sync time as an ISO-8601 UTC string
|
||||||
|
(e.g. ``2026-07-16T07:43:36Z``). This converts it to the system's local
|
||||||
|
timezone so the UI shows a human-friendly time to the operator.
|
||||||
|
"""
|
||||||
|
ts = get_last_sync_at()
|
||||||
|
if not ts:
|
||||||
|
return None
|
||||||
|
try:
|
||||||
|
dt = datetime.fromisoformat(ts.replace("Z", "+00:00"))
|
||||||
|
return dt.astimezone().strftime("%Y-%m-%d %H:%M:%S")
|
||||||
|
except Exception:
|
||||||
|
return ts
|
||||||
|
|
||||||
|
|
||||||
def import_full_history(
|
def import_full_history(
|
||||||
path: str,
|
path: str,
|
||||||
instance_id: int = 0,
|
instance_id: int = 0,
|
||||||
|
|||||||
Reference in New Issue
Block a user