@happychef/algorithm 1.3.2 → 1.4.0
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/.claude/settings.local.json +16 -0
- package/.github/workflows/ci-cd.yml +80 -80
- package/BRANCH_PROTECTION_SETUP.md +167 -167
- package/CHANGELOG.md +8 -8
- package/README.md +144 -144
- package/RESERVERINGEN_GIDS.md +986 -986
- package/__tests__/crossMidnight.test.js +63 -0
- package/__tests__/crossMidnightTimeblocks.test.js +312 -0
- package/__tests__/edgeCases.test.js +271 -0
- package/__tests__/filters.test.js +276 -276
- package/__tests__/isDateAvailable.test.js +179 -175
- package/__tests__/isTimeAvailable.test.js +174 -168
- package/__tests__/restaurantData.test.js +422 -422
- package/__tests__/tableHelpers.test.js +247 -247
- package/assignTables.js +506 -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__.md +20 -0
- package/changes/2026/February/PR16_add_getDateClosingReasons.md +31 -31
- 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/dateHelpers.js +31 -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/getDateClosingReasons.js +193 -193
- package/grouping.js +162 -162
- package/index.js +48 -43
- package/isDateAvailable.js +80 -80
- package/isDateAvailableWithTableCheck.js +172 -172
- package/isTimeAvailable.js +26 -26
- package/jest.config.js +23 -23
- package/package.json +27 -27
- package/processing/dailyGuestCounts.js +73 -73
- package/processing/mealTypeCount.js +133 -133
- package/processing/timeblocksAvailable.js +344 -182
- package/reservation_data/counter.js +82 -75
- package/restaurant_data/exceptions.js +150 -150
- package/restaurant_data/openinghours.js +142 -142
- package/simulateTableAssignment.js +833 -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-detailed-filter.js +100 -100
- package/test-lunch-debug.js +110 -110
- package/test-max-arrivals-filter.js +79 -79
- package/test-meal-stop-fix.js +147 -147
- package/test-meal-stop-simple.js +93 -93
- package/test-timezone-debug.js +47 -47
- package/test.js +336 -336
|
@@ -1,75 +1,82 @@
|
|
|
1
|
-
// counter.js
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
*
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
1
|
+
// counter.js
|
|
2
|
+
|
|
3
|
+
const { getPrevDateStr } = require('../dateHelpers');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Parses a time string in "HH:MM" format into minutes since midnight.
|
|
7
|
+
* @param {string} timeStr - The time string in "HH:MM" format.
|
|
8
|
+
* @returns {number} The time in minutes since midnight.
|
|
9
|
+
*/
|
|
10
|
+
function parseTime(timeStr) {
|
|
11
|
+
const [hours, minutes] = timeStr.split(':').map(Number);
|
|
12
|
+
return hours * 60 + minutes;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function getDuurReservatie(data) {
|
|
16
|
+
let duurReservatie = 120;
|
|
17
|
+
if (
|
|
18
|
+
data['general-settings'] &&
|
|
19
|
+
data['general-settings'].duurReservatie &&
|
|
20
|
+
parseInt(data['general-settings'].duurReservatie, 10) > 0
|
|
21
|
+
) {
|
|
22
|
+
duurReservatie = parseInt(data['general-settings'].duurReservatie, 10);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return duurReservatie;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Parses a reservation's duration, falling back to the default.
|
|
30
|
+
*/
|
|
31
|
+
function getReservationDuration(reservation, defaultDuration) {
|
|
32
|
+
if (reservation.duration) {
|
|
33
|
+
const rawDur = reservation.duration.$numberInt ?? reservation.duration;
|
|
34
|
+
const parsed = parseInt(rawDur, 10);
|
|
35
|
+
if (!isNaN(parsed) && parsed > 0) {
|
|
36
|
+
return parsed;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return defaultDuration;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Calculates the total number of guests for reservations that cover a specific hour on a specific date.
|
|
44
|
+
* Also includes guests from previous-day reservations whose duration extends past midnight.
|
|
45
|
+
* @param {Object} data - The main data object containing general settings.
|
|
46
|
+
* @param {Array} reservations - An array of reservation objects.
|
|
47
|
+
* @param {string} hour - The hour to check in "HH:MM" format.
|
|
48
|
+
* @param {string} dateStr - The date string in "YYYY-MM-DD" format.
|
|
49
|
+
* @returns {number} The total number of guests for that hour on the specified date.
|
|
50
|
+
*/
|
|
51
|
+
function getGuestCountAtHour(data, reservations, hour, dateStr) {
|
|
52
|
+
const duurReservatie = getDuurReservatie(data);
|
|
53
|
+
const targetTime = parseTime(hour);
|
|
54
|
+
const prevDateStr = getPrevDateStr(dateStr);
|
|
55
|
+
|
|
56
|
+
let totalGuests = 0;
|
|
57
|
+
|
|
58
|
+
for (const reservation of reservations) {
|
|
59
|
+
const startTime = parseTime(reservation.time);
|
|
60
|
+
const rDuration = getReservationDuration(reservation, duurReservatie);
|
|
61
|
+
const endTime = startTime + rDuration;
|
|
62
|
+
|
|
63
|
+
if (reservation.date === dateStr) {
|
|
64
|
+
// Same-day reservation
|
|
65
|
+
if (targetTime >= startTime && targetTime < endTime) {
|
|
66
|
+
totalGuests += parseInt(reservation.guests, 10);
|
|
67
|
+
}
|
|
68
|
+
} else if (reservation.date === prevDateStr && endTime > 1440) {
|
|
69
|
+
// Previous-day reservation that crosses midnight
|
|
70
|
+
const spilloverEnd = endTime - 1440;
|
|
71
|
+
if (targetTime < spilloverEnd) {
|
|
72
|
+
totalGuests += parseInt(reservation.guests, 10);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return totalGuests;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
module.exports = {
|
|
81
|
+
getGuestCountAtHour,
|
|
82
|
+
};
|
|
@@ -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
|
+
};
|