feat(worker-hall): 接单大厅支持内部打手可见订单已发布时长标签
This commit is contained in:
@@ -52,3 +52,34 @@ export function normalizeDateTimeValue(value: unknown): unknown {
|
||||
export function stringifyDisplayJson(value: unknown, space = 2) {
|
||||
return JSON.stringify(normalizeDateTimeValue(value), null, space)
|
||||
}
|
||||
|
||||
/** 抢单大厅发布耗时格式化(仅内部打手可见):发布 <1m / 发布 5m / 发布 1h 20m / 发布 1d 4h */
|
||||
export function formatPublishedElapsedTime(
|
||||
value: string | null | undefined,
|
||||
nowMs = Date.now(),
|
||||
): string {
|
||||
const normalized = String(value || '').trim()
|
||||
if (!normalized) return ''
|
||||
|
||||
const date = new Date(normalized)
|
||||
const time = date.getTime()
|
||||
if (Number.isNaN(time)) return ''
|
||||
|
||||
const diffSeconds = Math.max(0, Math.floor((nowMs - time) / 1000))
|
||||
|
||||
if (diffSeconds < 60) {
|
||||
return '发布 <1m'
|
||||
}
|
||||
const diffMinutes = Math.floor(diffSeconds / 60)
|
||||
if (diffMinutes < 60) {
|
||||
return `发布 ${diffMinutes}m`
|
||||
}
|
||||
const diffHours = Math.floor(diffMinutes / 60)
|
||||
const remMinutes = diffMinutes % 60
|
||||
if (diffHours < 24) {
|
||||
return remMinutes > 0 ? `发布 ${diffHours}h ${remMinutes}m` : `发布 ${diffHours}h`
|
||||
}
|
||||
const diffDays = Math.floor(diffHours / 24)
|
||||
const remHours = diffHours % 24
|
||||
return remHours > 0 ? `发布 ${diffDays}d ${remHours}h` : `发布 ${diffDays}d`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user