Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for groundhog.bat

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

  1. :: GROUNDHOG.BAT
  2. ::   Groundhog	
  3. :: 
  4. ::      By Wronski
  5. ::        (with some recycling from stuff in
  6. ::             www.chebucto.ns.ca/~ak621/dos/bat.adv.htm 
  7. ::         and Yesterday.bat  by Rob van der Woude
  8. ::             http://www.robvanderwoude.com)
  9. ::
  10. :: USAGE: groundhog [file] [date]  will run [file] set at date [date]
  11. :: Default values will be used if no [file] or [date] given
  12.  
  13. @echo off
  14. SETLOCAL
  15.  
  16. ::dafault file
  17. set file=C:\wherever\whatever.exe   
  18. ::default date
  19. set Fakedate=09/07/2003
  20.  
  21. if %1a==a goto default
  22. set file=%1
  23. if %2a==a goto default
  24. set Fakedate=%2     
  25.  
  26. :default
  27.  
  28. SET today=%date:~4,10%
  29. date=%Fakedate%
  30.  
  31. CALL %file%
  32.  
  33. :daycount
  34. If NOT "%date:~4,10%"=="%Fakedate%" (
  35. SET vardate = %Fakedate%
  36. CALL :addday
  37. SET Fakedate=%NextDate%
  38. SET vardate = %today%
  39. CALL :addday
  40. SET today=%NextDate%
  41. goto daycount
  42. )
  43.  
  44. date=%today% 	 ::restore previous date
  45. ENDLOCAL
  46. GOTO:EOF
  47.  
  48. :: * * * * * * * *  Subroutines  * * * * * * * *
  49.  
  50. :addday
  51.  
  52. :: Parse the day
  53.  
  54. SET Day=%date:~7,2%
  55. SET Month=%date:~4,2%
  56. SET Year=%date:~10,4%
  57.  
  58. SET NexTD=
  59. SET NextM=
  60. SET NextY=
  61.  
  62. :: Strip leading zeros
  63. SET DayS=%Day%
  64. IF %Day:~0,1%==0 SET DayS=%Day:~1%
  65. SET MonthS=%Month%
  66. IF %Month:~0,1%==0 SET MonthS=%Month:~1%
  67.  
  68. :: Calculate next day's date
  69.  
  70. SET /A NextD=%DayS% + 1
  71. SET NextM=%MonthS%
  72. SET NextY=%Year%
  73.  
  74. IF %DayS% EQU 31 (
  75. 	SET NextD=1
  76. 	Call :ChangeYear
  77. )
  78.  
  79. IF %DayS% EQU 30 (
  80. 	SET NextY=%Year%
  81. 	CALL :ChangeMonth
  82. ) 
  83.  
  84. IF "%MonthS%/%DayS%"=="2/28" CALL :LeapYear
  85.  
  86. :: Add leading zeros to NextD and NextM if necessary
  87. IF %NextD% LSS 10 SET NextD=0%NextD%
  88. IF %NextM% LSS 10 SET NextM=0%NextM%
  89.  
  90. :: Nextday's date in MM/DD/YYYY format
  91. SET NextDate=%NextM%/%NextD%/%NextY%
  92.  
  93. GOTO:EOF
  94.  
  95. :ChangeYear
  96.  
  97. IF %MonthS% EQU 12 (
  98. 	SET NextM=1
  99. 	SET /A NextY=%Year% + 1
  100. ) 
  101. ELSE (SET /A NextM=%MonthS%+1)      
  102. )
  103. GOTO:EOF
  104.  
  105. :ChangeMonth
  106.  
  107. IF %MonthS%==1 (
  108. 	SET NextD=31
  109. 	SET NextM=1
  110. 	SET /A NextY = %Year%
  111. )
  112.  
  113. IF %MonthS%==3 (
  114. 	SET NextD=31
  115. 	SET NextM=03
  116. 	CALL :LeapYear
  117. )
  118. IF %MonthS%==4 (
  119. 	SET NextD=1
  120. 	SET NextM=05
  121. )
  122. IF %MonthS%==5 (
  123. 	SET NextD=31
  124. 	SET NextM=05
  125. )
  126. IF %MonthS%==6 (
  127. 	SET NextD=1
  128. 	SET NextM=07
  129. )
  130. IF %MonthS%==7 (
  131. 	SET NextD=31
  132. 	SET NextM=07
  133. )
  134. IF %MonthS%==8 (
  135. 	SET NextD=31
  136. 	SET NextM=08
  137. )
  138. IF %MonthS%==9 (
  139. 	SET NextD=1
  140. 	SET NextM=10
  141. )
  142. IF %Month%==10 (
  143. 	SET NextD=31
  144. 	SET NextM=10
  145. )
  146. IF %Month%==11 (
  147. 	SET NextD=1
  148. 	SET NextM=12
  149. )
  150. IF %Month%==12 (
  151. 	SET NextD=31
  152. 	SET NextM=12
  153. )
  154. GOTO:EOF
  155.  
  156. :LeapYear
  157.  
  158. echo leap
  159. :: If the year divisable by 4 then it is a leap year . . .
  160. SET /A LeapYear = %Year% / 4
  161. SET /A LeapYear = %LeapYear% * 4
  162. IF NOT %LeapYear% EQU %Year% (
  163. 	SET NextD=1
  164. 	SET NextM=3
  165. )
  166. :: . . . unless it is also divisible by 100 . . .
  167. SET /A LeapYear = %Year% / 100
  168. SET /A LeapYear = %LeapYear% * 100
  169. IF %LeapYear% EQU %Year% (
  170. 	SET NextD=1
  171. 	SET NextM=3
  172. )
  173. :: . . . but when it is divisible by 400 it is a leap year again 
  174. SET /A LeapYear = %Year% / 400
  175. SET /A LeapYear = %LeapYear% * 400
  176. IF %LeapYear% EQU %Year% (
  177. 	SET NextD=29
  178. 	SET NextM=2
  179. )
  180. GOTO:EOF
  181.  

page last modified: 2024-02-26; loaded in 0.0184 seconds