(view source code of easter.bat as plain text)
@ECHO OFF
ECHO.
:: Localize environment and enable delayed variable expansion (XP and later only)
IF "%OS%"=="Windows_NT" (
SETLOCAL ENABLEDELAYEDEXPANSION
) ELSE (
GOTO Syntax
)
:: Command line check
IF NOT "%~2"=="" GOTO Syntax
:: REG.EXE version 3 or later required
IF NOT EXIST "%SystemRoot%\System32\reg.exe" GOTO Syntax
FOR /F "tokens=5" %%A IN ('FILEVER.EXE "%SystemRoot%\System32\reg.exe"') DO (
FOR /F "delims=." %%B IN ("%%A") DO (
IF %%B0 LSS 30 GOTO Syntax
)
)
:: Determine current year
CALL :ThisYear
:: If no year is specified, use current year
IF "%~1"=="" (
SET Y=%ThisYear%
) ELSE (
SET /A Y=%~1
IF ERRORLEVEL 1 GOTO Syntax
)
:: Is the specified year valid?
:: Check if number
FOR /F "tokens=1 delims=0123456789" %%A IN ("%Y%") DO IF NOT "%%~A"=="" GOTO Syntax
:: check if in range
IF %Y%0 LSS 17520 GOTO Syntax
IF %Y%0 GTR 30000 GOTO Syntax
:: Array of month names used
SET Month.03=March
SET Month.3=March
SET Month.04=April
SET Month.4=April
SET Month.05=May
SET Month.5=May
SET Month.06=June
SET Month.6=June
:: Calculate Easter Day using the instructions found at
:: Simon Kershaw's "KEEPING THE FEAST"
:: http://www.oremus.org/liturgy/etc/ktf/app/easter.html
SET /A G = ( %Y% %% 19 ) + 1
SET /A S = (( %Y% - 1600 ) / 100 ) - (( %Y% - 1600 ) / 400 )
SET /A L = ((( %Y% - 1400 ) / 100 ) * 8 ) / 25
SET /A P1 = ( 30003 - 11 * %G% + %S% - %L% ) %% 30
SET P=%P1%
IF %P%==28 IF %G% GTR 11 SET P=27
IF %P%==29 SET P=28
SET /A D = ( %Y% + ( %Y% / 4 ) - ( %Y% / 100 ) + ( %Y% / 400 )) %% 7
SET /A D1 = ( 8 - %D% ) %% 7
SET /A P2 = ( 70003 + %P% ) %% 7
SET /A X = (( 70004 - %D% - %P% ) %% 7 ) + 1
SET /A E = %P% + %X%
IF %E% LSS 11 (
SET /A ED = %E% + 21
SET EM=3
) ELSE (
SET /A ED = %E% - 10
SET EM=4
)
IF %Y% LSS %ThisYear% SET IS=was
IF %Y% EQU %ThisYear% SET IS=is
IF %Y% GTR %ThisYear% SET IS=will be
:: Calculate Ascension and Pentecost dates
CALL :JDate %Y% %EM% %ED%
SET /A ADJ = %JDate% + 39
SET /A PDJ = %JDate% + 49
CALL :GDate %ADJ%
FOR /F "tokens=2,3" %%A IN ("%GDate%") DO (
SET AM=%%A
SET AD=%%B
)
CALL :GDate %PDJ%
FOR /F "tokens=2,3" %%A IN ("%GDate%") DO (
SET PM=%%A
SET PD=%%B
)
:: Display the result
ECHO In %Y% Easter Day %IS% !Month.%EM%! %ED%
ECHO Ascension Day %IS% !Month.%AM%! %AD%
ECHO Pentecost %IS% !Month.%PM%! %PD%
:: Done
GOTO End
:GDate
:: Convert Julian date back to "normal" Gregorian date
:: Argument : Julian date
:: Returns : YYYY MM DD
::
:: Algorithm based on Fliegel-Van Flandern
:: algorithm from the Astronomical Almanac,
:: provided by Doctor Fenton on the Math Forum
:: (http://mathforum.org/library/drmath/view/51907.html),
:: and converted to batch code by Ron Bakowski.
::
SET /A P = %1 + 68569
SET /A Q = 4 * %P% / 146097
SET /A R = %P% - ( 146097 * %Q% +3 ) / 4
SET /A S = 4000 * ( %R% + 1 ) / 1461001
SET /A T = %R% - 1461 * %S% / 4 + 31
SET /A U = 80 * %T% / 2447
SET /A V = %U% / 11
SET /A GYear = 100 * ( %Q% - 49 ) + %S% + %V%
SET /A GMonth = %U% + 2 - 12 * %V%
SET /A GDay = %T% - 2447 * %U% / 80
:: Clean up the mess
FOR %%A IN (P Q R S T U V) DO SET %%A=
:: Add leading zeroes
IF 1%GMonth% LSS 20 SET GMonth=0%GMonth%
IF 1%GDay% LSS 20 SET GDay=0%GDay%
:: Return value
SET GDate=%GYear% %GMonth% %GDay%
GOTO:EOF
:JDate
SETLOCAL
:: Convert date to Julian
:: Arguments : YYYY MM DD
:: Returns : Julian date
::
:: Algorithm based on Fliegel-Van Flandern
:: algorithm from the Astronomical Almanac,
:: provided by Doctor Fenton on the Math Forum
:: (http://mathforum.org/library/drmath/view/51907.html),
:: and converted to batch code by Ron Bakowski.
::
SET Month0=%2
SET Day0=%3
:: Strip leading zeroes from month and day
IF 1%Month0% GTR 100 SET /A Month0 = 1%Month0% - 100
IF 1%Day0% GTR 100 SET /A Day0 = 1%Day0% - 100
SET /A Month1 = ( %Month0% - 14 ) / 12
SET /A Year1 = %1 + 4800
SET /A JDate = 1461 * ( %Year1% + %Month1% ) / 4 + 367 * ( %Month0% - 2 -12 * %Month1% ) / 12 - ( 3 * ( ( %Year1% + %Month1% + 100 ) / 100 ) ) / 4 + %3 - 32075
ENDLOCAL & SET JDate=%JDate%
GOTO:EOF
:ThisYear
:: Read iDate and sDate from the registry; more info on iDate and sDate:
:: https://www.itprotoday.com/windows-78/jsi-tip-0311-regional-settings-registry
FOR /F "tokens=3" %%A IN ('REG.EXE Query "HKEY_CURRENT_USER\Control Panel\International" /v iDate') DO SET iDate=%%A
FOR /F "tokens=3" %%A IN ('REG.EXE Query "HKEY_CURRENT_USER\Control Panel\International" /v sDate') DO SET sDate=%%A
:: Detemine current year depending on registry settings
FOR %%A IN (%Date%) DO SET Today=%%A
IF %iDate%==2 (SET Token=1) ELSE (SET Token=3)
FOR /F "tokens=%Token% delims=%sDate%" %%A IN ("%Today%") DO SET ThisYear=%%A
GOTO:EOF
:Syntax
ECHO Easter.bat, Version 3.01 for Windows XP and later
ECHO Calculate Easter day, Ascension day and Pentecost dates for the specified year.
ECHO.
ECHO Usage: EASTER [ year ]
ECHO.
ECHO Where: year should be within the range of 1752..3000 (default: current year)
ECHO.
ECHO Note: Easter day calculation based on Simon Kershaw's "KEEPING THE FEAST"
ECHO (http://www.oremus.org/liturgy/etc/ktf/app/easter.html).
ECHO Julian date math algorithms based on Fliegel-Van Flandern algorithm
ECHO from the Astronomical Almanac, provided by Doctor Fenton on the Math
ECHO Forum (http://mathforum.org/library/drmath/view/51907.html), and
ECHO converted to batch code by Ron Bakowski.
ECHO.
ECHO Written by Rob van der Woude
ECHO http://www.robvanderwoude.com
:End
IF "%OS%"=="Windows_NT" ENDLOCAL
page last modified: 2024-04-16; loaded in 0.0070 seconds