Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
business-days-calculator
Advanced tools
Library for calculating the number of working days (business days) between two dates (considering a Holiday Calendar given).
This is a library for calculating the number of business days between two dates, considering the number of holidays in the range.
You can use it as a Node.js module or in browser.
If you use NPM, then you can install it with npm install business-days-calculator
. Otherwise, you can download the latest release and use it in your browser or in other Javascript-based projects.
var calculator = require("business-days-calculator");
var calendar = require("holidays-calendar-brazil");
calculator.SetCalendar(calendar);
var today = new Date();
console.log('Today '+ (calculator.IsBusinessDay(today) ? 'is' : 'isn\'t') +' a business day');
console.log('Today '+ (calculator.IsHoliday(today) ? 'is' : 'isn\'t') +' a holiday');
console.log('The Carnival next year is due to '+ (calculator.NextHoliday(new Date("1 January "+today.getFullYear()))));
<script src="../node_modules/holidays-calendar/dist/HolidaysCalendar.js"></script>
<script src="../node_modules/holidays-calendar-brazil/src/HolidaysCalendar-brazil.js" charset="utf-8"></script>
<script src="../dist/BusinessDaysCalculator.js"></script>
<script>
var today = new Date();
console.log('Today '+ (BusinessDaysCalculator.IsBusinessDay(today) ? 'is' : 'isn\'t') +' a business day');
console.log('Today '+ (BusinessDaysCalculator.IsHoliday(today) ? 'is' : 'isn\'t') +' a holiday');
console.log('The Carnival next year is due to '+ (BusinessDaysCalculator.NextHoliday(new Date("1 January "+today.getFullYear()))));
</script>
Counts the number of continuous/consecutive days between date1 and date2
date1: date, required. Starting date.
date2: date, required. Ending date.
return: integer. Number of continous days between dates.
var calculator = require('business-days-calculator');
var data = calculator.ContinuousDaysBetween(new Date("1 January 2020"), new Date("31 January 2020"));
\\data equals to 30
Counts the number of holidays between date1 and date2
date1: date, required. Starting date.
date2: date, required. Ending date.
return: integer. Number of holidays according to the calendar in use.
var calendar = require('holidays-calendar-brazil');
var calculator = require('business-days-calculator');
calculator.SetCalendar(calendar);
var data = calculator.HolidaysBetween(new Date("1 January 2020"), new Date("31 December 2020"));
\\data equals to 12
Verifies if date doesn't correspond to a Sunday or Saturday, neither is a holiday.
date: date, required. Date reference.
return: Boolean. Whether date is a business day or not.
var calendar = require('holidays-calendar-brazil');
var calculator = require('business-days-calculator');
calculator.SetCalendar(calendar);
var data = calculator.IsBusinessDay(new Date("1 January 2020"));
\\data equals to false
Verifies if date happens to be a holiday.
date: date, required. Date reference.
return: Boolean. Whether date is a holiday or not.
var calendar = require('holidays-calendar-brazil');
var calculator = require('business-days-calculator');
calculator.SetCalendar(calendar);
var data = calculator.IsHoliday(new Date("1 January 2020"));
\\data equals to true
Verifies which locale/calendar the library is set to use.
return: String. Locale identificator.
var calendar = require('holidays-calendar-brazil');
var calculator = require('business-days-calculator');
calculator.SetCalendar(calendar);
var data = calculator.Locale();
\\data equals to 'brazil'
Retrieves the next holiday after date.
date: date, required. Date reference (date won't be considered as a candidate).
return: Mixed. date if there's a holiday in the calendar anywhere after date; false, otherwise.
var calendar = require('holidays-calendar-brazil');
var calculator = require('business-days-calculator');
calculator.SetCalendar(calendar);
var data = calculator.NextHoliday(new Date("1 January 2020"));
\\data equals to 'Mon Feb 24 2020' (which is Carnival)
Retrieves the next business/working day after date.
date: date, required. Date reference (date won't be considered as a candidate).
considerHolidays: boolean, optional (default: true). Whether the holiday calendar should be used in the filter. If negative, this method will output the first week day after date;
return: date. Next business/working day.
var calendar = require('holidays-calendar-brazil');
var calculator = require('business-days-calculator');
calculator.SetCalendar(calendar);
var data = calculator.NextHoliday(new Date("1 January 2020"));
\\data equals to 'Mon Feb 24 2020' (which is Carnival)
Configures the library to use calendar as a reference for holidays.
calendar: Mixed, required. object, as an extension of 'holidays-calendar' library (useful in Node.js environment only); String representing the locale to be used.
var brazilianCalendar = require('holidays-calendar-brazil');
var calendar = require('holidays-calendar');
var calculator = require('business-days-calculator');
calculator.SetCalendar(brazilianCalendar);
var data = calculator.Locale();
\\data equals to 'brazil'
calendar.AddCalendar('generic',{}); // adds a new calendar, although empty
calculator.SetCalendar(calendar);
data = calculator.Locale();
\\data equals to 'generic'
calendar.AddCalendar('generic2',{}); // adds a new calendar, although empty
calculator.SetCalendar('generic2');
data = calculator.Locale();
\\data equals to 'generic2'
Counts the number of business days between date1 and date2
date1: date, required. Starting date.
date2: date, required. Ending date.
discountHolidays: boolean, optional (default: true). Whether the library should consider holidays in the counting.
return: integer. Number of business days according to the calendar in use.
var calendar = require('holidays-calendar-brazil');
var calculator = require('business-days-calculator');
calculator.SetCalendar(calendar);
var data = calculator.WorkingDaysBetween(new Date("1 January 2020"), new Date("31 December 2020"));
\\data equals to 250
data = calculator.WorkingDaysBetween(new Date("1 January 2020"), new Date("31 December 2020"), false);
\\data equals to 262
FAQs
Library for calculating the number of working days (business days) between two dates (considering a Holiday Calendar given).
The npm package business-days-calculator receives a total of 9 weekly downloads. As such, business-days-calculator popularity was classified as not popular.
We found that business-days-calculator demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.