Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @ECHO OFF
- :: batch for generating calendars
- IF "%~1"=="/?" (
- ECHO START "%~NX0" WITHOUT ARGUMENTS AND THEN ENTER THE YEAR.
- ECHO "%~NX0" WILL OPEN IN IT'S OWN WINDOW TO AVOID RESIZING
- ECHO AN EXISTING WINDOW.
- ECHO.
- ECHO A SCREEN RESOLUTION AND/OR FONT SIZE THAT CAN DISPLAY
- ECHO CMD WINDOWS OF 96 COLUMNS AND 39 LINES IS REQUIRED.
- ECHO SOME CONFIGURATIONS MAY USE SCROLL BARS TO ACHIEVE
- ECHO THIS.
- EXIT /B
- )
- :: The current codepage is stored in variable %CodePage%,
- :: then changed to 850 to facilitate box drawing characters.....
- FOR /F "tokens=*" %%A IN ('CHCP') DO FOR %%B IN (%%~A) DO SET CodePage=%%B
- CHCP 850 >NUL 2>&1
- :: The title can be used to falicitate custom window
- :: positioning via the properties menu of "calendars..."
- :: /max is used so as much content as possible is visable
- :: without moving the window. /max must be removed for
- :: custom window positing.....
- IF NOT "%~1 %~2"=="WINDOW SIZE" (
- START "CALENDARS..." /MAX CMD /C "%~F0" WINDOW SIZE
- REM Restore the original codepage before exiting.....
- CHCP %CodePage% >NUL 2>&1
- EXIT /B
- )
- MODE CON:COLS=96 LINES=39
- SETLOCAL ENABLEDELAYEDEXPANSION
- :loop
- FOR %%Z IN (jan feb mar apr may jun jul aug sep oct nov dec year day leap noleap length test) DO SET %%Z=
- SET /P year=Enter a year to see it's calendar, or nothing to exit, then press enter:
- IF NOT DEFINED year (
- REM Restore the original codepage before exiting.....
- CHCP %CodePage% >NUL 2>&1
- EXIT /B
- )
- ::Test that the input is only numbers...
- SET test=!year!
- FOR /l %%Z IN (0 1 9) DO IF DEFINED test SET "test=!test:%%Z=!"
- IF DEFINED test CLS&GOTO loop
- :zero
- IF NOT DEFINED year (
- :error
- cls
- echo The year entered can not be accepted.
- echo.
- pause
- CLS
- GOTO loop
- )
- :: remove leading zeros, if any...
- IF "%year:~0,1%"=="0" SET year=%year:~1%&&GOTO zero
- :: The %processor_architecture% test is used to test
- :: limits of caculations, if the variable is undefined
- :: or unrecognised the test will fall through and complete
- :: anyway, if the limit is surpassed this way the results may
- :: not be valid. The tested number is ~80% of the limit of the
- :: os so that year + year / 4 yields a valid result.
- IF /I "!processor_architecture!"=="x86" (
- IF !year! gtr 1717986917 GOTO :error
- ) else (
- IF NOT "!processor_architecture:64=!"=="!processor_architecture!" (
- IF !year! gtr 7378697629483820645 GOTO :error
- )
- )
- :: Generate the first day of the year, 0=sun, 1=mon,...,6=sat
- :: A 365 day year ofsets by one day, so the next year will start
- :: the next day (i.e. 2009 starts on thr and 2010 starts on fri)
- :: an extra day must be added for every leapyear. Using modulo
- :: 7 on the total of offset days reviels the starting day of the
- :: year. one day must also be removed if the year is a leap year
- :: because the below will add one for it, the remainder for non
- :: leap years is not an issue because set /a only returns whole
- :: numbers.
- SET /A day=(year + year / 4) - (year / 100 - year / 400)
- SET /A leap=year %% 400
- SET /A noleap=year %% 100
- IF !leap! GTR 0 (
- IF !noleap! NEQ 0 SET /A leap=year %% 4
- )
- IF %leap%==0 SET /A day-=1
- SET /A day%%=7
- :: For each year every month is padded to is starting offset
- :: with spaces, january has the original offset generated above.
- :: each additional offset is generated by adding the total days of
- :: the previous month then processing it by modulo 7.
- :: The days are stored in a varianle to display later, these variables
- :: are padded to 111 characters using spaces for display purposes.
- FOR %%U IN (jan feb mar apr may jun jul aug sep oct nov dec) DO (
- FOR %%V IN (jan mar may jul aug oct dec) DO IF /I %%U==%%V SET length=31
- FOR %%W IN (apr jun sep nov) DO IF /I %%U==%%W SET length=30
- IF /I %%U==feb (
- IF !leap!==0 (
- SET length=29
- ) else (
- SET length=28
- )
- )
- FOR /l %%X IN (1 1 !day!) DO SET "%%U=!%%U! "
- FOR /l %%Y IN (1 1 !length!) DO (
- IF %%Y lss 10 (
- SET "%%U=!%%U!%%Y "
- ) else (
- SET "%%U=!%%U!%%Y "
- )
- )
- FOR /l %%Z IN (!length! 1 54) DO IF "!%%U:~110!"=="" SET "%%U=!%%U! "
- SET /A day=^(day + length^) %% 7
- )
- :test
- :: The results are displayed below using substrings of each month's
- variable.
- cls
- TITLE THE CALENDAR FOR THE YEAR OF %YEAR%
- echo. ��������������������ͻ ��������������������ͻ ��������������������ͻ ��������������������ͻ
- echo. � JANUARY � � FEBUARY � � MARCH � � APRIL �
- echo. �������������������� �������������������� �������������������� ��������������������
- 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 �
- echo. �������������������� �������������������� �������������������� ��������������������
- echo. �%JAN:~0,20%� �%FEB:~0,20%� �%MAR:~0,20%� �%APR:~0,20%�
- echo. �%JAN:~21,20%� �%FEB:~21,20%� �%MAR:~21,20%� �%APR:~21,20%�
- echo. �%JAN:~42,20%� �%FEB:~42,20%� �%MAR:~42,20%� �%APR:~42,20%�
- echo. �%JAN:~63,20%� �%FEB:~63,20%� �%MAR:~63,20%� �%APR:~63,20%�
- echo. �%JAN:~84,20%� �%FEB:~84,20%� �%MAR:~84,20%� �%APR:~84,20%�
- echo. �%JAN:~105% � �%FEB:~105% � �%MAR:~105% � �%APR:~105% �
- echo. ��������������������ͼ ��������������������ͼ ��������������������ͼ ��������������������ͼ
- echo.
- echo. ��������������������ͻ ��������������������ͻ ��������������������ͻ ��������������������ͻ
- echo. � MAY � � JUNE � � JULY � � AUGUST �
- echo. �������������������� �������������������� �������������������� ��������������������
- 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 �
- echo. �������������������� �������������������� �������������������� ��������������������
- echo. �%MAY:~0,20%� �%JUN:~0,20%� �%JUL:~0,20%� �%AUG:~0,20%�
- echo. �%MAY:~21,20%� �%JUN:~21,20%� �%JUL:~21,20%� �%AUG:~21,20%�
- echo. �%MAY:~42,20%� �%JUN:~42,20%� �%JUL:~42,20%� �%AUG:~42,20%�
- echo. �%MAY:~63,20%� �%JUN:~63,20%� �%JUL:~63,20%� �%AUG:~63,20%�
- echo. �%MAY:~84,20%� �%JUN:~84,20%� �%JUL:~84,20%� �%AUG:~84,20%�
- echo. �%MAY:~105% � �%JUN:~105% � �%JUL:~105% � �%AUG:~105% �
- echo. ��������������������ͼ ��������������������ͼ ��������������������ͼ ��������������������ͼ
- echo.
- echo. ��������������������ͻ ��������������������ͻ ��������������������ͻ ��������������������ͻ
- echo. � SEPTEMBER � � OCTOBER � � NOVEMBER � � DECEMBER �
- echo. �������������������� �������������������� �������������������� ��������������������
- 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 �
- echo. �������������������� �������������������� �������������������� ��������������������
- echo. �%SEP:~0,20%� �%OCT:~0,20%� �%NOV:~0,20%� �%DEC:~0,20%�
- echo. �%SEP:~21,20%� �%OCT:~21,20%� �%NOV:~21,20%� �%DEC:~21,20%�
- echo. �%SEP:~42,20%� �%OCT:~42,20%� �%NOV:~42,20%� �%DEC:~42,20%�
- echo. �%SEP:~63,20%� �%OCT:~63,20%� �%NOV:~63,20%� �%DEC:~63,20%�
- echo. �%SEP:~84,20%� �%OCT:~84,20%� �%NOV:~84,20%� �%DEC:~84,20%�
- echo. �%SEP:~105% � �%OCT:~105% � �%NOV:~105% � �%DEC:~105% �
- echo. ��������������������ͼ ��������������������ͼ ��������������������ͼ ��������������������ͼ
- GOTO loop
Advertisement
Add Comment
Please, Sign In to add comment