moment-weekdaysin
A Moment.js plugin for getting the weekdays of a month, year, or inbetween two dates.
Requirements
- moment.js v2.1.0 or higher
Installation
Node.js
npm install --save moment-weekdaysin
var moment = ;;
Browser
Bower
bower install --save moment-weekdaysin
Examples
weekdaysInBetween(date, weekdays, index)
// All weekends in the summer of 2010var summerWeekends = ; // Mondays remaining this yearvar remainingMondays = ; // Last Wednesdayvar lastWednesday = ; // Second to last Friday before Christmasvar paydayBeforeChristmas = ;
weekdaysInMonth(weekdays, index)
// Holidays this yearvar memorialDay = ;var laborDay = ;var thanksgivingDay = ; // Wednesdays in May of 1995var mayWednesdays = ;
weekdaysInYear(weekdays, index)
// Last two weekends of the yearvar lastWeekendsOfYear = ; // Thursdays this yearvar thursdaysThisYear = ; // The 10th and 4th to last Sundays and Wednesdays this yearvar complicatedExample = ;
Parameters
- date (
weekdaysInBetween
only) - The end date forweekdaysInBetween
. Can be any ISO date string that moment accepts or a moment object. Defaults to today. - weekdays - The weekdays to fetch. Can be any value that moment().day() accepts or an array of those values. Defaults to all.
- index - The index of the days to fetch. 1-indexed based. Can be a negative number.
1
will get the first instance,-1
will get the last. Can be a single value or an array of values. Defaults to all.
All parameters are optional.
Things To Note
All three functions will:
- Return a sorted array of moment objects if there are multiple found.
- Return a single moment object if there is only one found.
- Return false if none are found.
- Never return duplicate moment objects.
That means something like this may be necessary:
var t = ; if t if tlength // Returned multiple else // Returned one else // Returned none
However if weekdays
and index
parameters are both set to single values, you will never get multiple values returned.
License
MIT. See the License file for more info.