wm003

25 Mar 2008, 10:06 PM

For calculation of my national holidays i needed to calculate the easter Date of each year.

The following Function returns a Date-Object of Easter-Sunday of a given year. If no year is given the routine will use the current year.

[UPDATE 2008/03/28]

Added option to add/subtract a number of days from the calculated eastersunday

e.g.

Ext.util.EasterDate(2008) returns a DateObject of 2008/03/23

Ext.util.EasterDate(2008,5) returns a DateObject of 2008/03/28

Ext.util.EasterDate(2008,-3) returns a DateObject of 2008/03/20

Ext.util.EasterDate = function(year, plusDays) {

if (typeof year === "undefined") {

year = new Date().getFullYear();

}

year = parseInt(year,10);

if (typeof plusDays === "undefined") {

plusDays = 0;

}

plusDays = parseInt(plusDays,10);

//difference to first sunday after first fullmoon after beginning of spring

var a = year % 19;

var d = (19 * a + 24) % 30;

var diffDay = d + (2 * (year % 4) + 4 * (year % 7) + 6 * d + 5) % 7;

if ((diffDay == 35) || ((diffDay == 34) && (d == 28) && (a > 10))) {

diffDay -= 7;

}

var EasterDate = new Date(year, 2, 22); //beginning of spring

EasterDate.setTime(EasterDate.getTime() + 86400000 * diffDay + 86400000 * plusDays);

return EasterDate;

};

The following Function returns a Date-Object of Easter-Sunday of a given year. If no year is given the routine will use the current year.

[UPDATE 2008/03/28]

Added option to add/subtract a number of days from the calculated eastersunday

e.g.

Ext.util.EasterDate(2008) returns a DateObject of 2008/03/23

Ext.util.EasterDate(2008,5) returns a DateObject of 2008/03/28

Ext.util.EasterDate(2008,-3) returns a DateObject of 2008/03/20

Ext.util.EasterDate = function(year, plusDays) {

if (typeof year === "undefined") {

year = new Date().getFullYear();

}

year = parseInt(year,10);

if (typeof plusDays === "undefined") {

plusDays = 0;

}

plusDays = parseInt(plusDays,10);

//difference to first sunday after first fullmoon after beginning of spring

var a = year % 19;

var d = (19 * a + 24) % 30;

var diffDay = d + (2 * (year % 4) + 4 * (year % 7) + 6 * d + 5) % 7;

if ((diffDay == 35) || ((diffDay == 34) && (d == 28) && (a > 10))) {

diffDay -= 7;

}

var EasterDate = new Date(year, 2, 22); //beginning of spring

EasterDate.setTime(EasterDate.getTime() + 86400000 * diffDay + 86400000 * plusDays);

return EasterDate;

};