moment-holiday
Advanced tools
Comparing version 1.3.1 to 1.4.0
@@ -9,2 +9,23 @@ # Changelog | ||
## [1.4.0] - 2017-07-24 | ||
### Added | ||
- Ash Wednesday, Lent, Holy Saturday, Easter Monday, Ascension Day, Pentecost Sunday, Whit Monday, and Corpus Christi to Easter locale. | ||
- Valentine's Day, Islander Day, Louis Riel Day, Saint Patrick's Day, Good Friday, Easter Sunday, Aboriginal Day, St. Jean Baptiste Day, Canada Day, Halloween, Remembrance Day, and Thanksgiving Day to Canada locale. | ||
- Finland and Germany locales. | ||
- Specifics parameter to `modifyHolidays.set` and `modifyHolidays.add` functions for cherry-picking specific holidays to use from a locale. | ||
- Support for locale regions. | ||
- `modifyHolidays.undo` function. | ||
- Easter Sunday and Good Friday to actual US locale so that they get added back when using `modifyHolidays.set('US')`. | ||
### Changed | ||
- Fixed bug where using the `modifyHolidays.set` function would modify the original locale object. | ||
- Default parser will now skip a date if it doesn't start with a number or `(` character. | ||
- `isHoliday` function will now return an array of holiday names if not checking for a specific holiday in the case of multiple holidays on the same day. | ||
- Parser will continue to run through all parser extensions even after one has returned false. If the date is still false after all extensions, the parser will return false. | ||
- `test.js` now handles dynamic holiday counts and indexes. | ||
- Changed some keywords into regex keywords for better accuracy. | ||
- Changed active holiday object from `holidayObject` to `moment.holidays.active` to make it public. | ||
- Cleaned up some code. | ||
## [1.3.1] - 2017-07-19 | ||
@@ -56,2 +77,3 @@ ### Changed | ||
[Unreleased]: https://github.com/kodie/moment-holiday/compare/v1.0.0...HEAD | ||
[1.4.0]: https://github.com/kodie/moment-holiday/compare/v1.3.1...v1.4.0 | ||
[1.3.1]: https://github.com/kodie/moment-holiday/compare/v1.3.0...v1.3.1 | ||
@@ -58,0 +80,0 @@ [1.3.0]: https://github.com/kodie/moment-holiday/compare/v1.2.0...v1.3.0 |
//! moment-holiday.js locale configuration | ||
//! locale : Canada | ||
//! author : Kodie Grantham : https://github.com/kodie | ||
/*! regions : | ||
AB : Alberta | ||
BC : British Columbia | ||
MB : Manitoba | ||
NB : New Brunswick | ||
NL : Newfoundland and Labrador | ||
NS : Nova Scotia | ||
NT : Northwest Territories | ||
NU : Nunavut | ||
ON : Ontario | ||
PE : Prince Edward Island | ||
QC : Quebec | ||
SK : Saskatchewan | ||
*/ | ||
@@ -13,8 +27,42 @@ (function() { | ||
keywords_y: ['year'], | ||
keywords_n: ['eve'] | ||
keywords_n: ['eve'], | ||
}, | ||
"Valentine's Day": { | ||
date: '2/14', | ||
keywords_y: ['valentine'], | ||
}, | ||
"Islander Day": { | ||
date: '2/(1,2)', | ||
keywords_y: ['island'], | ||
regions: ['pe'] | ||
}, | ||
"Family Day": { | ||
date: '2/(1,3)', | ||
keywords_y: ['family'] | ||
keywords_y: ['family'], | ||
regions: ['ab', 'bc', 'on', 'sk'] | ||
}, | ||
"Louis Riel Day": { | ||
date: '2/(1,3)', | ||
keywords: ['louis', 'riel'], | ||
regions: ['mb'] | ||
}, | ||
"Saint Patrick's Day": { | ||
date: '3/17', | ||
keywords: ['patrick', 'saint', 'st[\\s\\.]', 'paddy', 'patty'] | ||
}, | ||
"Good Friday": { | ||
date: 'goodfriday', | ||
keywords_y: ['good', 'friday'], | ||
regions_n: ['qc'] | ||
}, | ||
"Easter Sunday": { | ||
date: 'easter', | ||
keywords_y: ['easter'], | ||
keywords: ['sunday'] | ||
}, | ||
"Victoria Day": { | ||
date: '5/(1,[-24])', | ||
keywords_y: ['victoria'], | ||
regions_n: ['nb', 'nl', 'ns'] | ||
}, | ||
"Mother's Day": { | ||
@@ -28,9 +76,20 @@ date: '5/(0,2)', | ||
}, | ||
"Victoria Day": { | ||
date: '5/(1,[-24])', | ||
keywords_y: ['victoria'] | ||
"Aboriginal Day": { | ||
date: '6/21', | ||
keywords_y: ['aboriginal'], | ||
regions: ['nt'] | ||
}, | ||
"Saint Jean Baptiste Day": { | ||
date: '6/24', | ||
keywords: ['st[\\s\\.]', 'saint', 'jean', 'baptiste'], | ||
regions: ['qc'] | ||
}, | ||
"Canada Day": { | ||
date: '7/1', | ||
keyword_y: ['canada'] | ||
}, | ||
"Civic Day": { | ||
date: '8/(1,1)', | ||
keywords_y: ['civic'] | ||
keywords_y: ['civic'], | ||
regions: ['ab', 'bc', 'nb', 'nu', 'on', 'sk'] | ||
}, | ||
@@ -41,5 +100,20 @@ "Labour Day": { | ||
}, | ||
"Halloween": { | ||
date: '10/31', | ||
keywords_y: ['halloween'] | ||
}, | ||
"Remembrance Day": { | ||
date: '11/11', | ||
keywords_y: ['remembrance'], | ||
regions_n: ['mb', 'ns', 'on', 'qc'] | ||
}, | ||
"Thanksgiving Day": { | ||
date: '11/(4,4)', | ||
keywords: ['thanksgiving', 'thanks', 'turkey'], | ||
keywords_n: ['after'], | ||
regions_n: ['nb', 'nl', 'ns'] | ||
}, | ||
"Christmas Day": { | ||
date: '12/25', | ||
keywords: ['christmas', 'christ', 'xmas', 'x-mas'], | ||
keywords: ['christmas', 'christ', 'x-?mas'], | ||
keywords_n: ['eve'] | ||
@@ -49,3 +123,4 @@ }, | ||
date: '12/26', | ||
keywords: ['box', 'boxing'] | ||
keywords: ['box', 'boxing'], | ||
regions: ['on'] | ||
} | ||
@@ -52,0 +127,0 @@ }; |
//! moment-holiday.js locale configuration | ||
//! locale : Easter (Adds Good Friday and Easter Sunday to any moment-holiday locale) | ||
//! locale : Easter Related Holidays | ||
//! author : Kodie Grantham : https://github.com/kodie | ||
@@ -9,2 +9,11 @@ | ||
moment.holidays.easter = { | ||
"Ash Wednesday": { | ||
date: 'ashwednesday', | ||
keywords_y: ['ash'], | ||
keywords: ['wednesday'] | ||
}, | ||
"Lent": { | ||
date: 'lent', | ||
keywords_y: ['lent'] | ||
}, | ||
"Good Friday": { | ||
@@ -14,2 +23,6 @@ date: 'goodfriday', | ||
}, | ||
"Holy Saturday": { | ||
date: 'holysaturday', | ||
keywords_y: ['holy', 'saturday'] | ||
}, | ||
"Easter Sunday": { | ||
@@ -19,2 +32,24 @@ date: 'easter', | ||
keywords: ['sunday'] | ||
}, | ||
"Easter Monday": { | ||
date: 'eastermonday', | ||
keywords_y: ['easter', 'monday'] | ||
}, | ||
"Ascension Day": { | ||
date: 'ascension', | ||
keywords_y: ['ascension'] | ||
}, | ||
"Pentecost Sunday": { | ||
date: 'pentecost', | ||
keywords_y: ['pentecost'], | ||
keywords: ['sunday'] | ||
}, | ||
"Whit Monday": { | ||
date: 'whitmonday', | ||
keywords_y: ['whit'], | ||
keywords: ['monday'] | ||
}, | ||
"Corpus Christi": { | ||
date: 'corpuschristi', | ||
keywords: ['corpus', 'christi', 'feast'] | ||
} | ||
@@ -39,6 +74,37 @@ }; | ||
moment.modifyHolidays.extendParser(function(m, date){ | ||
if (date === 'easter' || date === 'goodfriday') { | ||
if (date === 'ashwednesday' || | ||
date === 'lent' || | ||
date === 'goodfriday' || | ||
date === 'holysaturday' || | ||
date === 'easter' || | ||
date === 'eastermonday' || | ||
date === 'ascension' || | ||
date === 'pentecost' || | ||
date === 'whitmonday' || | ||
date === 'corpuschristi') { | ||
var e = easter(m.year()); | ||
if (date === 'ashwednesday') { return e.subtract(46, 'days'); } | ||
if (date === 'goodfriday') { return e.subtract(2, 'days'); } | ||
if (date === 'holysaturday') { return e.subtract(1, 'day'); } | ||
if (date === 'easter') { return e; } | ||
if (date === 'goodfriday') { return e.subtract(2, 'days'); } | ||
if (date === 'eastermonday') { return e.add(1, 'day'); } | ||
if (date === 'ascension') { return e.add(39, 'days'); } | ||
if (date === 'pentecost') { return e.add(49, 'days'); } | ||
if (date === 'whitmonday') { return e.add(50, 'days'); } | ||
if (date === 'corpuschristi') { return e.add(60, 'days'); } | ||
if (date === 'lent') { | ||
var lent = []; | ||
var d = moment(e).subtract(46, 'days'); | ||
var length = e.subtract(2, 'days').diff(d, 'days'); | ||
for (i = 0; i < length; i++) { | ||
lent.push(moment(d)); | ||
d.add(1, 'day'); | ||
} | ||
return lent; | ||
} | ||
} | ||
@@ -45,0 +111,0 @@ }); |
//! moment-holiday.js | ||
//! version : 1.3.1 | ||
//! version : 1.4.0 | ||
//! author : Kodie Grantham | ||
@@ -10,5 +10,5 @@ //! license : MIT | ||
var holidayObject = {}; | ||
moment.holidays = {}; | ||
moment.holidays.active = {}; | ||
moment.holidays.active_last = {}; | ||
@@ -24,3 +24,3 @@ moment.holidays.us = { | ||
date: '1/(1,3)', | ||
keywords: ['martin', 'luther', 'king', 'jr', 'mlk'] | ||
keywords: ['martin', 'luther', 'king', 'jr[\\s\\.]', 'mlk'] | ||
}, | ||
@@ -37,4 +37,13 @@ "Valentine's Day": { | ||
date: '3/17', | ||
keywords: ['patrick', 'saint', 'paddy', 'patty'] | ||
keywords: ['patrick', 'saint', 'st[\\s\\.]', 'paddy', 'patty'] | ||
}, | ||
"Good Friday": { | ||
date: 'goodfriday', | ||
keywords_y: ['good', 'friday'] | ||
}, | ||
"Easter Sunday": { | ||
date: 'easter', | ||
keywords_y: ['easter'], | ||
keywords: ['sunday'] | ||
}, | ||
"Memorial Day": { | ||
@@ -84,3 +93,3 @@ date: '5/(1,-1)', | ||
date: '12/24', | ||
keywords: ['christmas', 'christ', 'xmas', 'x-mas'], | ||
keywords: ['christmas', 'christ', 'x-?mas'], | ||
keywords_y: ['eve'] | ||
@@ -90,3 +99,3 @@ }, | ||
date: '12/25', | ||
keywords: ['christmas', 'christ', 'xmas', 'x-mas'], | ||
keywords: ['christmas', 'christ', 'x-?mas'], | ||
keywords_n: ['eve'] | ||
@@ -108,7 +117,8 @@ }, | ||
var pe = parserExtensions[i](self, date); | ||
if (pe === false) { return false; } | ||
if (pe) { days = pe; } | ||
if (pe || pe === false) { days = pe; } | ||
} | ||
if (!moment.isMoment(days) && !days.length) { | ||
if (days === false) { return false; } | ||
if (!moment.isMoment(days) && !days.length && date.charAt(0).match(/[0-9(]/)) { | ||
var range = false; | ||
@@ -222,4 +232,15 @@ var dates = date.split('|'); | ||
var findHoliday = function(self, holiday, adjust, parse) { | ||
var h = holidayObject; | ||
var keywordMatches = function(str, kw) { | ||
var m = []; | ||
kw = arrayify(kw); | ||
for (var i = 0; i < kw.length; i++) { | ||
var f = str.match(new RegExp(kw[i], 'gi')); | ||
if (f) { m = m.concat(f); } | ||
} | ||
return m; | ||
}; | ||
var findHoliday = function(self, holiday, adjust, parse, holidayObj) { | ||
var pt = {}; | ||
@@ -229,2 +250,4 @@ var wn = []; | ||
h = holidayObj || moment.holidays.active; | ||
for (var hd in h) { | ||
@@ -235,9 +258,12 @@ if (!h.hasOwnProperty(hd)) { continue; } | ||
if (h[hd].keywords_n && new RegExp(h[hd].keywords_n.join('|'), 'gi').test(holiday)) { | ||
pt[hd] = 0; | ||
continue; | ||
if (h[hd].keywords_n) { | ||
var matchesN = keywordMatches(holiday, h[hd].keywords_n); | ||
if (matchesN.length) { | ||
pt[hd] = 0; | ||
continue; | ||
} | ||
} | ||
if (h[hd].keywords_y) { | ||
var matchesY = holiday.match(new RegExp(h[hd].keywords_y.join('|'), 'gi')); | ||
var matchesY = keywordMatches(holiday, h[hd].keywords_y); | ||
if (matchesY && matchesY.length === h[hd].keywords_y.length) { | ||
@@ -252,3 +278,3 @@ pt[hd] += matchesY.length; | ||
if (h[hd].keywords) { | ||
var matches = holiday.match(new RegExp(h[hd].keywords.join('|'), 'gi')); | ||
var matches = keywordMatches(holiday, h[hd].keywords); | ||
if (matches) { | ||
@@ -262,2 +288,4 @@ pt[hd] += matches.length; | ||
//console.log(pt); // Display scores | ||
for (var w in pt) { | ||
@@ -285,4 +313,18 @@ if (!pt[w] || !pt.hasOwnProperty(w)) { continue; } | ||
var findHolidays = function(self, holidays, adjust, parse, holidayObj) { | ||
var h = {}; | ||
holidays = arrayify(holidays); | ||
if (!holidayObj) { holidayObj = moment.holidays.active; } | ||
for (var i = 0; i < holidays.length; i++) { | ||
var find = findHoliday(self, holidays[i], adjust, parse, holidayObj); | ||
if (find) { h[find] = holidayObj[find]; } | ||
} | ||
return h; | ||
}; | ||
var getAllHolidays = function(self, adjust) { | ||
var h = holidayObject; | ||
var h = moment.holidays.active; | ||
var d = {}; | ||
@@ -298,2 +340,54 @@ | ||
var compileRegions = function(locale, regions) { | ||
var h = moment.holidays[locale]; | ||
var o = {}; | ||
if (h) { | ||
for (var i = 0; i < regions.length; i++) { | ||
var r = regions[i].toLowerCase(); | ||
var l = moment.holidays[locale + '/' + r]; | ||
l = {}; | ||
for (var hd in h) { | ||
if (!h.hasOwnProperty(hd)) { continue; } | ||
var y = h[hd].regions || []; | ||
var n = h[hd].regions_n || []; | ||
if (y.length) { y.join().toLowerCase().split(); } | ||
if (n.length) { n.join().toLowerCase().split(); } | ||
if ((!y.length && !n.length) || (y.length && ~y.indexOf(r)) || (n.length && !~n.indexOf(r))) { | ||
l[hd] = h[hd]; | ||
} | ||
} | ||
if (l) { o = merge(o, l); } | ||
} | ||
} | ||
if (!Object.keys(o).length) { return false; } | ||
return o; | ||
}; | ||
var getLocale = function(locale) { | ||
regions = locale.split('/'); | ||
locale = regions[0].toLowerCase(); | ||
regions.shift(); | ||
if (!moment.holidays[locale]) { | ||
try { | ||
require('./locale/' + locale); | ||
} catch(e) { } | ||
} | ||
if (moment.holidays[locale]) { | ||
if (regions.length) { return compileRegions(locale, regions); } | ||
return moment.holidays[locale]; | ||
} | ||
return false; | ||
}; | ||
var holidayLoop = function(self, count, forward, adjust) { | ||
@@ -307,3 +401,3 @@ if (!count) { count = 1; } | ||
for (i = 0; i < count; i++) { | ||
for (var i = 0; i < count; i++) { | ||
var d = moment(l); | ||
@@ -328,2 +422,4 @@ | ||
for (var hd in h) { | ||
if (!h.hasOwnProperty(hd)) { continue; } | ||
var b2 = false; | ||
@@ -359,4 +455,8 @@ var ha = arrayify(h[hd]); | ||
var merge = function(...sources) { | ||
return Object.assign({}, ...sources); | ||
}; | ||
moment.fn.holiday = function(holidays, adjust) { | ||
var h = holidayObject; | ||
var h = moment.holidays.active; | ||
var d = {}; | ||
@@ -372,3 +472,3 @@ var single = false; | ||
for (i = 0; i < holidays.length; i++) { | ||
for (var i = 0; i < holidays.length; i++) { | ||
if (td = findHoliday(this, holidays[i], adjust)) { d = Object.assign({}, d, td); } | ||
@@ -390,3 +490,3 @@ } | ||
moment.fn.isHoliday = function(holidays, adjust) { | ||
var h, returnTitle; | ||
var h, returnTitle, hs = []; | ||
@@ -412,3 +512,3 @@ if (holidays) { | ||
if (returnTitle) { | ||
return hd; | ||
hs.push(hd); | ||
} else { | ||
@@ -421,2 +521,7 @@ return true; | ||
if (hs.length) { | ||
if (hs.length === 1) { return hs[0]; } | ||
return hs; | ||
} | ||
return false; | ||
@@ -450,3 +555,3 @@ }; | ||
for (i = 0; i < date.diff(this, 'days'); i++) { | ||
for (var i = 0; i < date.diff(this, 'days'); i++) { | ||
d.add(1, 'day'); | ||
@@ -483,7 +588,9 @@ | ||
moment.modifyHolidays = { | ||
set: function(holidays) { | ||
set: function(holidays, specifics) { | ||
var newH = {}; | ||
if (holidays.constructor === Array) { | ||
var hs = []; | ||
for (i = 0; i < holidays.length; i++) { | ||
for (var i = 0; i < holidays.length; i++) { | ||
var d = findHoliday(this, holidays[i], null, false); | ||
@@ -493,39 +600,51 @@ if (d) { hs.push(d); } | ||
for (var hd in holidayObject) { | ||
if (!holidayObject.hasOwnProperty(hd)) { continue; } | ||
if (hs.indexOf(hd) === -1) { delete(holidayObject[hd]); } | ||
if (hs.length) { | ||
newH = merge(moment.holidays.active); | ||
for (var hd in newH) { | ||
if (!newH.hasOwnProperty(hd)) { continue; } | ||
if (!~hs.indexOf(hd)) { delete(newH[hd]); } | ||
} | ||
} | ||
} else if (typeof holidays === 'string') { | ||
var locale = holidays.toLowerCase(); | ||
var locale = getLocale(holidays); | ||
if (!moment.holidays[locale]) { | ||
try { | ||
require('./locale/' + locale); | ||
} catch(e) { } | ||
if (locale) { | ||
if (specifics) { | ||
newH = findHolidays(this, specifics, null, false, locale); | ||
} else { | ||
newH = merge(locale); | ||
} | ||
} | ||
if (moment.holidays[locale]) { holidayObject = moment.holidays[locale]; } | ||
} else { | ||
holidayObject = holidays; | ||
newH = holidays; | ||
} | ||
if (Object.keys(newH).length && !Object.is(moment.holidays.active, newH)) { | ||
moment.holidays.active_last = merge(moment.holidays.active); | ||
moment.holidays.active = newH; | ||
} | ||
return this; | ||
}, | ||
add: function(holidays) { | ||
add: function(holidays, specifics) { | ||
if (typeof holidays === 'string') { | ||
var locale = holidays.toLowerCase(); | ||
var locale = getLocale(holidays); | ||
holidays = {}; | ||
if (!moment.holidays[locale]) { | ||
try { | ||
require('./locale/' + locale); | ||
} catch(e) { } | ||
if (locale) { | ||
if (specifics) { | ||
holidays = findHolidays(this, specifics, null, false, locale); | ||
} else { | ||
holidays = locale; | ||
} | ||
} | ||
} | ||
if (moment.holidays[locale]) { holidays = moment.holidays[locale]; } | ||
if (Object.keys(holidays).length) { | ||
moment.holidays.active_last = merge(moment.holidays.active); | ||
moment.holidays.active = merge(moment.holidays.active, holidays); | ||
} | ||
holidayObject = Object.assign({}, holidayObject, holidays); | ||
return this; | ||
@@ -537,10 +656,24 @@ }, | ||
for (i = 0; i < holidays.length; i++) { | ||
var d = findHoliday(this, holidays[i], null, false); | ||
if (d) { delete(holidayObject[d]); } | ||
var find = findHolidays(this, holidays, null, false); | ||
var newH = merge(moment.holidays.active); | ||
if (find) { | ||
for (var hd in find) { delete(newH[hd]); } | ||
} | ||
if (!Object.is(moment.holidays.active, newH)) { | ||
moment.holidays.active_last = merge(moment.holidays.active); | ||
moment.holidays.active = newH; | ||
} | ||
return this; | ||
}, | ||
undo: function() { | ||
var c = merge(moment.holidays.active); | ||
moment.holidays.active = merge(moment.holidays.active_last); | ||
moment.holidays.active_last = c; | ||
return this; | ||
}, | ||
extendParser: function(func) { | ||
@@ -552,5 +685,5 @@ parserExtensions.push(func); | ||
moment.modifyHolidays.set('US').add('Easter'); | ||
moment.modifyHolidays.set('US').add('Easter', ['Easter Sunday', 'Good Friday']); | ||
if ((typeof module !== 'undefined' && module !== null ? module.exports : void 0) != null) { module.exports = moment; } | ||
}).call(this); |
{ | ||
"name": "moment-holiday", | ||
"version": "1.3.1", | ||
"version": "1.4.0", | ||
"description": "A Moment.js plugin for handling holidays.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
126
README.md
@@ -81,3 +81,3 @@ # moment-holiday [![npm version](https://badge.fury.io/js/moment-holiday.svg)](https://badge.fury.io/js/moment-holiday) [![Build Status](https://travis-ci.org/kodie/moment-holiday.svg?branch=master)](https://travis-ci.org/kodie/moment-holiday) | ||
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. | ||
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. Will return an array of holiday names if multiple holidays land on that same day. | ||
@@ -109,2 +109,5 @@ #### Use | ||
//false | ||
moment('2017-04-17').isHoliday(null, true); | ||
//[ 'Easter Sunday', 'Easter Monday' ] | ||
``` | ||
@@ -146,2 +149,5 @@ | ||
// moment("2000-11-23T00:00:00.000") ] | ||
moment().previousHoliday().isHoliday(); | ||
//Independence Day | ||
``` | ||
@@ -183,2 +189,5 @@ | ||
// moment("2010-10-11T00:00:00.000") ] | ||
moment().nextHoliday().isHoliday(); | ||
//Labor Day | ||
``` | ||
@@ -240,25 +249,37 @@ | ||
## The Holidays | ||
The following holidays are built-in: | ||
* New Year's Day | ||
* Martin Luther King Jr. Day | ||
* Valentine's Day | ||
* Washington's Birthday | ||
* Saint Patrick's Day | ||
* Memorial Day | ||
* Mother's Day | ||
* Father's Day | ||
* Independence Day | ||
* Labor Day | ||
* Columbus Day | ||
* Halloween | ||
* Veteran's Day | ||
* Thanksgiving Day | ||
* Day after Thanksgiving | ||
* Christmas Eve | ||
* Christmas Day | ||
* New Year's Eve | ||
### Available Locales/Regions | ||
* [US](moment-holiday.js) (Default/Built-in) | ||
* [Easter](locale/easter.js) (Easter Related Holidays) | ||
* [Canada](locale/canada.js) | ||
* `Canada/AB` - Alberta | ||
* `Canada/BC` - British Columbia | ||
* `Canada/MB` - Manitoba | ||
* `Canada/NB` - New Brunswick | ||
* `Canada/NL` - Newfoundland and Labrador | ||
* `Canada/NS` - Nova Scotia | ||
* `Canada/NT` - Northwest Territories | ||
* `Canada/NU` - Nunavut | ||
* `Canada/ON` - Ontario | ||
* `Canada/PE` - Prince Edward Island | ||
* `Canada/QC` - Quebec | ||
* `Canada/SK` - Saskatchewan | ||
* [Finland](locale/finland.js) | ||
* [Germany](locale/germany.js) | ||
* `Germany/BB` - Brandenburg | ||
* `Germany/BW` - Baden-Württemberg | ||
* `Germany/BY` - Bayern | ||
* `Germany/HE` - Hessen | ||
* `Germany/MV` - Mecklenburg-Vorpommern | ||
* `Germany/NW` - Nordrhein-Westfalen | ||
* `Germany/RP` - Rheinland-Pfalz | ||
* `Germany/SN` - Sachsen | ||
* `Germany/SL` - Saarland | ||
* `Germany/ST` - Sachsen-Anhalt | ||
* `Germany/TH` - Thüringen | ||
Easter Sunday and Good Friday are also automatically included if you are using Node. (You can still easily add them in even when not using Node. See: [Modifying Holidays](#modifying-holidays)) | ||
Rather than listing all of the holidays here, to see available holidays, view the source of the locale file. | ||
Easter related holidays for any locale will only be available if the Easter locale has been added. It's automatically added if you are using Node. (You can still easily add them in even when not using Node. See: [Modifying Holidays](#modifying-holidays)) | ||
### Modifying Holidays | ||
@@ -270,2 +291,4 @@ You can add and remove holidays by using the following helper functions: | ||
#### modifyHolidays.set | ||
Sets the holidays to be used. | ||
```javascript | ||
@@ -296,2 +319,4 @@ moment.modifyHolidays.set(['New Years Day', 'Memorial Day', 'Thanksgiving']); | ||
#### modifyHolidays.add | ||
Adds holiday(s) to the holidays being used. | ||
```javascript | ||
@@ -310,2 +335,4 @@ moment.modifyHolidays.add({ | ||
#### modifyHolidays.remove | ||
Removes holiday(s) from the holidays being used. | ||
```javascript | ||
@@ -317,3 +344,27 @@ moment.modifyHolidays.remove('Christmas'); | ||
#### Adding/Setting Locales | ||
#### modifyHolidays.undo | ||
Sets the holidays being used back to the way they were before they were last changed. | ||
```javascript | ||
moment.modifyHolidays.set(['Christmas', 'Thanksgiving', 'Mothers Day', 'Fathers Day']); | ||
moment().holidays(); | ||
//{ 'Mother\'s Day': moment("2017-05-14T00:00:00.000"), | ||
// 'Father\'s Day': moment("2017-06-18T00:00:00.000"), | ||
// 'Thanksgiving Day': moment("2017-11-23T00:00:00.000"), | ||
// 'Christmas Day': moment("2017-12-25T00:00:00.000") } | ||
moment.modifyHolidays.remove(['Thanksgiving', 'Christmas']); | ||
moment().holidays(); | ||
//{ 'Mother\'s Day': moment("2017-05-14T00:00:00.000"), | ||
// 'Father\'s Day': moment("2017-06-18T00:00:00.000") } | ||
moment.modifyHolidays.undo(); | ||
moment().holidays(); | ||
//{ 'Mother\'s Day': moment("2017-05-14T00:00:00.000"), | ||
// 'Father\'s Day': moment("2017-06-18T00:00:00.000"), | ||
// 'Thanksgiving Day': moment("2017-11-23T00:00:00.000"), | ||
// 'Christmas Day': moment("2017-12-25T00:00:00.000") } | ||
``` | ||
#### Adding/Setting Locales/Regions | ||
You can also use these functions to set or add holidays from an available locale file: | ||
@@ -331,2 +382,28 @@ | ||
You use these same functions to specify regions to add: | ||
```javascript | ||
moment.modifyHolidays.set('Germany/SN'); | ||
moment('2017-11-22').isHoliday(); | ||
//Buß- und Bettag | ||
moment.modifyHolidays.set('Canada/QC/ON'); | ||
moment().holidays(['boxing', 'baptiste']); | ||
//{ 'Boxing Day': moment("2017-12-26T00:00:00.000"), | ||
// 'St. Jean Baptiste Day': moment("2017-06-24T00:00:00.000") } | ||
``` | ||
You can also cherry-pick the holidays you want from a locale by passing a string or an array of strings as the second parameter: | ||
```javascript | ||
moment.modifyHolidays.add('Easter', ['ascension', 'pentecost']); | ||
moment().holiday(['ascension', 'pentecost']); | ||
//{ 'Ascension Day': moment("2017-05-25T00:00:00.000"), | ||
// 'Pentecost Sunday': moment("2017-06-04T00:00:00.000") } | ||
moment.modifyHolidays.add('Germany/BB', 'Ostersonntag'); | ||
moment('2001-09-14').isHoliday(); | ||
//[ 'Easter Sunday', 'Ostersonntag' ] | ||
``` | ||
*Note: If you're not using Node (or anything that doesn't support the `require` function), you'll need to make sure that you include the locale file(s) that you're trying to use. For example:* | ||
@@ -358,2 +435,3 @@ | ||
* `(0)` - Every Sunday of the year. | ||
* `(6,-2)` - The second to last Friday of every month of the year. | ||
* `10/(3)` - Every Wednesday in October. | ||
@@ -368,3 +446,7 @@ * `12/7/2014` - December 7th, 2014. | ||
* **keywords_n** - An array of banned keywords. | ||
* **regions** - An array of region abbreviations that the holiday is celebrated in. Basically a white-list. | ||
* **regions_n** - An array of region abbreviations that the holiday is NOT celebrated in. Basically a black-list. | ||
RegEx can be used in keywords. For example, `st[\\s\\.]` will match `St Jean` and `St. Patrick`, but not `Christmas` and `x-?mas` will match `xmas` and `x-mas`. | ||
View the source of [moment-holiday.js](moment-holiday.js) for a better look at how the keywords work. | ||
@@ -371,0 +453,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
48632
9
911
487
6