@shopgate/engage
Version:
Shopgate's ENGAGE library.
5 lines • 2.18 kB
JavaScript
function _slicedToArray(arr,i){return _arrayWithHoles(arr)||_iterableToArrayLimit(arr,i)||_nonIterableRest();}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance");}function _iterableToArrayLimit(arr,i){var _arr=[];var _n=true;var _d=false;var _e=undefined;try{for(var _i=arr[Symbol.iterator](),_s;!(_n=(_s=_i.next()).done);_n=true){_arr.push(_s.value);if(i&&_arr.length===i)break;}}catch(err){_d=true;_e=err;}finally{try{if(!_n&&_i["return"]!=null)_i["return"]();}finally{if(_d)throw _e;}}return _arr;}function _arrayWithHoles(arr){if(Array.isArray(arr))return arr;}import moment from'moment';import{i18n}from'@shopgate/engage/core';/**
* Creates a display string for the given slot.
* @param {Object} fulfillmentSlot Slot
* @returns {Object}
*/export var getTimeSlotDisplayText=function getTimeSlotDisplayText(fulfillmentSlot){if(!fulfillmentSlot||!(fulfillmentSlot===null||fulfillmentSlot===void 0?void 0:fulfillmentSlot.date)||!(fulfillmentSlot===null||fulfillmentSlot===void 0?void 0:fulfillmentSlot.from)){return i18n.text('locations.your_current_timeslot.not_set');}var momentDate=moment(fulfillmentSlot.date,'YYYY-MM-DD');var fromNow=momentDate.fromNow();var relativeString=momentDate.calendar(null,{sameDay:"[".concat(i18n.text('locations.your_current_timeslot.today'),"]"),nextDay:"[".concat(i18n.text('locations.your_current_timeslot.tomorrow'),"]"),nextWeek:'dddd',sameElse:function sameElse(){return"[".concat(fromNow,"]");}});var _fulfillmentSlot$from=fulfillmentSlot.from.split(':').map(function(x){return parseInt(x,10);}),_fulfillmentSlot$from2=_slicedToArray(_fulfillmentSlot$from,2),fromHours=_fulfillmentSlot$from2[0],fromMinutes=_fulfillmentSlot$from2[1];var from=moment().set({hours:fromHours,minutes:fromMinutes||0});var _fulfillmentSlot$to$s=fulfillmentSlot.to.split(':').map(function(x){return parseInt(x,10);}),_fulfillmentSlot$to$s2=_slicedToArray(_fulfillmentSlot$to$s,2),toHours=_fulfillmentSlot$to$s2[0],toMinutes=_fulfillmentSlot$to$s2[1];var to=moment().set({hours:toHours,minutes:toMinutes||0});return"".concat(relativeString," ").concat(from.format('LT')," - ").concat(to.format('LT'));};