Files
observer/web/test/format.test.ts
T
grenadeandClaude Opus 5.5 21ec54bd24
ci / gate (push) Failing after 4m31s
fix(web): label local times with their zone and keep UTC days on their own date
Instants (blocks, swaps, node starts) render in the viewer's zone and say
which: tables carry the zone, charts name it once, titles give UTC. Daily
buckets the API cut at UTC midnight render in UTC and are headed "(UTC)" —
FlowChart formatted them as local dates, putting every bar a day early
anywhere west of Greenwich.

All date formatting goes through lib/format.ts (when, utc, clock, utcDay,
utcMonth, zone), one locale and a 24-hour clock. `pnpm test` runs Node's
built-in runner under America/New_York, where the old formatter turns
5 Oct into 4 Oct, and is part of the shared CI gate.

Closes #38

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015pkwBsR54NRmZyU4QVhvfj
2026-10-06 10:58:52 +03:00

33 lines
1.3 KiB
TypeScript

// Run under a zone west of Greenwich (`TZ=America/New_York`, see `pnpm test`),
// which is where a UTC day formatted as local time lands on the day before.
import assert from 'node:assert/strict'
import { test } from 'node:test'
import { clock, utc, utcDay, utcMonth, when, zone } from '../src/lib/format.ts'
test('the test runs west of UTC, or it proves nothing', () => {
assert.ok(new Date('2026-10-05T00:00:00Z').getTimezoneOffset() > 0)
})
test('a UTC-midnight bucket formats as its own date', () => {
assert.equal(utcDay('2026-10-05T00:00:00Z'), '5 Oct')
assert.equal(utcDay('2026-10-05T00:00:00Z', true), '5 Oct 2026')
assert.equal(utcMonth('2026-10-01T00:00:00Z'), 'Oct 2026')
})
test('an instant is local, 24-hour, and names its zone', () => {
assert.equal(when('2026-10-05T17:00:00Z'), '05 Oct 2026, 13:00 GMT-4')
assert.equal(zone(Date.parse('2026-10-05T17:00:00Z')), 'GMT-4')
assert.equal(when(null), '—')
})
test('a title carries the instant in UTC', () => {
assert.equal(utc('2026-10-05T17:00:00.123Z'), '2026-10-05 17:00:00 UTC')
})
test('chart labels are local clock time, dated past a day', () => {
const ms = Date.parse('2026-10-05T17:00:00Z')
assert.equal(clock(ms, 3_600_000), '13:00')
assert.equal(clock(ms, 2 * 86_400_000), '5 Oct, 13:00')
})