Calendar: Difference between revisions
Content added Content deleted
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: | Line 4,898: | ||
=={{header|Phix}}== |
=={{header|Phix}}== |
||
Gregorian calender only. |
Gregorian calender only. |
||
<lang Phix> |
<lang Phix>constant year = 1969 |
||
include builtins\timedate.e |
|||
function centre(string s, integer width) |
function centre(string s, integer width) |
||
integer pad = width-length(s), |
integer pad = width-length(s), |
||
Line 4,906: | Line 4,908: | ||
return repeat(' ',left)&s&repeat(' ',right) |
return repeat(' ',left)&s&repeat(' ',right) |
||
end function |
end function |
||
function one_month(integer year, integer month) |
function one_month(integer year, integer month, bool sun_to_sat) |
||
integer dow = day_of_week(year,month,1) |
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} |
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}), |
:{year,month+1,1,0,0,0,0,0}), |
||
timedelta(days:=-1)) |
timedelta(days:=-1)) |
||
string weekdays = iff(sun_to_sat?"Su Mo Tu We Th Fr Sa" |
|||
⚫ | |||
sequence res = {centre(format_timedate(ldm,"Mmmm"),20),weekdays} |
|||
integer lastday = ldm[DT_DAY] |
integer lastday = ldm[DT_DAY] |
||
string line = repeat(' ',20) |
string line = repeat(' ',20) |
||
Line 4,930: | Line 4,935: | ||
return res |
return res |
||
end function |
end function |
||
procedure print_calendar(integer year, integer width) |
procedure print_calendar(integer year, integer width, bool sun_to_sat=false) |
||
sequence months = repeat(0,12) |
sequence months = repeat(0,12) |
||
integer wide = floor((width+2)/22) |
integer wide = floor((width+2)/22) |
||
Line 4,937: | Line 4,942: | ||
printf(1,centre(sprintf("%d",year),width)&"\n") |
printf(1,centre(sprintf("%d",year),width)&"\n") |
||
for month=1 to 12 do |
for month=1 to 12 do |
||
months[month] = one_month(year,month) |
months[month] = one_month(year,month,sun_to_sat) |
||
end for |
end for |
||
for month=1 to 12 by wide do |
for month=1 to 12 by wide do |
||
Line 4,959: | Line 4,964: | ||
end for |
end for |
||
end procedure |
end procedure |
||
print_calendar( |
print_calendar(year,80) |
||
printf(1,join(repeat("1234567890",8),"")&"\n") |
printf(1,join(repeat("1234567890",8),"")&"\n") |
||
print_calendar( |
print_calendar(year,132,true) |
||
printf(1,join(repeat("1234567890",13),"")&"12\n")</lang> |
printf(1,join(repeat("1234567890",13),"")&"12\n")</lang> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
[Spot Reserved For Snoopy] |
[Spot Reserved For Snoopy] |
||
1969 |
1969 |
||
January February March |
January February March |
||
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 |
|||
6 7 8 9 10 11 12 3 4 5 6 7 8 9 3 4 5 6 7 8 9 |
|||
13 14 15 16 17 18 19 10 11 12 13 14 15 16 10 11 12 13 14 15 16 |
|||
20 21 22 23 24 25 26 17 18 19 20 21 22 23 17 18 19 20 21 22 23 |
|||
27 28 29 30 31 24 25 26 27 28 24 25 26 27 28 29 30 |
|||
31 |
|||
April May June |
April May June |
||
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 |
|||
7 8 9 10 11 12 13 5 6 7 8 9 10 11 2 3 4 5 6 7 8 |
|||
14 15 16 17 18 19 20 12 13 14 15 16 17 18 9 10 11 12 13 14 15 |
|||
21 22 23 24 25 26 27 19 20 21 22 23 24 25 16 17 18 19 20 21 22 |
|||
28 29 30 26 27 28 29 30 31 23 24 25 26 27 28 29 |
|||
⚫ | |||
July August September |
July August September |
||
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 |
|||
7 8 9 10 11 12 13 4 5 6 7 8 9 10 8 9 10 11 12 13 14 |
|||
14 15 16 17 18 19 20 11 12 13 14 15 16 17 15 16 17 18 19 20 21 |
|||
21 22 23 24 25 26 27 18 19 20 21 22 23 24 22 23 24 25 26 27 28 |
|||
28 29 30 31 25 26 27 28 29 30 31 29 30 |
|||
⚫ | |||
October November December |
October November December |
||
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 |
|||
6 7 8 9 10 11 12 3 4 5 6 7 8 9 8 9 10 11 12 13 14 |
|||
13 14 15 16 17 18 19 10 11 12 13 14 15 16 15 16 17 18 19 20 21 |
|||
20 21 22 23 24 25 26 17 18 19 20 21 22 23 22 23 24 25 26 27 28 |
|||
27 28 29 30 31 24 25 26 27 28 29 30 29 30 31 |
|||
⚫ | |||
12345678901234567890123456789012345678901234567890123456789012345678901234567890 |
12345678901234567890123456789012345678901234567890123456789012345678901234567890 |
||
[Spot Reserved For Snoopy] |
[Spot Reserved For Snoopy] |