JSFiddle - React, Tailwind, and code Playground
JavaScript
getHalfHourCount(1100, 1530);
getHalfHourCount(1059, 1531);
function getHalfHourCount(start, end) {
start = getMinutes(start);
end = getMinutes(end);
var diff;
if (end < start)
diff = 24*60 - start + end
else
diff = end - start;
if (start % 30 != 0)
diff = diff + start % 30;
--diff;
var result = Math.floor(diff / 30);
document.write(result + "<br />");
return result;
}
function getMinutes(time) {
time = String(time);
if (time.length == 4)
return parseInt(time.substr(0, 2)) * 60 + parseInt(time.substr(2, 2));
else
return parseInt(time.substr(0, 1)) * 60 + parseInt(time.substr(1, 2));
}