Socket
Socket
Sign inDemoInstall

node-red-contrib-sun-position

Package Overview
Dependencies
Maintainers
1
Versions
136
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-red-contrib-sun-position - npm Package Compare versions

Comparing version 0.2.0-alpha.3 to 0.2.0-alpha.4

nodes/test/flow-test2.json

281

nodes/lib/dateTimeHelper.js

@@ -463,3 +463,3 @@ /********************************************

*/
function getDateOfText(dt) {
function getDateOfText(dt, preferMonthFirst) {
console.log('getDateOfText dt=' + util.inspect(dt)); // eslint-disable-line

@@ -516,10 +516,10 @@ if (dt === null || typeof dt === 'undefined') {

if (typeof dt === 'string') {
let res = parseDateTime(dt, true);
if (res === null) {
res = parseDate(dt, true);
}
if (res === null) {
res = _parseArray(dt, dateFormat.parseTimes);
}
return res;
let res = parseDateTime(dt, preferMonthFirst);
if (res !== null) { return res; }
res = parseDate(dt, preferMonthFirst);
if (res !== null) { return res; }
res = _parseArray(dt, dateFormat.parseTimes);
if (res !== null) { return res; }
res = Date.parse(dt);
if (!isNaN(res)) { return res; }
}

@@ -599,3 +599,3 @@ throw new Error('could not evaluate ' + String(dt) + ' as a valid Date or time.');

const s = date[_ + 'Seconds']();
const L = date[_ + 'Milliseconds']();
const l = date[_ + 'Milliseconds']();
const o = utc ? 0 : date.getTimezoneOffset();

@@ -629,6 +629,8 @@

ss: pad(s),
lll: pad(L, 3),
ll: pad(Math.round(L / 10)),
l: L,
L: pad(L > 99 ? Math.round(L / 10) : L),
l,
ll: pad(l),
lll: pad(l, 3),
L: Math.round(l / 100),
LL: pad(Math.round(l / 10)),
LLL: pad(l, 3),
t: H < 12 ? 'a' : 'p',

@@ -651,82 +653,2 @@ tt: H < 12 ? 'am' : 'pm',

dateFormat.timeSpan = (function () {
const token = /t?[dhHkKms]{1,2}|t?l{1,3}|[tT]{1,2}|S|L|"[^"]*"|'[^']*'/g;
const pad = function (val, len) {
val = String(val);
len = len || 2;
while (val.length < len) {
val = '0' + val;
}
return val;
};
return function (timespan, mask) {
const perSecond = 1000;
const perMinute = 60000;
const perHour = 3600000;
const perDay = 86400000;
const tl = timespan;
const ts = timespan / perSecond;
const tm = timespan / perMinute;
const tH = timespan / perHour;
const td = timespan / perDay;
const L = timespan % 1000;
const s = Math.floor(timespan / perSecond) % 60;
const m = Math.floor(timespan / perMinute) % 60;
const H = Math.floor(timespan / perHour) % 60;
const d = Math.floor(timespan / perDay) % 24;
const flags = {
d,
dd: pad(d),
td,
tdd: pad(td),
h: H % 12 || 12,
hh: pad(H % 12 || 12),
th: tH % 12 || 12,
thh: pad(tH % 12 || 12),
H, // 0-23
HH: pad(H), // 00-23
tH, // 0-23
tHH: pad(tH), // 00-23
k: (H % 12 || 12) - 1,
kk: pad((H % 12 || 12) - 1),
tk: (tH % 12 || 12) - 1,
tkk: pad((tH % 12 || 12) - 1),
K: H + 1, // 1-24
KK: pad(H + 1), // 01-24
tK: tH + 1,
tKK: pad(tH + 1),
m,
mm: pad(m),
tm,
tmm: pad(tm),
s,
ss: pad(s),
ts,
tss: pad(ts),
lll: pad(L, 3),
ll: pad(Math.round(L / 10)),
l: L,
tlll: pad(tl, 3),
tll: pad(Math.round(tl / 10)),
tl,
L: pad(L > 99 ? Math.round(L / 10) : L),
t: H < 12 ? 'a' : 'p',
tt: H < 12 ? 'am' : 'pm',
T: H < 12 ? 'A' : 'P',
TT: H < 12 ? 'AM' : 'PM',
S: ['th', 'st', 'nd', 'rd'][d % 10 > 3 ? 0 : (d % 100 - d % 10 !== 10) * d % 10]
};
return mask.replace(token, $0 => {
return $0 in flags ? flags[$0] : $0.slice(1, $0.length - 1);
});
};
})();
// Some common format strings

@@ -749,8 +671,8 @@ dateFormat.masks = {

dateFormat.parseDates = {
general : ['y-M-d', 'MMM d, y', 'MMM d,y', 'y-MMM-d', 'd-MMM-y', 'MMM d'],
monthFirst : ['M/d/y', 'M-d-y', 'M.d.y', 'MMM-d', 'M/d', 'M-d'],
dateFirst : ['d/M/y', 'd-M-y', 'd.M.y', 'd-MMM', 'd/M', 'd-M']
monthFirst : ['MMM d, y', 'MMM d,y', 'M/d/y', 'M-d-y', 'M.d.y', 'MMM-d', 'M/d', 'MMM d', 'M-d'],
dateFirst : ['d-MMM-y', 'd/M/y', 'd-M-y', 'd.M.y', 'd-MMM', 'd/M', 'd-M', 'd MMM'],
general : ['y-M-d', 'y-MMM-d']
};
dateFormat.parseTimes = ['hh:mm:ss:lt', 'hh:mm:ss.lt', 'hh:mm:sst', 'hh:mmt', 'HH:mm:ss:l', 'HH:mm:ss.l', 'HH:mm:ss', 'HH:mm', 'h:mm:ss TT Z', 'h:mm:ss TT', 'h:mm TT'];
dateFormat.parseTimes = ['h:m:s:lt', 'h:m:s.lt', 'h:m:st', 'h:mt', 'h:m:s t', 'h:m:s.t', 'H:m:s:l', 'H:m:s.l', 'H:m:s', 'H:m', 'h:m:s t Z', 'H:m:s Z'];

@@ -808,24 +730,27 @@ dateFormat.i18n = {

{label: 'Year yyyy (4 digits)', value: 'yyyy'},
{label: 'Month M (1 digit)', value: 'M'},
{label: 'Month M (1/2 digit)', value: 'M'},
{label: 'Month MM (2 digits)', value: 'MM'},
{label: 'Month MMM (name or abbr.)', value: 'MMM'},
{label: 'Month NNN (abbr.)', value: 'NNN'},
{label: 'Day of Month d (1 digit)', value: 'd'},
{label: 'Day of Month d (1/2 digit)', value: 'd'},
{label: 'Day of Month dd (2 digits)', value: 'dd'},
{label: 'Day of Week E (abbr.)', value: 'E'},
{label: 'Day of Week EE (name)', value: 'EE'},
{label: 'Hour h (1 digit 1-12)', value: 'h'},
{label: 'Hour h (1/2 digit 1-12)', value: 'h'},
{label: 'Hour hh (2 digits 1-12)', value: 'hh'},
{label: 'Hour H (1 digit 0-23)', value: 'H'},
{label: 'Hour H (1/2 digit 0-23)', value: 'H'},
{label: 'Hour HH (2 digits 0-23)', value: 'HH'},
{label: 'Hour K (1 digit 0-11)', value: 'K'},
{label: 'Hour K (1/2 digit 0-11)', value: 'K'},
{label: 'Hour KK (2 digits 0-11)', value: 'KK'},
{label: 'Hour k (1 digit 1-24)', value: 'k'},
{label: 'Hour k (1/2 digit 1-24)', value: 'k'},
{label: 'Hour kk (2 digits 1-24)', value: 'kk'},
{label: 'Minute m (1 digit)', value: 'm'},
{label: 'Minute m (1/2 digit)', value: 'm'},
{label: 'Minute mm (2 digits)', value: 'mm'},
{label: 'Second s (1 digit)', value: 's'},
{label: 'Second s (1/2 digit)', value: 's'},
{label: 'Second ss (2 digits)', value: 'ss'},
{label: 'Milliseconds ll (2 digits)', value: 'll'},
{label: 'Milliseconds l (1-3 digits)', value: 'l'},
{label: 'Milliseconds ll (2/3 digits)', value: 'll'},
{label: 'Milliseconds lll (3 digits)', value: 'lll'},
{label: 'Milliseconds L (1 digit rounded)', value: 'L'},
{label: 'Milliseconds LL (2 digits rounded)', value: 'LL'},
{label: 'AM/PM t (1 digit)', value: 't'},

@@ -858,4 +783,6 @@ {label: 'AM/PM tt (2 digits)', value: 'tt'}

{label: 'Milliseconds l (0-999)', value: 'l'},
{label: 'Milliseconds ll (2 digits 00-99)', value: 'll'},
{label: 'Milliseconds ll (2/3 digits 00-999)', value: 'll'},
{label: 'Milliseconds lll (3 digits 000-999)', value: 'lll'},
{label: 'Milliseconds L (round to 1 digit 0-9)', value: 'L'},
{label: 'Milliseconds LL (round to 2 digits 00-99)', value: 'LL'},
{label: 'AM/PM t (1 digit - Lowercase)', value: 't'},

@@ -975,3 +902,8 @@ {label: 'AM/PM tt (2 digits - Lowercase)', value: 'tt'},

const delay = (date.getTime() - (new Date()).getTime());
const now = new Date();
console.log('date='+util.inspect(date)); // eslint-disable-line
console.log('now='+util.inspect(now)); // eslint-disable-line
const delay = (date.getTime() - now.getTime());
console.log('delay='+util.inspect(delay)); // eslint-disable-line
return {

@@ -1046,3 +978,3 @@ date,

// 9/2/00
// "MMM dd, yyyy hh:mm:ssa" matches: "January 01, 2000 12:30:45AM"
// "MMM dd, yyyy hh:mm:sst" matches: "January 01, 2000 12:30:45AM"
// ------------------------------------------------------------------

@@ -1107,4 +1039,2 @@

let i_format = 0;
let c = '';
let token = '';
let x; let y;

@@ -1122,4 +1052,4 @@ let year = now.getFullYear();

// Get next token from format string
c = format.charAt(i_format);
token = '';
const c = format.charAt(i_format);
let token = '';
while ((format.charAt(i_format) === c) && (i_format < format.length)) {

@@ -1191,3 +1121,2 @@ token += format.charAt(i_format++);

}
i_val += month.length;

@@ -1199,3 +1128,2 @@ } else if (token === 'dd' || token === 'd') {

}
i_val += date.length;

@@ -1207,3 +1135,2 @@ } else if (token === 'hh' || token === 'h') {

}
i_val += hh.length;

@@ -1215,3 +1142,2 @@ } else if (token === 'HH' || token === 'H') {

}
i_val += hh.length;

@@ -1223,3 +1149,2 @@ } else if (token === 'kk' || token === 'k') {

}
i_val += hh.length;

@@ -1231,3 +1156,2 @@ } else if (token === 'KK' || token === 'K') {

}
i_val += hh.length;

@@ -1240,3 +1164,2 @@ hh--;

}
i_val += mm.length;

@@ -1248,5 +1171,4 @@ } else if (token === 'ss' || token === 's') {

}
i_val += ss.length;
} else if (token === 'lll' || token === 'll' || token === 'l' || token === 'L') {
} else if (token.toLowerCase() === 'lll' || token.toLowerCase() === 'll' || token.toLowerCase() === 'l') {
ll = _getInt(val, i_val, token.length, 3);

@@ -1256,5 +1178,10 @@ if (ll === null || (ll < 0) || (ll > 999)) {

}
i_val += ll.length;
} else if ((token === 'tt') || (token === 't') || (token === 'TT') || (token === 'T')) {
if ( token === 'L' && ll < 10) {
ll = ll * 100;
}
if ( token === 'LL' && ll < 100) {
ll = ll * 10;
}
} else if ((token.toLowerCase() === 'tt') || (token.toLowerCase() === 't')) {
if (val.substring(i_val, i_val + 2).toLowerCase() === 'am') {

@@ -1313,3 +1240,4 @@ ampm = 'AM';

}
// console.log(year, month, date, hh, mm, ss, ll); // eslint-disable-line
console.log(`getDateFromFormat out year=${year} month=${month} date=${date} hh=${hh} mm=${mm} ss=${ss} ll=${ll}`); // eslint-disable-line
return new Date(year, month - 1, date, hh, mm, ss, ll);

@@ -1342,12 +1270,12 @@ }

* @param {string} val date string to parse
* @param {boolean} [preferEuro] if **true** the method to search for formats like d/M/y (European format) before M/d/y (American).
* @param {boolean} [preferMonthFirst] if **true** the method to search first for formats like M/d/y (e.g. American format) before d/M/y (e.g. European).
* @returns {Date|null} a Date object or **null** if no patterns match.
*/
function parseDate(val, preferEuro) {
console.debug('parseDate val=' + val + ' - preferEuro=' + preferEuro); // eslint-disable-line
let res = _parseArray(val, dateFormat.parseDates.general);
function parseDate(val, preferMonthFirst) {
console.debug('parseDate val=' + val + ' - preferMonthFirst=' + preferMonthFirst); // eslint-disable-line
let res = _parseArray(val, (preferMonthFirst) ? dateFormat.parseDates.monthFirst : dateFormat.parseDates.dateFirst);
if (res !== null) { return res; }
res = _parseArray(val, (preferEuro) ? dateFormat.parseDates.dateFirst : dateFormat.parseDates.monthFirst);
res = _parseArray(val, (preferMonthFirst) ? dateFormat.parseDates.dateFirst : dateFormat.parseDates.monthFirst);
if (res !== null) { return res; }
return _parseArray(val, (preferEuro) ? dateFormat.parseDates.monthFirst : dateFormat.parseDates.dateFirst);
return _parseArray(val, dateFormat.parseDates.general);
}

@@ -1359,7 +1287,7 @@

* @param {string} val date string to parse
* @param {boolean} [preferEuro] if **true** the method to search for formats like d/M/y (European format) before M/d/y (American).
* @param {boolean} [preferMonthFirst] if **true** the method to search first for formats like M/d/y (e.g. American format) before d/M/y (e.g. European).
* @returns {Date|null} a Date object or **null** if no patterns match.
*/
function parseDateTime(val, preferEuro) {
console.debug('parseDateTime val=' + val + ' - preferEuro=' + preferEuro); // eslint-disable-line
function parseDateTime(val, preferMonthFirst) {
console.debug('parseDateTime val=' + val + ' - preferMonthFirst=' + preferMonthFirst); // eslint-disable-line
function mix(lst1, lst2, result) {

@@ -1375,10 +1303,10 @@ for (let i = 0; i < lst1.length; i++) {

let checkList = [dateFormat.masks.isoDateTime];
checkList = mix(dateFormat.parseDates.general, dateFormat.parseTimes, checkList);
if (preferEuro) {
if (preferMonthFirst) {
checkList = mix(dateFormat.parseDates.monthFirst, dateFormat.parseTimes, checkList);
checkList = mix(dateFormat.parseDates.dateFirst, dateFormat.parseTimes, checkList);
checkList = mix(dateFormat.parseDates.monthFirst, dateFormat.parseTimes, checkList);
} else {
checkList = mix(dateFormat.parseDates.dateFirst, dateFormat.parseTimes, checkList);
checkList = mix(dateFormat.parseDates.monthFirst, dateFormat.parseTimes, checkList);
checkList = mix(dateFormat.parseDates.dateFirst, dateFormat.parseTimes, checkList);
}
checkList = mix(dateFormat.parseDates.general, dateFormat.parseTimes, checkList);
return _parseArray(val, checkList);

@@ -1394,3 +1322,3 @@ }

* @param {Array.<string>} [dayDiffNames] list of day diff names
* @returns {Date|null} a Date object or **null** if no patterns match.
* @returns {Date} a Date object or throws an error if no patterns match.
*/

@@ -1414,35 +1342,52 @@ function parseDateFromFormat(date, format, dayNames, monthNames, dayDiffNames) {

let res = null;
if (isNaN(format)) { // timeparse_TextOther
return getDateFromFormat(date, format);
}
const tryparse = (val, preferEuro) => {
console.debug('try parse ' + util.inspect(preferEuro)); // eslint-disable-line
let res = parseDateTime(val, preferEuro);
if (res === null) {
res = parseDate(val, preferEuro);
}
if (res === null) {
res = getDateFromFormat(date, format);
} else {
const tryparse = (val, preferMonthFirst) => {
console.debug('try parse ' + util.inspect(val) + ' preferMonthFirst=' + preferMonthFirst); // eslint-disable-line
let res = parseDateTime(val, preferMonthFirst);
if (res !== null) { return res; }
res = parseDate(val, preferMonthFirst);
if (res !== null) { return res; }
res = _parseArray(val, dateFormat.parseTimes);
}
return res;
};
if (res !== null) { return res; }
console.debug(`try parse last try res=${res}`); // eslint-disable-line
res = Date.parse(val);
if (isNaN(res)) {
return null;
}
return new Date(res);
};
switch (Number(format)) {
case 0: // UNIX Timestamp
return new Date(Number(date));
case 1: // timeparse_ECMA262
return Date.parse(date);
case 2: // various - try different Formats, prefer European formats
return tryparse(date, true);
case 3: // various - try different Formats, prefer American formats
return tryparse(date, false);
case 4: // timeformat_YYYYMMDDHHMMSS
return parseComparableDateFormat(date);
case 5: // timeformat_YYYYMMDD_HHMMSS
return parseComparableDateFormat2(date);
default: {
return getDateOfText(date);
switch (Number(format)) {
case 0: // UNIX Timestamp
res = new Date(Number(date));
break;
case 1: // timeparse_ECMA262
res = Date.parse(date);
break;
case 2: // various - try different Formats, prefer day first like d/M/y (e.g. European format)
res = tryparse(date, false);
break;
case 3: // various - try different Formats, prefer month first like M/d/y (e.g. American format)
res = tryparse(date, true);
break;
case 4: // timeformat_YYYYMMDDHHMMSS
res = parseComparableDateFormat(date);
break;
case 5: // timeformat_YYYYMMDD_HHMMSS
res = parseComparableDateFormat2(date);
break;
default: {
res = getDateOfText(date);
break;
}
}
}
if (res === 'Invalid Date' || isNaN(res) || res === null) {
throw new Error('could not evaluate format of ' + date + ' (' + format+')');
}
return res;
}

@@ -76,9 +76,2 @@ {

],
"month": [
"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December",
"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
],
"dayDiffNames": [
"Yesterday", "Today", "Tomorrow", "day after tomorrow"
],
"placeholder": {

@@ -85,0 +78,0 @@ "position": "Position",

@@ -48,5 +48,18 @@ {

"dayDiffNames": [
"1 week ago", "6 days ago", "5 days ago", "4 days ago", "3 days ago", "2 days ago", "Yesterday", "Today", "Tomorrow", "day after tomorrow", "in 3 days", "in 4 days", "in 5 days", "in 6 days"
"1 week ago",
"6 days ago",
"5 days ago",
"4 days ago",
"3 days ago",
"2 days ago",
"Yesterday",
"Today",
"Tomorrow",
"day after tomorrow",
"in 3 days",
"in 4 days",
"in 5 days",
"in 6 days"
]
}
}

@@ -5,2 +5,4 @@ {

"position" : "Position",
"positionConfig": "configuration",
"config": "configuration",
"topic" :"Topic",

@@ -7,0 +9,0 @@ "between":"between",

@@ -10,2 +10,3 @@ {

"position": "Position",
"positionConfig": "configuration",
"input": "Input",

@@ -116,3 +117,3 @@ "inputFormat": "parse format",

"Text (string)",
"Text free"
"Other"
],

@@ -122,7 +123,8 @@ "parseFormats": [

"ECMA-262 - JSON Date representation",
"various - try different Formats, prefere european formats",
"various - try different Formats, prefere american formats",
"try different text Formats, prefer day first like d/M/y",
"try different text Formats, prefer month first like M/d/y",
"YYYYMMDDHHMMSS",
"YYYYMMDD.HHMMSS",
"Other - free definition"
"try different various Formats (object, number, text)",
"free text format definition"
],

@@ -143,60 +145,2 @@ "multiplierGroups": [

],
"days": [
"Sunday",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday",
"Sun",
"Mon",
"Tue",
"Wed",
"Thu",
"Fri",
"Sat"
],
"month": [
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December",
"Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
"Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec"
],
"dayDiffNames": [
"1 week ago",
"6 days ago",
"5 days ago",
"4 days ago",
"3 days ago",
"2 days ago",
"Yesterday",
"Today",
"Tomorrow",
"day after tomorrow",
"in 3 days",
"in 4 days",
"in 5 days",
"in 6 days"
],
"placeholder": {

@@ -238,3 +182,3 @@ "position": "Position",

"error": "<strong>Error</strong>: __message__",
"error-text": "Exception occured on time-comp",
"error-text": "Exception occurred on time-comp",
"error-title": "internal error",

@@ -241,0 +185,0 @@ "unexpected": "unexpected error (__status__) __message__",

@@ -7,2 +7,3 @@ {

"position": "Position",
"positionConfig": "configuration",
"name": "Name",

@@ -124,9 +125,2 @@ "property": "Property",

],
"month": [
"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December",
"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
],
"dayDiffNames": [
"1 week ago", "6 days ago", "5 days ago", "4 days ago", "3 days ago", "2 days ago", "Yesterday", "Today", "Tomorrow", "day after tomorrow", "in 3 days", "in 4 days", "in 5 days", "in 6 days"
],
"placeholder": {

@@ -133,0 +127,0 @@ "position": "Position",

@@ -10,2 +10,3 @@ {

"position": "Position",
"positionConfig": "configuration",
"operand1": "Input 1",

@@ -144,3 +145,3 @@ "operand1Format": "parse format",

"Text (string)",
"Text free"
"Other"
],

@@ -150,7 +151,8 @@ "parseFormats": [

"ECMA-262 - JSON Date representation",
"various - try different Formats, prefere european formats",
"various - try different Formats, prefere american formats",
"try different text Formats, prefer day first d/M/y",
"try different text Formats, prefer month first M/d/y",
"YYYYMMDDHHMMSS",
"YYYYMMDD.HHMMSS",
"Other - free definition"
"try different various Formats (object, number, text)",
"free text format definition"
],

@@ -171,60 +173,2 @@ "multiplierGroups": [

],
"days": [
"Sunday",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday",
"Sun",
"Mon",
"Tue",
"Wed",
"Thu",
"Fri",
"Sat"
],
"month": [
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December",
"Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
"Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec"
],
"dayDiffNames": [
"1 week ago",
"6 days ago",
"5 days ago",
"4 days ago",
"3 days ago",
"2 days ago",
"Yesterday",
"Today",
"Tomorrow",
"day after tomorrow",
"in 3 days",
"in 4 days",
"in 5 days",
"in 6 days"
],
"placeholder": {

@@ -266,3 +210,3 @@ "position": "Position",

"error": "<strong>Error</strong>: __message__",
"error-text": "Exception occured on time-span",
"error-text": "Exception occurred on time-span",
"error-title": "internal error",

@@ -269,0 +213,0 @@ "unexpected": "unexpected error (__status__) __message__",

@@ -5,2 +5,3 @@ {

"position": "Position",
"positionConfig": "configuration",
"name": "Name",

@@ -63,3 +64,3 @@ "topic": "Topic",

"tips": {
"addTimes": "Here can be defined alternate times for start/end. If the given property is true the alternate start/end times will be used instead the normal ones. This can be used to have differend start/end times for holidays or other special days."
"addTimes": "Here can be defined alternate times for start/end. If the given property is true the alternate start/end times will be used instead the normal ones. This can be used to have different start/end times for holidays or other special days."
},

@@ -71,3 +72,3 @@ "notification": {

"error": "<strong>Error</strong>: __message__",
"error-text": "Exception occured on withinTimeSwitch",
"error-text": "Exception occurred on withinTimeSwitch",
"error-start-time": "Error get start time: __message__",

@@ -74,0 +75,0 @@ "error-end-time": "Error get end time: __message__",

@@ -60,3 +60,9 @@ /********************************************

} catch (err) {
hlp.handleError(this, 'Exception occurred on moon-position', err, 'internal error');
node.error(err.message);
node.debug(util.inspect(err, Object.getOwnPropertyNames(err)));
node.status({
fill: 'red',
shape: 'ring',
text: 'internal error'
});
}

@@ -63,0 +69,0 @@ // this.error("Input parameter wrong or missing. You need to setup (or give in the input message) the 'url' and 'content type' or the 'message' and 'language'!!");

@@ -74,178 +74,190 @@ /********************************************

RED.nodes.createNode(this, n);
try {
// this.debug('load position-config ' + n.name);
this.name = n.name;
this.longitude = parseFloat(this.credentials.posLongitude || n.longitude);
this.latitude = parseFloat(this.credentials.posLatitude || n.latitude);
this.angleType = n.angleType;
this.tzOffset = (n.timezoneOffset * -60) || 0;
// this.debug('load position-config ' + this.name + ' long:' + this.longitude + ' latitude:' + this.latitude + ' angelt:' + this.angleType + ' TZ:' + this.tzOffset);
// this.debug('load position-config ' + n.name);
this.name = n.name;
this.longitude = parseFloat(this.credentials.posLongitude || n.longitude);
this.latitude = parseFloat(this.credentials.posLatitude || n.latitude);
this.angleType = n.angleType;
this.tzOffset = (n.timezoneOffset * -60) || 0;
// this.debug('load position-config ' + this.name + ' long:' + this.longitude + ' latitude:' + this.latitude + ' angelt:' + this.angleType + ' TZ:' + this.tzOffset);
this.lastSunCalc = {
ts: 0
};
this.lastMoonCalc = {
ts: 0
};
const node = this;
/*
console.log(hlp.getNodeId(node) +' old lon '+n.longitude);
console.log(hlp.getNodeId(node) +' old lat '+n.latitude);
console.log(hlp.getNodeId(node) +' new lon '+this.credentials.posLongitude);
console.log(hlp.getNodeId(node) +' new lat '+this.credentials.posLatitude);
console.log(hlp.getNodeId(node) +' result lon '+node.longitude);
console.log(hlp.getNodeId(node) +' result lat '+node.latitude);
this.lastSunCalc = {
ts: 0
};
this.lastMoonCalc = {
ts: 0
};
const node = this;
/*
console.log(hlp.getNodeId(node) +' old lon '+n.longitude);
console.log(hlp.getNodeId(node) +' old lat '+n.latitude);
console.log(hlp.getNodeId(node) +' new lon '+this.credentials.posLongitude);
console.log(hlp.getNodeId(node) +' new lat '+this.credentials.posLatitude);
console.log(hlp.getNodeId(node) +' result lon '+node.longitude);
console.log(hlp.getNodeId(node) +' result lat '+node.latitude);
*/
/*
this.getSunTimes = () => {
//node.debug('getSunTimes');
let res = sunTimesCheck(node);
res.today = node.sunTimesToday;
res.tomorrow = node.sunTimesTomorrow;
return res;
/*
this.getSunTimes = () => {
//node.debug('getSunTimes');
let res = sunTimesCheck(node);
res.today = node.sunTimesToday;
res.tomorrow = node.sunTimesTomorrow;
return res;
}
*/
this.getSunTime = (now, value, offset, multiplier, next, days) => {
node.debug('getSunTime value=' + value + ' offset=' + offset + ' multiplier=' + multiplier + ' next=' + next + ' days=' + days);
let result = sunTimesCheck(node, now);
result = Object.assign(result, node.sunTimesToday[value]);
result.value = hlp.addOffset(new Date(result.value), offset, multiplier);
if (next && !isNaN(next) && result.value.getTime() <= now.getTime()) {
if (next === 1) {
result = Object.assign(result, node.sunTimesTomorow[value]);
} else if (next > 1) {
const date = (new Date()).addDays(next);
result = Object.assign(result, sunCalc.getTimes(date, node.latitude, node.longitude)[value]);
}
result.value = hlp.addOffset(new Date(result.value), offset, multiplier);
}
*/
this.getSunTime = (now, value, offset, multiplier, next, days) => {
node.debug('getSunTime value=' + value + ' offset=' + offset + ' multiplier=' + multiplier + ' next=' + next + ' days=' + days);
let result = sunTimesCheck(node, now);
result = Object.assign(result, node.sunTimesToday[value]);
result.value = hlp.addOffset(new Date(result.value), offset, multiplier);
if (next && !isNaN(next) && result.value.getTime() <= now.getTime()) {
if (next === 1) {
result = Object.assign(result, node.sunTimesTomorow[value]);
} else if (next > 1) {
const date = (new Date()).addDays(next);
result = Object.assign(result, sunCalc.getTimes(date, node.latitude, node.longitude)[value]);
}
if (days && (days !== '*') && (days !== '')) {
// node.debug('move days ' + days + ' result=' + util.inspect(result));
const dayx = hlp.calcDayOffset(days, result.value.getDay());
if (dayx > 0) {
const date = result.value.addDays(dayx);
// let times = sunCalc.getTimes(date, node.latitude, node.longitude);
result = Object.assign(result, sunCalc.getTimes(date, node.latitude, node.longitude)[value]);
result.value = hlp.addOffset(new Date(result.value), offset, multiplier);
} else if (dayx < 0) {
// node.debug('getSunTime - no valid day of week found value=' + value + ' - next=' + next + ' - days=' + days + ' result=' + util.inspect(result));
result.error = 'No valid day of week found!';
}
}
if (days && (days !== '*') && (days !== '')) {
// node.debug('move days ' + days + ' result=' + util.inspect(result));
const dayx = hlp.calcDayOffset(days, result.value.getDay());
if (dayx > 0) {
const date = result.value.addDays(dayx);
// let times = sunCalc.getTimes(date, node.latitude, node.longitude);
result = Object.assign(result, sunCalc.getTimes(date, node.latitude, node.longitude)[value]);
result.value = hlp.addOffset(new Date(result.value), offset, multiplier);
} else if (dayx < 0) {
// node.debug('getSunTime - no valid day of week found value=' + value + ' - next=' + next + ' - days=' + days + ' result=' + util.inspect(result));
result.error = 'No valid day of week found!';
}
}
// node.debug('getSunTime result=' + util.inspect(result));
return result;
};
// node.debug('getSunTime result=' + util.inspect(result));
return result;
};
this.getMoonTimes = () => {
// node.debug('getMoonTimes');
const res = moonTimesCheck(node);
res.today = node.moonTimesToday;
res.tomorrow = node.moonTimesTomorow;
return res;
};
this.getMoonTimes = () => {
// node.debug('getMoonTimes');
const res = moonTimesCheck(node);
res.today = node.moonTimesToday;
res.tomorrow = node.moonTimesTomorow;
return res;
};
this.getMoonTime = (now, value, offset, multiplier, next, days) => {
node.debug('getMoonTime value=' + value + ' offset=' + offset + ' next=' + next + ' days=' + days);
const result = moonTimesCheck(node, now);
// node.debug('Moon Times today =' + util.inspect(node.moonTimesToday));
result.value = hlp.addOffset(new Date(node.moonTimesToday[value]), offset, multiplier);
if (next && !isNaN(next) && result.value.getTime() <= now.getTime()) {
if (next === 1) {
result.value = hlp.addOffset(new Date(node.moonTimesTomorow[value]), offset, multiplier);
// node.debug('Moon Times tomorrow =' + util.inspect(node.moonTimesTomorrow));
} else if (next > 1) {
const date = (new Date()).addDays(next);
const times = sunCalc.getMoonTimes(date, node.latitude, node.longitude, true);
result.value = hlp.addOffset(new Date(new Date(times[value])), offset, multiplier);
// node.debug('Moon Times for ' + date + ' =' + util.inspect(times));
}
this.getMoonTime = (now, value, offset, multiplier, next, days) => {
node.debug('getMoonTime value=' + value + ' offset=' + offset + ' next=' + next + ' days=' + days);
const result = moonTimesCheck(node, now);
// node.debug('Moon Times today =' + util.inspect(node.moonTimesToday));
result.value = hlp.addOffset(new Date(node.moonTimesToday[value]), offset, multiplier);
if (next && !isNaN(next) && result.value.getTime() <= now.getTime()) {
if (next === 1) {
result.value = hlp.addOffset(new Date(node.moonTimesTomorow[value]), offset, multiplier);
// node.debug('Moon Times tomorrow =' + util.inspect(node.moonTimesTomorrow));
} else if (next > 1) {
const date = (new Date()).addDays(next);
const times = sunCalc.getMoonTimes(date, node.latitude, node.longitude, true);
result.value = hlp.addOffset(new Date(new Date(times[value])), offset, multiplier);
// node.debug('Moon Times for ' + date + ' =' + util.inspect(times));
}
}
if (days && (days !== '*') && (days !== '')) {
const dayx = hlp.calcDayOffset(days, result.value.getDay());
if (dayx > 0) {
const date = (new Date()).addDays(dayx);
const times = sunCalc.getMoonTimes(date, node.latitude, node.longitude, true);
result.value = hlp.addOffset(new Date(new Date(times[value])), offset, multiplier);
// node.debug('Moon Times for ' + date + ' =' + util.inspect(times));
} else if (dayx < 0) {
result.error = 'No valid day of week found!';
// node.debug('getMoonTime - no valid week day found value=' + value + ' - next=' + next + ' - days=' + days + ' result=' + result.value);
}
if (days && (days !== '*') && (days !== '')) {
const dayx = hlp.calcDayOffset(days, result.value.getDay());
if (dayx > 0) {
const date = (new Date()).addDays(dayx);
const times = sunCalc.getMoonTimes(date, node.latitude, node.longitude, true);
result.value = hlp.addOffset(new Date(new Date(times[value])), offset, multiplier);
// node.debug('Moon Times for ' + date + ' =' + util.inspect(times));
} else if (dayx < 0) {
result.error = 'No valid day of week found!';
// node.debug('getMoonTime - no valid week day found value=' + value + ' - next=' + next + ' - days=' + days + ' result=' + result.value);
}
}
// node.debug('getMoonTime result' + util.inspect(result));
return result;
};
// node.debug('getMoonTime result' + util.inspect(result));
return result;
};
this.getFloatProp = (_srcNode, msg, type, value) => {
_srcNode.debug('getFloatProp type='+type+' value='+value);
let data;
// 'msg', 'flow', 'global', 'num', 'bin', 'env', 'jsonata'
if (type === '' || type === 'none' || typeof type === 'undefined' || type === null) {
return 0;
} else if (type === 'msgPayload') {
data = msg.payload;
} else if (type === 'msgValue') {
data = msg.value;
} else {
data = RED.util.evaluateNodeProperty(value, type, _srcNode, msg);
this.getFloatProp = (_srcNode, msg, type, value) => {
_srcNode.debug('getFloatProp type='+type+' value='+value);
let data;
// 'msg', 'flow', 'global', 'num', 'bin', 'env', 'jsonata'
if (type === '' || type === 'none' || typeof type === 'undefined' || type === null) {
return 0;
} else if (type === 'msgPayload') {
data = msg.payload;
} else if (type === 'msgValue') {
data = msg.value;
} else {
data = RED.util.evaluateNodeProperty(value, type, _srcNode, msg);
}
if (data === null || typeof data === 'undefined') {
throw new Error('could not evaluate ' + type + '.' + value);
}
data = parseFloat(data);
if (isNaN(data)) {
throw new Error('the value of ' + type + '.' + value + ' is not a valid Number!');
}
return data;
};
this.formatOutDate = (date, format) => {
return hlp.getFormattedDateOut(date, format, RED._('time-comp.days'), RED._('time-comp.month'), RED._('time-comp.dayDiffNames'));
};
this.getOutDataProp = (_srcNode, msg, vType, value, format, offset, multiplier, days) => {
_srcNode.debug('getOutDataProp type='+vType+' value='+value+' format='+format+' offset='+offset+' multiplier='+multiplier);
let result = null;
if (vType === null || vType === 'none' || vType === '' || (typeof vType === 'undefined')) {
if (value === '' || (typeof value === 'undefined')) {
result = hlp.addOffset(Date.now(), offset, multiplier);
return node.formatOutDate(result, format);
}
if (data === null || typeof data === 'undefined') {
throw new Error('could not evaluate ' + type + '.' + value);
return value;
} else if (vType === 'date') {
result = hlp.addOffset(Date.now(), offset, multiplier);
return node.formatOutDate(result, format);
} else if (vType === 'msgPayload') {
return msg.payload;
} else if (vType === 'msgTs') {
return msg.ts;
} else if (vType === 'msgValue') {
return msg.value;
} else if (vType === 'pdsCalcData') {
return node.getSunCalc(msg.ts);
} else if (vType === 'pdmCalcData') {
return node.getMoonCalc(msg.ts);
} else if ((vType === 'pdsTime') || (vType === 'pdmTime')) {
if (vType === 'pdsTime') { // sun
result = node.getSunTime(Date.now(), value, offset, multiplier, undefined, days);
} else if (vType === 'pdmTime') { // moon
result = node.getMoonTime(Date.now(), value, offset, multiplier, undefined, days);
}
data = parseFloat(data);
if (isNaN(data)) {
throw new Error('the value of ' + type + '.' + value + ' is not a valid Number!');
if (result && result.value && !result.error) {
return node.formatOutDate(result, format);
}
return data;
};
this.getOutDataProp = (_srcNode, msg, vType, value, format, offset, multiplier) => {
_srcNode.debug('getOutDataProp type='+vType+' value='+value+' format='+format+' offset='+offset+' multiplier='+multiplier);
let result = null;
if (vType === null || vType === 'none' || vType === '' || vType === 'date') {
return hlp.getFormattedDateOut(Date.now(), format, RED._('position-config.days'), RED._('position-config.month'), RED._('position-config.dayDiffNames'));
} else if (vType === 'msgPayload') {
return msg.payload;
} else if (vType === 'msgTs') {
return msg.ts;
} else if (vType === 'pdsCalcData') {
return node.getSunCalc(msg.ts);
} else if (vType === 'pdmCalcData') {
return node.getMoonCalc(msg.ts);
} else if ((vType === 'pdsTime') ||
(vType === 'pdmTime')) {
if (vType === 'pdsTime') { // sun
result = node.getSunTime(Date.now(), value, offset, multiplier);
} else if (vType === 'pdmTime') { // moon
result = node.getMoonTime(Date.now(), value, offset, multiplier);
}
if (result && result.value && !result.error) {
return hlp.getFormattedDateOut(result, format, RED._('position-config.days'), RED._('position-config.month'), RED._('position-config.dayDiffNames'));
}
return null;
} else if (vType === 'entered' || vType === 'dateEntered') {
result = hlp.getDateOfText(String(value));
return null;
} else if (vType === 'entered' || vType === 'dateEntered') {
result = hlp.getDateOfText(String(value));
result = hlp.normalizeDate(Date.now(), offset, multiplier, undefined, days); // hlp.addOffset(result, offset, multiplier);
return node.formatOutDate(result, format);
} else if (vType === 'dayOfMonth') {
result = new Date();
result = hlp.getSpecialDayOfMonth(result.getFullYear(),result.getMonth(), value);
if (result !== null && typeof result !== 'undefined') {
result = hlp.addOffset(result, offset, multiplier);
return hlp.getFormattedDateOut(result, format, RED._('position-config.days'), RED._('position-config.month'), RED._('position-config.dayDiffNames'));
} else if (vType === 'dayOfMonth') {
result = new Date();
result = hlp.getSpecialDayOfMonth(result.getFullYear(),result.getMonth(), value);
if (result !== null && typeof result !== 'undefined') {
result = hlp.addOffset(result, offset, multiplier);
return hlp.getFormattedDateOut(result, format, RED._('position-config.days'), RED._('position-config.month'), RED._('position-config.dayDiffNames'));
}
return null;
return node.formatOutDate(result, format);
}
return RED.util.evaluateNodeProperty(value, vType, _srcNode, msg);
};
return null;
}
return RED.util.evaluateNodeProperty(value, vType, _srcNode, msg);
};
this.getDateFromProp = (_srcNode, msg, vType, value, format, offset, multiplier) => {
_srcNode.debug('getDateFromProp type='+vType+' value='+value+' format='+format+' offset='+offset+' multiplier='+multiplier);
let result = null;
this.getDateFromProp = (_srcNode, msg, vType, value, format, offset, multiplier) => {
_srcNode.debug('getDateFromProp type='+vType+' value='+value+' format='+format+' offset='+offset+' multiplier='+multiplier);
let result = null;
try {
if (vType === null || vType === 'none' || vType === '') {

@@ -280,2 +292,4 @@ return Date.now();

result = msg.ts;
} else if (vType === 'msgValue') {
result = msg.value;
} else {

@@ -287,191 +301,204 @@ // msg, flow, global, str, num, env

result = hlp.parseDateFromFormat(result, format, RED._('position-config.days'), RED._('position-config.month'), RED._('position-config.dayDiffNames'));
if (result === 'Invalid Date' || isNaN(result) || result === null) {
throw new Error('could not evaluate format of ' + result);
}
return hlp.addOffset(result, offset, multiplier);
}
throw new Error('could not evaluate ' + vType + '.' + value);
} catch (err) {
node.debug(util.inspect(err, Object.getOwnPropertyNames(err)));
const e = new Error(`Exception "${err.message}", on try to evaluate ${vType}.${value}`);
e.original = err;
e.stack = e.stack.split('\n').slice(0,2).join('\n')+'\n'+err.stack;
throw e;
}
};
this.getTimeProp = (_srcNode, msg, vType, value, offset, multiplier, next, days) => {
node.debug('getTimeProp ' + hlp.getNodeId(_srcNode) + ' vType=' + vType + ' value=' + value + ' offset=' + offset + ' multiplier=' + multiplier + ' next=' + next + ' days=' + days);
const now = new Date();
let result = {
value: null,
error: null,
fix: true
};
this.getTimeProp = (_srcNode, msg, vType, value, offset, multiplier, next, days) => {
node.debug('getTimeProp ' + hlp.getNodeId(_srcNode) + ' vType=' + vType + ' value=' + value + ' offset=' + offset + ' multiplier=' + multiplier + ' next=' + next + ' days=' + days);
const now = new Date();
let result = {
value: null,
error: null,
fix: true
};
try {
if (vType === '' || vType === 'none' || days === '') {
// nix
} else if (vType === 'date') {
result.value = hlp.normalizeDate(now, offset, multiplier, next, days);
result.fix = true;
} else if (vType === 'entered') {
result.value = hlp.getTimeOfText(String(value), now);
if (result.value !== null) {
result.value = hlp.normalizeDate(result.value, offset, multiplier, next, days);
}
result.fix = true;
} else if (vType === 'pdsTime') {
// sun
result = node.getSunTime(now, value, offset, multiplier, next, days);
result.fix = true;
} else if (vType === 'pdmTime') {
// moon
result = node.getMoonTime(now, value, offset, multiplier, next, days);
result.fix = true;
try {
if (vType === '' || vType === 'none' || days === '') {
// nix
} else if (vType === 'date') {
result.value = hlp.normalizeDate(now, offset, multiplier, next, days);
result.fix = true;
} else if (vType === 'entered') {
result.value = hlp.getTimeOfText(String(value), now);
if (result.value !== null) {
result.value = hlp.normalizeDate(result.value, offset, multiplier, next, days);
}
result.fix = true;
} else if (vType === 'pdsTime') {
// sun
result = node.getSunTime(now, value, offset, multiplier, next, days);
result.fix = true;
} else if (vType === 'pdmTime') {
// moon
result = node.getMoonTime(now, value, offset, multiplier, next, days);
result.fix = true;
} else {
// can handle context, json, jsonata, env, ...
result.fix = (vType === 'json'); // is not a fixed time if can be changed
const res = RED.util.evaluateNodeProperty(value, vType, _srcNode, msg);
if (res) {
result.value = hlp.getDateOfText(res);
result.value = hlp.normalizeDate(result.value, offset, multiplier, next, days);
// node.debug(String(res) + ' -- ' + result.value);
} else {
// can handle context, json, jsonata, env, ...
result.fix = (vType === 'json'); // is not a fixed time if can be changed
const res = RED.util.evaluateNodeProperty(value, vType, _srcNode, msg);
if (res) {
result.value = hlp.getDateOfText(res);
result.value = hlp.normalizeDate(result.value, offset, multiplier, next, days);
// node.debug(String(res) + ' -- ' + result.value);
} else {
result.error = 'could not evaluate ' + vType + '.' + value;
}
result.error = 'could not evaluate ' + vType + '.' + value;
}
} catch (err) {
result.error = 'could not evaluate ' + vType + '=' + value + ': ' + err.message;
node.debug(util.inspect(err, Object.getOwnPropertyNames(err)));
}
} catch (err) {
node.debug(util.inspect(err, Object.getOwnPropertyNames(err)));
const e = new Error('Error "${err.message}", could not evaluate ' + vType + '.' + value);
e.original = err;
e.stack = e.stack.split('\n').slice(0,2).join('\n')+'\n'+err.stack;
throw e;
}
if (!result.value) {
if (!result.error) {
result.error = 'Can not get time for ' + vType + '=' + value;
}
result.value = now;
if (!result.value) {
if (!result.error) {
result.error = 'Can not get time for ' + vType + '=' + value;
}
// node.debug('getTimeProp result' + util.inspect(result));
return result;
};
result.value = now;
}
/**************************************************************************************************************/
this.getSunCalc = date => {
if (typeof date === 'string') {
// node.debug('getSunCalc for date ' + date);
const dto = new Date(date);
if (dto !== 'Invalid Date' && !isNaN(dto)) {
date = dto;
}
// node.debug('getTimeProp result' + util.inspect(result));
return result;
};
/**************************************************************************************************************/
this.getSunCalc = date => {
if (typeof date === 'string') {
// node.debug('getSunCalc for date ' + date);
const dto = new Date(date);
if (dto !== 'Invalid Date' && !isNaN(dto)) {
date = dto;
}
}
if ((typeof date === 'undefined') || !(date instanceof Date)) {
// node.debug('getSunCalc, no valid date ' + date + ' given');
date = new Date();
if (Math.abs(date.getTime() - this.lastSunCalc.ts) < 4000) {
// node.debug('getSunCalc, time difference since last output to low, do no calculation');
return this.lastSunCalc;
}
if ((typeof date === 'undefined') || !(date instanceof Date)) {
// node.debug('getSunCalc, no valid date ' + date + ' given');
date = new Date();
if (Math.abs(date.getTime() - this.lastSunCalc.ts) < 4000) {
// node.debug('getSunCalc, time difference since last output to low, do no calculation');
return this.lastSunCalc;
}
}
const sunPos = sunCalc.getPosition(date, node.latitude, node.longitude);
const result = {
ts: date.getTime(),
lastUpdate: date,
latitude: node.latitude,
longitude: node.longitude,
angleType: node.angleType,
azimuth: (node.angleType === 'deg') ? 180 + 180 / Math.PI * sunPos.azimuth : sunPos.azimuth,
altitude: (node.angleType === 'deg') ? 180 / Math.PI * sunPos.altitude : sunPos.altitude // elevation = altitude
};
sunTimesCheck(node);
result.times = node.sunTimesToday;
this.lastSunCalc = result;
return result;
const sunPos = sunCalc.getPosition(date, node.latitude, node.longitude);
const result = {
ts: date.getTime(),
lastUpdate: date,
latitude: node.latitude,
longitude: node.longitude,
angleType: node.angleType,
azimuth: (node.angleType === 'deg') ? 180 + 180 / Math.PI * sunPos.azimuth : sunPos.azimuth,
altitude: (node.angleType === 'deg') ? 180 / Math.PI * sunPos.altitude : sunPos.altitude // elevation = altitude
};
sunTimesCheck(node);
result.times = node.sunTimesToday;
this.lastSunCalc = result;
/**************************************************************************************************************/
this.getMoonCalc = date => {
if (typeof date === 'string') {
const dto = new Date(date);
if (dto !== 'Invalid Date' && !isNaN(dto)) {
date = dto;
}
return result;
};
/**************************************************************************************************************/
this.getMoonCalc = date => {
if (typeof date === 'string') {
const dto = new Date(date);
if (dto !== 'Invalid Date' && !isNaN(dto)) {
date = dto;
}
}
if ((typeof date === 'undefined') || !(date instanceof Date)) {
date = new Date();
if (Math.abs(date.getTime() - this.lastMoonCalc.ts) < 3000) {
return this.lastMoonCalc;
}
if ((typeof date === 'undefined') || !(date instanceof Date)) {
date = new Date();
if (Math.abs(date.getTime() - this.lastMoonCalc.ts) < 3000) {
return this.lastMoonCalc;
}
}
const moonPos = sunCalc.getMoonPosition(date, node.latitude, node.longitude);
const moonIllum = sunCalc.getMoonIllumination(date);
const moonPos = sunCalc.getMoonPosition(date, node.latitude, node.longitude);
const moonIllum = sunCalc.getMoonIllumination(date);
const result = {
ts: date.getTime(),
lastUpdate: date,
latitude: node.latitude,
longitude: node.longitude,
angleType: node.angleType,
azimuth: (node.angleType === 'deg') ? 180 + 180 / Math.PI * moonPos.azimuth : moonPos.azimuth,
altitude: (node.angleType === 'deg') ? 180 / Math.PI * moonPos.altitude : moonPos.altitude, // elevation = altitude
distance: moonPos.distance,
parallacticAngle: (node.angleType === 'deg') ? 180 / Math.PI * moonPos.parallacticAngle : moonPos.parallacticAngle,
illumination: {
angle: (node.angleType === 'deg') ? 180 / Math.PI * moonIllum.angle : moonIllum.angle,
fraction: moonIllum.fraction,
phase: {},
zenithAngle: (node.angleType === 'deg') ? 180 / Math.PI * (moonIllum.angle - moonPos.parallacticAngle) : moonIllum.angle - moonPos.parallacticAngle
}
};
sunTimesCheck(node);
result.times = node.moonTimesToday;
// getAngle : angle / 57.2957795130823209 //angle(rad) * (180° / Pi) = angle(deg)
if (moonIllum.phase < 0.01) {
// 0 New Moon - Neumond(Phasenwinkel = 0°)
result.illumination.phase = moonPhases[0];
} else if (moonIllum.phase < 0.25) {
// 0 - 0.25 Waxing Crescent - erstes Viertel bzw. zunehmende Sichel(0° < Phasenwinkel < 90°),
result.illumination.phase = moonPhases[1];
} else if (moonIllum.phase < 0.26) {
// 0.25 First Quarter - zunehmender Halbmond(astronomisch: erstes Viertel, Phasenwinkel = 90°),
result.illumination.phase = moonPhases[2];
} else if (moonIllum.phase < 0.50) {
// 0.25 - 0.5 Waxing Gibbous - zweites Viertel(90° < Phasenwinkel < 180°),
result.illumination.phase = moonPhases[3];
} else if (moonIllum.phase < 0.51) {
// 0.5 Full Moon - Vollmond(Phasenwinkel = 180°),
result.illumination.phase = moonPhases[4];
} else if (moonIllum.phase <= 0.75) {
// 0.5 - 0.75 Waning Gibbous - drittes Viertel (180° < Phasenwinkel < 270°),
result.illumination.phase = moonPhases[5];
} else if (moonIllum.phase < 0.76) {
// 0.75 Last Quarter - abnehmender Halbmond(astronomisch: letztes Viertel, Phasenwinkel = 270°),
result.illumination.phase = moonPhases[6];
} else {
// Waning Crescent - letztes Viertel bzw. abnehmende Sichel(Phasenwinkel > 270°).
result.illumination.phase = moonPhases[7];
const result = {
ts: date.getTime(),
lastUpdate: date,
latitude: node.latitude,
longitude: node.longitude,
angleType: node.angleType,
azimuth: (node.angleType === 'deg') ? 180 + 180 / Math.PI * moonPos.azimuth : moonPos.azimuth,
altitude: (node.angleType === 'deg') ? 180 / Math.PI * moonPos.altitude : moonPos.altitude, // elevation = altitude
distance: moonPos.distance,
parallacticAngle: (node.angleType === 'deg') ? 180 / Math.PI * moonPos.parallacticAngle : moonPos.parallacticAngle,
illumination: {
angle: (node.angleType === 'deg') ? 180 / Math.PI * moonIllum.angle : moonIllum.angle,
fraction: moonIllum.fraction,
phase: {},
zenithAngle: (node.angleType === 'deg') ? 180 / Math.PI * (moonIllum.angle - moonPos.parallacticAngle) : moonIllum.angle - moonPos.parallacticAngle
}
};
sunTimesCheck(node);
result.times = node.moonTimesToday;
// getAngle : angle / 57.2957795130823209 //angle(rad) * (180° / Pi) = angle(deg)
result.illumination.phase.value = moonIllum.phase;
result.illumination.phase.angle = (node.angleType === 'rad') ? (moonIllum.phase * 360) / (180 / Math.PI) : moonIllum.phase * 360;
if (moonIllum.phase < 0.01) {
// 0 New Moon - Neumond(Phasenwinkel = 0°)
result.illumination.phase = moonPhases[0];
} else if (moonIllum.phase < 0.25) {
// 0 - 0.25 Waxing Crescent - erstes Viertel bzw. zunehmende Sichel(0° < Phasenwinkel < 90°),
result.illumination.phase = moonPhases[1];
} else if (moonIllum.phase < 0.26) {
// 0.25 First Quarter - zunehmender Halbmond(astronomisch: erstes Viertel, Phasenwinkel = 90°),
result.illumination.phase = moonPhases[2];
} else if (moonIllum.phase < 0.50) {
// 0.25 - 0.5 Waxing Gibbous - zweites Viertel(90° < Phasenwinkel < 180°),
result.illumination.phase = moonPhases[3];
} else if (moonIllum.phase < 0.51) {
// 0.5 Full Moon - Vollmond(Phasenwinkel = 180°),
result.illumination.phase = moonPhases[4];
} else if (moonIllum.phase <= 0.75) {
// 0.5 - 0.75 Waning Gibbous - drittes Viertel (180° < Phasenwinkel < 270°),
result.illumination.phase = moonPhases[5];
} else if (moonIllum.phase < 0.76) {
// 0.75 Last Quarter - abnehmender Halbmond(astronomisch: letztes Viertel, Phasenwinkel = 270°),
result.illumination.phase = moonPhases[6];
} else {
// Waning Crescent - letztes Viertel bzw. abnehmende Sichel(Phasenwinkel > 270°).
result.illumination.phase = moonPhases[7];
}
if (!result.times.alwaysUp) {
// true if the moon never rises/sets and is always above the horizon during the day
result.times.alwaysUp = false;
}
result.illumination.phase.value = moonIllum.phase;
result.illumination.phase.angle = (node.angleType === 'rad') ? (moonIllum.phase * 360) / (180 / Math.PI) : moonIllum.phase * 360;
if (!result.times.alwaysDown) {
// true if the moon is always below the horizon
result.times.alwaysDown = false;
}
if (!result.times.alwaysUp) {
// true if the moon never rises/sets and is always above the horizon during the day
result.times.alwaysUp = false;
}
this.lastMoonCalc = result;
if (!result.times.alwaysDown) {
// true if the moon is always below the horizon
result.times.alwaysDown = false;
}
return result;
};
this.lastMoonCalc = result;
/**************************************************************************************************************/
return result;
};
/**************************************************************************************************************/
try {
initTimes(this);
} catch (err) {
hlp.handleError(this, RED._('position-config.errors.error-text'), err, RED._('position-config.errors.error-title'));
this.debug(util.inspect(err, Object.getOwnPropertyNames(err)));
node.status({
fill: 'red',
shape: 'ring',
text: RED._('position-config.errors.error-title')
});
throw err;
}

@@ -478,0 +505,0 @@ /**************************************************************************************************************/

@@ -80,7 +80,8 @@ /************************************************************************/

{id: 1, group: 'string', label: 'ECMA-262', add: 'standard JSON Date representation'},
{id: 2, group: 'string', label: 'various - try different Formats, prefer European formats', add: 'will try different formats, prefer European formats'},
{id: 3, group: 'string', label: 'various - try different Formats, prefer American formats', add: 'will try different formats, prefer American formats'},
{id: 2, group: 'string', label: 'try different text Formats, prefer day first like d/M/y (e.g. European format)', add: 'will try different formats, prefer European formats'},
{id: 3, group: 'string', label: 'try different text Formats, prefer month first like M/d/y (e.g. American format)', add: 'will try different formats, prefer American formats'},
{id: 4, group: 'number', label: 'YYYYMMDDHHMMSS', add: 'xxx'},
{id: 5, group: 'number', label: 'YYYYMMDD.HHMMSS', add: 'xxx'},
{id: 99, group: 'other', label: 'free definition', add: 'xxx'}
{id: 98, group: 'other', label: 'various - try different Formats (object, number, text)', add: 'xxx'},
{id: 99, group: 'other', label: 'text - free definition', add: 'xxx'}
], multiplierGroups: [

@@ -137,2 +138,12 @@ {id: 'default', label: 'Standard'},

},
MsgLc: {
value: 'msgLc',
label: 'msg.lc',
hasValue: false
},
MsgValue: {
value: 'msgValue',
label: 'msg.value',
hasValue: false
},
TimeEntered: {

@@ -230,4 +241,7 @@ value: 'entered',

{label: 'ss Second (2 digits)', value: 'ss'},
{label: 'll Milliseconds (2 digits)', value: 'll'},
{label: 'l Milliseconds (1-3 digits)', value: 'l'},
{label: 'll Milliseconds (2/3 digits)', value: 'll'},
{label: 'lll Milliseconds (3 digits)', value: 'lll'},
{label: 'L Milliseconds (1 digit rounded)', value: 'L'},
{label: 'LL Milliseconds (2 digits rounded)', value: 'LL'},
{label: 't AM/PM (1 digit)', value: 't'},

@@ -268,2 +282,4 @@ {label: 'tt AM/PM (2 digits)', value: 'tt'}

{label: 'lll Milliseconds (3 digits 000-999)', value: 'lll'},
{label: 'L Milliseconds (1 digit rounded)', value: 'L'},
{label: 'LL Milliseconds (2 digits rounded)', value: 'LL'},
{label: 'tl total Milliseconds (0-999)', value: 'l'},

@@ -301,4 +317,6 @@ {label: 'tll total Milliseconds (2 digits 00-99)', value: 'll'},

{label: 'l Milliseconds (0-999)', value: 'l'},
{label: 'll Milliseconds (2 digits 00-99)', value: 'll'},
{label: 'll Milliseconds (2/3 digits 00-999)', value: 'll'},
{label: 'lll Milliseconds (3 digits 000-999)', value: 'lll'},
{label: 'L Milliseconds (round to 1 digit 0-9)', value: 'L'},
{label: 'LL Milliseconds (round to 2 digits 00-99)', value: 'LL'},
{label: 't AM/PM (1 digit - Lowercase)', value: 't'},

@@ -540,3 +558,3 @@ {label: 'tt AM/PM (2 digits - Lowercase)', value: 'tt'},

/**
* adds a multiselect combobox to the form
* adds a multiselect combo box to the form
* @param {*} node Node Red Source Node

@@ -611,4 +629,2 @@ * @param {*} parent Parent jQuery Element to add multiselect

return multiselect;
}
// #endregion functions
}

@@ -59,3 +59,9 @@ /********************************************

} catch (err) {
hlp.handleError(this, 'Exception occurred on sun-position', err, 'internal error');
node.error(err.message);
node.debug(util.inspect(err, Object.getOwnPropertyNames(err)));
node.status({
fill: 'red',
shape: 'ring',
text: 'internal error'
});
}

@@ -62,0 +68,0 @@ // this.error("Input parameter wrong or missing. You need to setup (or give in the input message) the 'URL' and 'content type' or the 'message' and 'language'!!");

@@ -23,3 +23,3 @@ /********************************************

node.debug('config ' + util.inspect(config)); // eslint-disable-line
node.debug('on input - msg ' + util.inspect(msg)); // eslint-disable-line
node.debug('emit - msg ' + util.inspect(msg)); // eslint-disable-line
if (node.positionConfig === null ||

@@ -38,11 +38,10 @@ config.operator === null ||

try {
node.debug('emit ' + util.inspect(msg));
const offset1 = node.positionConfig.getFloatProp(node,msg,config.inputOffsetType, config.inputOffset);
const inputData = node.positionConfig.getDateFromProp(node, msg, config.inputType, config.input, config.inputFormat, offset1, config.inputOffsetMultiplier);
node.debug('inputData ' + util.inspect(inputData));
node.debug('inputData ' + util.inspect(inputData)); // eslint-disable-line
if (config.result1Type !== 'none') {
let resultObj = null;
if (config.result1Type === 'input') {
resultObj = hlp.getFormattedDateOut(inputData, config.result1Format, RED._('time-comp.days'), RED._('time-comp.month'), RED._('time-comp.dayDiffNames'));
if (config.result1ValueType === 'input') {
resultObj = node.positionConfig.formatOutDate(inputData, config.result1Format);
} else {

@@ -205,5 +204,14 @@ resultObj = node.positionConfig.getOutDataProp(node, msg, config.result1ValueType, config.result1Value, config.result1Format, config.result1Offset, config.result1Multiplier);

node.debug('result object ' + util.inspect(resObj)); // eslint-disable-line
node.status({
text: inputData.toISOString()
});
node.send(resObj);
} catch (err) {
hlp.handleError(node, RED._('time-comp.errors.error-text'), err, RED._('time-comp.errors.error-title'));
node.debug(util.inspect(err, Object.getOwnPropertyNames(err)));
node.status({
fill: 'red',
shape: 'ring',
text: RED._('time-comp.errors.error-title')
});
throw err;
}

@@ -210,0 +218,0 @@ });

@@ -16,61 +16,16 @@ /********************************************

const now = new Date();
let milis = time.getTime() - now.getTime();
let millisec = time.getTime() - now.getTime();
if (limit) {
while (milis < limit) {
milis += 86400000; // 24h
while (millisec < limit) {
millisec += 86400000; // 24h
}
}
return milis;
return millisec;
}
function tsGetPropData(node, msg, type, value, format, offset, offsetType, multiplier, days) {
if (type === null || type === 'none' || type === '' || (typeof type === 'undefined')) {
if (value === '' || (typeof value === 'undefined')) {
const offsetX = this.positionConfig.getFloatProp(node,offsetType, offset);
const result = hlp.addOffset(Date.now(), offsetX, multiplier);
return hlp.getFormattedDateOut(result, format, RED._('time-inject.days'), RED._('time-inject.month'), RED._('time-inject.dayDiffNames'));
}
return value;
} else if (type === 'pdsCalcData') {
return node.positionConfig.getSunCalc(msg.ts);
} else if (type === 'pdmCalcData') {
return node.positionConfig.getMoonCalc(msg.ts);
} else if (type === 'msgPayload') {
return msg.payload;
} else if (type === 'msgTs') {
return msg.ts;
} else if ((type === 'pdsTime') ||
(type === 'pdmTime')) {
let result;
const offsetX = this.positionConfig.getFloatProp(node,offsetType, offset);
if (type === 'pdsTime') { // sun
result = node.getSunTime(Date.now(), value, offsetX, multiplier, days);
} else if (type === 'pdmTime') { // moon
result = node.getMoonTime(Date.now(), value, offsetX, multiplier, days);
}
if (result && result.value && !result.error) {
return hlp.getFormattedDateOut(result, format, RED._('time-inject.days'), RED._('time-inject.month'), RED._('time-inject.dayDiffNames'));
}
return null;
} else if (type === 'entered' || type === 'dateEntered') {
let result = hlp.getDateOfText(String(value));
const offsetX = this.positionConfig.getFloatProp(node,offsetType, offset);
result = hlp.normalizeDate(result, offsetX, multiplier, 1, days);
return hlp.getFormattedDateOut(result, format, RED._('time-inject.days'), RED._('time-inject.month'), RED._('time-inject.dayDiffNames'));
} else if (type === 'dayOfMonth') {
let result = new Date();
result = hlp.getSpecialDayOfMonth(result.getFullYear(),result.getMonth(), value);
if (result !== null && typeof result !== 'undefined') {
result = hlp.addOffset(result, offset, multiplier);
return hlp.getFormattedDateOut(result, format, RED._('position-config.days'), RED._('position-config.month'), RED._('position-config.dayDiffNames'));
}
return null;
}
return RED.util.evaluateNodeProperty(value, type, node, msg);
}
function tsSetAddProp(node, msg, type, name, valueType, value, format, offset, offsetType, multiplier, days) {
if (type !== 'none' && name) {
const res = tsGetPropData(node, msg, valueType, value, format, offset, offsetType, multiplier, days);
const offsetX = this.positionConfig.getFloatProp(node,offsetType, offset);
const res = node.positionConfig.getOutDataProp(node, msg, valueType, value, format, offsetX, multiplier, days);
if (res === null || (typeof res === 'undefined')) {

@@ -80,2 +35,8 @@ throw new Error('could not evaluate ' + valueType + '.' + value);

this.error('error on getting additional payload 1: ' + res.error);
} else if (type === 'msgPayload') {
msg.payload = res;
} else if (type === 'msgTs') {
msg.ts = res;
} else if (type === 'msgValue') {
msg.value = res;
} else if (type === 'msg' || type === 'msgProperty') {

@@ -128,3 +89,9 @@ RED.util.setMessageProperty(msg, name, res);

} catch (err) {
hlp.handleError(this, RED._('time-inject.errors.error-text'), err, RED._('time-inject.errors.error-title'));
node.error(err.message);
node.debug(util.inspect(err, Object.getOwnPropertyNames(err)));
node.status({
fill: 'red',
shape: 'ring',
text: RED._('time-inject.errors.error-title')
});
}

@@ -198,8 +165,8 @@ }, 360000); // 6 Minuten

let milis = tsGetScheduleTime(node.nextTime, 10);
let millisec = tsGetScheduleTime(node.nextTime, 10);
const isAlt = (node.nextTimeAlt);
if (isAlt) {
const milisAlt = tsGetScheduleTime(node.nextTimeAlt, 10);
if (milisAlt < milis) {
milis = milisAlt;
const millisecAlt = tsGetScheduleTime(node.nextTimeAlt, 10);
if (millisecAlt < millisec) {
millisec = millisecAlt;
isAltFirst = true;

@@ -209,3 +176,3 @@ }

// node.debug('timeout ' + node.nextTime + ' is in ' + milis + 'ms (isAlt=' + isAlt + ' isAltFirst=' + isAltFirst + ')');
// node.debug('timeout ' + node.nextTime + ' is in ' + millisec + 'ms (isAlt=' + isAlt + ' isAltFirst=' + isAltFirst + ')');
node.timeOutObj = setTimeout((isAlt, isAltFirst) => {

@@ -237,3 +204,9 @@ const msg = {

} catch (err) {
hlp.handleError(node, RED._('time-inject.errors.error-text'), err, RED._('time-inject.errors.error-title'));
node.error(err.message);
node.debug(util.inspect(err, Object.getOwnPropertyNames(err)));
node.status({
fill: 'red',
shape: 'ring',
text: RED._('time-inject.errors.error-title')
});
}

@@ -250,3 +223,3 @@ return;

node.emit('input', msg);
}, milis, isAlt, isAltFirst);
}, millisec, isAlt, isAltFirst);
}

@@ -321,3 +294,4 @@

const value = tsGetPropData(this, msg, config.payloadType, config.payload, config.payloadTimeFormat, node.payloadOffset, config.payloadOffsetType, config.payloadOffsetMultiplier);
const offsetX = this.positionConfig.getFloatProp(node, node.payloadOffset, config.payloadOffsetType);
const value = node.positionConfig.getOutDataProp(node, msg, config.payloadType, config.payload, config.payloadTimeFormat, offsetX, config.payloadOffsetMultiplier);
if (value === null || (typeof value === 'undefined')) {

@@ -340,3 +314,9 @@ throw new Error('could not evaluate ' + config.payloadType + '.' + config.payload);

} catch (err) {
hlp.handleError(this, RED._('time-inject.errors.error-text'), err, RED._('time-inject.errors.error-title'));
node.error(err.message);
node.debug(util.inspect(err, Object.getOwnPropertyNames(err)));
node.status({
fill: 'red',
shape: 'ring',
text: RED._('time-inject.errors.error-title')
});
}

@@ -361,3 +341,9 @@ });

} catch (err) {
hlp.handleError(this, RED._('time-inject.errors.error-text'), err, RED._('time-inject.errors.error-title'));
node.error(err.message);
node.debug(util.inspect(err, Object.getOwnPropertyNames(err)));
node.status({
fill: 'red',
shape: 'ring',
text: RED._('time-inject.errors.error-title')
});
}

@@ -370,3 +356,9 @@ return;

} catch (err) {
hlp.handleError(this, RED._('time-inject.errors.error-text'), err, RED._('time-inject.errors.error-title'));
node.error(err.message);
node.debug(util.inspect(err, Object.getOwnPropertyNames(err)));
node.status({
fill: 'red',
shape: 'ring',
text: RED._('time-inject.errors.error-title')
});
}

@@ -373,0 +365,0 @@ }

@@ -7,7 +7,5 @@ /********************************************

const path = require('path');
// const path = require('path');
// const hlp = require(path.join(__dirname, '/lib/dateTimeHelper.js'));
const hlp = require(path.join(__dirname, '/lib/dateTimeHelper.js'));
// const def = require(path.join(__dirname, '/lib/genericDefinitions.js'));
const perSecond = 1000;

@@ -75,3 +73,3 @@ const perMinute = 60000;

const L = timeSpan % 1000;
const l = timeSpan % 1000;
const s = Math.floor(timeSpan / perSecond) % 60;

@@ -119,9 +117,11 @@ const m = Math.floor(timeSpan / perMinute) % 60;

tss: pad(ts),
lll: pad(L, 3),
ll: pad(Math.round(L / 10)),
l: L,
l,
ll: pad(l),
lll: pad(l, 3),
L: Math.round(l / 100),
LL: pad(Math.round(l / 10)),
LLL: pad(l, 3),
tl,
tll: pad(Math.round(tl / 10)),
tlll: pad(tl, 3),
tll: pad(Math.round(tl / 10)),
tl,
L: pad(L > 99 ? Math.round(L / 10) : L),
t: H < 12 ? 'a' : 'p',

@@ -231,72 +231,3 @@ tt: H < 12 ? 'am' : 'pm',

'use strict';
/*
function tsGetOperandData(node, msg, type, value, format, offset, multiplier) {
let result = {};
if (type === null || type === 'none' || type === '') {
return Date.now();
}
if (type === 'entered' ||
type === 'pdsTime' ||
type === 'pdmTime' ||
type === 'date'
) {
result = node.positionConfig.getTimeProp(node, msg, type, value, offset, multiplier);
if (result === null) {
throw new Error('could not evaluate ' + type + '.' + value);
} else if (result.error) {
throw new Error('error on getting operand: ' + result.error);
}
return result.value;
}
let data;
if (type === 'msgPayload') {
data = msg.payload;
} else if (type === 'msgTs') {
data = msg.ts;
} else {
// msg, flow, global, str, num, env
data = RED.util.evaluateNodeProperty(value, type, node, msg);
}
if (data === null || typeof data === 'undefined') {
throw new Error('could not evaluate ' + type + '.' + value);
}
result.value = hlp.parseDateFromFormat(data, format, RED._('time-span.days'), RED._('time-span.month'), RED._('time-span.dayDiffNames'));
if (result.value === 'Invalid Date' || isNaN(result.value) || result.value === null) {
throw new Error('could not evaluate format of ' + data);
}
return hlp.addOffset(result.value, offset, multiplier);
}
function tsGetPropData(node, msg, type, value, format, offset, multiplier, days) {
if (type === null || type === 'none' || type === '') {
if (value === '' || typeof value === 'undefined') {
return Date.now();
}
return value;
}
if (type === 'pdsCalcData') {
return node.positionConfig.getSunCalc(msg.ts);
}
if (type === 'pdmCalcData') {
return node.positionConfig.getMoonCalc(msg.ts);
}
if (type === 'entered' ||
type === 'pdsTime' ||
type === 'pdmTime' ||
type === 'date') {
const data = node.positionConfig.getTimeProp(node, msg, type, value, offset, multiplier, 1, days);
if (!data.error) {
return hlp.getFormattedDateOut(data.value, format, RED._('time-span.days'), RED._('time-span.month'), RED._('time-span.dayDiffNames'));
}
return data;
}
return RED.util.evaluateNodeProperty(value, type, node, msg);
} /* */
function timeSpanNode(config) {

@@ -309,4 +240,4 @@ RED.nodes.createNode(this, config);

this.on('input', msg => {
node.debug('config ' + util.inspect(config)); // eslint-disable-line
node.debug('on input - msg ' + util.inspect(msg)); // eslint-disable-line
node.debug('config ' + util.inspect(config)); // eslint-disable-line
node.debug('emit - msg ' + util.inspect(msg)); // eslint-disable-line
if (node.positionConfig === null ||

@@ -342,34 +273,32 @@ config.operand1Type === null ||

if (config.result1Type !== 'none') {
let resObj = null;
node.debug('resObj1 ' + util.inspect(config.result1ValueType) + ' + ' + util.inspect(config.result1Format)); // eslint-disable-line
let resultObj = null;
node.debug('resultObj1 ' + util.inspect(config.result1ValueType) + ' + ' + util.inspect(config.result1Format)); // eslint-disable-line
if (config.result1ValueType === 'timespan') {
resObj = getFormattedTimeSpanOut(operand1, operand2, config.result1TSFormat);
resultObj = getFormattedTimeSpanOut(operand1, operand2, config.result1TSFormat);
} else if (config.result1ValueType === 'operand1') {
resObj = hlp.getFormattedDateOut(operand1, config.result1Format, RED._('time-span.days'), RED._('time-span.month'), RED._('time-span.dayDiffNames'));
resultObj = node.positionConfig.formatOutDate(operand1, config.result1Format);
} else if (config.result1ValueType === 'operand2') {
resObj = hlp.getFormattedDateOut(operand2, config.result1Format, RED._('time-span.days'), RED._('time-span.month'), RED._('time-span.dayDiffNames'));
resultObj = node.positionConfig.formatOutDate(operand2, config.result1Format);
} else {
const resOffset = node.positionConfig.getFloatProp(node,msg,config.result1OffsetType, config.result1Offset);
resObj = node.positionConfig.getOutDataProp(node, msg, config.result1ValueType, config.result1Value, config.result1Format, resOffset, config.result1Multiplier);
resultObj = node.positionConfig.getOutDataProp(node, msg, config.result1ValueType, config.result1Value, config.result1Format, resOffset, config.result1Multiplier);
}
// to
node.debug('resObj1 ' + util.inspect(resObj)); // eslint-disable-line
if (config.result1Type === 'msgPayload') {
config.result1Type = 'msg';
config.result1 = 'payload';
}
if (config.result1Type === 'msgTs') {
config.result1Type = 'msg';
config.result1 = 'ts';
}
node.debug('resObj2 ' + util.inspect(resObj)); // eslint-disable-line
if (resObj === null) {
node.debug('resultObj1 ' + util.inspect(resultObj)); // eslint-disable-line
node.debug('resultObj2 ' + util.inspect(resultObj)); // eslint-disable-line
if (resultObj === null) {
throw new Error('could not evaluate ' + config.result1ValueType + '.' + config.result1Value);
} else if (resObj.error) {
node.error('error on getting result: ' + resObj.error);
} else if (resultObj.error) {
node.error('error on getting result: ' + resultObj.error);
} else if (config.result1Type === 'msgPayload') {
msg.payload = resultObj;
} else if (config.result1Type === 'msgTs') {
msg.ts = resultObj;
} else if (config.result1Type === 'msgValue') {
msg.value = resultObj;
} else if (config.result1Type === 'msg' || config.result1Type === 'msgProperty') {
RED.util.setMessageProperty(msg, config.result1, resObj);
RED.util.setMessageProperty(msg, config.result1, resultObj);
} else if (config.result1Type === 'flow' || config.result1Type === 'global') {
const contextKey = RED.util.parseContextStore(config.result1);
node.context()[config.result1Type].set(contextKey.key, resObj, contextKey.store);
node.context()[config.result1Type].set(contextKey.key, resultObj, contextKey.store);
}

@@ -425,3 +354,9 @@ }

} catch (err) {
hlp.handleError(node, RED._('time-span.errors.error-text'), err, RED._('time-span.errors.error-title'));
node.error(err.message);
node.debug(util.inspect(err, Object.getOwnPropertyNames(err)));
node.status({
fill: 'red',
shape: 'ring',
text: err.message
});
resObj.push(null);

@@ -439,5 +374,15 @@ continue;

node.debug('result object ' + util.inspect(resObj)); // eslint-disable-line
node.status({
text: (operand1.getTime() - operand2.getTime()) / 1000 + 's'
});
node.send(resObj);
} catch (err) {
hlp.handleError(node, RED._('time-span.errors.error-text'), err, RED._('time-span.errors.error-title'));
node.debug(util.inspect(err, Object.getOwnPropertyNames(err)));
node.status({
fill: 'red',
shape: 'ring',
text: RED._('time-span.errors.error-title')
});
throw err;
}

@@ -444,0 +389,0 @@ });

@@ -228,3 +228,9 @@ /********************************************

} catch (err) {
hlp.handleError(this, RED._('within-time-switch.errors.error-text'), err, RED._('within-time-switch.errors.error-title'));
node.error(err.message);
node.debug(util.inspect(err, Object.getOwnPropertyNames(err)));
node.status({
fill: 'red',
shape: 'ring',
text: RED._('within-time-switch.errors.error-title')
});
}

@@ -244,3 +250,9 @@ });

} catch (err) {
hlp.handleError(this, RED._('within-time-switch.errors.error-text'), err, RED._('within-time-switch.errors.error-title'));
node.error(err.message);
node.debug(util.inspect(err, Object.getOwnPropertyNames(err)));
node.status({
fill: 'red',
shape: 'ring',
text: RED._('within-time-switch.errors.error-title')
});
}

@@ -250,3 +262,9 @@ }, 360000); // 6 Minuten

} catch (err) {
hlp.handleError(this, RED._('within-time-switch.errors.error-text'), err, RED._('within-time-switch.errors.error-title'));
node.error(err.message);
node.debug(util.inspect(err, Object.getOwnPropertyNames(err)));
node.status({
fill: 'red',
shape: 'ring',
text: RED._('within-time-switch.errors.error-title')
});
}

@@ -253,0 +271,0 @@ }

{
"name": "node-red-contrib-sun-position",
"version": "0.2.0-alpha.3",
"version": "0.2.0-alpha.4",
"description": "NodeRED nodes to get sun and moon position",

@@ -5,0 +5,0 @@ "keywords": [

@@ -107,3 +107,3 @@ # node-red-contrib-sun-position for NodeRED

- **Topic** defines the topic of the first output
- **position container** here you can define multiple lower and upepr limits for azimuth. If the calculated value of the azimuth is inside the defined limit the input message will send to the associated output.
- **position container** here you can define multiple lower and upper limits for azimuth. If the calculated value of the azimuth is inside the defined limit the input message will send to the associated output.
- **Name** name of the Node

@@ -184,3 +184,3 @@

- **second output** to **... output** if limits for azimuth are defined the incomming message will send to this output. It adds a `msg.posChanged` property of type _boolean_ which is true if in the previous calculation no message was send to this output.
- **second output** to **... output** if limits for azimuth are defined the incoming message will send to this output. It adds a `msg.posChanged` property of type _boolean_ which is true if in the previous calculation no message was send to this output.

@@ -203,3 +203,3 @@ ### moon-position

- **Topic** defines the topic of the first output
- **position container** here you can define multiple lower and upepr limits for azimuth. If the calculated value of the azimuth is inside the defined limit the input message will send to the associated output.
- **position container** here you can define multiple lower and upper limits for azimuth. If the calculated value of the azimuth is inside the defined limit the input message will send to the associated output.
- **Name** name of the Node

@@ -266,7 +266,7 @@

- **second output** to **... output** if limits for azimuth are defined the incomming message will send to this output. It adds a `msg.payload.posChanged` property of type _boolean_ which is true if the limit has changed since the last azimuth calculation.
- **second output** to **... output** if limits for azimuth are defined the incoming message will send to this output. It adds a `msg.payload.posChanged` property of type _boolean_ which is true if the limit has changed since the last azimuth calculation.
### time-inject
Injects a message into a flow either manually or at timestamps which can also depending on the sunset, sunrise, or moon set and rise. The message payload can be a variety of types, including strings, JavaScript objects, the current time or the cuttent sun or moon position.
Injects a message into a flow either manually or at timestamps which can also depending on the sunset, sunrise, or moon set and rise. The message payload can be a variety of types, including strings, JavaScript objects, the current time or the current sun or moon position.

@@ -287,13 +287,13 @@ ![time-inject](images/time-inject-example.png?raw=true)

- **Time** An optional property that can be [configured](#times-definitions) when the inject node should emit a message on that timestamp.
- **Offset** An optional property which is only available if an time is choosen. The offset can be a positive or negative and defines a time offset to the choosen time.
- **Days** An optional property which is only available if an time is choosen. There can be defined on which days a msg should be emited.
- **Offset** An optional property which is only available if an time is chosen. The offset can be a positive or negative and defines a time offset to the chosen time.
- **Days** An optional property which is only available if an time is chosen. There can be defined on which days a msg should be emitted.
- **Property** _optional_ here can be defined a context property which must be of tyxpe boolean. If this property is true alternate time will be used.
- **Property** _optional_ here can be defined a context property which must be of type boolean. If this property is true alternate time will be used.
- **Alternate time** _optional_ defines an alternate start time which will be used if the property is true. This can be used for different times for example of holidays/weekend.
- **Additional Inject on Start** If this checkbox is set the inject node dcan emit the message on Node-Red Start or on any deploy of this node. There can be defined a delay after the emit should be done. This can be usefull for initializing any flow.
- **Additional Inject on Start** If this checkbox is set the inject node can emit the message on Node-Red Start or on any deploy of this node. There can be defined a delay after the emit should be done. This can be useful for initializing any flow.
- **Set additional** With this selection you can
- set __global__, __flow__ context or set additional property of the message object (if the property is __payload__ the payload will be overridden.)
- for any timestamp properties like __timestamp__, __sun time__, __moon time__ there are a lot of possibilities to influence this. You can add an offset or select the days wherfor the timestamp should be calculated. The output format could be Unix, ECMA timestamp, object or the time difference between timestamp and emit the message. This is useful to to send a payload of true on sunset with an additional message oprperty as __on time__ with the seconds until sunrise.
- for any timestamp properties like __timestamp__, __sun time__, __moon time__ there are a lot of possibilities to influence this. You can add an offset or select the days wherefore the timestamp should be calculated. The output format could be Unix, ECMA timestamp, object or the time difference between timestamp and emit the message. This is useful to to send a payload of true on sunset with an additional message property as __on time__ with the seconds until sunrise.
- **set additional timestamp**:

@@ -303,3 +303,3 @@ ![time-inject](images/time-inject-settings-addProp1.png?raw=true)

![time-inject](images/time-inject-settings-addProp2.png?raw=true)
- **possible formates of timestamp output**
- **possible formats of timestamp output**
- number - milliseconds UNIX timestamp

@@ -358,4 +358,4 @@ - string - ECMA-262

- **Status** here can be adjusted which status should be displayed under the node.
- this has the following posibilities:
- **none** - no status will be displayed - **only errors** - if an error occures it will be displayed
- this has the following possibilities:
- **none** - no status will be displayed - **only errors** - if an error occurs it will be displayed
![within-time-status-error](images/within-time-status-error.png?raw=true)

@@ -366,5 +366,5 @@ - **time limits** - the time limits will be displayed. An `⎇` sign after a time will show that an alternate time is used.

![within-time-status-error](images/within-time-status-message-block.png?raw=true)
if the message was pass throught the timestamp of this message will be shown.
if the message was pass through the timestamp of this message will be shown.
![within-time-status-send](images/within-time-status-message-send.png?raw=true)
- **time limits or last message** - on deploy/start until a message arrives the same behaviour as `time limits` options, otherwise the `last message` status display.
- **time limits or last message** - on deploy/start until a message arrives the same behavior as `time limits` options, otherwise the `last message` status display.
- **resend start** If this checkbox is checked and a message arrived outside of time, this message will be additional send again some milliseconds after next start time point. This option is only for fixed time definitions available.

@@ -375,3 +375,3 @@ - **resend end** If this checkbox is checked and a message arrived within time, this message will be additional send again some milliseconds after next end time point. This option is only for fixed time definitions available.

A enhanced node for time format change and time comparision.
A enhanced node for time format change and time comparison.

@@ -398,7 +398,7 @@ ![time-comp](images/time-comp-example.png?raw=true)

- **operator** Drop down to define operator
- **compare type** allows to define whoat parts of the timestring shoudl be compared. Default is a comparision of the complete timestamp. But it is possible to only compare a pat like the only the year.
- **compare type** allows to define what parts of the time string should be compared. Default is a comparison of the complete timestamp. But it is possible to only compare a pat like the only the year.
- **time** defines where the time to which should be compared comes from
- **parse format** defines the format for the time to compare, more information see [input parse formats](#input-parse-formats).
- **Offset** allows to define a positive or negative offset to the given time.
- **limitation** here it is possible to additionally define a parameter. if defined this comparision will only be made if this parameter has the value "true".
- **limitation** here it is possible to additionally define a parameter. if defined this comparison will only be made if this parameter has the value "true".
- **result** allows to write the **Input time** to a parameter in a different format. Without defining any **compare with**, the node allows by only defining input and result parameter a simply time format conversation.

@@ -408,3 +408,3 @@

A enhanced node for time span calculation and time span comparision.
A enhanced node for time span calculation and time span comparison.

@@ -433,9 +433,9 @@ ![time-span](images/time-span-example.png?raw=true)

- **compare with** here can be defined various time spams to which the time span between timestamp of input 1 and input 2 should be compared.
- **operator** Drop down to define operator for comparision
- **operator** Drop down to define operator for comparison
- **time** defines a number to which should be the timespan be compared
- **time type** the unit of the given time
- **result** ** as result of an incomming message, data could be written to that destination. This could be a message property, a flow or a global context.
- **result** ** as result of an incoming message, data could be written to that destination. This could be a message property, a flow or a global context.
- **result value** defines the value which should be written to the result destination. Could be the timestamp, one of the Input times or any other time/data. For timestamp or times the output format or maybe an offset could be defined.
Without defining any comparision, the node allows by only defining inputs and result a simply timespan calculation.
Without defining any comparison, the node allows by only defining inputs and result a simply timespan calculation.

@@ -457,3 +457,3 @@ ### Times definitions

following Sun times can be choosen:
following Sun times can be chosen:

@@ -499,3 +499,3 @@ | Time | Description | SunBH |

The following time parameters are exists in the output for backwart compatibility. These are equal to parameters in the table above:
The following time parameters are exists in the output for backward compatibility. These are equal to parameters in the table above:

@@ -554,3 +554,3 @@ | time parameter | is equal to |

Day of Month | dd (2 digits) | d (1 or 2 digits)
Day of Week | EE (name) | E (abbr)
Day of Week | EE (name) | E (abbr.)
Hour (1-12) | hh (2 digits) | h (1 or 2 digits)

@@ -567,3 +567,3 @@ Hour (0-23) | HH (2 digits) | H (1 or 2 digits)

For timestamp outputs some nodes has the ability to define the format of the timestamp. Therfore different pre defined formates exists or a free format definition.
For timestamp outputs some nodes has the ability to define the format of the timestamp. Therefore different pre defined formats exists or a free format definition.

@@ -576,9 +576,9 @@ The formats are:

- **YYYYMMDD.HHMMSS** is a number of the format YYYYMMDD.HHMMSS.
- **local** is the javascript output of date.toLocaleString()
- **localLong** is the javascript output of date.toString()
- **localTime** is the javascript output of date.toLocaleTimeString()
- **localTimeLong** is the javascript output of date.toTimeString()
- **localDate** is the javascript output of date.toLocaleDateString()
- **localDateLong** is the javascript output of date.toDateString()
- **UTC** is the javascript output of date.toUTCString()
- **local** is the java script output of date.toLocaleString()
- **localLong** is the java script output of date.toString()
- **localTime** is the java script output of date.toLocaleTimeString()
- **localTimeLong** is the java script output of date.toTimeString()
- **localDate** is the java script output of date.toLocaleDateString()
- **localDateLong** is the java script output of date.toDateString()
- **UTC** is the java script output of date.toUTCString()
- **ISO** YYYY-MM-DDTHH:mm:ss.sssZ (output of date.toISOString())

@@ -591,9 +591,9 @@ - **ms** the time in milliseconds between output and timestamp

- **Day in relative** the timestamps day in relative to output time in the format Today, 22.12.
- **object** gived back an object for the timestamp with the following properties:
- **date** Javascript Date object
- **object** gives back an object for the timestamp with the following properties:
- **date** Java script Date object
- **ts** number - Unix timestamp (milliseconds since 1970-01-01 UTC)
- **timeUTCStr** string representation of the TIme in UTC format
- **timeISOStr** string representation of the TIme in ISO format
- **timeLocaleStr** the javascript output of date.toLocaleString()
- **timeLocaleTimeStr** the javascript output of date.toLocaleTimeString()
- **timeUTCStr** string representation of the Time in UTC format
- **timeISOStr** string representation of the Time in ISO format
- **timeLocaleStr** the java script output of date.toLocaleString()
- **timeLocaleTimeStr** the java script output of date.toLocaleTimeString()
- **delay** the time in milliseconds between output and timestamp

@@ -629,3 +629,7 @@ - **delaySec** the time in seconds between output and timestamp

|ss|Seconds; leading zero for single-digit seconds.|
|l or L|Milliseconds. l gives 3 digits. L gives 2 digits.|
|l|Milliseconds; no leading zeros for single-digit|
|ll|Milliseconds; 1 leading zero for single-digit; no for 3 digits|
|lll|Milliseconds; 2 leading zero for single-digit; 2 for 2 digits|
|L|Milliseconds divided by 100 round to 0; no leading zero|
|LL|Milliseconds divided by 10 round to 0; leading zero for single-digit|
|t|Lowercase, single-character time marker string: a or p.|

@@ -645,3 +649,3 @@ |tt|Lowercase, two-character time marker string: am or pm.|

For timespan output the calc-timespan node has the ability to define the format of the timespan. Therfore different pre defined formates exists or a free format definition.
For timespan output the calc-timespan node has the ability to define the format of the timespan. Therefore different pre defined formats exists or a free format definition.

@@ -651,10 +655,10 @@ The formats are:

- **ms** timespan im milliseconds (integer value)
- **sec**, **min**,..., **month**, **years** timespan as a floating point number or as a integer number of the the choosen unit.
- **object** gived back an object for the timespan with the following properties:
- **date** Javascript Date object
- **sec**, **min**,..., **month**, **years** timespan as a floating point number or as a integer number of the the chosen unit.
- **object** gives back an object for the timespan with the following properties:
- **date** Java script Date object
- **ts** number - Unix timestamp (milliseconds since 1970-01-01 UTC)
- **timeUTCStr** string representation of the TIme in UTC format
- **timeISOStr** string representation of the TIme in ISO format
- **timeLocaleStr** the javascript output of date.toLocaleString()
- **timeLocaleTimeStr** the javascript output of date.toLocaleTimeString()
- **timeUTCStr** string representation of the Time in UTC format
- **timeISOStr** string representation of the Time in ISO format
- **timeLocaleStr** the java script output of date.toLocaleString()
- **timeLocaleTimeStr** the java script output of date.toLocaleTimeString()
- **delay** the time in milliseconds between output and timestamp

@@ -668,3 +672,3 @@ - **delaySec** the time in seconds between output and timestamp

- [ ] select auto add get info from getTimezoneOffset
- [ ] solve problem of dst
- [ ] solve problem of DST
- [ ] within-time

@@ -671,0 +675,0 @@ - [ ] add result like other nodes

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc