Tuesday, March 25, 2008

getEaster([year])

This code will return the date of easter at a [given] year. If you call the function without any year, current year will be used:


function getEaster(year) {
year = (arguments.length==1) ? year : new Date().getYear();
var a=year%19, b=Math.floor(year/100), c=year%100, d=Math.floor(b/4), e=b%4, f=Math.floor((b+8)/25), g=Math.floor((b-f+1)/3), h=(19*a+b-d-g+15)%30, i=Math.floor(c/4), k=c%4, l=(32+2*e+2*i-h-k)%7, m=Math.floor((a+11*h+22*l)/451), n=h+l-7*m+114;
return new Date(year, Math.floor(n/31)-1,n%31+1);
}

It return a javascript Date object.

No comments: