Source Code



Calculate Easter Day for a specified year

  • anonymous
  • Jan 16' 14
  • Delphi
  • 248
  • 132
  • United States
function Easter(Year: Integer): TDateTime;
  {----------------------------------------------------------------}
  { Calculates and returns Easter Day for specified year.          }
  { Originally from Mark Lussier, AppVision <[email protected]>.   }
  { Corrected to prevent integer overflow if it is inadvertently   }
  { passed a year of 6554 or greater.                              }
  {----------------------------------------------------------------}
var
  nMonth, nDay, nMoon, nEpact, nSunday, nGold, nCent, nCorx, nCorz: Integer;
begin
  { The Golden Number of the year in the 19 year Metonic Cycle: }
  nGold := (Year mod 19) + 1;
  { Calculate the Century: }
  nCent := (Year div 100) + 1;
  { Number of years in which leap year was dropped in order... }
  { to keep in step with the sun: }
  nCorx := (3 * nCent) div 4 - 12;
  { Special correction to syncronize Easter with moon's orbit: }
  nCorz := (8 * nCent + 5) div 25 - 5;
  { Find Sunday: }
  nSunday := (Longint(5) * Year) div 4 - nCorx - 10;
  { ^ To prevent overflow at year 6554}
  { Set Epact - specifies occurrence of full moon: }
  nEpact := (11 * nGold + 20 + nCorz - nCorx) mod 30;
  if nEpact < 0 then
    nEpact := nEpact + 30;
  if ((nEpact = 25) and (nGold > 11)) or (nEpact = 24) then
    nEpact := nEpact + 1;
  { Find Full Moon: }
  nMoon := 44 - nEpact;
  if nMoon < 21 then
    nMoon := nMoon + 30;
  { Advance to Sunday: }
  nMoon := nMoon + 7 - ((nSunday + nMoon) mod 7);
  if nMoon > 31 then
  begin
    nMonth := 4;
    nDay   := nMoon - 31;
  end
  else
  begin
    nMonth := 3;
    nDay   := nMoon;
  end;
  Easter := EncodeDate(Year, nMonth, nDay);
end; {Easter}
  • Tags : date, calculate
comments powered by Disqus

Related Code

Get Current Date System

Calculate Java hashCode

convert minutes in a days / hours / minutes format

Check or Validate e-mail address



Category

Tag Linked