forked from darkskyapp/astro
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
63 lines (51 loc) · 1.48 KB
/
index.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
"use strict";
const lunar = require("./lib/lunar");
const solar = require("./lib/solar");
// Convert to/from J2000 dates.
const J1970 = -10957.5;
function ms_to_julian(ms) {
return J1970 + ms / 86400000;
}
function unix_to_julian(unix) {
return J1970 + unix / 86400;
}
function date_to_julian(date) {
return ms_to_julian(date.getTime());
}
function julian_to_ms(t) {
return (t - J1970) * 86400000;
}
function julian_to_unix(t) {
return (t - J1970) * 86400;
}
function julian_to_date(t) {
return new Date(julian_to_ms(t));
}
// Greenwich mean sidereal time, accurate to ~1 second.
// http://aa.usno.navy.mil/faq/docs/GAST.php
const GMST0 = 18.697374558 * Math.PI / 12;
const GMST1 = 24.06570982441908 * Math.PI / 12;
function greenwich_mean_sidereal_time(jt) {
return GMST0 + GMST1 * jt;
}
function local_sidereal_time(jt, lon_r) {
return greenwich_mean_sidereal_time(jt) + lon_r;
}
function hour_angle(jt, lon_r) {
let angle = local_sidereal_time(jt, lon_r) - solar.right_ascension(jt);
angle -= Math.floor(angle / (2 * Math.PI)) * (2 * Math.PI);
if(angle > Math.PI) {
angle -= 2 * Math.PI;
}
return angle;
}
exports.ms_to_julian = ms_to_julian;
exports.unix_to_julian = unix_to_julian;
exports.date_to_julian = date_to_julian;
exports.julian_to_ms = julian_to_ms;
exports.julian_to_unix = julian_to_unix;
exports.julian_to_date = julian_to_date;
exports.local_sidereal_time = local_sidereal_time;
exports.hour_angle = hour_angle;
exports.solar = solar;
exports.lunar = lunar;