MCPcopy Index your code
hub / github.com/ChatLab/ChatLab / parseTimestamp

Function parseTimestamp

packages/parser/src/utils.ts:45–57  ·  view source on GitHub ↗
(value: string | number)

Source from the content-addressed store, hash-verified

43 * @returns 秒级时间戳,如果解析失败返回 null
44 */
45export function parseTimestamp(value: string | number): number | null {
46 if (typeof value === 'string') {
47 // ISO 字符串格式:2017-12-30T03:24:36.000Z
48 const parsed = Date.parse(value)
49 if (isNaN(parsed)) return null
50 return Math.floor(parsed / 1000)
51 } else if (typeof value === 'number') {
52 // 毫秒时间戳
53 if (isNaN(value)) return null
54 return Math.floor(value / 1000)
55 }
56 return null
57}
58
59/**
60 * 验证年份是否合理(2000年以后)

Callers 2

parseV4Function · 0.90
parseChunkedJsonlFunction · 0.90

Calls 1

parseMethod · 0.80

Tested by

no test coverage detected