(value: string | number)
| 43 | * @returns 秒级时间戳,如果解析失败返回 null |
| 44 | */ |
| 45 | export 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年以后) |
no test coverage detected