-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathholiday.js
55 lines (42 loc) · 1.45 KB
/
holiday.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
module.exports = function (RED) {
function HolidayNode(config) {
RED.nodes.createNode(this, config);
var node = this;
var Holidays = require('date-holidays')
node.on('input', function (msg) {
var types = [];
if (config.typePublic)
types.push('public');
if (config.typeBank)
types.push('bank');
if (config.typeSchool)
types.push('school');
if (config.typeObservance)
types.push('observance');
if (config.typeOptional)
types.push('optional');
var hd = new Holidays(
config.country,
config.state,
config.region,
{
languages: config.languages,
types: types
});
var holiday = hd.isHoliday(msg.payload);
var dayOfWeek = new Date(msg.payload).getDay().toString();
var isWeekend = config.weekend.split(",").includes(dayOfWeek);
if (!!holiday || isWeekend) {
if (!!holiday)
msg.holiday = holiday;
if (isWeekend)
msg.weekend = true;
node.send([msg, null]);
}
else {
node.send([null, msg]);
}
});
}
RED.nodes.registerType("holiday", HolidayNode);
}