new WorkingDays(configopt)
Working days Calculator
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
config |
object |
<optional> |
Configure includeToday, verbose, weekOffDays, dateFormat, customHolidays |
Example
const WorkingDays = require('moment-working-days');
const momentWorkingdays = new WorkingDays({
includeToday: true, // optional. Default true
verbose: true, // optional. Default false
weekOffDays: [0, 6], // optional. Default [0, 6]
dateFormat: 'DD-MM-YYYY', // optional. Default 'YYYY-MM-DD'
customHolidays: ['02-12-2019'], // optional
customWorkingDays: ['07-12-2019'] // optional
})
Methods
addWorkingDays(date, noOfDays) → {string}
Takes date string and number of days.
Parameters:
Name | Type | Default | Description |
---|---|---|---|
date |
string | Date string | |
noOfDays |
number | 1 | Number of days |
Returns:
returns date string after adding noOfDays working days
- Type
- string
Example
momentWorkingdays.addWorkingDays("06-12-2019", 2) // Friday
// returns 10-12-2019
// Tuesday
getWorkingDays(data) → {number}
Takes array of dates.
Parameters:
Name | Type | Description |
---|---|---|
data |
Array.<string> | Array of Date string(s) |
Returns:
returns number of working days
- Type
- number
Examples
momentWorkingdays.getWorkingDays([
"29-11-2019", "03-12-2019",
"07-12-2019", "12-12-2019"
])
// returns 6
momentWorkingdays.getWorkingDays([
"29-11-2019", "03-12-2019",
"07-12-2019"
])
// returns 3
momentWorkingdays.getWorkingDays([
"29-11-2019"
])
// returns 6
isWorkingday(date) → {boolean}
Util to calculate working days considering sequence
of date(s) - similar to start-stop timer sequence
Parameters:
Name | Type | Description |
---|---|---|
date |
string | Date string |
Returns:
returns if its a working day or not
- Type
- boolean
Examples
momentWorkingdays.isWorkingday("02-12-2019") // Monday
// returns 6
momentWorkingdays.isWorkingday("01-12-2019") // Sunday
// returns false
momentWorkingdays.isWorkingday("06-12-2019") // Friday
// returns true
nextWorkingDay(date) → {string}
Takes date string.
Parameters:
Name | Type | Description |
---|---|---|
date |
string | Date string |
Returns:
returns next working day
- Type
- string
Example
momentWorkingdays.nextWorkingDay("06-12-2019") // Friday
// returns 09-12-2019
// Monday
prevWorkingDay(date) → {string}
Takes date string.
Parameters:
Name | Type | Description |
---|---|---|
date |
string | Date string |
Returns:
returns previous working day
- Type
- string
Example
momentWorkingdays.prevWorkingDay("09-12-2019") // Monday
// returns 06-12-2019
// Friday
setCustomWorkingDays(customWorkingDays) → {WorkingDays}
Sets customWorkingDays.
Parameters:
Name | Type | Description |
---|---|---|
customWorkingDays |
Array.<string> |
Returns:
returns WorkingDays object
- Type
- WorkingDays
Example
momentWorkingdays.customWorkingDays(['07-12-2019'])
setWeekOffDays(weekOffDays) → {WorkingDays}
Sets weekOffDays.
Parameters:
Name | Type | Description |
---|---|---|
weekOffDays |
Array.<string> |
Returns:
returns WorkingDays object
- Type
- WorkingDays
Example
momentWorkingdays.setWeekOffDays([0, 1, 2, 3, 4, 6])
subtractWorkingDays(date, noOfDays) → {string}
Takes date string and number of days.
Parameters:
Name | Type | Default | Description |
---|---|---|---|
date |
string | Date string | |
noOfDays |
number | 1 | Number of days |
Returns:
returns date string after subtracting noOfDays working days
- Type
- string
Example
momentWorkingdays.subtractWorkingDays("09-12-2019", 2) // Monday
// returns 05-12-2019
// Thursday