@happychef/algorithm 1.2.11 → 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 +234 -234
- 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__/filters.test.js +276 -276
- package/__tests__/isDateAvailable.test.js +175 -175
- package/__tests__/isTimeAvailable.test.js +168 -168
- package/__tests__/restaurantData.test.js +422 -422
- package/__tests__/tableHelpers.test.js +247 -247
- package/assignTables.js +424 -424
- 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/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/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 +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-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
package/test-meal-stop-fix.js
CHANGED
|
@@ -1,147 +1,147 @@
|
|
|
1
|
-
// Test to verify meal stop filters work with Brussels timezone
|
|
2
|
-
|
|
3
|
-
const { getAvailableTimeblocks } = require('./getAvailableTimeblocks');
|
|
4
|
-
const { getMealTypeByTime } = require('./tableHelpers');
|
|
5
|
-
|
|
6
|
-
// Mock restaurant data
|
|
7
|
-
const testData = {
|
|
8
|
-
'general-settings': {
|
|
9
|
-
zitplaatsen: 20,
|
|
10
|
-
uurOpVoorhand: 0,
|
|
11
|
-
dagenInToekomst: 365,
|
|
12
|
-
minGasten: 1,
|
|
13
|
-
maxGasten: 10,
|
|
14
|
-
intervalReservatie: 30,
|
|
15
|
-
duurReservatie: 120,
|
|
16
|
-
ontbijtStop: "10:00", // Breakfast stops at 10:00
|
|
17
|
-
lunchStop: "12:00", // Lunch stops at 12:00
|
|
18
|
-
dinerStop: "20:00" // Dinner stops at 20:00
|
|
19
|
-
},
|
|
20
|
-
'openinghours-breakfast': {
|
|
21
|
-
monday: { enabled: true, startTime: '08:00', endTime: '11:00' },
|
|
22
|
-
tuesday: { enabled: true, startTime: '08:00', endTime: '11:00' },
|
|
23
|
-
wednesday: { enabled: true, startTime: '08:00', endTime: '11:00' },
|
|
24
|
-
thursday: { enabled: true, startTime: '08:00', endTime: '11:00' },
|
|
25
|
-
friday: { enabled: true, startTime: '08:00', endTime: '11:00' },
|
|
26
|
-
saturday: { enabled: true, startTime: '08:00', endTime: '11:00' },
|
|
27
|
-
sunday: { enabled: true, startTime: '08:00', endTime: '11:00' }
|
|
28
|
-
},
|
|
29
|
-
'openinghours-lunch': {
|
|
30
|
-
monday: { enabled: true, startTime: '11:00', endTime: '15:00' },
|
|
31
|
-
tuesday: { enabled: true, startTime: '11:00', endTime: '15:00' },
|
|
32
|
-
wednesday: { enabled: true, startTime: '11:00', endTime: '15:00' },
|
|
33
|
-
thursday: { enabled: true, startTime: '11:00', endTime: '15:00' },
|
|
34
|
-
friday: { enabled: true, startTime: '11:00', endTime: '15:00' },
|
|
35
|
-
saturday: { enabled: true, startTime: '11:00', endTime: '15:00' },
|
|
36
|
-
sunday: { enabled: true, startTime: '11:00', endTime: '15:00' }
|
|
37
|
-
},
|
|
38
|
-
'openinghours-dinner': {
|
|
39
|
-
monday: { enabled: true, startTime: '17:00', endTime: '22:00' },
|
|
40
|
-
tuesday: { enabled: true, startTime: '17:00', endTime: '22:00' },
|
|
41
|
-
wednesday: { enabled: true, startTime: '17:00', endTime: '22:00' },
|
|
42
|
-
thursday: { enabled: true, startTime: '17:00', endTime: '22:00' },
|
|
43
|
-
friday: { enabled: true, startTime: '17:00', endTime: '22:00' },
|
|
44
|
-
saturday: { enabled: true, startTime: '17:00', endTime: '22:00' },
|
|
45
|
-
sunday: { enabled: true, startTime: '17:00', endTime: '22:00' }
|
|
46
|
-
},
|
|
47
|
-
'max-arrivals-breakfast': {},
|
|
48
|
-
'max-arrivals-lunch': {},
|
|
49
|
-
'max-arrivals-dinner': {},
|
|
50
|
-
tables: [
|
|
51
|
-
{ name: 'Table 1', minCapacity: 1, maxCapacity: 4 },
|
|
52
|
-
{ name: 'Table 2', minCapacity: 1, maxCapacity: 4 },
|
|
53
|
-
{ name: 'Table 3', minCapacity: 1, maxCapacity: 4 },
|
|
54
|
-
{ name: 'Table 4', minCapacity: 1, maxCapacity: 4 },
|
|
55
|
-
{ name: 'Table 5', minCapacity: 1, maxCapacity: 4 }
|
|
56
|
-
]
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
// Get today's date in YYYY-MM-DD format (Brussels timezone)
|
|
60
|
-
const nowInBrussels = new Date(new Date().toLocaleString('en-US', { timeZone: 'Europe/Brussels' }));
|
|
61
|
-
const year = nowInBrussels.getFullYear();
|
|
62
|
-
const month = String(nowInBrussels.getMonth() + 1).padStart(2, '0');
|
|
63
|
-
const day = String(nowInBrussels.getDate()).padStart(2, '0');
|
|
64
|
-
const todayStr = `${year}-${month}-${day}`;
|
|
65
|
-
|
|
66
|
-
const currentHour = nowInBrussels.getHours();
|
|
67
|
-
const currentMinute = nowInBrussels.getMinutes();
|
|
68
|
-
const currentTimeStr = `${String(currentHour).padStart(2, '0')}:${String(currentMinute).padStart(2, '0')}`;
|
|
69
|
-
|
|
70
|
-
console.log('=== MEAL STOP FILTER TEST ===\n');
|
|
71
|
-
console.log(`Current date (Brussels): ${todayStr}`);
|
|
72
|
-
console.log(`Current time (Brussels): ${currentTimeStr}`);
|
|
73
|
-
console.log(`\nMeal stop times:`);
|
|
74
|
-
console.log(` - Breakfast stops at: 10:00`);
|
|
75
|
-
console.log(` - Lunch stops at: 12:00`);
|
|
76
|
-
console.log(` - Dinner stops at: 20:00\n`);
|
|
77
|
-
|
|
78
|
-
// Test with today's date
|
|
79
|
-
const reservations = [];
|
|
80
|
-
const guests = 2;
|
|
81
|
-
const blockedSlots = [];
|
|
82
|
-
const giftcard = null;
|
|
83
|
-
const isAdmin = false;
|
|
84
|
-
|
|
85
|
-
const availableTimeblocks = getAvailableTimeblocks(
|
|
86
|
-
testData,
|
|
87
|
-
todayStr,
|
|
88
|
-
reservations,
|
|
89
|
-
guests,
|
|
90
|
-
blockedSlots,
|
|
91
|
-
giftcard,
|
|
92
|
-
isAdmin
|
|
93
|
-
);
|
|
94
|
-
|
|
95
|
-
// Categorize by meal type
|
|
96
|
-
const breakfast = [];
|
|
97
|
-
const lunch = [];
|
|
98
|
-
const dinner = [];
|
|
99
|
-
|
|
100
|
-
for (const time in availableTimeblocks) {
|
|
101
|
-
const mealType = getMealTypeByTime(time);
|
|
102
|
-
if (mealType === 'breakfast') breakfast.push(time);
|
|
103
|
-
else if (mealType === 'lunch') lunch.push(time);
|
|
104
|
-
else if (mealType === 'dinner') dinner.push(time);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
console.log('Available timeblocks:');
|
|
108
|
-
console.log(` - Breakfast slots (${breakfast.length}): ${breakfast.join(', ') || 'NONE'}`);
|
|
109
|
-
console.log(` - Lunch slots (${lunch.length}): ${lunch.join(', ') || 'NONE'}`);
|
|
110
|
-
console.log(` - Dinner slots (${dinner.length}): ${dinner.join(', ') || 'NONE'}`);
|
|
111
|
-
|
|
112
|
-
console.log('\n--- Expected Behavior ---');
|
|
113
|
-
console.log('If current time < 10:00: Breakfast slots should be available');
|
|
114
|
-
console.log('If current time >= 10:00: Breakfast slots should be BLOCKED');
|
|
115
|
-
console.log('If current time < 12:00: Lunch slots should be available');
|
|
116
|
-
console.log('If current time >= 12:00: Lunch slots should be BLOCKED');
|
|
117
|
-
console.log('If current time < 20:00: Dinner slots should be available');
|
|
118
|
-
console.log('If current time >= 20:00: Dinner slots should be BLOCKED');
|
|
119
|
-
|
|
120
|
-
console.log('\n--- Actual Behavior ---');
|
|
121
|
-
const currentMinutes = currentHour * 60 + currentMinute;
|
|
122
|
-
|
|
123
|
-
if (currentMinutes < 10 * 60) {
|
|
124
|
-
console.log(`Current time (${currentTimeStr}) is BEFORE 10:00`);
|
|
125
|
-
console.log(`✓ Expected: Breakfast available = ${breakfast.length > 0 ? 'YES ✓' : 'NO ✗'}`);
|
|
126
|
-
} else {
|
|
127
|
-
console.log(`Current time (${currentTimeStr}) is AT OR AFTER 10:00`);
|
|
128
|
-
console.log(`✓ Expected: Breakfast blocked = ${breakfast.length === 0 ? 'YES ✓' : 'NO ✗'}`);
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
if (currentMinutes < 12 * 60) {
|
|
132
|
-
console.log(`Current time (${currentTimeStr}) is BEFORE 12:00`);
|
|
133
|
-
console.log(`✓ Expected: Lunch available = ${lunch.length > 0 ? 'YES ✓' : 'NO ✗'}`);
|
|
134
|
-
} else {
|
|
135
|
-
console.log(`Current time (${currentTimeStr}) is AT OR AFTER 12:00`);
|
|
136
|
-
console.log(`✓ Expected: Lunch blocked = ${lunch.length === 0 ? 'YES ✓' : 'NO ✗'}`);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
if (currentMinutes < 20 * 60) {
|
|
140
|
-
console.log(`Current time (${currentTimeStr}) is BEFORE 20:00`);
|
|
141
|
-
console.log(`✓ Expected: Dinner available = ${dinner.length > 0 ? 'YES ✓' : 'NO ✗'}`);
|
|
142
|
-
} else {
|
|
143
|
-
console.log(`Current time (${currentTimeStr}) is AT OR AFTER 20:00`);
|
|
144
|
-
console.log(`✓ Expected: Dinner blocked = ${dinner.length === 0 ? 'YES ✓' : 'NO ✗'}`);
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
console.log('\n=== TEST COMPLETE ===');
|
|
1
|
+
// Test to verify meal stop filters work with Brussels timezone
|
|
2
|
+
|
|
3
|
+
const { getAvailableTimeblocks } = require('./getAvailableTimeblocks');
|
|
4
|
+
const { getMealTypeByTime } = require('./tableHelpers');
|
|
5
|
+
|
|
6
|
+
// Mock restaurant data
|
|
7
|
+
const testData = {
|
|
8
|
+
'general-settings': {
|
|
9
|
+
zitplaatsen: 20,
|
|
10
|
+
uurOpVoorhand: 0,
|
|
11
|
+
dagenInToekomst: 365,
|
|
12
|
+
minGasten: 1,
|
|
13
|
+
maxGasten: 10,
|
|
14
|
+
intervalReservatie: 30,
|
|
15
|
+
duurReservatie: 120,
|
|
16
|
+
ontbijtStop: "10:00", // Breakfast stops at 10:00
|
|
17
|
+
lunchStop: "12:00", // Lunch stops at 12:00
|
|
18
|
+
dinerStop: "20:00" // Dinner stops at 20:00
|
|
19
|
+
},
|
|
20
|
+
'openinghours-breakfast': {
|
|
21
|
+
monday: { enabled: true, startTime: '08:00', endTime: '11:00' },
|
|
22
|
+
tuesday: { enabled: true, startTime: '08:00', endTime: '11:00' },
|
|
23
|
+
wednesday: { enabled: true, startTime: '08:00', endTime: '11:00' },
|
|
24
|
+
thursday: { enabled: true, startTime: '08:00', endTime: '11:00' },
|
|
25
|
+
friday: { enabled: true, startTime: '08:00', endTime: '11:00' },
|
|
26
|
+
saturday: { enabled: true, startTime: '08:00', endTime: '11:00' },
|
|
27
|
+
sunday: { enabled: true, startTime: '08:00', endTime: '11:00' }
|
|
28
|
+
},
|
|
29
|
+
'openinghours-lunch': {
|
|
30
|
+
monday: { enabled: true, startTime: '11:00', endTime: '15:00' },
|
|
31
|
+
tuesday: { enabled: true, startTime: '11:00', endTime: '15:00' },
|
|
32
|
+
wednesday: { enabled: true, startTime: '11:00', endTime: '15:00' },
|
|
33
|
+
thursday: { enabled: true, startTime: '11:00', endTime: '15:00' },
|
|
34
|
+
friday: { enabled: true, startTime: '11:00', endTime: '15:00' },
|
|
35
|
+
saturday: { enabled: true, startTime: '11:00', endTime: '15:00' },
|
|
36
|
+
sunday: { enabled: true, startTime: '11:00', endTime: '15:00' }
|
|
37
|
+
},
|
|
38
|
+
'openinghours-dinner': {
|
|
39
|
+
monday: { enabled: true, startTime: '17:00', endTime: '22:00' },
|
|
40
|
+
tuesday: { enabled: true, startTime: '17:00', endTime: '22:00' },
|
|
41
|
+
wednesday: { enabled: true, startTime: '17:00', endTime: '22:00' },
|
|
42
|
+
thursday: { enabled: true, startTime: '17:00', endTime: '22:00' },
|
|
43
|
+
friday: { enabled: true, startTime: '17:00', endTime: '22:00' },
|
|
44
|
+
saturday: { enabled: true, startTime: '17:00', endTime: '22:00' },
|
|
45
|
+
sunday: { enabled: true, startTime: '17:00', endTime: '22:00' }
|
|
46
|
+
},
|
|
47
|
+
'max-arrivals-breakfast': {},
|
|
48
|
+
'max-arrivals-lunch': {},
|
|
49
|
+
'max-arrivals-dinner': {},
|
|
50
|
+
tables: [
|
|
51
|
+
{ name: 'Table 1', minCapacity: 1, maxCapacity: 4 },
|
|
52
|
+
{ name: 'Table 2', minCapacity: 1, maxCapacity: 4 },
|
|
53
|
+
{ name: 'Table 3', minCapacity: 1, maxCapacity: 4 },
|
|
54
|
+
{ name: 'Table 4', minCapacity: 1, maxCapacity: 4 },
|
|
55
|
+
{ name: 'Table 5', minCapacity: 1, maxCapacity: 4 }
|
|
56
|
+
]
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
// Get today's date in YYYY-MM-DD format (Brussels timezone)
|
|
60
|
+
const nowInBrussels = new Date(new Date().toLocaleString('en-US', { timeZone: 'Europe/Brussels' }));
|
|
61
|
+
const year = nowInBrussels.getFullYear();
|
|
62
|
+
const month = String(nowInBrussels.getMonth() + 1).padStart(2, '0');
|
|
63
|
+
const day = String(nowInBrussels.getDate()).padStart(2, '0');
|
|
64
|
+
const todayStr = `${year}-${month}-${day}`;
|
|
65
|
+
|
|
66
|
+
const currentHour = nowInBrussels.getHours();
|
|
67
|
+
const currentMinute = nowInBrussels.getMinutes();
|
|
68
|
+
const currentTimeStr = `${String(currentHour).padStart(2, '0')}:${String(currentMinute).padStart(2, '0')}`;
|
|
69
|
+
|
|
70
|
+
console.log('=== MEAL STOP FILTER TEST ===\n');
|
|
71
|
+
console.log(`Current date (Brussels): ${todayStr}`);
|
|
72
|
+
console.log(`Current time (Brussels): ${currentTimeStr}`);
|
|
73
|
+
console.log(`\nMeal stop times:`);
|
|
74
|
+
console.log(` - Breakfast stops at: 10:00`);
|
|
75
|
+
console.log(` - Lunch stops at: 12:00`);
|
|
76
|
+
console.log(` - Dinner stops at: 20:00\n`);
|
|
77
|
+
|
|
78
|
+
// Test with today's date
|
|
79
|
+
const reservations = [];
|
|
80
|
+
const guests = 2;
|
|
81
|
+
const blockedSlots = [];
|
|
82
|
+
const giftcard = null;
|
|
83
|
+
const isAdmin = false;
|
|
84
|
+
|
|
85
|
+
const availableTimeblocks = getAvailableTimeblocks(
|
|
86
|
+
testData,
|
|
87
|
+
todayStr,
|
|
88
|
+
reservations,
|
|
89
|
+
guests,
|
|
90
|
+
blockedSlots,
|
|
91
|
+
giftcard,
|
|
92
|
+
isAdmin
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
// Categorize by meal type
|
|
96
|
+
const breakfast = [];
|
|
97
|
+
const lunch = [];
|
|
98
|
+
const dinner = [];
|
|
99
|
+
|
|
100
|
+
for (const time in availableTimeblocks) {
|
|
101
|
+
const mealType = getMealTypeByTime(time);
|
|
102
|
+
if (mealType === 'breakfast') breakfast.push(time);
|
|
103
|
+
else if (mealType === 'lunch') lunch.push(time);
|
|
104
|
+
else if (mealType === 'dinner') dinner.push(time);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
console.log('Available timeblocks:');
|
|
108
|
+
console.log(` - Breakfast slots (${breakfast.length}): ${breakfast.join(', ') || 'NONE'}`);
|
|
109
|
+
console.log(` - Lunch slots (${lunch.length}): ${lunch.join(', ') || 'NONE'}`);
|
|
110
|
+
console.log(` - Dinner slots (${dinner.length}): ${dinner.join(', ') || 'NONE'}`);
|
|
111
|
+
|
|
112
|
+
console.log('\n--- Expected Behavior ---');
|
|
113
|
+
console.log('If current time < 10:00: Breakfast slots should be available');
|
|
114
|
+
console.log('If current time >= 10:00: Breakfast slots should be BLOCKED');
|
|
115
|
+
console.log('If current time < 12:00: Lunch slots should be available');
|
|
116
|
+
console.log('If current time >= 12:00: Lunch slots should be BLOCKED');
|
|
117
|
+
console.log('If current time < 20:00: Dinner slots should be available');
|
|
118
|
+
console.log('If current time >= 20:00: Dinner slots should be BLOCKED');
|
|
119
|
+
|
|
120
|
+
console.log('\n--- Actual Behavior ---');
|
|
121
|
+
const currentMinutes = currentHour * 60 + currentMinute;
|
|
122
|
+
|
|
123
|
+
if (currentMinutes < 10 * 60) {
|
|
124
|
+
console.log(`Current time (${currentTimeStr}) is BEFORE 10:00`);
|
|
125
|
+
console.log(`✓ Expected: Breakfast available = ${breakfast.length > 0 ? 'YES ✓' : 'NO ✗'}`);
|
|
126
|
+
} else {
|
|
127
|
+
console.log(`Current time (${currentTimeStr}) is AT OR AFTER 10:00`);
|
|
128
|
+
console.log(`✓ Expected: Breakfast blocked = ${breakfast.length === 0 ? 'YES ✓' : 'NO ✗'}`);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
if (currentMinutes < 12 * 60) {
|
|
132
|
+
console.log(`Current time (${currentTimeStr}) is BEFORE 12:00`);
|
|
133
|
+
console.log(`✓ Expected: Lunch available = ${lunch.length > 0 ? 'YES ✓' : 'NO ✗'}`);
|
|
134
|
+
} else {
|
|
135
|
+
console.log(`Current time (${currentTimeStr}) is AT OR AFTER 12:00`);
|
|
136
|
+
console.log(`✓ Expected: Lunch blocked = ${lunch.length === 0 ? 'YES ✓' : 'NO ✗'}`);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
if (currentMinutes < 20 * 60) {
|
|
140
|
+
console.log(`Current time (${currentTimeStr}) is BEFORE 20:00`);
|
|
141
|
+
console.log(`✓ Expected: Dinner available = ${dinner.length > 0 ? 'YES ✓' : 'NO ✗'}`);
|
|
142
|
+
} else {
|
|
143
|
+
console.log(`Current time (${currentTimeStr}) is AT OR AFTER 20:00`);
|
|
144
|
+
console.log(`✓ Expected: Dinner blocked = ${dinner.length === 0 ? 'YES ✓' : 'NO ✗'}`);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
console.log('\n=== TEST COMPLETE ===');
|
package/test-meal-stop-simple.js
CHANGED
|
@@ -1,93 +1,93 @@
|
|
|
1
|
-
// Simple unit test for meal stop filter logic
|
|
2
|
-
|
|
3
|
-
const { parseTime, getMealTypeByTime } = require('./tableHelpers');
|
|
4
|
-
|
|
5
|
-
console.log('=== MEAL STOP FILTER LOGIC TEST ===\n');
|
|
6
|
-
|
|
7
|
-
// Get current time in Brussels using Intl.DateTimeFormat (reliable timezone conversion)
|
|
8
|
-
const now = new Date();
|
|
9
|
-
const formatter = new Intl.DateTimeFormat('en-US', {
|
|
10
|
-
timeZone: 'Europe/Brussels',
|
|
11
|
-
hour: '2-digit',
|
|
12
|
-
minute: '2-digit',
|
|
13
|
-
hour12: false,
|
|
14
|
-
});
|
|
15
|
-
const parts = formatter.formatToParts(now);
|
|
16
|
-
const timeParts = Object.fromEntries(parts.map(p => [p.type, p.value]));
|
|
17
|
-
const currentTimeMinutes = parseInt(timeParts.hour, 10) * 60 + parseInt(timeParts.minute, 10);
|
|
18
|
-
const currentTimeStr = `${timeParts.hour}:${timeParts.minute}`;
|
|
19
|
-
|
|
20
|
-
console.log(`Current time in Brussels: ${currentTimeStr} (${currentTimeMinutes} minutes since midnight)`);
|
|
21
|
-
console.log('');
|
|
22
|
-
|
|
23
|
-
// Define stop times
|
|
24
|
-
const breakfastStop = "10:00";
|
|
25
|
-
const lunchStop = "12:00";
|
|
26
|
-
const dinnerStop = "20:00";
|
|
27
|
-
|
|
28
|
-
console.log('Configured stop times:');
|
|
29
|
-
console.log(` - Breakfast stops at: ${breakfastStop} (${parseTime(breakfastStop)} minutes)`);
|
|
30
|
-
console.log(` - Lunch stops at: ${lunchStop} (${parseTime(lunchStop)} minutes)`);
|
|
31
|
-
console.log(` - Dinner stops at: ${dinnerStop} (${parseTime(dinnerStop)} minutes)`);
|
|
32
|
-
console.log('');
|
|
33
|
-
|
|
34
|
-
// Calculate which meals should be stopped
|
|
35
|
-
const breakfastStopMinutes = parseTime(breakfastStop);
|
|
36
|
-
const lunchStopMinutes = parseTime(lunchStop);
|
|
37
|
-
const dinnerStopMinutes = parseTime(dinnerStop);
|
|
38
|
-
|
|
39
|
-
const breakfastStopped = currentTimeMinutes >= breakfastStopMinutes;
|
|
40
|
-
const lunchStopped = currentTimeMinutes >= lunchStopMinutes;
|
|
41
|
-
const dinnerStopped = currentTimeMinutes >= dinnerStopMinutes;
|
|
42
|
-
|
|
43
|
-
console.log('Filter decisions based on current time:');
|
|
44
|
-
console.log(` - Breakfast: ${breakfastStopped ? '🔴 STOPPED (current time >= stop time)' : '🟢 AVAILABLE (current time < stop time)'}`);
|
|
45
|
-
console.log(` - Lunch: ${lunchStopped ? '🔴 STOPPED (current time >= stop time)' : '🟢 AVAILABLE (current time < stop time)'}`);
|
|
46
|
-
console.log(` - Dinner: ${dinnerStopped ? '🔴 STOPPED (current time >= stop time)' : '🟢 AVAILABLE (current time < stop time)'}`);
|
|
47
|
-
console.log('');
|
|
48
|
-
|
|
49
|
-
// Test with example time slots
|
|
50
|
-
console.log('--- Example: How different time slots would be filtered ---');
|
|
51
|
-
const exampleSlots = [
|
|
52
|
-
'08:00', '08:30', '09:00', '09:30', // Breakfast
|
|
53
|
-
'11:00', '11:30', '12:00', '12:30', '13:00', '13:30', '14:00', // Lunch
|
|
54
|
-
'17:00', '18:00', '19:00', '20:00', '21:00' // Dinner
|
|
55
|
-
];
|
|
56
|
-
|
|
57
|
-
exampleSlots.forEach(timeSlot => {
|
|
58
|
-
const mealType = getMealTypeByTime(timeSlot);
|
|
59
|
-
let willBeRemoved = false;
|
|
60
|
-
let reason = '';
|
|
61
|
-
|
|
62
|
-
if (mealType === 'breakfast' && breakfastStopped) {
|
|
63
|
-
willBeRemoved = true;
|
|
64
|
-
reason = 'breakfast is stopped';
|
|
65
|
-
} else if (mealType === 'lunch' && lunchStopped) {
|
|
66
|
-
willBeRemoved = true;
|
|
67
|
-
reason = 'lunch is stopped';
|
|
68
|
-
} else if (mealType === 'dinner' && dinnerStopped) {
|
|
69
|
-
willBeRemoved = true;
|
|
70
|
-
reason = 'dinner is stopped';
|
|
71
|
-
} else {
|
|
72
|
-
reason = `${mealType} is still available`;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
const status = willBeRemoved ? '❌ REMOVED' : '✅ AVAILABLE';
|
|
76
|
-
console.log(` ${timeSlot} (${mealType}): ${status} - ${reason}`);
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
console.log('\n--- Key Points ---');
|
|
80
|
-
console.log('✓ The filter compares CURRENT TIME against stop time (not reservation time vs stop time)');
|
|
81
|
-
console.log('✓ When current time >= stop time, ALL slots for that meal type are removed');
|
|
82
|
-
console.log('✓ This ensures users in Brussels timezone see correct availability');
|
|
83
|
-
console.log('');
|
|
84
|
-
console.log('BEFORE the fix:');
|
|
85
|
-
console.log(' ❌ At 10:30, trying to book lunch at 12:00 would be blocked (wrong!)');
|
|
86
|
-
console.log(' ❌ The code compared reservation time (12:00) >= lunchStop (12:00)');
|
|
87
|
-
console.log('');
|
|
88
|
-
console.log('AFTER the fix:');
|
|
89
|
-
console.log(' ✅ At 10:30, you CAN book lunch at 12:00 (correct!)');
|
|
90
|
-
console.log(' ✅ The code compares current time (10:30) < lunchStop (12:00)');
|
|
91
|
-
console.log(' ✅ Only when current time reaches 12:00 will lunch bookings stop');
|
|
92
|
-
|
|
93
|
-
console.log('\n=== TEST COMPLETE ===');
|
|
1
|
+
// Simple unit test for meal stop filter logic
|
|
2
|
+
|
|
3
|
+
const { parseTime, getMealTypeByTime } = require('./tableHelpers');
|
|
4
|
+
|
|
5
|
+
console.log('=== MEAL STOP FILTER LOGIC TEST ===\n');
|
|
6
|
+
|
|
7
|
+
// Get current time in Brussels using Intl.DateTimeFormat (reliable timezone conversion)
|
|
8
|
+
const now = new Date();
|
|
9
|
+
const formatter = new Intl.DateTimeFormat('en-US', {
|
|
10
|
+
timeZone: 'Europe/Brussels',
|
|
11
|
+
hour: '2-digit',
|
|
12
|
+
minute: '2-digit',
|
|
13
|
+
hour12: false,
|
|
14
|
+
});
|
|
15
|
+
const parts = formatter.formatToParts(now);
|
|
16
|
+
const timeParts = Object.fromEntries(parts.map(p => [p.type, p.value]));
|
|
17
|
+
const currentTimeMinutes = parseInt(timeParts.hour, 10) * 60 + parseInt(timeParts.minute, 10);
|
|
18
|
+
const currentTimeStr = `${timeParts.hour}:${timeParts.minute}`;
|
|
19
|
+
|
|
20
|
+
console.log(`Current time in Brussels: ${currentTimeStr} (${currentTimeMinutes} minutes since midnight)`);
|
|
21
|
+
console.log('');
|
|
22
|
+
|
|
23
|
+
// Define stop times
|
|
24
|
+
const breakfastStop = "10:00";
|
|
25
|
+
const lunchStop = "12:00";
|
|
26
|
+
const dinnerStop = "20:00";
|
|
27
|
+
|
|
28
|
+
console.log('Configured stop times:');
|
|
29
|
+
console.log(` - Breakfast stops at: ${breakfastStop} (${parseTime(breakfastStop)} minutes)`);
|
|
30
|
+
console.log(` - Lunch stops at: ${lunchStop} (${parseTime(lunchStop)} minutes)`);
|
|
31
|
+
console.log(` - Dinner stops at: ${dinnerStop} (${parseTime(dinnerStop)} minutes)`);
|
|
32
|
+
console.log('');
|
|
33
|
+
|
|
34
|
+
// Calculate which meals should be stopped
|
|
35
|
+
const breakfastStopMinutes = parseTime(breakfastStop);
|
|
36
|
+
const lunchStopMinutes = parseTime(lunchStop);
|
|
37
|
+
const dinnerStopMinutes = parseTime(dinnerStop);
|
|
38
|
+
|
|
39
|
+
const breakfastStopped = currentTimeMinutes >= breakfastStopMinutes;
|
|
40
|
+
const lunchStopped = currentTimeMinutes >= lunchStopMinutes;
|
|
41
|
+
const dinnerStopped = currentTimeMinutes >= dinnerStopMinutes;
|
|
42
|
+
|
|
43
|
+
console.log('Filter decisions based on current time:');
|
|
44
|
+
console.log(` - Breakfast: ${breakfastStopped ? '🔴 STOPPED (current time >= stop time)' : '🟢 AVAILABLE (current time < stop time)'}`);
|
|
45
|
+
console.log(` - Lunch: ${lunchStopped ? '🔴 STOPPED (current time >= stop time)' : '🟢 AVAILABLE (current time < stop time)'}`);
|
|
46
|
+
console.log(` - Dinner: ${dinnerStopped ? '🔴 STOPPED (current time >= stop time)' : '🟢 AVAILABLE (current time < stop time)'}`);
|
|
47
|
+
console.log('');
|
|
48
|
+
|
|
49
|
+
// Test with example time slots
|
|
50
|
+
console.log('--- Example: How different time slots would be filtered ---');
|
|
51
|
+
const exampleSlots = [
|
|
52
|
+
'08:00', '08:30', '09:00', '09:30', // Breakfast
|
|
53
|
+
'11:00', '11:30', '12:00', '12:30', '13:00', '13:30', '14:00', // Lunch
|
|
54
|
+
'17:00', '18:00', '19:00', '20:00', '21:00' // Dinner
|
|
55
|
+
];
|
|
56
|
+
|
|
57
|
+
exampleSlots.forEach(timeSlot => {
|
|
58
|
+
const mealType = getMealTypeByTime(timeSlot);
|
|
59
|
+
let willBeRemoved = false;
|
|
60
|
+
let reason = '';
|
|
61
|
+
|
|
62
|
+
if (mealType === 'breakfast' && breakfastStopped) {
|
|
63
|
+
willBeRemoved = true;
|
|
64
|
+
reason = 'breakfast is stopped';
|
|
65
|
+
} else if (mealType === 'lunch' && lunchStopped) {
|
|
66
|
+
willBeRemoved = true;
|
|
67
|
+
reason = 'lunch is stopped';
|
|
68
|
+
} else if (mealType === 'dinner' && dinnerStopped) {
|
|
69
|
+
willBeRemoved = true;
|
|
70
|
+
reason = 'dinner is stopped';
|
|
71
|
+
} else {
|
|
72
|
+
reason = `${mealType} is still available`;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const status = willBeRemoved ? '❌ REMOVED' : '✅ AVAILABLE';
|
|
76
|
+
console.log(` ${timeSlot} (${mealType}): ${status} - ${reason}`);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
console.log('\n--- Key Points ---');
|
|
80
|
+
console.log('✓ The filter compares CURRENT TIME against stop time (not reservation time vs stop time)');
|
|
81
|
+
console.log('✓ When current time >= stop time, ALL slots for that meal type are removed');
|
|
82
|
+
console.log('✓ This ensures users in Brussels timezone see correct availability');
|
|
83
|
+
console.log('');
|
|
84
|
+
console.log('BEFORE the fix:');
|
|
85
|
+
console.log(' ❌ At 10:30, trying to book lunch at 12:00 would be blocked (wrong!)');
|
|
86
|
+
console.log(' ❌ The code compared reservation time (12:00) >= lunchStop (12:00)');
|
|
87
|
+
console.log('');
|
|
88
|
+
console.log('AFTER the fix:');
|
|
89
|
+
console.log(' ✅ At 10:30, you CAN book lunch at 12:00 (correct!)');
|
|
90
|
+
console.log(' ✅ The code compares current time (10:30) < lunchStop (12:00)');
|
|
91
|
+
console.log(' ✅ Only when current time reaches 12:00 will lunch bookings stop');
|
|
92
|
+
|
|
93
|
+
console.log('\n=== TEST COMPLETE ===');
|
package/test-timezone-debug.js
CHANGED
|
@@ -1,47 +1,47 @@
|
|
|
1
|
-
// Test timezone handling
|
|
2
|
-
const moment = require('moment-timezone');
|
|
3
|
-
|
|
4
|
-
const testDate = "2025-12-08";
|
|
5
|
-
const testTime = "14:15";
|
|
6
|
-
|
|
7
|
-
console.log('=== TIMEZONE DEBUG ===\n');
|
|
8
|
-
|
|
9
|
-
// What the algorithm does
|
|
10
|
-
const now = new Date();
|
|
11
|
-
console.log('System now:', now);
|
|
12
|
-
console.log('System now ISO:', now.toISOString());
|
|
13
|
-
console.log('System now local string:', now.toString());
|
|
14
|
-
|
|
15
|
-
// Parse the time as the algorithm does (line 68-69 in getAvailableTimeblocks.js)
|
|
16
|
-
const [year, month, day] = testDate.split('-').map(Number);
|
|
17
|
-
const targetDateInTimeZone = new Date(year, month - 1, day);
|
|
18
|
-
console.log('\nTarget date:', targetDateInTimeZone);
|
|
19
|
-
console.log('Target date string:', targetDateInTimeZone.toString());
|
|
20
|
-
|
|
21
|
-
const isToday = now.toDateString() === targetDateInTimeZone.toDateString();
|
|
22
|
-
console.log('\nIs today?:', isToday);
|
|
23
|
-
|
|
24
|
-
// With uurOpVoorhand = 0
|
|
25
|
-
const uurOpVoorhand = 0;
|
|
26
|
-
const cutoffTime = new Date(now.getTime());
|
|
27
|
-
cutoffTime.setHours(cutoffTime.getHours() + uurOpVoorhand);
|
|
28
|
-
console.log('\nCutoff time (now + 0 hours):', cutoffTime);
|
|
29
|
-
console.log('Cutoff time string:', cutoffTime.toString());
|
|
30
|
-
|
|
31
|
-
// Parse the test time
|
|
32
|
-
const [hours, minutes] = testTime.split(':').map(Number);
|
|
33
|
-
const timeBlockDateTime = new Date(year, month - 1, day, hours, minutes);
|
|
34
|
-
console.log('\nTime block (14:15):', timeBlockDateTime);
|
|
35
|
-
console.log('Time block string:', timeBlockDateTime.toString());
|
|
36
|
-
|
|
37
|
-
console.log('\nComparison:');
|
|
38
|
-
console.log('timeBlockDateTime < cutoffTime:', timeBlockDateTime < cutoffTime);
|
|
39
|
-
console.log('Should be filtered out?:', timeBlockDateTime < cutoffTime ? 'YES' : 'NO');
|
|
40
|
-
|
|
41
|
-
// Check with Europe/Brussels timezone
|
|
42
|
-
console.log('\n=== Using moment-timezone ===');
|
|
43
|
-
const nowBrussels = moment.tz('Europe/Brussels');
|
|
44
|
-
console.log('Now in Brussels:', nowBrussels.format('YYYY-MM-DD HH:mm:ss Z'));
|
|
45
|
-
const targetTimeBrussels = moment.tz(`${testDate} ${testTime}`, 'YYYY-MM-DD HH:mm', 'Europe/Brussels');
|
|
46
|
-
console.log('Target time in Brussels:', targetTimeBrussels.format('YYYY-MM-DD HH:mm:ss Z'));
|
|
47
|
-
console.log('Is target time in past?:', targetTimeBrussels.isBefore(nowBrussels));
|
|
1
|
+
// Test timezone handling
|
|
2
|
+
const moment = require('moment-timezone');
|
|
3
|
+
|
|
4
|
+
const testDate = "2025-12-08";
|
|
5
|
+
const testTime = "14:15";
|
|
6
|
+
|
|
7
|
+
console.log('=== TIMEZONE DEBUG ===\n');
|
|
8
|
+
|
|
9
|
+
// What the algorithm does
|
|
10
|
+
const now = new Date();
|
|
11
|
+
console.log('System now:', now);
|
|
12
|
+
console.log('System now ISO:', now.toISOString());
|
|
13
|
+
console.log('System now local string:', now.toString());
|
|
14
|
+
|
|
15
|
+
// Parse the time as the algorithm does (line 68-69 in getAvailableTimeblocks.js)
|
|
16
|
+
const [year, month, day] = testDate.split('-').map(Number);
|
|
17
|
+
const targetDateInTimeZone = new Date(year, month - 1, day);
|
|
18
|
+
console.log('\nTarget date:', targetDateInTimeZone);
|
|
19
|
+
console.log('Target date string:', targetDateInTimeZone.toString());
|
|
20
|
+
|
|
21
|
+
const isToday = now.toDateString() === targetDateInTimeZone.toDateString();
|
|
22
|
+
console.log('\nIs today?:', isToday);
|
|
23
|
+
|
|
24
|
+
// With uurOpVoorhand = 0
|
|
25
|
+
const uurOpVoorhand = 0;
|
|
26
|
+
const cutoffTime = new Date(now.getTime());
|
|
27
|
+
cutoffTime.setHours(cutoffTime.getHours() + uurOpVoorhand);
|
|
28
|
+
console.log('\nCutoff time (now + 0 hours):', cutoffTime);
|
|
29
|
+
console.log('Cutoff time string:', cutoffTime.toString());
|
|
30
|
+
|
|
31
|
+
// Parse the test time
|
|
32
|
+
const [hours, minutes] = testTime.split(':').map(Number);
|
|
33
|
+
const timeBlockDateTime = new Date(year, month - 1, day, hours, minutes);
|
|
34
|
+
console.log('\nTime block (14:15):', timeBlockDateTime);
|
|
35
|
+
console.log('Time block string:', timeBlockDateTime.toString());
|
|
36
|
+
|
|
37
|
+
console.log('\nComparison:');
|
|
38
|
+
console.log('timeBlockDateTime < cutoffTime:', timeBlockDateTime < cutoffTime);
|
|
39
|
+
console.log('Should be filtered out?:', timeBlockDateTime < cutoffTime ? 'YES' : 'NO');
|
|
40
|
+
|
|
41
|
+
// Check with Europe/Brussels timezone
|
|
42
|
+
console.log('\n=== Using moment-timezone ===');
|
|
43
|
+
const nowBrussels = moment.tz('Europe/Brussels');
|
|
44
|
+
console.log('Now in Brussels:', nowBrussels.format('YYYY-MM-DD HH:mm:ss Z'));
|
|
45
|
+
const targetTimeBrussels = moment.tz(`${testDate} ${testTime}`, 'YYYY-MM-DD HH:mm', 'Europe/Brussels');
|
|
46
|
+
console.log('Target time in Brussels:', targetTimeBrussels.format('YYYY-MM-DD HH:mm:ss Z'));
|
|
47
|
+
console.log('Is target time in past?:', targetTimeBrussels.isBefore(nowBrussels));
|