fix: 时间显示统一使用本地时区(修复UTC显示问题)

之前 ISO 时间戳直接 slice(0, 16).replace('T', ' ') 显示 UTC 时间
(北京时间晚 8 小时),现统一用 formatDateTime 转本地时区。

新增 lib/format.ts:
- formatDateTime(iso) → YYYY-MM-DD HH:mm(本地时区)
- formatDate(iso) → YYYY-MM-DD(本地时区)
- formatDateTimeShort(iso) → MM-DD HH:mm(本地时区)

替换文件:
- versions/[id]/page.tsx (实际开始/截止)
- workspace/page.tsx (计划任务时间)
- BugDetailDrawer.tsx (基本信息+操作日志)
- TestCaseDetailDrawer.tsx (执行时间)
- DevTaskDetailDrawer.tsx (开始/提测时间)
- PlanDetailDrawer.tsx (计划/实际/完成时间)
- PlanTab.tsx (计划任务列表时间)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Script Generator
2026-06-16 14:15:20 +08:00
parent 6d2f6d8b9f
commit 4ac0dab4c5
8 changed files with 70 additions and 17 deletions

46
apps/web/lib/format.ts Normal file
View File

@@ -0,0 +1,46 @@
/**
* 时间格式化工具——统一处理 ISO 时间戳到本地时区显示
* 避免在 UI 直接 slice ISO 字符串导致显示 UTC 时间
*/
/**
* 格式化为 YYYY-MM-DD HH:mm本地时区
*/
export function formatDateTime(iso?: string | null): string {
if (!iso) return '-';
const d = new Date(iso);
if (isNaN(d.getTime())) return '-';
const yyyy = d.getFullYear();
const mm = String(d.getMonth() + 1).padStart(2, '0');
const dd = String(d.getDate()).padStart(2, '0');
const hh = String(d.getHours()).padStart(2, '0');
const mi = String(d.getMinutes()).padStart(2, '0');
return `${yyyy}-${mm}-${dd} ${hh}:${mi}`;
}
/**
* 格式化为 YYYY-MM-DD本地时区
*/
export function formatDate(iso?: string | null): string {
if (!iso) return '-';
const d = new Date(iso);
if (isNaN(d.getTime())) return '-';
const yyyy = d.getFullYear();
const mm = String(d.getMonth() + 1).padStart(2, '0');
const dd = String(d.getDate()).padStart(2, '0');
return `${yyyy}-${mm}-${dd}`;
}
/**
* 格式化为 MM-DD HH:mm紧凑版本地时区
*/
export function formatDateTimeShort(iso?: string | null): string {
if (!iso) return '-';
const d = new Date(iso);
if (isNaN(d.getTime())) return '-';
const mm = String(d.getMonth() + 1).padStart(2, '0');
const dd = String(d.getDate()).padStart(2, '0');
const hh = String(d.getHours()).padStart(2, '0');
const mi = String(d.getMinutes()).padStart(2, '0');
return `${mm}-${dd} ${hh}:${mi}`;
}