Mega Code Archive

 
Categories / Delphi / Algorithm Math
 

How to calculate the easter sunday

Title: How to calculate the easter sunday Question: A small function that returns the Easter Sunday of a given year. Answer: function EasterSunday(aYear: Word): TDateTime; { Ash Wednesday := EasterSunday - 46 } { Good Friday := EasterSunday - 2 } { Ascension Day := EasterSunday + 39 } { Whit Monday := EasterSunday + 50 } { Corpus Christi := EasterSunday + 60 } var R1, R2, R3, R4, R5: Longint; Easter : TDateTime; VJ, VM, VD : Word; begin R1 := aYear mod 19; R2 := aYear mod 4; R3 := aYear mod 7; R4 := (19 * R1 + 24) mod 30; R5 := (6 * R4 + 4 * R3 + 2 * R2 + 5) mod 7; Easter := EncodeDate(aYear, 3, 22); Easter := Easter + R4 + R5; DecodeDate(Easter, VJ, VM, VD); case VD of 26 : Easter := EncodeDate(aYear, 4, 19); 25 : if R1 10 then Easter := EncodeDate(aYear, 4, 18); end; Result:= Easter; end;