next-biz-date
Advanced tools
Comparing version 2.1.1 to 2.1.2
18
main.js
(() => { | ||
const moment = require("moment"); | ||
const memoize = require("memoizee"); | ||
const _crawlForCount = memoize(__crawlForCount); | ||
//const memoize = (c) => {return c;}; | ||
const crawlForCount = memoize(_crawlForCount); | ||
const findBizDate = memoize(_findBizDate); | ||
const findNextBizDate = memoize(_findNextBizDate); | ||
@@ -16,3 +18,3 @@ /*** | ||
*/ | ||
function findNextBizDate(baseDate, holidaysArray, countTarget, direction) { | ||
function _findNextBizDate(baseDate, holidaysArray, countTarget, direction) { | ||
if (!countTarget) { | ||
@@ -30,3 +32,3 @@ countTarget = 0; | ||
return _crawlForCount(baseDate, holidaysArray, countTarget, direction); | ||
return crawlForCount(baseDate, holidaysArray, countTarget, direction); | ||
} | ||
@@ -42,5 +44,5 @@ } | ||
* @param {String} direction FORWARD or BACKWARDS | ||
* @returns {main=>#1._crawlForCount.mResultDate} | ||
* @returns {main=>#1.crawlForCount.mResultDate} | ||
*/ | ||
function __crawlForCount(baseDate, holidaysArray, countTarget, direction) { | ||
function _crawlForCount(baseDate, holidaysArray, countTarget, direction) { | ||
const mBaseDate = moment(baseDate); | ||
@@ -185,4 +187,4 @@ let mResultDate = mBaseDate; | ||
exports.FindBizDate = memoize(findBizDate); | ||
exports.FindNextBizDate = memoize(findNextBizDate); | ||
exports.FindBizDate = findBizDate; | ||
exports.FindNextBizDate = findNextBizDate; | ||
})(); |
{ | ||
"name": "next-biz-date", | ||
"version": "2.1.1", | ||
"version": "2.1.2", | ||
"description": "Returns the next business date for a given reference date (initialDate), an offset count value, a direction (FORWARD or BACKWARDS) and a given array of holidays. This package is optimized by memoization techniques.", | ||
@@ -5,0 +5,0 @@ "main": "main.js", |
@@ -182,22 +182,31 @@ const assert = require("assert"); | ||
const targetYears = 2; | ||
const targetYears = 1; | ||
const targetFFDays = 5; | ||
it(`Should support ${targetYears} years of days iterations in reasonable time`, () => { | ||
console.log(`COUNTING ${targetFFDays} days FOR ${targetYears} YEARS...`); | ||
let volumeTestItem = moment("2010-01-01"); | ||
const volumeTests = []; | ||
for (vt = 0; vt < 365 * targetYears; vt++) { | ||
volumeTests.push(moment(volumeTestItem)); | ||
volumeTestItem = volumeTestItem.add(1, "days"); | ||
let volumeTestItem = moment("2020-01-01"); | ||
let results = []; | ||
for (vt = 0; vt < 365*targetYears; vt++) { | ||
volumeTestItem = moment(volumeTestItem.add(1, "days")); | ||
result = nbd.FindNextBizDate(volumeTestItem, holidays, targetFFDays, "FORWARD"); | ||
results.push({volumeTestItem, result}); | ||
} | ||
volumeTests.forEach((item) => { | ||
result = nbd.FindNextBizDate(item, holidays, targetFFDays, "FORWARD"); | ||
}); | ||
console.log(`FINISHED AFTER PROCESSING ${results.length} days that counted forward ${targetFFDays} business days each!`); | ||
console.log(`FINISHED AFTER PROCESSING ${volumeTests.length} days that counted forward ${targetFFDays} business days each!`); | ||
}); | ||
it("Shoud process 10000 of the same day in record time", () => { | ||
let counter = 0; | ||
for (i = 0; i < 10000; i++) { | ||
let volumeTestItem = "2020-12-25"; | ||
let result = nbd.FindNextBizDate(volumeTestItem, holidays, 15, "FORWARD"); | ||
assert.equal(result.isSame(moment("2021-01-20")), true); | ||
counter = i; | ||
} | ||
assert.equal(counter, 9999); | ||
}); | ||
}); |
20588
358