node-red-contrib-german-holidays
Advanced tools
Comparing version 0.1.15 to 1.0.0
### CHANGELOG | ||
#### 1.0.0 - maintenance | ||
- #7 Fixed typo - Interface change implied | ||
- set Node-Red 1.0 or above as the required Version | ||
- removed backward compatibility. Node will only used holidays setup before. If a node was not changed since 0.1.0 it will no longer work! Need to open of the node settings in node-Red, Save and deploy is necessary for migration! | ||
#### 0.1.15 - maintenance | ||
@@ -4,0 +10,0 @@ |
@@ -16,23 +16,2 @@ /******************************************** | ||
const allRegions = [ | ||
'BW', | ||
'BY', | ||
'BE', | ||
'BB', | ||
'HB', | ||
'HE', | ||
'HH', | ||
'MV', | ||
'NI', | ||
'NW', | ||
'RP', | ||
'SL', | ||
'SN', | ||
'ST', | ||
'SH', | ||
'TH', | ||
'BUND', | ||
'ALL' | ||
]; | ||
const characteristic = { | ||
@@ -60,128 +39,2 @@ unspecified: 0, | ||
const holidayDef = { | ||
NEUJAHRSTAG: { | ||
name : 'Neujahrstag', // 1.1. | ||
month: 1, | ||
day: 1, | ||
regions: allRegions, | ||
character: characteristic.holiday | ||
}, | ||
HEILIGEDREIKOENIGE: { | ||
name : 'Heilige Drei Könige', // 6.1. | ||
nameAlt: 'Epiphanias', | ||
month: 1, | ||
day: 6, | ||
regions: ['BW', 'BY', 'ST', 'ALL'], | ||
character: characteristic.holiday | ||
}, | ||
KARFREITAG: { | ||
name : 'Karfreitag', | ||
month: easterX, | ||
day: -2, | ||
regions: allRegions, | ||
character: characteristic.holiday | ||
}, | ||
OSTERSONNTAG: { | ||
name : 'Ostersonntag', | ||
month: easterX, | ||
day: 0, | ||
regions: ['BB', 'ALL'], | ||
character: characteristic.holiday | ||
}, | ||
OSTERMONTAG: { | ||
name : 'Ostermontag', | ||
month: easterX, | ||
day: 1, | ||
regions: allRegions, | ||
character: characteristic.holiday | ||
}, | ||
TAG_DER_ARBEIT: { | ||
name : 'Tag der Arbeit', // 1. Mai | ||
nameAlt: 'Maifeiertag', | ||
month: 5, | ||
day: 1, | ||
regions: allRegions, | ||
character: characteristic.holiday | ||
}, | ||
CHRISTIHIMMELFAHRT: { | ||
name : 'Christi Himmelfahrt', | ||
nameAlt: 'Vatertag', | ||
month: easterX, | ||
day: 39, | ||
regions: allRegions, | ||
character: characteristic.holiday | ||
}, | ||
PFINGSTSONNTAG: { | ||
name : 'Pfingstsonntag', | ||
month: easterX, | ||
day: 49, | ||
regions: ['BB', 'ALL'], | ||
character: characteristic.holiday | ||
}, | ||
PFINGSTMONTAG: { | ||
name : 'Pfingstmontag', | ||
month: easterX, | ||
day: 50, | ||
regions: allRegions, | ||
character: characteristic.holiday | ||
}, | ||
FRONLEICHNAM: { | ||
name : 'Fronleichnam', | ||
month: easterX, | ||
day: 60, | ||
regions: ['BW', 'BY', 'HE', 'NW', 'RP', 'SL', 'ALL'], | ||
character: characteristic.holiday | ||
}, | ||
MARIAHIMMELFAHRT: { | ||
name : 'Mariä Himmelfahrt', | ||
month: 8, | ||
day: 15, | ||
regions: ['SL', 'BY', 'ALL'], | ||
character: characteristic.holiday | ||
}, | ||
DEUTSCHEEINHEIT: { | ||
name : 'Tag der Deutschen Einheit', | ||
month: 10, | ||
day: 3, | ||
regions: allRegions, | ||
character: characteristic.holiday | ||
}, | ||
REFORMATIONSTAG: { | ||
name : 'Reformationstag', // 31. Oktober | ||
nameAlt: 'Halloween', | ||
month: 10, | ||
day: 31, | ||
regions: ['BB', 'MV', 'SN', 'ST', 'TH', 'ALL'], | ||
character: characteristic.holiday | ||
}, | ||
ALLERHEILIGEN: { | ||
name : 'Allerheiligen', | ||
month: 11, | ||
day: 1, | ||
regions: ['BW', 'BY', 'NW', 'RP', 'SL', 'ALL'], | ||
character: characteristic.holiday | ||
}, | ||
BUBETAG: { | ||
name : 'Buß- und Bettag', | ||
month: adventX, | ||
day: -32, | ||
regions: ['SN', 'ALL'], | ||
character: characteristic.holiday | ||
}, | ||
ERSTERWEIHNACHTSFEIERTAG: { | ||
name : '1. Weihnachtstag', | ||
month: 12, | ||
day: 25, | ||
regions: allRegions, | ||
character: characteristic.holiday | ||
}, | ||
ZWEITERWEIHNACHTSFEIERTAG: { | ||
name : '2. Weihnachtstag', | ||
month: 12, | ||
day: 26, | ||
regions: allRegions, | ||
character: characteristic.holiday | ||
} | ||
}; | ||
/*******************************************************************************************************/ | ||
@@ -229,2 +82,7 @@ /** | ||
/** | ||
* check if default value could be used | ||
* @param {*} node The Node object | ||
* @param {*} ts the timestamp | ||
*/ | ||
function _checkDefault(node, ts) { | ||
@@ -235,3 +93,3 @@ const newYear = (new Date()).getUTCFullYear(); | ||
node.default.year = newYear; | ||
node.default.dayObjs = _getSpecialDaysOfYear(node, node.default.year, undefined, true, true); | ||
node.default.dayObjs = _getSpecialDaysOfYear(node, node.default.year, true, true); | ||
} | ||
@@ -249,3 +107,3 @@ } | ||
} | ||
const pos = arr.findIndex( (x) => { | ||
const pos = arr.findIndex( x => { | ||
return (el.day === x.day) && (el.month === x.month) && (el.year === x.year); | ||
@@ -260,23 +118,5 @@ }); | ||
/** | ||
* added default holidays for a region | ||
* @param {Array} arrayToAdd array to add | ||
* @param {String} region region for adding | ||
*/ | ||
function _addToArrayForRegion(arrayToAdd, region) { | ||
if (region && region !== '') { | ||
Object.keys(holidayDef).forEach((key) => { | ||
const d = holidayDef[key]; | ||
if (d.regions.includes(region)) { | ||
d.id = key; | ||
arrayToAdd.push(d); | ||
} | ||
}); | ||
} | ||
} | ||
/** | ||
* creates all data of special and holidays of a year | ||
* @param {*} node - the node object for debuging | ||
* @param {Number} year - the year for calculation of the special days | ||
* @param {String} [region] - force to recalculate, otherwise load existing data | ||
* @param {Boolean} [force] - force to recalculate, otherwise load existing data | ||
@@ -287,6 +127,6 @@ * @param {Boolean} [calcNext] - calculate the holiday also for the next year | ||
*/ | ||
function _getSpecialDaysOfYear(node, year, region, force, calcNext) { | ||
node.debug(`_getSpecialDaysOfYear year=${year}, region=${region}, force=${force}, calcNext=${calcNext}`); | ||
function _getSpecialDaysOfYear(node, year, force, calcNext) { | ||
node.debug(`_getSpecialDaysOfYear year=${year}, force=${force}, calcNext=${calcNext}`); | ||
if (node.default.dayObjs && (node.default.year === year) && (force !== true) && !region) { | ||
if (node.default.dayObjs && (node.default.year === year) && (force !== true)) { | ||
// node.debug('return default obj'); | ||
@@ -299,6 +139,4 @@ return node.default.dayObjs; | ||
const holidayObjects = []; | ||
const specialdaysObjects = []; | ||
_addToArrayForRegion(holidayObjects, region); | ||
_addDaysToArray(node.holidaysArray, holidayObjects, year, easter, advent4th, node.characters); | ||
@@ -478,2 +316,8 @@ _addDaysToArray(node.specialdaysArray, specialdaysObjects, year, easter, advent4th, node.characters); | ||
/** | ||
* get the name of an array | ||
* @param {*} character character to test if set | ||
* @param {*} arr array to check | ||
* @returns {Array} | ||
*/ | ||
function _getCharacterNames(character, arr) { | ||
@@ -540,2 +384,6 @@ const result = []; | ||
/** | ||
* converts a Date to a timestamp Object | ||
* @param {Date} date Date to convert | ||
*/ | ||
function _toTimestamp(date) { | ||
@@ -548,2 +396,7 @@ const d = new Date(date); | ||
module.exports = function (RED) { | ||
'use strict'; | ||
/** | ||
* genearla node function | ||
* @param {*} config Node-Red config for the Node | ||
*/ | ||
function germanHolidaysNode(config) { | ||
@@ -557,10 +410,4 @@ RED.nodes.createNode(this, config); | ||
// this.debug(JSON.stringify(config, Object.getOwnPropertyNames(config))); | ||
if (config.region && config.region !== '' && config.region !== null && typeof config.region !== 'undefined') { | ||
_addToArrayForRegion(this.holidaysArray, config.region); | ||
delete config.region; | ||
} | ||
this.characters = []; | ||
Object.keys(characteristic).forEach((key) => { | ||
Object.keys(characteristic).forEach(key => { | ||
const id = characteristic[key]; | ||
@@ -663,3 +510,3 @@ this.characters.push({ | ||
// var creds = RED.nodes.getNode(config.creds); - not used | ||
const attrs = ['region', 'day', 'date', 'ts', 'year']; | ||
const attrs = ['day', 'date', 'ts', 'year']; | ||
@@ -733,18 +580,2 @@ const outMsg = RED.util.cloneMessage(msg); | ||
if (typeof outMsg.data.region !== 'undefined' && outMsg.data.region !== '' && outMsg.data.region !== null) { | ||
outMsg.data.region = outMsg.data.region.toUpperCase(); | ||
if (allRegions.indexOf(outMsg.data.region) === -1) { | ||
// this.error('Invalid region: ' + outMsg.data.region + '! Must be one of ' + allRegions.toString()); | ||
this.status({ | ||
fill: 'red', | ||
shape: 'dot', | ||
text: 'Invalid Region given!' | ||
}); | ||
done('Invalid region: ' + outMsg.data.region + '! Must be one of ' + allRegions.toString() ,msg); | ||
return; | ||
} | ||
} else { | ||
delete outMsg.data.region; | ||
} | ||
if ((typeof outMsg.data.date !== 'undefined') && ((outMsg.data.date instanceof Date) || (typeof outMsg.data.date === 'string'))) { | ||
@@ -755,3 +586,3 @@ const dto = new Date(outMsg.data.date); | ||
outMsg.data.year = dto.getUTCFullYear(); | ||
const specialdays = _getSpecialDaysOfYear(this, outMsg.data.year, outMsg.data.region); | ||
const specialdays = _getSpecialDaysOfYear(this, outMsg.data.year); | ||
outMsg.payload = this.getDataForDate(dto, specialdays); | ||
@@ -773,3 +604,3 @@ this.status({ | ||
outMsg.data.year = outMsg.data.ts.getUTCFullYear(); | ||
const dataObjs = _getSpecialDaysOfYear(this, outMsg.data.year, outMsg.data.region); | ||
const dataObjs = _getSpecialDaysOfYear(this, outMsg.data.year); | ||
@@ -787,3 +618,3 @@ outMsg.payload = this.getDataForDay(outMsg.data.ts, outMsg.data.day, dataObjs); | ||
const dayObjs = _getSpecialDaysOfYear(this, outMsg.data.year, outMsg.data.region); | ||
const dayObjs = _getSpecialDaysOfYear(this, outMsg.data.year); | ||
@@ -797,7 +628,7 @@ outMsg.payload = { | ||
afterTheDayAfterTomorrow: {}, | ||
hollidays: dayObjs.holidays, | ||
holidays: dayObjs.holidays, | ||
specialdays: dayObjs.specialdays, | ||
next: { | ||
hollidays : [], | ||
hollidaysDiff : [], | ||
holidays : [], | ||
holidaysDiff : [], | ||
specialdays: [], | ||
@@ -836,4 +667,4 @@ specialdaysDiff: [] | ||
for (let i = 0; i < outMsg.payload.hollidays.length; i++) { | ||
const hd = outMsg.payload.hollidays[i]; | ||
for (let i = 0; i < outMsg.payload.holidays.length; i++) { | ||
const hd = outMsg.payload.holidays[i]; | ||
const d = hd.date; | ||
@@ -845,4 +676,4 @@ | ||
hd.diffDays = Math.ceil(hd.diff / (1000 * 3600 * 24)); | ||
outMsg.payload.next.hollidays.push(hd); | ||
if (outMsg.payload.next.hollidays.length > 9) { | ||
outMsg.payload.next.holidays.push(hd); | ||
if (outMsg.payload.next.holidays.length > 9) { | ||
break; | ||
@@ -852,5 +683,5 @@ } | ||
} | ||
if (outMsg.payload.next.hollidays[0]) { | ||
outMsg.payload.next.holliday = outMsg.payload.next.hollidays[0]; | ||
outMsg.payload.next.hollidayDiff = outMsg.payload.next.hollidays[0].diffDays; | ||
if (outMsg.payload.next.holidays[0]) { | ||
outMsg.payload.next.holiday = outMsg.payload.next.holidays[0]; | ||
outMsg.payload.next.holidayDiff = outMsg.payload.next.holidays[0].diffDays; | ||
} | ||
@@ -894,5 +725,5 @@ | ||
outMsg.payload.next.weekendOrHolidayDiff = (outMsg.payload.next.hollidayDiff) ? Math.min(outMsg.payload.next.hollidayDiff, outMsg.payload.next.weekendDayDiff) : outMsg.payload.next.weekendDayDiff; | ||
if (outMsg.payload.next.holliday && (outMsg.payload.next.weekendOrHolidayDiff === outMsg.payload.next.hollidayDiff)) { | ||
outMsg.payload.next.weekendOrHoliday = outMsg.payload.next.holliday; | ||
outMsg.payload.next.weekendOrHolidayDiff = (outMsg.payload.next.holidayDiff) ? Math.min(outMsg.payload.next.holidayDiff, outMsg.payload.next.weekendDayDiff) : outMsg.payload.next.weekendDayDiff; | ||
if (outMsg.payload.next.holiday && (outMsg.payload.next.weekendOrHolidayDiff === outMsg.payload.next.holidayDiff)) { | ||
outMsg.payload.next.weekendOrHoliday = outMsg.payload.next.holiday; | ||
} else { | ||
@@ -899,0 +730,0 @@ outMsg.payload.next.weekendOrHoliday = outMsg.payload.next.weekendDay; |
{ | ||
"name": "node-red-contrib-german-holidays", | ||
"version": "0.1.15", | ||
"description": "NodeRED nodes to get german holidays", | ||
"version": "1.0.0", | ||
"description": "NodeRED nodes to get holidays or special days (not even german holidays)", | ||
"keywords": [ | ||
@@ -53,3 +53,3 @@ "node-red", | ||
"node-red": { | ||
"version": ">=0.19.0", | ||
"version": ">=1.0.0", | ||
"nodes": { | ||
@@ -63,4 +63,4 @@ "german-holidays": "german-holidays.js" | ||
"eslint-plugin-html": "^6.0.0", | ||
"eslint-plugin-jsdoc": "^21.0.0", | ||
"eslint-plugin-json": "^2.1.0", | ||
"eslint-plugin-jsdoc": "^22.1.0", | ||
"eslint-plugin-json": "^2.1.1", | ||
"eslint-plugin-node": "^11.0.0" | ||
@@ -132,2 +132,12 @@ }, | ||
"prefer-arrow-callback": "error", | ||
"no-confusing-arrow": [ | ||
"error", | ||
{ | ||
"allowParens": true | ||
} | ||
], | ||
"arrow-parens": [ | ||
"error", | ||
"as-needed" | ||
], | ||
"no-console": "warn", | ||
@@ -152,3 +162,19 @@ "no-unused-vars": [ | ||
"no-var": "error", | ||
"object-shorthand": [ | ||
"error", | ||
"always" | ||
], | ||
"prefer-const": "error", | ||
"prefer-rest-params": "error", | ||
"no-useless-concat": "error", | ||
"no-template-curly-in-string": "error", | ||
"require-jsdoc": "warn", | ||
"rest-spread-spacing": [ | ||
"error", | ||
"never" | ||
], | ||
"symbol-description": "error", | ||
"array-callback-return": "error", | ||
"consistent-return": "error", | ||
"no-lone-blocks": "error", | ||
"linebreak-style": [ | ||
@@ -155,0 +181,0 @@ "warn", |
@@ -17,2 +17,8 @@ # node-red-contrib-german-holidays for NodeRED | ||
> :warning: **Warning! Version 1.0 breaks to existing!** :warning: | ||
> | ||
> - Requires Node-Red 1.0 or later! | ||
> - Changed payload (holiday* instead of holliday*)! | ||
> - Not configured Holidays will not be used (no backwards compatibility). Existing nodes needs to be opened, saved and deployed once! | ||
## Installation | ||
@@ -109,5 +115,5 @@ | ||
- `msg.payload.next` _object_ object representing information about the next holiday. | ||
- `msg.payload.next.holliday` _enh-day-object_ object representing the next holiday. | ||
- `msg.payload.next.hollidays` _array_ array of the next 10 holiday (`msg.payload.next.hollidays.0` is equal to `msg.payload.next.holliday`), every _enh-day-object_ has additional a `diffDays` property which is the count of days until this holiday and a `diff` which represents the difference in milliseconds. | ||
- `msg.payload.next.hollidayDiff` _number_ count of days until next holiday. | ||
- `msg.payload.next.holiday` _enh-day-object_ object representing the next holiday. | ||
- `msg.payload.next.holidays` _array_ array of the next 10 holiday (`msg.payload.next.holidays.0` is equal to `msg.payload.next.holiday`), every _enh-day-object_ has additional a `diffDays` property which is the count of days until this holiday and a `diff` which represents the difference in milliseconds. | ||
- `msg.payload.next.holidayDiff` _number_ count of days until next holiday. | ||
- `msg.payload.next.specialday` _enh-day-object_ object representing the next special day. | ||
@@ -119,5 +125,5 @@ - `msg.payload.next.specialdays` _array_ array of the next 10 special days (`msg.payload.next.specialdays.0` is equal to `msg.payload.next.specialday`), every _enh-day-object_ has additional a `diffDays` property which is the count of days until this holiday and a `diff` which represents the difference in milliseconds. | ||
- `msg.payload.next.weekendOrHolidayDiff` _number_ count of days until next holiday or Saturday or Sunday (next free day). | ||
- `msg.payload.hollidays` _enh-day-object_ An array of objects for every Holiday in the year. | ||
- `msg.payload.hollidays` _array_ An array of objects for every Holiday in the year. | ||
- `msg.payload.hollidaysNum` _array_ An array of numbers for every Holiday in the year. | ||
- `msg.payload.holidays` _enh-day-object_ An array of objects for every Holiday in the year. | ||
- `msg.payload.holidays` _array_ An array of objects for every Holiday in the year. | ||
- `msg.payload.holidaysNum` _array_ An array of numbers for every Holiday in the year. | ||
- `msg.payload.weekNumber` _number_ weekNumber for today. | ||
@@ -157,6 +163,4 @@ - `msg.payload.weekNumberEven` _boolean_ Is `true` if the weekNumber is even. | ||
[![Greenkeeper badge](https://badges.greenkeeper.io/Hypnos3/node-red-contrib-german-holidays.svg)](https://greenkeeper.io/) | ||
this node is published also here: | ||
- [NPM package](https://www.npmjs.com/package/node-red-contrib-german-holidays) | ||
- [Node-Red](https://flows.nodered.org/node/node-red-contrib-german-holidays) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
0
163
294002
959