Calculate business day dates optionally considering holidays.

Usage no npm install needed!

<script type="module">
  import dateBusiness from 'https://cdn.skypack.dev/@date/business';



Build Status Dependency Status npm version

Calculate business day dates optionally considering holidays.

See @date/holidays


npm install @date/business --save


// 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.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
// OR:
// biz.addBusinessDays date, -1
biz.isBusinessDay(date) // true

MIT License