Il giorno Thu 21 Jul 2022 07:30:05p, *Harry Potter* ha inviato su
alt.msdos.batch.nt il messaggio news:e20f893d-011a-4341-ae0b-
Post by Harry PotterI have some batch files that may be useful to others.
Me too. I found this some years ago
Note that holidays and birthdays (at the end) are in German language, but
you can translate as well as add new items
@echo off
setlocal
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: usage:
:: calendar.bat show current month
:: calendar.bat 9 show month september of current year
:: calendar.bat 4 2007 show month april of year 2007
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: the format of the %date% variable must be in the following format:
:: set date=28.02.2001
:: if not, change the next three lines
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
set /a y=%date:~6,4%
set /a m=1%date:~3,2%-100
set /a d=1%date:~0,2%-100
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: test for parameter month
if not [%1]==[] set /a m=%1
if %m% lss 1 goto :eof
if %m% gtr 12 goto :eof
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: test for parameter year
if not [%2]==[] set /a y=%2
if %y% lss 1901 goto :eof
if %y% gtr 2099 goto :eof
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: calculate the string for the week numbers
setlocal
(set t= )
for /l %%i in (1,7,29) do (
set d=%%i
call :date2week
call set v= %%v%%
call set v=%%v:~-2%%
call set t=%%t%%%%v%%: )
endlocal & (set t=%t% )
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: calculate the name of the first day of month %m% 0:monday 7:sunday
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
call :date2day
set /a w=(w-d+2)%%7
set m[1]=January & set m[2]=February & set m[3]=March & set m[4]=April
set m[5]=May & set m[6]=June & set m[7]=July & set m[8]=August
set m[9]=September&set m[10]=October&set m[11]=November&set m[12]=December
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: calculate the number of days in the month %m%
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
set /a n=28+(62648012^>^>(2*%m%)^&3)+ (!(%y% %% 4))*(!(%m%-2))
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: calculate the string for the days
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
(set s= )
for /l %%i in (1,1,%w%) do (call set s= %%s%%)
for /l %%i in (1,1,9) do if %%i EQU %d% (
call set s=%%s%%[ %%i]) else (call set s=%%s%% %%i )
for /l %%i in (10,1,%n%) do if %%i EQU %d% (
call set s=%%s%%[%%i]) else (call set s=%%s%% %%i )
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: output the calendar
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
echo.&echo.
call echo %%m[%m%]%% %y%
echo Mo Tu We Th Fr Sa Su
for /l %%i in (1,28,141) do (call echo.%%t:~%%i,4%%%%s:~%%i,28%%)
echo.
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: output public holidays and bithdays
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
set /a month=m
if %m% lss 10 set month=0%m%
set /a m=3
set /a d=1
call :date2day
call :ostern
set /a o=w+o-1
set i=.
for /f "tokens=2,3* delims=. " %%i in ('find "::%i%"^<"%~f0"') do (
set /a d=%%i
set /a m=%%j
set name=%%k
call :sub)
goto :eof
:sub
if not %m%==0 if %d%==0 echo.&goto :eof
if %m% lss 10 set m=0%m%
if %d% lss 10 set d=0%d%
if [%m%]==[%month%] echo %d%.%m%.%y% %name%
if not [%m%]==[00] goto :eof
set /a w=o+%d%
call :day2date
if %m% lss 10 set m=0%m%
if %d% lss 10 set d=0%d%
if [%m%]==[%month%] echo %d%.%m%.%y% %name%
goto :eof
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: calculate the date of eastern in the year %y% ::
:: 1: 1. march 31: 31. march 32: 1. april ... ::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:ostern
set /a i=((y%%19)*19+15+((y/100)*3+3)/4-((y/100)*8+13)/25)%%30
set /a j=21+i-(i/29+(i/28-i/29)*((y%%19)/11))
set /a o=j+7-(j-(7-(y+y/4+2-((y/100)*3+3)/4)%%7))%%7
goto :eof
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: convert the date in %y% %m% %d% to the number of days (%w%) ::
:: since 1901 (day 0 is 1. Jan. 1901) ::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:date2day
set /a w=(y-1901)*365+(y-1901)/4+d-1+(!(y %% 4))*(!((m-3)^&16))
set /a w=w+(m-1)*30+2*(!((m-7)^&16))-1+((65611044^>^>(2*m))^&3)
goto :eof
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: convert the number of days in %w% to the date (%y% %m% %d%) ::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:day2date
set /a x=w/1461
set /a w=w-x*1461
set /a z=w/365-((w/365)^>^>2)
set /a w=w-z*365
set /a y=1901+x*4+z
set /a v=w-!(y%%4)
set /a m=!!(w/31)+!!(v/59)+!!(v/90)+!!(v/120)+!!(v/151)+!!(v/181)
set /a m=m+!!(v/212)+!!(v/243)+!!(v/273)+!!(v/304)+!!(v/334)+1
set /a d=w+1-(!(y%%4))*(!((m-3)^&16))
set /a d=d-((m-1)*30+2*(!((m-7)^&16))-1+((65611044^>^>(2*m))^&3))
goto :eof
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: calculate the week number %v% for the date (%y% %m% %d%) ::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:date2week
setlocal
call :date2day
set i=%w%
set d=1
set m=1
call :date2day
set /a n=(w+1)%%7
set /a v=!(n/4)
set /a v=v+(i-w+n)/7
if %v% gtr 0 goto :d2w1
set v=53
if %n%==4 goto :d2w2
set /a y=y-1
call :date2day
set /a n=(w+1)%%7
if %n%==3 goto :d2w2
set v=52
goto :d2w2
:d2w1
if %v% leq 52 goto :d2w2
if %n%==3 goto :d2w2
set /a y=y+1
call :date2day
set /a n=(w+1)%%7
if %n%==4 goto :d2w2
set v=1
:d2w2
endlocal & set v=%v%
goto :eof
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: insert holidays and birthdays here ::
:: format: :: . day.month. description ::
:: if month==0 then day is the offset to eastern ::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::. 1.1. Neujahr
::. 6.1. Hl. 3 Koenige
::. 14.2. Valentinstag
::.-48.0. Rosenmontag
::.-47.0. Faschingsdienstag
::. -2.0. Karfreitag
::. -1.0. Karsamstag
::. 0.0. Ostersonntag
::. 1.0. Ostermontag
::. 1.5. Maifeiertag
::. 39.0. Christi Himmelfahrt
::. 49.0. Pfingstsonntag
::. 50.0. Pfingstmontag
::. 60.0. Fronleichnam
::. 15.8. Maria Himmelfahrt
::. 3.10. Tag d. dt. Einheit
::. 1.11. Allerheiligen
::. 24.12. Heiligabend
::. 25.12. 1. Weihnachtstag
::. 26.12. 2. Weihnachtstag
::. 31.12. Silvester
--
/-\ /\/\ /\/\ /-\ /\/\ /\/\ /-\ T /-\
-=- -=- -=- -=- -=- -=- -=- -=- - -=-
........... [ al lavoro ] ...........