
Security News
The Changelog Podcast: Practical Steps to Stay Safe on npm
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.
@chatwoot/business-hours
Advanced tools
pnpm install @chatwoot/business-hours
npm install @chatwoot/business-hours
yarn add @chatwoot/business-hours
You need to initialize the scheduler using the following options, the hours defines the schedule for each day of the week, and the holidays is an array of Date objects.
import { Scheduler } from '@chatwoot/business-hours'
const scheduler = new Scheduler({
hours: {
0: null,
1: [
{ start: "09:00", end: "12:00" },
{ start: "13:00", end: "18:00" },
],
2: [
{ start: "09:00", end: "12:00" },
{ start: "13:00", end: "18:00" },
],
3: [{ start: "09:00", end: "12:00" }],
4: [{ start: "09:00", end: "18:00" }],
5: [{ start: "09:00", end: "18:00" }],
6: null,
},
holidays: [
new Date("2024-03-08"),
new Date("2024-03-09"),
new Date("2024-03-10"),
],
});
nextWorkingTimeThis method takes a date and returns the next working time. If the date is a holiday, it will return the next working day. If the date is a working day, it will return the next working time.
scheduler.nextWorkingTime(new Date("2024-03-08"));
nextWorkingDayThis method takes a date and returns the next working day. If the date is a holiday, it will return the next working day. If the date is a working day, it will return the same day.
scheduler.nextWorkingDay(new Date("2024-03-08"));
isWorkingDayThis method takes a date and returns a boolean. If the date is a holiday, it will return false. If the date is a working day, it will return true.
scheduler.isWorkingDay(new Date("2024-03-08"));
isWorkingTimeThis method takes a date and returns a boolean. If the date is a holiday, it will return false. If the date is a working day, it will return true.
scheduler.isWorkingTime(new Date("2024-03-08"));
isHolidayThis method takes a date and returns a boolean. If the date is a holiday, it will return true. If the date is a working day, it will return false.
scheduler.isHoliday(new Date("2024-03-08"));
addTimeThis method takes a datetime, along with the time to add in seconds and returns the new date. If the date is outside working hours, it will add it to the working hours, suppose the working hours is between 8AM to 5PM, and I pass it 7:30 PM and ask it to add 10 mins, it will return 8:10 AM.
scheduler.addTime(new Date("2024-03-08"), 3600);
FAQs
Compute business hours like a pro
We found that @chatwoot/business-hours demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.

Security News
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.

Security News
Ruby's creator Matz assumes control of RubyGems and Bundler repositories while former maintainers agree to step back and transfer all rights to end the dispute.