@happychef/algorithm 1.2.13 → 1.2.15

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.
@@ -1,110 +1,110 @@
1
- // Test script to debug why Monday lunch isn't showing
2
- const { getAvailableTimeblocks } = require('./getAvailableTimeblocks');
3
- const { timeblocksAvailable } = require('./processing/timeblocksAvailable');
4
- const { getDailyGuestCounts } = require('./processing/dailyGuestCounts');
5
-
6
- // Your restaurant data
7
- const restaurantData = {
8
- "_id": "demo",
9
- "openinghours-lunch": {
10
- "schemeSettings": {
11
- "Monday": {
12
- "enabled": true,
13
- "startTime": "14:15",
14
- "endTime": "15:00",
15
- "maxCapacityEnabled": true,
16
- "maxCapacity": "10",
17
- "shiftsEnabled": false,
18
- "shifts": [],
19
- "giftcardsEnabled": false,
20
- "giftcards": [],
21
- "giftcardTakeawayEnabled": false,
22
- "giftcardTakeawayStart": "",
23
- "giftcardTakeawayEnd": ""
24
- },
25
- "Wednesday": {
26
- "enabled": true,
27
- "startTime": "13:45",
28
- "endTime": "14:45",
29
- "maxCapacityEnabled": false,
30
- "maxCapacity": "",
31
- "shiftsEnabled": false,
32
- "shifts": [],
33
- "giftcardsEnabled": false,
34
- "giftcards": [],
35
- "giftcardTakeawayEnabled": true,
36
- "giftcardTakeawayStart": "11:00",
37
- "giftcardTakeawayEnd": "16:00"
38
- }
39
- }
40
- },
41
- "general-settings": {
42
- "zitplaatsen": 13,
43
- "uurOpVoorhand": 0,
44
- "dagenInToekomst": 365,
45
- "minGasten": 1,
46
- "maxGasten": 10,
47
- "intervalReservatie": 30,
48
- "duurReservatie": 60,
49
- "ontbijtStop": "",
50
- "lunchStop": "",
51
- "dinerStop": ""
52
- },
53
- "max-arrivals-lunch": {
54
- "12:00": 6,
55
- "12:15": 1,
56
- "12:30": 6,
57
- "12:45": 4,
58
- "13:00": 10,
59
- "14:15": 10,
60
- "14:30": 10,
61
- "14:45": 10,
62
- "storedNumber": 30
63
- },
64
- "exceptions": [],
65
- "blocked-slots": []
66
- };
67
-
68
- // Test for Monday December 8, 2025
69
- const testDate = "2025-12-08"; // Monday
70
- const guests = 2;
71
- const reservations = [];
72
-
73
- console.log('=== LUNCH AVAILABILITY DEBUG ===\n');
74
- console.log('Date:', testDate, '(Monday)');
75
- console.log('Guests:', guests);
76
- console.log('Current time:', new Date().toISOString());
77
- console.log('\n--- Restaurant Settings ---');
78
- console.log('Lunch Opening Hours (Monday):', restaurantData['openinghours-lunch'].schemeSettings.Monday);
79
- console.log('General Settings:', restaurantData['general-settings']);
80
- console.log('Max Arrivals Lunch:', restaurantData['max-arrivals-lunch']);
81
-
82
- console.log('\n--- Step 1: getDailyGuestCounts ---');
83
- const { guestCounts, shiftsInfo } = getDailyGuestCounts(restaurantData, testDate, reservations);
84
- console.log('Guest Counts:', guestCounts);
85
- console.log('Shifts Info:', shiftsInfo);
86
-
87
- console.log('\n--- Step 2: timeblocksAvailable ---');
88
- const timeblocks = timeblocksAvailable(restaurantData, testDate, reservations, guests, [], null, false);
89
- console.log('Available Timeblocks:', timeblocks);
90
-
91
- console.log('\n--- Step 3: getAvailableTimeblocks (with filters) ---');
92
- const finalTimeblocks = getAvailableTimeblocks(restaurantData, testDate, reservations, guests, [], null, false);
93
- console.log('Final Available Timeblocks:', finalTimeblocks);
94
-
95
- console.log('\n--- Step 4: Test with Admin Flag ---');
96
- const adminTimeblocks = getAvailableTimeblocks(restaurantData, testDate, reservations, guests, [], null, true);
97
- console.log('Admin Timeblocks (no time restrictions):', adminTimeblocks);
98
-
99
- // Check if lunch times exist
100
- const lunchTimes = ['14:15', '14:30', '14:45'];
101
- console.log('\n--- Lunch Time Analysis ---');
102
- lunchTimes.forEach(time => {
103
- console.log(`${time}:`);
104
- console.log(` - In guestCounts: ${guestCounts.hasOwnProperty(time) ? 'YES (capacity: ' + guestCounts[time] + ')' : 'NO'}`);
105
- console.log(` - In timeblocks: ${timeblocks.hasOwnProperty(time) ? 'YES' : 'NO'}`);
106
- console.log(` - In final: ${finalTimeblocks.hasOwnProperty(time) ? 'YES' : 'NO'}`);
107
- console.log(` - In admin: ${adminTimeblocks.hasOwnProperty(time) ? 'YES' : 'NO'}`);
108
- });
109
-
110
- console.log('\n=== END DEBUG ===');
1
+ // Test script to debug why Monday lunch isn't showing
2
+ const { getAvailableTimeblocks } = require('./getAvailableTimeblocks');
3
+ const { timeblocksAvailable } = require('./processing/timeblocksAvailable');
4
+ const { getDailyGuestCounts } = require('./processing/dailyGuestCounts');
5
+
6
+ // Your restaurant data
7
+ const restaurantData = {
8
+ "_id": "demo",
9
+ "openinghours-lunch": {
10
+ "schemeSettings": {
11
+ "Monday": {
12
+ "enabled": true,
13
+ "startTime": "14:15",
14
+ "endTime": "15:00",
15
+ "maxCapacityEnabled": true,
16
+ "maxCapacity": "10",
17
+ "shiftsEnabled": false,
18
+ "shifts": [],
19
+ "giftcardsEnabled": false,
20
+ "giftcards": [],
21
+ "giftcardTakeawayEnabled": false,
22
+ "giftcardTakeawayStart": "",
23
+ "giftcardTakeawayEnd": ""
24
+ },
25
+ "Wednesday": {
26
+ "enabled": true,
27
+ "startTime": "13:45",
28
+ "endTime": "14:45",
29
+ "maxCapacityEnabled": false,
30
+ "maxCapacity": "",
31
+ "shiftsEnabled": false,
32
+ "shifts": [],
33
+ "giftcardsEnabled": false,
34
+ "giftcards": [],
35
+ "giftcardTakeawayEnabled": true,
36
+ "giftcardTakeawayStart": "11:00",
37
+ "giftcardTakeawayEnd": "16:00"
38
+ }
39
+ }
40
+ },
41
+ "general-settings": {
42
+ "zitplaatsen": 13,
43
+ "uurOpVoorhand": 0,
44
+ "dagenInToekomst": 365,
45
+ "minGasten": 1,
46
+ "maxGasten": 10,
47
+ "intervalReservatie": 30,
48
+ "duurReservatie": 60,
49
+ "ontbijtStop": "",
50
+ "lunchStop": "",
51
+ "dinerStop": ""
52
+ },
53
+ "max-arrivals-lunch": {
54
+ "12:00": 6,
55
+ "12:15": 1,
56
+ "12:30": 6,
57
+ "12:45": 4,
58
+ "13:00": 10,
59
+ "14:15": 10,
60
+ "14:30": 10,
61
+ "14:45": 10,
62
+ "storedNumber": 30
63
+ },
64
+ "exceptions": [],
65
+ "blocked-slots": []
66
+ };
67
+
68
+ // Test for Monday December 8, 2025
69
+ const testDate = "2025-12-08"; // Monday
70
+ const guests = 2;
71
+ const reservations = [];
72
+
73
+ console.log('=== LUNCH AVAILABILITY DEBUG ===\n');
74
+ console.log('Date:', testDate, '(Monday)');
75
+ console.log('Guests:', guests);
76
+ console.log('Current time:', new Date().toISOString());
77
+ console.log('\n--- Restaurant Settings ---');
78
+ console.log('Lunch Opening Hours (Monday):', restaurantData['openinghours-lunch'].schemeSettings.Monday);
79
+ console.log('General Settings:', restaurantData['general-settings']);
80
+ console.log('Max Arrivals Lunch:', restaurantData['max-arrivals-lunch']);
81
+
82
+ console.log('\n--- Step 1: getDailyGuestCounts ---');
83
+ const { guestCounts, shiftsInfo } = getDailyGuestCounts(restaurantData, testDate, reservations);
84
+ console.log('Guest Counts:', guestCounts);
85
+ console.log('Shifts Info:', shiftsInfo);
86
+
87
+ console.log('\n--- Step 2: timeblocksAvailable ---');
88
+ const timeblocks = timeblocksAvailable(restaurantData, testDate, reservations, guests, [], null, false);
89
+ console.log('Available Timeblocks:', timeblocks);
90
+
91
+ console.log('\n--- Step 3: getAvailableTimeblocks (with filters) ---');
92
+ const finalTimeblocks = getAvailableTimeblocks(restaurantData, testDate, reservations, guests, [], null, false);
93
+ console.log('Final Available Timeblocks:', finalTimeblocks);
94
+
95
+ console.log('\n--- Step 4: Test with Admin Flag ---');
96
+ const adminTimeblocks = getAvailableTimeblocks(restaurantData, testDate, reservations, guests, [], null, true);
97
+ console.log('Admin Timeblocks (no time restrictions):', adminTimeblocks);
98
+
99
+ // Check if lunch times exist
100
+ const lunchTimes = ['14:15', '14:30', '14:45'];
101
+ console.log('\n--- Lunch Time Analysis ---');
102
+ lunchTimes.forEach(time => {
103
+ console.log(`${time}:`);
104
+ console.log(` - In guestCounts: ${guestCounts.hasOwnProperty(time) ? 'YES (capacity: ' + guestCounts[time] + ')' : 'NO'}`);
105
+ console.log(` - In timeblocks: ${timeblocks.hasOwnProperty(time) ? 'YES' : 'NO'}`);
106
+ console.log(` - In final: ${finalTimeblocks.hasOwnProperty(time) ? 'YES' : 'NO'}`);
107
+ console.log(` - In admin: ${adminTimeblocks.hasOwnProperty(time) ? 'YES' : 'NO'}`);
108
+ });
109
+
110
+ console.log('\n=== END DEBUG ===');
@@ -1,79 +1,79 @@
1
- // Test the max arrivals filter specifically
2
- const { filterTimeblocksByMaxArrivals } = require('./filters/maxArrivalsFilter');
3
- const { getAvailableTimeblocks } = require('./getAvailableTimeblocks');
4
-
5
- const restaurantData = {
6
- "_id": "demo",
7
- "openinghours-lunch": {
8
- "schemeSettings": {
9
- "Monday": {
10
- "enabled": true,
11
- "startTime": "14:15",
12
- "endTime": "15:00",
13
- "maxCapacityEnabled": true,
14
- "maxCapacity": "10"
15
- }
16
- }
17
- },
18
- "general-settings": {
19
- "zitplaatsen": 13,
20
- "uurOpVoorhand": 0,
21
- "dagenInToekomst": 365,
22
- "intervalReservatie": 30,
23
- "duurReservatie": 60,
24
- "ontbijtStop": "",
25
- "lunchStop": "",
26
- "dinerStop": ""
27
- },
28
- "max-arrivals-lunch": {
29
- "12:00": 6,
30
- "12:15": 1,
31
- "12:30": 6,
32
- "12:45": 4,
33
- "13:00": 10,
34
- "14:15": 10,
35
- "14:30": 10,
36
- "14:45": 10,
37
- "storedNumber": 30
38
- }
39
- };
40
-
41
- const testDate = "2025-12-08";
42
- const guests = 2;
43
- const reservations = [];
44
-
45
- console.log('=== MAX ARRIVALS FILTER TEST ===\n');
46
-
47
- // Get initial timeblocks from algorithm
48
- const timeblocks = getAvailableTimeblocks(restaurantData, testDate, reservations, guests, [], null, true);
49
- console.log('Timeblocks from algorithm (admin mode):', Object.keys(timeblocks));
50
-
51
- // Apply max arrivals filter
52
- const filtered = filterTimeblocksByMaxArrivals(restaurantData, testDate, timeblocks, reservations, guests);
53
- console.log('\nAfter max arrivals filter:', Object.keys(filtered));
54
-
55
- // Debug each time slot
56
- console.log('\n--- Detailed Analysis ---');
57
- for (const time of Object.keys(timeblocks)) {
58
- const maxArrivalsConfig = restaurantData['max-arrivals-lunch'];
59
- const maxArrivals = maxArrivalsConfig ? maxArrivalsConfig[time] : null;
60
-
61
- const currentArrivals = reservations
62
- .filter(r => r.date === testDate && r.time === time)
63
- .reduce((sum, r) => sum + (parseInt(r.guests, 10) || 0), 0);
64
-
65
- const isInFiltered = filtered.hasOwnProperty(time);
66
-
67
- console.log(`\n${time}:`);
68
- console.log(` Max arrivals setting: ${maxArrivals || 'NOT SET'}`);
69
- console.log(` Current arrivals: ${currentArrivals}`);
70
- console.log(` New reservation: ${guests} guests`);
71
- console.log(` Total after adding: ${currentArrivals + guests}`);
72
- console.log(` Passes filter: ${isInFiltered ? 'YES' : 'NO'}`);
73
-
74
- if (maxArrivals !== null && maxArrivals !== undefined) {
75
- console.log(` Logic: ${currentArrivals} + ${guests} = ${currentArrivals + guests} ${currentArrivals + guests <= maxArrivals ? '<=' : '>'} ${maxArrivals}`);
76
- }
77
- }
78
-
79
- console.log('\n=== END TEST ===');
1
+ // Test the max arrivals filter specifically
2
+ const { filterTimeblocksByMaxArrivals } = require('./filters/maxArrivalsFilter');
3
+ const { getAvailableTimeblocks } = require('./getAvailableTimeblocks');
4
+
5
+ const restaurantData = {
6
+ "_id": "demo",
7
+ "openinghours-lunch": {
8
+ "schemeSettings": {
9
+ "Monday": {
10
+ "enabled": true,
11
+ "startTime": "14:15",
12
+ "endTime": "15:00",
13
+ "maxCapacityEnabled": true,
14
+ "maxCapacity": "10"
15
+ }
16
+ }
17
+ },
18
+ "general-settings": {
19
+ "zitplaatsen": 13,
20
+ "uurOpVoorhand": 0,
21
+ "dagenInToekomst": 365,
22
+ "intervalReservatie": 30,
23
+ "duurReservatie": 60,
24
+ "ontbijtStop": "",
25
+ "lunchStop": "",
26
+ "dinerStop": ""
27
+ },
28
+ "max-arrivals-lunch": {
29
+ "12:00": 6,
30
+ "12:15": 1,
31
+ "12:30": 6,
32
+ "12:45": 4,
33
+ "13:00": 10,
34
+ "14:15": 10,
35
+ "14:30": 10,
36
+ "14:45": 10,
37
+ "storedNumber": 30
38
+ }
39
+ };
40
+
41
+ const testDate = "2025-12-08";
42
+ const guests = 2;
43
+ const reservations = [];
44
+
45
+ console.log('=== MAX ARRIVALS FILTER TEST ===\n');
46
+
47
+ // Get initial timeblocks from algorithm
48
+ const timeblocks = getAvailableTimeblocks(restaurantData, testDate, reservations, guests, [], null, true);
49
+ console.log('Timeblocks from algorithm (admin mode):', Object.keys(timeblocks));
50
+
51
+ // Apply max arrivals filter
52
+ const filtered = filterTimeblocksByMaxArrivals(restaurantData, testDate, timeblocks, reservations, guests);
53
+ console.log('\nAfter max arrivals filter:', Object.keys(filtered));
54
+
55
+ // Debug each time slot
56
+ console.log('\n--- Detailed Analysis ---');
57
+ for (const time of Object.keys(timeblocks)) {
58
+ const maxArrivalsConfig = restaurantData['max-arrivals-lunch'];
59
+ const maxArrivals = maxArrivalsConfig ? maxArrivalsConfig[time] : null;
60
+
61
+ const currentArrivals = reservations
62
+ .filter(r => r.date === testDate && r.time === time)
63
+ .reduce((sum, r) => sum + (parseInt(r.guests, 10) || 0), 0);
64
+
65
+ const isInFiltered = filtered.hasOwnProperty(time);
66
+
67
+ console.log(`\n${time}:`);
68
+ console.log(` Max arrivals setting: ${maxArrivals || 'NOT SET'}`);
69
+ console.log(` Current arrivals: ${currentArrivals}`);
70
+ console.log(` New reservation: ${guests} guests`);
71
+ console.log(` Total after adding: ${currentArrivals + guests}`);
72
+ console.log(` Passes filter: ${isInFiltered ? 'YES' : 'NO'}`);
73
+
74
+ if (maxArrivals !== null && maxArrivals !== undefined) {
75
+ console.log(` Logic: ${currentArrivals} + ${guests} = ${currentArrivals + guests} ${currentArrivals + guests <= maxArrivals ? '<=' : '>'} ${maxArrivals}`);
76
+ }
77
+ }
78
+
79
+ console.log('\n=== END TEST ===');
@@ -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));