Giter Club home page Giter Club logo

moment-weekdaysin's Introduction

moment-weekdaysin npm version Build Status

A Moment.js plugin for getting the weekdays of a month, year, or inbetween two dates.

NO LONGER MAINTAINED (DEPRECATED)

Since Moment.js is being deprecated, it only makes sense to deprecate this project as well. Feel free to fork and use this code in any way you wish however I will no longer be maintaining it.

Requirements

Installation

Node.js

npm install --save moment-weekdaysin
var moment = require('moment-weekdaysin');
moment().weekdaysInMonth('Monday');

Browser

<script src="moment.js"></script>
<script src="moment-weekdaysin.js"></script>
<script>
  moment().weekdaysInYear('Friday');
</script>

Bower

bower install --save moment-weekdaysin

Examples

weekdaysInBetween(date, weekdays, index)

// All weekends in the summer of 2010
var summerWeekends = moment('2010-06-20').weekdaysInBetween('2010-09-23', [0, 5, 6]);

// Mondays remaining this year
var remainingMondays = moment().weekdaysInBetween(moment().endOf('year'), 'Monday');

// Last Wednesday
var lastWednesday = moment().dayOfYear(1).weekdaysInBetween(null, 3, -1);

// Second to last Friday before Christmas
var paydayBeforeChristmas = moment().weekdaysInBetween(moment().month('December').date(25), 'Friday', -2);

weekdaysInMonth(weekdays, index)

// Holidays this year
var memorialDay = moment().month('May').weekdaysInMonth('Monday', -1);
var laborDay = moment().month('September').weekdaysInMonth('Monday', 1);
var thanksgivingDay = moment().month('November').weekdaysInMonth('Thursday', 4);

// Wednesdays in May of 1995
var mayWednesdays = moment('1999-05-01').weekdaysInMonth(3);

weekdaysInYear(weekdays, index)

// Last two weekends of the year
var lastWeekendsOfYear = moment().weekdaysInYear([0, 5, 6], [-1, -2]);

// Thursdays this year
var thursdaysThisYear = moment().weekdaysInYear('Thursday');

// The 10th and 4th to last Sundays and Wednesdays this year
var complicatedExample = moment().weekdaysInYear(['Sunday', 3], [10, -4]);

Parameters

  • date (weekdaysInBetween only) - The end date for weekdaysInBetween. 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 = moment().weekdaysInBetween(moment().endOf('year'), 'Monday');

if (t) {
  if (t.length) {
    // 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.

moment-weekdaysin's People

Contributors

kodie avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.