{"ScriptPreparationCode":"const weekDays = [\r\n \u0022sundayShort\u0022,\r\n \u0022mondayShort\u0022,\r\n \u0022tuesdayShort\u0022,\r\n \u0022wednesdayShort\u0022,\r\n \u0022thursdayShort\u0022,\r\n \u0022fridayShort\u0022,\r\n \u0022saturdayShort\u0022,\r\n];\r\n\r\nconst dateToDayName = (date) =\u003E weekDays[date.getDay()];\r\n\r\nfunction currentWeekRange () {\r\n const dt = new Date(); // current date of week\r\n dt.setHours(0); //reset hours\r\n const currentWeekDay = dt.getDay();\r\n const daysToMonday = currentWeekDay === 0 ? 6 : currentWeekDay - 1;\r\n const weekStart = new Date(new Date(dt).setDate(dt.getDate() - daysToMonday));\r\n const weekEnd = new Date(new Date(weekStart).setDate(weekStart.getDate() \u002B 7));\r\n return { weekStart, weekEnd };\r\n};\r\n\r\nfunction parseOpeningHours(openingHoursRaw, timeFormat){\r\n const openingHours = new opening_hours(openingHoursRaw,{ address: {country_code:\u0022us\u0022}});\r\n const {\r\n weekStart,\r\n weekEnd\r\n } = currentWeekRange();\r\n const intervals = openingHours.getOpenIntervals(weekStart, weekEnd);\r\n const timeRanges = {};\r\n intervals.forEach((interval)=\u003E {\r\n const weekDay = dateToDayName(interval[0]);\r\n //init array if day key is missing\r\n if (!timeRanges[weekDay]) timeRanges[weekDay] = [];\r\n const hoursFrom = interval[0].toLocaleTimeString(\u0022en-US\u0022, {\r\n hour: \u00222-digit\u0022,\r\n minute: \u00222-digit\u0022,\r\n hour12: timeFormat ,\r\n });\r\n const hoursTo = interval[1].toLocaleTimeString(\u0022en-US\u0022, {\r\n hour: \u00222-digit\u0022,\r\n minute: \u00222-digit\u0022,\r\n hour12: timeFormat,\r\n });\r\n timeRanges[weekDay].push(\u0060${hoursFrom} - ${hoursTo}\u0060);\r\n });\r\n const todayValues = timeRanges[dateToDayName(new Date())];\r\n\r\n const today = new Date().getTime();\r\n const todayNextChangeDiff = openingHours.getNextChange() - today;\r\n const todayNextChangeDiffHours = Math.trunc(todayNextChangeDiff / (1000 * 60 * 60));\r\n\r\n return {\r\n timeRanges,\r\n todayValues,\r\n isItOpenNow: openingHours.getState(),\r\n nextChange: todayNextChangeDiffHours\r\n };\r\n};\r\n\r\nfunction Memo(props) {\r\n const handler = React.useMemo(() =\u003E {\r\n return _.debounce(props.handler, props.wait);\r\n }, [props.handler, props.wait]);\r\n return React.createElement(\u0022div\u0022, { className: handler() });\r\n}\r\n\r\n\r\nvar propCases = [{\r\n handler: function() {\r\n return Math.random();\r\n },\r\n wait: 100\r\n}, {\r\n handler: function() {\r\n return Math.random();\r\n },\r\n wait: 200\r\n}];\r\npropCases.push(propCases[1]);","TestCases":[{"Name":"parseOpeningHours","Code":"propCases.forEach((props, i) =\u003E {\r\n parseOpeningHours(\u0027Mo,Tu,Th,Fr 12:00-18:00; Sa,PH 12:00-17:00; Th[3],Th[-1] off\u0027 , \u002712h\u0027)\r\n});","IsDeferred":false},{"Name":"memo","Code":"propCases.forEach((props, i) =\u003E {\r\n ReactDOM.render(React.createElement(Memo, props, null), root);\r\n});","IsDeferred":false}]}