This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const moment = require('moment'); | |
moment.fn.addWorkdays = function (days) { | |
// Getting negative / positive increment | |
var increment = days / Math.abs(days); | |
// Looping weeks for each full 5 workdays | |
var date = this.clone().add(Math.floor(Math.abs(days) / 5) * 7 * increment, 'days'); | |
// Account for starting on Saturdays and Sundays | |
if (date.isoWeekday() === 6) { date.add(-increment, 'days'); } | |
else if (date.isoWeekday() === 7) { date.add(-2 * increment, 'days'); } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const moment = require('moment'); | |
moment.fn.addWorkdays = function addWorkdays(days) { | |
// Getting negative / positive increment | |
const increment = days / Math.abs(days); | |
// Looping weeks for each full 5 workdays | |
const date = this.clone().add(Math.floor(Math.abs(days) / 5) * 7 * increment, 'days'); | |
// Account for starting on Saturdays and Sundays | |
if (date.isoWeekday() === 6) { date.add(-increment, 'days'); } | |
else if (date.isoWeekday() === 7) { date.add(-2 * increment, 'days'); } |