Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for calendar.bat

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

  1. @ECHO OFF
  2.  
  3. :: Xp batch for generating calendars
  4. :: Chances look good for win 2000 and above(untested)
  5. :: By Judago, August 2009
  6.  
  7. IF "%~1"=="/?" (
  8.     ECHO START "%~NX0" WITHOUT ARGUMENTS AND THEN ENTER THE YEAR.
  9.     ECHO "%~NX0" WILL OPEN IN IT'S OWN WINDOW TO AVOID RESIZING
  10.     ECHO AN EXISTING WINDOW.
  11.     ECHO.
  12.     ECHO A SCREEN RESOLUTION AND/OR FONT SIZE THAT CAN DISPLAY
  13.     ECHO CMD WINDOWS OF 96 COLUMNS AND 39 LINES IS REQUIRED.
  14.     ECHO SOME CONFIGURATIONS MAY USE SCROLL BARS TO ACHIEVE
  15.     ECHO THIS.
  16.     EXIT /B
  17. )
  18.  
  19. :: The current codepage is stored in variable %CodePage%,
  20. :: then changed to 850 to facilitate box drawing characters.....
  21.  
  22. FOR /F "tokens=*" %%A IN ('CHCP') DO FOR %%B IN (%%~A) DO SET CodePage=%%B
  23. CHCP 850 >NUL 2>&1
  24.  
  25. :: The title can be used to falicitate custom window
  26. :: positioning via the properties menu of "calendars..."
  27. :: /max is used so as much content as possible is visable
  28. :: without moving the window. /max must be removed for
  29. :: custom window positing.....
  30.  
  31. IF NOT "%~1 %~2"=="WINDOW SIZE" (
  32. 	START "CALENDARS..." /MAX CMD /C "%~F0" WINDOW SIZE
  33.  
  34. 	REM Restore the original codepage before exiting.....
  35.  
  36. 	CHCP %CodePage% >NUL 2>&1
  37. 	EXIT /B
  38. )
  39. MODE CON:COLS=96 LINES=39
  40. SETLOCAL ENABLEDELAYEDEXPANSION
  41.  
  42. :loop
  43. FOR %%Z IN (jan feb mar apr may jun jul aug sep oct nov dec year day leap noleap length test) DO SET %%Z=
  44. SET /P year=Enter a year to see it's calendar, or nothing to exit, then press enter: 
  45. IF NOT DEFINED year (
  46.  
  47. 	REM Restore the original codepage before exiting.....
  48.  
  49. 	CHCP %CodePage% >NUL 2>&1
  50. 	EXIT /B
  51. )
  52.  
  53. ::Test that the input is only numbers...
  54.  
  55. SET test=!year!
  56. FOR /l %%Z IN (0 1 9) DO IF DEFINED test SET "test=!test:%%Z=!"
  57. IF DEFINED test CLS&GOTO loop
  58. :zero
  59. IF NOT DEFINED year (
  60. 	:error
  61. 	cls
  62. 	echo The year entered can not be accepted.
  63. 	echo.
  64. 	pause
  65. 	CLS
  66. 	GOTO loop
  67. )
  68.  
  69. :: remove leading zeros, if any...
  70.  
  71. IF "%year:~0,1%"=="0" SET year=%year:~1%&&GOTO zero
  72.  
  73. :: The %processor_architecture% test is used to test
  74. :: limits of caculations, if the variable is undefined
  75. :: or unrecognised the test will fall through and complete
  76. :: anyway, if the limit is surpassed this way the results may
  77. :: not be valid. The tested number is ~80% of the limit of the
  78. :: os so that year + year / 4 yields a valid result.
  79.  
  80. IF /I "!processor_architecture!"=="x86" (
  81. 	IF !year! gtr 1717986917 GOTO :error
  82. ) else (
  83. 	IF NOT "!processor_architecture:64=!"=="!processor_architecture!" (
  84. 		IF !year! gtr 7378697629483820645 GOTO :error
  85. 	)
  86. )
  87.  
  88. :: Generate the first day of the year, 0=sun, 1=mon,...,6=sat
  89. :: A 365 day year ofsets by one day, so the next year will start
  90. :: the next day (i.e. 2009 starts on thr and 2010 starts on fri)
  91. :: an extra day must be added for every leapyear. Using modulo
  92. :: 7 on the total of offset days reviels the starting day of the
  93. :: year. one day must also be removed if the year is a leap year
  94. :: because the below will add one for it, the remainder for non
  95. :: leap years is not an issue because set /a only returns whole
  96. :: numbers.
  97.  
  98. SET /A day=(year + year / 4) - (year / 100 - year / 400)
  99. SET /A leap=year %% 400
  100. SET /A noleap=year %% 100
  101. IF !leap! GTR 0 (
  102. 	IF !noleap! NEQ 0 SET /A leap=year %% 4
  103. )
  104. IF %leap%==0 SET /A day-=1
  105. SET /A day%%=7
  106.  
  107. :: For each year every month is padded to is starting offset
  108. :: with spaces, january has the original offset generated above.
  109. :: each additional offset is generated by adding the total days of
  110. :: the previous month then processing it by modulo 7.
  111. :: The days are stored in a varianle to display later, these variables
  112. :: are padded to 111 characters using spaces for display purposes.
  113.  
  114. FOR %%U IN (jan feb mar apr may jun jul aug sep oct nov dec) DO (
  115. 	FOR %%V IN (jan mar may jul aug oct dec) DO IF /I %%U==%%V SET length=31
  116. 	FOR %%W IN (apr jun sep nov) DO IF /I %%U==%%W SET length=30
  117. 	IF /I %%U==feb (
  118. 		IF !leap!==0 (
  119. 			SET length=29
  120. 		) else (
  121. 			SET length=28
  122. 		)
  123. 	)
  124. 	FOR /l %%X IN (1 1 !day!) DO SET "%%U=!%%U!   "
  125. 	FOR /l %%Y IN (1 1 !length!) DO (
  126. 		IF %%Y lss 10 (
  127. 			SET "%%U=!%%U!%%Y  "
  128. 		) else (
  129. 			SET "%%U=!%%U!%%Y "
  130. 		)
  131. 	)
  132. 	FOR /l %%Z IN (!length! 1 54) DO IF "!%%U:~110!"=="" SET "%%U=!%%U! "
  133. 	SET /A day=^(day + length^) %% 7
  134. )
  135. :test
  136.  
  137. :: The results are displayed below using substrings of each month's 
  138. variable.
  139.  
  140. cls
  141. TITLE THE CALENDAR FOR THE YEAR OF %YEAR%
  142. echo. ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»  ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»  ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»  ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»
  143. echo. º      JANUARY       º  º      FEBUARY       º  º       MARCH        º  º       APRIL        º
  144. echo. ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹  ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹  ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹  ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹
  145. echo. ºS  M  T  W  T  F  S º  ºS  M  T  W  T  F  S º  ºS  M  T  W  T  F  S º  ºS  M  T  W  T  F  S º
  146. echo. ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹  ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹  ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹  ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹
  147. echo. º%JAN:~0,20%º  º%FEB:~0,20%º  º%MAR:~0,20%º  º%APR:~0,20%º
  148. echo. º%JAN:~21,20%º  º%FEB:~21,20%º  º%MAR:~21,20%º  º%APR:~21,20%º
  149. echo. º%JAN:~42,20%º  º%FEB:~42,20%º  º%MAR:~42,20%º  º%APR:~42,20%º
  150. echo. º%JAN:~63,20%º  º%FEB:~63,20%º  º%MAR:~63,20%º  º%APR:~63,20%º
  151. echo. º%JAN:~84,20%º  º%FEB:~84,20%º  º%MAR:~84,20%º  º%APR:~84,20%º
  152. echo. º%JAN:~105%              º  º%FEB:~105%              º  º%MAR:~105%              º  º%APR:~105%              º
  153. echo. ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ  ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ  ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ  ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ
  154. echo.
  155. echo. ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»  ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»  ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»  ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»
  156. echo. º        MAY         º  º        JUNE        º  º        JULY        º  º       AUGUST       º
  157. echo. ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹  ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹  ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹  ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹
  158. echo. ºS  M  T  W  T  F  S º  ºS  M  T  W  T  F  S º  ºS  M  T  W  T  F  S º  ºS  M  T  W  T  F  S º
  159. echo. ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹  ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹  ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹  ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹
  160. echo. º%MAY:~0,20%º  º%JUN:~0,20%º  º%JUL:~0,20%º  º%AUG:~0,20%º
  161. echo. º%MAY:~21,20%º  º%JUN:~21,20%º  º%JUL:~21,20%º  º%AUG:~21,20%º
  162. echo. º%MAY:~42,20%º  º%JUN:~42,20%º  º%JUL:~42,20%º  º%AUG:~42,20%º
  163. echo. º%MAY:~63,20%º  º%JUN:~63,20%º  º%JUL:~63,20%º  º%AUG:~63,20%º
  164. echo. º%MAY:~84,20%º  º%JUN:~84,20%º  º%JUL:~84,20%º  º%AUG:~84,20%º
  165. echo. º%MAY:~105%              º  º%JUN:~105%              º  º%JUL:~105%              º  º%AUG:~105%              º
  166. echo. ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ  ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ  ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ  ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ
  167. echo.
  168. echo. ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»  ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»  ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»  ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»
  169. echo. º     SEPTEMBER      º  º      OCTOBER       º  º      NOVEMBER      º  º      DECEMBER      º
  170. echo. ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹  ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹  ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹  ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹
  171. echo. ºS  M  T  W  T  F  S º  ºS  M  T  W  T  F  S º  ºS  M  T  W  T  F  S º  ºS  M  T  W  T  F  S º
  172. echo. ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹  ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹  ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹  ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹
  173. echo. º%SEP:~0,20%º  º%OCT:~0,20%º  º%NOV:~0,20%º  º%DEC:~0,20%º
  174. echo. º%SEP:~21,20%º  º%OCT:~21,20%º  º%NOV:~21,20%º  º%DEC:~21,20%º
  175. echo. º%SEP:~42,20%º  º%OCT:~42,20%º  º%NOV:~42,20%º  º%DEC:~42,20%º
  176. echo. º%SEP:~63,20%º  º%OCT:~63,20%º  º%NOV:~63,20%º  º%DEC:~63,20%º
  177. echo. º%SEP:~84,20%º  º%OCT:~84,20%º  º%NOV:~84,20%º  º%DEC:~84,20%º
  178. echo. º%SEP:~105%              º  º%OCT:~105%              º  º%NOV:~105%              º  º%DEC:~105%              º
  179. echo. ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ  ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ  ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ  ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ
  180. GOTO loop
  181.  

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