atriusmaps-node-sdk 3.3.1165 → 3.3.1167
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/dist/cjs/package.json.js +1 -1
- package/dist/cjs/plugins/poiDataManager/src/computeIsOpenNow.js +7 -4
- package/dist/cjs/src/utils/operationHours.js +94 -260
- package/dist/package.json.js +1 -1
- package/dist/plugins/poiDataManager/src/computeIsOpenNow.js +1 -1
- package/dist/src/utils/operationHours.js +1 -1
- package/package.json +1 -1
package/dist/cjs/package.json.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var luxon = require('luxon');
|
|
3
4
|
var operationHours = require('../../../src/utils/operationHours.js');
|
|
4
5
|
var constants = require('../../../utils/constants.js');
|
|
5
6
|
|
|
6
|
-
const SOON_THRESHOLD_MINUTES = 60;
|
|
7
7
|
function computeIsOpenNow(poi, venueTimezone, now = /* @__PURE__ */ new Date()) {
|
|
8
8
|
if (poi.state === "permanently-closed") {
|
|
9
9
|
return false;
|
|
@@ -26,7 +26,7 @@ function computeIsOpenNow(poi, venueTimezone, now = /* @__PURE__ */ new Date())
|
|
|
26
26
|
if (!weekdayPeriods || weekdayPeriods.length === 0) {
|
|
27
27
|
return void 0;
|
|
28
28
|
}
|
|
29
|
-
return operationHours.isOpen(weekdayPeriods,
|
|
29
|
+
return operationHours.isOpen(weekdayPeriods, luxon.DateTime.fromJSDate(now, { zone: venueTimezone }));
|
|
30
30
|
}
|
|
31
31
|
function computePoiOpenStatus(poi, venueTimezone, T, now = /* @__PURE__ */ new Date()) {
|
|
32
32
|
const openNow = computeIsOpenNow(poi, venueTimezone, now);
|
|
@@ -57,14 +57,17 @@ function resolveStatus(poi, venueTimezone, openNow, now) {
|
|
|
57
57
|
if (!weekdayPeriods || weekdayPeriods.length === 0) {
|
|
58
58
|
return plainStatus;
|
|
59
59
|
}
|
|
60
|
-
const { minutesToOpen, minutesToClose } = operationHours.getBoundaryMinutes(
|
|
60
|
+
const { minutesToOpen, minutesToClose } = operationHours.getBoundaryMinutes(
|
|
61
|
+
weekdayPeriods,
|
|
62
|
+
luxon.DateTime.fromJSDate(now, { zone: venueTimezone })
|
|
63
|
+
);
|
|
61
64
|
if (openNow) {
|
|
62
65
|
return isWithinThreshold(minutesToClose) ? constants.PoiOpenStatus.CLOSING_SOON : constants.PoiOpenStatus.OPEN;
|
|
63
66
|
}
|
|
64
67
|
return isWithinThreshold(minutesToOpen) ? constants.PoiOpenStatus.OPENING_SOON : constants.PoiOpenStatus.CLOSED;
|
|
65
68
|
}
|
|
66
69
|
function isWithinThreshold(minutes) {
|
|
67
|
-
return minutes !== void 0 && minutes > 0 && minutes <= SOON_THRESHOLD_MINUTES;
|
|
70
|
+
return minutes !== void 0 && minutes > 0 && minutes <= operationHours.SOON_THRESHOLD_MINUTES;
|
|
68
71
|
}
|
|
69
72
|
|
|
70
73
|
exports.computeIsOpenNow = computeIsOpenNow;
|
|
@@ -1,297 +1,131 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var luxon = require('luxon');
|
|
4
|
-
var R = require('ramda');
|
|
5
4
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
5
|
+
const SOON_THRESHOLD_MINUTES = 60;
|
|
6
|
+
const WEEKDAYS = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
|
|
7
|
+
const SHORT_WEEKDAYS = ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"];
|
|
8
|
+
const HOURS_PATTERN = /^(Su|Mo|Tu|We|Th|Fr|Sa)(?:-(Su|Mo|Tu|We|Th|Fr|Sa))?\s+(\d{1,2}:\d{2})-(\d{1,2}:\d{2})$/;
|
|
9
|
+
function canParseOperationHours(hours) {
|
|
10
|
+
return typeof hours === "string" && hours.trim() !== "" && hours.split(";").every((part) => HOURS_PATTERN.test(part.trim()));
|
|
11
|
+
}
|
|
12
|
+
function parseAndOrderWeekdays(hours, today) {
|
|
13
|
+
const periods = /* @__PURE__ */ new Map();
|
|
14
|
+
for (const segment of hours.split(";")) {
|
|
15
|
+
const match = HOURS_PATTERN.exec(segment.trim());
|
|
16
|
+
if (!match) {
|
|
17
|
+
return [];
|
|
18
|
+
}
|
|
19
|
+
const [, firstDay, lastDay, opening, closing] = match;
|
|
20
|
+
const from = parseTime(opening);
|
|
21
|
+
const to = parseTime(closing);
|
|
22
|
+
const timePeriod = { from, to, formatted: `${formatTime(from)} - ${formatTime(to)}` };
|
|
23
|
+
const start = SHORT_WEEKDAYS.indexOf(firstDay);
|
|
24
|
+
const end = SHORT_WEEKDAYS.indexOf(lastDay ?? firstDay);
|
|
25
|
+
let day = start;
|
|
26
|
+
do {
|
|
27
|
+
periods.set(day, timePeriod);
|
|
28
|
+
if (day === end) {
|
|
29
|
+
break;
|
|
16
30
|
}
|
|
17
|
-
|
|
31
|
+
day = (day + 1) % WEEKDAYS.length;
|
|
32
|
+
} while (day !== start);
|
|
18
33
|
}
|
|
19
|
-
|
|
20
|
-
return Object.freeze(n);
|
|
34
|
+
return [...periods.entries()].sort(([a], [b]) => a - b).map(([day, timePeriod]) => ({ weekday: WEEKDAYS[day], isToday: day === today.getDay(), timePeriod }));
|
|
21
35
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
function canParseOperationHours(operationHours) {
|
|
26
|
-
if (!operationHours || typeof operationHours !== "string") {
|
|
27
|
-
return false;
|
|
28
|
-
}
|
|
29
|
-
const trimmed = operationHours.trim();
|
|
30
|
-
if (trimmed === "") {
|
|
31
|
-
return false;
|
|
32
|
-
}
|
|
33
|
-
const validDayPattern = /^(Su|Mo|Tu|We|Th|Fr|Sa)(-(?:Su|Mo|Tu|We|Th|Fr|Sa))?\s+\d{1,2}:\d{2}-\d{1,2}:\d{2}$/;
|
|
34
|
-
const segments = trimmed.split(";").map((s) => s.trim());
|
|
35
|
-
return segments.every((segment) => validDayPattern.test(segment));
|
|
36
|
+
function isOpen(periods, today) {
|
|
37
|
+
return Boolean(resolveSchedule(periods, asDateTime(today)).active);
|
|
36
38
|
}
|
|
37
|
-
function
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
return false;
|
|
41
|
-
}
|
|
42
|
-
const hours = today.getHours();
|
|
43
|
-
const minutes = today.getMinutes();
|
|
44
|
-
const { from, to } = currentWeekday.timePeriod;
|
|
45
|
-
return isInTimePeriod(hours, minutes, from.hours, from.minutes, to.hours, to.minutes);
|
|
46
|
-
}
|
|
47
|
-
function getBoundaryMinutes(weekdayPeriods, localizedNow) {
|
|
48
|
-
const currentWeekday = findWeekday(weekdayPeriods, localizedNow);
|
|
49
|
-
if (!currentWeekday) {
|
|
50
|
-
return { minutesToOpen: void 0, minutesToClose: void 0 };
|
|
51
|
-
}
|
|
39
|
+
function getBoundaryMinutes(periods, today) {
|
|
40
|
+
const now = asDateTime(today);
|
|
41
|
+
const { active, next, alwaysOpen } = resolveSchedule(periods, now);
|
|
52
42
|
return {
|
|
53
|
-
minutesToOpen:
|
|
54
|
-
minutesToClose:
|
|
43
|
+
minutesToOpen: !active && next ? next.start.diff(now, "minutes").minutes : void 0,
|
|
44
|
+
minutesToClose: active && !alwaysOpen ? active.end.diff(now, "minutes").minutes : void 0
|
|
55
45
|
};
|
|
56
46
|
}
|
|
57
|
-
function
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
return isInTimePeriod(nowHours, nowMinutes, fromHours, fromMinutes, 24, 0) || isInTimePeriod(nowHours, nowMinutes, 0, 0, toHours, toMinutes);
|
|
61
|
-
} else {
|
|
62
|
-
const isAfterFrom = isFirstTimeAfterSecond(nowHours, nowMinutes, fromHours, fromMinutes);
|
|
63
|
-
const isBeforeTo = isFirstTimeAfterSecond(toHours, toMinutes, nowHours, nowMinutes);
|
|
64
|
-
return isAfterFrom && isBeforeTo;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
function isFirstTimeAfterSecond(firstHours, firstMinutes, secondHours, secondMinutes) {
|
|
68
|
-
return firstHours > secondHours || firstHours === secondHours && firstMinutes >= secondMinutes;
|
|
69
|
-
}
|
|
70
|
-
function findWeekday(weekdayPeriods, today) {
|
|
71
|
-
return findWeekdayByDayIndex(weekdayPeriods, today.getDay());
|
|
72
|
-
}
|
|
73
|
-
function findWeekdayByDayIndex(weekdayPeriods, index) {
|
|
74
|
-
const currentWeekdayName = WEEKDAY_ARRAY[index];
|
|
75
|
-
return weekdayPeriods.find(({ weekday }) => weekday === currentWeekdayName);
|
|
76
|
-
}
|
|
77
|
-
function parseAndOrderWeekdays(rawWeekdayPeriods, today) {
|
|
78
|
-
const weekdays = parseWeekdayPeriods(rawWeekdayPeriods);
|
|
79
|
-
const orderedWeekdays = orderFromSunday(weekdays);
|
|
80
|
-
return markCurrentWeekday(orderedWeekdays, today);
|
|
81
|
-
}
|
|
82
|
-
const SHORT_WEEKDAY_TO_NUMERAL = {
|
|
83
|
-
Su: 0,
|
|
84
|
-
Mo: 1,
|
|
85
|
-
Tu: 2,
|
|
86
|
-
We: 3,
|
|
87
|
-
Th: 4,
|
|
88
|
-
Fr: 5,
|
|
89
|
-
Sa: 6
|
|
90
|
-
};
|
|
91
|
-
const WEEKDAY_ARRAY = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
|
|
92
|
-
const WEEKDAY_TO_NUMERAL = WEEKDAY_ARRAY.reduce(
|
|
93
|
-
(obj, weekday, index) => Object.assign(obj, { [weekday]: index }),
|
|
94
|
-
{}
|
|
95
|
-
);
|
|
96
|
-
const WEEKDAYS_DELIMITER = ";";
|
|
97
|
-
const WEEKDAY_AND_TIME_DELIMITER = /\s+/;
|
|
98
|
-
const WEEKDAY_DELIMITER = "-";
|
|
99
|
-
const TIME_PERIOD_DELIMITER = "-";
|
|
100
|
-
const TIME_DELIMITER = ":";
|
|
101
|
-
const AM = " AM";
|
|
102
|
-
const PM = " PM";
|
|
103
|
-
function parseWeekdayPeriods(rawWeekdayPeriods) {
|
|
104
|
-
return rawWeekdayPeriods.split(WEEKDAYS_DELIMITER).map((weekdayAndTimePeriod) => weekdayAndTimePeriod.trim()).map((weekdayAndTimePeriod) => weekdayAndTimePeriod.split(WEEKDAY_AND_TIME_DELIMITER)).flatMap(([weekdayPeriod, timePeriod]) => {
|
|
105
|
-
const weekdays = parseWeekdayPeriod(weekdayPeriod);
|
|
106
|
-
const formattedTimePeriod = prepareTimePeriodData(timePeriod);
|
|
107
|
-
return createWeekdayAndTimePeriodPairs(weekdays, formattedTimePeriod);
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
function parseWeekdayPeriod(weekdayPeriod) {
|
|
111
|
-
const [start, end] = weekdayPeriod.split(WEEKDAY_DELIMITER);
|
|
112
|
-
const startIndex = SHORT_WEEKDAY_TO_NUMERAL[start];
|
|
113
|
-
let weekdayIndices;
|
|
114
|
-
if (end) {
|
|
115
|
-
const endIndex = SHORT_WEEKDAY_TO_NUMERAL[end];
|
|
116
|
-
weekdayIndices = weekdayIndicesRange(startIndex, endIndex);
|
|
117
|
-
} else {
|
|
118
|
-
weekdayIndices = [startIndex];
|
|
47
|
+
function getOpenTimeLabel(hours, nowDate, T, timezone) {
|
|
48
|
+
if (!hours || !canParseOperationHours(hours)) {
|
|
49
|
+
return "";
|
|
119
50
|
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
let currentDayIndex = startIndex;
|
|
125
|
-
do {
|
|
126
|
-
currentDayIndex = (currentDayIndex + 1) % WEEKDAY_ARRAY.length;
|
|
127
|
-
weekdayIndices.push(currentDayIndex);
|
|
128
|
-
} while (currentDayIndex !== endIndex);
|
|
129
|
-
return weekdayIndices;
|
|
130
|
-
}
|
|
131
|
-
function prepareTimePeriodData(timePeriod) {
|
|
132
|
-
const [from, to] = timePeriod.split(TIME_PERIOD_DELIMITER);
|
|
133
|
-
const [fromTime, fromTimeFormatted] = getHoursMinutesAndFormatted(from);
|
|
134
|
-
const [toTime, toTimeFormatted] = getHoursMinutesAndFormatted(to);
|
|
135
|
-
const timePeriodFormatted = fromTimeFormatted + ` ${TIME_PERIOD_DELIMITER} ` + toTimeFormatted;
|
|
136
|
-
return {
|
|
137
|
-
from: fromTime,
|
|
138
|
-
to: toTime,
|
|
139
|
-
formatted: timePeriodFormatted
|
|
140
|
-
};
|
|
141
|
-
}
|
|
142
|
-
function getHoursMinutesAndFormatted(time) {
|
|
143
|
-
const [hours, minutes] = time.split(TIME_DELIMITER);
|
|
144
|
-
const timeFormatted = formatTimeAmPm(hours, minutes);
|
|
145
|
-
return [{ hours: +hours, minutes: +minutes }, timeFormatted];
|
|
146
|
-
}
|
|
147
|
-
function formatTimeAmPm(hours, minutes) {
|
|
148
|
-
const hoursNum = +hours;
|
|
149
|
-
const minutesNum = +minutes;
|
|
150
|
-
const ampm = hoursNum < 12 || hoursNum === 24 ? AM : PM;
|
|
151
|
-
const displayHours = hoursNum % 12 || 12;
|
|
152
|
-
const minutesStr = minutesNum > 9 ? String(minutesNum) : "0" + minutesNum;
|
|
153
|
-
return displayHours + TIME_DELIMITER + minutesStr + ampm;
|
|
154
|
-
}
|
|
155
|
-
function createWeekdayAndTimePeriodPairs(weekdays, timePeriod) {
|
|
156
|
-
return weekdays.map((weekday) => ({ weekday, timePeriod }));
|
|
157
|
-
}
|
|
158
|
-
function orderFromSunday(weekdayPeriods) {
|
|
159
|
-
const startWeekdayIndex = 0;
|
|
160
|
-
const orderedWeekdays = [];
|
|
161
|
-
weekdayPeriods.forEach((weekday) => {
|
|
162
|
-
const weekdayIndex = WEEKDAY_TO_NUMERAL[weekday.weekday];
|
|
163
|
-
let order = weekdayIndex - startWeekdayIndex;
|
|
164
|
-
if (order < 0) {
|
|
165
|
-
order += WEEKDAY_ARRAY.length;
|
|
166
|
-
}
|
|
167
|
-
orderedWeekdays[order] = weekday;
|
|
168
|
-
});
|
|
169
|
-
return filterEmptyDays(orderedWeekdays);
|
|
170
|
-
}
|
|
171
|
-
function filterEmptyDays(weekdays) {
|
|
172
|
-
return weekdays.filter((x) => Boolean(x));
|
|
173
|
-
}
|
|
174
|
-
function markCurrentWeekday(weekdays, today) {
|
|
175
|
-
const todayDayName = WEEKDAY_ARRAY[today.getDay()];
|
|
176
|
-
const addIsToday = R__namespace.converge(R__namespace.assoc("isToday"), [R__namespace.propEq(todayDayName, "weekday"), R__namespace.identity]);
|
|
177
|
-
return weekdays.map((weekday) => addIsToday(weekday));
|
|
178
|
-
}
|
|
179
|
-
function getOpenTimeLabel(operationHours, nowDate, T, timezone) {
|
|
180
|
-
if (operationHours === "Mo-Su 00:00-24:00") {
|
|
51
|
+
const now = luxon.DateTime.fromJSDate(nowDate, { zone: timezone ?? void 0 }).startOf("minute");
|
|
52
|
+
const periods = parseAndOrderWeekdays(hours, toLocalDate(nowDate, timezone));
|
|
53
|
+
const { active, next, alwaysOpen } = resolveSchedule(periods, now);
|
|
54
|
+
if (alwaysOpen) {
|
|
181
55
|
return T("ui:Always open");
|
|
182
56
|
}
|
|
183
|
-
if (
|
|
184
|
-
|
|
57
|
+
if (active) {
|
|
58
|
+
const minutes2 = active.end.diff(now, "minutes").minutes;
|
|
59
|
+
return minutes2 <= SOON_THRESHOLD_MINUTES ? T("ui:Closing in _minutes_", { count: minutes2 }) : T("ui:Open until _time_", { time: formatDateTime(active.end) });
|
|
185
60
|
}
|
|
186
|
-
if (!
|
|
61
|
+
if (!next) {
|
|
187
62
|
return "";
|
|
188
63
|
}
|
|
189
|
-
const
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
return "";
|
|
193
|
-
}
|
|
194
|
-
const currentWeekday = findWeekday(weekdayPeriods, localizedDate);
|
|
195
|
-
if (!currentWeekday || compareDateTimeAndWeekdayTime(localizedDate, currentWeekday.timePeriod.to) === -1) {
|
|
196
|
-
return prepareTimeToNextWorkingDay(localizedDate, weekdayPeriods, T);
|
|
197
|
-
}
|
|
198
|
-
if (isDateInWeekdayOpenHours(localizedDate, currentWeekday)) {
|
|
199
|
-
return prepareTimeToTodayClose(localizedDate, currentWeekday, T);
|
|
64
|
+
const minutes = next.start.diff(now, "minutes").minutes;
|
|
65
|
+
if (minutes <= SOON_THRESHOLD_MINUTES) {
|
|
66
|
+
return T("ui:Opening in _minutes_", { count: minutes });
|
|
200
67
|
}
|
|
201
|
-
|
|
68
|
+
const time = formatDateTime(next.start);
|
|
69
|
+
const weekday = WEEKDAYS[next.start.weekday % 7];
|
|
70
|
+
return T("ui:Closed until _time_", { time: next.start.hasSame(now, "day") ? time : `${weekday} ${time}` });
|
|
202
71
|
}
|
|
203
72
|
function toLocalDate(date, timezone) {
|
|
204
|
-
const { year, month, day, hour, minute } = luxon.DateTime.fromJSDate(date, {
|
|
205
|
-
zone: timezone ?? void 0
|
|
206
|
-
});
|
|
73
|
+
const { year, month, day, hour, minute } = luxon.DateTime.fromJSDate(date, { zone: timezone ?? void 0 });
|
|
207
74
|
return new Date(year, month - 1, day, hour, minute);
|
|
208
75
|
}
|
|
209
|
-
function
|
|
210
|
-
const
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
const
|
|
214
|
-
if (
|
|
215
|
-
|
|
216
|
-
} else {
|
|
217
|
-
return formatOpeningInMinutes(minutesToTomorrowOpen, T);
|
|
76
|
+
function resolveSchedule(periods, now) {
|
|
77
|
+
const windows = [];
|
|
78
|
+
for (let offset = -1; offset <= 14; offset++) {
|
|
79
|
+
const day = now.startOf("day").plus({ days: offset });
|
|
80
|
+
const period = periods.find((period2) => period2.weekday === WEEKDAYS[day.weekday % 7]);
|
|
81
|
+
if (period) {
|
|
82
|
+
windows.push(createWindow(day, period.timePeriod));
|
|
218
83
|
}
|
|
219
|
-
} else {
|
|
220
|
-
const nextWorkingWeekday = findNextWorkingWeekday(weekdayPeriods, nowDate);
|
|
221
|
-
return nextWorkingWeekday ? formatClosedUntilWeekday(nextWorkingWeekday, T) : "";
|
|
222
84
|
}
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
85
|
+
const merged = [];
|
|
86
|
+
for (const window of windows.sort((a, b) => a.start.toMillis() - b.start.toMillis())) {
|
|
87
|
+
const previous = merged[merged.length - 1];
|
|
88
|
+
if (previous && window.start <= previous.end) {
|
|
89
|
+
if (window.end > previous.end) {
|
|
90
|
+
previous.end = window.end;
|
|
91
|
+
}
|
|
92
|
+
} else {
|
|
93
|
+
merged.push(window);
|
|
94
|
+
}
|
|
230
95
|
}
|
|
96
|
+
const active = merged.find((window) => window.start <= now && now < window.end);
|
|
97
|
+
return {
|
|
98
|
+
active,
|
|
99
|
+
next: merged.find((window) => window.start > now),
|
|
100
|
+
alwaysOpen: Boolean(active && active.end >= now.plus({ weeks: 1 }))
|
|
101
|
+
};
|
|
231
102
|
}
|
|
232
|
-
function
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
return formatClosedUntilHours(currentWeekday, T);
|
|
236
|
-
} else {
|
|
237
|
-
return formatOpeningInMinutes(minutesToOpen, T);
|
|
103
|
+
function createWindow(day, { from, to }) {
|
|
104
|
+
if (from.hours === to.hours && from.minutes === to.minutes) {
|
|
105
|
+
return { start: day, end: day.plus({ days: 1 }) };
|
|
238
106
|
}
|
|
107
|
+
const overnight = from.hours > to.hours || from.hours === to.hours && from.minutes > to.minutes;
|
|
108
|
+
return { start: atTime(day, from), end: atTime(overnight ? day.plus({ days: 1 }) : day, to) };
|
|
239
109
|
}
|
|
240
|
-
function
|
|
241
|
-
|
|
242
|
-
return isInTimePeriod(date.getHours(), date.getMinutes(), from.hours, from.minutes, to.hours, to.minutes);
|
|
110
|
+
function atTime(day, time) {
|
|
111
|
+
return time.hours === 24 ? day.plus({ days: 1 }).startOf("day") : day.set({ hour: time.hours, minute: time.minutes });
|
|
243
112
|
}
|
|
244
|
-
function
|
|
245
|
-
|
|
246
|
-
nextDate.setDate(nextDate.getDate() + 1);
|
|
247
|
-
return nextDate;
|
|
113
|
+
function asDateTime(date) {
|
|
114
|
+
return (date instanceof Date ? luxon.DateTime.fromJSDate(date) : date).startOf("minute");
|
|
248
115
|
}
|
|
249
|
-
function
|
|
250
|
-
const
|
|
251
|
-
|
|
252
|
-
return 0;
|
|
253
|
-
}
|
|
254
|
-
if (minutesBetween > 0) {
|
|
255
|
-
return 1;
|
|
256
|
-
}
|
|
257
|
-
return -1;
|
|
116
|
+
function parseTime(time) {
|
|
117
|
+
const [hours, minutes] = time.split(":").map(Number);
|
|
118
|
+
return { hours, minutes };
|
|
258
119
|
}
|
|
259
|
-
function
|
|
260
|
-
|
|
261
|
-
const weekdayTimeMinutes = weekdayTime.hours * 60 + weekdayTime.minutes;
|
|
262
|
-
return weekdayTimeMinutes - dateTimeMinutes;
|
|
120
|
+
function formatDateTime(date) {
|
|
121
|
+
return formatTime({ hours: date.hour, minutes: date.minute });
|
|
263
122
|
}
|
|
264
|
-
function
|
|
265
|
-
const
|
|
266
|
-
|
|
267
|
-
const midnightMinutes = 24 * 60;
|
|
268
|
-
return weekdayTimeMinutes + (midnightMinutes - dateTimeMinutes);
|
|
123
|
+
function formatTime({ hours, minutes }) {
|
|
124
|
+
const suffix = hours < 12 || hours === 24 ? "AM" : "PM";
|
|
125
|
+
return `${hours % 12 || 12}:${String(minutes).padStart(2, "0")} ${suffix}`;
|
|
269
126
|
}
|
|
270
|
-
const formatOpeningInMinutes = (minutesToOpen, T) => T("ui:Opening in _minutes_", { count: minutesToOpen });
|
|
271
|
-
const formatClosingInMinutes = (minutesToClose, T) => T("ui:Closing in _minutes_", { count: minutesToClose });
|
|
272
|
-
const formatClosedUntilHours = (weekday, T) => {
|
|
273
|
-
const { hours, minutes } = weekday.timePeriod.from;
|
|
274
|
-
const formattedTime = formatTimeAmPm(hours, minutes);
|
|
275
|
-
return T("ui:Closed until _time_", { time: formattedTime });
|
|
276
|
-
};
|
|
277
|
-
const formatOpenUntilHours = (weekday, T) => {
|
|
278
|
-
const { hours, minutes } = weekday.timePeriod.to;
|
|
279
|
-
const formattedTime = formatTimeAmPm(hours, minutes);
|
|
280
|
-
return T("ui:Open until _time_", { time: formattedTime });
|
|
281
|
-
};
|
|
282
|
-
const formatClosedUntilWeekday = (weekday, T) => {
|
|
283
|
-
const { hours, minutes } = weekday.timePeriod.from;
|
|
284
|
-
const formattedTime = `${weekday.weekday} ${formatTimeAmPm(hours, minutes)}`;
|
|
285
|
-
return T("ui:Closed until _time_", { time: formattedTime });
|
|
286
|
-
};
|
|
287
|
-
const findNextWorkingWeekday = (weekdayPeriods, nowDate) => {
|
|
288
|
-
let startIndex = (nowDate.getDay() + 1) % 7;
|
|
289
|
-
while (!findWeekdayByDayIndex(weekdayPeriods, startIndex)) {
|
|
290
|
-
startIndex = (startIndex + 1) % 7;
|
|
291
|
-
}
|
|
292
|
-
return findWeekdayByDayIndex(weekdayPeriods, startIndex);
|
|
293
|
-
};
|
|
294
127
|
|
|
128
|
+
exports.SOON_THRESHOLD_MINUTES = SOON_THRESHOLD_MINUTES;
|
|
295
129
|
exports.canParseOperationHours = canParseOperationHours;
|
|
296
130
|
exports.getBoundaryMinutes = getBoundaryMinutes;
|
|
297
131
|
exports.getOpenTimeLabel = getOpenTimeLabel;
|
package/dist/package.json.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var a="3.3.
|
|
1
|
+
var a="3.3.1167",e={version:a};export{e as default,a as version};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{getOpenTimeLabel as
|
|
1
|
+
import{DateTime as t}from"luxon";import{getOpenTimeLabel as e,canParseOperationHours as n,toLocalDate as o,parseAndOrderWeekdays as r,isOpen as i,getBoundaryMinutes as s,SOON_THRESHOLD_MINUTES as u}from"../../../src/utils/operationHours.js";import{PoiOpenStatus as a}from"../../../utils/constants.js";function c(e,s,u=new Date){if("permanently-closed"===e.state)return!1;const a=e.dynamicData?.["open-closed-status"];if(a){const t=a.expiresAt;if(void 0===t||t>u.getTime())return a.isOpen}if(!s)return;if(!n(e.operationHours))return;const c=o(u,s),f=r(e.operationHours,c);return f&&0!==f.length?i(f,t.fromJSDate(u,{zone:s})):void 0}function f(i,u,f,l=new Date){const O=c(i,u,l);if(void 0===O)return;const d=function(e,i,u,c){const f=u?a.OPEN:a.CLOSED;if(p(e,c)||!i||!n(e.operationHours))return f;const l=o(c,i),O=r(e.operationHours,l);if(!O||0===O.length)return f;const{minutesToOpen:d,minutesToClose:D}=s(O,t.fromJSDate(c,{zone:i}));if(u)return m(D)?a.CLOSING_SOON:a.OPEN;return m(d)?a.OPENING_SOON:a.CLOSED}(i,u,O,l);return{isOpen:O,status:d,timeLabel:u&&!p(i,l)&&e(i.operationHours,l,f,u)||void 0}}function p(t,e){if("permanently-closed"===t.state)return!0;const n=t.dynamicData?.["open-closed-status"];return!!n&&(void 0===n.expiresAt||n.expiresAt>e.getTime())}function m(t){return void 0!==t&&t>0&&t<=u}export{c as computeIsOpenNow,f as computePoiOpenStatus};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{DateTime as t}from"luxon";
|
|
1
|
+
import{DateTime as t}from"luxon";const n=60,e=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],s=["Su","Mo","Tu","We","Th","Fr","Sa"],r=/^(Su|Mo|Tu|We|Th|Fr|Sa)(?:-(Su|Mo|Tu|We|Th|Fr|Sa))?\s+(\d{1,2}:\d{2})-(\d{1,2}:\d{2})$/;function i(t){return"string"==typeof t&&""!==t.trim()&&t.split(";").every(t=>r.test(t.trim()))}function u(t,n){const i=new Map;for(const n of t.split(";")){const t=r.exec(n.trim());if(!t)return[];const[,u,o,a,d]=t,f=h(a),m=h(d),c={from:f,to:m,formatted:`${S(f)} - ${S(m)}`},l=s.indexOf(u),y=s.indexOf(o??u);let p=l;do{if(i.set(p,c),p===y)break;p=(p+1)%e.length}while(p!==l)}return[...i.entries()].sort(([t],[n])=>t-n).map(([t,s])=>({weekday:e[t],isToday:t===n.getDay(),timePeriod:s}))}function o(t,n){return Boolean(m(t,y(n)).active)}function a(t,n){const e=y(n),{active:s,next:r,alwaysOpen:i}=m(t,e);return{minutesToOpen:!s&&r?r.start.diff(e,"minutes").minutes:void 0,minutesToClose:s&&!i?s.end.diff(e,"minutes").minutes:void 0}}function d(n,s,r,o){if(!n||!i(n))return"";const a=t.fromJSDate(s,{zone:o??void 0}).startOf("minute"),d=u(n,f(s,o)),{active:c,next:l,alwaysOpen:y}=m(d,a);if(y)return r("ui:Always open");if(c){const t=c.end.diff(a,"minutes").minutes;return t<=60?r("ui:Closing in _minutes_",{count:t}):r("ui:Open until _time_",{time:p(c.end)})}if(!l)return"";const h=l.start.diff(a,"minutes").minutes;if(h<=60)return r("ui:Opening in _minutes_",{count:h});const S=p(l.start),w=e[l.start.weekday%7];return r("ui:Closed until _time_",{time:l.start.hasSame(a,"day")?S:`${w} ${S}`})}function f(n,e){const{year:s,month:r,day:i,hour:u,minute:o}=t.fromJSDate(n,{zone:e??void 0});return new Date(s,r-1,i,u,o)}function m(t,n){const s=[];for(let r=-1;r<=14;r++){const i=n.startOf("day").plus({days:r}),u=t.find(t=>t.weekday===e[i.weekday%7]);u&&s.push(c(i,u.timePeriod))}const r=[];for(const t of s.sort((t,n)=>t.start.toMillis()-n.start.toMillis())){const n=r[r.length-1];n&&t.start<=n.end?t.end>n.end&&(n.end=t.end):r.push(t)}const i=r.find(t=>t.start<=n&&n<t.end);return{active:i,next:r.find(t=>t.start>n),alwaysOpen:Boolean(i&&i.end>=n.plus({weeks:1}))}}function c(t,{from:n,to:e}){if(n.hours===e.hours&&n.minutes===e.minutes)return{start:t,end:t.plus({days:1})};const s=n.hours>e.hours||n.hours===e.hours&&n.minutes>e.minutes;return{start:l(t,n),end:l(s?t.plus({days:1}):t,e)}}function l(t,n){return 24===n.hours?t.plus({days:1}).startOf("day"):t.set({hour:n.hours,minute:n.minutes})}function y(n){return(n instanceof Date?t.fromJSDate(n):n).startOf("minute")}function h(t){const[n,e]=t.split(":").map(Number);return{hours:n,minutes:e}}function p(t){return S({hours:t.hour,minutes:t.minute})}function S({hours:t,minutes:n}){const e=t<12||24===t?"AM":"PM";return`${t%12||12}:${String(n).padStart(2,"0")} ${e}`}export{n as SOON_THRESHOLD_MINUTES,i as canParseOperationHours,a as getBoundaryMinutes,d as getOpenTimeLabel,o as isOpen,u as parseAndOrderWeekdays,f as toLocalDate};
|
package/package.json
CHANGED