1.1.1 • Published 6 years ago

moment-workdays v1.1.1

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

moment-workdays

Build Status Maintainability

A moment plugin for working with Monday through Friday schedules. Extends a moment instance's diff method to include the computation of workdays between any two dates.

const start = moment().day('Tuesday')
const end = moment().day('Friday')

start.diff(end, 'workdays')
// 3

Usage

Install using npm

$ npm install --save moment-workdays

Import and run the extension function

const moment = require('moment')
const { extendMoment } = require('moment-workdays')

extendMoment(moment)

Examples

Handles crossing weekends correctly

const start = moment().day('Tuesday')
const end = moment().day('Friday').add(7, 'days')

start.diff(end, 'workdays')
// 8

Also handles things that are overdue

const start = moment().day('Friday')
const end = moment().day('Tuesday').subtract(7, 'days')

start.diff(end, 'workdays')
// -8

Holidays

moment-workdays adds support for an additional, optional array of holiday ranges. The holidays should each be an instance of moment-range. For example

const holiday = moment.range('2017-12-10', '2017-12-30')
const start = moment('2017-12-05')
const end = moment('2017-01-04')

start.diff(end, 'workdays', [ holiday ])
// 7
1.1.1

6 years ago

1.1.0

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago