PowerShell Get-Easter function
Just to long to twitter :
Function Get-Easter ($y){$a=(19*($y%19)+15)%30;$b=(2*($y%4)+4*($y%7)-$a+34)%7;$d=(($a+$b+114)%31)+1;$m=[math]::Floor(($a+$b+114)/31);([datetime]"$m/$d/$y").adddays(13)}
can be used like this :
PS > Get-Easter 2011
Sonntag, 24. April 2011 00:00:00
*Update* : after a comment from , that some of the dates where not correct I did a bit more research, and a there seem to be 3 different methods to calculate easter, the problem was not a bug in the function but taking the wrong method at least for western countries that is,( as I'm a not religious and originaly wanted to twitter the function, I just took the shortest ;) ).
I did allready see 2 Columns in Wikipedia here : http://en.wikipedia.org/wiki/Easter but did not know the difference and just checked against the first one.
But as that is not the most common one and also not the one used where I live, so not realy usefull, I also translated the Western one ;).
function get-Easter ($year) {
$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)
$Month = [math]::floor(($h+$l-7*$m+114)/31)
$day = (($h+$l-7*$m+114)%31)+1
[datetime]"$Month/$Day/$Year"
}
Before making this second script ( from Wikipedia example) I found much more information about easter dates here : http://www.gmarts.org/index.php?go=410
There is also a page with explaination about the 3 different methods and examples of different algorithms if you want to explore easter calculation yourself.
It was a much more interesting topic as I tought before, thanks for the comment about my mistake and getting me in to it more.
* Update 2*
Got it as a Tweetliner after all by delegating the calculation ;) :
function get-easter ($year){[datetime](New-WebServiceProxy "http://bit.ly/clujA9").easter_date($year)}
* Update 3 *
Another way witih for US and GB/I complete holiday list :
$h = New-WebServiceProxy "http://www.holidaywebservice.com/Holidays/HolidayService.asmx?WSDL";$h.GetHolidaysAvailable('US').tables | ft;$h.GetHolidayDate('US','EASTER',2011)
Enjoy, and happy easter calculating,
Greetings /\/\o\/\/