Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

✨ chore: modelParse support Millisecond time stamp (#8939)

sxjeru26c2dd68de7d
diff --git a/packages/model-runtime/src/utils/modelParse.ts b/packages/model-runtime/src/utils/modelParse.ts
index baa1b405659..66a4c26fd69 100644
--- a/packages/model-runtime/src/utils/modelParse.ts
+++ b/packages/model-runtime/src/utils/modelParse.ts
@@ -211,9 +211,21 @@ export const detectModelProvider = (modelId: string): keyof typeof MODEL_LIST_CO
* @param timestamp 时间戳(秒)
* @returns 格式化的日期字符串 (YYYY-MM-DD)
*/
-const formatTimestampToDate = (timestamp: number): string => {
- const date = new Date(timestamp * 1000); // 将秒转换为毫秒
- return date.toISOString().split('T')[0]; // 返回 YYYY-MM-DD 格式
+const formatTimestampToDate = (timestamp: number): string | undefined => {
+ if (timestamp === null || timestamp === undefined || Number.isNaN(timestamp)) return undefined;
+
+ // 支持秒级或毫秒级时间戳:
+ // - 如果是毫秒级(>= 1e12),直接当作毫秒;
+ // - 否则视为秒,需要 *1000 转为毫秒
+ const msTimestamp = timestamp > 1e12 ? timestamp : timestamp * 1000;
+ const date = new Date(msTimestamp);
+
+ // 验证解析结果和年份范围(只接受 4 位年份,避免超出 varchar(10) 的 YYYY-MM-DD)
+ const year = date.getUTCFullYear();
+ if (year < 1000 || year > 9999) return undefined;
+
+ const dateStr = date.toISOString().split('T')[0]; // YYYY-MM-DD
+ return dateStr.length === 10 ? dateStr : undefined;
};
/**