Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for leapyear.bat

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

  1. @ECHO OFF
  2.  
  3. REM Check command line parameter
  4. IF NOT [%2]==[]   GOTO Syntax
  5. IF     [%1]==[?]  GOTO Syntax
  6. IF     [%1]==[/?] GOTO Syntax
  7. IF     [%1]==[-?] GOTO Syntax
  8. IF NOT [%1]==[]   GOTO Year
  9.  
  10. REM Check if BATCHMAN.COM is available
  11. BATCHMAN MONTH
  12. IF NOT ERRORLEVEL 1 GOTO Syntax
  13.  
  14. REM If no year specified: get current year as errorlevel offset with -1980
  15. BATCHMAN YEAR
  16.  
  17. REM "Convert" errorlevel to year
  18. SET Year=1980
  19. IF ERRORLEVEL   1 SET Year=1981
  20. IF ERRORLEVEL   2 SET Year=1982
  21. IF ERRORLEVEL   3 SET Year=1983
  22. IF ERRORLEVEL   4 SET Year=1984
  23. IF ERRORLEVEL   5 SET Year=1985
  24. IF ERRORLEVEL   6 SET Year=1986
  25. IF ERRORLEVEL   7 SET Year=1987
  26. IF ERRORLEVEL   8 SET Year=1988
  27. IF ERRORLEVEL   9 SET Year=1989
  28. IF ERRORLEVEL  10 SET Year=1990
  29. IF ERRORLEVEL  11 SET Year=1991
  30. IF ERRORLEVEL  12 SET Year=1992
  31. IF ERRORLEVEL  13 SET Year=1993
  32. IF ERRORLEVEL  14 SET Year=1994
  33. IF ERRORLEVEL  15 SET Year=1995
  34. IF ERRORLEVEL  16 SET Year=1996
  35. IF ERRORLEVEL  17 SET Year=1997
  36. IF ERRORLEVEL  18 SET Year=1998
  37. IF ERRORLEVEL  19 SET Year=1999
  38. IF ERRORLEVEL  20 SET Year=2000
  39. IF ERRORLEVEL  21 SET Year=2001
  40. IF ERRORLEVEL  22 SET Year=2002
  41. IF ERRORLEVEL  23 SET Year=2003
  42. IF ERRORLEVEL  24 SET Year=2004
  43. IF ERRORLEVEL  25 SET Year=2005
  44. IF ERRORLEVEL  26 SET Year=2006
  45. IF ERRORLEVEL  27 SET Year=2007
  46. IF ERRORLEVEL  28 SET Year=2008
  47. IF ERRORLEVEL  29 SET Year=2009
  48. IF ERRORLEVEL  30 SET Year=2010
  49. IF ERRORLEVEL  31 SET Year=2011
  50. IF ERRORLEVEL  32 SET Year=2012
  51. IF ERRORLEVEL  33 SET Year=2013
  52. IF ERRORLEVEL  34 SET Year=2014
  53. IF ERRORLEVEL  35 SET Year=2015
  54. IF ERRORLEVEL  36 SET Year=2016
  55. IF ERRORLEVEL  37 SET Year=2017
  56. IF ERRORLEVEL  38 SET Year=2018
  57. IF ERRORLEVEL  39 SET Year=2019
  58. IF ERRORLEVEL  40 SET Year=2020
  59. IF ERRORLEVEL  41 SET Year=2021
  60. IF ERRORLEVEL  42 SET Year=2022
  61. IF ERRORLEVEL  43 SET Year=2023
  62. IF ERRORLEVEL  44 SET Year=2024
  63. IF ERRORLEVEL  45 SET Year=2025
  64. IF ERRORLEVEL  46 SET Year=2026
  65. IF ERRORLEVEL  47 SET Year=2027
  66. IF ERRORLEVEL  48 SET Year=2028
  67. IF ERRORLEVEL  49 SET Year=2029
  68. IF ERRORLEVEL  50 SET Year=2030
  69. IF ERRORLEVEL  51 SET Year=2031
  70. IF ERRORLEVEL  52 SET Year=2032
  71. IF ERRORLEVEL  53 SET Year=2033
  72. IF ERRORLEVEL  54 SET Year=2034
  73. IF ERRORLEVEL  55 SET Year=2035
  74. IF ERRORLEVEL  56 SET Year=2036
  75. IF ERRORLEVEL  57 SET Year=2037
  76. IF ERRORLEVEL  58 SET Year=2038
  77. IF ERRORLEVEL  59 SET Year=2039
  78. IF ERRORLEVEL  60 SET Year=2040
  79. IF ERRORLEVEL  61 SET Year=2041
  80. IF ERRORLEVEL  62 SET Year=2042
  81. IF ERRORLEVEL  63 SET Year=2043
  82. IF ERRORLEVEL  64 SET Year=2044
  83. IF ERRORLEVEL  65 SET Year=2045
  84. IF ERRORLEVEL  66 SET Year=2046
  85. IF ERRORLEVEL  67 SET Year=2047
  86. IF ERRORLEVEL  68 SET Year=2048
  87. IF ERRORLEVEL  69 SET Year=2049
  88. IF ERRORLEVEL  70 SET Year=2050
  89. IF ERRORLEVEL  71 SET Year=2051
  90. IF ERRORLEVEL  72 SET Year=2052
  91. IF ERRORLEVEL  73 SET Year=2053
  92. IF ERRORLEVEL  74 SET Year=2054
  93. IF ERRORLEVEL  75 SET Year=2055
  94. IF ERRORLEVEL  76 SET Year=2056
  95. IF ERRORLEVEL  77 SET Year=2057
  96. IF ERRORLEVEL  78 SET Year=2058
  97. IF ERRORLEVEL  79 SET Year=2059
  98. IF ERRORLEVEL  80 SET Year=2060
  99. IF ERRORLEVEL  81 SET Year=2061
  100. IF ERRORLEVEL  82 SET Year=2062
  101. IF ERRORLEVEL  83 SET Year=2063
  102. IF ERRORLEVEL  84 SET Year=2064
  103. IF ERRORLEVEL  85 SET Year=2065
  104. IF ERRORLEVEL  86 SET Year=2066
  105. IF ERRORLEVEL  87 SET Year=2067
  106. IF ERRORLEVEL  88 SET Year=2068
  107. IF ERRORLEVEL  89 SET Year=2069
  108. IF ERRORLEVEL  90 SET Year=2070
  109. IF ERRORLEVEL  91 SET Year=2071
  110. IF ERRORLEVEL  92 SET Year=2072
  111. IF ERRORLEVEL  93 SET Year=2073
  112. IF ERRORLEVEL  94 SET Year=2074
  113. IF ERRORLEVEL  95 SET Year=2075
  114. IF ERRORLEVEL  96 SET Year=2076
  115. IF ERRORLEVEL  97 SET Year=2077
  116. IF ERRORLEVEL  98 SET Year=2078
  117. IF ERRORLEVEL  99 SET Year=2079
  118. IF ERRORLEVEL 100 SET Year=2080
  119. IF ERRORLEVEL 101 SET Year=2081
  120. IF ERRORLEVEL 102 SET Year=2082
  121. IF ERRORLEVEL 103 SET Year=2083
  122. IF ERRORLEVEL 104 SET Year=2084
  123. IF ERRORLEVEL 105 SET Year=2085
  124. IF ERRORLEVEL 106 SET Year=2086
  125. IF ERRORLEVEL 107 SET Year=2087
  126. IF ERRORLEVEL 108 SET Year=2088
  127. IF ERRORLEVEL 109 SET Year=2089
  128. IF ERRORLEVEL 110 SET Year=2090
  129. IF ERRORLEVEL 111 SET Year=2091
  130. IF ERRORLEVEL 112 SET Year=2092
  131. IF ERRORLEVEL 113 SET Year=2093
  132. IF ERRORLEVEL 114 SET Year=2094
  133. IF ERRORLEVEL 115 SET Year=2095
  134. IF ERRORLEVEL 116 SET Year=2096
  135. IF ERRORLEVEL 117 SET Year=2097
  136. IF ERRORLEVEL 118 SET Year=2098
  137. IF ERRORLEVEL 119 SET Year=2099
  138. IF ERRORLEVEL 120 SET Year=2100
  139. IF ERRORLEVEL 121 SET Year=2101
  140. IF ERRORLEVEL 122 SET Year=2102
  141. IF ERRORLEVEL 123 SET Year=2103
  142. IF ERRORLEVEL 124 SET Year=2104
  143. IF ERRORLEVEL 125 SET Year=2105
  144. IF ERRORLEVEL 126 SET Year=2106
  145. IF ERRORLEVEL 127 SET Year=2107
  146. IF ERRORLEVEL 128 SET Year=2108
  147. IF ERRORLEVEL 129 SET Year=2109
  148. IF ERRORLEVEL 130 SET Year=2110
  149. IF ERRORLEVEL 131 SET Year=2111
  150. IF ERRORLEVEL 132 SET Year=2112
  151. IF ERRORLEVEL 133 SET Year=2113
  152. IF ERRORLEVEL 134 SET Year=2114
  153. IF ERRORLEVEL 135 SET Year=2115
  154. IF ERRORLEVEL 136 SET Year=2116
  155. IF ERRORLEVEL 137 SET Year=2117
  156. IF ERRORLEVEL 138 SET Year=2118
  157. IF ERRORLEVEL 139 SET Year=2119
  158. IF ERRORLEVEL 140 SET Year=2120
  159. IF ERRORLEVEL 141 SET Year=2121
  160. IF ERRORLEVEL 142 SET Year=2122
  161. IF ERRORLEVEL 143 SET Year=2123
  162. IF ERRORLEVEL 144 SET Year=2124
  163. IF ERRORLEVEL 145 SET Year=2125
  164. IF ERRORLEVEL 146 SET Year=2126
  165. IF ERRORLEVEL 147 SET Year=2127
  166. IF ERRORLEVEL 148 SET Year=2128
  167. IF ERRORLEVEL 149 SET Year=2129
  168. IF ERRORLEVEL 150 SET Year=2130
  169. IF ERRORLEVEL 151 SET Year=2131
  170. IF ERRORLEVEL 152 SET Year=2132
  171. IF ERRORLEVEL 153 SET Year=2133
  172. IF ERRORLEVEL 154 SET Year=2134
  173. IF ERRORLEVEL 155 SET Year=2135
  174. IF ERRORLEVEL 156 SET Year=2136
  175. IF ERRORLEVEL 157 SET Year=2137
  176. IF ERRORLEVEL 158 SET Year=2138
  177. IF ERRORLEVEL 159 SET Year=2139
  178. IF ERRORLEVEL 160 SET Year=2140
  179. IF ERRORLEVEL 161 SET Year=2141
  180. IF ERRORLEVEL 162 SET Year=2142
  181. IF ERRORLEVEL 163 SET Year=2143
  182. IF ERRORLEVEL 164 SET Year=2144
  183. IF ERRORLEVEL 165 SET Year=2145
  184. IF ERRORLEVEL 166 SET Year=2146
  185. IF ERRORLEVEL 167 SET Year=2147
  186. IF ERRORLEVEL 168 SET Year=2148
  187. IF ERRORLEVEL 169 SET Year=2149
  188. IF ERRORLEVEL 170 SET Year=2150
  189. IF ERRORLEVEL 171 SET Year=2151
  190. IF ERRORLEVEL 172 SET Year=2152
  191. IF ERRORLEVEL 173 SET Year=2153
  192. IF ERRORLEVEL 174 SET Year=2154
  193. IF ERRORLEVEL 175 SET Year=2155
  194. IF ERRORLEVEL 176 SET Year=2156
  195. IF ERRORLEVEL 177 SET Year=2157
  196. IF ERRORLEVEL 178 SET Year=2158
  197. IF ERRORLEVEL 179 SET Year=2159
  198. IF ERRORLEVEL 180 SET Year=2160
  199. IF ERRORLEVEL 181 SET Year=2161
  200. IF ERRORLEVEL 182 SET Year=2162
  201. IF ERRORLEVEL 183 SET Year=2163
  202. IF ERRORLEVEL 184 SET Year=2164
  203. IF ERRORLEVEL 185 SET Year=2165
  204. IF ERRORLEVEL 186 SET Year=2166
  205. IF ERRORLEVEL 187 SET Year=2167
  206. IF ERRORLEVEL 188 SET Year=2168
  207. IF ERRORLEVEL 189 SET Year=2169
  208. IF ERRORLEVEL 190 SET Year=2170
  209. IF ERRORLEVEL 191 SET Year=2171
  210. IF ERRORLEVEL 192 SET Year=2172
  211. IF ERRORLEVEL 193 SET Year=2173
  212. IF ERRORLEVEL 194 SET Year=2174
  213. IF ERRORLEVEL 195 SET Year=2175
  214. IF ERRORLEVEL 196 SET Year=2176
  215. IF ERRORLEVEL 197 SET Year=2177
  216. IF ERRORLEVEL 198 SET Year=2178
  217. IF ERRORLEVEL 199 SET Year=2179
  218. GOTO LeapYear
  219.  
  220. :Year
  221. REM Reset LY for leap years
  222. FOR %%A IN (%1) DO SET Year=%%A
  223.  
  224. :LeapYear
  225. SET LY=is NOT
  226. FOR %%A IN (1980 1984 1988 1992 1996 2000 2004 2008 2012 2016) DO IF %Year%==%%A SET LY=IS
  227. FOR %%A IN (2020 2024 2028 2032 2036 2040 2044 2048 2052 2056) DO IF %Year%==%%A SET LY=IS
  228. FOR %%A IN (2060 2064 2068 2072 2076 2080 2084 2088 2092 2096) DO IF %Year%==%%A SET LY=IS
  229. REM 2100 is NOT a leap year
  230. FOR %%A IN (2104 2108 2112 2116 2120 2124 2128 2132 2136 2140) DO IF %Year%==%%A SET LY=IS
  231. FOR %%A IN (2144 2148 2152 2156 2160 2164 2168 2172 2176) DO IF %Year%==%%A SET LY=IS
  232.  
  233. REM Set variable LeapYear true or false
  234. SET LeapYear=0
  235. IF "%LY%"=="IS" SET LeapYear=1
  236.  
  237. REM Display the result
  238. ECHO %Year% %LY% a leap year
  239.  
  240. REM Done
  241. GOTO End
  242.  
  243. :Syntax
  244. ECHO.
  245. ECHO LeapYear.bat,  Version 2.00 for DOS
  246. ECHO Check if the specified or current year is a leap year
  247. ECHO.
  248. ECHO Usage:    LEAPYEAR  [ year ]
  249. ECHO.
  250. ECHO Where:    "year" is a number from 1980 .. 2179
  251. ECHO           Default is the current year
  252. ECHO.
  253. ECHO Returns:  Screen output plus environment variable %%LeapYear%%
  254. ECHO.
  255. ECHO This batch file uses BATCHMAN by Michael Mefford to retrieve the current year
  256. ECHO.
  257. ECHO Written by Rob van der Woude
  258. ECHO http://www.robvanderwoude.com
  259.  
  260. :End
  261. REM Clean up temporary variables
  262. SET Year=
  263. SET LY=
  264.  

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