Security News
RubyGems.org Adds New Maintainer Role
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
moment-holiday
Advanced tools
A Moment.js plugin for handling holidays.
npm install --save moment-holiday
var moment = require('moment-holiday');
moment().holiday('Christmas');
<script src="moment.js"></script>
<script src="moment-holiday.js"></script>
<script>
moment().isHoliday();
</script>
bower install --save moment-holiday
or holidays
Searches for holiday(s) by keywords. Returns a single moment object, an object containing moment objects with the holiday names as keys, or false
if no holidays were found.
moment().holiday(holidays, adjust);
//or
moment().holidays(holidays, adjust);
moment().holiday('Memorial Day');
//moment("2017-05-29T00:00:00.000")
moment().holiday('Totally not a holiday');
//false
moment().holiday(['Dad Day']);
//{ 'Father\'s Day': moment("2017-06-18T00:00:00.000") }
moment().holidays(['Turkey Day', 'New Years Eve']);
//{ 'Thanksgiving Day': moment("2017-11-23T00:00:00.000"),
// 'New Year\'s Eve': moment("2017-12-31T00:00:00.000") }
moment().holidays(['Not actually a holiday', 'Mothers Day']);
//{ 'Mother\'s Day': moment("2017-05-14T00:00:00.000") }
moment('2018-01-01').holiday('Veterans Day');
//moment("2018-11-11T00:00:00.000")
moment('2018-01-01').holiday('Veterans Day', true);
//moment("2018-11-12T00:00:00.000")
moment().holidays();
//Returns all holidays
Returns the name of the holiday (or true
if holidays
parameter is used) if the given date is in fact a holiday or false
if it isn't.
moment().isHoliday(holidays, adjust);
true
if there is a match. Can be a string to compare with a single holiday or an array for multiple. Defaults to all holidays.moment('2017-12-25').isHoliday();
//Christmas Day
moment('2005-03-15').isHoliday();
//false
moment('2009-10-31').isHoliday('Halloween');
//true
moment('2017-12-31').isHoliday();
//New Year's Eve
moment('2017-12-31').isHoliday(null, true);
//false
or previousHolidays
Returns an array (or a moment object if count
is set to 1
) containing the previous holidays before the given date.
moment().previousHoliday(count, adjust);
//or
moment().previousHolidays(count, adjust);
1
.moment().previousHoliday();
//moment("2017-07-04T00:00:00.000")
moment('2001-02-14').previousHolidays(5);
//[ moment("2001-01-15T00:00:00.000"),
// moment("2001-01-01T00:00:00.000"),
// moment("2000-12-31T00:00:00.000"),
// moment("2000-12-25T00:00:00.000"),
// moment("2000-12-24T00:00:00.000") ]
moment('2001-02-14').previousHolidays(5, true);
//[ moment("2001-01-15T00:00:00.000"),
// moment("2001-01-01T00:00:00.000"),
// moment("2000-12-25T00:00:00.000"),
// moment("2000-11-24T00:00:00.000"),
// moment("2000-11-23T00:00:00.000") ]
or nextHolidays
Returns an array (or a moment object if count
is set to 1
) containing the next holidays after the given date.
moment().nextHoliday(count, adjust);
//or
moment().nextHolidays(count, adjust);
1
.moment().nextHoliday();
//moment("2017-09-04T00:00:00.000")
moment('2010-05-23').nextHolidays(5);
//[ moment("2010-05-31T00:00:00.000"),
// moment("2010-06-20T00:00:00.000"),
// moment("2010-07-04T00:00:00.000"),
// moment("2010-09-06T00:00:00.000"),
// moment("2010-10-11T00:00:00.000") ]
moment('2010-05-23').nextHolidays(5, true);
//[ moment("2010-05-31T00:00:00.000"),
// moment("2010-06-21T00:00:00.000"),
// moment("2010-07-05T00:00:00.000"),
// moment("2010-09-06T00:00:00.000"),
// moment("2010-10-11T00:00:00.000") ]
Returns an array containing the holidays between the given date and the date
parameter or false
if no dates were found.
moment().holidaysBetween(date, adjust);
moment().holidaysBetween(moment().endOf('year'));
//[ moment("2017-09-04T00:00:00.000"),
// moment("2017-10-09T00:00:00.000"),
// moment("2017-10-31T00:00:00.000"),
// moment("2017-11-11T00:00:00.000"),
// moment("2017-11-23T00:00:00.000"),
// moment("2017-11-24T00:00:00.000"),
// moment("2017-12-24T00:00:00.000"),
// moment("2017-12-25T00:00:00.000") ]
moment('2011-11-01').holidaysBetween('2011-12-31');
//[ moment("2011-11-11T00:00:00.000"),
// moment("2011-11-24T00:00:00.000"),
// moment("2011-11-25T00:00:00.000"),
// moment("2011-12-24T00:00:00.000"),
// moment("2011-12-25T00:00:00.000") ]
moment('2011-11-01').holidaysBetween('2011-12-31', true);
//[ moment("2011-11-11T00:00:00.000"),
// moment("2011-11-24T00:00:00.000"),
// moment("2011-11-25T00:00:00.000"),
// moment("2011-12-23T00:00:00.000"),
// moment("2011-12-26T00:00:00.000"),
// moment("2011-12-30T00:00:00.000") ]
moment('2017-01-01').holidaysBetween();
//[ moment("2017-01-16T00:00:00.000"),
// moment("2017-02-14T00:00:00.000"),
// moment("2017-02-20T00:00:00.000"),
// moment("2017-03-17T00:00:00.000"),
// moment("2017-05-14T00:00:00.000"),
// moment("2017-05-29T00:00:00.000"),
// moment("2017-06-18T00:00:00.000"),
// moment("2017-07-04T00:00:00.000") ]
true
to make all holidays that land on a Saturday go to the prior Friday and all holidays that land on a Sunday go to the following Monday. Defaults to false
.The following holidays are built-in:
You can add and remove holidays by using the following helper functions:
moment().modifyHolidays.set(['New Years Day', 'Memorial Day', 'Thanksgiving']);
moment().holidays(); // Returns all holidays
//{ 'New Year\'s Day': moment("2017-01-01T00:00:00.000"),
// 'Memorial Day': moment("2017-05-29T00:00:00.000"),
// 'Thanksgiving Day': moment("2017-11-23T00:00:00.000") }
moment().modifyHolidays.set({
"My Birthday": {
date: '11/17',
keywords: ['my', 'birthday']
},
"Last Friday of the year": {
date: '12/(5,-1)',
keywords_y: ['friday']
}
});
moment().holidays(); // Returns all holidays
//{ 'My Birthday': moment("2017-11-17T00:00:00.000"),
// 'Last Friday of the year': moment("2017-12-29T00:00:00.000") }
moment().modifyHolidays.add({
"Inauguration Day": {
date: '1/20',
keywords_y: ['inauguration']
}
});
moment().holiday('Inauguration');
//moment("2017-01-20T00:00:00.000")
moment().modifyHolidays.remove('Christmas');
moment().modifyHolidays.remove(['Dad Day', 'Mom Day', 'Saint Paddys Day']);
Holiday objects accept the following options:
date (Required) - The date of the holiday in the format of Month/Day
. A day wrapped in parentheses means a specific day of the week and expects two values separated by a comma. The first part is the day of the week as recognized by moment().day() (0=Sunday, 6=Saturday). The second part is the 1-indexed index of that day of week.
Examples:
5/20
- The 20th of May.7/(1,3)
- The third Monday of July.3/(4,-1)
- The last Thursday of March.keywords - An array of optional keywords.
keywords_y - An array of required keywords.
keywords_n - An array of banned keywords.
View the source of moment-holiday.js for a better look at how the keywords work.
MIT. See the License file for more info.
FAQs
A Moment.js plugin for handling holidays.
We found that moment-holiday 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.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.
Security News
Research
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.