Calendar: Difference between revisions

354 bytes added ,  10 years ago
Tighter code, verbage
(added zkl)
(Tighter code, verbage)
Line 3,648:
<lang zkl>var [const] D=Time.Date, days="Su Mo Tu We Th Fr Sa";
 
fcn center(text,m) { String(" "*((m-text.len())/2),text,"\n") }
 
fcn oneMonth(year,month){
day1:=D.zeller(year,month,1); //1969-1-1 -->3 (Wed, ISO 8601)
dayz:=D.daysInMonth(year,month); //1969-1 -->31
mn :=T(center(D.monthNames[month],days.len());,days).extend(
(1).pump(dayz,(0).pump(day1,T,T(Void,""))).apply("%2s ".fmt)
x :=(1-day1);
(1) .pump(dayz-x+1List,T(T,Void.Read, mn+days+"\n".len()/3,False),String.create));
'wrap(d){ "%2s ".fmt(if(d<=day1)""else d-day1) + (if(d%7)""else"\n") })
.split("\n"); // list of lines for this month
}
 
const M=70; // mystery number
fcn oneYear(y,title){
println(center("3 Days of Peace & Music"title,M),"\n",center(y.toString(),M),"\n");
[1..12,3].pump(String,'wrap(m){ // 3 months per line
mmm:=L(oneMonth(y,m).pump(3,List,oneMonth.fp(y,m+1)); //L(L(7-8 lines),oneMonth L(y...),m+2 L(...));
if (mmm.apply("len").sum() % 3) // months have diff # of lines, pad
mmm=mmm.apply("append","");
Line 3,672 ⟶ 3,670:
}
 
oneYear(1969,"3 Days of Peace & Music").println();</lang>
oneMonth produces a list of strings that make up a one month calender. Each day is three characters, the first line is padded with blanks to line it up with the 1st day of the week. The entire month is one long list of "days" that is then chunked into a list of weeks (one line per week). oneYear takes 3 months and builds the page line by line.
{{out}}
<pre>
Anonymous user