:: EASTER.BAT J R Stockton www.merlyn.demon.co.uk >= 2009-04-09 @echo off :: JavaScript from my estr-inc.js ; see estr-bcp.htm - :: this code is thereby traceable to the Prayer Book and to the :: Calendar Act (as passed), which are definitive and shown to :: give results which concur with the Papal definition. :: Batch here corresponds :: function jrsEaster(YR) { // Fast JRSEaster, unsigned 32-bit year :: var gn, xx, cy, DM :: gn = YR % 19 // gn ~ GoldenNumber :: xx = (YR/100)|0 :: cy = ((3*(xx+1)/4)|0) - (((13+xx*8)/25)|0) // cy ~ BCPcypher :: xx = ( 6 + YR + ((YR/4)|0) - xx + ((YR/400)|0) ) % 7 :: DM = 21 + (gn*19 + cy + 15)%30 ; DM -= ((gn>10) + DM > 49) // PFM :: return DM + 1 + (66-xx-DM)%7 /* Day-of-March */ } :: Use: EASTER year [1] optional second argument 1 shows intermediates set test=%2 set /a Eyear = %1 if %test%x == 1x echo Eyear is %Eyear% set /a gn = Eyear %% 19 if %test%x == 1x echo gn is %gn% set /a xx = Eyear / 100 if %test%x == 1x echo xx is %xx% set /a cy = 3*(xx+1)/4 - (13+xx*8)/25 if %test%x == 1x echo cy is %cy% set /a xx = ( 6 + Eyear + Eyear/4 - xx + Eyear/400 ) %% 7 if %test%x == 1x echo xx is %xx% set /a DM = 21 + (gn*19 + cy + 15) %% 30 if %test%x == 1x echo DM 1 is %DM% ::set /a DM -= (gn > 10) + DM > 49 set /a DM -= ( (gn / 11) + DM ) / 50 if %test%x == 1x echo DM 2 is %DM% set /a DoM = DM + 1 + (66-xx-DM) %% 7 if %test%x == 1x echo Easter Sunday as Day of March is %DoM% set /a Eday = ((DoM - 1) %% 31 ) + 1 set /a Emonth = 3 + DoM/32 set /a Eday = Eday + 100 set Eday=%Eday:~-2% set EasterSunday=%Eyear%-0%Emonth%-%Eday% if %test%x == 1x echo Easter Sunday is %EasterSunday% if not %test%x == 1x echo %EasterSunday% set gn= set xx= set cy= set DM= set DoM= set test= if %test%x == 1x echo. GOTO FINISH :: NOWMINUS is Pascal, independently tested, known good. Y<~30000 :: FOR /L %A IN (1000,1,9999) DO @EASTER %A >> $$E.TXT :: FOR /L %A IN (1000,1,9999) DO @NOWMINUS z6 y-%A y1 ¬ l10 r l0 r >> $$N.TXT :: Tested OK, 0000-20000. :: Using JavaScript page js-date8.htm to list Easter, OK 1500-50000 :: Using the following (slow), OK 1500-5725000, 0 - 10000. :: DRAFT : ETEST.BAT set /a yr = %1 :RPT CALL EASTER %yr% :: use ZEG1886 in: for /f %%t in ('CSCRIPT //NOLOGO ETEST.JS %yr%') do @set JSE=%%t if %EasterSunday%==%JSE% GOTO INC echo FAIL - BAT: %EasterSunday% JS: %JSE% GOTO FINISH :INC :: echo %yr% OK set /a yr += 1 GOTO RPT ::FINISH :: ETEST.JS : function ZEG1886(Yr) { var a, b, d, g, K = Yr%100, J = (Yr-K)/100, Ko4 = Math.floor(K/4), Jo4 = Math.floor(J/4), e = J%4 a = (5*J + K) % 19 g = J - Jo4 - Math.floor((8*J+13)/25) b = ( 19*a+15 + g ) % 30 d = (b + K + Ko4 + Jo4 + 2 + 5*J) % 7 // arg be neg? // +2 +5* if (d==0) { if ((b==29) || ( b==28 && a>10)) d = 7 } return 28 + b - d } var x = WScript.Arguments var Yr = x(0) Dy = ZEG1886(Yr) ; Mo = 3 if (Dy>31) { Mo++ ; Dy -= 31 } WScript.echo(Yr + "-0" + Mo + "-" + String(Dy+100).substr(1)) :FINISH