The runner's Node carries English-only ICU and formats en-GB as en-US
("Oct 5", "EDT"); browsers carry full ICU. What #38 guards is which day
and which hour, so that is what the test checks.
Refs #38
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015pkwBsR54NRmZyU4QVhvfj
45 lines
1.8 KiB
TypeScript
45 lines
1.8 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.
|
|
//
|
|
// Assertions are on the date and the hour, not the whole string: a Node built
|
|
// with English-only ICU formats en-GB as en-US ("Oct 5", "EDT"), and the order
|
|
// of the words is the locale's business, not what this test is guarding.
|
|
import assert from 'node:assert/strict'
|
|
import { test } from 'node:test'
|
|
|
|
import { clock, utc, utcDay, utcMonth, when, zone } from '../src/lib/format.ts'
|
|
|
|
/** The day-of-month numbers in a formatted string. */
|
|
const days = (s: string) => (s.match(/\b\d{1,2}\b/g) ?? []).map(Number)
|
|
|
|
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.deepEqual(days(utcDay('2026-10-05T00:00:00Z')), [5])
|
|
assert.match(utcDay('2026-10-05T00:00:00Z', true), /2026/)
|
|
assert.match(utcMonth('2026-10-01T00:00:00Z'), /Oct.*2026|2026.*Oct/)
|
|
assert.doesNotMatch(utcMonth('2026-10-01T00:00:00Z'), /Sep/)
|
|
})
|
|
|
|
test('an instant is local, 24-hour, and names its zone', () => {
|
|
const at = '2026-10-05T17:00:00Z'
|
|
const shown = when(at)
|
|
assert.match(shown, /\b13:00\b/)
|
|
assert.match(shown, /\b0?5\b/)
|
|
assert.ok(shown.endsWith(zone(Date.parse(at))), shown)
|
|
assert.notEqual(zone(Date.parse(at)), 'local')
|
|
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.match(clock(ms, 2 * 86_400_000), /\b5\b.*13:00|13:00.*\b5\b/)
|
|
})
|