@happychef/algorithm 1.2.25 → 1.2.26
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/getAvailableTimeblocks.js +10 -4
- package/isDateAvailable.js +5 -2
- package/package.json +1 -1
|
@@ -19,18 +19,21 @@ function getDatePartsInTimeZone(date, timeZone) {
|
|
|
19
19
|
hour: '2-digit',
|
|
20
20
|
minute: '2-digit',
|
|
21
21
|
second: '2-digit',
|
|
22
|
-
hour12:
|
|
22
|
+
hourCycle: 'h23', // Use 'h23' instead of hour12:false for consistent 0-23 range
|
|
23
23
|
});
|
|
24
24
|
const parts = formatter.formatToParts(date);
|
|
25
25
|
const values = {};
|
|
26
26
|
for (const part of parts) {
|
|
27
27
|
values[part.type] = part.value;
|
|
28
28
|
}
|
|
29
|
+
// Handle edge case: Chrome may return "24" for midnight with some hourCycle settings
|
|
30
|
+
let hour = parseInt(values.hour, 10);
|
|
31
|
+
if (hour === 24) hour = 0;
|
|
29
32
|
return {
|
|
30
33
|
year: parseInt(values.year, 10),
|
|
31
34
|
month: parseInt(values.month, 10),
|
|
32
35
|
day: parseInt(values.day, 10),
|
|
33
|
-
hour:
|
|
36
|
+
hour: hour,
|
|
34
37
|
minute: parseInt(values.minute, 10),
|
|
35
38
|
second: parseInt(values.second, 10),
|
|
36
39
|
};
|
|
@@ -152,11 +155,14 @@ function getAvailableTimeblocks(data, dateStr, reservations, guests, blockedSlot
|
|
|
152
155
|
timeZone: 'Europe/Brussels',
|
|
153
156
|
hour: '2-digit',
|
|
154
157
|
minute: '2-digit',
|
|
155
|
-
|
|
158
|
+
hourCycle: 'h23', // Use 'h23' for consistent 0-23 hour range across browsers
|
|
156
159
|
});
|
|
157
160
|
const parts = formatter.formatToParts(now);
|
|
158
161
|
const timeParts = Object.fromEntries(parts.map(p => [p.type, p.value]));
|
|
159
|
-
|
|
162
|
+
// Handle edge case: some browsers may return "24" for midnight
|
|
163
|
+
let hourValue = parseInt(timeParts.hour, 10);
|
|
164
|
+
if (hourValue === 24) hourValue = 0;
|
|
165
|
+
const currentTimeMinutes = hourValue * 60 + parseInt(timeParts.minute, 10);
|
|
160
166
|
|
|
161
167
|
// Check if current time has passed any stop times
|
|
162
168
|
const breakfastStopMinutes = breakfastStop ? parseTime(breakfastStop) : null;
|
package/isDateAvailable.js
CHANGED
|
@@ -28,18 +28,21 @@ function getDatePartsInTimeZone(date, timeZone) {
|
|
|
28
28
|
hour: '2-digit',
|
|
29
29
|
minute: '2-digit',
|
|
30
30
|
second: '2-digit',
|
|
31
|
-
hour12:
|
|
31
|
+
hourCycle: 'h23', // Use 'h23' instead of hour12:false for consistent 0-23 range
|
|
32
32
|
});
|
|
33
33
|
const parts = formatter.formatToParts(date);
|
|
34
34
|
const values = {};
|
|
35
35
|
for (const part of parts) {
|
|
36
36
|
values[part.type] = part.value;
|
|
37
37
|
}
|
|
38
|
+
// Handle edge case: Chrome may return "24" for midnight with some hourCycle settings
|
|
39
|
+
let hour = parseInt(values.hour, 10);
|
|
40
|
+
if (hour === 24) hour = 0;
|
|
38
41
|
return {
|
|
39
42
|
year: parseInt(values.year, 10),
|
|
40
43
|
month: parseInt(values.month, 10),
|
|
41
44
|
day: parseInt(values.day, 10),
|
|
42
|
-
hour:
|
|
45
|
+
hour: hour,
|
|
43
46
|
minute: parseInt(values.minute, 10),
|
|
44
47
|
second: parseInt(values.second, 10),
|
|
45
48
|
};
|