Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for easter.bat

(view source code of easter.bat as plain text)

  1. @ECHO OFF
  2. ECHO.
  3.  
  4. :: Localize environment and enable delayed variable expansion (XP and later only)
  5. IF "%OS%"=="Windows_NT" (
  6. 	SETLOCAL ENABLEDELAYEDEXPANSION
  7. ) ELSE (
  8. 	GOTO Syntax
  9. )
  10.  
  11. :: Command line check
  12. IF NOT "%~2"=="" GOTO Syntax
  13.  
  14. :: REG.EXE version 3 or later required
  15. IF NOT EXIST "%SystemRoot%\System32\reg.exe" GOTO Syntax
  16. FOR /F "tokens=5" %%A IN ('FILEVER.EXE "%SystemRoot%\System32\reg.exe"') DO (
  17. 	FOR /F "delims=." %%B IN ("%%A") DO (
  18. 		IF %%B0 LSS 30 GOTO Syntax
  19. 	)
  20. )
  21.  
  22. :: Determine current year
  23. CALL :ThisYear
  24.  
  25. :: If no year is specified, use current year
  26. IF "%~1"=="" (
  27. 	SET Y=%ThisYear%
  28. ) ELSE (
  29. 	SET /A Y=%~1
  30. 	IF ERRORLEVEL 1 GOTO Syntax
  31. )
  32.  
  33. :: Is the specified year valid?
  34. :: Check if number
  35. FOR /F "tokens=1 delims=0123456789" %%A IN ("%Y%") DO IF NOT "%%~A"=="" GOTO Syntax
  36. :: check if in range
  37. IF %Y%0 LSS 17520 GOTO Syntax
  38. IF %Y%0 GTR 30000 GOTO Syntax
  39.  
  40. :: Array of month names used
  41. SET Month.03=March
  42. SET Month.3=March
  43. SET Month.04=April
  44. SET Month.4=April
  45. SET Month.05=May
  46. SET Month.5=May
  47. SET Month.06=June
  48. SET Month.6=June
  49.  
  50. :: Calculate Easter Day using the instructions found at
  51. :: Simon Kershaw's "KEEPING THE FEAST"
  52. :: http://www.oremus.org/liturgy/etc/ktf/app/easter.html
  53. SET /A G  = ( %Y% %% 19 ) + 1
  54. SET /A S  = (( %Y% - 1600 ) / 100 ) - (( %Y% - 1600 ) / 400 )
  55. SET /A L  = ((( %Y% - 1400 ) / 100 ) * 8 ) / 25
  56. SET /A P1 = ( 30003 - 11 * %G% + %S% - %L% ) %% 30
  57. SET P=%P1%
  58. IF %P%==28 IF %G% GTR 11 SET P=27
  59. IF %P%==29 SET P=28
  60. SET /A D  = ( %Y% + ( %Y% / 4 ) - ( %Y% / 100 ) + ( %Y% / 400 )) %% 7
  61. SET /A D1 = ( 8 - %D% ) %% 7
  62. SET /A P2 = ( 70003 + %P% ) %% 7
  63. SET /A X  = (( 70004 - %D% - %P% ) %% 7 ) + 1
  64. SET /A E  = %P% + %X%
  65. IF %E% LSS 11 (
  66. 	SET /A ED = %E% + 21
  67. 	SET EM=3
  68. ) ELSE (
  69. 	SET /A ED = %E% - 10
  70. 	SET EM=4
  71. )
  72. IF %Y% LSS %ThisYear% SET IS=was
  73. IF %Y% EQU %ThisYear% SET IS=is
  74. IF %Y% GTR %ThisYear% SET IS=will be
  75.  
  76. :: Calculate Ascension and Pentecost dates
  77. CALL :JDate %Y% %EM% %ED%
  78. SET /A ADJ = %JDate% + 39
  79. SET /A PDJ = %JDate% + 49
  80. CALL :GDate %ADJ%
  81. FOR /F "tokens=2,3" %%A IN ("%GDate%") DO (
  82. 	SET AM=%%A
  83. 	SET AD=%%B
  84. )
  85. CALL :GDate %PDJ%
  86. FOR /F "tokens=2,3" %%A IN ("%GDate%") DO (
  87. 	SET PM=%%A
  88. 	SET PD=%%B
  89. )
  90.  
  91. :: Display the result
  92. ECHO In %Y% Easter Day %IS% !Month.%EM%! %ED%
  93. ECHO         Ascension Day %IS% !Month.%AM%! %AD%
  94. ECHO         Pentecost %IS% !Month.%PM%! %PD%
  95.  
  96. :: Done
  97. GOTO End
  98.  
  99.  
  100. :GDate
  101. :: Convert Julian date back to "normal" Gregorian date
  102. :: Argument : Julian date
  103. :: Returns  : YYYY MM DD
  104. ::
  105. :: Algorithm based on Fliegel-Van Flandern
  106. :: algorithm from the Astronomical Almanac,
  107. :: provided by Doctor Fenton on the Math Forum
  108. :: (http://mathforum.org/library/drmath/view/51907.html),
  109. :: and converted to batch code by Ron Bakowski.
  110. ::
  111. SET /A P      = %1 + 68569
  112. SET /A Q      = 4 * %P% / 146097
  113. SET /A R      = %P% - ( 146097 * %Q% +3 ) / 4
  114. SET /A S      = 4000 * ( %R% + 1 ) / 1461001
  115. SET /A T      = %R% - 1461 * %S% / 4 + 31
  116. SET /A U      = 80 * %T% / 2447
  117. SET /A V      = %U% / 11
  118. SET /A GYear  = 100 * ( %Q% - 49 ) + %S% + %V%
  119. SET /A GMonth = %U% + 2 - 12 * %V%
  120. SET /A GDay   = %T% - 2447 * %U% / 80
  121. :: Clean up the mess
  122. FOR %%A IN (P Q R S T U V) DO SET %%A=
  123. :: Add leading zeroes
  124. IF 1%GMonth% LSS 20 SET GMonth=0%GMonth%
  125. IF 1%GDay%   LSS 20 SET GDay=0%GDay%
  126. :: Return value
  127. SET GDate=%GYear% %GMonth% %GDay%
  128. GOTO:EOF
  129.  
  130.  
  131. :JDate
  132. SETLOCAL
  133. :: Convert date to Julian
  134. :: Arguments : YYYY MM DD
  135. :: Returns   : Julian date
  136. ::
  137. :: Algorithm based on Fliegel-Van Flandern
  138. :: algorithm from the Astronomical Almanac,
  139. :: provided by Doctor Fenton on the Math Forum
  140. :: (http://mathforum.org/library/drmath/view/51907.html),
  141. :: and converted to batch code by Ron Bakowski.
  142. ::
  143. SET Month0=%2
  144. SET Day0=%3
  145. :: Strip leading zeroes from month and day
  146. IF 1%Month0% GTR 100 SET /A Month0 = 1%Month0% - 100
  147. IF 1%Day0%   GTR 100 SET /A Day0   = 1%Day0%   - 100
  148. SET /A Month1 = ( %Month0% - 14 ) / 12
  149. SET /A Year1  = %1 + 4800
  150. SET /A JDate  = 1461 * ( %Year1% + %Month1% ) / 4 + 367 * ( %Month0% - 2 -12 * %Month1% ) / 12 - ( 3 * ( ( %Year1% + %Month1% + 100 ) / 100 ) ) / 4 + %3 - 32075
  151. ENDLOCAL & SET JDate=%JDate%
  152. GOTO:EOF
  153.  
  154.  
  155. :ThisYear
  156. :: Read iDate and sDate from the registry; more info on iDate and sDate:
  157. :: https://www.itprotoday.com/windows-78/jsi-tip-0311-regional-settings-registry
  158. FOR /F "tokens=3" %%A IN ('REG.EXE Query "HKEY_CURRENT_USER\Control Panel\International" /v iDate') DO SET iDate=%%A
  159. FOR /F "tokens=3" %%A IN ('REG.EXE Query "HKEY_CURRENT_USER\Control Panel\International" /v sDate') DO SET sDate=%%A
  160. :: Detemine current year depending on registry settings
  161. FOR %%A IN (%Date%) DO SET Today=%%A
  162. IF %iDate%==2 (SET Token=1) ELSE (SET Token=3)
  163. FOR /F "tokens=%Token% delims=%sDate%" %%A IN ("%Today%") DO SET ThisYear=%%A
  164. GOTO:EOF
  165.  
  166.  
  167. :Syntax
  168. ECHO Easter.bat,  Version 3.01 for Windows XP and later
  169. ECHO Calculate Easter day, Ascension day and Pentecost dates for the specified year.
  170. ECHO.
  171. ECHO Usage:  EASTER  [ year ]
  172. ECHO.
  173. ECHO Where:  year should be within the range of 1752..3000 (default: current year)
  174. ECHO.
  175. ECHO Note:   Easter day calculation based on Simon Kershaw's "KEEPING THE FEAST"
  176. ECHO         (http://www.oremus.org/liturgy/etc/ktf/app/easter.html).
  177. ECHO         Julian date math algorithms based on Fliegel-Van Flandern algorithm
  178. ECHO         from the Astronomical Almanac, provided by Doctor Fenton on the Math
  179. ECHO         Forum (http://mathforum.org/library/drmath/view/51907.html), and
  180. ECHO         converted to batch code by Ron Bakowski.
  181. ECHO.
  182. ECHO Written by Rob van der Woude
  183. ECHO http://www.robvanderwoude.com
  184.  
  185. :End
  186. IF "%OS%"=="Windows_NT" ENDLOCAL
  187.  

page last modified: 2024-04-16; loaded in 0.0248 seconds