@date/business

Calculate business day dates optionally considering holidays.

Stats

StarsIssuesVersionUpdatedCreatedSize
@date/business
200.1.15 years ago5 years agoMinified + gzip package size for @date/business in KB

Readme

@date/business

Build Status Dependency Status npm version

Calculate business day dates optionally considering holidays.

See @date/holidays

Install

npm install @date/business --save

Usage

// use @date/holidays instance when calculating business days
// it's optional. don't set a holidays instance and it only considers Mon-Fri
var biz = require('@date/business')({
  // use USA bank holidays
  holidays: require('@date/holidays-us').bank()
})

// New Year's Day 2016 is a Friday, a bank holiday
var date = new Date(2016, 0, 1)
biz.isBusinessDay(date) // false, it's a holiday

// nextBusinessDay() will change it to
// Monday, the 4th, which is a business day
biz.nextBusinessDay(date)
biz.isBusinessDay(date) // true

// move it to Wednesday
biz.addBusinessDays(date, 2)
biz.isBusinessDay(date) // true

// move it to the next Monday, it skips both Saturday and Sunday
biz.addBusinessDays(date, 3) // three would be Saturday, but it skips to Monday
biz.isBusinessDay(date) // true

// 5 business days would be the next Monday, which is
// Martin Luther King Jr. Day, so, it'll end up being Tuesday instead
biz.addBusinessDays(date, 5)
biz.isBusinessDay(date) // true

// back up to the holiday
date.setDate(date.getDate() - 1)
biz.isBusinessDay(date) // false

// previous business day is the Friday
biz.previousBusinessDay(date)
// OR:
// biz.addBusinessDays date, -1
biz.isBusinessDay(date) // true

MIT License

If you find any bugs or have a feature request, please open an issue on github!

The npm package download data comes from npm's download counts api and package details come from npms.io.