[engine] Sun: nextInvitation checks yesterday, today and tomorrow; addDays steps the calendar; NamedPlace
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import fc from 'fast-check';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { isLocalDay, localDay } from '../src/time/localDay.js';
|
||||
import { addDays, isLocalDay, localDay } from '../src/time/localDay.js';
|
||||
|
||||
const at = (iso: string): number => Date.parse(iso);
|
||||
|
||||
@@ -86,3 +86,27 @@ describe('localDay — properties', () => {
|
||||
fc.assert(fc.property(instant, zone, (t, z) => localDay(t, z) === localDay(t, z)));
|
||||
});
|
||||
});
|
||||
|
||||
describe('addDays — a calendar step, no zone', () => {
|
||||
it.each([
|
||||
['2026-03-28', 1, '2026-03-29'], // across a DST change: still one day
|
||||
['2026-12-31', 1, '2027-01-01'],
|
||||
['2028-02-28', 1, '2028-02-29'], // leap year
|
||||
['2026-03-01', -1, '2026-02-28'],
|
||||
['2026-06-21', 0, '2026-06-21']
|
||||
])('%s + %s = %s', (day, n, expected) => {
|
||||
expect(addDays(day, n)).toBe(expected);
|
||||
});
|
||||
|
||||
it('refuses a day that is not a LocalDay, and a part of a day', () => {
|
||||
expect(() => addDays('2026-6-1', 1)).toThrow(/not a LocalDay/);
|
||||
expect(() => addDays('2026-06-01', 0.5)).toThrow(/whole number/);
|
||||
});
|
||||
|
||||
it('stepping forward and back again returns the same day', () => {
|
||||
fc.assert(fc.property(fc.integer({ min: 0, max: 3000 }), fc.integer({ min: -400, max: 400 }), (k, n) => {
|
||||
const day = addDays('2025-01-01', k);
|
||||
return addDays(addDays(day, n), -n) === day && isLocalDay(addDays(day, n));
|
||||
}));
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user