Calendar - for "REAL" programmers: Difference between revisions

m (→‎{{header|Sidef}}: updated code)
Line 819:
 
=={{header|Elena}}==
ELENA 3.x1 :
<lang elena>#import system'text.
#import system'routines.
#import system'calendar.
#import extensions.
#import extensions'math.
#import extensions'routines.
 
const MonthNames = ("JANUARY","FEBRUARY","MARCH","APRIL","MAY","JUNE","JULY","AUGUST","SEPTEMBER","OCTOBER","NOVEMBER","DECEMBER").
Line 838:
object theRow.
constructor new &year:aYear &month:aMonth
[
theMonth := aMonth.
theYear := aYear.
theLine := TextBuffer new.
theRow := Integer new &int:0.
]
 
Line 849:
[
theRow set:0.
theDate := Date new &year:(theYear int) &month:(theMonth int) &day:1.
DayNames run &each: (:aName)
[ theLine writeLiteral:" ":aName ].
]
Line 860:
if (theDate month == theMonth)
[
theLine write:" " &length:(((theDate dayOfWeek) => 0 [ 7 ]; ! [ theDate dayOfWeek ]) - 1).
control do:
[
theLine write:(theDate day; literal) &paddingLeft:3 &with:#$32.
theDate := theDate add &days:1.
]
&until:[$((theDate month != theMonth)or:[$(theDate dayOfWeek == 1]])).
].
int aLength := theLine length.
if (aLength < 21)
[ theLine write:" " &length:(21 - aLength). ].
theRow +=append int:1.
]
iteratorindexer = IteratorIndexer::
{
available = theRow < 7.
 
readIndexreadIndexTo &vint:anIndex [ anIndex setint := theRow. ]
 
writeset &index:anIndex
[
if (anIndex <= theRow)
[ $owner writeTitle. ].
while (anIndex > theRow)
[ $owner writeLine. ].
]
 
Line 898:
printTitleTo : anOutput
[
anOutput write:(MonthNames @(theMonth - 1)) &padding:21 &with:#$32.
]
Line 920:
printTo:anOutput
[
anOutput write:"[SNOOPY]" &padding:(theRowLength * 25) &with:#$32.
anOutput writeLine.
anOutput write:(theYear literal) &padding:(theRowLength * 25) &with:#$32.
anOutput writeLine; writeLine.
var aRowCount := 12 / theRowLength.
var Months := Array new &length:aRowCount; set &every:(&indexint:i)
[ ^ Array new &length:theRowLength; set &every:(&indexint:j)
[ ^ CalendarMonthPrinter new &year:(theYear int) &month:((i * theRowLength + j + 1) int) ]].
Months run &each: (:aRow)
[
aRow run &each: (:aMonth)
[
aMonth printTitleTo:anOutput.
anOutput write:" ".
].
anOutput writeLine.
ParallelEnumerator new:aRow; run &each: (:aLine)
[
aLine run &each: (:aPrinter)
[
aPrinter printTo:anOutput.
 
anOutput write:" ".
].
anOutput writeLine.
].
].
]
}
 
program =
[
var aCalender := Calendar new:(console write:"ENTER THE YEAR:"; readLinereadLineTo:(Integer new)).
aCalender printTo:console.
Anonymous user