include builtins\timedate.e function centre(string s, integer width) integer pad = width-length(s), left = floor(pad/2), right = pad-left return repeat(' ',left)&s&repeat(' ',right) end function function one_month(integer year, integer month) integer dow = day_of_week(year,month,1) sequence ldm = adjust_timedate(iff(month=12?{year+1,1,1,0,0,0,0,0} :{year,month+1,1,0,0,0,0,0}), timedelta(days:=-1)) sequence res = {centre(format_timedate(ldm,"Mmmm"),20),"Su Mo Tu We Th Fr Sa"} integer lastday = ldm[DT_DAY] string line = repeat(' ',20) integer p = dow*3-2 for d=1 to lastday do line[p..p+1] = sprintf("%2d",d) p += 3 if dow=7 or d=lastday then res = append(res,line) line = repeat(' ',20) dow = 1 p = 1 else dow += 1 end if end for return res end function procedure print_calendar(integer year, integer width) sequence months = repeat(0,12) integer wide = floor((width+2)/22) printf(1,centre("[Spot Reserved For Snoopy]",width)&"\n") printf(1,centre(sprintf("%d",year),width)&"\n") for month=1 to 12 do months[month] = one_month(year,month) end for for month=1 to 12 by wide do for k=1 to 9 do -- (more than enough) integer any = 0 string line = "", this for j=0 to wide-1 do if length(line) then line &= " " end if if k>length(months[month+j]) then line &= repeat(' ',20) else line &= months[month+j][k] any = 1 end if end for if any=0 then exit end if printf(1,centre(line,width)&"\n") end for end for end procedure print_calendar(1969,80) printf(1,join(repeat("1234567890",8),"")&"\n") print_calendar(1969,132) printf(1,join(repeat("1234567890",13),"")&"12\n")