cmvr-wms/mobile-app/tests/date-display.test.mjs

24 lines
1.4 KiB
JavaScript

import test from 'node:test';
import assert from 'node:assert/strict';
import {formatDateTime,displayTimestamp} from '../src/core/date-display.ts';
import {display} from '../src/core/modules.ts';
import {referenceText} from '../src/core/assistant-display.ts';
test('native messages, feedback and generic lists display readable timestamps',()=>{
for(const value of ['2026-10-26T12:01:54','2026-10-26T12:01:54.123456','2026-10-26 12:01:54'])assert.equal(formatDateTime(value),'2026-10-26 12:01:54');
assert.equal(display('2026-10-26T12:01:54'),'2026-10-26 12:01:54');
assert.equal(referenceText('2026-10-26T12:01:54'),'2026-10-26 12:01:54');
assert.equal(formatDateTime('2026-10-26'),'2026-10-26');
});
test('native timestamp offsets and numeric epoch values refer to the same instant',()=>{
const instant=Date.UTC(2026,9,26,4,1,54),expected=formatDateTime(new Date(instant));
assert.equal(formatDateTime('2026-10-26T12:01:54+08:00'),expected);
assert.equal(formatDateTime('2026-10-26T04:01:54Z'),expected);
assert.equal(formatDateTime(instant/1000),expected);
assert.equal(formatDateTime(String(instant)),expected);
});
test('native invalid dates are safe and ordinary values are preserved',()=>{
for(const value of [null,'','invalid',new Date(NaN),{},true,'2026-02-30'])assert.equal(formatDateTime(value),'—');
for(const value of [1000,'物品T1','2026-10-26T12:01:54.pdf'])assert.equal(displayTimestamp(value),value);
});