Node.js Project to Build Business or Work Days Calculator in Browser Using HTML5 CSS3 and Javascript

 

 

BusinessDaysCalculator

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.

Instalation

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.

Usage

Node.js

Browser

API Reference

ContinuousDaysBetween(date1, date2)

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.

Example

HolidaysBetween(date1, date2)

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.

Example

IsBusinessDay(date)

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.

Example

IsHoliday(date)

Verifies if date happens to be a holiday.

date: date, required. Date reference.

return: Boolean. Whether date is a holiday or not.

Example

Locale()

Verifies which locale/calendar the library is set to use.

return: String. Locale identificator.

Example

NextHoliday(date)

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 datefalse, otherwise.

Example

NextWorkingDay(date, considerHolidays)

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;

returndate. Next business/working day.

Example

SetCalendar(calendar)

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.

Example

WorkingDaysBetween(date1, date2, discountHolidays)

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.

Example

Leave a Reply