From bb12667a7c5b88a17cfc5c71ed05b62ccfa7ad7c Mon Sep 17 00:00:00 2001 From: Nathan FONTEYNE Date: Thu, 23 Jul 2026 11:15:41 +0200 Subject: [PATCH] update: 3 -> 4 weeks in calendar --- public/js/calendar.js | 2 +- src/lib/calendarAvailability.js | 4 ++-- src/repositories/calendarRepo.js | 4 ++-- src/routes/calendar.js | 2 +- src/services/calendarSync.js | 6 +++--- test/calendarAvailability.test.js | 8 ++++---- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/public/js/calendar.js b/public/js/calendar.js index 5a0755d..fa1b973 100644 --- a/public/js/calendar.js +++ b/public/js/calendar.js @@ -15,7 +15,7 @@ async function loadPeople() { } async function loadSlots() { - state.slots = await api.get('/api/calendar/slots?weeks=3'); + state.slots = await api.get('/api/calendar/slots?weeks=4'); renderCalendar(); } diff --git a/src/lib/calendarAvailability.js b/src/lib/calendarAvailability.js index ba7daf3..66404b4 100644 --- a/src/lib/calendarAvailability.js +++ b/src/lib/calendarAvailability.js @@ -8,9 +8,9 @@ const DEFAULT_SLOT_CONFIG = { weekday: { startHour: 18, startMinute: 30, endHour: 21, endMinute: 0 }, weekend: { startHour: 15, startMinute: 0, endHour: 19, endMinute: 0 }, }; -const MAX_WEEKS = 3; +const MAX_WEEKS = 4; -// One slot per day for the next `weeks` weeks (capped at 3, same as the rest +// One slot per day for the next `weeks` weeks (capped at 4, same as the rest // of the calendar feature), starting from today's Paris-local calendar date // — not the server's own timezone, which may not be Europe/Paris. function generateSlots(weeks = MAX_WEEKS, slotConfig = DEFAULT_SLOT_CONFIG) { diff --git a/src/repositories/calendarRepo.js b/src/repositories/calendarRepo.js index 209b81e..7613254 100644 --- a/src/repositories/calendarRepo.js +++ b/src/repositories/calendarRepo.js @@ -84,8 +84,8 @@ async function ingestSlots(slots) { return summary; } -async function getSlots({ minPeople = 0, personIds = null, weeks = 3 } = {}) { - const cappedWeeks = Math.min(weeks || 3, 3); +async function getSlots({ minPeople = 0, personIds = null, weeks = 4 } = {}) { + const cappedWeeks = Math.min(weeks || 4, 4); const now = new Date(); const end = new Date(now); end.setDate(end.getDate() + cappedWeeks * 7); diff --git a/src/routes/calendar.js b/src/routes/calendar.js index 5f094d6..8e5a1e0 100644 --- a/src/routes/calendar.js +++ b/src/routes/calendar.js @@ -22,7 +22,7 @@ router.get( // ingested slot (heat-colored by availability ratio on the frontend), // not just slots where at least one person happens to be free. const minPeople = req.query.min_people !== undefined ? parseInt(req.query.min_people, 10) : 0; - const weeks = req.query.weeks !== undefined ? parseInt(req.query.weeks, 10) : 3; + const weeks = req.query.weeks !== undefined ? parseInt(req.query.weeks, 10) : 4; const personIds = req.query.person_ids ? req.query.person_ids.split(',').map(Number).filter((n) => !Number.isNaN(n)) : null; diff --git a/src/services/calendarSync.js b/src/services/calendarSync.js index 33a670d..8038f85 100644 --- a/src/services/calendarSync.js +++ b/src/services/calendarSync.js @@ -3,7 +3,7 @@ const calendarRepo = require('../repositories/calendarRepo'); const { generateSlots, isBusyDuring, widenWindow } = require('../lib/calendarAvailability'); const { parisWallClockToUTC } = require('../lib/calendarDates'); -const RANGE_DAYS = 22; // slightly more than the 3 weeks generateSlots() covers +const RANGE_DAYS = 29; // slightly more than the 4 weeks generateSlots() covers const FETCH_TIMEOUT_MS = 15000; // Fetches one ICS feed and parses it into node-ical's raw component map. @@ -84,7 +84,7 @@ function dateOnlyToParisSpan(dateOnly) { } // Fetches every registered feed, derives per-person busy/free for each of the -// next 3 weeks' slots (using the admin-configured rehearsal hours, falling +// next 4 weeks' slots (using the admin-configured rehearsal hours, falling // back to calendarAvailability's defaults if none are set), and ingests the // result via calendarRepo.ingestSlots — the same sink the old n8n-webhook flow // used to feed. A feed that fails to fetch is logged by id only (never its @@ -113,7 +113,7 @@ async function syncAvailability() { intervalsByUser.set(feed.user_id, existing.concat(result.value)); }); - const slots = generateSlots(3, slotConfig); + const slots = generateSlots(4, slotConfig); const slotPayload = slots.map((slot) => { // The margin only widens the *check* window (to account for travel time // between back-to-back calendar events) — the slot itself, as stored and diff --git a/test/calendarAvailability.test.js b/test/calendarAvailability.test.js index 4ca3690..f645e0f 100644 --- a/test/calendarAvailability.test.js +++ b/test/calendarAvailability.test.js @@ -2,14 +2,14 @@ const { test } = require('node:test'); const assert = require('node:assert/strict'); const { generateSlots, isBusyDuring, widenWindow } = require('../src/lib/calendarAvailability'); -test('generateSlots: default 3 weeks produces one slot per day for 21 days', () => { +test('generateSlots: default 4 weeks produces one slot per day for 28 days', () => { const slots = generateSlots(); - assert.equal(slots.length, 21); + assert.equal(slots.length, 28); }); -test('generateSlots: caps weeks at 3 even if a larger value is requested', () => { +test('generateSlots: caps weeks at 4 even if a larger value is requested', () => { const slots = generateSlots(10); - assert.equal(slots.length, 21); + assert.equal(slots.length, 28); }); test('generateSlots: every slot has upper strictly after lower', () => {