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>includeconstant builtins\timedate.eyear = 1969
 
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))
sequencestring resweekdays = {centreiff(format_timedate(ldm,"Mmmm"),20),sun_to_sat?"Su Mo Tu We Th Fr Sa"}
31 :"Mo Tu We Th Fr Sa Su")
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(1969year,80)
printf(1,join(repeat("1234567890",8),"")&"\n")
print_calendar(1969year,132,true)
printf(1,join(repeat("1234567890",13),"")&"12\n")</lang>
{{out}}
<pre>
 
[Spot Reserved For Snoopy]
1969
January February March
Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su
1 2 3 4 5 1 2 1 2
5 6 7 8 9 10 11 12 2 3 4 5 6 7 8 9 2 3 4 5 6 7 8 9
12 13 14 15 16 17 18 19 9 10 11 12 13 14 15 16 9 10 11 12 13 14 15 16
19 20 21 22 23 24 25 26 16 17 18 19 20 21 22 23 16 17 18 19 20 21 22 23
26 27 28 29 30 31 23 24 25 26 27 28 23 24 25 26 27 28 29 30
30 31
April May June
Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su
1 2 3 4 5 6 1 2 3 4 1 2 3 4 5 6 7 1
6 7 8 9 10 11 12 13 4 5 6 7 8 9 10 11 8 2 9 103 11 124 13 145 6 7 8
13 14 15 16 17 18 19 20 11 12 13 14 15 16 17 18 15 16 179 1810 1911 2012 2113 14 15
20 21 22 23 24 25 26 27 18 19 20 21 22 23 24 25 22 2316 2417 2518 2619 2720 2821 22
27 28 29 30 25 26 27 28 29 30 31 29 30 23 24 25 26 27 28 29
30
July August September
Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su
1 2 3 4 5 6 1 2 3 1 2 3 4 5 6 7
6 7 8 9 10 11 12 13 3 4 5 6 7 8 9 10 7 8 9 10 11 12 13 14
13 14 15 16 17 18 19 20 10 11 12 13 14 15 16 17 14 15 16 17 18 19 20 21
20 21 22 23 24 25 26 27 17 18 19 20 21 22 23 24 21 22 23 24 25 26 27 28
27 28 29 30 31 24 25 26 27 28 29 30 31 28 29 30
31
October November December
Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su
1 2 3 4 5 1 2 1 2 3 4 5 6 7
5 6 7 8 9 10 11 12 2 3 4 5 6 7 8 9 7 8 9 10 11 12 13 14
12 13 14 15 16 17 18 19 9 10 11 12 13 14 15 16 14 15 16 17 18 19 20 21
19 20 21 22 23 24 25 26 16 17 18 19 20 21 22 23 21 22 23 24 25 26 27 28
26 27 28 29 30 31 23 24 25 26 27 28 29 30 28 29 30 31
30
12345678901234567890123456789012345678901234567890123456789012345678901234567890
[Spot Reserved For Snoopy]
7,830

edits