-
25 Mar 2008 10:06 PM #1
Ext.util.EasterDate
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;
};
Extensions:
Ext.ux.DatePickerPlus (Multimonth,Multiselect,...)
Ext.ux.menu.StoreMenu - Ajax Store as menu-item config
Extended Window - Aero Shadows, nested grayscaled modal windows
Ext.MessageBox.promptCombo/promptRadio/promptCheckbox
Ext.ux.plugin.triggerfieldTooltip (for Comboboxes, Datefields...)
Ext.util.MD5
Ext.util.Utf8 (encode/decode)
Ext.util.base64 (encode/decode)
Using:
ExtJS 3.4.1.1/4.2
XPsp3/W7sp1
IE8/9/10
FF 20
Chrome 26
-
25 Mar 2008 10:19 PM #2
interesting plugin, but
i didn't know that..."Ext can only calculate DateObjects between 1970 and 2099"
are you sure?
Sencha Docs / Ext 3.x - ( Docs | Examples )
Learning Center / Saki's Examples (for 2.x) / HOWTO - ( Report Bugs | Post Proper Code )
-
25 Mar 2008 10:53 PM #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
Extensions:
Ext.ux.DatePickerPlus (Multimonth,Multiselect,...)
Ext.ux.menu.StoreMenu - Ajax Store as menu-item config
Extended Window - Aero Shadows, nested grayscaled modal windows
Ext.MessageBox.promptCombo/promptRadio/promptCheckbox
Ext.ux.plugin.triggerfieldTooltip (for Comboboxes, Datefields...)
Ext.util.MD5
Ext.util.Utf8 (encode/decode)
Ext.util.base64 (encode/decode)
Using:
ExtJS 3.4.1.1/4.2
XPsp3/W7sp1
IE8/9/10
FF 20
Chrome 26
-
25 Mar 2008 11:29 PM #4
Sencha Docs / Ext 3.x - ( Docs | Examples )
Learning Center / Saki's Examples (for 2.x) / HOWTO - ( Report Bugs | Post Proper Code )
-
25 Mar 2008 11:54 PM #5
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.Extensions:
Ext.ux.DatePickerPlus (Multimonth,Multiselect,...)
Ext.ux.menu.StoreMenu - Ajax Store as menu-item config
Extended Window - Aero Shadows, nested grayscaled modal windows
Ext.MessageBox.promptCombo/promptRadio/promptCheckbox
Ext.ux.plugin.triggerfieldTooltip (for Comboboxes, Datefields...)
Ext.util.MD5
Ext.util.Utf8 (encode/decode)
Ext.util.base64 (encode/decode)
Using:
ExtJS 3.4.1.1/4.2
XPsp3/W7sp1
IE8/9/10
FF 20
Chrome 26
-
27 Mar 2008 11:28 PM #6
Updated the code with optional number of days to add/subtract from the calculated eastersunday
Extensions:
Ext.ux.DatePickerPlus (Multimonth,Multiselect,...)
Ext.ux.menu.StoreMenu - Ajax Store as menu-item config
Extended Window - Aero Shadows, nested grayscaled modal windows
Ext.MessageBox.promptCombo/promptRadio/promptCheckbox
Ext.ux.plugin.triggerfieldTooltip (for Comboboxes, Datefields...)
Ext.util.MD5
Ext.util.Utf8 (encode/decode)
Ext.util.base64 (encode/decode)
Using:
ExtJS 3.4.1.1/4.2
XPsp3/W7sp1
IE8/9/10
FF 20
Chrome 26
-
3 Aug 2011 6:47 AM #7
Where you apply it?
Where you apply it?
@wm003, I was looking where apply this method, but don't was so lucky... Where do you thought add it?
-
10 Aug 2011 1:57 AM #8
i am using it in the DatePickerPlus Widget to calculate the national holidays around easter
Extensions:
Ext.ux.DatePickerPlus (Multimonth,Multiselect,...)
Ext.ux.menu.StoreMenu - Ajax Store as menu-item config
Extended Window - Aero Shadows, nested grayscaled modal windows
Ext.MessageBox.promptCombo/promptRadio/promptCheckbox
Ext.ux.plugin.triggerfieldTooltip (for Comboboxes, Datefields...)
Ext.util.MD5
Ext.util.Utf8 (encode/decode)
Ext.util.base64 (encode/decode)
Using:
ExtJS 3.4.1.1/4.2
XPsp3/W7sp1
IE8/9/10
FF 20
Chrome 26


Reply With Quote

