import assert from 'node:assert/strict'; import { describe, it } from 'node:test'; import { addDays, compactDate, daysBetween, germanDate, germanDay, germanWeekday, isCalendarDate, schoolToday, } from '../src/core/dates.ts'; describe('schoolToday', () => { it('is the school\'s date, not the container\'s', () => { // 23:30 UTC in January is already tomorrow in Berlin (UTC+1) — the case // that would make a nightly briefing prepare the wrong day. assert.equal(schoolToday(new Date('2026-01-15T23:30:00Z')), '2026-01-16'); // And in summer the offset is two hours. assert.equal(schoolToday(new Date('2026-07-15T22:30:00Z')), '2026-07-16'); assert.equal(schoolToday(new Date('2026-07-15T21:30:00Z')), '2026-07-15'); }); }); describe('addDays and daysBetween', () => { it('walks calendar dates across a daylight-saving change', () => { // Clocks go forward in the EU on 2026-03-29, so a day of 23 hours lies // inside this range. assert.equal(addDays('2026-03-28', 2), '2026-03-30'); assert.equal(daysBetween('2026-03-28', '2026-03-30'), 2); // And back again in October. assert.equal(addDays('2026-10-24', 2), '2026-10-26'); }); it('crosses months and years', () => { assert.equal(addDays('2026-12-31', 1), '2027-01-01'); assert.equal(addDays('2026-01-01', -1), '2025-12-31'); assert.equal(addDays('2028-02-28', 1), '2028-02-29'); assert.equal(daysBetween('2026-09-21', '2026-09-18'), -3); }); it('refuses something that is not a calendar date', () => { assert.throws(() => addDays('21.09.2026', 1), /YYYY-MM-DD/); }); }); describe('calendar date helpers', () => { it('recognises real dates only', () => { assert.equal(isCalendarDate('2026-09-21'), true); assert.equal(isCalendarDate('2026-13-01'), false); assert.equal(isCalendarDate('2026-02-30'), false); assert.equal(isCalendarDate('2026-9-21'), false); assert.equal(isCalendarDate('heute'), false); }); it('formats the way a German timetable reads', () => { assert.equal(germanWeekday('2026-09-21'), 'Montag'); assert.equal(germanWeekday('2026-09-17'), 'Donnerstag'); assert.equal(germanDay('2026-09-21'), '21.09.2026'); assert.equal(compactDate('2026-09-21'), 20_260_921); }); it('gives a moment the school\'s day, with its weekday', () => { assert.equal(germanDate(new Date('2026-09-14T23:30:00Z')), 'Dienstag, 15.09.2026'); }); });