That JavaScript is a LOT more complicated than it needs to be - JavaScript has a Date object that provides the ability to do date manipulations without needing all those calculations.
The following does the same thing as all the code originally posted. Note that the code to get the Julian Day doesn't use the code to determine leap years, I have just included that so you can see how much simpler it can be done in JavaScript than the complicated (and incomplete) formula the original code uses.
To determine whether or not a year is a leap year or not:
Code:
function leap_gregorian(year) {return ((new Date(year,1,29)).getDate() == 29);}
To convert a Gregorian Date into a Julian Day (including the correct fraction of a day - which the original code doesn't do)
Code:
Date.prototype.getJulian = function() { return Math.floor((this / 86400000) - (this.getTimezoneOffset()/1440) + 2440587.5);}
function gregorian_to_jd(year, month, day) {return ((new Date(year, month-1, day)).getJulian());
Bookmarks