Created
March 2, 2020 19:17
-
-
Save kolyuchii/6a89d12396d58378e556f54de2585c80 to your computer and use it in GitHub Desktop.
Business Open Hours Ratio
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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