@happychef/algorithm 1.2.10 → 1.2.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/ci-cd.yml +133 -2
- package/BRANCH_PROTECTION_SETUP.md +167 -0
- package/CHANGELOG.md +8 -8
- package/RESERVERINGEN_GIDS.md +986 -986
- package/assignTables.js +424 -398
- package/changes/2025/December/PR2___change.md +14 -14
- package/changes/2025/December/PR3_add__change.md +20 -20
- package/changes/2025/December/PR4___.md +16 -0
- package/changes/2025/December/PR5___.md +16 -0
- package/changes/2025/December/PR6__del_.md +18 -0
- package/changes/2025/December/PR7_add__change.md +22 -0
- package/changes/2026/January/PR8_add__change.md +39 -0
- package/changes/2026/January/PR9_add__change.md +20 -0
- package/filters/maxArrivalsFilter.js +114 -114
- package/filters/maxGroupsFilter.js +221 -221
- package/filters/timeFilter.js +89 -89
- package/getAvailableTimeblocks.js +158 -158
- package/grouping.js +162 -162
- package/index.js +42 -42
- package/isDateAvailable.js +80 -80
- package/isDateAvailableWithTableCheck.js +171 -171
- package/isTimeAvailable.js +25 -25
- package/package.json +27 -27
- package/processing/dailyGuestCounts.js +73 -73
- package/processing/mealTypeCount.js +133 -133
- package/processing/timeblocksAvailable.js +167 -167
- package/reservation_data/counter.js +64 -64
- package/restaurant_data/exceptions.js +149 -149
- package/restaurant_data/openinghours.js +123 -123
- package/simulateTableAssignment.js +709 -699
- package/tableHelpers.js +178 -178
- package/tables/time/parseTime.js +19 -19
- package/tables/time/shifts.js +7 -7
- package/tables/utils/calculateDistance.js +13 -13
- package/tables/utils/isTableFreeForAllSlots.js +14 -14
- package/tables/utils/isTemporaryTableValid.js +39 -39
- package/test/test_counter.js +194 -194
- package/test/test_dailyCount.js +81 -81
- package/test/test_datesAvailable.js +106 -106
- package/test/test_exceptions.js +172 -172
- package/test/test_isDateAvailable.js +330 -330
- package/test/test_mealTypeCount.js +54 -54
- package/test/test_timesAvailable.js +88 -88
- package/test-meal-stop-fix.js +147 -147
- package/test-meal-stop-simple.js +93 -93
- package/test.js +336 -336
|
@@ -1,168 +1,168 @@
|
|
|
1
|
-
const { getDailyGuestCounts } = require('./dailyGuestCounts');
|
|
2
|
-
const { getMealTypesWithShifts } = require('./mealTypeCount');
|
|
3
|
-
const { getDataByDateAndMealWithExceptions } = require('../restaurant_data/exceptions');
|
|
4
|
-
const { getMealTypeByTime, parseTime: parseTimeOH, daysOfWeekEnglish } = require('../restaurant_data/openinghours');
|
|
5
|
-
const moment = require('moment-timezone');
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Parses a time string in "HH:MM" format into minutes since midnight.
|
|
9
|
-
*/
|
|
10
|
-
function parseTime(timeStr) {
|
|
11
|
-
const [hours, minutes] = timeStr.split(':').map(Number);
|
|
12
|
-
return hours * 60 + minutes;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Retrieves interval and duurReservatie from general settings
|
|
17
|
-
*/
|
|
18
|
-
function getInterval(data) {
|
|
19
|
-
let intervalReservatie = 15;
|
|
20
|
-
if (
|
|
21
|
-
data['general-settings'] &&
|
|
22
|
-
data['general-settings'].intervalReservatie &&
|
|
23
|
-
parseInt(data['general-settings'].intervalReservatie, 10) > 0
|
|
24
|
-
) {
|
|
25
|
-
intervalReservatie = parseInt(data['general-settings'].intervalReservatie, 10);
|
|
26
|
-
}
|
|
27
|
-
return intervalReservatie;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function getDuurReservatie(data) {
|
|
31
|
-
let duurReservatie = 120;
|
|
32
|
-
if (
|
|
33
|
-
data['general-settings'] &&
|
|
34
|
-
data['general-settings'].duurReservatie &&
|
|
35
|
-
parseInt(data['general-settings'].duurReservatie, 10) > 0
|
|
36
|
-
) {
|
|
37
|
-
duurReservatie = parseInt(data['general-settings'].duurReservatie, 10);
|
|
38
|
-
}
|
|
39
|
-
return duurReservatie;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Checks if a time slot belongs to a meal that has the selected giftcard enabled.
|
|
44
|
-
*/
|
|
45
|
-
function timeHasGiftcard(data, dateStr, timeStr, giftcard) {
|
|
46
|
-
if (!giftcard || (typeof giftcard === 'string' && !giftcard.trim())) {
|
|
47
|
-
return true; // No giftcard => no restriction
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const mealType = getMealTypeByTime(timeStr);
|
|
51
|
-
if (!mealType) return false;
|
|
52
|
-
|
|
53
|
-
const m = moment.tz(dateStr, 'YYYY-MM-DD', 'Europe/Brussels');
|
|
54
|
-
if (!m.isValid()) return false;
|
|
55
|
-
const englishDay = daysOfWeekEnglish[m.day()];
|
|
56
|
-
|
|
57
|
-
const ohKey = `openinghours-${mealType}`;
|
|
58
|
-
const daySettings =
|
|
59
|
-
data[ohKey] &&
|
|
60
|
-
data[ohKey].schemeSettings &&
|
|
61
|
-
data[ohKey].schemeSettings[englishDay]
|
|
62
|
-
? data[ohKey].schemeSettings[englishDay]
|
|
63
|
-
: null;
|
|
64
|
-
|
|
65
|
-
if (!daySettings) return false;
|
|
66
|
-
if (daySettings.giftcardsEnabled !== true) return false;
|
|
67
|
-
if (!Array.isArray(daySettings.giftcards) || daySettings.giftcards.length === 0) return false;
|
|
68
|
-
|
|
69
|
-
return daySettings.giftcards.includes(giftcard);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Determines if a given start time plus duurReservatie fits within the meal timeframe.
|
|
74
|
-
*/
|
|
75
|
-
function fitsWithinMeal(data, dateStr, startTimeStr, duurReservatie) {
|
|
76
|
-
// Determine the meal type based on the start time
|
|
77
|
-
const mealType = getMealTypeByTime(startTimeStr);
|
|
78
|
-
if (!mealType) return false;
|
|
79
|
-
|
|
80
|
-
// Get the meal data (with exceptions applied)
|
|
81
|
-
const mealData = getDataByDateAndMealWithExceptions(data, dateStr, mealType);
|
|
82
|
-
if (!mealData) return false;
|
|
83
|
-
|
|
84
|
-
const mealStartTime = parseTime(mealData.startTime);
|
|
85
|
-
const mealEndTime = parseTime(mealData.endTime);
|
|
86
|
-
const startTime = parseTime(startTimeStr);
|
|
87
|
-
|
|
88
|
-
// Check if startTime is after or equal to mealStartTime AND startTime + duurReservatie is within the mealEndTime
|
|
89
|
-
return startTime >= mealStartTime && startTime + duurReservatie <= mealEndTime;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
function timeblocksAvailable(data, dateStr, reservations, guests, blockedSlots = [], giftcard = null, isAdmin = false) {
|
|
93
|
-
const duurReservatie = getDuurReservatie(data);
|
|
94
|
-
const intervalReservatie = getInterval(data);
|
|
95
|
-
|
|
96
|
-
// Slots needed
|
|
97
|
-
const slotsNeeded = Math.ceil(duurReservatie / intervalReservatie);
|
|
98
|
-
|
|
99
|
-
// Get guest counts and shifts info
|
|
100
|
-
const { guestCounts, shiftsInfo } = getDailyGuestCounts(data, dateStr, reservations);
|
|
101
|
-
|
|
102
|
-
const availableTimeblocks = {};
|
|
103
|
-
|
|
104
|
-
// Handle shifts first
|
|
105
|
-
const mealTypesWithShifts = getMealTypesWithShifts(data, dateStr);
|
|
106
|
-
if (mealTypesWithShifts.length > 0 && shiftsInfo && shiftsInfo.length > 0) {
|
|
107
|
-
for (const shift of shiftsInfo) {
|
|
108
|
-
const { time, availableSeats } = shift;
|
|
109
|
-
if (availableSeats >= guests && fitsWithinMeal(data, dateStr, time, duurReservatie)) {
|
|
110
|
-
// Check if time matches giftcard requirement
|
|
111
|
-
if (timeHasGiftcard(data, dateStr, time, giftcard)) {
|
|
112
|
-
availableTimeblocks[time] = { name: time };
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
// Handle non-shift times
|
|
119
|
-
if (guestCounts && Object.keys(guestCounts).length > 0) {
|
|
120
|
-
const timeSlots = Object.keys(guestCounts).sort((a, b) => parseTime(a) - parseTime(b));
|
|
121
|
-
|
|
122
|
-
for (let i = 0; i <= timeSlots.length - slotsNeeded; i++) {
|
|
123
|
-
// Check capacity for all needed slots
|
|
124
|
-
let consecutiveSlotsAvailable = true;
|
|
125
|
-
if (guestCounts[timeSlots[i]] < guests) {
|
|
126
|
-
continue;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
let previousTime = parseTime(timeSlots[i]);
|
|
130
|
-
for (let j = 1; j < slotsNeeded; j++) {
|
|
131
|
-
const currentTimeSlot = timeSlots[i + j];
|
|
132
|
-
const currentTime = parseTime(currentTimeSlot);
|
|
133
|
-
|
|
134
|
-
// Check interval and capacity
|
|
135
|
-
if ((currentTime - previousTime) !== intervalReservatie || guestCounts[currentTimeSlot] < guests) {
|
|
136
|
-
consecutiveSlotsAvailable = false;
|
|
137
|
-
break;
|
|
138
|
-
}
|
|
139
|
-
previousTime = currentTime;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
// If all consecutive slots are available, check if the full duration fits
|
|
143
|
-
if (consecutiveSlotsAvailable && fitsWithinMeal(data, dateStr, timeSlots[i], duurReservatie)) {
|
|
144
|
-
// Check if time matches giftcard requirement
|
|
145
|
-
if (timeHasGiftcard(data, dateStr, timeSlots[i], giftcard)) {
|
|
146
|
-
availableTimeblocks[timeSlots[i]] = { name: timeSlots[i] };
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
// Filter out blocked time slots (skip for admin)
|
|
153
|
-
if (!isAdmin && blockedSlots && blockedSlots.length > 0) {
|
|
154
|
-
for (const blockedSlot of blockedSlots) {
|
|
155
|
-
// Check if the blocked slot matches the current date
|
|
156
|
-
if (blockedSlot.date === dateStr && blockedSlot.time) {
|
|
157
|
-
// Remove the blocked time from available timeblocks
|
|
158
|
-
delete availableTimeblocks[blockedSlot.time];
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
return availableTimeblocks;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
module.exports = {
|
|
167
|
-
timeblocksAvailable,
|
|
1
|
+
const { getDailyGuestCounts } = require('./dailyGuestCounts');
|
|
2
|
+
const { getMealTypesWithShifts } = require('./mealTypeCount');
|
|
3
|
+
const { getDataByDateAndMealWithExceptions } = require('../restaurant_data/exceptions');
|
|
4
|
+
const { getMealTypeByTime, parseTime: parseTimeOH, daysOfWeekEnglish } = require('../restaurant_data/openinghours');
|
|
5
|
+
const moment = require('moment-timezone');
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Parses a time string in "HH:MM" format into minutes since midnight.
|
|
9
|
+
*/
|
|
10
|
+
function parseTime(timeStr) {
|
|
11
|
+
const [hours, minutes] = timeStr.split(':').map(Number);
|
|
12
|
+
return hours * 60 + minutes;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Retrieves interval and duurReservatie from general settings
|
|
17
|
+
*/
|
|
18
|
+
function getInterval(data) {
|
|
19
|
+
let intervalReservatie = 15;
|
|
20
|
+
if (
|
|
21
|
+
data['general-settings'] &&
|
|
22
|
+
data['general-settings'].intervalReservatie &&
|
|
23
|
+
parseInt(data['general-settings'].intervalReservatie, 10) > 0
|
|
24
|
+
) {
|
|
25
|
+
intervalReservatie = parseInt(data['general-settings'].intervalReservatie, 10);
|
|
26
|
+
}
|
|
27
|
+
return intervalReservatie;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function getDuurReservatie(data) {
|
|
31
|
+
let duurReservatie = 120;
|
|
32
|
+
if (
|
|
33
|
+
data['general-settings'] &&
|
|
34
|
+
data['general-settings'].duurReservatie &&
|
|
35
|
+
parseInt(data['general-settings'].duurReservatie, 10) > 0
|
|
36
|
+
) {
|
|
37
|
+
duurReservatie = parseInt(data['general-settings'].duurReservatie, 10);
|
|
38
|
+
}
|
|
39
|
+
return duurReservatie;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Checks if a time slot belongs to a meal that has the selected giftcard enabled.
|
|
44
|
+
*/
|
|
45
|
+
function timeHasGiftcard(data, dateStr, timeStr, giftcard) {
|
|
46
|
+
if (!giftcard || (typeof giftcard === 'string' && !giftcard.trim())) {
|
|
47
|
+
return true; // No giftcard => no restriction
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const mealType = getMealTypeByTime(timeStr);
|
|
51
|
+
if (!mealType) return false;
|
|
52
|
+
|
|
53
|
+
const m = moment.tz(dateStr, 'YYYY-MM-DD', 'Europe/Brussels');
|
|
54
|
+
if (!m.isValid()) return false;
|
|
55
|
+
const englishDay = daysOfWeekEnglish[m.day()];
|
|
56
|
+
|
|
57
|
+
const ohKey = `openinghours-${mealType}`;
|
|
58
|
+
const daySettings =
|
|
59
|
+
data[ohKey] &&
|
|
60
|
+
data[ohKey].schemeSettings &&
|
|
61
|
+
data[ohKey].schemeSettings[englishDay]
|
|
62
|
+
? data[ohKey].schemeSettings[englishDay]
|
|
63
|
+
: null;
|
|
64
|
+
|
|
65
|
+
if (!daySettings) return false;
|
|
66
|
+
if (daySettings.giftcardsEnabled !== true) return false;
|
|
67
|
+
if (!Array.isArray(daySettings.giftcards) || daySettings.giftcards.length === 0) return false;
|
|
68
|
+
|
|
69
|
+
return daySettings.giftcards.includes(giftcard);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Determines if a given start time plus duurReservatie fits within the meal timeframe.
|
|
74
|
+
*/
|
|
75
|
+
function fitsWithinMeal(data, dateStr, startTimeStr, duurReservatie) {
|
|
76
|
+
// Determine the meal type based on the start time
|
|
77
|
+
const mealType = getMealTypeByTime(startTimeStr);
|
|
78
|
+
if (!mealType) return false;
|
|
79
|
+
|
|
80
|
+
// Get the meal data (with exceptions applied)
|
|
81
|
+
const mealData = getDataByDateAndMealWithExceptions(data, dateStr, mealType);
|
|
82
|
+
if (!mealData) return false;
|
|
83
|
+
|
|
84
|
+
const mealStartTime = parseTime(mealData.startTime);
|
|
85
|
+
const mealEndTime = parseTime(mealData.endTime);
|
|
86
|
+
const startTime = parseTime(startTimeStr);
|
|
87
|
+
|
|
88
|
+
// Check if startTime is after or equal to mealStartTime AND startTime + duurReservatie is within the mealEndTime
|
|
89
|
+
return startTime >= mealStartTime && startTime + duurReservatie <= mealEndTime;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function timeblocksAvailable(data, dateStr, reservations, guests, blockedSlots = [], giftcard = null, isAdmin = false) {
|
|
93
|
+
const duurReservatie = getDuurReservatie(data);
|
|
94
|
+
const intervalReservatie = getInterval(data);
|
|
95
|
+
|
|
96
|
+
// Slots needed
|
|
97
|
+
const slotsNeeded = Math.ceil(duurReservatie / intervalReservatie);
|
|
98
|
+
|
|
99
|
+
// Get guest counts and shifts info
|
|
100
|
+
const { guestCounts, shiftsInfo } = getDailyGuestCounts(data, dateStr, reservations);
|
|
101
|
+
|
|
102
|
+
const availableTimeblocks = {};
|
|
103
|
+
|
|
104
|
+
// Handle shifts first
|
|
105
|
+
const mealTypesWithShifts = getMealTypesWithShifts(data, dateStr);
|
|
106
|
+
if (mealTypesWithShifts.length > 0 && shiftsInfo && shiftsInfo.length > 0) {
|
|
107
|
+
for (const shift of shiftsInfo) {
|
|
108
|
+
const { time, availableSeats } = shift;
|
|
109
|
+
if (availableSeats >= guests && fitsWithinMeal(data, dateStr, time, duurReservatie)) {
|
|
110
|
+
// Check if time matches giftcard requirement
|
|
111
|
+
if (timeHasGiftcard(data, dateStr, time, giftcard)) {
|
|
112
|
+
availableTimeblocks[time] = { name: time };
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// Handle non-shift times
|
|
119
|
+
if (guestCounts && Object.keys(guestCounts).length > 0) {
|
|
120
|
+
const timeSlots = Object.keys(guestCounts).sort((a, b) => parseTime(a) - parseTime(b));
|
|
121
|
+
|
|
122
|
+
for (let i = 0; i <= timeSlots.length - slotsNeeded; i++) {
|
|
123
|
+
// Check capacity for all needed slots
|
|
124
|
+
let consecutiveSlotsAvailable = true;
|
|
125
|
+
if (guestCounts[timeSlots[i]] < guests) {
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
let previousTime = parseTime(timeSlots[i]);
|
|
130
|
+
for (let j = 1; j < slotsNeeded; j++) {
|
|
131
|
+
const currentTimeSlot = timeSlots[i + j];
|
|
132
|
+
const currentTime = parseTime(currentTimeSlot);
|
|
133
|
+
|
|
134
|
+
// Check interval and capacity
|
|
135
|
+
if ((currentTime - previousTime) !== intervalReservatie || guestCounts[currentTimeSlot] < guests) {
|
|
136
|
+
consecutiveSlotsAvailable = false;
|
|
137
|
+
break;
|
|
138
|
+
}
|
|
139
|
+
previousTime = currentTime;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// If all consecutive slots are available, check if the full duration fits
|
|
143
|
+
if (consecutiveSlotsAvailable && fitsWithinMeal(data, dateStr, timeSlots[i], duurReservatie)) {
|
|
144
|
+
// Check if time matches giftcard requirement
|
|
145
|
+
if (timeHasGiftcard(data, dateStr, timeSlots[i], giftcard)) {
|
|
146
|
+
availableTimeblocks[timeSlots[i]] = { name: timeSlots[i] };
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// Filter out blocked time slots (skip for admin)
|
|
153
|
+
if (!isAdmin && blockedSlots && blockedSlots.length > 0) {
|
|
154
|
+
for (const blockedSlot of blockedSlots) {
|
|
155
|
+
// Check if the blocked slot matches the current date
|
|
156
|
+
if (blockedSlot.date === dateStr && blockedSlot.time) {
|
|
157
|
+
// Remove the blocked time from available timeblocks
|
|
158
|
+
delete availableTimeblocks[blockedSlot.time];
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
return availableTimeblocks;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
module.exports = {
|
|
167
|
+
timeblocksAvailable,
|
|
168
168
|
};
|
|
@@ -1,65 +1,65 @@
|
|
|
1
|
-
// counter.js
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Parses a time string in "HH:MM" format into minutes since midnight.
|
|
5
|
-
* @param {string} timeStr - The time string in "HH:MM" format.
|
|
6
|
-
* @returns {number} The time in minutes since midnight.
|
|
7
|
-
*/
|
|
8
|
-
function parseTime(timeStr) {
|
|
9
|
-
const [hours, minutes] = timeStr.split(':').map(Number);
|
|
10
|
-
return hours * 60 + minutes;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
function getDuurReservatie(data) {
|
|
14
|
-
let duurReservatie = 120;
|
|
15
|
-
if (
|
|
16
|
-
data['general-settings'] &&
|
|
17
|
-
data['general-settings'].duurReservatie &&
|
|
18
|
-
parseInt(data['general-settings'].duurReservatie, 10) > 0
|
|
19
|
-
) {
|
|
20
|
-
duurReservatie = parseInt(data['general-settings'].duurReservatie, 10);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
return duurReservatie;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Calculates the total number of guests for reservations that cover a specific hour on a specific date.
|
|
28
|
-
* @param {Object} data - The main data object containing general settings.
|
|
29
|
-
* @param {Array} reservations - An array of reservation objects.
|
|
30
|
-
* @param {string} hour - The hour to check in "HH:MM" format.
|
|
31
|
-
* @param {string} dateStr - The date string in "YYYY-MM-DD" format.
|
|
32
|
-
* @returns {number} The total number of guests for that hour on the specified date.
|
|
33
|
-
*/
|
|
34
|
-
function getGuestCountAtHour(data, reservations, hour, dateStr) {
|
|
35
|
-
// Get 'duurReservatie' from general settings, default to 120 if not set or zero
|
|
36
|
-
let duurReservatie = getDuurReservatie(data)
|
|
37
|
-
|
|
38
|
-
// Convert the target hour to minutes since midnight
|
|
39
|
-
const targetTime = parseTime(hour);
|
|
40
|
-
|
|
41
|
-
let totalGuests = 0;
|
|
42
|
-
|
|
43
|
-
for (const reservation of reservations) {
|
|
44
|
-
// Only consider reservations on the specified date
|
|
45
|
-
if (reservation.date !== dateStr) {
|
|
46
|
-
continue;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const startTime = parseTime(reservation.time);
|
|
50
|
-
|
|
51
|
-
const endTime = startTime + duurReservatie; // Use 'duurReservatie' from general settings
|
|
52
|
-
// Check if the target time is within the reservation time range
|
|
53
|
-
// Start time is inclusive, end time is exclusive
|
|
54
|
-
if (targetTime >= startTime && targetTime < endTime) {
|
|
55
|
-
totalGuests += parseInt(reservation.guests, 10);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
return totalGuests;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
module.exports = {
|
|
63
|
-
getGuestCountAtHour,
|
|
64
|
-
};
|
|
1
|
+
// counter.js
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Parses a time string in "HH:MM" format into minutes since midnight.
|
|
5
|
+
* @param {string} timeStr - The time string in "HH:MM" format.
|
|
6
|
+
* @returns {number} The time in minutes since midnight.
|
|
7
|
+
*/
|
|
8
|
+
function parseTime(timeStr) {
|
|
9
|
+
const [hours, minutes] = timeStr.split(':').map(Number);
|
|
10
|
+
return hours * 60 + minutes;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function getDuurReservatie(data) {
|
|
14
|
+
let duurReservatie = 120;
|
|
15
|
+
if (
|
|
16
|
+
data['general-settings'] &&
|
|
17
|
+
data['general-settings'].duurReservatie &&
|
|
18
|
+
parseInt(data['general-settings'].duurReservatie, 10) > 0
|
|
19
|
+
) {
|
|
20
|
+
duurReservatie = parseInt(data['general-settings'].duurReservatie, 10);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return duurReservatie;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Calculates the total number of guests for reservations that cover a specific hour on a specific date.
|
|
28
|
+
* @param {Object} data - The main data object containing general settings.
|
|
29
|
+
* @param {Array} reservations - An array of reservation objects.
|
|
30
|
+
* @param {string} hour - The hour to check in "HH:MM" format.
|
|
31
|
+
* @param {string} dateStr - The date string in "YYYY-MM-DD" format.
|
|
32
|
+
* @returns {number} The total number of guests for that hour on the specified date.
|
|
33
|
+
*/
|
|
34
|
+
function getGuestCountAtHour(data, reservations, hour, dateStr) {
|
|
35
|
+
// Get 'duurReservatie' from general settings, default to 120 if not set or zero
|
|
36
|
+
let duurReservatie = getDuurReservatie(data)
|
|
37
|
+
|
|
38
|
+
// Convert the target hour to minutes since midnight
|
|
39
|
+
const targetTime = parseTime(hour);
|
|
40
|
+
|
|
41
|
+
let totalGuests = 0;
|
|
42
|
+
|
|
43
|
+
for (const reservation of reservations) {
|
|
44
|
+
// Only consider reservations on the specified date
|
|
45
|
+
if (reservation.date !== dateStr) {
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const startTime = parseTime(reservation.time);
|
|
50
|
+
|
|
51
|
+
const endTime = startTime + duurReservatie; // Use 'duurReservatie' from general settings
|
|
52
|
+
// Check if the target time is within the reservation time range
|
|
53
|
+
// Start time is inclusive, end time is exclusive
|
|
54
|
+
if (targetTime >= startTime && targetTime < endTime) {
|
|
55
|
+
totalGuests += parseInt(reservation.guests, 10);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return totalGuests;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
module.exports = {
|
|
63
|
+
getGuestCountAtHour,
|
|
64
|
+
};
|
|
65
65
|
|