45 lines
1.9 KiB
TypeScript
45 lines
1.9 KiB
TypeScript
import { describe, it, expect } from 'vitest';
|
|
import {
|
|
addDays, compareDates, dateToISO, daysBetween, isEuroEra,
|
|
isLastDayOfMonth, isSunday, parseISO, START_DATE,
|
|
} from '../../src/sim/calendar';
|
|
|
|
describe('calendar', () => {
|
|
it('starts on the European Game Boy launch (Friday 28/09/1990)', () => {
|
|
expect(START_DATE).toEqual({ year: 1990, month: 9, day: 28 });
|
|
expect(isSunday(START_DATE)).toBe(false);
|
|
});
|
|
|
|
it('detects Sundays', () => {
|
|
expect(isSunday({ year: 1990, month: 9, day: 30 })).toBe(true);
|
|
expect(isSunday({ year: 1990, month: 9, day: 29 })).toBe(false);
|
|
});
|
|
|
|
it('adds days across month and year boundaries', () => {
|
|
expect(addDays({ year: 1990, month: 12, day: 31 }, 1)).toEqual({ year: 1991, month: 1, day: 1 });
|
|
expect(addDays({ year: 1990, month: 9, day: 28 }, 3)).toEqual({ year: 1990, month: 10, day: 1 });
|
|
});
|
|
|
|
it('detects the last day of a month, including leap years', () => {
|
|
expect(isLastDayOfMonth({ year: 1992, month: 2, day: 29 })).toBe(true);
|
|
expect(isLastDayOfMonth({ year: 1992, month: 2, day: 28 })).toBe(false);
|
|
expect(isLastDayOfMonth({ year: 1990, month: 9, day: 30 })).toBe(true);
|
|
});
|
|
|
|
it('switches to the euro on 01/01/2002', () => {
|
|
expect(isEuroEra({ year: 2001, month: 12, day: 31 })).toBe(false);
|
|
expect(isEuroEra({ year: 2002, month: 1, day: 1 })).toBe(true);
|
|
});
|
|
|
|
it('computes days between dates', () => {
|
|
expect(daysBetween({ year: 1990, month: 9, day: 28 }, { year: 1990, month: 10, day: 28 })).toBe(30);
|
|
expect(daysBetween({ year: 1990, month: 10, day: 28 }, { year: 1990, month: 9, day: 28 })).toBe(-30);
|
|
});
|
|
|
|
it('round-trips ISO strings and compares dates', () => {
|
|
expect(dateToISO(parseISO('1990-09-28'))).toBe('1990-09-28');
|
|
expect(compareDates(parseISO('1990-09-28'), parseISO('1991-01-01'))).toBeLessThan(0);
|
|
expect(compareDates(parseISO('1991-01-01'), parseISO('1991-01-01'))).toBe(0);
|
|
});
|
|
});
|