Created
December 23, 2021 17:52
-
-
Save RuiGuilherme/7c76e39b7018b304a114836b0b6a5f2b to your computer and use it in GitHub Desktop.
Verifica se a data atual é útil | Check if the current date is a business day
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
// https://momentjs.com/docs/ | |
const isBussinessDay = (timezone = 'America/Araguaina', startHour = 8, endHour = 18) => { | |
const now = moment().tz(timezone) | |
const day = now.day() | |
const hour = now.hour() | |
// 6 === Satday and 7 === Sunday | |
return day !== 6 && day !== 7 && hour >= startHour && hour <= endHour | |
} | |
// examples: | |
isBussinessDay('America/Araguaina', 10, 20) | |
isBussinessDay('America/Sao_Paulo', 8, 18) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment