Created
March 18, 2014 10:23
-
-
Save zeroows/9617351 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Create a new date from a Julian date. | |
@param jd (number) the Julian date to convert | |
@return (CDate) the equivalent date */ | |
fromJD: function(jd) { | |
// Jean Meeus algorithm, "Astronomical Algorithms", 1991 | |
var z = Math.floor(jd + 0.5); | |
var a = Math.floor((z - 1867216.25) / 36524.25); | |
a = z + 1 + a - Math.floor(a / 4); | |
var b = a + 1524; | |
var c = Math.floor((b - 122.1) / 365.25); | |
var d = Math.floor(365.25 * c); | |
var e = Math.floor((b - d) / 30.6001); | |
var day = b - d - Math.floor(e * 30.6001); | |
var month = e - (e > 13.5 ? 13 : 1); | |
var year = c - (month > 2.5 ? 4716 : 4715); | |
if (year <= 0) { year--; } // No year zero | |
return this.newDate(year, month, day); | |
}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment