Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(moon): changed to type specific return values and added moon test #123

Merged
merged 7 commits into from
Apr 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading