From b8418f9ab2d52ec0f21e71bfc7b396b6e7a6748f Mon Sep 17 00:00:00 2001 From: collin Date: Fri, 24 Jul 2026 12:50:28 +0200 Subject: [PATCH] Fixing issue with weekend reservations due to different opening times (and as a result different start times for the courts) --- src/runner/baanreserveren/service.ts | 197 +++++++++++++++++---------- 1 file changed, 128 insertions(+), 69 deletions(-) diff --git a/src/runner/baanreserveren/service.ts b/src/runner/baanreserveren/service.ts index d587b4e..ad9c473 100644 --- a/src/runner/baanreserveren/service.ts +++ b/src/runner/baanreserveren/service.ts @@ -119,74 +119,128 @@ export const StartTimeClassCourtSlots: Record< } as const const StartTimeClassStartTimes = { - [StartTimeClass.First]: [ - '07:15', - '08:00', - '08:45', - '09:30', - '10:15', - '11:00', - '11:45', - '12:30', - '13:15', - '14:00', - '14:45', - '15:30', - '16:15', - '17:00', - '17:45', - '18:30', - '19:15', - '20:00', - '20:45', - '21:30', - '22:15', - ], - [StartTimeClass.Second]: [ - '07:45', - '08:30', - '09:15', - '10:00', - '10:45', - '11:30', - '12:15', - '13:00', - '13:45', - '14:30', - '15:15', - '16:00', - '16:45', - '17:30', - '18:15', - '19:00', - '19:45', - '20:30', - '21:15', - '22:00', - ], - [StartTimeClass.Third]: [ - '07:30', - '08:15', - '09:00', - '09:45', - '10:30', - '11:15', - '12:00', - '12:45', - '13:30', - '14:15', - '15:00', - '15:45', - '16:30', - '17:15', - '18:00', - '18:45', - '19:30', - '20:15', - '21:00', - '21:45', - '22:30', - ], + [StartTimeClass.First]: { + weekday: [ + '07:15', + '08:00', + '08:45', + '09:30', + '10:15', + '11:00', + '11:45', + '12:30', + '13:15', + '14:00', + '14:45', + '15:30', + '16:15', + '17:00', + '17:45', + '18:30', + '19:15', + '20:00', + '20:45', + '21:30', + '22:15', + ], + weekend: [ + '09:00', + '09:45', + '10:30', + '11:15', + '12:00', + '12:45', + '13:30', + '14:15', + '15:00', + '15:45', + '16:30', + '17:15', + '18:00', + '18:45', + ], + }, + [StartTimeClass.Second]: { + weekday: [ + '07:45', + '08:30', + '09:15', + '10:00', + '10:45', + '11:30', + '12:15', + '13:00', + '13:45', + '14:30', + '15:15', + '16:00', + '16:45', + '17:30', + '18:15', + '19:00', + '19:45', + '20:30', + '21:15', + '22:00', + ], + weekend: [ + '09:15', + '10:00', + '10:45', + '11:30', + '12:15', + '13:00', + '13:45', + '14:30', + '15:15', + '16:00', + '16:45', + '17:30', + '18:15', + '19:00', + ], + }, + [StartTimeClass.Third]: { + weekday: [ + '07:30', + '08:15', + '09:00', + '09:45', + '10:30', + '11:15', + '12:00', + '12:45', + '13:30', + '14:15', + '15:00', + '15:45', + '16:30', + '17:15', + '18:00', + '18:45', + '19:30', + '20:15', + '21:00', + '21:45', + '22:30', + ], + weekend: [ + '08:45', + '09:30', + '10:15', + '11:00', + '11:45', + '12:30', + '13:15', + '14:00', + '14:45', + '15:30', + '16:15', + '17:00', + '17:45', + '18:30', + ], + }, } const TYPING_DELAY_MS = 2 @@ -739,7 +793,12 @@ export class BaanReserverenService { public getCourtSlotsForDate(date: Dayjs) { const time = date.format('HH:mm') - for (const [timeClass, times] of Object.entries(StartTimeClassStartTimes)) { + const weekdayEndSelector = + date.day() !== 0 || date.day() !== 6 ? 'weekday' : 'weekend' + for (const [timeClass, timesForWeekdayAndWeekend] of Object.entries( + StartTimeClassStartTimes, + )) { + const times = timesForWeekdayAndWeekend[weekdayEndSelector] if (times.includes(time)) { const courtSlots = [ ...StartTimeClassCourtSlots[timeClass as StartTimeClass],