-
Notifications
You must be signed in to change notification settings - Fork 73
/
Copy pathseasons.js
40 lines (33 loc) · 1.16 KB
/
seasons.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/*
seasons.js - by Don Cross - 2019-06-16
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('./astronomy.js');
function DisplayEvent(name, evt) {
let text = evt ? evt.date.toISOString() : '';
console.log(name.padEnd(17) + ' : ' + text);
}
function Demo() {
if (process.argv.length === 3) {
let year = parseInt(process.argv[2]);
if (!Number.isSafeInteger(year)) {
console.log(`ERROR: Not a valid year: "${process.argv[2]}"`);
process.exit(1);
}
let seasons = Astronomy.Seasons(year);
DisplayEvent('March equinox', seasons.mar_equinox);
DisplayEvent('June solstice', seasons.jun_solstice);
DisplayEvent('September equinox', seasons.sep_equinox);
DisplayEvent('December solstice', seasons.dec_solstice);
process.exit(0);
} else {
console.log('USAGE: node seasons.js year');
process.exit(1);
}
}
Demo();