import { test } from 'node:test';
import assert from 'node:assert/strict';
import {
  isValidIanaTimezone,
  localDateInTimezone,
} from '@/shared/constants/timezone';

test('localDateInTimezone yields the campus-local date (Phoenix, no DST)', () => {
  // Phoenix is UTC-7 year-round. 05:30Z = 22:30 previous day in Phoenix.
  assert.equal(
    localDateInTimezone('America/Phoenix', new Date('2026-06-12T05:30:00Z')),
    '2026-06-11',
  );
  // 12:00Z = 05:00 same day in Phoenix.
  assert.equal(
    localDateInTimezone('America/Phoenix', new Date('2026-06-12T12:00:00Z')),
    '2026-06-12',
  );
});

test('localDateInTimezone is DST-correct (New York, summer = UTC-4)', () => {
  // 03:00Z on 2026-06-12 = 23:00 EDT on 2026-06-11.
  assert.equal(
    localDateInTimezone('America/New_York', new Date('2026-06-12T03:00:00Z')),
    '2026-06-11',
  );
});

test('isValidIanaTimezone accepts IANA zones and rejects junk', () => {
  assert.equal(isValidIanaTimezone('America/Phoenix'), true);
  assert.equal(isValidIanaTimezone('Mars/Phobos'), false);
  assert.equal(isValidIanaTimezone(''), false);
  assert.equal(isValidIanaTimezone(null), false);
  assert.equal(isValidIanaTimezone(5), false);
});
