feat: 完善代理池与抢购链路,发布 0.5.0

This commit is contained in:
yml
2026-11-20 00:48:21 +08:00
parent 2f087ac7f1
commit 98b3dc4b16
28 changed files with 1522 additions and 204 deletions
+36
View File
@@ -0,0 +1,36 @@
const pad = (value: number) => String(value).padStart(2, '0')
const parseTimeValue = (value: unknown): Date | null => {
const text = String(value ?? '').trim()
if (!text) return null
if (/^\d+$/.test(text)) {
const numeric = Number(text)
if (!Number.isFinite(numeric) || numeric <= 0) return null
const milliseconds = numeric < 10_000_000_000 ? numeric * 1000 : numeric
const date = new Date(milliseconds)
return Number.isNaN(date.getTime()) ? null : date
}
if (/^\d{4}-\d{2}-\d{2}[ T]\d{2}:\d{2}:\d{2}/.test(text)) {
const date = new Date(text.replace(' ', 'T'))
return Number.isNaN(date.getTime()) ? null : date
}
return null
}
export const formatExchangeTime = (value: unknown): string => {
const text = String(value ?? '').trim()
if (!text) return '-'
const date = parseTimeValue(text)
if (!date) return text.replace('T', ' ')
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())} ${pad(date.getHours())}:${pad(date.getMinutes())}:${pad(date.getSeconds())}`
}
export const formatShortExchangeTime = (value: unknown): string => {
const text = String(value ?? '').trim()
if (!text) return ''
const date = parseTimeValue(text)
if (!date) return text.replace('T', ' ').slice(0, 16)
return `${pad(date.getMonth() + 1)}-${pad(date.getDate())} ${pad(date.getHours())}:${pad(date.getMinutes())}`
}