之前 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>
47 lines
1.5 KiB
TypeScript
47 lines
1.5 KiB
TypeScript
/**
|
||
* 时间格式化工具——统一处理 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}`;
|
||
}
|