views:

98

answers:

3

Hi all!

I'm making a calendar generator in JavaScript. I need the Unix Timestamp for easter day midnight, for a given year. Can anyone tell me how I need to do that (in JavaScript)?

Thanks in advance.

PHP's function can be found here: http://www.php.net/easter%5Fdate

A: 

Here's one implementation. Can't vouch for it's accuracy.

http://users.sa.chariot.net.au/~gmarts/eastalg.htm#easterscript

tvanfosson
+3  A: 

According to this:-

function Easter(Y) {
    var C = Math.floor(Y/100);
    var N = Y - 19*Math.floor(Y/19);
    var K = Math.floor((C - 17)/25);
    var I = C - Math.floor(C/4) - Math.floor((C - K)/3) + 19*N + 15;
    I = I - 30*Math.floor((I/30));
    I = I - Math.floor(I/28)*(1 - Math.floor(I/28)*Math.floor(29/(I + 1))*Math.floor((21 - N)/11));
    var J = Y + Math.floor(Y/4) + I + 2 - C + Math.floor(C/4);
    J = J - 7*Math.floor(J/7);
    var L = I - J;
    var M = 3 + Math.floor((L + 40)/44);
    var D = L + 28 - 31*Math.floor(M/4);

    return padout(M) + '.' + padout(D);
}

function padout(number) { return (number < 10) ? '0' + number : number; }

Example usage:-

document.write(Easter(1997));
Gavin Gilmour
Thanks, I let my other functions convert it into a Unix timestamp
Time Machine
+1  A: 

Have a look at the PHP source code to see how they calculate theirs and replicate in JavaScript?

KTC
Omg, is PHP open source? Well, I didn't know that :p
Time Machine