Batch-Generated Calendar


By: nbrane
February 14, 2013

@echo off & setlocal enabledelayedexpansion
::debug/display settings
::=================== LATEST VERSION 2/13/13 - debugging eqpt removed
set z=%1
set thisbat=%~n0.bat
if "%z%" equ "/?" set z=?
if "%z%" equ "-?" set z=?
if "%z%" equ "?" (
call :findline "--- END batch"
more +!n! %thisbat% |findstr /e /c:" "
goto :eof
)
if /I "%z%" equ "dofw" (
call :findline "--- END helpfile"
echo building dofw.vbs from %thisbat% line !n!:
pause
more +!n! %thisbat%> dofw.vbs
echo done.
goto :eof
)
set L1=ÚÄÄÄÄÄÄÂÄÄÄÄÄÄÂÄÄÄÄÄÄÂÄÄÄÄÄÄÂÄÄÄÄÄÄÂÄÄÄÄÄÄÂÄÄÄÄÄÄ¿
set L2=ÃÄÄÄÄÄÄÅÄÄÄÄÄÄÅÄÄÄÄÄÄÅÄÄÄÄÄÄÅÄÄÄÄÄÄÅÄÄÄÄÄÄÅÄÄÄÄÄÄ´
set L3=ÀÄÄÄÄÄÄÁÄÄÄÄÄÄÁÄÄÄÄÄÄÁÄÄÄÄÄÄÁÄÄÄÄÄÄÁÄÄÄÄÄÄÁÄÄÄÄÄÄÙ
set blank=³      ³      ³      ³      ³      ³      ³      ³
set bar=³
(set aster= )
:heighth of each cell
set height=2
set days=   Sun    Mon    Tue    Wed    Thu    Fri    Sat
set months=January  February March    April    May      June     July     August   SeptemberOctober  November December
set thirty=" 4 6 9 11"
:--- date
:--- attempt to allow override of current-date-default via vbscript
set z=%1
:startnext
if "%z%" neq "" (
for /f "tokens=1-3 delims=/-." %%a in ("%z%") do if "%%c" equ "" set z=%%a/1/%%b
for /f "tokens=*" %%a in ('cscript /Nologo dofw.vbs !z!') do set dd=%%a
) else (
set aster=*
set dd=%date%
:: enable for foll. manual override/testing
rem set /p dd=date:
)
for /f "tokens=1-4 delims=-/ " %%a in ("%dd%") do (
set day=%%c
set mo=%%b
set yr=%%d
set dofw=%%a
)
if "%yr:~2%" equ "" set yr=20%yr%
:--- establish length of month
set eom=31
set test=!thirty: %mo%=**!
if %test% neq %thirty% set eom=30
if %mo% equ 2 (
set /a test="yr%%4"
if !test! equ 0 (set eom=29) else (set eom=28)
)
:--- setup formal (display) month
set /a test=(mo-1)*9
set month=!months:~%test%,9!
:--- establish day-of-week
set c=0
for %%i in (%days%) do (if /i %dofw% equ %%i (goto :gout) else (set /a c+=1))
echo ???????? problem here!!
goto :eof
:gout
:--- establish dofw of the first of the month
set /a offs=c-"(day-1)%%7"
set /a first="(7-((day-1)%%7)+c)%%7-1"
(set e=      )
set ee=%bar%
for /L %%i in (0,1,%first%) do set ee=!ee!%e%%bar%
echo.
(set sp= )
set sep=%L2%
:*********** D I S P L A Y   S T A R T
echo                   %month% %yr%
echo.
echo %days%
echo %L1%
:*********** M A I N   L O O P
for /L %%i in (1,1,%eom%) do (
if %%i gtr 9 set sp=
(set tag= )
if %%i equ %day% set tag=%aster%
set ee=!ee!!sp!   !tag!%%i%bar%
set /a u="(%%i+offs)%%7"
if !u! equ 0 (
if %%i equ %eom% set sep=%L3%
call :box
set ee=%bar%
)
)
if %sep% equ %L3% goto :getnext
set sep=%L3%
for /L %%i in (%u%,1,6) do set ee=!ee!%e%%bar%
call :box
 
:getnext
set z=
set /p z=next date, or [ENTER] to end:
if not defined z goto :eof
goto :startnext
 
:box
echo !ee!
for /L %%g in (1,1,%height%) do (
echo %blank%
)
echo %sep%
goto :eof
 
:findline
for /f "tokens=1-2 delims=[]" %%a in ('find /i /n %1 ^<%thisbat%') do set n=%%a
goto :eof
 
:be sure to leave at least one space at end of each of the "help" lines,
:since that's how they are extracted by "findstr" for display.
:So, if you add or change a line, always put a trailing space.
:Also, leave the following relatively intact (see ":findline" sub)
:------------------ END BATCH, begin helpfile
  Calendr.bat can generate/display a calendar of the current month unassisted,
but to generate other months, it needs the help of the included file
"dofw.vbs" to do the date-math required to determine the day-of-week
offset of the non-current dates.
To use the non-current-date extension, you can use MORE to create the vbs
file. Just run the following from the command-prompt:
                   MORE +nnn calendr.bat > dofw.vbs
or, preferably (and more reliably), you can do this from the command-prompt:
                   CALENDR DOFW
And the batchfile will create the vbscript, after which Calendr could now
process a command-line date-modifier (mm-yy), like (for Jan 2012):
  CALENDR 1/12  or: CALENDR 1-12   (dashes and slashes are interchangeable. You can include the day, but it's ignored as being irrelevant)
please report any errors/ommissions/bugs/suggestions via pmail to nbrane
 

:------------------ END helpfile, begin vbscript "dofw.vbs"
'obtain day-of-week of given input date, output like: Sun 1/2/2012
set y=wscript.arguments
a=y.count-1
if a < 0 then x=date else x=y(0)
dofw=left(FormatDateTime(x,1),3)
test=FormatDateTime(x,0)
wscript.stdout.write(dofw+" "+test)


Need more help?
Describe your Problem
Example: Hard Drive Not Detected on My PC

Ask Question