@happychef/algorithm 1.3.0 → 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.
Files changed (71) hide show
  1. package/.claude/settings.local.json +16 -0
  2. package/.github/workflows/ci-cd.yml +80 -80
  3. package/BRANCH_PROTECTION_SETUP.md +167 -167
  4. package/CHANGELOG.md +8 -8
  5. package/README.md +144 -144
  6. package/RESERVERINGEN_GIDS.md +986 -986
  7. package/__tests__/crossMidnight.test.js +63 -0
  8. package/__tests__/crossMidnightTimeblocks.test.js +312 -0
  9. package/__tests__/edgeCases.test.js +271 -0
  10. package/__tests__/filters.test.js +276 -276
  11. package/__tests__/isDateAvailable.test.js +179 -175
  12. package/__tests__/isTimeAvailable.test.js +174 -168
  13. package/__tests__/restaurantData.test.js +422 -422
  14. package/__tests__/tableHelpers.test.js +247 -247
  15. package/assignTables.js +506 -444
  16. package/changes/2025/December/PR2___change.md +14 -14
  17. package/changes/2025/December/PR3_add__change.md +20 -20
  18. package/changes/2025/December/PR4___.md +15 -15
  19. package/changes/2025/December/PR5___.md +15 -15
  20. package/changes/2025/December/PR6__del_.md +17 -17
  21. package/changes/2025/December/PR7_add__change.md +21 -21
  22. package/changes/2026/February/PR15_add__change.md +21 -21
  23. package/changes/2026/February/PR16_add__.md +20 -0
  24. package/changes/2026/February/PR16_add_getDateClosingReasons.md +31 -31
  25. package/changes/2026/January/PR10_add__change.md +21 -21
  26. package/changes/2026/January/PR11_add__change.md +19 -19
  27. package/changes/2026/January/PR12_add__.md +21 -21
  28. package/changes/2026/January/PR13_add__change.md +20 -20
  29. package/changes/2026/January/PR14_add__change.md +19 -19
  30. package/changes/2026/January/PR8_add__change.md +38 -38
  31. package/changes/2026/January/PR9_add__change.md +19 -19
  32. package/dateHelpers.js +31 -0
  33. package/filters/maxArrivalsFilter.js +114 -114
  34. package/filters/maxGroupsFilter.js +221 -221
  35. package/filters/timeFilter.js +89 -89
  36. package/getAvailableTimeblocks.js +158 -158
  37. package/getDateClosingReasons.js +193 -193
  38. package/grouping.js +162 -162
  39. package/index.js +48 -43
  40. package/isDateAvailable.js +80 -80
  41. package/isDateAvailableWithTableCheck.js +172 -172
  42. package/isTimeAvailable.js +26 -26
  43. package/jest.config.js +23 -23
  44. package/package.json +27 -27
  45. package/processing/dailyGuestCounts.js +73 -73
  46. package/processing/mealTypeCount.js +133 -133
  47. package/processing/timeblocksAvailable.js +344 -182
  48. package/reservation_data/counter.js +82 -75
  49. package/restaurant_data/exceptions.js +150 -150
  50. package/restaurant_data/openinghours.js +142 -142
  51. package/simulateTableAssignment.js +833 -726
  52. package/tableHelpers.js +209 -209
  53. package/tables/time/parseTime.js +19 -19
  54. package/tables/time/shifts.js +7 -7
  55. package/tables/utils/calculateDistance.js +13 -13
  56. package/tables/utils/isTableFreeForAllSlots.js +14 -14
  57. package/tables/utils/isTemporaryTableValid.js +39 -39
  58. package/test/test_counter.js +194 -194
  59. package/test/test_dailyCount.js +81 -81
  60. package/test/test_datesAvailable.js +106 -106
  61. package/test/test_exceptions.js +172 -172
  62. package/test/test_isDateAvailable.js +330 -330
  63. package/test/test_mealTypeCount.js +54 -54
  64. package/test/test_timesAvailable.js +88 -88
  65. package/test-detailed-filter.js +100 -100
  66. package/test-lunch-debug.js +110 -110
  67. package/test-max-arrivals-filter.js +79 -79
  68. package/test-meal-stop-fix.js +147 -147
  69. package/test-meal-stop-simple.js +93 -93
  70. package/test-timezone-debug.js +47 -47
  71. package/test.js +336 -336
package/tableHelpers.js CHANGED
@@ -1,209 +1,209 @@
1
- // file: client side ./algorithm/tableHelpers.js
2
-
3
- // --- Time and Shift Helpers ---
4
-
5
- /**
6
- * Parses a time string ("HH:MM") into minutes since midnight.
7
- * Returns NaN if the format is invalid.
8
- */
9
- function parseTime(timeStr) {
10
- if (!timeStr || typeof timeStr !== 'string') return NaN;
11
- const parts = timeStr.split(':');
12
- if (parts.length !== 2) return NaN;
13
- const hours = parseInt(parts[0], 10);
14
- const minutes = parseInt(parts[1], 10);
15
- if (isNaN(hours) || isNaN(minutes) || hours < 0 || hours > 23 || minutes < 0 || minutes > 59) {
16
- return NaN;
17
- }
18
- return hours * 60 + minutes;
19
- }
20
-
21
- const shifts = {
22
- breakfast: { start: '07:00', end: '11:00' },
23
- lunch: { start: '11:00', end: '16:00' },
24
- dinner: { start: '16:00', end: '23:00' }, // Adjust end time if needed
25
- };
26
-
27
- /**
28
- * Determines the meal type ('breakfast', 'lunch', 'dinner') for a given time string ("HH:MM").
29
- * Returns null if the time doesn't fall into a defined shift.
30
- */
31
- function getMealTypeByTime(timeStr) {
32
- const time = parseTime(timeStr);
33
- if (isNaN(time)) return null;
34
-
35
- for (const [mealType, shift] of Object.entries(shifts)) {
36
- const start = parseTime(shift.start);
37
- const end = parseTime(shift.end);
38
- // Handle potential errors from parseTime if shift definitions are invalid
39
- if (isNaN(start) || isNaN(end)) continue;
40
-
41
- // Check if time falls within the shift range [start, end)
42
- if (time >= start && time < end) {
43
- return mealType;
44
- }
45
- }
46
- return null; // Return null if no matching shift is found
47
- }
48
-
49
-
50
- // --- Table Fetching ---
51
-
52
- /**
53
- * Gets the floor ID linked to a seat place from seatAreaFloorLinks.
54
- * Mirrors the server-side getFloorIdForSeatPlace in assignTables.js.
55
- * @param {Object} restaurantData - The restaurant data object.
56
- * @param {string} seatPlace - The seat place identifier (zitplaats).
57
- * @returns {string|null} The floor ID or null if not found.
58
- */
59
- function getFloorIdForSeatPlace(restaurantData, seatPlace) {
60
- if (!seatPlace || !restaurantData) return null;
61
- const seatAreaFloorLinks = restaurantData["general-settings"]?.seatAreaFloorLinks;
62
- if (!seatAreaFloorLinks || typeof seatAreaFloorLinks !== 'object') return null;
63
- return seatAreaFloorLinks[seatPlace] || null;
64
- }
65
-
66
- /**
67
- * Extracts and processes table data from the restaurantData object.
68
- * Includes temporary table properties and sorts tables.
69
- * When selectedZitplaats is provided and has a linked floor via seatAreaFloorLinks,
70
- * only tables from that linked floor are returned (matching server-side behavior).
71
- * @param {Object} restaurantData - The main restaurant data object.
72
- * @param {string|null} selectedZitplaats - Optional seat place to filter by linked floor.
73
- * @returns {Array} An array of processed table objects.
74
- */
75
- function getAllTables(restaurantData, selectedZitplaats) {
76
- let allTables = [];
77
- if (restaurantData?.floors && Array.isArray(restaurantData.floors)) {
78
- // If a zitplaats is specified and has a floor link, only use that floor
79
- let floorsToUse = restaurantData.floors;
80
- if (selectedZitplaats) {
81
- const linkedFloorId = getFloorIdForSeatPlace(restaurantData, selectedZitplaats);
82
- if (linkedFloorId) {
83
- const linkedFloor = restaurantData.floors.find(f => f.id === linkedFloorId);
84
- if (linkedFloor) {
85
- floorsToUse = [linkedFloor];
86
- console.log(`[getAllTables] Floor link found: zitplaats '${selectedZitplaats}' -> floor '${linkedFloorId}'`);
87
- }
88
- }
89
- }
90
-
91
- floorsToUse.forEach(floor => {
92
- if (floor?.tables && Array.isArray(floor.tables)) {
93
- floor.tables.forEach(tbl => {
94
- // Ensure table number, capacities, priority exist before parsing
95
- const tableNumberRaw = tbl.tableNumber?.$numberInt ?? tbl.tableNumber;
96
- const minCapacityRaw = tbl.minCapacity?.$numberInt ?? tbl.minCapacity;
97
- const maxCapacityRaw = tbl.maxCapacity?.$numberInt ?? tbl.maxCapacity;
98
- const priorityRaw = tbl.priority?.$numberInt ?? tbl.priority;
99
- const xRaw = tbl.x?.$numberInt ?? tbl.x;
100
- const yRaw = tbl.y?.$numberInt ?? tbl.y;
101
-
102
- if (tbl.objectType === "Tafel" &&
103
- tableNumberRaw !== undefined &&
104
- minCapacityRaw !== undefined &&
105
- maxCapacityRaw !== undefined &&
106
- priorityRaw !== undefined &&
107
- xRaw !== undefined &&
108
- yRaw !== undefined)
109
- {
110
- allTables.push({
111
- tableId: tbl.id,
112
- tableNumber: parseInt(tableNumberRaw, 10),
113
- minCapacity: parseInt(minCapacityRaw, 10),
114
- maxCapacity: parseInt(maxCapacityRaw, 10),
115
- priority: parseInt(priorityRaw, 10),
116
- x: parseInt(xRaw, 10),
117
- y: parseInt(yRaw, 10),
118
- isTemporary: tbl.isTemporary === true, // Ensure boolean
119
- startDate: tbl.startDate || null, // Expects 'YYYY-MM-DD'
120
- endDate: tbl.endDate || null, // Expects 'YYYY-MM-DD'
121
- application: tbl.application || null // Expects 'breakfast', 'lunch', or 'dinner'
122
- });
123
- } else if (tbl.objectType === "Tafel") {
124
- console.warn(`Skipping table due to missing essential properties: ${JSON.stringify(tbl)}`);
125
- }
126
- });
127
- }
128
- });
129
- } else {
130
- console.warn("Restaurant data is missing 'floors' array.");
131
- }
132
-
133
- // Sort tables
134
- allTables.sort((a, b) => {
135
- if (a.maxCapacity !== b.maxCapacity) {
136
- return a.maxCapacity - b.maxCapacity;
137
- }
138
- if (a.priority !== b.priority) {
139
- // Assuming lower priority number means higher priority
140
- return a.priority - b.priority;
141
- }
142
- return a.minCapacity - b.minCapacity;
143
- });
144
-
145
- // Filter out tables where parsing failed (resulted in NaN)
146
- allTables = allTables.filter(t =>
147
- !isNaN(t.tableNumber) &&
148
- !isNaN(t.minCapacity) &&
149
- !isNaN(t.maxCapacity) &&
150
- !isNaN(t.priority) &&
151
- !isNaN(t.x) &&
152
- !isNaN(t.y)
153
- );
154
-
155
- return allTables;
156
- }
157
-
158
-
159
- // --- Temporary Table Validation ---
160
-
161
- /**
162
- * Checks if a temporary table is valid for a specific reservation date and time.
163
- * @param {Object} table - The table object (must include isTemporary, startDate, endDate, application).
164
- * @param {string} reservationDateStr - The date of the reservation ("YYYY-MM-DD").
165
- * @param {string} reservationTimeStr - The time of the reservation ("HH:MM").
166
- * @returns {boolean} True if the table is valid, false otherwise.
167
- */
168
- function isTemporaryTableValid(table, reservationDateStr, reservationTimeStr) {
169
- if (!table.isTemporary) {
170
- return true; // Not temporary, always valid (subject to other checks like availability)
171
- }
172
-
173
- // Check date range
174
- if (!table.startDate || !table.endDate) {
175
- console.log(`Temporary Table ${table.tableNumber} skipped: Missing start/end date.`);
176
- return false; // Invalid temporary table definition
177
- }
178
- // Basic date string comparison (YYYY-MM-DD format)
179
- if (reservationDateStr < table.startDate || reservationDateStr > table.endDate) {
180
- // console.log(`Temporary Table ${table.tableNumber} skipped: Date ${reservationDateStr} outside range ${table.startDate}-${table.endDate}.`); // Optional verbose logging
181
- return false;
182
- }
183
-
184
- // Check application (meal type/shift)
185
- const reservationMealType = getMealTypeByTime(reservationTimeStr);
186
- if (!reservationMealType) {
187
- console.log(`Temporary Table ${table.tableNumber} skipped: Could not determine meal type for time ${reservationTimeStr}.`);
188
- return false; // Cannot determine meal type for the reservation
189
- }
190
- if (table.application !== reservationMealType) {
191
- // console.log(`Temporary Table ${table.tableNumber} skipped: Application '${table.application}' does not match reservation meal type '${reservationMealType}'.`); // Optional verbose logging
192
- return false;
193
- }
194
-
195
- // console.log(`Temporary Table ${table.tableNumber} is valid for ${reservationDateStr} at ${reservationTimeStr} (${reservationMealType}).`); // Optional verbose logging
196
- return true;
197
- }
198
-
199
-
200
- // --- Exports ---
201
- // Use CommonJS exports (adjust if using ES6 modules)
202
- module.exports = {
203
- shifts,
204
- parseTime,
205
- getMealTypeByTime,
206
- getAllTables,
207
- getFloorIdForSeatPlace,
208
- isTemporaryTableValid
209
- };
1
+ // file: client side ./algorithm/tableHelpers.js
2
+
3
+ // --- Time and Shift Helpers ---
4
+
5
+ /**
6
+ * Parses a time string ("HH:MM") into minutes since midnight.
7
+ * Returns NaN if the format is invalid.
8
+ */
9
+ function parseTime(timeStr) {
10
+ if (!timeStr || typeof timeStr !== 'string') return NaN;
11
+ const parts = timeStr.split(':');
12
+ if (parts.length !== 2) return NaN;
13
+ const hours = parseInt(parts[0], 10);
14
+ const minutes = parseInt(parts[1], 10);
15
+ if (isNaN(hours) || isNaN(minutes) || hours < 0 || hours > 23 || minutes < 0 || minutes > 59) {
16
+ return NaN;
17
+ }
18
+ return hours * 60 + minutes;
19
+ }
20
+
21
+ const shifts = {
22
+ breakfast: { start: '07:00', end: '11:00' },
23
+ lunch: { start: '11:00', end: '16:00' },
24
+ dinner: { start: '16:00', end: '23:00' }, // Adjust end time if needed
25
+ };
26
+
27
+ /**
28
+ * Determines the meal type ('breakfast', 'lunch', 'dinner') for a given time string ("HH:MM").
29
+ * Returns null if the time doesn't fall into a defined shift.
30
+ */
31
+ function getMealTypeByTime(timeStr) {
32
+ const time = parseTime(timeStr);
33
+ if (isNaN(time)) return null;
34
+
35
+ for (const [mealType, shift] of Object.entries(shifts)) {
36
+ const start = parseTime(shift.start);
37
+ const end = parseTime(shift.end);
38
+ // Handle potential errors from parseTime if shift definitions are invalid
39
+ if (isNaN(start) || isNaN(end)) continue;
40
+
41
+ // Check if time falls within the shift range [start, end)
42
+ if (time >= start && time < end) {
43
+ return mealType;
44
+ }
45
+ }
46
+ return null; // Return null if no matching shift is found
47
+ }
48
+
49
+
50
+ // --- Table Fetching ---
51
+
52
+ /**
53
+ * Gets the floor ID linked to a seat place from seatAreaFloorLinks.
54
+ * Mirrors the server-side getFloorIdForSeatPlace in assignTables.js.
55
+ * @param {Object} restaurantData - The restaurant data object.
56
+ * @param {string} seatPlace - The seat place identifier (zitplaats).
57
+ * @returns {string|null} The floor ID or null if not found.
58
+ */
59
+ function getFloorIdForSeatPlace(restaurantData, seatPlace) {
60
+ if (!seatPlace || !restaurantData) return null;
61
+ const seatAreaFloorLinks = restaurantData["general-settings"]?.seatAreaFloorLinks;
62
+ if (!seatAreaFloorLinks || typeof seatAreaFloorLinks !== 'object') return null;
63
+ return seatAreaFloorLinks[seatPlace] || null;
64
+ }
65
+
66
+ /**
67
+ * Extracts and processes table data from the restaurantData object.
68
+ * Includes temporary table properties and sorts tables.
69
+ * When selectedZitplaats is provided and has a linked floor via seatAreaFloorLinks,
70
+ * only tables from that linked floor are returned (matching server-side behavior).
71
+ * @param {Object} restaurantData - The main restaurant data object.
72
+ * @param {string|null} selectedZitplaats - Optional seat place to filter by linked floor.
73
+ * @returns {Array} An array of processed table objects.
74
+ */
75
+ function getAllTables(restaurantData, selectedZitplaats) {
76
+ let allTables = [];
77
+ if (restaurantData?.floors && Array.isArray(restaurantData.floors)) {
78
+ // If a zitplaats is specified and has a floor link, only use that floor
79
+ let floorsToUse = restaurantData.floors;
80
+ if (selectedZitplaats) {
81
+ const linkedFloorId = getFloorIdForSeatPlace(restaurantData, selectedZitplaats);
82
+ if (linkedFloorId) {
83
+ const linkedFloor = restaurantData.floors.find(f => f.id === linkedFloorId);
84
+ if (linkedFloor) {
85
+ floorsToUse = [linkedFloor];
86
+ console.log(`[getAllTables] Floor link found: zitplaats '${selectedZitplaats}' -> floor '${linkedFloorId}'`);
87
+ }
88
+ }
89
+ }
90
+
91
+ floorsToUse.forEach(floor => {
92
+ if (floor?.tables && Array.isArray(floor.tables)) {
93
+ floor.tables.forEach(tbl => {
94
+ // Ensure table number, capacities, priority exist before parsing
95
+ const tableNumberRaw = tbl.tableNumber?.$numberInt ?? tbl.tableNumber;
96
+ const minCapacityRaw = tbl.minCapacity?.$numberInt ?? tbl.minCapacity;
97
+ const maxCapacityRaw = tbl.maxCapacity?.$numberInt ?? tbl.maxCapacity;
98
+ const priorityRaw = tbl.priority?.$numberInt ?? tbl.priority;
99
+ const xRaw = tbl.x?.$numberInt ?? tbl.x;
100
+ const yRaw = tbl.y?.$numberInt ?? tbl.y;
101
+
102
+ if (tbl.objectType === "Tafel" &&
103
+ tableNumberRaw !== undefined &&
104
+ minCapacityRaw !== undefined &&
105
+ maxCapacityRaw !== undefined &&
106
+ priorityRaw !== undefined &&
107
+ xRaw !== undefined &&
108
+ yRaw !== undefined)
109
+ {
110
+ allTables.push({
111
+ tableId: tbl.id,
112
+ tableNumber: parseInt(tableNumberRaw, 10),
113
+ minCapacity: parseInt(minCapacityRaw, 10),
114
+ maxCapacity: parseInt(maxCapacityRaw, 10),
115
+ priority: parseInt(priorityRaw, 10),
116
+ x: parseInt(xRaw, 10),
117
+ y: parseInt(yRaw, 10),
118
+ isTemporary: tbl.isTemporary === true, // Ensure boolean
119
+ startDate: tbl.startDate || null, // Expects 'YYYY-MM-DD'
120
+ endDate: tbl.endDate || null, // Expects 'YYYY-MM-DD'
121
+ application: tbl.application || null // Expects 'breakfast', 'lunch', or 'dinner'
122
+ });
123
+ } else if (tbl.objectType === "Tafel") {
124
+ console.warn(`Skipping table due to missing essential properties: ${JSON.stringify(tbl)}`);
125
+ }
126
+ });
127
+ }
128
+ });
129
+ } else {
130
+ console.warn("Restaurant data is missing 'floors' array.");
131
+ }
132
+
133
+ // Sort tables
134
+ allTables.sort((a, b) => {
135
+ if (a.maxCapacity !== b.maxCapacity) {
136
+ return a.maxCapacity - b.maxCapacity;
137
+ }
138
+ if (a.priority !== b.priority) {
139
+ // Assuming lower priority number means higher priority
140
+ return a.priority - b.priority;
141
+ }
142
+ return a.minCapacity - b.minCapacity;
143
+ });
144
+
145
+ // Filter out tables where parsing failed (resulted in NaN)
146
+ allTables = allTables.filter(t =>
147
+ !isNaN(t.tableNumber) &&
148
+ !isNaN(t.minCapacity) &&
149
+ !isNaN(t.maxCapacity) &&
150
+ !isNaN(t.priority) &&
151
+ !isNaN(t.x) &&
152
+ !isNaN(t.y)
153
+ );
154
+
155
+ return allTables;
156
+ }
157
+
158
+
159
+ // --- Temporary Table Validation ---
160
+
161
+ /**
162
+ * Checks if a temporary table is valid for a specific reservation date and time.
163
+ * @param {Object} table - The table object (must include isTemporary, startDate, endDate, application).
164
+ * @param {string} reservationDateStr - The date of the reservation ("YYYY-MM-DD").
165
+ * @param {string} reservationTimeStr - The time of the reservation ("HH:MM").
166
+ * @returns {boolean} True if the table is valid, false otherwise.
167
+ */
168
+ function isTemporaryTableValid(table, reservationDateStr, reservationTimeStr) {
169
+ if (!table.isTemporary) {
170
+ return true; // Not temporary, always valid (subject to other checks like availability)
171
+ }
172
+
173
+ // Check date range
174
+ if (!table.startDate || !table.endDate) {
175
+ console.log(`Temporary Table ${table.tableNumber} skipped: Missing start/end date.`);
176
+ return false; // Invalid temporary table definition
177
+ }
178
+ // Basic date string comparison (YYYY-MM-DD format)
179
+ if (reservationDateStr < table.startDate || reservationDateStr > table.endDate) {
180
+ // console.log(`Temporary Table ${table.tableNumber} skipped: Date ${reservationDateStr} outside range ${table.startDate}-${table.endDate}.`); // Optional verbose logging
181
+ return false;
182
+ }
183
+
184
+ // Check application (meal type/shift)
185
+ const reservationMealType = getMealTypeByTime(reservationTimeStr);
186
+ if (!reservationMealType) {
187
+ console.log(`Temporary Table ${table.tableNumber} skipped: Could not determine meal type for time ${reservationTimeStr}.`);
188
+ return false; // Cannot determine meal type for the reservation
189
+ }
190
+ if (table.application !== reservationMealType) {
191
+ // console.log(`Temporary Table ${table.tableNumber} skipped: Application '${table.application}' does not match reservation meal type '${reservationMealType}'.`); // Optional verbose logging
192
+ return false;
193
+ }
194
+
195
+ // console.log(`Temporary Table ${table.tableNumber} is valid for ${reservationDateStr} at ${reservationTimeStr} (${reservationMealType}).`); // Optional verbose logging
196
+ return true;
197
+ }
198
+
199
+
200
+ // --- Exports ---
201
+ // Use CommonJS exports (adjust if using ES6 modules)
202
+ module.exports = {
203
+ shifts,
204
+ parseTime,
205
+ getMealTypeByTime,
206
+ getAllTables,
207
+ getFloorIdForSeatPlace,
208
+ isTemporaryTableValid
209
+ };
@@ -1,19 +1,19 @@
1
- // --- Time and Shift Helpers ---
2
-
3
- /**
4
- * Parses a time string ("HH:MM") into minutes since midnight.
5
- * Returns NaN if the format is invalid.
6
- */
7
- function parseTime(timeStr) {
8
- if (!timeStr || typeof timeStr !== 'string') return NaN;
9
- const parts = timeStr.split(':');
10
- if (parts.length !== 2) return NaN;
11
- const hours = parseInt(parts[0], 10);
12
- const minutes = parseInt(parts[1], 10);
13
- if (isNaN(hours) || isNaN(minutes) || hours < 0 || hours > 23 || minutes < 0 || minutes > 59) {
14
- return NaN;
15
- }
16
- return hours * 60 + minutes;
17
- }
18
-
19
- module.exports = parseTime;
1
+ // --- Time and Shift Helpers ---
2
+
3
+ /**
4
+ * Parses a time string ("HH:MM") into minutes since midnight.
5
+ * Returns NaN if the format is invalid.
6
+ */
7
+ function parseTime(timeStr) {
8
+ if (!timeStr || typeof timeStr !== 'string') return NaN;
9
+ const parts = timeStr.split(':');
10
+ if (parts.length !== 2) return NaN;
11
+ const hours = parseInt(parts[0], 10);
12
+ const minutes = parseInt(parts[1], 10);
13
+ if (isNaN(hours) || isNaN(minutes) || hours < 0 || hours > 23 || minutes < 0 || minutes > 59) {
14
+ return NaN;
15
+ }
16
+ return hours * 60 + minutes;
17
+ }
18
+
19
+ module.exports = parseTime;
@@ -1,7 +1,7 @@
1
- const shifts = {
2
- breakfast: { start: '07:00', end: '11:00' },
3
- lunch: { start: '11:00', end: '16:00' },
4
- dinner: { start: '16:00', end: '23:00' }, // Adjust end time if needed
5
- };
6
-
7
- module.exports = { shifts };
1
+ const shifts = {
2
+ breakfast: { start: '07:00', end: '11:00' },
3
+ lunch: { start: '11:00', end: '16:00' },
4
+ dinner: { start: '16:00', end: '23:00' }, // Adjust end time if needed
5
+ };
6
+
7
+ module.exports = { shifts };
@@ -1,13 +1,13 @@
1
- /**
2
- * Calculates Euclidean distance between two tables (assuming x, y properties).
3
- */
4
- function calculateDistance(tableA, tableB) {
5
- if (tableA?.x === undefined || tableA?.y === undefined || tableB?.x === undefined || tableB?.y === undefined) {
6
- return Infinity; // Cannot calculate distance if coordinates are missing
7
- }
8
- const dx = tableA.x - tableB.x;
9
- const dy = tableA.y - tableB.y;
10
- return Math.sqrt(dx * dx + dy * dy);
11
- }
12
-
13
- module.exports = calculateDistance;
1
+ /**
2
+ * Calculates Euclidean distance between two tables (assuming x, y properties).
3
+ */
4
+ function calculateDistance(tableA, tableB) {
5
+ if (tableA?.x === undefined || tableA?.y === undefined || tableB?.x === undefined || tableB?.y === undefined) {
6
+ return Infinity; // Cannot calculate distance if coordinates are missing
7
+ }
8
+ const dx = tableA.x - tableB.x;
9
+ const dy = tableA.y - tableB.y;
10
+ return Math.sqrt(dx * dx + dy * dy);
11
+ }
12
+
13
+ module.exports = calculateDistance;
@@ -1,14 +1,14 @@
1
- /**
2
- * Checks if the given tableNumber is free for all requiredSlots based on the occupied map.
3
- */
4
- function isTableFreeForAllSlots(tableNumber, requiredSlots, tableOccupiedSlots) {
5
- const occupiedSlots = tableOccupiedSlots[tableNumber] || new Set();
6
- for (const slot of requiredSlots) {
7
- if (occupiedSlots.has(slot)) {
8
- return false;
9
- }
10
- }
11
- return true;
12
- }
13
-
14
- module.exports = isTableFreeForAllSlots;
1
+ /**
2
+ * Checks if the given tableNumber is free for all requiredSlots based on the occupied map.
3
+ */
4
+ function isTableFreeForAllSlots(tableNumber, requiredSlots, tableOccupiedSlots) {
5
+ const occupiedSlots = tableOccupiedSlots[tableNumber] || new Set();
6
+ for (const slot of requiredSlots) {
7
+ if (occupiedSlots.has(slot)) {
8
+ return false;
9
+ }
10
+ }
11
+ return true;
12
+ }
13
+
14
+ module.exports = isTableFreeForAllSlots;
@@ -1,39 +1,39 @@
1
- const getMealTypeByTime = require('../time/getMealTypeByTime');
2
-
3
- /**
4
- * Checks if a temporary table is valid for a specific reservation date and time.
5
- * @param {Object} table - The table object (must include isTemporary, startDate, endDate, application).
6
- * @param {string} reservationDateStr - The date of the reservation ("YYYY-MM-DD").
7
- * @param {string} reservationTimeStr - The time of the reservation ("HH:MM").
8
- * @returns {boolean} True if the table is valid, false otherwise.
9
- */
10
- function isTemporaryTableValid(table, reservationDateStr, reservationTimeStr) {
11
- if (!table.isTemporary) {
12
- return true; // Not temporary, always valid (subject to other checks like availability)
13
- }
14
-
15
- // Check date range
16
- if (!table.startDate || !table.endDate) {
17
- return false; // Invalid temporary table definition
18
- }
19
- // Basic date string comparison (YYYY-MM-DD format)
20
- if (reservationDateStr < table.startDate || reservationDateStr > table.endDate) {
21
- // console.log(`Temporary Table ${table.tableNumber} skipped: Date ${reservationDateStr} outside range ${table.startDate}-${table.endDate}.`); // Optional verbose logging
22
- return false;
23
- }
24
-
25
- // Check application (meal type/shift)
26
- const reservationMealType = getMealTypeByTime(reservationTimeStr);
27
- if (!reservationMealType) {
28
- return false; // Cannot determine meal type for the reservation
29
- }
30
- if (table.application !== reservationMealType) {
31
- // console.log(`Temporary Table ${table.tableNumber} skipped: Application '${table.application}' does not match reservation meal type '${reservationMealType}'.`); // Optional verbose logging
32
- return false;
33
- }
34
-
35
- // console.log(`Temporary Table ${table.tableNumber} is valid for ${reservationDateStr} at ${reservationTimeStr} (${reservationMealType}).`); // Optional verbose logging
36
- return true;
37
- }
38
-
39
- module.exports = isTemporaryTableValid;
1
+ const getMealTypeByTime = require('../time/getMealTypeByTime');
2
+
3
+ /**
4
+ * Checks if a temporary table is valid for a specific reservation date and time.
5
+ * @param {Object} table - The table object (must include isTemporary, startDate, endDate, application).
6
+ * @param {string} reservationDateStr - The date of the reservation ("YYYY-MM-DD").
7
+ * @param {string} reservationTimeStr - The time of the reservation ("HH:MM").
8
+ * @returns {boolean} True if the table is valid, false otherwise.
9
+ */
10
+ function isTemporaryTableValid(table, reservationDateStr, reservationTimeStr) {
11
+ if (!table.isTemporary) {
12
+ return true; // Not temporary, always valid (subject to other checks like availability)
13
+ }
14
+
15
+ // Check date range
16
+ if (!table.startDate || !table.endDate) {
17
+ return false; // Invalid temporary table definition
18
+ }
19
+ // Basic date string comparison (YYYY-MM-DD format)
20
+ if (reservationDateStr < table.startDate || reservationDateStr > table.endDate) {
21
+ // console.log(`Temporary Table ${table.tableNumber} skipped: Date ${reservationDateStr} outside range ${table.startDate}-${table.endDate}.`); // Optional verbose logging
22
+ return false;
23
+ }
24
+
25
+ // Check application (meal type/shift)
26
+ const reservationMealType = getMealTypeByTime(reservationTimeStr);
27
+ if (!reservationMealType) {
28
+ return false; // Cannot determine meal type for the reservation
29
+ }
30
+ if (table.application !== reservationMealType) {
31
+ // console.log(`Temporary Table ${table.tableNumber} skipped: Application '${table.application}' does not match reservation meal type '${reservationMealType}'.`); // Optional verbose logging
32
+ return false;
33
+ }
34
+
35
+ // console.log(`Temporary Table ${table.tableNumber} is valid for ${reservationDateStr} at ${reservationTimeStr} (${reservationMealType}).`); // Optional verbose logging
36
+ return true;
37
+ }
38
+
39
+ module.exports = isTemporaryTableValid;