Основной код:
Библиотека iblib.yab
Код: Выделить всё
print "Ian's Calendar Author"
print "uses iblib"
import iblib
input "Year :" year
do
month=month+1
if month>12 then break endif
open "Month/"+str$(month)+".html" for writing as #1
print #1 chr$(60),"!DOCTYPE HTML PUBLIC ",chr$(34),"-//W3C//DTD HTML 4.01//EN",chr$(34),chr$(62)
print #1 chr$(60),"head",chr$(62)
print #1 chr$(60),"TITLE",chr$(62),iblib.monthname$(month)+" "+str$(year),chr$(60),"/TITLE",chr$(62)
print #1 chr$(60),"meta http-equiv",chr$(61),chr$(34),"Content-Type",chr$(34)," content",chr$(61),chr$(34),"text/html",chr$(59),"charset",chr$(61),"utf-8",chr$(34),chr$(62)
print #1 chr$(60),"/head",chr$(62)
print #1 chr$(60),"body",chr$(62)
print #1 chr$(60),"h1",chr$(62),iblib.monthname$(month)+" "+str$(year),chr$(60),"/h1",chr$(62)
print #1 chr$(60),"table border=",chr$(34),"1",chr$(34)," style=",chr$(34),"text-align: center",chr$(34),chr$(62),chr$(10),chr$(60),"tr",chr$(62)
print #1 "<td style=",chr$(34),"width:20px",chr$(34),">","W","</td>"
print #1 "<td style=",chr$(34),"width:200px",chr$(34),">",iblib.dayname$(1),"</td>"
print #1 "<td style=",chr$(34),"width:200px",chr$(34),">",iblib.dayname$(2),"</td>"
print #1 "<td style=",chr$(34),"width:200px",chr$(34),">",iblib.dayname$(3),"</td>"
print #1 "<td style=",chr$(34),"width:200px",chr$(34),">",iblib.dayname$(4),"</td>"
print #1 "<td style=",chr$(34),"width:200px",chr$(34),">",iblib.dayname$(5),"</td>"
print #1 "<td style=",chr$(34),"width:200px",chr$(34),">",iblib.dayname$(6),"</td>"
print #1 "<td style=",chr$(34),"width:200px",chr$(34),">",iblib.dayname$(7),"</td>"
lunarpixheight$="25px"
print #1 "</tr>"
workingdate$=iblib.modDaystoDate$(iblib.formatdate$(year, month, 1), (iblib.returndayofweek(iblib.formatdate$(year, month, 1))-1)*-1)
do
print #1 "<tr>"
print #1 "<td style=",chr$(34),"width:0px; height:85px; text-align:centre; vertical-align:centre",chr$(34),">",mid$(iblib.getWeekNumber$(workingdate$),7,2),"</td>"
print #1 "<td style=",chr$(34),"width:200px; height:85px; text-align:left; vertical-align:top",chr$(34),">",iblib.returnDay(iblib.modDaystoDate$(workingdate$, 0))
if iblib.lunarphase$(iblib.modDaystoDate$(workingdate$, 0))<>iblib.lunarphase$(iblib.modDaystoDate$(workingdate$, -1)) then
print #1 "<img src=",chr$(34),"images/",iblib.lunarphase$(iblib.modDaystoDate$(workingdate$, 0)),".png",chr$(34),"alt=",chr$(34),chr$(34), "height=",chr$(34),lunarpixheight$,chr$(34),">"
endif
print #1 "</td>"
print #1 "<td style=",chr$(34),"width:200px; height:85px; text-align:left; vertical-align:top",chr$(34),">",iblib.returnDay(iblib.modDaystoDate$(workingdate$, 1))
if iblib.lunarphase$(iblib.modDaystoDate$(workingdate$, 1))<>iblib.lunarphase$(iblib.modDaystoDate$(workingdate$, 0)) then
print #1 "<img src=",chr$(34),"images/",iblib.lunarphase$(iblib.modDaystoDate$(workingdate$, 1)),".png",chr$(34),"alt=",chr$(34),chr$(34), "height=",chr$(34),lunarpixheight$,chr$(34),">"
endif
print #1 "</td>"
print #1 "<td style=",chr$(34),"width:200px; height:85px; text-align:left; vertical-align:top",chr$(34),">",iblib.returnDay(iblib.modDaystoDate$(workingdate$, 2))
if iblib.lunarphase$(iblib.modDaystoDate$(workingdate$, 2))<>iblib.lunarphase$(iblib.modDaystoDate$(workingdate$, 1)) then
print #1 "<img src=",chr$(34),"images/",iblib.lunarphase$(iblib.modDaystoDate$(workingdate$, 2)),".png",chr$(34),"alt=",chr$(34),chr$(34), "height=",chr$(34),lunarpixheight$,chr$(34),">"
endif
print #1 "</td>"
print #1 "<td style=",chr$(34),"width:200px; height:85px; text-align:left; vertical-align:top",chr$(34),">",iblib.returnDay(iblib.modDaystoDate$(workingdate$, 3))
if iblib.lunarphase$(iblib.modDaystoDate$(workingdate$, 3))<>iblib.lunarphase$(iblib.modDaystoDate$(workingdate$, 2)) then
print #1 "<img src=",chr$(34),"images/",iblib.lunarphase$(iblib.modDaystoDate$(workingdate$, 3)),".png",chr$(34),"alt=",chr$(34),chr$(34), "height=",chr$(34),lunarpixheight$,chr$(34),">"
endif
print #1 "</td>"
print #1 "<td style=",chr$(34),"width:200px; height:85px; text-align:left; vertical-align:top",chr$(34),">",iblib.returnDay(iblib.modDaystoDate$(workingdate$, 4))
if iblib.lunarphase$(iblib.modDaystoDate$(workingdate$, 4))<>iblib.lunarphase$(iblib.modDaystoDate$(workingdate$, 3)) then
print #1 "<img src=",chr$(34),"images/",iblib.lunarphase$(iblib.modDaystoDate$(workingdate$, 4)),".png",chr$(34),"alt=",chr$(34),chr$(34), "height=",chr$(34),lunarpixheight$,chr$(34),">"
endif
print #1 "</td>"
print #1 "<td style=",chr$(34),"width:200px; height:85px; text-align:left; vertical-align:top",chr$(34),">",iblib.returnDay(iblib.modDaystoDate$(workingdate$, 5))
if iblib.lunarphase$(iblib.modDaystoDate$(workingdate$, 5))<>iblib.lunarphase$(iblib.modDaystoDate$(workingdate$, 4)) then
print #1 "<img src=",chr$(34),"images/",iblib.lunarphase$(iblib.modDaystoDate$(workingdate$, 5)),".png",chr$(34),"alt=",chr$(34),chr$(34), "height=",chr$(34),lunarpixheight$,chr$(34),">"
endif
print #1 "</td>"
print #1 "<td style=",chr$(34),"width:200px; height:85px; text-align:left; vertical-align:top",chr$(34),">",iblib.returnDay(iblib.modDaystoDate$(workingdate$, 6))
if iblib.lunarphase$(iblib.modDaystoDate$(workingdate$, 6))<>iblib.lunarphase$(iblib.modDaystoDate$(workingdate$, 5)) then
print #1 "<img src=",chr$(34),"images/",iblib.lunarphase$(iblib.modDaystoDate$(workingdate$, 6)),".png",chr$(34),"alt=",chr$(34),chr$(34), "height=",chr$(34),lunarpixheight$,chr$(34),">"
endif
print #1 "</td>"
print #1 "</tr>"
workingdate$=iblib.modDaystoDate$(workingdate$, 7)
if iblib.returnMonth(workingdate$)>month or iblib.returnYear(workingdate$)>year then break endif
loop
print #1 "</table>"
print #1 "</body>"
close #1
loop
Код: Выделить всё
sub getWeekNumber$(x$)
local year, month, day, baseweek
year=returnYear(x$)
month=returnMonth(x$)
day=returnDay(x$)
baseweek=int((getordinalDate(x$)-returndayofweek(x$)+10)/7)
if baseweek=0 then
x$=str$(year-1)+"-12-28"
baseweek=int((getordinalDate(x$)-returndayofweek(x$)+10)/7)
return str$(year-1)+"-W"+str$(baseweek,"%02.2g")
elseif baseweek=53
if returndayofweek(str$(year)+"-12-31")<4 then
return str$(year+1)+"-W01"
else
x$=str$(year)+"-12-28"
baseweek=int((getordinalDate(x$)-returndayofweek(x$)+10)/7)
return str$(year)+"-W"+str$(baseweek,"%02.2g")
endif
else
return str$(year)+"-W"+str$(baseweek,"%02.2g")
endif
end sub
sub getordinalDate(x$)
local year, month, day, ord
ord=0
year=returnYear(x$)
month=returnMonth(x$)
day=returnDay(x$)
if isLeapYear(year)=1 then
if month>2 then day=day+1 endif
endif
if month=1 then return day
elseif month=2 then return day+31
elseif month=3 then return day+59
elseif month=4 then return day+90
elseif month=5 then return day+120
elseif month=6 then return day+151
elseif month=7 then return day+181
elseif month=8 then return day+212
elseif month=9 then return day+243
elseif month=10 then return day+273
elseif month=11 then return day+304
elseif month=12 then return day+334
endif
end sub
sub returnYear(x$)
return val(mid$(x$,1,4))
end sub
#
sub returnMonth(x$)
return val(mid$(x$,6,2))
end sub
sub returnDay(x$)
return val(mid$(x$,9,4))
end sub
sub returndayofweek(x$)
local y,m,d,c,s
y=returnYear(x$)
m=returnMonth(x$)
d=returnDay(x$)
if m<3 then y=y-1 endif
m=mod(m+9,12)+1
c=int(y/100)
y=y-(100*c)
s=int(2.6*m-0.2)+int(y/4)+int(c/4)+d+y-(2*c)
day=mod(s, 7)
if day<0 then
day=day+7
endif
if day=0 then day=7 endif
return day
end sub
sub dayname$(day)
if day=1 then return "Monday"
elseif day=2 then return "Tuesday"
elseif day=3 then return "Wednesday"
elseif day=4 then return "Thursday"
elseif day=5 then return "Friday"
elseif day=6 then return "Saturday"
elseif day=7 then return "Sunday"
endif
end sub
sub monthname$(month)
if month=1 then return "January"
elseif month=2 then return "February"
elseif month=3 then return "March"
elseif month=4 then return "April"
elseif month=5 then return "May"
elseif month=6 then return "June"
elseif month=7 then return "July"
elseif month=8 then return "August"
elseif month=9 then return "September"
elseif month=10 then return "October"
elseif month=11 then return "November"
elseif month=12 then return "December"
endif
end sub
sub isLeapYear(year)
if year/400=int(year/400) then
return 1
elseif year/100=int(year/100) then
return 0
elseif year/4=int(year/4) then
return 1
else
return 0
endif
end sub
sub daysbetweentwodates(x$, y$)
local daysbetween, x, y, year1, year2, returnneg, temp$
daysbetween=0
year1=returnYear(x$)
year2=returnYear(y$)
if year1>year2 then
returnneg=-1
temp$=x$
x$=y$
y$=temp$
else returnneg=1
endif
year1=returnYear(x$)
year2=returnYear(y$)
x=year1+1
y=year2-1
if x<=y then
do
daysbetween=daysbetween+365
if isLeapYear(x)=1 then daysbetween=daysbetween+1 endif
if x=y then break endif
x=x+1
loop
endif
if year1=year2 then
daysbetween=getordinalDate(y$)-getordinalDate(x$) //formula for same-year calculations
else
daysbetween=daysbetween+(365-getordinalDate(x$))
if isLeapYear(year1)=1 then daysbetween=daysbetween+1 endif //add end parital year
daysbetween=daysbetween+getordinalDate(y$)
endif
return daysbetween*returnneg
end sub
sub modDaystoDate$(x$, days_mod) //Take input date and add or subtract a number of days to it
local year, ordinalvalue
year=returnYear(x$)
ordinalvalue=getordinalDate(x$)
if days_mod<0 then
days_mod=days_mod*-1
do
if ordinalvalue-days_mod<1 then
days_mod=days_mod-(ordinalvalue)
year=year-1
ordinalvalue=365+isLeapYear(year)
else
ordinalvalue=ordinalvalue-days_mod
return ordinaltoDate$(ordinalvalue, year)
endif
loop
else
do
if days_mod+ordinalvalue>365+isLeapYear(year) then
days_mod=days_mod-((365+isLeapYear(year)+1)-ordinalvalue)
ordinalvalue=1
year=year+1
else
ordinalvalue=ordinalvalue+days_mod
return ordinaltoDate$(ordinalvalue, year)
endif
loop
endif
end sub
sub ordinaltoDate$(ordinal, year)
local day
if ordinal<32 then return str$(year)+"-01-"+str$(ordinal-0,"%02.2g")
elseif ordinal<60+isLeapYear(year) then return str$(year)+"-02-"+str$(ordinal-31,"%02.2g")
elseif ordinal<91+isLeapYear(year) then return str$(year)+"-03-"+str$(ordinal-(59+isLeapYear(year)),"%02.2g")
elseif ordinal<121+isLeapYear(year) then return str$(year)+"-04-"+str$(ordinal-(90+isLeapYear(year)),"%02.2g")
elseif ordinal<152+isLeapYear(year) then return str$(year)+"-05-"+str$(ordinal-(120+isLeapYear(year)),"%02.2g")
elseif ordinal<182+isLeapYear(year) then return str$(year)+"-06-"+str$(ordinal-(151+isLeapYear(year)),"%02.2g")
elseif ordinal<213+isLeapYear(year) then return str$(year)+"-07-"+str$(ordinal-(181+isLeapYear(year)),"%02.2g")
elseif ordinal<244+isLeapYear(year) then return str$(year)+"-08-"+str$(ordinal-(212+isLeapYear(year)),"%02.2g")
elseif ordinal<274+isLeapYear(year) then return str$(year)+"-09-"+str$(ordinal-(243+isLeapYear(year)),"%02.2g")
elseif ordinal<305+isLeapYear(year) then return str$(year)+"-10-"+str$(ordinal-(273+isLeapYear(year)),"%02.2g")
elseif ordinal<335+isLeapYear(year) then return str$(year)+"-11-"+str$(ordinal-(304+isLeapYear(year)),"%02.2g")
else
return str$(year)+"-12-"+str$(ordinal-(334+isLeapYear(year)),"%02.2g")
endif
end sub
sub lunarphase$(x$)
local backtrack
if daysbetweentwodates("1999-08-11",x$)>0 then
lunarphase=mod(daysbetweentwodates("1999-08-11",x$), 29.530588853)
backtrack=0
else
backtrack=1
lunarphase=mod(daysbetweentwodates(x$,"1999-08-11"), 29.530588853)
endif
if lunarphase<1.8456618033 then phase=0
elseif lunarphase<5.5369854099 then phase=1
elseif lunarphase<9.2283090165 then phase=2
elseif lunarphase<12.9196326231 then phase=3
elseif lunarphase<16.6109562297 then phase=4
elseif lunarphase<20.3022798363 then phase=5
elseif lunarphase<23.9936034429 then phase=6
elseif lunarphase<27.6849270495 then phase=7
else phase=0
endif
if phase=0 then
return "New Moon"
elseif phase=1 then
if backtrack=0 then
return "Waxing Cresent"
else
return "Waning Cresent"
endif
elseif phase=2 then
if backtrack=0 then
return "First Quarter"
else
return "Third Quarter"
endif
elseif phase=3 then
if backtrack=0 then
return "Waxing Gibbous"
else
return "Waning Gibbous"
endif
elseif phase=4 then
return "Full Moon"
elseif phase=5 then
if backtrack=0 then
return "Waning Gibbous"
else
return "Waxing Gibbous"
endif
elseif phase=6 then
if backtrack=0 then
return "Third Quarter"
else
return "First Quarter"
endif
elseif phase=7 then
if backtrack=0 then
return "Waning Cresent"
else
return "Waxing Cresent"
endif
endif
end sub
sub round(in, decimalplaces)
local negative
if in<0 then
negative=1
in=in*-1
else
negative=0
endif
decimalplaces=int(decimalplaces)
decimalplaces=max(0, decimalplaces)
in=in*(10^decimalplaces)
if in-int(in)=0.5 then
if int(in)/2=int(int(in)/2) then
in=int(in)
else
in=int(in+0.5)
endif
else
#Standard Rounding Method
in=int(in+0.5)
endif
in=in/(10^decimalplaces)
if negative=1 then in=in*-1 endif
return in
end sub
sub formatdate$(year, month, day)
return str$(year, "%04.4g")+"-"+str$(month, "%02.2g")+"-"+str$(day, "%02.2g")
end sub
sub secs2hms$(seconds)
local h,m,s
h=int(seconds/3600)
seconds=seconds-h*3600
m=int(seconds/60)
seconds=seconds-m*60
s=seconds
return str$(h)+":"+str$(m,"%02.0f")+":"+str$(s,"%02.0f")
end sub