JSPM

@date/business

0.1.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 352
  • Score
    100M100P100Q81468F
  • License MIT

Calculate business day dates optionally considering holidays.

Package Exports

  • @date/business

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@date/business) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

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