Skip to content

Commit

Permalink
fix(moon): change to type specific return values (#123)
Browse files Browse the repository at this point in the history
  • Loading branch information
godind authored Apr 19, 2024
1 parent 89d148d commit 9c129d3
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions calcs/moon.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,22 @@ module.exports = function (app, plugin) {
optionKey: 'Moon',
title: 'Sets environment.moon.* information such as phase, rise, and set',
derivedFrom: ['navigation.datetime', 'navigation.position'],
defaults: ['', undefined],
defaults: [undefined, undefined],
debounceDelay: 60 * 1000,
calculator: function (datetime, position) {
var value
var mode
var date

if (datetime && datetime.length > 0) {
if (!_.isUndefined(datetime) && datetime.length > 0) {
date = new Date(datetime)
} else {
date = new Date()
}

app.debug(`Using datetime: ${date} position: ${JSON.stringify(position)}`)

var illumination = suncalc.getMoonIllumination(date)
const illumination = suncalc.getMoonIllumination(date)
_.keys(illumination).forEach(key => {
illumination[key] = illumination[key].toFixed(2)
illumination[key] = _.round(illumination[key], 2)
})
app.debug('moon illumination:' + JSON.stringify(illumination, null, 2))

Expand Down Expand Up @@ -57,27 +55,30 @@ module.exports = function (app, plugin) {
}
app.debug('Phase Name:' + phaseName)

var times = suncalc.getMoonTimes(
const times = suncalc.getMoonTimes(
date,
position.latitude,
position.longitude
)
app.debug('moon times:' + JSON.stringify(times, null, 2))

return [
{ path: 'environment.moon.fraction', value: illumination.fraction },
{
path: 'environment.moon.fraction',
value: illumination.fraction
},
{ path: 'environment.moon.phase', value: illumination.phase },
{ path: 'environment.moon.phaseName', value: phaseName },
{ path: 'environment.moon.angle', value: illumination.angle },
{ path: 'environment.moon.times.rise', value: times.rise || null },
{ path: 'environment.moon.times.set', value: times.set || null },
{
path: 'environment.moon.times.alwaysUp',
value: times.alwaysUp ? 'true' : 'false'
value: !!times.alwaysUp
},
{
path: 'environment.moon.times.alwaysDown',
value: times.alwaysDown ? 'true' : 'false'
value: !!times.alwaysDown
}
]
}
Expand Down

0 comments on commit 9c129d3

Please sign in to comment.