Skip to content

Instantly share code, notes, and snippets.

@kolyuchii
Created March 2, 2020 19:17
Show Gist options
  • Select an option

  • Save kolyuchii/6a89d12396d58378e556f54de2585c80 to your computer and use it in GitHub Desktop.

Select an option

Save kolyuchii/6a89d12396d58378e556f54de2585c80 to your computer and use it in GitHub Desktop.
Business Open Hours Ratio
function openHoursRatio(queryTimeRange, openHours) {
let duration = 0;
for (let i = 0; i < openHours.length; i += 1) {
const openHour = openHours[i];
duration += Math.min(queryTimeRange.end, openHour.end) - Math.max(queryTimeRange.start, openHour.start);
}
if (duration < 0) {
return 0;
}
return duration / (queryTimeRange.end - queryTimeRange.start);
}
openHoursRatio(
{
start: 7,
end: 11,
},
[
{
start: 14,
end: 17,
},
]
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment