WinBatch® Technical Support Forum

All Things WinBatch => WinBatch => Topic started by: stanl on July 17, 2019, 03:27:07 AM

Title: What's up with Easter
Post by: stanl on July 17, 2019, 03:27:07 AM
was playing around with an old Easter Finder script I posted in 2009 and the new TimeFormat() WB function. I was pretty sure the math in the function was accurate, but in trying to predict future Easter Sundays, the script occasionally comes up with the Friday date.  Run the script as is and see what I mean. If you have spare time and like math you might want to provide a second set of eyes...
Code (WINBATCH) Select


;Easter finder function
;Initial Post: Stan Littlefield, 3/25/2009
;
;
;Revised: just tries to predict future Easter Sundays
;occasionally comes up with Friday -
;=======================================================================


#DefineFunction FindEaster(x)
    X=INT(X)


;1  ;Divide X by 19 to get a quotient (which we ignore) and
    ;a reminader A (This is the year's position in the 19 year
    ;lunar cycle.  (A+1) is the Golden number)
    A=X MOD 19


;2  ;Divide X by 100 to get a quotient B and remainder C
    B=X / 100
    C=X MOD 100


;3  ;Divide B by 4 to get quotient D and remainder E
    D=B/4
    E=B MOD 4


;4  ;Divide (8B+13) by 25 to get quotient G.  Ignore remainder.
     G = ((8*B)+13) / 25


;5  ;Divide 19A+B-D-G+15 by 30 to get a quotient (which we ignore)
    ;and a remainder H (The year's EPACT is 23-H when H is less than 24
    ;and 53-H otherwise)
    H = ((19*A)+B-D-G+15) MOD 30


;6  ;Divide A+11H by 319 to get quotient M and a ignored remainder
    M = (A + (11*H)) / 319


;7  ;Divide C by 4 to get quotient J and remainder K
    J= C/4
    K= C MOD 4


;8  ;Divide 2E+2J-K-H-M+32 by 7 to get a quotient (which we ignore)
    ;and a remainder L
    L = ((2*E)+(2*J)-K-H-M+32) MOD 7


;9  ;Divide H-M+L+90 by 25 to get quotient N and a ignored remainder
    N = (H-M+L+90) / 25


;10 ;Divide H-M+L+N+19 by 32 to get a quotient (which we ignore) and
    ; a remainder P
    P = (H-M+L+N+19) MOD 32


;Easter Sunday is the Pth day ofthe Nth month
;(N can be 3=March or 4=April)
    Z=X:":":N:":":P
    return(Z)
   
#endfunction


nStart=2010
nEnd=2050
nMonth=3
nDay=25
list=""


EFFormat=`WWWDLGED,6.2`


EFCaption=`Easter Between `:nStart:' and ':nEnd
EFX=084
EFY=142
EFWidth=122
EFHeight=102
EFNumControls=007
EFProcedure=`DEFAULT`
EFFont=`DEFAULT`
EFTextColor=`DEFAULT`
EFBackground=`DEFAULT,DEFAULT`
EFConfig=0


EF001=`009,067,036,012,PUSHBUTTON,"PushButton_OK",DEFAULT,"OK",1,10,@csDefButton,DEFAULT,DEFAULT,"0|255|0"`
EF002=`067,067,036,012,PUSHBUTTON,"PushButton_Cancel",DEFAULT,"Cancel",0,20,DEFAULT,DEFAULT,DEFAULT,"255|0|0"`
EF003=`007,007,032,012,STATICTEXT,"StaticText_1",DEFAULT,"Start Year",DEFAULT,30,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
EF004=`007,027,028,012,STATICTEXT,"StaticText_2",DEFAULT,"End Year",DEFAULT,40,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
EF005=`051,007,036,012,EDITBOX,"EditBox_1",nStart,DEFAULT,DEFAULT,60,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
EF006=`051,025,036,012,EDITBOX,"EditBox_2",nEnd,DEFAULT,DEFAULT,70,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
EF007=`027,047,056,012,STATICTEXT,"StaticText_4",DEFAULT,"Change as Needed",DEFAULT,50,DEFAULT,DEFAULT,DEFAULT,DEFAULT`


ButtonPushed=Dialog("EF")




for xx=nStart to nEnd
   easter=TimeFormat(FindEaster(xx),"dddd MMMM d, yyyy")
   if list==""
   list=easter
   else
   list=list:@tab:easter
   endif
next


AskItemList("Easter Should fall on",list,@tab,@unsorted,@single)


Title: Re: What's up with Easter
Post by: td on July 17, 2019, 09:31:50 AM
Being too lazy to debug your formula, decided to try a slightly different formula based on some pseudo-code someone posted at some point in the past.  It seems to work or at least it doesn't produce Friday Easters.

Code (winbatch) Select
#DefineFunction FindEaster(y)
   a = y mod 19
   b = y / 100
   c = y mod 100
   d = b / 4
   e = b mod 4
   f = (b + 8)/ 25
   g = (b - f + 1)/3
   h = ((19*a) + b - d - g + 15) mod 30
   i = c / 4
   k = c mod 4
   l = (32 + (2 * e) + (2 * i) - h - k) mod 7
   m = (a + (11 * h) + (22 * l)) / 451
   month = (h + l - ( 7 * m) + 114) /31
   day = ((h + l - (7 * m) + 114) mod 31) + 1

   return y:':':month:':':day

#endfunction