Календарь 2
Скачать скрипт.
/**/
call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
call SysLoadFuncs
version="1.5"
displayDays=40
displayBDays=10
birthDays.0=0
singleCol=0
/*
Warpnote birthday format file
dd,mm,yyyy,comment
*/
birthDayFile='C:\UTILS\General\WARPNOTE\birthday.txt'
/*mm.dd*/
holidays.0=7
holidays.1='01.01'
holidays.2='01.02'
holidays.3='01.07'
holidays.4='12.12'
holidays.5='03.07'
holidays.6='03.08'
holidays.7='11.07'
signal on halt name help
signal on error name help
usage.0=12
usage.1="Usage:"
usage.2="calendar.cmd [[dd.]mm[.yyyy]] [/BW] [/MONTH] [/SINGLE] [/E] [/LEGEND]"
usage.3=""
usage.4="switches:"
usage.5="BW - Black & White mode;"
usage.6="MONTH - Display whole month;"
usage.7="SINGLE - Do not use multiple columns;"
usage.8="E - European mode;"
usage.9="LEGEND - Show legend;"
usage.10="[dd.]mm[.yyyy] - Assume current day is dd.mm.yyyy."
usage.11=''
usage.12='calendar v'||version||'. Done by Sergey Gryaznov'
arguments=arg(1)
if (isArg('-?')) | (isArg('-h')) | (isArg('/h')) | (isArg('/?')) then do
signal help
end
call readBirthdays(birthDayFile)
Esc = D2C( 27 ); Command = "[1;"; End = "m"; CommandLow= "[0;"
cl.Green = Esc || Command || "32" || End
cl.DarkGreen = Esc || CommandLow || "32" || End
cl.Cyan = Esc || Command || "36" || End
cl.White= Esc || Command || "37" || End
cl.Magenta=Esc || Command || "35" || End
cl.DarkMagenta=Esc || CommandLow || "35" || End
cl.Grey= Esc || CommandLow || "37" || End
cl.DarkGrey= Esc || Command || "30" || End
cl.Red = Esc || Command || "31" || End
cl.DarkRed = Esc || CommandLow || "31" || End
cl.Yellow=Esc || Command || "33" || End
color.Frame=cl.White
color.DayName=cl.Yellow
color.YearName=cl.Cyan
color.DayNum=cl.Grey
color.WeekDay=cl.Red
color.WeekDayAndHoliday=cl.DarkRed
color.Birthday=cl.Green
color.BirthdayAndHoliday=cl.DarkGreen
color.Holiday=cl.Magenta
color.DeferedHoliday=cl.DarkMagenta
color.Normal=cl.Grey
len.nStr=10
len.firstSkip=9
len.BaseSkip=25
if isArg('/BW') then do
len.nStr=3
len.firstSkip=2
len.BaseSkip=4
color.Frame=''
color.DayName=''
color.YearName=''
color.DayNum=''
color.WeekDay='·'
color.WeekDayAndHoliday='*'
color.Birthday='#'
color.BirthdayAndHoliday='#'
color.Holiday='¤'
color.DeferedHoliday='#'
color.Normal=''
end
name.Year=''
name.Month=''
month.1 ='Январь'||color.Frame||'══'
month.2 ='Февраль'||color.Frame||'═'
month.3 ='Март'||color.Frame||'════'
month.4 ='Апрель'||color.Frame||'══'
month.5 ='Май'||color.Frame||'═════'
month.6 ='Июнь'||color.Frame||'════'
month.7 ='Июль'||color.Frame||'════'
month.8 ='Август'||color.Frame||'══'
month.9 ='Сентябрь'||color.Frame
month.10='Октябрь'||color.Frame||'═'
month.11='Ноябрь'||color.Frame||'══'
month.12='Декабрь'||color.Frame||'═'
st.PreYear=color.Frame||'╔'||color.YearName
st.PostYear=color.Frame||'══════════════╗'
st.Month=color.Frame||'║'||color.DayName||'Пн. Вт. Ср. Чт. Пт. Сб. Вс.' ||color.Frame||'║'
st.MonthFrame=color.Frame||'╠═══╤═══╤═══╤═══╤═══╤═══╤═══╣'
st.MonthEndFrame=color.Frame||'╚═══════════════════════════╝'
if isArg('/E') then do
st.PostYear=color.Frame||'════════════╗'
month.1 ='January'||color.Frame||'═══'
month.2 ='Febriary'||color.Frame||'══'
month.3 ='March'||color.Frame||'═════'
month.4 ='April'||color.Frame||'═════'
month.5 ='May'||color.Frame||'═══════'
month.6 ='June'||color.Frame||'══════'
month.7 ='July'||color.Frame||'══════'
month.8 ='August'||color.Frame||'════'
month.9 ='September'||color.Frame
month.10='October'||color.Frame||'═══'
month.11='November'||color.Frame||'══'
month.12='December'||color.Frame||'══'
st.Month=color.Frame||'║'||color.DayName||'Mon Tue Wed Thu Fri Sat Sun' ||color.Frame||'║'
end
parse value Date('E') with cDay '/' cMonth '/' cYear
/*y2k bug*/
if (cYear<50) then do
cYear='20'||cYear
end
else do
cYear='19'||cYear
end
if isArg('/LEGEND') then do
say color.DayNum||'23'||color.Normal||' - usial day;'
say color.DayNum||'23'||d2c(17)||color.Normal||' - current day;'
say color.WeekDay||'23'||color.Normal||' - weekend;'
say color.Holiday||'23'||color.Normal||' - holiday;'
say color.WeekDayAndHoliday||'23'||color.Normal||' - holiday on weekend;'
say color.DeferedHoliday||'23'||color.Normal||' - defered holiday (prognoze);'
say color.Birthday||'23'||color.Normal||' - birthday;'
say color.BirthDayAndHoliday||'23'||color.Normal||' - birthday on weekend or holiday.'
exit
end
if isArg('/MONTH') then do
displayDays=getMonthDays(cMonth,cYear)-cDay+1
displayBDays=cDay-1
singleCol=1
end
if isArg('/SINGLE') then do
singleCol=1
end
Arguments=strip(translate(Arguments))
parse value arguments with arguments ' ' /* first option*/
if length(Arguments)>0 then do
if Pos('.',Arguments)>0 then do
if Pos('.',Arguments)<>lastPos('.',Arguments) then do
/* Assuming dd.mm.yyyy */
parse value arguments with cDay '.' cMonth '.' cYear
end
else do
/* Assuming mm.yyyy */
parse value arguments with cMonth '.' cYear
end
end
else do
cMonth=Arguments
end
if (datatype(cDay)<>'NUM') | (datatype(cMonth)<>'NUM') | (datatype(cYear)<>'NUM') then signal help
if (cDay>31) | (cDay<1) | (cMonth<1) | (cMonth>12) | (cYear>9998) | (cYear<1) then signal help
if (length(cYear)=2) then do
if (cYear<50) then do
cYear='20'||cYear
end
else do
cYear='19'||cYear
end
end
cYear=right(cYear,4,'0')
cDay=right(cDay,2,'0')
cMonth=right(cMonth,2,'0')
displayDays=getMonthDays(cMonth,cYear)-cDay+1
displayBDays=cDay-1
singleCol=1
end
parse value G2J(cYear||'.'||cMonth||'.'||cDay) with julYear '.' julDay
parse value G2J(cYear||'.12.31') with '.' maxCDay
if (julDay-displayBDays<=0) then do
cDisplayDays=DisplayBDays
Year=julYear
do forever
Year=Year-1
parse value G2J(Year||'.12.31') with '.' maxCDay
if (cDisplayDays>maxCDay) then cDisplayDays=cDisplayDays-maxCDay
if cDisplayDays<maxcday then="" leave="" end="" parse="" value="" g2j(year||'.12.31')="" with="" '.'="" maxcday="" day="maxCDay-cDisplayDays" else="" do="" year="julYear" j2g(year||'.'||day)="" gregyear="" gregmonth="" gregday="" *dayofweek="translate(Date('W',gregYear||gregMonth||gregDay,'S'))*/" dayofweek="translate(DayOfTheWeek(gregDay||'.'||gregMonth||'.'||gregYear))" select="" when="" otherwise="" systextscreensize()="" row="" col="" monthinrow="col%30" if="" singlecol="1" j="0" nullstr="" i="1" to="" len.nstr="" '="" deferedholidays="0" forever="" string.0="10" k="1" (monthinrow)*7="" string.i="" preframe="│" postframe="" ((k-1)="" 7="0)" &="" (kmonthinrow*7)="" (k="monthInRow*7)" string.1="" string.2="" string.3="" string.10="" m="0" l="gregMonth+k-1" l>12="" '||month.l||st.postyear||'="" while(i<="monthInRow)" cdaychar="" (gregyear="cYear)" &="" (gregmonth="cMonth)" (gregday="cDay)" oldmonth="gregMonth" s="gregDay" while="" (s>dayofweek)="" *m="gregDay%7" ((gregday%7)>0)="" |="" ((gregday="" 7)>0)="" (dayofweek="0)|(m=0)" week="3+m" (gregmonth<>oldmonth)="" (i>monthinrow)="" (j>="displayDays+displayBDays)" (string.00)) then dayColor=color.BirthdayAndHoliday
when (isBirthday=0) & (isWeekEnd=1) & (isHoliday=1) then dayColor=color.WeekdayAndHoliday
when (isBirthday=0) & (isWeekEnd=0) & (isHoliday=0) & (deferedHolidays>0) then do
dayColor=color.DeferedHoliday
deferedHolidays=deferedHolidays-1
end
otherwise
dayColor=color.DayNum
end
string.Week=overlay(dayColor||gregDay||cDayChar,string.Week,(len.BaseSkip*dayOfWeek)+((i-1)*len.BaseSkip*7+(i-1)*3)+len.FirstSkip)
DayOfWeek=DayOfWeek+1
if DayOfWeek>6 then do
DayOfWeek=0
Week=Week+1
end
Day=Day+1
if Day>maxCDay then do
Day=1
Year=Year+1
parse value G2J(Year||'.12.31') with '.' maxCDay
end
j=j+1
end
do i=1 to string.0
do while pos(' ',string.i)>0
string.i=delstr(string.i,pos(' ',string.i),1)
end
say string.i
end
say string.10
if (j>=displayDays+displayBDays) then leave
end
call charout ,color.Normal
exit
help:
call showUsage
exit
getMonthDays:procedure
parse arg month,year
month=month%1
year=year%1
MonthDays.0=12
MonthDays.1=31
MonthDays.2=28
MonthDays.3=31
MonthDays.4=30
MonthDays.5=31
MonthDays.6=30
MonthDays.7=31
MonthDays.8=31
MonthDays.9=30
MonthDays.10=31
MonthDays.11=30
MonthDays.12=31
if (Month=2) & (Year//4=0) then do
tDays=29
end
else do
tDays=MonthDays.month
end
return tDays
isArg:procedure expose arguments
parse arg option
option=translate(option)
if (pos(option,translate(arguments))>0) then do
rc=1
end
else do
rc=0
end
if rc=1 then
arguments=strip(delstr(arguments,pos(option,translate(arguments)),length(option)))
return rc
readBirthdays:procedure expose birthdays.
parse arg fName
k=birthdays.0
do while(lines(fName)>0)
parse value linein(fName) with dd ',' mm ',' other
dd=strip(dd)
mm=strip(mm)
if (length(dd)=0) | (length(mm)=0) | (length(dd)>2) | (length(mm)>2) then iterate
k=k+1
birthdays.k=mm||'.'||dd
end
birthdays.0=k
call stream fname,'c','close'
return 0
checkBirthday:procedure expose birthdays.
parse arg Year,Day
rc=0
do i=1 to birthdays.0
parse value G2J(Year||'.'||birthdays.i) with '.' hDay
if hDay=Day then do
rc=1
leave
end
end
return rc
checkHoliday:procedure expose holidays.
parse arg Year,Day
rc=0
do i=1 to holidays.0
parse value G2J(Year||'.'||holidays.i) with '.' hDay
if hDay=Day then do
rc=1
leave
end
end
return rc
G2J: Procedure
Arg gregDate
year = SubStr(gregDate,1,4)
mon = SubStr(gregDate,6,2) + 0
day = SubStr(gregDate,9,2)
mon.0 = 12
mon.1 = 0
mon.2 = 31
mon.3 = 59
mon.4 = 90
mon.5 = 120
mon.6 = 151
mon.7 = 181
mon.8 = 212
mon.9 = 243
mon.10 = 273
mon.11 = 304
mon.12 = 334
If (year // 400 = 0 | (year // 100 > 0 & year // 4 = 0)) & mon > 2 Then
leap = 1
Else leap = 0
julDay = mon.mon + day + leap
Return Right(year,4,'0')'.'Right(julDay,3,'0')
J2G: Procedure
Arg julDate
Parse Var julDate year'.'jday
mon.0 = 12
mon.1 = 0
mon.2 = 31
mon.3 = 59
mon.4 = 90
mon.5 = 120
mon.6 = 151
mon.7 = 181
mon.8 = 212
mon.9 = 243
mon.10 = 273
mon.11 = 304
mon.12 = 334
If year // 400 = 0 | (year // 100 > 0 & year // 4 = 0) Then
leap = 1
Else
leap = 0
Do i = 1 To mon.0
If i > 2 Then mon.i = mon.i + leap
If jday > mon.i Then mon = i
End
day = jday - mon.mon
gregDate = Right(year,4,'0')'.'Right(mon,2,'0')'.'Right(day,2,'0')
return gregDate
showUsage: procedure expose usage.
do i=1 to usage.0
say usage.i
end
return
DayOfTheWeek: Procedure
sep = '.'
parse arg dd (sep) mm (sep) year
days = "Sunday Monday Tuesday Wednesday Thursday Friday Saturday"
magic = 6 2 3 6 1 4 6 2 5 0 3 5
parse var year cent +2 yr
leap = year // 4 = 0 & (yr\=0 | cent//4=0)
dow=yr + yr%4 + (6-2*(cent//4)) + word(magic,mm) + dd
if mm < 3 & \leap then dow=dow+1
dow = dow // 7
return word(days,dow+1)