next-biz-date
Advanced tools
Comparing version 1.0.0 to 1.0.1
57
main.js
(() => { | ||
const moment = require("moment"); | ||
/** | ||
* Find a business date by shifting a base date by a provided offset in the provided direction. It leverages the findBizDate() function. | ||
* @param {String} baseDate String of YYYY-MM-DD format or Moment object | ||
* @param {Array} holidaysArray Array of strings of YYYY-MM-DD format | ||
* @param {Int} offset | ||
* @param {String} direction with content of "FORWARD" or "BACKWARDS" | ||
* @returns {main=>#1.findBizDate.mCandidateDate|moment} | ||
*/ | ||
/** | ||
* Find a business date by shifting a base date by a provided offset in the provided direction. It leverages the findBizDate() function. | ||
* @param {String} baseDate String of YYYY-MM-DD format or Moment object | ||
* @param {Array} holidaysArray Array of strings of YYYY-MM-DD format | ||
* @param {Int} offset | ||
* @param {String} direction with content of "FORWARD" or "BACKWARDS" | ||
* @returns {main=>#1.findBizDate.mCandidateDate|moment} | ||
*/ | ||
function findNextBizDate(baseDate, holidaysArray, offset, direction) { | ||
@@ -55,22 +55,9 @@ if (!offset) { | ||
if (holidaysArray === undefined || holidaysArray.length === undefined || holidaysArray.length === 0) { | ||
console.warn("Holidays Array is Empty"); | ||
return mCandidateDate; | ||
} | ||
//SCAN the HolyDays array and use recursion | ||
let initial, increment, exitCondition; | ||
if (direction === "FORWARD") { | ||
initial = 0; | ||
increment = 1; | ||
exitCondition = (value) => { | ||
return value < holidaysArray.length; | ||
}; | ||
} else { | ||
initial = holidaysArray.length - 1; | ||
increment = -1; | ||
exitCondition = (value) => { | ||
return value >= 0; | ||
}; | ||
} | ||
for (var i = initial; exitCondition(i); i += increment) { | ||
let directionLogic = getDirectionLogic(direction, holidaysArray); | ||
for (var i = directionLogic.initial; directionLogic.exitCondition(i); i += directionLogic.increment) { | ||
let item = holidaysArray[i]; | ||
@@ -95,5 +82,23 @@ const mHoliday = moment(item); | ||
} | ||
function getDirectionLogic(direction, holidaysArray) { | ||
let result = {}; | ||
if (direction === "FORWARD") { | ||
result.initial = 0; | ||
result.increment = 1; | ||
result.exitCondition = (value) => { | ||
return value < holidaysArray.length; | ||
}; | ||
} else { | ||
result.initial = holidaysArray.length - 1; | ||
result.increment = -1; | ||
result.exitCondition = (value) => { | ||
return value >= 0; | ||
}; | ||
} | ||
return result; | ||
} | ||
exports.FindBizDate = findBizDate; | ||
exports.FindNextBizDate = findNextBizDate; | ||
})(); |
{ | ||
"name": "next-biz-date", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "returns the next future business date based on a reference date and a number of days to look into the future and given array of holidays", | ||
@@ -5,0 +5,0 @@ "main": "main.js", |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
12160
208
0