{"version":1,"customWidget":{"_id":"xkjceyEuApD5E4k5K","name":"Get Hours Between Dates","props":[{"name":"Start Time","type":"timestamp","id":"tThe26Bfs5D57sKZ5","requireWriteable":false,"description":"This is the beginning time of the range that you want the time between"},{"name":"End Time","type":"timestamp","id":"AWvRLH5exXzAnSuZW","requireWriteable":false,"description":"This is the End time of the range that you want the time between"},{"name":"Exclude Weekends","type":"boolean","id":"bAEEZs2jbjpzsX73X","requireWriteable":false,"description":"When checked, weekends wont be counted."},{"name":"Shift Start Time","type":"integer","id":"Ec6vJ9zpZWaDH3QQw","requireWriteable":false,"description":"hours, in 24hr"},{"name":"Shift End Time","type":"integer","id":"ewFvZasvZNS9gDBPj","requireWriteable":false,"description":"hours, in 24hr"}],"events":[{"name":"Hours","type":"integer","id":"23LZH6bB2cc2TNqnr"}],"html":"","javascript":"$('#btn').click(function() {calculateDelta();})\n\nfunction getDate(dt_obj){\n //Convert a Tulip Datetime to a JS date object\n \n let d = new Date(0); // The 0 there is the key, which sets the date to the epoch\n d.setUTCSeconds(dt_obj['timestamp']/1000);\n return d\n}\n\nfunction getShiftStart(start){\n //Get the datetime of the shift start, on the date of the starttime.\n //So if starttime is 1/1/2022 at 13:00 and shift start time is 8 \n // this would return 1/1/2022 at 8:00\n const startOfDay = new Date(start);\n startOfDay.setHours(getValue(\"Shift Start Time\")||0);\n return startOfDay\n}\nfunction getShiftEnd(end){\n //Get the datetime of the shift end, on the date of the endtime.\n //So if endtime is 1/1/2022 at 13:00 and shift end time is 16 \n // this would return 1/1/2022 at 16:00\n const startOfDay = new Date(end);\n startOfDay.setHours(getValue(\"Shift End Time\")||24);\n return startOfDay\n}\n\nfunction getBusinessDatesCount(startDate, endDate) {\n //Returns the number of business days between 2 dates\n \n console.log(startDate.toLocaleString(),endDate.toLocaleString());\n let count = 0;\n let first = true;\n const curDate = new Date(startDate.getTime());\n while (curDate <= endDate) {\n const dayOfWeek = curDate.getDay();\n if(dayOfWeek !== 0 && dayOfWeek !== 6){\n count++;\n \n } \n curDate.setDate(curDate.getDate() + 1);\n }\n //alert(count);\n return count;\n}\nfunction getDaysCount(start,end){\n //Returns all the days between 2 dates.\n let Difference_In_Time = end.getTime() - start.getTime();\n\n let Difference_In_Days = Difference_In_Time / (1000 * 3600 * 24);\n return Math.ceil(Difference_In_Days)\n}\n\nfunction getTruncDateTime(date){\n //Returns the time being passed in, but truncated to 00:00 on that day\n let startOfDay = new Date(date);\n startOfDay.setHours(0);\n //console.log(\"Before return test\", startOfDay.toLocaleString());\n return startOfDay\n}\n\nfunction betterDeltaEnd(measure,shiftEnd,shiftLengh){\n let shiftStart = getShiftStart(shiftEnd);\n if (measure.getTime()shiftEnd.getTime()){\n console.log(\"in 2\")\n return 0\n }\n else{\n console.log(\"in 3\")\n let diff = shiftEnd.getTime() - measure.getTime();\n diff = diff/1000/3600\n diff = Math.floor(diff)\n return (diff)\n }\n}\nfunction betterDeltaStart(measure,shiftStart,shiftLengh){\n let shiftEnd = getShiftEnd(shiftStart);\n //console.log(shiftEnd.toLocaleString());\n if (measure.getTime()>shiftEnd.getTime()){\n //console.log(\"in 1\")\n return shiftLengh\n }\n else if (measure.getTime()