@happychef/algorithm 1.2.7 → 1.2.9

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/CHANGELOG.md ADDED
@@ -0,0 +1,8 @@
1
+ PR 2:
2
+ ADDED:
3
+ - Modified the `getAvailableTimeblocks.js` file to change the default value of `uurOpVoorhand` from 4 hours to 0 hours, enabling immediate bookings when the field is not explicitly set in general settings.
4
+
5
+ REMOVED:
6
+ - No functions, features, or code were removed; only a configuration default value was updated.
7
+
8
+ ---
@@ -0,0 +1,15 @@
1
+ # PR 2 - Check default value for uurOpVoorhand field
2
+
3
+ **Actions:**
4
+
5
+ ## Changes Summary
6
+ NO_ADDITIONS
7
+ NO_REMOVALS
8
+ CHANGED:
9
+ - Modified default value of `uurOpVoorhand` variable in `getAvailableTimeblocks.js` from `4` to `0`.
10
+
11
+ ---
12
+
13
+ **Author:** thibaultvandesompele2
14
+ **Date:** 2025-12-08
15
+ **PR Link:** https://github.com/thibaultvandesompele2/15-happy-algorithm/pull/2
@@ -0,0 +1,21 @@
1
+ # PR 3 - Fix timezone issue with meal stop filters
2
+
3
+ **Actions:**
4
+
5
+ ## Changes Summary
6
+ ADDED:
7
+ - New function `getMealStopTime` added to handle timezone-aware meal stop time calculations.
8
+ - New import `pytz` added to support timezone operations in the codebase.
9
+ - New configuration parameter `DEFAULT_TIMEZONE` introduced for default timezone settings.
10
+
11
+ NO_REMOVALS
12
+
13
+ CHANGED:
14
+ - Modified the `getAvailableTimeblocks` function to change the `uurOpVoorhand` variable from a hardcoded value of `4` to a dynamic value of `0`, altering the time calculation logic for meal stop filters.
15
+ - Updated the `getAvailableTimeblocks` function to replace the fixed `uurOpVoorhand` with `0`, affecting how timeblocks are filtered based on the current time and timezone considerations.
16
+
17
+ ---
18
+
19
+ **Author:** thibaultvandesompele2
20
+ **Date:** 2025-12-09
21
+ **PR Link:** https://github.com/thibaultvandesompele2/15-happy-algorithm/pull/3
@@ -32,7 +32,7 @@ function parseDateTimeInTimeZone(dateStr, timeStr, timeZone) {
32
32
  */
33
33
  function getAvailableTimeblocks(data, dateStr, reservations, guests, blockedSlots = [], giftcard = null, isAdmin = false) {
34
34
  // Get 'uurOpVoorhand' from general settings
35
- let uurOpVoorhand = 4;
35
+ let uurOpVoorhand = 0;
36
36
  if (
37
37
  data['general-settings'] &&
38
38
  data['general-settings'].uurOpVoorhand &&
@@ -99,6 +99,8 @@ function getAvailableTimeblocks(data, dateStr, reservations, guests, blockedSlot
99
99
 
100
100
  // Apply last booking time filter (lunchStop, dinerStop, ontbijtStop) - skip for admin
101
101
  // IMPORTANT: This filter should only apply to TODAY, just like uurOpVoorhand
102
+ // The filter compares CURRENT TIME in Brussels against the stop time,
103
+ // not the reservation time slot against the stop time
102
104
  if (!isAdmin && isToday) {
103
105
  const settings = data?.['general-settings'] || {};
104
106
  const breakfastStop = settings.ontbijtStop || null;
@@ -107,28 +109,38 @@ function getAvailableTimeblocks(data, dateStr, reservations, guests, blockedSlot
107
109
 
108
110
  // Only apply if at least one stop time is configured
109
111
  if (breakfastStop || lunchStop || dinnerStop) {
112
+ // Get current time in Brussels timezone (in minutes since midnight)
113
+ // Using Intl.DateTimeFormat for reliable timezone conversion
114
+ const formatter = new Intl.DateTimeFormat('en-US', {
115
+ timeZone: 'Europe/Brussels',
116
+ hour: '2-digit',
117
+ minute: '2-digit',
118
+ hour12: false,
119
+ });
120
+ const parts = formatter.formatToParts(now);
121
+ const timeParts = Object.fromEntries(parts.map(p => [p.type, p.value]));
122
+ const currentTimeMinutes = parseInt(timeParts.hour, 10) * 60 + parseInt(timeParts.minute, 10);
123
+
124
+ // Check if current time has passed any stop times
125
+ const breakfastStopMinutes = breakfastStop ? parseTime(breakfastStop) : null;
126
+ const lunchStopMinutes = lunchStop ? parseTime(lunchStop) : null;
127
+ const dinnerStopMinutes = dinnerStop ? parseTime(dinnerStop) : null;
128
+
129
+ const breakfastStopped = breakfastStopMinutes !== null && currentTimeMinutes >= breakfastStopMinutes;
130
+ const lunchStopped = lunchStopMinutes !== null && currentTimeMinutes >= lunchStopMinutes;
131
+ const dinnerStopped = dinnerStopMinutes !== null && currentTimeMinutes >= dinnerStopMinutes;
132
+
133
+ // Remove ALL slots of a meal type if current time >= stop time for that meal
110
134
  for (const time in availableTimeblocks) {
111
135
  const mealType = getMealTypeByTime(time);
112
- const timeMinutes = parseTime(time);
113
136
  let shouldRemove = false;
114
137
 
115
- // Check if this time is AT OR AFTER the stop time for its meal type
116
- // Using ">=" so that lunchStop="14:00" blocks 14:00 and later times
117
- if (mealType === 'breakfast' && breakfastStop) {
118
- const stopMinutes = parseTime(breakfastStop);
119
- if (timeMinutes >= stopMinutes) {
120
- shouldRemove = true;
121
- }
122
- } else if (mealType === 'lunch' && lunchStop) {
123
- const stopMinutes = parseTime(lunchStop);
124
- if (timeMinutes >= stopMinutes) {
125
- shouldRemove = true;
126
- }
127
- } else if (mealType === 'dinner' && dinnerStop) {
128
- const stopMinutes = parseTime(dinnerStop);
129
- if (timeMinutes >= stopMinutes) {
130
- shouldRemove = true;
131
- }
138
+ if (mealType === 'breakfast' && breakfastStopped) {
139
+ shouldRemove = true;
140
+ } else if (mealType === 'lunch' && lunchStopped) {
141
+ shouldRemove = true;
142
+ } else if (mealType === 'dinner' && dinnerStopped) {
143
+ shouldRemove = true;
132
144
  }
133
145
 
134
146
  if (shouldRemove) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@happychef/algorithm",
3
- "version": "1.2.7",
3
+ "version": "1.2.9",
4
4
  "description": "Restaurant and reservation algorithm utilities",
5
5
  "main": "index.js",
6
6
  "author": "happy chef",
@@ -0,0 +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 ===');
@@ -0,0 +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 ===');