Mega Code Archive

 
Categories / Delphi / Algorithm Math
 

Happy Easter )

Title: Happy Easter :) Question: This program demonstrates how to determine the easter date for a given year. Answer: It's quite complex: function GetEaster(Year: Integer): TDate; var y, m, d: Word; G, I, J, C, H, L: Integer; E: TDate; begin G := Year mod 19; C := year div 100; H := (C - C div 4 - (8*C+13) div 25 + 19*G + 15) mod 30; I := H - (H div 28)*(1 - (H div 28)*(29 div (H + 1))*((21 - G) div 11)); J := (Year + Year div 4 + I + 2 - C + C div 4) mod 7; L := I - J; m := 3 + (L + 40) div 44; d := L + 28 - 31*(m div 4); y := Year; // E is the date of the full moon E := EncodeDate(y, m, d); // find next sunday while DayOfWeek(E) 1 do E := E + 1; Result := E; end; { Usage var EasterDate: TDateTime; ... EasterDate := GetEaster(2002); } //* it may work under Delphi v1.x and v2.x as well. i tested it with Delphi 6 Enterprise and it worked fine. *//