Calculate date for Easter

Post Reply
Dalede
Posts: 131
Joined: Fri Dec 28, 2012 4:00 pm
Location: Grass Valley, CA, USA
Contact:

Calculate date for Easter

Post by Dalede »

Have you ever wondered when Easter will come in the years ahead or in the past. Computing the date of Easter requires finding the remainder of a bunch of integer divisions. For that you need a mod operator that this basic doesn't have. Another def function to the rescue!

Enjoy,
Dale

print "EASTER DATE CALCULATION FOR YEARS 1583 TO 4099"
rem y is a 4 digit year 1583 to 4099
rem d returns the day of the month of Easter
rem m returns the month of Easter
rem Easter Sunday is the Sunday following the Paschal
rem Full Moon (PFM) date for the year
rem This algorithm is an arithmetic interpretation of the 3
rem step Easter Dating Method developed by Ron Mallen 1985.
rem from http://www.assa.org.au/edm
def mod(a,n)=a-(n* int(a/n))
start:
input "year":y
gosub calc
d$=d
print m$;" ";d$;",";y
goto start
rem Subroutine EasterDate (d, m, y)
calc:
FirstDig = int(y / 100) rem first 2 digits of year
Remain19 = mod(y,19) rem remainder of year / 19
rem calculate PFM date
temp = int((FirstDig - 15)/2) + 202 - 11 * Remain19
on FirstDig-20 goto once,done,done,once,once,done,once,once, once,once,once,once,twice,once,once,twice,twice,once,twice, twice
goto done
twice: temp = temp - 1
once: temp = temp - 1
done:
temp = mod(temp,30)
tA = temp + 21
If temp = 29 Then tA = tA - 1
If temp = 28 And Remain19 > 10 Then tA = tA - 1
rem find the next Sunday
tB = mod((tA - 19),7)
tC = mod((40 - FirstDig),4)
If tC = 3 Then tC = tC + 1
If tC > 1 Then tC = tC + 1
temp = mod(y,100)
tD = mod((temp + int(temp / 4)),7)
tE = mod((20 - tB - tC - tD),7) + 1
d = tA + tE rem return the date
If d > 31 Then
d = d - 31
m = 4
m$="April"
else
m = 3
m$="March"
End if
return

foxbase
Posts: 2
Joined: Tue Jan 19, 2016 1:02 am

Re: Calculate date for Easter

Post by foxbase »

I've noticed I get different results for many of the programs on this forum.
When I run 2001-2020, the only years that are correct are 2005,2008,2013,2016
The other years compute a date 1-36 days too early.

Henko
Posts: 814
Joined: Tue Apr 09, 2013 12:23 pm
My devices: iPhone,iPad
Windows
Location: Groningen, Netherlands
Flag: Netherlands

Re: Calculate date for Easter

Post by Henko »

foxbase wrote:I've noticed I get different results for many of the programs on this forum.
When I run 2001-2020, the only years that are correct are 2005,2008,2013,2016
The other years compute a date 1-36 days too early.
I can make a guess where the error is.
The program is coded years ago when the "int" function had a truncation function. In one of the updates of SB, the "floor" function was introduced, and the "int" function was changed into a rounding function. A number of programs using the "int" function suddenly gave erronous results. This program is probably one of them.

So, changing the "int" in the "def mod.. etc." line after the REM's by a "floor" might do the trick. (Maybe there are more INT's in the code, i didn't check)

User avatar
Dutchman
Posts: 851
Joined: Mon May 06, 2013 9:21 am
My devices: iMac, iPad Air, iPhone
Location: Netherlands
Flag: Netherlands

Re: Calculate date for Easter

Post by Dutchman »

Dalede wrote:For that you need a mod operator that this basic doesn't have. Another def function to the rescue!
Smart basic has a mod-operator:
Numeric math operations are: +, -, *, /, %, ^.
Operation % is a remainder of division …
There is some work to do DaleDe in order to make it correct and at SB-level ;)

User avatar
Mr. Kibernetik
Site Admin
Posts: 4786
Joined: Mon Nov 19, 2012 10:16 pm
My devices: iPhone, iPad, MacBook
Location: Russia
Flag: Russia

Re: Calculate date for Easter

Post by Mr. Kibernetik »

Dutchman wrote:
Dalede wrote:For that you need a mod operator that this basic doesn't have. Another def function to the rescue!
Smart basic has a mod-operator:
Numeric math operations are: +, -, *, /, %, ^.
Operation % is a remainder of division …
There is some work to do DaleDe in order to make it correct and at SB-level ;)
Yes, mod operator % was added later.

Henko
Posts: 814
Joined: Tue Apr 09, 2013 12:23 pm
My devices: iPhone,iPad
Windows
Location: Groningen, Netherlands
Flag: Netherlands

Re: Calculate date for Easter

Post by Henko »

Dutchman wrote:
Dalede wrote:For that you need a mod operator that this basic doesn't have. Another def function to the rescue!
Smart basic has a mod-operator:

Yes but NOT at the time of coding. Please look at the date of the original posting.
Numeric math operations are: +, -, *, /, %, ^.
Operation % is a remainder of division …
There is some work to do DaleDe in order to make it correct and at SB-level ;)
It WAS at SB level and would still operate correctly if the "int" function was not changed.
Such change is very annoying for hobby programmers and could be disasterous in case of professional usage. SB is an interpreter, not a compiler. That makes a difference in this case.

User avatar
Mr. Kibernetik
Site Admin
Posts: 4786
Joined: Mon Nov 19, 2012 10:16 pm
My devices: iPhone, iPad, MacBook
Location: Russia
Flag: Russia

Re: Calculate date for Easter

Post by Mr. Kibernetik »

Henko wrote:It WAS at SB level and would still operate correctly if the "int" function was not changed.
Such change is very annoying for hobby programmers and could be disasterous in case of professional usage. SB is an interpreter, not a compiler. That makes a difference in this case.
Yes, maybe this decision was not the best one. Now I have this experience... :|

User avatar
Mr. Kibernetik
Site Admin
Posts: 4786
Joined: Mon Nov 19, 2012 10:16 pm
My devices: iPhone, iPad, MacBook
Location: Russia
Flag: Russia

Re: Calculate date for Easter

Post by Mr. Kibernetik »

But this is a common practice :D
If you'd know how much Apple is changing in each iOS version (usually each new iOS release is disastrous for my apps), sB is very stable in its coding paradigm :mrgreen:

Henko
Posts: 814
Joined: Tue Apr 09, 2013 12:23 pm
My devices: iPhone,iPad
Windows
Location: Groningen, Netherlands
Flag: Netherlands

Re: Calculate date for Easter

Post by Henko »

Mr. Kibernetik wrote:But this is a common practice :D

I hope not.


If you'd know how much Apple is changing in each iOS version (usually each new iOS release is disastrous for my apps),

Unbelievable (for a company like Apple)

sB is very stable in its coding paradigm :mrgreen:
Yes it is very stable indeed. I hope you have enough income from it to stay connected...

User avatar
Mr. Kibernetik
Site Admin
Posts: 4786
Joined: Mon Nov 19, 2012 10:16 pm
My devices: iPhone, iPad, MacBook
Location: Russia
Flag: Russia

Re: Calculate date for Easter

Post by Mr. Kibernetik »

New users are in better position because they skipped time of sB's growth :D

Post Reply