### Author Topic: Easter Date Calculator  (Read 1543 times)

#### artmaker43

• Sr. Member
• Posts: 262
• Old Fart
##### Easter Date Calculator
« on: March 22, 2016, 08:05:49 pm »
Calculate any range of Easter Sunday Dates between 1583 through 4099

NOTE: The engine that makes the computations came from:

https://www.assa.org.au/edm (Scroll to the bottom of the page)

I have just designed the front end with error checking.

Code: [Select]
`'' **** Easter Date Calculator ****'DEFINT A-ZVIEW PRINTCLSLOCATE 1, 18, 1COLOR 9PRINT "EASTER SUNDAY DATE CALCULATOR (1583 - 4099)"FromHere:VIEW PRINT 3 TO 24COLOR 14CLSGOSUB Prompt1LOCATE 3, 2COLOR 2PRINT "STARTING FROM This 4-Digit Year (ò 1583 & ó 4099): ";COLOR 14LINE INPUT ; FromYear\$FromYear\$ = LTRIM\$(RTRIM\$(FromYear\$))IF FromYear\$ = "" THEN    VIEW PRINT    COLOR 7    CLS    SYSTEMELSEIF LEFT\$(FromYear\$, 1) = "0" OR LEN(FromYear\$) <> 4 THEN    RUNEND IFFromYear = VAL(FromYear\$)IF FromYear < 1583 OR Year > 4099 THEN    RUNEND IFToHere:VIEW PRINT 6 TO 24CLSGOSUB Prompt2LOCATE 6, 2COLOR 2PRINT "ENDING AT This 4-Digit Year (ò "; FromYear\$; " & ó 4099): ";COLOR 14LINE INPUT ; ToYear\$ToYear\$ = LTRIM\$(RTRIM\$(ToYear\$))IF ToYear\$ = "" THEN    GOTO FromHereELSEIF LEFT\$(ToYear\$, 1) = "0" OR LEN(ToYear\$) <> 4 THEN    GOTO ToHereEND IFToYear = VAL(ToYear\$)IF ToYear < FromYear OR ToYear > 4099 THEN    GOTO ToHereEND IFIF FromYear = ToYear THEN    VIEW PRINT 18 TO 24    CLS    LOCATE 18, 19    COLOR 2    PRINT "Easter Sunday: ";    COLOR 14ELSE    VIEW PRINT 9 TO 24    CLSEND IFCount = 0FOR Year = FromYear TO ToYear    Count = Count + 1    IF Count = 7 THEN        Count = 1        PRINT        IF CSRLIN = 23 THEN            GOSUB SeeMore            IF NoMore THEN                RUN            END IF        END IF    END IF    Year\$ = MID\$(STR\$(Year), 2)    GOSUB Compute    IF Count = 1 AND FromYear < ToYear THEN        LOCATE CSRLIN, 2    END IF    PRINT "0";    IF Month = 4 THEN        PRINT "4";    ELSE        PRINT "3";    END IF    PRINT "/";    Day\$ = MID\$(STR\$(Day), 2)    IF LEN(Day\$) = 1 THEN        PRINT "0";    END IF    PRINT Day\$; "/"; Year\$; SPC(2);    IF FromYear = ToYear THEN        COLOR 2        PRINT "(";        COLOR 14        IF Month = 3 THEN            PRINT "March";        ELSE            PRINT "April";        END IF        PRINT SPC(1); Day\$; ","; SPC(1); Year\$;        COLOR 2        PRINT ")"        EXIT FOR    END IFNEXT YearCOLOR 14LOCATE 24, 40, 1'wait for any key to restartWHILE INKEY\$ = ""    _LIMIT 25WENDRUNCompute:' code from: https://www.assa.org.au/edmFirstDig = Year \ 100 'first 2 digits of yearRemain19 = Year MOD 19 'remainder of year / 19' calculate PFM datetemp = (FirstDig - 15) \ 2 + 202 - 11 * Remain19SELECT CASE FirstDig    CASE 21, 24, 25, 27 TO 32, 34, 35, 38        temp = temp - 1    CASE 33, 36, 37, 39, 40        temp = temp - 2END SELECTtemp = temp MOD 30tA = temp + 21IF temp = 29 THEN tA = tA - 1IF (temp = 28 AND Remain19 > 10) THEN tA = tA - 1' find the next SundaytB = (tA - 19) MOD 7tC = (40 - FirstDig) MOD 4IF tC = 3 THEN tC = tC + 1IF tC > 1 THEN tC = tC + 1temp = Year MOD 100tD = (temp + temp \ 4) MOD 7tE = ((20 - tB - tC - tD) MOD 7) + 1Day = tA + tE' return the dateIF Day > 31 THEN    Day = Day - 31    Month = 4ELSE    Month = 3END IFRETURNPrompt1:LOCATE 24, 30COLOR 7PRINT "Hit ";COLOR 23PRINT "<Enter>";COLOR 7PRINT " to Quit";RETURNPrompt2:LOCATE 24, 29COLOR 7PRINT "Hit ";COLOR 23PRINT "<Enter>";COLOR 7PRINT " to Go Back";RETURNSeeMore:VIEW PRINT 24 TO 24CLSLOCATE 24, 14, 0COLOR 7PRINT "Hit ";COLOR 23PRINT "<Esc>";COLOR 7PRINT " to Restart OR ";COLOR 23PRINT "<Any Other Key>";COLOR 7PRINT " to Continue";DO    _LIMIT 25    An\$ = INKEY\$    IF LEN(An\$) THEN        IF An\$ = CHR\$(27) THEN            NoMore = -1        ELSE            VIEW PRINT 9 TO 24            COLOR 14            CLS        END IF        EXIT DO    END IFLOOPRETURN`
The zip file contains the source code, the Windows executable, and a PDF with multiple screen shots.

#### Pete

• Hero Member
• Posts: 7410
• Cuz I sez so varmint!
##### Re: Easter Date Calculator
« Reply #1 on: March 23, 2016, 01:17:25 pm »
Great, but I was trying to book a trip for Easter 4100. We'll have transporters by then, but due to the TSA worker's union, you will still have to arrive 2 hours before your departure time to be beamed.

Tried it. Works as advertised. Very, very nice!

Pete
Give a man a program, and he does one thing for a day. Teach a man to program, and he does one thing for a lifetime.

#### artmaker43

• Sr. Member
• Posts: 262
• Old Fart
##### Re: Easter Date Calculator
« Reply #2 on: March 23, 2016, 03:15:54 pm »
It was a fun project. Glad you found it useful. I'm not sure if the algorithm will work past 4099, but if it does, take care and have a nice trip. Remember - no open containers...

#### Pete

• Hero Member
• Posts: 7410
• Cuz I sez so varmint!
##### Re: Easter Date Calculator
« Reply #3 on: March 23, 2016, 07:02:37 pm »
I made a calendar program to use in my appointment book. I got lucky with the Easter part, because I never worked on Sundays. If you have a calendar routine, great. If not, and you would like one. I have one, and I believe so does Clippy.

Oh, and you forgot to add.. And keep your hands and feet inside the particle disseminator at all times.

Pete
Give a man a program, and he does one thing for a day. Teach a man to program, and he does one thing for a lifetime.

#### Clippy

• Hero Member
• Posts: 19404
• I LOVE π = 4 * ATN(1)    Use the QB64 WIKI >>>
##### Re: Easter Date Calculator
« Reply #4 on: March 23, 2016, 07:25:47 pm »
Code: [Select]
`yr = VAL(RIGHT\$(DATE\$, 4))Easter yr, EM, EDprint EM; EDSUB Easter (yrn, EM, ED)c = yrn \ 100 'CenturyG = yrn MOD 19K = (c - 17) \ 25i = (c - (c \ 4) - (c - K) \ 3 + (19 * G) + 15) MOD 30i = i - (i \ 28) * (1 - (i \ 28) * (29 \ (i + 1)) * ((21 - G) \ 11))J = (yrn + yrn \ 4 + i + 2 - c + c \ 4) MOD 7L = i - JEM = 3 + (L + 40) \ 44 'Month of Easter.ED = L + 28 - 31 * (EM \ 4) 'Day of Easter.END SUB`
QB64 WIKI: Main Page
QB64 SDL

#### Pete

• Hero Member
• Posts: 7410
• Cuz I sez so varmint!
##### Re: Easter Date Calculator
« Reply #5 on: March 23, 2016, 07:47:32 pm »
Not bad for a scarecrow apprentice!

Here is a comparison between both of your programs, and yes, at the year 4100 the program ends with a dependency.

Code: [Select]
`DEFINT A-Zyr = 2015DO  yr = yr + 1  yr\$ = LTRIM\$(STR\$(yr))  Easter yr, EM, ED  PRINT EM; ED,  FromYear\$ = LTRIM\$(RTRIM\$(yr\$))  FromYear = VAL(FromYear\$)  ToYear = FromYear  Count = 0  FOR Year = FromYear TO ToYear    Count = Count + 1    IF Count = 7 THEN      Count = 1    END IF    Year\$ = MID\$(STR\$(Year), 2)    GOSUB Compute    IF Count = 1 AND FromYear < ToYear THEN      LOCATE CSRLIN, 2    END IF    PRINT "0";    IF Month = 4 THEN      PRINT "4";    ELSE      PRINT "3";    END IF    PRINT "/";    Day\$ = MID\$(STR\$(Day), 2)    IF LEN(Day\$) = 1 THEN      PRINT "0";    END IF    PRINT Day\$; "/"; Year\$; SPC(2)    IF VAL(Day\$) <> ED OR Month <> EM THEN END  NEXT YearLOOPCompute:' code from: https://www.assa.org.au/edmFirstDig = Year \ 100 'first 2 digits of yearRemain19 = Year MOD 19 'remainder of year / 19' calculate PFM datetemp = (FirstDig - 15) \ 2 + 202 - 11 * Remain19SELECT CASE FirstDig  CASE 21, 24, 25, 27 TO 32, 34, 35, 38    temp = temp - 1  CASE 33, 36, 37, 39, 40    temp = temp - 2END SELECTtemp = temp MOD 30tA = temp + 21IF temp = 29 THEN tA = tA - 1IF (temp = 28 AND Remain19 > 10) THEN tA = tA - 1' find the next SundaytB = (tA - 19) MOD 7tC = (40 - FirstDig) MOD 4IF tC = 3 THEN tC = tC + 1IF tC > 1 THEN tC = tC + 1temp = Year MOD 100tD = (temp + temp \ 4) MOD 7tE = ((20 - tB - tC - tD) MOD 7) + 1Day = tA + tE' return the dateIF Day > 31 THEN  Day = Day - 31  Month = 4ELSE  Month = 3END IFRETURNPrompt1:LOCATE 24, 30COLOR 7PRINT "Hit ";COLOR 23PRINT "<Enter>";COLOR 7PRINT " to Quit";RETURNPrompt2:LOCATE 24, 29COLOR 7PRINT "Hit ";COLOR 23PRINT "<Enter>";COLOR 7PRINT " to Go Back";RETURNSeeMore:VIEW PRINT 24 TO 24CLSLOCATE 24, 14, 0COLOR 7PRINT "Hit ";COLOR 23PRINT "<Esc>";COLOR 7PRINT " to Restart OR ";COLOR 23PRINT "<Any Other Key>";COLOR 7PRINT " to Continue";DO  _LIMIT 25  An\$ = INKEY\$  IF LEN(An\$) THEN    IF An\$ = CHR\$(27) THEN      NoMore = -1    ELSE      VIEW PRINT 9 TO 24      COLOR 14      CLS    END IF    EXIT DO  END IFLOOPRETURNSUB Easter (yrn, EM, ED)c = yrn \ 100 'CenturyG = yrn MOD 19K = (c - 17) \ 25i = (c - (c \ 4) - (c - K) \ 3 + (19 * G) + 15) MOD 30i = i - (i \ 28) * (1 - (i \ 28) * (29 \ (i + 1)) * ((21 - G) \ 11))J = (yrn + yrn \ 4 + i + 2 - c + c \ 4) MOD 7L = i - JEM = 3 + (L + 40) \ 44 'Month of Easter.ED = L + 28 - 31 * (EM \ 4) 'Day of Easter.END SUB`

Pete
Give a man a program, and he does one thing for a day. Teach a man to program, and he does one thing for a lifetime.

#### artmaker43

• Sr. Member
• Posts: 262
• Old Fart
##### Re: Easter Date Calculator
« Reply #6 on: March 23, 2016, 09:23:11 pm »
I did make a perpetual calendar. See my post here:

http://www.qb64.net/forum/index.php?topic=11838.msg102299#msg102299

As I stated then:

"I just wanted to be able to display an entire year on one screen. I find it handy when you are trying to figure out what day a certain date falls on - either past or present."

#### Billbo

• Hero Member
• Posts: 1143
##### Re: Easter Date Calculator
« Reply #7 on: March 24, 2016, 03:08:02 am »
Pete,

Quote
Here is a comparison between both of your programs, and yes, at the year 4100 the program ends with a dependency.

Are you sure that this is a comparison?

Bill

#### Johny B.

• QB64 Partner Site Owner
• Hero Member
• Posts: 1544
##### Re: Easter Date Calculator
« Reply #8 on: March 24, 2016, 04:12:33 am »
Calculating Easter on Unix:
Code: [Select]
`year\$ = "2016"SHELL "ncal -e " + year\$ + " >easter_date.txt"OPEN "easter_date.txt" FOR INPUT AS #1LINE INPUT #1, e\$PRINT e\$CLOSE #1KILL "easter_date.txt"`
Displaying a yearly calendar:
Code: [Select]
`year\$ = "2016"SHELL "ncal -h " + year\$ + " >yearly_cal.txt"OPEN "easter_date.txt" FOR INPUT AS #1FOR i = 1 TO 25    LINE INPUT #1, e\$    IF e\$ <> "" THEN PRINT e\$NEXT iCLOSE #1KILL "yearly_cal.txt"`

#### DanTurtle

• Jr. Member
• Posts: 77
• DanTurtle aka CodeHunter
##### Re: Easter Date Calculator
« Reply #9 on: June 17, 2016, 12:21:56 am »
Okay I couldn't resist.  I thought I would share a function I use:

Code: [Select]
`Function DayEaster(Year As Integer) As StringDim As Single A, B, C, D, E, F, Year1Dim As String DayIf Year>1582 Then  Year1=Int(Year/100)/4  A=Int((Year/19-Int(Year/19))*19+.001)  B=Int((Int(Year/100)-Int(((Int(Year/100)+8)/25)+.001)+1)/3)  C=(19*A+Int(Year/100)-Int(Year1)-B+15)/30  C=Int((C-Int(C))*30+.001)  D=Int((Year/100-Int(Year/100))*100+.001)/4  E=(32+2*Int((Year1-Int(Year1))*4+.001)+2*Int(D)-C-Int((D-Int(D))*4+.001))/7  E=Int((E-Int(E))*7+.001)  F=(C+E-7*Int((A+11*C+22*E)/451)+114)/31  Day=Right("0"+LTrim(Str(Int((F-Int(F))*31+.001)+1)),2)  If Int(F)=3 Then DayEaster="March "+Day Else DayEaster="April "+DayEnd IfEnd Function`
Here is where you can find the original code I took it from:

BASIC Programs from Sky & Telescope
http://www.skyandtelescope.com/astronomy-resources/basic-programs-from-sky-telescope/

Direct link to the source code: