@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.
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
@@ -1,142 +1,142 @@
1
- // index.js
2
-
3
- const daysOfWeekEnglish = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
4
- const daysOfWeekDutch = ['zondag', 'maandag', 'dinsdag', 'woensdag', 'donderdag', 'vrijdag', 'zaterdag'];
5
-
6
- const shifts = {
7
- breakfast: { start: '07:00', end: '11:00' },
8
- lunch: { start: '11:00', end: '16:00' },
9
- dinner: { start: '16:00', end: '23:00' },
10
- };
11
-
12
- function parseTime(timeStr) {
13
- const [hours, minutes] = timeStr.split(':').map(Number);
14
- return hours * 60 + minutes;
15
- }
16
-
17
- /**
18
- * Parse a YYYY-MM-DD date string consistently across browsers.
19
- * Using new Date(dateStr) directly causes browser differences:
20
- * - Chrome parses "YYYY-MM-DD" as local midnight
21
- * - Firefox parses "YYYY-MM-DD" as UTC midnight
22
- * This function ensures consistent local time parsing.
23
- */
24
- function parseDateString(dateStr) {
25
- if (!dateStr || typeof dateStr !== 'string') {
26
- return new Date(NaN);
27
- }
28
- const [year, month, day] = dateStr.split('-').map(Number);
29
- return new Date(year, month - 1, day);
30
- }
31
-
32
- function getMealTypeByTime(timeStr) {
33
- const time = parseTime(timeStr);
34
- for (const [mealType, shift] of Object.entries(shifts)) {
35
- const start = parseTime(shift.start);
36
- const end = parseTime(shift.end);
37
- if (time >= start && time < end) {
38
- return mealType;
39
- }
40
- }
41
- return null;
42
- }
43
-
44
- function getDataByDayAndMeal(data, dayOfWeek, mealType) {
45
- const mealKey = `openinghours-${mealType}`;
46
- if (!data[mealKey]) {
47
- return null;
48
- }
49
- const mealData = data[mealKey];
50
- if (!mealData.schemeSettings) {
51
- return null;
52
- }
53
- const dayData = mealData.schemeSettings[dayOfWeek];
54
- if (!dayData) {
55
- return null;
56
- }
57
- return { ...dayData };
58
- }
59
-
60
- function adjustMealData(mealData, generalSettings) {
61
- if (mealData.maxCapacityEnabled === false) {
62
- if (generalSettings && generalSettings.zitplaatsen) {
63
- mealData.maxCapacity = generalSettings.zitplaatsen;
64
- mealData.maxCapacityEnabled = true;
65
- } else {
66
- mealData.maxCapacity = '0';
67
- mealData.maxCapacityEnabled = true;
68
- }
69
- }
70
- }
71
-
72
- function getDuurReservatie(data) {
73
- let duurReservatie = 120;
74
- if (
75
- data['general-settings'] &&
76
- data['general-settings'].duurReservatie &&
77
- parseInt(data['general-settings'].duurReservatie, 10) > 0
78
- ) {
79
- duurReservatie = parseInt(data['general-settings'].duurReservatie, 10);
80
- }
81
- return duurReservatie;
82
- }
83
-
84
- function addDuurReservatieToEndTime(mealData, data) {
85
- const duurReservatie = getDuurReservatie(data);
86
- const endMinutes = parseTime(mealData.endTime);
87
- const newEndMinutes = endMinutes + duurReservatie;
88
- const hours = String(Math.floor(newEndMinutes / 60)).padStart(2, '0');
89
- const minutes = String(newEndMinutes % 60).padStart(2, '0');
90
- mealData.endTime = `${hours}:${minutes}`;
91
- }
92
-
93
- function getDataByDateAndMeal(data, dateStr, mealType) {
94
- const date = parseDateString(dateStr);
95
- if (isNaN(date)) {
96
- return null;
97
- }
98
- const dayOfWeekIndex = date.getDay();
99
- const dayOfWeek = daysOfWeekEnglish[dayOfWeekIndex];
100
- let mealData = getDataByDayAndMeal(data, dayOfWeek, mealType);
101
- if (!mealData || mealData.enabled !== true) {
102
- return null;
103
- }
104
-
105
- adjustMealData(mealData, data['general-settings']);
106
-
107
- // Add duurReservatie to endTime
108
- addDuurReservatieToEndTime(mealData, data);
109
-
110
- return mealData;
111
- }
112
-
113
- function getDataByDateAndTime(data, dateStr, timeStr) {
114
- const mealType = getMealTypeByTime(timeStr);
115
- if (!mealType) {
116
- return null;
117
- }
118
- const mealData = getDataByDateAndMeal(data, dateStr, mealType);
119
- if (!mealData) {
120
- return null;
121
- }
122
- const requestedTime = parseTime(timeStr);
123
- const startTime = parseTime(mealData.startTime);
124
- const endTime = parseTime(mealData.endTime);
125
- if (requestedTime >= startTime && requestedTime < endTime) {
126
- return mealData;
127
- } else {
128
- return null;
129
- }
130
- }
131
-
132
- module.exports = {
133
- getDataByDayAndMeal,
134
- getDataByDateAndMeal,
135
- getDataByDateAndTime,
136
- daysOfWeekEnglish,
137
- daysOfWeekDutch,
138
- getMealTypeByTime,
139
- parseTime,
140
- parseDateString,
141
- shifts,
142
- };
1
+ // index.js
2
+
3
+ const daysOfWeekEnglish = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
4
+ const daysOfWeekDutch = ['zondag', 'maandag', 'dinsdag', 'woensdag', 'donderdag', 'vrijdag', 'zaterdag'];
5
+
6
+ const shifts = {
7
+ breakfast: { start: '07:00', end: '11:00' },
8
+ lunch: { start: '11:00', end: '16:00' },
9
+ dinner: { start: '16:00', end: '23:00' },
10
+ };
11
+
12
+ function parseTime(timeStr) {
13
+ const [hours, minutes] = timeStr.split(':').map(Number);
14
+ return hours * 60 + minutes;
15
+ }
16
+
17
+ /**
18
+ * Parse a YYYY-MM-DD date string consistently across browsers.
19
+ * Using new Date(dateStr) directly causes browser differences:
20
+ * - Chrome parses "YYYY-MM-DD" as local midnight
21
+ * - Firefox parses "YYYY-MM-DD" as UTC midnight
22
+ * This function ensures consistent local time parsing.
23
+ */
24
+ function parseDateString(dateStr) {
25
+ if (!dateStr || typeof dateStr !== 'string') {
26
+ return new Date(NaN);
27
+ }
28
+ const [year, month, day] = dateStr.split('-').map(Number);
29
+ return new Date(year, month - 1, day);
30
+ }
31
+
32
+ function getMealTypeByTime(timeStr) {
33
+ const time = parseTime(timeStr);
34
+ for (const [mealType, shift] of Object.entries(shifts)) {
35
+ const start = parseTime(shift.start);
36
+ const end = parseTime(shift.end);
37
+ if (time >= start && time < end) {
38
+ return mealType;
39
+ }
40
+ }
41
+ return null;
42
+ }
43
+
44
+ function getDataByDayAndMeal(data, dayOfWeek, mealType) {
45
+ const mealKey = `openinghours-${mealType}`;
46
+ if (!data[mealKey]) {
47
+ return null;
48
+ }
49
+ const mealData = data[mealKey];
50
+ if (!mealData.schemeSettings) {
51
+ return null;
52
+ }
53
+ const dayData = mealData.schemeSettings[dayOfWeek];
54
+ if (!dayData) {
55
+ return null;
56
+ }
57
+ return { ...dayData };
58
+ }
59
+
60
+ function adjustMealData(mealData, generalSettings) {
61
+ if (mealData.maxCapacityEnabled === false) {
62
+ if (generalSettings && generalSettings.zitplaatsen) {
63
+ mealData.maxCapacity = generalSettings.zitplaatsen;
64
+ mealData.maxCapacityEnabled = true;
65
+ } else {
66
+ mealData.maxCapacity = '0';
67
+ mealData.maxCapacityEnabled = true;
68
+ }
69
+ }
70
+ }
71
+
72
+ function getDuurReservatie(data) {
73
+ let duurReservatie = 120;
74
+ if (
75
+ data['general-settings'] &&
76
+ data['general-settings'].duurReservatie &&
77
+ parseInt(data['general-settings'].duurReservatie, 10) > 0
78
+ ) {
79
+ duurReservatie = parseInt(data['general-settings'].duurReservatie, 10);
80
+ }
81
+ return duurReservatie;
82
+ }
83
+
84
+ function addDuurReservatieToEndTime(mealData, data) {
85
+ const duurReservatie = getDuurReservatie(data);
86
+ const endMinutes = parseTime(mealData.endTime);
87
+ const newEndMinutes = endMinutes + duurReservatie;
88
+ const hours = String(Math.floor(newEndMinutes / 60)).padStart(2, '0');
89
+ const minutes = String(newEndMinutes % 60).padStart(2, '0');
90
+ mealData.endTime = `${hours}:${minutes}`;
91
+ }
92
+
93
+ function getDataByDateAndMeal(data, dateStr, mealType) {
94
+ const date = parseDateString(dateStr);
95
+ if (isNaN(date)) {
96
+ return null;
97
+ }
98
+ const dayOfWeekIndex = date.getDay();
99
+ const dayOfWeek = daysOfWeekEnglish[dayOfWeekIndex];
100
+ let mealData = getDataByDayAndMeal(data, dayOfWeek, mealType);
101
+ if (!mealData || mealData.enabled !== true) {
102
+ return null;
103
+ }
104
+
105
+ adjustMealData(mealData, data['general-settings']);
106
+
107
+ // Add duurReservatie to endTime
108
+ addDuurReservatieToEndTime(mealData, data);
109
+
110
+ return mealData;
111
+ }
112
+
113
+ function getDataByDateAndTime(data, dateStr, timeStr) {
114
+ const mealType = getMealTypeByTime(timeStr);
115
+ if (!mealType) {
116
+ return null;
117
+ }
118
+ const mealData = getDataByDateAndMeal(data, dateStr, mealType);
119
+ if (!mealData) {
120
+ return null;
121
+ }
122
+ const requestedTime = parseTime(timeStr);
123
+ const startTime = parseTime(mealData.startTime);
124
+ const endTime = parseTime(mealData.endTime);
125
+ if (requestedTime >= startTime && requestedTime < endTime) {
126
+ return mealData;
127
+ } else {
128
+ return null;
129
+ }
130
+ }
131
+
132
+ module.exports = {
133
+ getDataByDayAndMeal,
134
+ getDataByDateAndMeal,
135
+ getDataByDateAndTime,
136
+ daysOfWeekEnglish,
137
+ daysOfWeekDutch,
138
+ getMealTypeByTime,
139
+ parseTime,
140
+ parseDateString,
141
+ shifts,
142
+ };