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.5.1-beta-2 to 0.5.1

nodes/icons/inputTypeSunTime.png

17

nodes/lib/suncalc.js

@@ -405,3 +405,4 @@ /*

julian: Jnoon,
valid: !isNaN(Jnoon)
valid: !isNaN(Jnoon),
index: sunTimes.length
},

@@ -415,6 +416,6 @@ nadir: {

julian: Jnoon + 0.5,
valid: !isNaN(Jnoon)
valid: !isNaN(Jnoon),
index: (sunTimes.length * 2) + 1
}
};
for (let i = 0, len = sunTimes.length; i < len; i += 1) {

@@ -448,3 +449,4 @@ const time = sunTimes[i];

julian: Jset,
valid
valid,
index : len + i + 1
};

@@ -458,3 +460,4 @@ result[time[1]] = {

julian: Jrise,
valid
valid,
index: len - i - 1
};

@@ -467,6 +470,6 @@ }

const time = sunTimesAlternate[i];
result[time[0]] = result[time[1]];
result[time[0]] = Object.assign({}, result[time[1]]);
result[time[0]].index = -2;
}
}
return result;

@@ -473,0 +476,0 @@ };

@@ -9,2 +9,3 @@ {

"timestamp": "Zeitpunkt",
"suntimeObj": "{Sonnenzeit}",
"blank": "\"\"",

@@ -25,5 +26,7 @@ "nothing": "nichts",

"timesun": "Uhrzeit Sonnenstand",
"timesunnow": "nächste Uhrzeit Sonnenstand",
"suninsky":"Sonne am Himmel (Prozent)",
"timemoon": "Uhrzeit Mond Auf/Untergang",
"suncalc": "Sonnenposition",
"suntime":"Sonnenzeit",
"mooncalc": "Mondposition",

@@ -118,3 +121,4 @@ "moonPhase": "Mondphase",

"Wochentag",
"Woche",
"Tag des Jahres",
"Woche des Jahres",
"freier Text"

@@ -140,2 +144,4 @@ ],

"Kalenderwoche gerade",
"Tag des Jahres (Zahl)",
"ist der tag gerade",
"als Objekt",

@@ -142,0 +148,0 @@ "Anderes"

@@ -9,2 +9,3 @@ {

"timestamp":"timestamp",
"suntimeObj": "{next suntime}",
"blank": "\"\"",

@@ -25,5 +26,8 @@ "nothing": "nothing",

"timesun":"sun time",
"timesunnow": "next sun time",
"timemoon":"moon time",
"suncalc":"sun calculation",
"suninsky":"sun in the sky (percent)",
"suntime":"sun time",
"suntimes":"sun times",
"mooncalc":"moon calculation",

@@ -34,3 +38,4 @@ "moonPhase":"moon phase",

"levelfree": "Level entered",
"levelND": "N/D - use default, sun control or reset"
"levelND": "N/D - use default, sun control or reset",
"PlTRes":"msg.payload if topic contains \"__value__\""
},

@@ -120,3 +125,4 @@ "typeOptions": {

"day of week",
"week",
"day of year",
"week of year",
"Text free"

@@ -140,4 +146,6 @@ ],

"Day in relative, e.g. Today, 22.12.",
"Week Number",
"Week number",
"is week even",
"day number",
"is day even",
"as object",

@@ -144,0 +152,0 @@ "Other"

@@ -179,3 +179,3 @@ /********************************************

/**
* gets sun time
* gets sun time by Name
* @param {Date} now current time

@@ -189,15 +189,15 @@ * @param {string} value name of the sun time

*/
getSunTime(now, value, offset, multiplier, next, days) {
getSunTimeByName(now, value, offset, multiplier, next, days) {
let result;
const dayid = this._getDayId(now); // this._getUTCDayId(now);
const today = this._sunTimesCheck(); // refresh if needed, get dayId
// this.debug(`getSunTime value=${value} offset=${offset} multiplier=${multiplier} next=${next} days=${days} now=${now} dayid=${dayid} today=${util.inspect(today, { colors: true, compact: 10, breakLength: Infinity })}`);
// this.debug(`getSunTimeByName value=${value} offset=${offset} multiplier=${multiplier} next=${next} days=${days} now=${now} dayid=${dayid} today=${util.inspect(today, { colors: true, compact: 10, breakLength: Infinity })}`);
if (dayid === today.dayId) {
this.debug('getSunTime sunTimesToday');
this.debug('getSunTimes sunTimesToday');
result = Object.assign({}, this.sunTimesToday[value]); // needed for a object copy
} else if (dayid === (today.dayId + 1)) {
this.debug('getSunTime sunTimesTomorow');
this.debug('getSunTimes sunTimesTomorow');
result = Object.assign({},this.sunTimesTomorow[value]); // needed for a object copy
} else {
this.debug('getSunTime calc extra time');
this.debug('getSunTimes calc extra time');
result = Object.assign({},sunCalc.getSunTimes(now, this.latitude, this.longitude, false)[value]); // needed for a object copy

@@ -230,3 +230,3 @@ }

} else if (dayx < 0) {
// this.debug('getSunTime - no valid day of week found value=' + value + ' - next=' + next + ' - days=' + days + ' result=' + util.inspect(result, { colors: true, compact: 10, breakLength: Infinity }));
// this.debug('getSunTimeByName - no valid day of week found value=' + value + ' - next=' + next + ' - days=' + days + ' result=' + util.inspect(result, { colors: true, compact: 10, breakLength: Infinity }));
result.error = 'No valid day of week found!';

@@ -236,5 +236,48 @@ }

// this.debug('getSunTime result=' + util.inspect(result, { colors: true, compact: 10, breakLength: Infinity }));
// this.debug('getSunTimeByName result=' + util.inspect(result, { colors: true, compact: 10, breakLength: Infinity }));
return result;
}
/**
* gets previous and next sun time
* @param {Date} now current time
* @return {array} result object of sunTime
*/
getSunTimePrevNext(now) {
const dayid = this._getDayId(now); // this._getUTCDayId(now);
const today = this._sunTimesCheck(); // refresh if needed, get dayId
let result;
// this.debug(`getSunTimePrevNext value=${value} offset=${offset} multiplier=${multiplier} next=${next} days=${days} now=${now} dayid=${dayid} today=${util.inspect(today, { colors: true, compact: 10, breakLength: Infinity })}`);
if (dayid === today.dayId) {
result = this.sunTimesToday; // needed for a object copy
} else if (dayid === (today.dayId + 1)) {
result = this.sunTimesTomorow; // needed for a object copy
} else {
result = sunCalc.getSunTimes(now, this.latitude, this.longitude, false); // needed for a object copy
}
const sortable = [];
for (const key in result) {
if (result[key].index >=0) {
sortable.push(result[key]);
}
}
sortable.sort((a, b) => {
return a.ts - b.ts;
});
const nowTs = now.getTime();
let last = sortable[0];
if (last.ts > nowTs) {
return [result['nadir'], last];
}
for (let index = 1; index < sortable.length; index++) {
const element = sortable[index];
if (last.ts < element.ts) {
if (element.ts > nowTs) {
return [last, element];
}
last = element;
}
}
return [last, sortable[0]];
}
/*******************************************************************************************************/

@@ -256,3 +299,3 @@ /**

*/
getMoonTime(now, value, offset, multiplier, next, days) {
getMoonTimeByName(now, value, offset, multiplier, next, days) {
const result = {};

@@ -262,3 +305,3 @@ const datebase = new Date(now);

const today = this._moonTimesCheck(); // refresh if needed, get dayId
// this.debug(`getMoonTime value=${value} offset=${offset} multiplier=${multiplier} next=${next} days=${days} now=${now} dayid=${dayid} today=${today}`);
// this.debug(`getMoonTimeByName value=${value} offset=${offset} multiplier=${multiplier} next=${next} days=${days} now=${now} dayid=${dayid} today=${today}`);

@@ -302,3 +345,3 @@ if (dayid === today.dayId) {

} else if (dayx < 0) {
// this.debug('getSunTime - no valid day of week found value=' + value + ' - next=' + next + ' - days=' + days + ' result=' + util.inspect(result, { colors: true, compact: 10, breakLength: Infinity }));
// this.debug('getMoonTimeByName - no valid day of week found value=' + value + ' - next=' + next + ' - days=' + days + ' result=' + util.inspect(result, { colors: true, compact: 10, breakLength: Infinity }));
result.error = 'No valid day of week found!';

@@ -308,3 +351,3 @@ }

// this.debug('getMoonTime result=' + util.inspect(result, { colors: true, compact: 10, breakLength: Infinity }));
// this.debug('getMoonTimeByName result=' + util.inspect(result, { colors: true, compact: 10, breakLength: Infinity }));
return result;

@@ -425,6 +468,6 @@ }

const offsetX = this.getFloatProp(_srcNode, msg, data.offsetType, data.offset, 0);
result = this.getSunTime(now, data.value, offsetX, data.multiplier, data.next, data.days);
result = this.getSunTimeByName(now, data.value, offsetX, data.multiplier, data.next, data.days);
} else if (data.type === 'pdmTime') { // moon
const offsetX = this.getFloatProp(_srcNode, msg, data.offsetType, data.offset, 0);
result = this.getMoonTime(now, data.value, offsetX, data.multiplier, data.next, data.days);
result = this.getMoonTimeByName(now, data.value, offsetX, data.multiplier, data.next, data.days);
}

@@ -435,2 +478,4 @@ if (result && result.value && !result.error) {

return null;
} else if (data.type === 'pdsTimeNow') {
return Object.assign({}, this.getSunTimePrevNext(now));
} else if (data.type === 'entered' || data.type === 'dateEntered') {

@@ -533,3 +578,3 @@ result = hlp.getDateOfText(String(data.value), (this.tzOffset === 0), this.tzOffset);

const offsetX = this.getFloatProp(_srcNode, msg, data.offsetType, data.offset, 0);
result = this.getSunTime(now, data.value, offsetX, data.multiplier, data.next, data.days);
result = this.getSunTimeByName(now, data.value, offsetX, data.multiplier, data.next, data.days);
if (this.tzOffset) {

@@ -542,3 +587,3 @@ result.value = hlp.convertDateTimeZone(result.value, this.tzOffset);

const offsetX = this.getFloatProp(_srcNode, msg, data.offsetType, data.offset, 0);
result = this.getMoonTime(now, data.value, offsetX, data.multiplier, data.next, data.days);
result = this.getMoonTimeByName(now, data.value, offsetX, data.multiplier, data.next, data.days);
if (this.tzOffset) {

@@ -548,2 +593,4 @@ result.value = hlp.convertDateTimeZone(result.value, this.tzOffset);

result.fix = true;
} else if (data.type === 'pdsTimeNow') {
return this.getSunTimePrevNext(now)[1];
} else if (data.type === 'str') {

@@ -778,13 +825,13 @@ result.fix = true;

const today = this._sunTimesCheck(); // refresh if needed, get dayId
// this.debug(`getSunTime value=${value} offset=${offset} multiplier=${multiplier} next=${next} days=${days} now=${now} dayid=${dayid} today=${util.inspect(today, { colors: true, compact: 10, breakLength: Infinity })}`);
// this.debug(`getSunTimes value=${value} offset=${offset} multiplier=${multiplier} next=${next} days=${days} now=${now} dayid=${dayid} today=${util.inspect(today, { colors: true, compact: 10, breakLength: Infinity })}`);
if (dayid === today.dayId) {
this.debug('getSunTime sunTimesToday');
this.debug('getSunTimes sunTimesToday');
result.times =this.sunTimesToday; // needed for a object copy
result.positionAtSolarNoon = this.sunSolarNoonToday;
} else if (dayid === (today.dayId + 1)) {
this.debug('getSunTime sunTimesTomorow');
this.debug('getSunTimes sunTimesTomorow');
result.times = this.sunTimesTomorow; // needed for a object copy
result.positionAtSolarNoon = this.sunSolarNoonTomorow;
} else {
this.debug('getSunTime calc extra time');
this.debug('getSunTimes calc extra time');
result.times = sunCalc.getSunTimes(date, this.latitude, this.longitude, false); // needed for a object copy

@@ -791,0 +838,0 @@ if (sunInSky && result.times.solarNoon.valid) {

@@ -58,3 +58,4 @@ /************************************************************************/

{id: 'dayOfWeek', label: 'day of week'},
{id: 'Week', label: 'info about week'},
{id: 'dayOfYear', label: 'day of year'},
{id: 'WeekOfYear', label: 'week of year'},
{id: 'other', label: 'Other'}

@@ -77,4 +78,6 @@ ], outputFormats: [

{id: 17, group: 'dayOfWeek', name: 'Day', label: 'Day in relative, e.g. Today, 22.12.'},
{id: 19, group: 'Week', name: 'week number', label: 'Number of week e.g. 22'},
{id: 20, group: 'Week', name: 'is week even', label: 'Boolean if week is even'},
{id: 19, group: 'WeekOfYear', name: 'week number', label: 'Number of week e.g. 22'},
{id: 20, group: 'WeekOfYear', name: 'is week even', label: 'Boolean if week is even'},
{id: 21, group: 'dayOfYear', name: 'day number', label: 'Number of day e.g. 365'},
{id: 22, group: 'dayOfYear', name: 'is day even', label: 'Boolean if day is even'},
{id: -1, group: 'other', name: 'object', label: 'as object'},

@@ -319,2 +322,8 @@ {id: 99, group: 'other', name: 'free definition', label: 'Other'}

},
TimeSunNow: {
value: 'pdsTimeNow',
label: node._('node-red-contrib-sun-position/position-config:common.types.timesunnow'),
icon: 'icons/node-red-contrib-sun-position/inputTypeSunTime.png',
hasValue: false
},
TimeMoon: {

@@ -469,3 +478,4 @@ value: 'pdmTime',

],
dateOutFormat: [{label: 'yyyy Year (4 digits)', value: 'yyyy'},
dateOutFormat: [
{label: 'yyyy Year (4 digits)', value: 'yyyy'},
{label: 'yy Year (2 digits)', value: 'yy'},

@@ -501,3 +511,6 @@ {label: 'M Month (1 digit)', value: 'M'},

{label: 'TT AM/PM (2 digits - Uppercase)', value: 'TT'},
{label: 'ww workweek (number)', value: 'ww'},
{label: 'w week of year (0-53)', value: 'w'},
{label: 'ww week of year (2 digits 00-53)', value: 'ww'},
{label: 'dy day of year (0-365)', value: 'dy'},
{label: 'ddy day of year (3 digits 000-365)', value: 'ddy'},
{label: 'Z time zone (abbr.)', value: 'Z'},

@@ -504,0 +517,0 @@ {label: 'o time zone offset (abbr.)', value: 'o'},

{
"name": "node-red-contrib-sun-position",
"version": "0.5.1-beta-2",
"version": "0.5.1",
"description": "NodeRED nodes to get sun and moon position",

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

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

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

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