Skip to content

Instantly share code, notes, and snippets.

@zeroows
Created March 18, 2014 10:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zeroows/9617351 to your computer and use it in GitHub Desktop.
Save zeroows/9617351 to your computer and use it in GitHub Desktop.
/* 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