LB Booster
Programming >> BASIC code examples >> Easter
http://lbb.conforums.com/index.cgi?board=code&action=display&num=1474120502

Easter
Post by Jack Kelly on Sep 17th, 2016, 1:55pm

I found this snippet in the Liberty BASIC Community Wiki, posted in the Shared Code section by HarmonV. I was impressed. You know how I like calendar functions.

Code:
' Easter date Calculation -- function definition by HarmonV,  February 2007
print "The date of Easter for any year from 1583 to 4099."
print ""
[begin] 
input "Enter year: "; yyyy
yyyy=abs(int(yyyy))
if yyyy=0 then [finish]
Easter$ = Easter$(yyyy)
if Easter$<>"" then
    print Easter$
else
    print "Invalid year"
end if
goto [begin]
 
[finish]
print "Done."
end
 
function Easter$(yyyy)
    if yyyy<1583 or yyyy>4099 then Easter$="": exit function
    gn = yyyy mod 19 + 1    ' Golden Number
    c = int(yyyy/100)+1     ' Century
    JE = (11*(gn-1)) mod 30 ' Julian Epact #
    S = int(3*c/4)          ' Solar Equation (3 non-leap days every 4 centuries)
    L = int((8*c+5)/25)     ' Lunar Equation (8 days every 25 centuries)
    GE = JE - S + L + 8     ' Gregorian Epact #
    if GE<1 then GE = GE + 30*(1+int(abs(GE)/30))
    GE = GE mod 30
' efm = Ecclesiastical full moon (22=Mar 22nd, 32=Apr 1st, etc)
    if GE<24 then efm = 44-GE
    if GE>23 then efm = 74-GE
    if (GE=24) or (GE=25 and gn>11) then efm = efm - 1
 
    wd = (efm + 2 + yyyy + int(yyyy/4) - int(yyyy/100) + int(yyyy/400) ) mod 7
    ed = efm + 7 - wd    ' Easter Day = first Sunday after EFM
    mm = 3+int(ed/32): mm$=str$(mm): if len(mm$)=1 then mm$="0"+mm$
    dd = ed - 31*int(mm/4): dd$=str$(dd): if len(dd$)=1 then dd$="0"+dd$
    Easter$ = str$(yyyy)+mm$+dd$
end function
 


I made myself a page there and posted some of my recent programs. The "organizers" went to a great deal of effort making the wiki many years ago, but it doesn't appear to be getting much use lately.

http://basic.wikispaces.com/JackKelly6

Re: Easter
Post by Richard Russell on Sep 17th, 2016, 3:44pm

on Sep 17th, 2016, 1:55pm, Jack Kelly wrote:
I found this snippet in the Liberty BASIC Community Wiki, posted in the Shared Code section by HarmonV. I was impressed.

Indeed, calculating the date of Easter is challenging. Another difficult calendar-related problem is calculating sunrise and sunset times accurately, especially for latitudes where they don't happen at all for some of the year! I've got some BBC BASIC code to do it but I've not tried translating it to Liberty BASIC.

Richard.