-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
37 lines (32 loc) · 941 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
const Holidays = require('date-holidays');
const moment = require('moment');
function addYear(hd, year, min, max) {
return hd.getHolidays(year).filter((day) => {
const d = moment(day.date);
if (day.type === 'public') {
if (d.isSame(min) || d.isSame(max)) {
return true
} else {
return d.isAfter(min, 'day') && d.isBefore(max, 'day');
}
}
})
.map((day) => {
return {
date: day.date,
name: day.name
}
});;
}
exports.holidaysBetween = function(min, max, locale) {
const hd = new Holidays(locale);
let years = [];
let data = [];
for(var i=min.year(); i<=max.year(); i++) {
years.push(i);
}
years.forEach((year) => {
data = data.concat(addYear(hd, year, min, max));
});
return data;
}