refactor: 使用管理员日期时间格式化器更新请求和完成时间的显示
This commit is contained in:
36
src/lib/admin-datetime.ts
Normal file
36
src/lib/admin-datetime.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import type { AdminApiLocale } from "@/lib/admin-locale";
|
||||
|
||||
function pad2(n: number): string {
|
||||
return String(n).padStart(2, "0");
|
||||
}
|
||||
|
||||
/**
|
||||
* 将接口返回的 ISO 时间串格式化为 **浏览器本地时区** 下的
|
||||
* `YYYY-MM-DD HH:mm:ss`(与《01-界面文档》时间展示习惯一致,且列宽稳定)。
|
||||
*
|
||||
* 不使用 `Intl` 拼接 `GMT+8` 等时区后缀,避免在表格里挤出过长、重叠的字符串。
|
||||
*
|
||||
* `@param options.locale` 与调用方保持一致,便于日后按界面语言微调格式。
|
||||
*/
|
||||
export function formatAdminInstant(
|
||||
iso: string | null | undefined,
|
||||
_options: {
|
||||
locale: AdminApiLocale;
|
||||
},
|
||||
): string {
|
||||
if (iso == null || iso === "") {
|
||||
return "—";
|
||||
}
|
||||
const ms = Date.parse(iso);
|
||||
if (Number.isNaN(ms)) {
|
||||
return "—";
|
||||
}
|
||||
const date = new Date(ms);
|
||||
const y = date.getFullYear();
|
||||
const m = pad2(date.getMonth() + 1);
|
||||
const d = pad2(date.getDate());
|
||||
const h = pad2(date.getHours());
|
||||
const min = pad2(date.getMinutes());
|
||||
const s = pad2(date.getSeconds());
|
||||
return `${y}-${m}-${d} ${h}:${min}:${s}`;
|
||||
}
|
||||
Reference in New Issue
Block a user