feat(engine): 实现同步引擎与 engine_status 快照
apps/engine 独立进程(syncRound + 防重叠调度);上游 log/token;QPU 采样; server 读 engine_status;时刻出参 toUnixSec;中文日志;zod-openapi 扩展顺序修复。
This commit is contained in:
@@ -1,18 +1,35 @@
|
||||
/** 存储层 UTC Unix 秒 / Date / ISO 字符串 ↔ DTO 层 ISO 8601 UTC */
|
||||
export function unixToIso(
|
||||
value: number | string | Date | null | undefined,
|
||||
): string | null {
|
||||
/**
|
||||
* 时间口径(API 响应统一 Unix 秒整数;请求 from/to 仍收 ISO 8601 便于试调)
|
||||
* 库内 timestamptz ↔ JS Date ↔ Unix 秒
|
||||
*/
|
||||
function toDate(value: number | string | Date | null | undefined): Date | null {
|
||||
if (value === null || value === undefined) return null;
|
||||
let d: Date;
|
||||
if (value instanceof Date) {
|
||||
d = value;
|
||||
} else if (typeof value === "number") {
|
||||
// Unix 秒(或毫秒:量级区分)
|
||||
d = new Date(value < 1e12 ? value * 1000 : value);
|
||||
} else {
|
||||
d = new Date(value);
|
||||
}
|
||||
if (Number.isNaN(d.getTime())) return null;
|
||||
return Number.isNaN(d.getTime()) ? null : d;
|
||||
}
|
||||
|
||||
/** → Unix 秒(UTC);无效则 null */
|
||||
export function toUnixSec(
|
||||
value: number | string | Date | null | undefined,
|
||||
): number | null {
|
||||
const d = toDate(value);
|
||||
if (!d) return null;
|
||||
return Math.floor(d.getTime() / 1000);
|
||||
}
|
||||
|
||||
/** 兼容旧名:ISO 串(仅本地/文档用;API 响应改用 toUnixSec) */
|
||||
export function unixToIso(
|
||||
value: number | string | Date | null | undefined,
|
||||
): string | null {
|
||||
const d = toDate(value);
|
||||
if (!d) return null;
|
||||
return d.toISOString().replace(/\.\d{3}Z$/, "Z");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user