Calendar: Difference between revisions
m
→{{header|Phix}}: bugfix: day_of_week is [as per ISO 8601] now 1..7 for mon..sun (was sun..sat), added sat_to_sun arg to revert output.
m (→{{header|Phix}}: bugfix: day_of_week is [as per ISO 8601] now 1..7 for mon..sun (was sun..sat), added sat_to_sun arg to revert output.) |
|||
Line 4,898:
=={{header|Phix}}==
Gregorian calender only.
<lang Phix>
include builtins\timedate.e
function centre(string s, integer width)
integer pad = width-length(s),
Line 4,906 ⟶ 4,908:
return repeat(' ',left)&s&repeat(' ',right)
end function
function one_month(integer year, integer month, bool sun_to_sat)
integer dow = day_of_week(year,month,1)
if sun_to_sat then dow = remainder(dow,7)+1 end if
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),weekdays}
integer lastday = ldm[DT_DAY]
string line = repeat(' ',20)
Line 4,930 ⟶ 4,935:
return res
end function
procedure print_calendar(integer year, integer width, bool sun_to_sat=false)
sequence months = repeat(0,12)
integer wide = floor((width+2)/22)
Line 4,937 ⟶ 4,942:
printf(1,centre(sprintf("%d",year),width)&"\n")
for month=1 to 12 do
months[month] = one_month(year,month,sun_to_sat)
end for
for month=1 to 12 by wide do
Line 4,959 ⟶ 4,964:
end for
end procedure
print_calendar(
printf(1,join(repeat("1234567890",8),"")&"\n")
print_calendar(
printf(1,join(repeat("1234567890",13),"")&"12\n")</lang>
{{out}}
<pre>
[Spot Reserved For Snoopy]
1969
January February March
April May June
30▼
July August September
▲ 31
October November December
▲ 30
12345678901234567890123456789012345678901234567890123456789012345678901234567890
[Spot Reserved For Snoopy]
|