Created
June 6, 2019 14:58
-
-
Save hendrikkao1/efcd13050c8159e87864a9838c3a36be to your computer and use it in GitHub Desktop.
Function to check if current day and time fit the opening hours
This file contains 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 to check if current day and time fit the opening hours. | |
* @param {number[]} openDays - Array of days represented as numbers, sunday - saturday : 0 - 6. | |
* @param {number} openingTime - Opening time in minutes, 9:00 : 9 * 60. | |
* @param {number} closingTime - Closing time in minutes 17:00 : 17 * 60. | |
* @return {boolean} | |
*/ | |
function isOpeningHours(openDays = [1, 2, 3, 4, 5], openingTime = 9 * 60, closingTime = 17 * 60) { | |
const date = new Date(); | |
const day = date.getDay(); | |
const time = date.getHours() * 60 + date.getMinutes(); | |
return openDays.includes(day) && openingTime <= time && time <= closingTime; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment