-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathastro.dates.js
More file actions
69 lines (56 loc) · 1.95 KB
/
Copy pathastro.dates.js
File metadata and controls
69 lines (56 loc) · 1.95 KB
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
64
65
66
/*
astro.dates.js - astronomy date manipulation
*/
(function () {
// Create the main function
function init(astrojs) {
// Return the full Julian Date
// It is important to remember to include the timezone
// offset if setting this with a string
this.getJulianDate = function(today) {
// The Julian Date of the Unix Time epoch is 2440587.5
if(!today) today = new Date();
if(typeof today==="string") today = new Date(today);
return ( ((typeof today==="number") ? today : today.getTime()) / 86400000.0 ) + 2440587.5;
}
// Return the Greenwich Sidereal Time
this.getGST = function(clock){
if(typeof clock==="undefined") return { status: -1 };
if(typeof clock==="string") clock = new Date(clock);
else if(typeof clock==="number") clock = new Date(clock);
var JD, JD0, S, T, T0, UT, A, GST;
JD = this.getJulianDate(clock);
JD0 = Math.floor(JD-0.5)+0.5;
S = JD0-2451545.0;
T = S/36525.0;
T0 = (6.697374558 + (2400.051336*T) + (0.000025862*T*T))%24;
if(T0 < 0) T0 += 24;
UT = (((clock.getUTCMilliseconds()/1000 + clock.getUTCSeconds())/60) + clock.getUTCMinutes())/60 + clock.getUTCHours();
A = UT*1.002737909;
T0 += A;
GST = T0%24;
if(GST < 0) GST += 24;
return GST;
}
// Return the Local Sidereal Time
this.getLST = function(clock,lon){
if(typeof clock==="undefined" || typeof lon==="undefined") return { status: -1 };
var GST = this.getGST(clock);
var d = (GST + lon/15.0)/24.0;
d = d - Math.floor(d);
if(d < 0) d += 1;
return 24.0*d;
}
// Return a structure with the Julian Date, Local Sidereal Time and Greenwich Sidereal Time
this.astronomicalTimes = function(clock,lon){
if(typeof clock==="undefined" || typeof lon==="undefined") return { status: -1 };
return { GST:this.getGST(clock,lon), LST:this.getLST(clock,lon), JD:this.getJulianDate(clock) };
}
return this;
}
astrojs.registerPackage({
init: init,
name: 'dates',
version: '0.1'
});
})(astrojs);