collabSupport/tests/time.test.js
Joseph McQueen 1117be40cc Format chat footers in DISPLAY_TIMEZONE instead of UTC.
Docker hosts default to UTC, so bare toLocaleTimeString() showed
wrong "Last checked" times in avstatus and other commands. Add
formatDisplayTime() (default America/New_York, overridable via
DISPLAY_TIMEZONE) and use it across renderers and command footers.
2026-07-21 14:41:26 -04:00

26 lines
985 B
JavaScript

import test from 'node:test';
import assert from 'node:assert/strict';
import { formatDisplayTime, DISPLAY_TIMEZONE } from '../utils/time.js';
test('DISPLAY_TIMEZONE defaults to America/New_York', () => {
// If DISPLAY_TIMEZONE env is unset in test runner, we expect the default.
const expected = process.env.DISPLAY_TIMEZONE || 'America/New_York';
assert.equal(DISPLAY_TIMEZONE, expected);
});
test('formatDisplayTime: converts UTC instant to Eastern wall clock', () => {
// 2026-07-21 18:13:45 UTC → 2:13:45 PM EDT (DST)
const d = new Date('2026-07-21T18:13:45.000Z');
const formatted = formatDisplayTime(d);
assert.match(formatted, /2:13:45 PM/);
assert.match(formatted, /EDT/);
});
test('formatDisplayTime: winter offset uses EST', () => {
// 2026-01-15 18:00:00 UTC → 1:00:00 PM EST
const d = new Date('2026-01-15T18:00:00.000Z');
const formatted = formatDisplayTime(d);
assert.match(formatted, /1:00:00 PM/);
assert.match(formatted, /EST/);
});