New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

next-biz-date

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

next-biz-date - npm Package Compare versions

Comparing version 2.0.3 to 2.1.0

23

main.js
(() => {
const moment = require("moment");
const memoize = require("memoizee");

@@ -55,11 +56,2 @@ /***

let isBusinessDay_Cache = [];
function isBusinessDay_getFromCache(mCandidateDate) {
for (idx = 0; idx < isBusinessDay_Cache.length; idx++) {
let cachedItem = isBusinessDay_Cache[idx];
if (cachedItem.cachedDate.isSame(mCandidateDate)) {
return cachedItem.result;
}
}
}
/**

@@ -75,9 +67,3 @@ * Deterimnes if provided candidateDate exists in the holidays array

let cachedResult = isBusinessDay_getFromCache(mCandidateDate);
if (cachedResult !== undefined) {
return cachedResult;
}
if (dow === 6 || dow === 0) {
isBusinessDay_Cache.push({cachedDate: mCandidateDate, result: false});
return false;

@@ -89,8 +75,5 @@ }

if (mHolidayAtStake.isSame(mCandidateDate)) {
isBusinessDay_Cache.push({cachedDate: mCandidateDate, result: false});
return false;
}
}
isBusinessDay_Cache.push({cachedDate: mCandidateDate, result: true});
return true;

@@ -199,4 +182,4 @@ }

exports.FindBizDate = findBizDate;
exports.FindNextBizDate = findNextBizDate;
exports.FindBizDate = memoize(findBizDate);
exports.FindNextBizDate = memoize(findNextBizDate);
})();

5

package.json
{
"name": "next-biz-date",
"version": "2.0.3",
"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",
"version": "2.1.0",
"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.",
"main": "main.js",

@@ -34,2 +34,3 @@ "scripts": {

"dependencies": {
"memoizee": "^0.4.14",
"moment": "^2.29.1"

@@ -36,0 +37,0 @@ },

@@ -114,3 +114,3 @@ const assert = require("assert");

{baseDate: "2020-12-19", offset: 11 /* WW1234HWWH567HWWH8901 */, expectedResult: "2021-01-08"},
{baseDate: "2020-12-24", offset: 4 /* WW1234HWWH567HWWH8901 */, expectedResult: "2021-01-05"},

@@ -183,14 +183,22 @@ ];

it("Should support 11000 iterations in reasonable time", () => {
const targetYears = 1;
const targetFFDays = 1;
it(`Should support ${targetYears} years of days iterations in reasonable time`, () => {
console.log(`COUNTING ${targetFFDays} days FOR ${targetYears} YEARS...`);
const cornerCase = {baseDate: "2020-12-19", expectedResult: "2020-12-16"};
let i = 0;
let result;
for (i = 0; i < 11000; i++) {
result = nbd.FindNextBizDate(cornerCase.baseDate, holidays, 2, "BACKWARDS");
let volumeTestItem = moment("2010-01-01");
const volumeTests = [];
for (vt = 0; vt < 365 * targetYears; vt++) {
volumeTests.push(moment(volumeTestItem));
volumeTestItem = volumeTestItem.add(1, "days");
}
console.log(`FINISHED AFTER ${i} iterations`, result);
assert.equal(result.isSame(moment(cornerCase.expectedResult)), true);
volumeTests.forEach((item) => {
result = nbd.FindNextBizDate(item, holidays, targetFFDays, "FORWARD");
});
console.log(`FINISHED AFTER PROCESSING ${volumeTests.length} days that counted forward ${targetFFDays} business days each!`);
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc