# Thread: Ext.util.EasterDate

1. ## Ext.util.EasterDate

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

PHP Code:
```     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;    };  ```

2. interesting plugin, but
"Ext can only calculate DateObjects between 1970 and 2099"
i didn't know that...

are you sure?

3. Mmh, i read about this on the net somewhere, that javascript should have these restrictions on 32-Bit machines....anyway i did some more testing and it also seems to work with other years such as 3100 and 1960....

I deleted the exception-catch out of the code, so it should work for any year now.

Thanks for pointing that out

4. Originally Posted by wm003
Mmh, i read about this on the net somewhere, that javascript should have these restrictions on 32-Bit machines....anyway i did some more testing and it also seems to work with other years such as 3100 and 1960....

I deleted the exception-catch out of the code, so it should work for any year now.

Thanks for pointing that out
do you happen to have the URL to the article?
might be good to know.

5. Originally Posted by mystix
do you happen to have the URL to the article?
might be good to know.
e.g:
http://jneumeyer.com/Chap10Notes.htm

He talks only about the 1970 thing

The original javascript routine i had adopted the code above also had this restriction set. And i never doubt about that myself (maybe because i never happened to use any date outside this range)
The quote about the 32-Bit machines i read in the PHP-Docs for easter_date.

6. Updated the code with optional number of days to add/subtract from the calculated eastersunday

7. ## Where you apply it?

@wm003, I was looking where apply this method, but don't was so lucky... Where do you thought add it?

8. i am using it in the DatePickerPlus Widget to calculate the national holidays around easter

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•