node-red-contrib-sun-position
Advanced tools
Comparing version 0.5.3 to 0.5.4
@@ -267,20 +267,14 @@ /* | ||
const sunTimes = SunCalc.times = [ | ||
[6, 'goldenHourDawnEnd', 'goldenHourDuskStart', 10, 12], // GOLDEN_HOUR_2 | ||
[-0.3, 'sunriseEnd', 'sunsetStart', 9, 13], // SUNRISE_END | ||
[-0.833, 'sunrise', 'sunset', 8, 14], // SUNRISE | ||
[-1, 'goldenHourDawnStart', 'goldenHourDuskEnd', 7, 15], // GOLDEN_HOUR_1 | ||
[-4, 'blueHourDawnEnd', 'blueHourDuskStart', 6, 16], // BLUE_HOUR | ||
[-6, 'civilDawn', 'civilDusk', 5, 17], // DAWN | ||
[-8, 'blueHourDawnStart', 'blueHourDuskEnd', 4, 18], // BLUE_HOUR | ||
[-12, 'nauticalDawn', 'nauticalDusk', 3, 19], // NAUTIC_DAWN | ||
[-15, 'amateurDawn', 'amateurDusk', 2, 20], | ||
[-18, 'astronomicalDawn', 'astronomicalDusk', 1, 21] // ASTRO_DAWN | ||
[6, 'goldenHourDawnEnd', 'goldenHourDuskStart'], // GOLDEN_HOUR_2 | ||
[-0.3, 'sunriseEnd', 'sunsetStart'], // SUNRISE_END | ||
[-0.833, 'sunrise', 'sunset'], // SUNRISE | ||
[-1, 'goldenHourDawnStart', 'goldenHourDuskEnd'], // GOLDEN_HOUR_1 | ||
[-4, 'blueHourDawnEnd', 'blueHourDuskStart'], // BLUE_HOUR | ||
[-6, 'civilDawn', 'civilDusk'], // DAWN | ||
[-8, 'blueHourDawnStart', 'blueHourDuskEnd'], // BLUE_HOUR | ||
[-12, 'nauticalDawn', 'nauticalDusk'], // NAUTIC_DAWN | ||
[-15, 'amateurDawn', 'amateurDusk'], | ||
[-18, 'astronomicalDawn', 'astronomicalDusk'] // ASTRO_DAWN | ||
]; | ||
/** default time definitions */ | ||
const sunTimesDefault = SunCalc.timesDefault = { | ||
solarNoon: 11, | ||
nadir: 0 | ||
}; | ||
/** alternate time names for backward compatibility */ | ||
@@ -402,3 +396,2 @@ const sunTimesAlternate = SunCalc.timesAlternate = [ | ||
ts: noonVal.getTime(), | ||
pos: sunTimesDefault.solarNoon, | ||
name: 'solarNoon', | ||
@@ -408,3 +401,3 @@ // elevation: 90, | ||
valid: !isNaN(Jnoon), | ||
index: sunTimes.length | ||
pos: sunTimes.length | ||
}, | ||
@@ -414,3 +407,2 @@ nadir: { | ||
ts: nadirVal.getTime(), | ||
pos: sunTimesDefault.nadir, | ||
name: 'nadir', | ||
@@ -420,3 +412,3 @@ // elevation: 270, | ||
valid: !isNaN(Jnoon), | ||
index: (sunTimes.length * 2) + 1 | ||
pos: (sunTimes.length * 2) + 1 | ||
} | ||
@@ -448,3 +440,2 @@ }; | ||
ts: v1.getTime(), | ||
pos: time[4], | ||
name: time[2], | ||
@@ -454,3 +445,3 @@ elevation: sa, | ||
valid, | ||
index : len + i + 1 | ||
pos: len + i + 1 | ||
}; | ||
@@ -460,3 +451,2 @@ result[time[1]] = { | ||
ts: v2.getTime(), | ||
pos: time[3], | ||
name: time[1], | ||
@@ -466,3 +456,3 @@ elevation: sa, // (180 + (sa * -1)), | ||
valid, | ||
index: len - i - 1 | ||
pos: len - i - 1 | ||
}; | ||
@@ -476,3 +466,5 @@ } | ||
result[time[0]] = Object.assign({}, result[time[1]]); | ||
result[time[0]].index = -2; | ||
result[time[0]].deprecated = true; | ||
result[time[0]].posOrg = result[time[0]].pos; | ||
result[time[0]].pos = -2; | ||
} | ||
@@ -479,0 +471,0 @@ } |
@@ -243,6 +243,6 @@ /******************************************** | ||
getSunTimePrevNext(now) { | ||
const dayid = this._getDayId(now); // this._getUTCDayId(now); | ||
let 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 })}`); | ||
// this.debug(`getSunTimePrevNext now=${now} dayid=${dayid} today=${util.inspect(today, { colors: true, compact: 10, breakLength: Infinity })}`); | ||
if (dayid === today.dayId) { | ||
@@ -257,3 +257,3 @@ result = this.sunTimesToday; // needed for a object copy | ||
for (const key in result) { | ||
if (result[key].index >=0) { | ||
if (result[key].pos >= 0) { | ||
sortable.push(result[key]); | ||
@@ -266,2 +266,4 @@ } | ||
const nowTs = now.getTime() + 300; // offset to get really next | ||
// this.debug(`getSunTimePrevNext nowTs=${nowTs} sortable=${util.inspect(sortable, { colors: true, compact: 10, breakLength: Infinity })}`); | ||
let last = sortable[0]; | ||
@@ -271,53 +273,65 @@ if (last.ts >= nowTs) { | ||
next : { | ||
value : new Date(last.value), | ||
name : last.name, | ||
pos : last.pos, | ||
valid : last.valid, | ||
elevation : last.elevation | ||
}, | ||
last : { | ||
value : new Date(result['nadir'].value), | ||
name : result['nadir'].name, | ||
index : result['nadir'].index, | ||
pos : result['nadir'].pos, | ||
valid : result['nadir'].valid, | ||
elevation : result['nadir'].elevation | ||
}, | ||
last : { | ||
value : new Date(last.value), | ||
name : last.name, | ||
index : last.index, | ||
pos : last.pos, | ||
valid : last.valid, | ||
elevation : last.elevation | ||
} | ||
}; | ||
} | ||
for (let index = 1; index < sortable.length; index++) { | ||
const element = sortable[index]; | ||
if (last.ts < element.ts) { | ||
if (element.ts > nowTs) { | ||
return { | ||
next : { | ||
value : new Date(element.value), | ||
name : element.name, | ||
index : element.index, | ||
pos : element.pos, | ||
valid : element.valid, | ||
elevation : element.elevation | ||
}, | ||
last : { | ||
value : new Date(last.value), | ||
name : last.name, | ||
index : last.index, | ||
pos : last.pos, | ||
valid : last.valid, | ||
elevation : last.elevation | ||
} | ||
}; | ||
} | ||
last = element; | ||
for (let i = 1; i < sortable.length; i++) { | ||
const element = sortable[i]; | ||
if (nowTs < element.ts) { | ||
return { | ||
next : { | ||
value : new Date(element.value), | ||
name : element.name, | ||
pos : element.pos, | ||
valid : element.valid, | ||
elevation : element.elevation | ||
}, | ||
last : { | ||
value : new Date(last.value), | ||
name : last.name, | ||
pos : last.pos, | ||
valid : last.valid, | ||
elevation : last.elevation | ||
} | ||
}; | ||
} | ||
last = element; | ||
} | ||
dayid += 1; | ||
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 { | ||
const tomorrow = new Date(now); | ||
tomorrow.setDate(tomorrow.getDate() + 1); | ||
result = sunCalc.getSunTimes(tomorrow, this.latitude, this.longitude, false); // needed for a object copy | ||
} | ||
const sortable2 = []; | ||
for (const key in result) { | ||
if (result[key].pos >=0) { | ||
sortable2.push(result[key]); | ||
} | ||
} | ||
sortable2.sort((a, b) => { | ||
return a.ts - b.ts; | ||
}); | ||
return { | ||
next : { | ||
value : new Date(sortable[0].value), | ||
name : sortable[0].name, | ||
index : sortable[0].index, | ||
pos : sortable[0].pos, | ||
valid : sortable[0].valid, | ||
elevation : sortable[0].elevation | ||
value : new Date(sortable2[0].value), | ||
name : sortable2[0].name, | ||
pos : sortable2[0].pos, | ||
valid : sortable2[0].valid, | ||
elevation : sortable2[0].elevation | ||
}, | ||
@@ -327,3 +341,2 @@ last : { | ||
name : last.name, | ||
index : last.index, | ||
pos : last.pos, | ||
@@ -448,3 +461,3 @@ valid : last.valid, | ||
getFloatProp(_srcNode, msg, type, value, def, opCallback, noError) { | ||
_srcNode.debug('getFloatProp type='+type+' value='+value); | ||
// _srcNode.debug('getFloatProp type='+type+' value='+value); | ||
let data; // 'msg', 'flow', 'global', 'num', 'bin', 'env', 'jsonata' | ||
@@ -496,3 +509,3 @@ if (type === 'num') { | ||
getOutDataProp(_srcNode, msg, data) { | ||
// _srcNode.debug(`getOutDataProp data=${util.inspect(data, { colors: true, compact: 10, breakLength: Infinity }) } tzOffset=${this.tzOffset}`); | ||
// _srcNode.debug(`getOutDataProp IN data=${util.inspect(data, { colors: true, compact: 10, breakLength: Infinity }) } tzOffset=${this.tzOffset}`); | ||
let now = new Date(data.now); | ||
@@ -531,10 +544,11 @@ if (!hlp.isValidDate(data.now)) { now = new Date(); } | ||
result = Object.assign({}, this.getSunTimePrevNext(now)); | ||
_srcNode.debug(`getOutDataProp 1 result=${util.inspect(result, { colors: true, compact: 10, breakLength: Infinity }) }`); | ||
const offsetX = this.getFloatProp(_srcNode, msg, data.offsetType, data.offset, 0, data.offsetCallback, data.noOffsetError); | ||
result.last.value = hlp.normalizeDate(result.last.value, offsetX, data.multiplier, data.next, data.days); | ||
result.next.value = hlp.normalizeDate(result.next.value, offsetX, data.multiplier, data.next, data.days); | ||
if (data.format > 0) { | ||
return hlp.getFormattedDateOut(result.next, data.format, (this.tzOffset === 0), this.tzOffset); | ||
} | ||
_srcNode.debug(`getOutDataProp 2 result=${util.inspect(result, { colors: true, compact: 10, breakLength: Infinity }) }`); | ||
if (this.tzOffset) { | ||
result.prev.value = hlp.convertDateTimeZone(result.prev.value, this.tzOffset).getTime(); | ||
result.last.value = hlp.convertDateTimeZone(result.last.value, this.tzOffset).getTime(); | ||
result.next.value = hlp.convertDateTimeZone(result.next.value, this.tzOffset).getTime(); | ||
_srcNode.debug(`getOutDataProp 3 result=${util.inspect(result, { colors: true, compact: 10, breakLength: Infinity }) }`); | ||
} | ||
@@ -557,3 +571,3 @@ return result; | ||
} | ||
// _srcNode.debug(`getOutDataProp data=${util.inspect(data, { colors: true, compact: 10, breakLength: Infinity })} tzOffset=${this.tzOffset} result=${util.inspect(result, { colors: true, compact: 10, breakLength: Infinity })}`); | ||
// _srcNode.debug(`getOutDataProp OUT data=${util.inspect(data, { colors: true, compact: 10, breakLength: Infinity })} tzOffset=${this.tzOffset} result=${util.inspect(result, { colors: true, compact: 10, breakLength: Infinity })}`); | ||
return this.getPropValue(_srcNode, msg, { type: data.type, value: data.value }); | ||
@@ -590,3 +604,3 @@ } | ||
getTimeProp(_srcNode, msg, data) { | ||
_srcNode.debug(`getTimeProp data=${util.inspect(data, { colors: true, compact: 10, breakLength: Infinity })} tzOffset=${this.tzOffset}`); | ||
// _srcNode.debug(`getTimeProp data=${util.inspect(data, { colors: true, compact: 10, breakLength: Infinity })} tzOffset=${this.tzOffset}`); | ||
let result = { | ||
@@ -593,0 +607,0 @@ value: null, |
@@ -338,3 +338,2 @@ /******************************************** | ||
}); | ||
if (value === null || (typeof value === 'undefined')) { | ||
@@ -341,0 +340,0 @@ throw new Error('could not evaluate ' + config.payloadType + '.' + config.payload); |
{ | ||
"name": "node-red-contrib-sun-position", | ||
"version": "0.5.3", | ||
"version": "0.5.4", | ||
"description": "NodeRED nodes to get sun and moon position", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1205113
8946