@happychef/algorithm 1.2.32 → 1.3.2
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 +80 -80
- package/CHANGELOG.md +8 -8
- package/RESERVERINGEN_GIDS.md +986 -986
- package/assignTables.js +444 -444
- 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 +15 -15
- package/changes/2025/December/PR5___.md +15 -15
- package/changes/2025/December/PR6__del_.md +17 -17
- package/changes/2025/December/PR7_add__change.md +21 -21
- package/changes/2026/February/PR15_add__change.md +21 -21
- package/changes/2026/February/PR16_add_getDateClosingReasons.md +31 -0
- package/changes/2026/January/PR10_add__change.md +21 -21
- package/changes/2026/January/PR11_add__change.md +19 -19
- package/changes/2026/January/PR12_add__.md +21 -21
- package/changes/2026/January/PR13_add__change.md +20 -20
- package/changes/2026/January/PR14_add__change.md +19 -19
- package/changes/2026/January/PR8_add__change.md +38 -38
- package/changes/2026/January/PR9_add__change.md +19 -19
- package/filters/maxArrivalsFilter.js +114 -114
- package/filters/maxGroupsFilter.js +221 -221
- package/filters/timeFilter.js +89 -89
- package/getAvailableTimeblocks.js +158 -158
- package/getDateClosingReasons.js +193 -0
- package/grouping.js +162 -162
- package/index.js +43 -42
- package/isDateAvailable.js +80 -80
- package/isDateAvailableWithTableCheck.js +172 -172
- package/isTimeAvailable.js +26 -26
- package/package.json +27 -27
- package/processing/dailyGuestCounts.js +73 -73
- package/processing/mealTypeCount.js +133 -133
- package/processing/timeblocksAvailable.js +182 -182
- package/reservation_data/counter.js +74 -74
- package/restaurant_data/exceptions.js +150 -150
- package/restaurant_data/openinghours.js +142 -156
- package/simulateTableAssignment.js +726 -726
- package/tableHelpers.js +209 -209
- 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
- package/bundle_entry.js +0 -100
- package/moment-timezone-shim.js +0 -179
- package/nul +0 -0
|
@@ -1,75 +1,75 @@
|
|
|
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
|
-
// Use reservation specific duration if available, else default
|
|
52
|
-
let rDuration = duurReservatie;
|
|
53
|
-
if (reservation.duration) {
|
|
54
|
-
const rawDur = reservation.duration.$numberInt ?? reservation.duration;
|
|
55
|
-
const parsed = parseInt(rawDur, 10);
|
|
56
|
-
if (!isNaN(parsed) && parsed > 0) {
|
|
57
|
-
rDuration = parsed;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
const endTime = startTime + rDuration;
|
|
62
|
-
// Check if the target time is within the reservation time range
|
|
63
|
-
// Start time is inclusive, end time is exclusive
|
|
64
|
-
if (targetTime >= startTime && targetTime < endTime) {
|
|
65
|
-
totalGuests += parseInt(reservation.guests, 10);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
return totalGuests;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
module.exports = {
|
|
73
|
-
getGuestCountAtHour,
|
|
74
|
-
};
|
|
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
|
+
// Use reservation specific duration if available, else default
|
|
52
|
+
let rDuration = duurReservatie;
|
|
53
|
+
if (reservation.duration) {
|
|
54
|
+
const rawDur = reservation.duration.$numberInt ?? reservation.duration;
|
|
55
|
+
const parsed = parseInt(rawDur, 10);
|
|
56
|
+
if (!isNaN(parsed) && parsed > 0) {
|
|
57
|
+
rDuration = parsed;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const endTime = startTime + rDuration;
|
|
62
|
+
// Check if the target time is within the reservation time range
|
|
63
|
+
// Start time is inclusive, end time is exclusive
|
|
64
|
+
if (targetTime >= startTime && targetTime < endTime) {
|
|
65
|
+
totalGuests += parseInt(reservation.guests, 10);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return totalGuests;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
module.exports = {
|
|
73
|
+
getGuestCountAtHour,
|
|
74
|
+
};
|
|
75
75
|
|
|
@@ -1,150 +1,150 @@
|
|
|
1
|
-
// exceptions.js
|
|
2
|
-
|
|
3
|
-
const {
|
|
4
|
-
getDataByDateAndMeal,
|
|
5
|
-
getDataByDateAndTime,
|
|
6
|
-
getMealTypeByTime,
|
|
7
|
-
parseTime,
|
|
8
|
-
parseDateString,
|
|
9
|
-
shifts,
|
|
10
|
-
daysOfWeekEnglish,
|
|
11
|
-
daysOfWeekDutch,
|
|
12
|
-
} = require('./openinghours');
|
|
13
|
-
|
|
14
|
-
function isDateInRange(dateStr, startDateStr, endDateStr) {
|
|
15
|
-
const date = parseDateString(dateStr);
|
|
16
|
-
const startDate = parseDateString(startDateStr);
|
|
17
|
-
const endDate = parseDateString(endDateStr);
|
|
18
|
-
if (isNaN(date) || isNaN(startDate) || isNaN(endDate)) {
|
|
19
|
-
return false;
|
|
20
|
-
}
|
|
21
|
-
return date >= startDate && date <= endDate;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function getDutchDayOfWeek(date) {
|
|
25
|
-
const dayIndex = date.getDay();
|
|
26
|
-
return daysOfWeekDutch[dayIndex];
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function doesExceptionApply(exception, dateStr, dateDayOfWeekDutch, mealType) {
|
|
30
|
-
const { timeframe, startDate, endDate, daysOfWeek } = exception;
|
|
31
|
-
|
|
32
|
-
if (!isDateInRange(dateStr, startDate, endDate)) {
|
|
33
|
-
return false;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
if (Array.isArray(daysOfWeek) && daysOfWeek.length > 0) {
|
|
37
|
-
const daysOfWeekLower = daysOfWeek.map(day => day.toLowerCase());
|
|
38
|
-
if (!daysOfWeekLower.includes(dateDayOfWeekDutch)) {
|
|
39
|
-
return false;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
if (timeframe === 'Volledige Dag' || timeframe === mealType) {
|
|
44
|
-
return true;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
return false;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function getDuurReservatie(data) {
|
|
51
|
-
let duurReservatie = 120;
|
|
52
|
-
if (
|
|
53
|
-
data['general-settings'] &&
|
|
54
|
-
data['general-settings'].duurReservatie &&
|
|
55
|
-
parseInt(data['general-settings'].duurReservatie, 10) > 0
|
|
56
|
-
) {
|
|
57
|
-
duurReservatie = parseInt(data['general-settings'].duurReservatie, 10);
|
|
58
|
-
}
|
|
59
|
-
return duurReservatie;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
function addDuurReservatieToEndTime(mealData, data) {
|
|
63
|
-
const duurReservatie = getDuurReservatie(data);
|
|
64
|
-
const endMinutes = parseTime(mealData.endTime);
|
|
65
|
-
const newEndMinutes = endMinutes + duurReservatie;
|
|
66
|
-
const hours = String(Math.floor(newEndMinutes / 60)).padStart(2, '0');
|
|
67
|
-
const minutes = String(newEndMinutes % 60).padStart(2, '0');
|
|
68
|
-
mealData.endTime = `${hours}:${minutes}`;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
function mapExceptionToMealData(exception, data) {
|
|
72
|
-
let mealData = {
|
|
73
|
-
enabled: true,
|
|
74
|
-
startTime: exception.startHour,
|
|
75
|
-
endTime: exception.endHour,
|
|
76
|
-
maxCapacityEnabled: exception.maxSeats ? true : false,
|
|
77
|
-
maxCapacity: exception.maxSeats || null,
|
|
78
|
-
shiftsEnabled: false,
|
|
79
|
-
shifts: [],
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
// Add duurReservatie to endTime
|
|
83
|
-
addDuurReservatieToEndTime(mealData, data);
|
|
84
|
-
|
|
85
|
-
return mealData;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
function getDataByDateAndMealWithExceptions(data, dateStr, mealType) {
|
|
89
|
-
const exceptions = data.exceptions || [];
|
|
90
|
-
const date = parseDateString(dateStr);
|
|
91
|
-
if (isNaN(date)) {
|
|
92
|
-
return null;
|
|
93
|
-
}
|
|
94
|
-
const dateDayOfWeekDutch = getDutchDayOfWeek(date).toLowerCase();
|
|
95
|
-
|
|
96
|
-
const exceptionTypesPriority = ['Opening', 'Sluiting', 'Uitzondering'];
|
|
97
|
-
|
|
98
|
-
for (const exceptionType of exceptionTypesPriority) {
|
|
99
|
-
for (const exception of exceptions) {
|
|
100
|
-
if (exception.type === exceptionType) {
|
|
101
|
-
if (doesExceptionApply(exception, dateStr, dateDayOfWeekDutch, mealType)) {
|
|
102
|
-
if (exceptionType === 'Sluiting') {
|
|
103
|
-
return null;
|
|
104
|
-
} else {
|
|
105
|
-
return mapExceptionToMealData(exception, data);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
return getDataByDateAndMeal(data, dateStr, mealType);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
function shouldIncludeEndTime(mealType, endTime) {
|
|
116
|
-
if ((mealType === 'breakfast' && endTime === '11:00') ||
|
|
117
|
-
(mealType === 'lunch' && endTime === '16:00')) {
|
|
118
|
-
return false;
|
|
119
|
-
}
|
|
120
|
-
return true;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
function getDataByDateAndTimeWithExceptions(data, dateStr, timeStr) {
|
|
124
|
-
const mealType = getMealTypeByTime(timeStr);
|
|
125
|
-
if (!mealType) {
|
|
126
|
-
return null;
|
|
127
|
-
}
|
|
128
|
-
const mealData = getDataByDateAndMealWithExceptions(data, dateStr, mealType);
|
|
129
|
-
if (!mealData) {
|
|
130
|
-
return null;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
const requestedTime = parseTime(timeStr);
|
|
134
|
-
const startTime = parseTime(mealData.startTime);
|
|
135
|
-
const endTime = parseTime(mealData.endTime);
|
|
136
|
-
|
|
137
|
-
const includeEndTime = shouldIncludeEndTime(mealType, mealData.endTime);
|
|
138
|
-
|
|
139
|
-
const timeFallsWithin =
|
|
140
|
-
includeEndTime
|
|
141
|
-
? requestedTime >= startTime && requestedTime <= endTime
|
|
142
|
-
: requestedTime >= startTime && requestedTime < endTime;
|
|
143
|
-
|
|
144
|
-
return timeFallsWithin ? mealData : null;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
module.exports = {
|
|
148
|
-
getDataByDateAndMealWithExceptions,
|
|
149
|
-
getDataByDateAndTimeWithExceptions,
|
|
150
|
-
};
|
|
1
|
+
// exceptions.js
|
|
2
|
+
|
|
3
|
+
const {
|
|
4
|
+
getDataByDateAndMeal,
|
|
5
|
+
getDataByDateAndTime,
|
|
6
|
+
getMealTypeByTime,
|
|
7
|
+
parseTime,
|
|
8
|
+
parseDateString,
|
|
9
|
+
shifts,
|
|
10
|
+
daysOfWeekEnglish,
|
|
11
|
+
daysOfWeekDutch,
|
|
12
|
+
} = require('./openinghours');
|
|
13
|
+
|
|
14
|
+
function isDateInRange(dateStr, startDateStr, endDateStr) {
|
|
15
|
+
const date = parseDateString(dateStr);
|
|
16
|
+
const startDate = parseDateString(startDateStr);
|
|
17
|
+
const endDate = parseDateString(endDateStr);
|
|
18
|
+
if (isNaN(date) || isNaN(startDate) || isNaN(endDate)) {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
return date >= startDate && date <= endDate;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function getDutchDayOfWeek(date) {
|
|
25
|
+
const dayIndex = date.getDay();
|
|
26
|
+
return daysOfWeekDutch[dayIndex];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function doesExceptionApply(exception, dateStr, dateDayOfWeekDutch, mealType) {
|
|
30
|
+
const { timeframe, startDate, endDate, daysOfWeek } = exception;
|
|
31
|
+
|
|
32
|
+
if (!isDateInRange(dateStr, startDate, endDate)) {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (Array.isArray(daysOfWeek) && daysOfWeek.length > 0) {
|
|
37
|
+
const daysOfWeekLower = daysOfWeek.map(day => day.toLowerCase());
|
|
38
|
+
if (!daysOfWeekLower.includes(dateDayOfWeekDutch)) {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (timeframe === 'Volledige Dag' || timeframe === mealType) {
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function getDuurReservatie(data) {
|
|
51
|
+
let duurReservatie = 120;
|
|
52
|
+
if (
|
|
53
|
+
data['general-settings'] &&
|
|
54
|
+
data['general-settings'].duurReservatie &&
|
|
55
|
+
parseInt(data['general-settings'].duurReservatie, 10) > 0
|
|
56
|
+
) {
|
|
57
|
+
duurReservatie = parseInt(data['general-settings'].duurReservatie, 10);
|
|
58
|
+
}
|
|
59
|
+
return duurReservatie;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function addDuurReservatieToEndTime(mealData, data) {
|
|
63
|
+
const duurReservatie = getDuurReservatie(data);
|
|
64
|
+
const endMinutes = parseTime(mealData.endTime);
|
|
65
|
+
const newEndMinutes = endMinutes + duurReservatie;
|
|
66
|
+
const hours = String(Math.floor(newEndMinutes / 60)).padStart(2, '0');
|
|
67
|
+
const minutes = String(newEndMinutes % 60).padStart(2, '0');
|
|
68
|
+
mealData.endTime = `${hours}:${minutes}`;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function mapExceptionToMealData(exception, data) {
|
|
72
|
+
let mealData = {
|
|
73
|
+
enabled: true,
|
|
74
|
+
startTime: exception.startHour,
|
|
75
|
+
endTime: exception.endHour,
|
|
76
|
+
maxCapacityEnabled: exception.maxSeats ? true : false,
|
|
77
|
+
maxCapacity: exception.maxSeats || null,
|
|
78
|
+
shiftsEnabled: false,
|
|
79
|
+
shifts: [],
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
// Add duurReservatie to endTime
|
|
83
|
+
addDuurReservatieToEndTime(mealData, data);
|
|
84
|
+
|
|
85
|
+
return mealData;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function getDataByDateAndMealWithExceptions(data, dateStr, mealType) {
|
|
89
|
+
const exceptions = data.exceptions || [];
|
|
90
|
+
const date = parseDateString(dateStr);
|
|
91
|
+
if (isNaN(date)) {
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
const dateDayOfWeekDutch = getDutchDayOfWeek(date).toLowerCase();
|
|
95
|
+
|
|
96
|
+
const exceptionTypesPriority = ['Opening', 'Sluiting', 'Uitzondering'];
|
|
97
|
+
|
|
98
|
+
for (const exceptionType of exceptionTypesPriority) {
|
|
99
|
+
for (const exception of exceptions) {
|
|
100
|
+
if (exception.type === exceptionType) {
|
|
101
|
+
if (doesExceptionApply(exception, dateStr, dateDayOfWeekDutch, mealType)) {
|
|
102
|
+
if (exceptionType === 'Sluiting') {
|
|
103
|
+
return null;
|
|
104
|
+
} else {
|
|
105
|
+
return mapExceptionToMealData(exception, data);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return getDataByDateAndMeal(data, dateStr, mealType);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function shouldIncludeEndTime(mealType, endTime) {
|
|
116
|
+
if ((mealType === 'breakfast' && endTime === '11:00') ||
|
|
117
|
+
(mealType === 'lunch' && endTime === '16:00')) {
|
|
118
|
+
return false;
|
|
119
|
+
}
|
|
120
|
+
return true;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function getDataByDateAndTimeWithExceptions(data, dateStr, timeStr) {
|
|
124
|
+
const mealType = getMealTypeByTime(timeStr);
|
|
125
|
+
if (!mealType) {
|
|
126
|
+
return null;
|
|
127
|
+
}
|
|
128
|
+
const mealData = getDataByDateAndMealWithExceptions(data, dateStr, mealType);
|
|
129
|
+
if (!mealData) {
|
|
130
|
+
return null;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const requestedTime = parseTime(timeStr);
|
|
134
|
+
const startTime = parseTime(mealData.startTime);
|
|
135
|
+
const endTime = parseTime(mealData.endTime);
|
|
136
|
+
|
|
137
|
+
const includeEndTime = shouldIncludeEndTime(mealType, mealData.endTime);
|
|
138
|
+
|
|
139
|
+
const timeFallsWithin =
|
|
140
|
+
includeEndTime
|
|
141
|
+
? requestedTime >= startTime && requestedTime <= endTime
|
|
142
|
+
: requestedTime >= startTime && requestedTime < endTime;
|
|
143
|
+
|
|
144
|
+
return timeFallsWithin ? mealData : null;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
module.exports = {
|
|
148
|
+
getDataByDateAndMealWithExceptions,
|
|
149
|
+
getDataByDateAndTimeWithExceptions,
|
|
150
|
+
};
|