Skip to content

wojtek1150/moment-business-days-diff

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

moment-business-days-diff

This is a Moment.js plugin that allows you to work with only business days (Monday to Friday). You can customize the working week

Usage

// NodeJS: require instead of standard moment package
const moment = require('moment-business-days');
// You'll be able use Moment.js as you normally do
<!-- Browser -->
<!-- NB: add after moment.js -->
<script src="moment.js"></script>
<script src="moment-business-days-diff.js"></script>

Use localization to configure business days

const moment = require('moment-business-days');

moment.updateLocale('us', {
   workingWeekdays: [1, 2, 3, 4, 5, 6]
});

// Defines days from 1 (Monday) to 6 (Saturday) as business days.
// When omitting this configuration parameter, business days are based on locale default

API

.isBusinessDay() => boolean

Check if the date is a business day and return true or false:

// 2018-09-17 is Monday
moment('2018-09-20', 'DD-MM-YYYY').isBusinessDay() // true

// 2018-09-20 is Sunday
moment('2018-09-20', 'DD-MM-YYYY').isBusinessDay() // false

.businessDiff() => number

Calculate the number of business days between dates.

const diff = moment('2018-09-12').businessDiff(moment('2018-09-19'));
// diff = 5

.countBusinessDaysInDaysFromDate() => number

Calculate the number of business days in next given days

const count = moment('2018-09-12').countBusinessDaysInDaysFromDate(7);
// count = 5

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published