Skip to content

Instantly share code, notes, and snippets.

@RuiGuilherme
Created December 23, 2021 17:52
Show Gist options
  • Save RuiGuilherme/7c76e39b7018b304a114836b0b6a5f2b to your computer and use it in GitHub Desktop.
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
// 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