Files
astronomy/demo/nodejs/riseset.js
Don Cross 1b0ba300d8 Removed all references to GitHub Pages, because it has been disabled.
I'm not going to use GitHub Pages after all, because it is
causing more problems than it is helping. All I really wanted
was a way to host live JavaScript browser examples.
I will find my own way of hosting just those.

The main problem is that GitHub pages uses a different flavor
of Markdown than GitHub. This makes it really difficult to get
something that works right across both.  In general, it doubles
how much stuff I have to look at when I make a cosmetic change.

So I have already turned off GitHub Pages on this repo,
and this commit removes all links and references to it.
2019-07-09 19:49:28 -04:00

44 lines
1.6 KiB
JavaScript

/*
riseset.js - by Don Cross - 2019-06-15
Example Node.js program for Astronomy Engine:
https://github.com/cosinekitty/astronomy
This program calculates the time of the next
sunrise, sunset, moonrise, and moonset.
To execute, run the command:
node riseset latitude longitude [date]
*/
const Astronomy = require('../../source/js/astronomy.js'); // adjust path as needed for your system
function DisplayEvent(name, evt) {
let text = evt ? evt.date.toISOString() : '';
console.log(name.padEnd(8) + ' : ' + text);
}
function Demo() {
if (process.argv.length === 4 || process.argv.length === 5) {
const latitude = parseFloat(process.argv[2]);
const longitude = parseFloat(process.argv[3]);
const observer = Astronomy.MakeObserver(latitude, longitude, 0);
const date = (process.argv.length === 5) ? new Date(process.argv[4]) : new Date();
let sunrise = Astronomy.SearchRiseSet('Sun', observer, +1, date, 300);
let sunset = Astronomy.SearchRiseSet('Sun', observer, -1, date, 300);
let moonrise = Astronomy.SearchRiseSet('Moon', observer, +1, date, 300);
let moonset = Astronomy.SearchRiseSet('Moon', observer, -1, date, 300);
console.log('search : ' + date.toISOString());
DisplayEvent('sunrise', sunrise);
DisplayEvent('sunset', sunset);
DisplayEvent('moonrise', moonrise);
DisplayEvent('moonset', moonset);
process.exit(0);
} else {
console.log('USAGE: node riseset.js latitude longitude [date]');
process.exit(1);
}
}
Demo();