Skip to content

Let your date libaray like Moment.js can count holidays and make-up days!

License

Notifications You must be signed in to change notification settings

jackypan1989/business-day

Repository files navigation

CI

business-day

Let your date libaray like Moment.js can count holidays!

features

  • configurable workdays (default: Mon. -> Fri.)
  • configurable holidays
  • configurable make-up days
  • support Moment.js
  • support Day.js
  • support date-fns
  • fully tests

install

# use npm
yarn add business-day

# use npm
npm i business-day

usage

import moment from 'moment'
import { MomentCore as BusinessDay } from 'business-day'

// 2020-12-01 (Tuesday), 2020-12-02 (Wednesday)

BusinessDay.setConfig({ holidays: ['2020-12-01'] })
const day1 = moment('2020-11-30')
console.log(BusinessDay.addBusinessDays(day1.toDate(), 1))
// Moment<2020-12-02T00:00:00+08:00>

BusinessDay.setConfig({ holidays: ['2020-12-01', '2020-12-02'] })
const day2 = moment('2020-11-30')
console.log(BusinessDay.addBusinessDays(day2.toDate(), 1))
// Moment<2020-12-03T00:00:00+08:00>