1.0.9 • Published 5 years ago

this-month v1.0.9

Weekly downloads
24
License
MIT
Repository
github
Last release
5 years ago

ThisMonth

Version Downloads License

How many natural days does April has? How many business days does February has? How many Holidays are there in December? How many Weeks does June has? How many Sundays in September?

ThisMonth can help you with this details!

ThisMonth is an small utility class that provides useful methods to get calculations and details of an specific month.

Installation

npm install this-month --save or yarn add this-month

Usage

const ThisMonth = require('this-month').default;

// ES6

import ThisMonth from 'this-month';
const february = new ThisMonth({
    year: 2017,
    month: 2
})

const totalDays = february.numberOfNaturalDays(); // 28
const totalBusinessDays = february.numberOfBusinessDays(); // 19 (Using default days off - Sat, Sun)

Initial settings

OptionTypeDescriptionRequired
yearintYear of the monthyes
monthintMonth of the yearyes
daysOffarrayNames of weekly days offNo
holidaysarrayHoliday dates in the yearNo

Example

const december = ThisMonth({
    year: 2017,
    month: 12,
    daysOff: ['Monday'], // working days Tuesday - Sunday,
    holidays: ['2017-12-25', '2017-12-31'] // you can also list all the holiday dates of the year
})
december.numberOfNaturalDays(); // 31
december.numberOfBusinessDays(); // 26 (4 Mondays are off and 2 holidays, but the 25th is Monday so it's already off day)

Methods

MethodDescription
weeklyDaysOffReturns string of day numbers.
numberOfWeeksReturns number of weeks in the month
numberOfNaturalDaysReturns number of days in the month
numberOfDaysOffReturns number of days in the month
numberOfHolidaysReturns number of days in the month
numberOfBusinessDaysReturns number of days in the month
numberOfSundaysReturns number of days in the month
numberOfMondaysReturns number of days in the month
numberOfTuesdaysReturns number of days in the month
numberOfWednesdaysReturns number of days in the month
numberOfThursdaysReturns number of days in the month
numberOfFridaysReturns number of days in the month
numberOfSaturdaysReturns number of days in the month