// 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') })