Easter calculation (Gregorian only)

Share your advanced PureBasic knowledge/code with the community.
User avatar
jacdelad
Addict
Addict
Posts: 2010
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Easter calculation (Gregorian only)

Post by jacdelad »

In case anyone needs this (I know you've all been waiting for this):

Code: Select all

Procedure.s Easter(Year.w)
  Protected Easter.a,a.a=Mod(Year,19),b.a=Mod(Year,4),c.a=Mod(Year,7),k.a=Int(Year/100),p.a=Int((8*k+13)/25),q.a=Int(k/4),M.a=Mod(15+k-p-q,30),d.a=Mod(19*a+M,30),N.a=Mod(4+k-q,7),e.a=Mod(2*b+4*c+6*d+N,7)
  If d=29 And e=6
    ProcedureReturn "19.04."+Str(Year)
  ElseIf d=28 And e=6 And Mod(11*M+11,30)<19
    ProcedureReturn "18.04."+Str(Year)
  Else
    Easter=22+d+e
  EndIf
  If Easter>31
    ProcedureReturn RSet(Str(Easter-31),2,"0")+".04."+Str(Year)
  Else
    ProcedureReturn RSet(Str(Easter),2,"0")+".03."+Str(Year)
  EndIf
EndProcedure

For Temp=1900 To 2050
  Debug Easter(Temp)
Next
Returns the date of the Easter sunday for the Gregorian calendar. Working on calculating the Julian one, but it somehow doesn't work (which is odd, because it should be easier).
Last edited by jacdelad on Tue Dec 12, 2023 2:16 pm, edited 1 time in total.
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
dige
Addict
Addict
Posts: 1405
Joined: Wed Apr 30, 2003 8:15 am
Location: Germany
Contact:

Re: Easter calculation (Gregorian only)

Post by dige »

Muchas Gracias!!! :D
"Daddy, I'll run faster, then it is not so far..."
Little John
Addict
Addict
Posts: 4789
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Easter calculation (Gregorian only)

Post by Little John »

Easter calculation can be done for the Julian calendar as well as for the Gregorian calendar with version 2.0 of my DateEx module.
Post Reply