detective1711

Calendar

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