-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjulian-day.js
61 lines (55 loc) · 2.1 KB
/
julian-day.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
import computeΔT from '@robireton/delta-t'
export function JulianDay (date, gregorian = true) {
// c.f. Chapter 7 of Astronomical Algorithms by Jean Meeus
// the Julian Day number for the given date
let Y = date.getUTCFullYear()
let M = 1 + date.getUTCMonth()
if (M < 3) {
Y--
M += 12
}
const D = date.getUTCDate() + date.getUTCHours() / 24 + date.getUTCMinutes() / 1440 + date.getUTCSeconds() / 86400 + date.getUTCMilliseconds() / 86400000
const A = Math.floor(Y / 100)
const B = gregorian ? 2 - A + Math.floor(A / 4) : 0
const JD = Math.floor(365.25 * (Y + 4716)) + Math.floor(30.6001 * (M + 1)) + D + B - 1524.5
if (JD < 0) throw new Error('method not valid for negative Julian Day numbers')
return JD // the Julian Day Number for the given date
}
export default function JulianEphemerisDay (date, gregorian = true) {
// c.f. Chapter 9 of Astronomical Algorithms by Jean Meeus
// the Julian Ephemeris Day number for the given date
return JulianDay(date, gregorian) + computeΔT(date.getUTCFullYear(), 1 + date.getUTCMonth()) / 86400
}
// Number.prototype.JDtoDate = function() {
// if (this.valueOf() < 0) throw new Error('method not valid for negative Julian Day numbers')
// const JD = this.valueOf() + 0.5
// const Z = Math.floor(JD)
// const F = JD - Z
// let A = Z
// if ( Z >= 2299161 ) {
// const α = Math.floor( (Z - 1867216.25) / 36524.25 )
// A = Z + 1 + α - Math.floor( α / 4 )
// }
// const B = A + 1524
// const C = Math.floor( (B - 122.1) / 365.25 )
// const D = Math.floor( 365.25 * C )
// const E = Math.floor( (B - D) / 30.6001 )
//
// const month = (E < 14) ? (E - 1) : (E - 13)
// const year = (month > 2) ? (C - 4716) : (C - 4715)
// let X = B - D - Math.floor( 30.6001 * E ) + F
// const date = Math.floor(X)
// X -= date
// X *= 24
// const hours = Math.floor(X)
// X -= hours
// X *= 60
// const minutes = Math.floor(X)
// X -= minutes
// X *= 60
// const seconds = Math.floor(X)
// X -= seconds
// X *= 1000
//
// return new Date( Date.UTC(year, month - 1, date, hours, minutes, seconds, Math.floor(X)) )
// }