@ancon/wildcat-utils 1.20.14 → 1.20.16
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/checkout/getCheckoutOrderStatusTexts.js +1 -1
- package/checkout/getCheckoutOrderStatusTexts.mjs +32 -38
- package/outlet/getListOutletOpeningHoursTable.d.ts +1 -0
- package/outlet/getListOutletOpeningHoursTable.js +1 -1
- package/outlet/getListOutletOpeningHoursTable.mjs +106 -94
- package/outlet/getOutletTagInformation.d.ts +1 -1
- package/outlet/getOutletTagInformation.js +1 -1
- package/outlet/getOutletTagInformation.mjs +66 -62
- package/outlet/searchNextOpeningMoment.d.ts +2 -1
- package/outlet/searchNextOpeningMoment.js +1 -1
- package/outlet/searchNextOpeningMoment.mjs +63 -51
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const r=require("@ancon/wildcat-types"),
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const r=require("@ancon/wildcat-types"),f=require("./getCheckoutItemsMappedByTicketItemStatus.js");var g=(e=>(e.YourOrderIsBeingProcessed="yourOrderIsBeingProcessed",e.YourOrderWasCancelled="yourOrderWasCancelled",e.ProcessingPayment="processingPayment",e.YourOrderIsBeingPrepared="yourOrderIsBeingPrepared",e.YourOrderIsReadyToCollect="yourOrderIsReadyToCollect",e.YourOrderHasBeenCompleted="yourOrderHasBeenCompleted",e.YourOrderWillArriveAtYourTable="yourOrderWillArriveAtYourTable",e.ModifiedDeliveryStartTime="modifiedDeliveryStartTime",e.ModifiedPickUpTime="modifiedPickUpTime",e.YourOrderHasBeenAcceptedEstimatedDeliveryStartTime="yourOrderHasBeenAcceptedEstimatedDeliveryStartTime",e.YourOrderHasBeenAcceptedEstimatedTime="yourOrderHasBeenAcceptedEstimatedTime",e.YourOrderHasBeenAcceptedPickupTime="yourOrderHasBeenAcceptedPickupTime",e.DeliveryWasCompleted="deliveryWasCompleted",e.OneItemIsReadyToCollect="oneItemIsReadyToCollect",e.MultipleItemsAreReadyToCollect="multipleItemsAreReadyToCollect",e.EnjoyMealWhileOtherItemsBeingPrepared="enjoyMealWhileOtherItemsBeingPrepared",e))(g||{});function C(e){switch(e){case r.CheckoutStatus.Created:case r.CheckoutStatus.Ready:case r.CheckoutStatus.Processing:case r.CheckoutStatus.Authorized:return"yourOrderIsBeingProcessed";case r.CheckoutStatus.Canceled:return"yourOrderWasCancelled";case r.CheckoutStatus.Received:return"processingPayment";case r.CheckoutStatus.ReadyToCollect:return"yourOrderIsReadyToCollect";default:return null}}function m(e){switch(e){case r.TicketStatus.Pending:case r.TicketStatus.PendingAccept:return"yourOrderIsBeingProcessed";case r.TicketStatus.Preparing:return"yourOrderIsBeingPrepared";case r.TicketStatus.Ready:return"yourOrderIsReadyToCollect";case r.TicketStatus.Closed:return"yourOrderHasBeenCompleted";case r.TicketStatus.Canceled:return"yourOrderWasCancelled";default:throw new Error(`Unhandled ticket status "${e}" in getTranslationKeyByTicketStatus()`)}}function T(e,{checkoutStatus:i,ticketStatus:a,customersFetchTableOrders:o}){const d=(e==null?void 0:e.orderFormat)===r.OrderFormat.Delivery,t=(e==null?void 0:e.orderFormat)===r.OrderFormat.TakeAway,l=(e==null?void 0:e.orderFormat)===r.OrderFormat.TableOrder;if(d||t||l&&!o)return!1;const u=i!=null,c=a!=null;if(u){const n=i===r.CheckoutStatus.Captured,s=i===r.CheckoutStatus.InProgress;return n||s}if(c){const n=a===r.TicketStatus.Preparing,s=a===r.TicketStatus.Ready;return n||s}return!1}function P(e,{checkoutStatus:i,ticketStatus:a,customersFetchTableOrders:o,pickupTimeUpdated:d},t){if(T(e,{checkoutStatus:i,ticketStatus:a,customersFetchTableOrders:o})){if(t.ready>0)return t.ready===t.all?["yourOrderIsReadyToCollect"]:t.ready<2?["oneItemIsReadyToCollect"]:["multipleItemsAreReadyToCollect",{count:t.ready}];if(t.done>0&&t.done<t.all)return["enjoyMealWhileOtherItemsBeingPrepared",{count:Math.max(0,t.all-t.done-t.ready)}]}if(a!=null)return[m(a)];const l=C(i);if(l)return[l];const u=i===r.CheckoutStatus.Captured,c=i===r.CheckoutStatus.InProgress,n=i===r.CheckoutStatus.Done,s=(e==null?void 0:e.orderFormat)===r.OrderFormat.EatIn,p=(e==null?void 0:e.orderFormat)===r.OrderFormat.TakeAway,O=(e==null?void 0:e.orderFormat)===r.OrderFormat.TableOrder,y=(e==null?void 0:e.orderFormat)===r.OrderFormat.Delivery;if(u)return O&&!o?["yourOrderWillArriveAtYourTable"]:y?d?["modifiedDeliveryStartTime"]:["yourOrderHasBeenAcceptedEstimatedDeliveryStartTime"]:d?["modifiedPickUpTime"]:["yourOrderHasBeenAcceptedPickupTime"];if(c){if(y)return d?["modifiedDeliveryStartTime"]:["yourOrderHasBeenAcceptedEstimatedDeliveryStartTime"];if(s||p){if(t.ready===t.all)return["yourOrderIsReadyToCollect"];if(t.done===t.all)return["yourOrderHasBeenCompleted"]}return O?t.ready===t.all?o?["yourOrderIsReadyToCollect"]:["yourOrderWillArriveAtYourTable"]:t.done===t.all?o?["yourOrderHasBeenCompleted"]:["yourOrderWillArriveAtYourTable"]:d?["modifiedPickUpTime"]:o?["yourOrderIsBeingPrepared"]:["yourOrderWillArriveAtYourTable"]:d?["modifiedPickUpTime"]:["yourOrderIsBeingPrepared"]}if(n)return s||p?["yourOrderHasBeenCompleted"]:y?["deliveryWasCompleted"]:["yourOrderHasBeenCompleted"];throw new Error("Could not resolve translation key in getTranslationKey()")}const h={yourOrderIsBeingProcessed:()=>({title:"Your order is being processed"}),yourOrderWasCancelled:()=>({title:"Your order was canceled",message:"Sorry. Your order could not go through."}),processingPayment:()=>({title:"Processing payment",message:"Please wait while your payment is being processed"}),yourOrderIsBeingPrepared:()=>({title:"Your order is now being prepared!",message:"We will let you know when it is ready for pickup."}),yourOrderIsReadyToCollect:()=>({title:"Your order is ready to be collected!",message:"Please go ahead and show this screen at the collection point"}),yourOrderHasBeenCompleted:()=>({title:"Enjoy your meal!",message:"Your order has been completed!"}),yourOrderWillArriveAtYourTable:()=>({title:"Your order has been accepted!",message:"It will arrive at your table shortly"}),modifiedDeliveryStartTime:()=>({title:"Your delivery time was modified",message:"Delivery will start at approximately 00:00."}),modifiedPickUpTime:()=>({title:"Your pickup time was modified",message:"Pickup time: 00:00"}),yourOrderHasBeenAcceptedEstimatedDeliveryStartTime:()=>({title:"Your order has been accepted",message:"Estimated delivery start time: 00:00"}),yourOrderHasBeenAcceptedEstimatedTime:()=>({title:"Your order has been accepted",message:"Estimated time: 00:00"}),yourOrderHasBeenAcceptedPickupTime:()=>({title:"Your order has been accepted",message:"Pickup time: 00:00"}),deliveryWasCompleted:()=>({title:"Your order was completed",message:"Enjoy your meal!"}),oneItemIsReadyToCollect:()=>({title:"One item is ready to pick up!",message:"Please allow cashier or waiter to confirm that the prepared item has been successfully issued."}),multipleItemsAreReadyToCollect:()=>({title:"Multiple items are ready to pick up!",message:"Please allow cashier or waiter to confirm that the prepared items have been successfully issued."}),enjoyMealWhileOtherItemsBeingPrepared:({meta:e})=>({title:"Enjoy your meal while the rest of the items are being prepared!",message:`${e.count} more items are being prepared`})};function I(e,i,a=h){const o=f((e==null?void 0:e.items)??[]),[d,t]=P(e,i,{all:o.all.length,ready:o.ready.length,done:o.done.length}),l=a[d]({key:d,meta:t});if(!l)throw new Error("Could not resolve translation in getOrderStatusTexts()");return[l,d]}exports.TranslationKey=g;exports.default=I;
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { CheckoutStatus as
|
|
1
|
+
import { CheckoutStatus as t, OrderFormat as s, TicketStatus as a } from "@ancon/wildcat-types";
|
|
2
2
|
import m from "./getCheckoutItemsMappedByTicketItemStatus.mjs";
|
|
3
3
|
var C = /* @__PURE__ */ ((e) => (e.YourOrderIsBeingProcessed = "yourOrderIsBeingProcessed", e.YourOrderWasCancelled = "yourOrderWasCancelled", e.ProcessingPayment = "processingPayment", e.YourOrderIsBeingPrepared = "yourOrderIsBeingPrepared", e.YourOrderIsReadyToCollect = "yourOrderIsReadyToCollect", e.YourOrderHasBeenCompleted = "yourOrderHasBeenCompleted", e.YourOrderWillArriveAtYourTable = "yourOrderWillArriveAtYourTable", e.ModifiedDeliveryStartTime = "modifiedDeliveryStartTime", e.ModifiedPickUpTime = "modifiedPickUpTime", e.YourOrderHasBeenAcceptedEstimatedDeliveryStartTime = "yourOrderHasBeenAcceptedEstimatedDeliveryStartTime", e.YourOrderHasBeenAcceptedEstimatedTime = "yourOrderHasBeenAcceptedEstimatedTime", e.YourOrderHasBeenAcceptedPickupTime = "yourOrderHasBeenAcceptedPickupTime", e.DeliveryWasCompleted = "deliveryWasCompleted", e.OneItemIsReadyToCollect = "oneItemIsReadyToCollect", e.MultipleItemsAreReadyToCollect = "multipleItemsAreReadyToCollect", e.EnjoyMealWhileOtherItemsBeingPrepared = "enjoyMealWhileOtherItemsBeingPrepared", e))(C || {});
|
|
4
4
|
function P(e) {
|
|
5
5
|
switch (e) {
|
|
6
|
-
case
|
|
7
|
-
case
|
|
8
|
-
case
|
|
9
|
-
case
|
|
6
|
+
case t.Created:
|
|
7
|
+
case t.Ready:
|
|
8
|
+
case t.Processing:
|
|
9
|
+
case t.Authorized:
|
|
10
10
|
return "yourOrderIsBeingProcessed";
|
|
11
|
-
case
|
|
11
|
+
case t.Canceled:
|
|
12
12
|
return "yourOrderWasCancelled";
|
|
13
|
-
case
|
|
13
|
+
case t.Received:
|
|
14
14
|
return "processingPayment";
|
|
15
|
-
case
|
|
15
|
+
case t.ReadyToCollect:
|
|
16
16
|
return "yourOrderIsReadyToCollect";
|
|
17
17
|
default:
|
|
18
18
|
return null;
|
|
@@ -38,16 +38,16 @@ function I(e) {
|
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
function T(e, {
|
|
41
|
-
checkoutStatus:
|
|
41
|
+
checkoutStatus: i,
|
|
42
42
|
ticketStatus: l,
|
|
43
|
-
customersFetchTableOrders:
|
|
43
|
+
customersFetchTableOrders: o
|
|
44
44
|
}) {
|
|
45
45
|
const d = (e == null ? void 0 : e.orderFormat) === s.Delivery, r = (e == null ? void 0 : e.orderFormat) === s.TakeAway, n = (e == null ? void 0 : e.orderFormat) === s.TableOrder;
|
|
46
|
-
if (d || r || n && !
|
|
46
|
+
if (d || r || n && !o)
|
|
47
47
|
return !1;
|
|
48
|
-
const y =
|
|
48
|
+
const y = i != null, p = l != null;
|
|
49
49
|
if (y) {
|
|
50
|
-
const u =
|
|
50
|
+
const u = i === t.Captured, c = i === t.InProgress;
|
|
51
51
|
return u || c;
|
|
52
52
|
}
|
|
53
53
|
if (p) {
|
|
@@ -57,15 +57,15 @@ function T(e, {
|
|
|
57
57
|
return !1;
|
|
58
58
|
}
|
|
59
59
|
function B(e, {
|
|
60
|
-
checkoutStatus:
|
|
60
|
+
checkoutStatus: i,
|
|
61
61
|
ticketStatus: l,
|
|
62
|
-
customersFetchTableOrders:
|
|
62
|
+
customersFetchTableOrders: o,
|
|
63
63
|
pickupTimeUpdated: d
|
|
64
64
|
}, r) {
|
|
65
65
|
if (T(e, {
|
|
66
|
-
checkoutStatus:
|
|
66
|
+
checkoutStatus: i,
|
|
67
67
|
ticketStatus: l,
|
|
68
|
-
customersFetchTableOrders:
|
|
68
|
+
customersFetchTableOrders: o
|
|
69
69
|
})) {
|
|
70
70
|
if (r.ready > 0)
|
|
71
71
|
return r.ready === r.all ? ["yourOrderIsReadyToCollect"] : r.ready < 2 ? ["oneItemIsReadyToCollect"] : [
|
|
@@ -80,34 +80,28 @@ function B(e, {
|
|
|
80
80
|
}
|
|
81
81
|
if (l != null)
|
|
82
82
|
return [I(l)];
|
|
83
|
-
const n = P(
|
|
83
|
+
const n = P(i);
|
|
84
84
|
if (n)
|
|
85
85
|
return [n];
|
|
86
|
-
const y =
|
|
86
|
+
const y = i === t.Captured, p = i === t.InProgress, u = i === t.Done, c = (e == null ? void 0 : e.orderFormat) === s.EatIn, g = (e == null ? void 0 : e.orderFormat) === s.TakeAway, O = (e == null ? void 0 : e.orderFormat) === s.TableOrder, f = (e == null ? void 0 : e.orderFormat) === s.Delivery;
|
|
87
87
|
if (y)
|
|
88
|
-
return
|
|
88
|
+
return O && !o ? ["yourOrderWillArriveAtYourTable"] : f ? d ? ["modifiedDeliveryStartTime"] : ["yourOrderHasBeenAcceptedEstimatedDeliveryStartTime"] : d ? ["modifiedPickUpTime"] : ["yourOrderHasBeenAcceptedPickupTime"];
|
|
89
89
|
if (p) {
|
|
90
|
-
if (
|
|
90
|
+
if (f)
|
|
91
91
|
return d ? ["modifiedDeliveryStartTime"] : ["yourOrderHasBeenAcceptedEstimatedDeliveryStartTime"];
|
|
92
|
-
if (c ||
|
|
92
|
+
if (c || g) {
|
|
93
93
|
if (r.ready === r.all)
|
|
94
94
|
return ["yourOrderIsReadyToCollect"];
|
|
95
95
|
if (r.done === r.all)
|
|
96
96
|
return ["yourOrderHasBeenCompleted"];
|
|
97
97
|
}
|
|
98
|
-
return
|
|
99
|
-
}
|
|
100
|
-
if (u) {
|
|
101
|
-
if (c || O)
|
|
102
|
-
return ["yourOrderHasBeenCompleted"];
|
|
103
|
-
if (g)
|
|
104
|
-
return ["deliveryWasCompleted"];
|
|
105
|
-
if (f)
|
|
106
|
-
return t ? ["yourOrderHasBeenCompleted"] : ["yourOrderWillArriveAtYourTable"];
|
|
98
|
+
return O ? r.ready === r.all ? o ? ["yourOrderIsReadyToCollect"] : ["yourOrderWillArriveAtYourTable"] : r.done === r.all ? o ? ["yourOrderHasBeenCompleted"] : ["yourOrderWillArriveAtYourTable"] : d ? ["modifiedPickUpTime"] : o ? ["yourOrderIsBeingPrepared"] : ["yourOrderWillArriveAtYourTable"] : d ? ["modifiedPickUpTime"] : ["yourOrderIsBeingPrepared"];
|
|
107
99
|
}
|
|
100
|
+
if (u)
|
|
101
|
+
return c || g ? ["yourOrderHasBeenCompleted"] : f ? ["deliveryWasCompleted"] : ["yourOrderHasBeenCompleted"];
|
|
108
102
|
throw new Error("Could not resolve translation key in getTranslationKey()");
|
|
109
103
|
}
|
|
110
|
-
const
|
|
104
|
+
const h = {
|
|
111
105
|
yourOrderIsBeingProcessed: () => ({
|
|
112
106
|
title: "Your order is being processed"
|
|
113
107
|
}),
|
|
@@ -172,13 +166,13 @@ const A = {
|
|
|
172
166
|
message: `${e.count} more items are being prepared`
|
|
173
167
|
})
|
|
174
168
|
};
|
|
175
|
-
function w(e,
|
|
176
|
-
const
|
|
169
|
+
function w(e, i, l = h) {
|
|
170
|
+
const o = m(
|
|
177
171
|
(e == null ? void 0 : e.items) ?? []
|
|
178
|
-
), [d, r] = B(e,
|
|
179
|
-
all:
|
|
180
|
-
ready:
|
|
181
|
-
done:
|
|
172
|
+
), [d, r] = B(e, i, {
|
|
173
|
+
all: o.all.length,
|
|
174
|
+
ready: o.ready.length,
|
|
175
|
+
done: o.done.length
|
|
182
176
|
}), n = l[d]({ key: d, meta: r });
|
|
183
177
|
if (!n)
|
|
184
178
|
throw new Error("Could not resolve translation in getOrderStatusTexts()");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const
|
|
1
|
+
"use strict";const g=require("moment"),f=require("@ancon/wildcat-types"),o=require("../shared/enums.js"),F=require("../shared/isWithinFlag.js"),k=require("../shared/generateId.js"),I=[{id:f.OrderFormat.EatIn,name:"eatIn"},{id:f.OrderFormat.TakeAway,name:"takeaway"},{id:f.OrderFormat.TableOrder,name:"tableOrder"},{id:f.OrderFormat.Delivery,name:"delivery"}];function v(e){const r=g.utc(e).subtract(1,"day").startOf("day"),t=[];for(let y=0,n=r;y<7;y+=1)n=n.clone().add(1,"day").startOf("day"),t.push(n.clone());return t}function T(e){return[...e].sort((r,t)=>r.isoWeekday()-t.isoWeekday())}function W(e){return e.split(":").map(Number)}function h(e,r,t){const[y,n]=W(e.start),[a,u]=W(e.duration),[s,l]=W(t||"00:00:00");if(e.type===o.IntervalType.Interval){let d=r.clone().add(y,"hour").add(n,"minute");const i=d.clone().add(s,"hour").add(l,"minute").date()-r.date();i!==0&&(d=d.subtract(i,"day"));const p=d.clone().add(a,"hour").add(u,"minute");return{id:e.id,start:d.toISOString(),end:p.toISOString()}}if(e.type===o.IntervalType.Exception){const d=g(e.fromDate),m=g(e.toDate);if(r.isBetween(d,m,void 0,"[]")){const i=r.clone().add(y,"hour").add(n,"minute"),p=i.clone().add(a,"hour").add(u,"minute");return{id:e.id,start:i.toISOString(),end:p.toISOString(),reason:e.reason}}return null}throw new Error("Invalid interval type")}function S(e,r,t,y){const n={[o.DayOfWeek.Monday]:1,[o.DayOfWeek.Tuesday]:2,[o.DayOfWeek.Wednesday]:3,[o.DayOfWeek.Thursday]:4,[o.DayOfWeek.Friday]:5,[o.DayOfWeek.Saturday]:6,[o.DayOfWeek.Sunday]:7};for(let a=0;a<r.length;a+=1){const u=r[a],s=u.isoWeekday(),l=e.dayOfWeek,m=(n[l]??null)===s||l===o.DayOfWeek.Everyday;if(t[s]||(t[s]={isoWeekday:s,key:"",open:[],adjusted:[],closed:[]}),m){const i=h(e,u,y);i&&(t[s].key+=i.id,e.type===o.IntervalType.Interval&&e.state===o.IntervalState.Open?t[s].open.push(i):e.type===o.IntervalType.Interval&&e.state===o.IntervalState.Closed?t[s].closed.push(i):e.type===o.IntervalType.Exception&&e.state===o.IntervalState.Open?t[s].adjusted.push(i):e.type===o.IntervalType.Exception&&e.state===o.IntervalState.Closed&&t[s].closed.push(i))}}}function D(e){switch(e.type){case o.IntervalType.Exception:return k("interval-exception");case o.IntervalType.Interval:return k("interval-normal");default:return k("interval-unknown")}}function M(e){const r=e.reduce((t,y)=>(I.forEach(n=>{F(n.id,y.orderFormats)&&(t[n.id]||(t[n.id]={orderFormat:n,intervals:[]}),t[n.id].intervals.push(...y.intervals.sort((a,u)=>a.dayOfWeek-u.dayOfWeek)))}),t),{});return Object.values(r)}function H(e){return e.reduce((r,t,y)=>{const n=r.findIndex(a=>a!==t&&!a.orderFormats.some(u=>t.orderFormats.some(s=>s.id===u.id))&&a.openingHours.every(u=>t.openingHours.some(s=>s.key===u.key))&&t.openingHours.every(u=>a.openingHours.some(s=>s.key===u.key)));if(n>=0){const a=r[n];return r.splice(n,1,{...a,orderFormats:[...t.orderFormats,...a.orderFormats]}),r.splice(y,1),r}return r},[...e])}function E(e){return e.map(r=>({...r,intervals:r.intervals.map(t=>({...t,id:D(t)}))}))}function x(e,r){const t=M(E(e.serviceDateTimes)),y=v(r),n=T(y),a=t.reduce((d,m)=>(d[m.orderFormat.id]||(d[m.orderFormat.id]={}),m.intervals.reduce((i,p)=>(S(p,n,i,e.timeZoneOffset),i),d[m.orderFormat.id]),d),{}),u={[f.OrderFormat.EatIn]:I[0],[f.OrderFormat.TakeAway]:I[1],[f.OrderFormat.TableOrder]:I[2],[f.OrderFormat.Delivery]:I[3]},s=Object.entries(a).map(([d,m])=>({orderFormats:[u[Number(d)]],openingHours:Object.entries(m).map(([i,p])=>({isoWeekday:Number(i),key:p.key,open:p.open.sort((c,O)=>c.start.localeCompare(O.start)),adjusted:p.adjusted.sort((c,O)=>c.start.localeCompare(O.start)),closed:p.closed.sort((c,O)=>c.start.localeCompare(O.start))}))}));return H(s).sort((d,m)=>d.orderFormats[0].id-m.orderFormats[0].id)}module.exports=x;
|
|
@@ -1,46 +1,49 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { OrderFormat as
|
|
3
|
-
import { DayOfWeek as
|
|
1
|
+
import M from "moment";
|
|
2
|
+
import { OrderFormat as f } from "@ancon/wildcat-types";
|
|
3
|
+
import { DayOfWeek as y, IntervalType as c, IntervalState as g } from "../shared/enums.mjs";
|
|
4
4
|
import h from "../shared/isWithinFlag.mjs";
|
|
5
5
|
import W from "../shared/generateId.mjs";
|
|
6
6
|
const k = [
|
|
7
|
-
{ id:
|
|
8
|
-
{ id:
|
|
9
|
-
{ id:
|
|
10
|
-
{ id:
|
|
7
|
+
{ id: f.EatIn, name: "eatIn" },
|
|
8
|
+
{ id: f.TakeAway, name: "takeaway" },
|
|
9
|
+
{ id: f.TableOrder, name: "tableOrder" },
|
|
10
|
+
{ id: f.Delivery, name: "delivery" }
|
|
11
11
|
];
|
|
12
|
-
function
|
|
13
|
-
const
|
|
14
|
-
for (let
|
|
15
|
-
|
|
12
|
+
function S(e) {
|
|
13
|
+
const n = M.utc(e).subtract(1, "day").startOf("day"), t = [];
|
|
14
|
+
for (let u = 0, o = n; u < 7; u += 1)
|
|
15
|
+
o = o.clone().add(1, "day").startOf("day"), t.push(o.clone());
|
|
16
16
|
return t;
|
|
17
17
|
}
|
|
18
|
-
function
|
|
19
|
-
return [...e].sort((
|
|
18
|
+
function H(e) {
|
|
19
|
+
return [...e].sort((n, t) => n.isoWeekday() - t.isoWeekday());
|
|
20
20
|
}
|
|
21
|
-
function
|
|
21
|
+
function F(e) {
|
|
22
22
|
return e.split(":").map(Number);
|
|
23
23
|
}
|
|
24
|
-
function
|
|
25
|
-
const [
|
|
24
|
+
function v(e, n, t) {
|
|
25
|
+
const [u, o] = F(e.start), [s, i] = F(
|
|
26
26
|
e.duration
|
|
27
|
-
);
|
|
28
|
-
if (e.type ===
|
|
29
|
-
|
|
27
|
+
), [r, l] = F(t || "00:00:00");
|
|
28
|
+
if (e.type === c.Interval) {
|
|
29
|
+
let d = n.clone().add(u, "hour").add(o, "minute");
|
|
30
|
+
const a = d.clone().add(r, "hour").add(l, "minute").date() - n.date();
|
|
31
|
+
a !== 0 && (d = d.subtract(a, "day"));
|
|
32
|
+
const p = d.clone().add(s, "hour").add(i, "minute");
|
|
30
33
|
return {
|
|
31
34
|
id: e.id,
|
|
32
|
-
start:
|
|
33
|
-
end:
|
|
35
|
+
start: d.toISOString(),
|
|
36
|
+
end: p.toISOString()
|
|
34
37
|
};
|
|
35
38
|
}
|
|
36
|
-
if (e.type ===
|
|
37
|
-
const
|
|
38
|
-
if (
|
|
39
|
-
const
|
|
39
|
+
if (e.type === c.Exception) {
|
|
40
|
+
const d = M(e.fromDate), m = M(e.toDate);
|
|
41
|
+
if (n.isBetween(d, m, void 0, "[]")) {
|
|
42
|
+
const a = n.clone().add(u, "hour").add(o, "minute"), p = a.clone().add(s, "hour").add(i, "minute");
|
|
40
43
|
return {
|
|
41
44
|
id: e.id,
|
|
42
|
-
start:
|
|
43
|
-
end:
|
|
45
|
+
start: a.toISOString(),
|
|
46
|
+
end: p.toISOString(),
|
|
44
47
|
reason: e.reason
|
|
45
48
|
};
|
|
46
49
|
}
|
|
@@ -48,126 +51,135 @@ function H(e, r) {
|
|
|
48
51
|
}
|
|
49
52
|
throw new Error("Invalid interval type");
|
|
50
53
|
}
|
|
51
|
-
function E(e,
|
|
52
|
-
const
|
|
53
|
-
[
|
|
54
|
-
[
|
|
55
|
-
[
|
|
56
|
-
[
|
|
57
|
-
[
|
|
58
|
-
[
|
|
59
|
-
[
|
|
54
|
+
function E(e, n, t, u) {
|
|
55
|
+
const o = {
|
|
56
|
+
[y.Monday]: 1,
|
|
57
|
+
[y.Tuesday]: 2,
|
|
58
|
+
[y.Wednesday]: 3,
|
|
59
|
+
[y.Thursday]: 4,
|
|
60
|
+
[y.Friday]: 5,
|
|
61
|
+
[y.Saturday]: 6,
|
|
62
|
+
[y.Sunday]: 7
|
|
60
63
|
};
|
|
61
|
-
for (let
|
|
62
|
-
const
|
|
63
|
-
if (t[
|
|
64
|
-
isoWeekday:
|
|
64
|
+
for (let s = 0; s < n.length; s += 1) {
|
|
65
|
+
const i = n[s], r = i.isoWeekday(), l = e.dayOfWeek, m = (o[l] ?? null) === r || l === y.Everyday;
|
|
66
|
+
if (t[r] || (t[r] = {
|
|
67
|
+
isoWeekday: r,
|
|
65
68
|
key: "",
|
|
66
69
|
open: [],
|
|
67
70
|
adjusted: [],
|
|
68
71
|
closed: []
|
|
69
|
-
}),
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
+
}), m) {
|
|
73
|
+
const a = v(
|
|
74
|
+
e,
|
|
75
|
+
i,
|
|
76
|
+
u
|
|
77
|
+
);
|
|
78
|
+
a && (t[r].key += a.id, e.type === c.Interval && e.state === g.Open ? t[r].open.push(a) : e.type === c.Interval && e.state === g.Closed ? t[r].closed.push(a) : e.type === c.Exception && e.state === g.Open ? t[r].adjusted.push(a) : e.type === c.Exception && e.state === g.Closed && t[r].closed.push(a));
|
|
72
79
|
}
|
|
73
80
|
}
|
|
74
81
|
}
|
|
75
82
|
function T(e) {
|
|
76
83
|
switch (e.type) {
|
|
77
|
-
case
|
|
84
|
+
case c.Exception:
|
|
78
85
|
return W("interval-exception");
|
|
79
|
-
case
|
|
86
|
+
case c.Interval:
|
|
80
87
|
return W("interval-normal");
|
|
81
88
|
default:
|
|
82
89
|
return W("interval-unknown");
|
|
83
90
|
}
|
|
84
91
|
}
|
|
85
92
|
function x(e) {
|
|
86
|
-
const
|
|
87
|
-
(t,
|
|
88
|
-
h(
|
|
89
|
-
orderFormat:
|
|
93
|
+
const n = e.reduce(
|
|
94
|
+
(t, u) => (k.forEach((o) => {
|
|
95
|
+
h(o.id, u.orderFormats) && (t[o.id] || (t[o.id] = {
|
|
96
|
+
orderFormat: o,
|
|
90
97
|
intervals: []
|
|
91
|
-
}), t[
|
|
92
|
-
...
|
|
93
|
-
(s,
|
|
98
|
+
}), t[o.id].intervals.push(
|
|
99
|
+
...u.intervals.sort(
|
|
100
|
+
(s, i) => s.dayOfWeek - i.dayOfWeek
|
|
94
101
|
)
|
|
95
102
|
));
|
|
96
103
|
}), t),
|
|
97
104
|
{}
|
|
98
105
|
);
|
|
99
|
-
return Object.values(
|
|
106
|
+
return Object.values(n);
|
|
100
107
|
}
|
|
101
|
-
function
|
|
108
|
+
function D(e) {
|
|
102
109
|
return e.reduce(
|
|
103
|
-
(
|
|
104
|
-
const
|
|
110
|
+
(n, t, u) => {
|
|
111
|
+
const o = n.findIndex(
|
|
105
112
|
(s) => s !== t && !s.orderFormats.some(
|
|
106
|
-
(
|
|
107
|
-
(
|
|
113
|
+
(i) => t.orderFormats.some(
|
|
114
|
+
(r) => r.id === i.id
|
|
108
115
|
)
|
|
109
116
|
) && s.openingHours.every(
|
|
110
|
-
(
|
|
117
|
+
(i) => t.openingHours.some((r) => r.key === i.key)
|
|
111
118
|
) && t.openingHours.every(
|
|
112
|
-
(
|
|
119
|
+
(i) => s.openingHours.some((r) => r.key === i.key)
|
|
113
120
|
)
|
|
114
121
|
);
|
|
115
|
-
if (
|
|
116
|
-
const s =
|
|
117
|
-
return
|
|
122
|
+
if (o >= 0) {
|
|
123
|
+
const s = n[o];
|
|
124
|
+
return n.splice(o, 1, {
|
|
118
125
|
...s,
|
|
119
126
|
orderFormats: [...t.orderFormats, ...s.orderFormats]
|
|
120
|
-
}),
|
|
127
|
+
}), n.splice(u, 1), n;
|
|
121
128
|
}
|
|
122
|
-
return
|
|
129
|
+
return n;
|
|
123
130
|
},
|
|
124
131
|
[...e]
|
|
125
132
|
);
|
|
126
133
|
}
|
|
127
|
-
function
|
|
128
|
-
return e.map((
|
|
129
|
-
...
|
|
130
|
-
intervals:
|
|
134
|
+
function j(e) {
|
|
135
|
+
return e.map((n) => ({
|
|
136
|
+
...n,
|
|
137
|
+
intervals: n.intervals.map((t) => ({
|
|
131
138
|
...t,
|
|
132
139
|
id: T(t)
|
|
133
140
|
}))
|
|
134
141
|
}));
|
|
135
142
|
}
|
|
136
|
-
function
|
|
143
|
+
function Z(e, n) {
|
|
137
144
|
const t = x(
|
|
138
|
-
|
|
139
|
-
),
|
|
140
|
-
(
|
|
145
|
+
j(e.serviceDateTimes)
|
|
146
|
+
), u = S(n), o = H(u), s = t.reduce(
|
|
147
|
+
(d, m) => (d[m.orderFormat.id] || (d[m.orderFormat.id] = {}), m.intervals.reduce((a, p) => (E(
|
|
148
|
+
p,
|
|
149
|
+
o,
|
|
150
|
+
a,
|
|
151
|
+
e.timeZoneOffset
|
|
152
|
+
), a), d[m.orderFormat.id]), d),
|
|
141
153
|
{}
|
|
142
|
-
),
|
|
143
|
-
[
|
|
144
|
-
[
|
|
145
|
-
[
|
|
146
|
-
[
|
|
147
|
-
},
|
|
154
|
+
), i = {
|
|
155
|
+
[f.EatIn]: k[0],
|
|
156
|
+
[f.TakeAway]: k[1],
|
|
157
|
+
[f.TableOrder]: k[2],
|
|
158
|
+
[f.Delivery]: k[3]
|
|
159
|
+
}, r = Object.entries(
|
|
148
160
|
s
|
|
149
|
-
).map(([
|
|
150
|
-
orderFormats: [
|
|
151
|
-
openingHours: Object.entries(
|
|
152
|
-
([
|
|
153
|
-
isoWeekday: Number(
|
|
154
|
-
key:
|
|
155
|
-
open:
|
|
156
|
-
(
|
|
161
|
+
).map(([d, m]) => ({
|
|
162
|
+
orderFormats: [i[Number(d)]],
|
|
163
|
+
openingHours: Object.entries(m).map(
|
|
164
|
+
([a, p]) => ({
|
|
165
|
+
isoWeekday: Number(a),
|
|
166
|
+
key: p.key,
|
|
167
|
+
open: p.open.sort(
|
|
168
|
+
(I, O) => I.start.localeCompare(O.start)
|
|
157
169
|
),
|
|
158
|
-
adjusted:
|
|
159
|
-
(
|
|
170
|
+
adjusted: p.adjusted.sort(
|
|
171
|
+
(I, O) => I.start.localeCompare(O.start)
|
|
160
172
|
),
|
|
161
|
-
closed:
|
|
162
|
-
(
|
|
173
|
+
closed: p.closed.sort(
|
|
174
|
+
(I, O) => I.start.localeCompare(O.start)
|
|
163
175
|
)
|
|
164
176
|
})
|
|
165
177
|
)
|
|
166
178
|
}));
|
|
167
|
-
return
|
|
168
|
-
(
|
|
179
|
+
return D(r).sort(
|
|
180
|
+
(d, m) => d.orderFormats[0].id - m.orderFormats[0].id
|
|
169
181
|
);
|
|
170
182
|
}
|
|
171
183
|
export {
|
|
172
|
-
|
|
184
|
+
Z as default
|
|
173
185
|
};
|
|
@@ -12,5 +12,5 @@ export declare const DaysOfWeekMap: {
|
|
|
12
12
|
7: number;
|
|
13
13
|
};
|
|
14
14
|
declare function getOutletTagInformation(operatingHours: ServiceDateTimeInterval[], open: boolean, // Derived by the `state` given by the server
|
|
15
|
-
specificTime: Moment, currentTime: Moment): OutletTagInformation;
|
|
15
|
+
specificTime: Moment, currentTime: Moment, outletTimeZoneOffset?: string): OutletTagInformation;
|
|
16
16
|
export default getOutletTagInformation;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const c=require("moment"),g=require("./types.js"),d=require("./constants.js"),M=require("./getOutletCurrentActiveOperatingHour.js"),v=require("./getMomentFromDateAndTimeString.js"),k=require("./searchNextOpeningMoment.js");require("@ancon/wildcat-types");const D={0:127,1:1,2:2,3:4,4:8,5:16,6:32,7:64};function S(o,e){const a=o.isSame(e,"d"),n={[e.format(d.OutletMapKeyFormatter)]:{intervals:[],exception:null,metadata:{dayOfWeek:D[e.isoWeekday()]}}};for(let i=a?1:0;i<d.OutletTimelineDayCount;i+=1){const s=c(o).add(i,"d");n[s.format(d.OutletMapKeyFormatter)]={intervals:[],exception:null,metadata:{dayOfWeek:D[s.isoWeekday()]}}}return n}function W(o,e){const a=c().utcOffset(),t=c(e.fromDate).utc(!1).subtract(a,"minutes"),n=c(e.toDate).utc(!1).subtract(a,"minutes");if(!t.isSame(n,"d"))Object.keys(o).forEach(s=>{const r=c(s);if(r.isSame(t,"d")||r.isSame(n,"d")||r.isBetween(t,n)){const l=o[s],u=l.exception?l.exception.position:0;e.position>u&&(l.exception=e)}});else{const s=t.format(d.OutletMapKeyFormatter),r=o[s];if(r){const y=r.exception?r.exception.position:0;e.position>y&&(r.exception=e)}}}function E(o,e){Object.keys(o).forEach(a=>{const t=o[a],{dayOfWeek:n}=t.metadata,{dayOfWeek:i}=e;(n&i)===n&&t.intervals.push(e)})}function K(o,e,a){const t=S(e,a);return o.forEach(n=>{n.type===g.OperatingHourType.Exception?W(t,n):E(t,n)}),t}function x(o,e,a,t,n){const i=K(o,a,t),s=t.format(d.OutletMapKeyFormatter),r=M(s,i[s],t)!==null,y=e;let l=null,u=null;if(e){const m=a.format(d.OutletMapKeyFormatter),p=M(m,i[m],a);if(p){const[f,O]=p.duration.split(":").map(Number);u=v(m,p.start),l=u.clone().add(f,"hours").add(O,"minutes")}}else u=k(i,a,n);if(!e&&!u){const m=o.filter(f=>f.state&&c(f.toDate).isAfter(a)),[p]=m.sort((f,O)=>t.valueOf()-(c(f.toDate).valueOf()-c(O.toDate).valueOf()));if(p)return x(o,e,c(p.toDate),t)}return{closingTime:l,openingTime:u,openDuringSpecifiedTime:y,openNow:r}}exports.DaysOfWeekMap=D;exports.default=x;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { OperatingHourType as
|
|
3
|
-
import { OutletMapKeyFormatter as d, OutletTimelineDayCount as
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
1
|
+
import c from "moment";
|
|
2
|
+
import { OperatingHourType as g } from "./types.mjs";
|
|
3
|
+
import { OutletMapKeyFormatter as d, OutletTimelineDayCount as k } from "./constants.mjs";
|
|
4
|
+
import D from "./getOutletCurrentActiveOperatingHour.mjs";
|
|
5
|
+
import v from "./getMomentFromDateAndTimeString.mjs";
|
|
6
|
+
import M from "./searchNextOpeningMoment.mjs";
|
|
7
7
|
import "@ancon/wildcat-types";
|
|
8
|
-
const
|
|
8
|
+
const x = {
|
|
9
9
|
0: 127,
|
|
10
10
|
1: 1,
|
|
11
11
|
2: 2,
|
|
@@ -15,100 +15,104 @@ const D = {
|
|
|
15
15
|
6: 32,
|
|
16
16
|
7: 64
|
|
17
17
|
};
|
|
18
|
-
function
|
|
19
|
-
const a =
|
|
18
|
+
function S(o, t) {
|
|
19
|
+
const a = o.isSame(t, "d"), n = {
|
|
20
20
|
[t.format(d)]: {
|
|
21
21
|
intervals: [],
|
|
22
22
|
exception: null,
|
|
23
|
-
metadata: { dayOfWeek:
|
|
23
|
+
metadata: { dayOfWeek: x[t.isoWeekday()] }
|
|
24
24
|
}
|
|
25
25
|
};
|
|
26
|
-
for (let
|
|
27
|
-
const s =
|
|
28
|
-
|
|
26
|
+
for (let i = a ? 1 : 0; i < k; i += 1) {
|
|
27
|
+
const s = c(o).add(i, "d");
|
|
28
|
+
n[s.format(d)] = {
|
|
29
29
|
intervals: [],
|
|
30
30
|
exception: null,
|
|
31
|
-
metadata: { dayOfWeek:
|
|
31
|
+
metadata: { dayOfWeek: x[s.isoWeekday()] }
|
|
32
32
|
};
|
|
33
33
|
}
|
|
34
|
-
return
|
|
34
|
+
return n;
|
|
35
35
|
}
|
|
36
|
-
function
|
|
37
|
-
const a =
|
|
36
|
+
function W(o, t) {
|
|
37
|
+
const a = c().utcOffset(), e = c(t.fromDate).utc(!1).subtract(a, "minutes"), n = c(t.toDate).utc(!1).subtract(a, "minutes");
|
|
38
38
|
if (!e.isSame(
|
|
39
|
-
|
|
39
|
+
n,
|
|
40
40
|
"d"
|
|
41
41
|
))
|
|
42
|
-
Object.keys(
|
|
43
|
-
const
|
|
44
|
-
if (
|
|
45
|
-
const
|
|
46
|
-
t.position >
|
|
42
|
+
Object.keys(o).forEach((s) => {
|
|
43
|
+
const r = c(s);
|
|
44
|
+
if (r.isSame(e, "d") || r.isSame(n, "d") || r.isBetween(e, n)) {
|
|
45
|
+
const f = o[s], p = f.exception ? f.exception.position : 0;
|
|
46
|
+
t.position > p && (f.exception = t);
|
|
47
47
|
}
|
|
48
48
|
});
|
|
49
49
|
else {
|
|
50
|
-
const s = e.format(d),
|
|
51
|
-
if (
|
|
52
|
-
const
|
|
53
|
-
t.position >
|
|
50
|
+
const s = e.format(d), r = o[s];
|
|
51
|
+
if (r) {
|
|
52
|
+
const y = r.exception ? r.exception.position : 0;
|
|
53
|
+
t.position > y && (r.exception = t);
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
|
-
function
|
|
58
|
-
Object.keys(
|
|
59
|
-
const e =
|
|
60
|
-
(
|
|
57
|
+
function E(o, t) {
|
|
58
|
+
Object.keys(o).forEach((a) => {
|
|
59
|
+
const e = o[a], { dayOfWeek: n } = e.metadata, { dayOfWeek: i } = t;
|
|
60
|
+
(n & i) === n && e.intervals.push(t);
|
|
61
61
|
});
|
|
62
62
|
}
|
|
63
|
-
function
|
|
64
|
-
const e =
|
|
65
|
-
return
|
|
66
|
-
|
|
63
|
+
function I(o, t, a) {
|
|
64
|
+
const e = S(t, a);
|
|
65
|
+
return o.forEach((n) => {
|
|
66
|
+
n.type === g.Exception ? W(e, n) : E(e, n);
|
|
67
67
|
}), e;
|
|
68
68
|
}
|
|
69
|
-
function
|
|
70
|
-
const
|
|
71
|
-
|
|
69
|
+
function h(o, t, a, e, n) {
|
|
70
|
+
const i = I(
|
|
71
|
+
o,
|
|
72
72
|
a,
|
|
73
73
|
e
|
|
74
|
-
),
|
|
75
|
-
|
|
76
|
-
|
|
74
|
+
), s = e.format(d), r = D(
|
|
75
|
+
s,
|
|
76
|
+
i[s],
|
|
77
77
|
e
|
|
78
|
-
) !== null,
|
|
79
|
-
let
|
|
78
|
+
) !== null, y = t;
|
|
79
|
+
let f = null, p = null;
|
|
80
80
|
if (t) {
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
-
|
|
81
|
+
const u = a.format(d), l = D(
|
|
82
|
+
u,
|
|
83
|
+
i[u],
|
|
84
84
|
a
|
|
85
85
|
);
|
|
86
86
|
if (l) {
|
|
87
|
-
const [m,
|
|
88
|
-
|
|
89
|
-
|
|
87
|
+
const [m, O] = l.duration.split(":").map(Number);
|
|
88
|
+
p = v(
|
|
89
|
+
u,
|
|
90
90
|
l.start
|
|
91
|
-
),
|
|
91
|
+
), f = p.clone().add(m, "hours").add(O, "minutes");
|
|
92
92
|
}
|
|
93
93
|
} else
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
)
|
|
99
|
-
|
|
94
|
+
p = M(
|
|
95
|
+
i,
|
|
96
|
+
a,
|
|
97
|
+
n
|
|
98
|
+
);
|
|
99
|
+
if (!t && !p) {
|
|
100
|
+
const u = o.filter(
|
|
101
|
+
(m) => m.state && c(m.toDate).isAfter(a)
|
|
102
|
+
), [l] = u.sort(
|
|
103
|
+
(m, O) => e.valueOf() - (c(m.toDate).valueOf() - c(O.toDate).valueOf())
|
|
100
104
|
);
|
|
101
105
|
if (l)
|
|
102
|
-
return
|
|
103
|
-
|
|
106
|
+
return h(
|
|
107
|
+
o,
|
|
104
108
|
t,
|
|
105
|
-
|
|
109
|
+
c(l.toDate),
|
|
106
110
|
e
|
|
107
111
|
);
|
|
108
112
|
}
|
|
109
|
-
return { closingTime:
|
|
113
|
+
return { closingTime: f, openingTime: p, openDuringSpecifiedTime: y, openNow: r };
|
|
110
114
|
}
|
|
111
115
|
export {
|
|
112
|
-
|
|
113
|
-
|
|
116
|
+
x as DaysOfWeekMap,
|
|
117
|
+
h as default
|
|
114
118
|
};
|
|
@@ -6,8 +6,9 @@ import { OperatingHourFormattedMap } from './types';
|
|
|
6
6
|
*
|
|
7
7
|
* @param {OperatingHourFormattedMap} operatingHourMap The map of formatted intervals and exceptions indexed against the date
|
|
8
8
|
* @param {Moment} relevantMoment The relevant moment to compare
|
|
9
|
+
* @param {String} outletTimeZoneOffset
|
|
9
10
|
*
|
|
10
11
|
* @return {Moment}
|
|
11
12
|
*/
|
|
12
|
-
declare function searchNextOpeningMoment(operatingHourMap: OperatingHourFormattedMap, relevantMoment: Moment): Moment | null;
|
|
13
|
+
declare function searchNextOpeningMoment(operatingHourMap: OperatingHourFormattedMap, relevantMoment: Moment, outletTimeZoneOffset?: string): Moment | null;
|
|
13
14
|
export default searchNextOpeningMoment;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const
|
|
1
|
+
"use strict";const m=require("moment"),p=require("@ancon/wildcat-types"),c=require("./constants.js"),a=require("./getMomentFromDateAndTimeString.js");function O(i){const[e]=i.split(":").map(Number)??[];return e??0}function d(i,e,r="00:00:00"){const[t,o]=r.split(":"),n=i.clone().add(t,"hour").add(o,"minute").date()-e.date();return n!==0?i.subtract(n,"day"):i}function g(i){let e=null;const{intervals:r,exception:t}=i;if(t){const{state:o}=t;o||(e=t)}else{const o=r.sort((n,s)=>O(n.start)-O(s.start)),[u]=o;return u}return e}function h(i,e,r){var o,u;const t=[];if(e.exception){if(e.exception.state===p.OutletState.Open){const n=a(i,e.exception.start);r.isBefore(n)&&t.push({interval:e.exception,moment:n})}}else for(let n=0;n<e.intervals.length;n+=1){const s=e.intervals[n],l=a(i,s.start);r.isBefore(l)&&t.push({interval:s,moment:l})}return t.length<2?((o=t[0])==null?void 0:o.interval)??null:((u=t.sort((n,s)=>n.moment-r-(s.moment-r))[0])==null?void 0:u.interval)??null}function x(i,e,r){let t=null;const o=m(e).format(c.OutletMapKeyFormatter),u=h(o,i[o],e);if(u&&(t=a(o,u.start),t=d(t,e,r)),!t)for(let n=1;n<c.OutletTimelineDayCount;n+=1){const s=m(e).add(n,"d"),l=s.format(c.OutletMapKeyFormatter),y=i[l],f=g(y);if(f){t=a(l,f.start),t=d(t,s,r);break}}return t}module.exports=x;
|
|
@@ -1,74 +1,86 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { OutletState as
|
|
3
|
-
import { OutletMapKeyFormatter as m, OutletTimelineDayCount as
|
|
1
|
+
import c from "moment";
|
|
2
|
+
import { OutletState as y } from "@ancon/wildcat-types";
|
|
3
|
+
import { OutletMapKeyFormatter as m, OutletTimelineDayCount as g } from "./constants.mjs";
|
|
4
4
|
import a from "./getMomentFromDateAndTimeString.mjs";
|
|
5
|
-
function
|
|
6
|
-
const [
|
|
7
|
-
return
|
|
5
|
+
function O(i) {
|
|
6
|
+
const [e] = i.split(":").map(Number) ?? [];
|
|
7
|
+
return e ?? 0;
|
|
8
8
|
}
|
|
9
|
-
function
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
function p(i, e, r = "00:00:00") {
|
|
10
|
+
const [t, o] = r.split(":"), n = i.clone().add(t, "hour").add(o, "minute").date() - e.date();
|
|
11
|
+
return n !== 0 ? i.subtract(n, "day") : i;
|
|
12
|
+
}
|
|
13
|
+
function h(i) {
|
|
14
|
+
let e = null;
|
|
15
|
+
const { intervals: r, exception: t } = i;
|
|
16
|
+
if (t) {
|
|
17
|
+
const { state: o } = t;
|
|
18
|
+
o || (e = t);
|
|
15
19
|
} else {
|
|
16
|
-
const
|
|
17
|
-
(n,
|
|
18
|
-
), [
|
|
19
|
-
return
|
|
20
|
+
const o = r.sort(
|
|
21
|
+
(n, s) => O(n.start) - O(s.start)
|
|
22
|
+
), [l] = o;
|
|
23
|
+
return l;
|
|
20
24
|
}
|
|
21
|
-
return
|
|
25
|
+
return e;
|
|
22
26
|
}
|
|
23
|
-
function x(
|
|
24
|
-
var
|
|
25
|
-
const
|
|
26
|
-
if (
|
|
27
|
-
if (
|
|
27
|
+
function x(i, e, r) {
|
|
28
|
+
var o, l;
|
|
29
|
+
const t = [];
|
|
30
|
+
if (e.exception) {
|
|
31
|
+
if (e.exception.state === y.Open) {
|
|
28
32
|
const n = a(
|
|
29
|
-
|
|
30
|
-
|
|
33
|
+
i,
|
|
34
|
+
e.exception.start
|
|
31
35
|
);
|
|
32
|
-
|
|
33
|
-
interval:
|
|
36
|
+
r.isBefore(n) && t.push({
|
|
37
|
+
interval: e.exception,
|
|
34
38
|
moment: n
|
|
35
39
|
});
|
|
36
40
|
}
|
|
37
41
|
} else
|
|
38
|
-
for (let n = 0; n <
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
+
for (let n = 0; n < e.intervals.length; n += 1) {
|
|
43
|
+
const s = e.intervals[n], u = a(
|
|
44
|
+
i,
|
|
45
|
+
s.start
|
|
42
46
|
);
|
|
43
|
-
|
|
47
|
+
r.isBefore(u) && t.push({ interval: s, moment: u });
|
|
44
48
|
}
|
|
45
|
-
return
|
|
46
|
-
(n,
|
|
47
|
-
)[0]) == null ? void 0 :
|
|
49
|
+
return t.length < 2 ? ((o = t[0]) == null ? void 0 : o.interval) ?? null : ((l = t.sort(
|
|
50
|
+
(n, s) => n.moment - r - (s.moment - r)
|
|
51
|
+
)[0]) == null ? void 0 : l.interval) ?? null;
|
|
48
52
|
}
|
|
49
|
-
function
|
|
50
|
-
let
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
o
|
|
54
|
-
|
|
53
|
+
function b(i, e, r) {
|
|
54
|
+
let t = null;
|
|
55
|
+
const o = c(e).format(m), l = x(
|
|
56
|
+
o,
|
|
57
|
+
i[o],
|
|
58
|
+
e
|
|
55
59
|
);
|
|
56
|
-
if (
|
|
60
|
+
if (l && (t = a(
|
|
61
|
+
o,
|
|
62
|
+
l.start
|
|
63
|
+
), t = p(
|
|
64
|
+
t,
|
|
57
65
|
e,
|
|
58
|
-
r
|
|
59
|
-
)), !
|
|
60
|
-
for (let
|
|
61
|
-
const
|
|
62
|
-
if (
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
+
r
|
|
67
|
+
)), !t)
|
|
68
|
+
for (let n = 1; n < g; n += 1) {
|
|
69
|
+
const s = c(e).add(n, "d"), u = s.format(m), d = i[u], f = h(d);
|
|
70
|
+
if (f) {
|
|
71
|
+
t = a(
|
|
72
|
+
u,
|
|
73
|
+
f.start
|
|
74
|
+
), t = p(
|
|
75
|
+
t,
|
|
76
|
+
s,
|
|
77
|
+
r
|
|
66
78
|
);
|
|
67
79
|
break;
|
|
68
80
|
}
|
|
69
81
|
}
|
|
70
|
-
return
|
|
82
|
+
return t;
|
|
71
83
|
}
|
|
72
84
|
export {
|
|
73
|
-
|
|
85
|
+
b as default
|
|
74
86
|
};
|