// eventTime 取事件上的服务端时间;后端 0 值占位(0001-01-01T00:00:00Z) // 不能让状态栏把「已工作」读成几百年的耗时——非正 epoch 一律回落到墙上时钟。 import { describe, expect, it } from 'vitest' import { eventTime } from '../src/store' describe('eventTime', () => { it('returns now when the timestamp is missing', () => { const now = 1_700_000_000_000 expect(eventTime({}, now)).toBe(now) expect(eventTime({ ts: '' }, now)).toBe(now) expect(eventTime({ ts: undefined }, now)).toBe(now) }) it('returns now for unparseable timestamps', () => { const now = 1_700_000_000_000 expect(eventTime({ ts: 'not-a-date' }, now)).toBe(now) expect(eventTime({ ts: '2026-13-40T99:99:99Z' }, now)).toBe(now) }) it('returns now when the parsed time is not a positive epoch (zero-value placeholder)', () => { // 0001-01-01T00:00:00Z is the Go/Unix zero time;过去不能解释为有效事件时间。 const now = 1_700_000_000_000 expect(eventTime({ ts: '0001-01-01T00:00:00Z' }, now)).toBe(now) // Date.parse('1970-01-01T00:00:00Z') === 0,应被一并回落,否则状态栏会显示从 epoch 至今。 expect(eventTime({ ts: '1970-01-01T00:00:00Z' }, now)).toBe(now) }) it('returns the parsed epoch for a real, parseable timestamp', () => { const now = 1_700_000_000_000 expect(eventTime({ ts: '2024-01-02T03:04:05Z' }, now)).toBe(Date.parse('2024-01-02T03:04:05Z')) expect(eventTime({ ts: '2026-10-12T10:00:00Z' }, now)).toBe(Date.parse('2026-10-12T10:00:00Z')) }) })