Calendar - for "REAL" programmers: Difference between revisions

(Initial entry for PL/I)
Line 288:
 
<lang guiss>RIGHTCLICK:CLOCK,ADJUST DATE AND TIME,BUTTON:CANCEL</lang>
 
=={header|Elena}==
 
<lang elena>#define system.
#define system'text.
#define system'routines.
#define system'calendar.
#define extensions.
#define extensions'math.
#define extensions'routines.
 
#symbol MonthNames = ("JANUARY","FEBRUARY","MARCH","APRIL","MAY","JUNE","JULY","AUGUST","SEPTEMBER","OCTOBER","NOVEMBER","DECEMBER").
#symbol DayNames = ("MO", "TU", "WE", "TH", "FR", "SA", "SU").
 
#class CalendarMonthPrinter
{
#field theDate.
#field theLine.
#field theMonth.
#field theYear.
#field theRow.
#constructor new &Year:aYear &Month:aMonth
[
theMonth := aMonth.
theYear := aYear.
theLine := TextBuffer new.
theRow := Integer new.
]
#method firstLine : aDay
[
theRow << 0.
theDate := Date new &Year:theYear &Month:theMonth &Day:aDay.
control foreach:DayNames &do: aName
[ theLine write:" " write:aName ].
]
#method nextLine
[
theLine clear.
(theDate Month == theMonth)
? [
theLine~textOp write:" " &length:(((theDate DayOfWeek) => 0 ? [ 7 ] ! [ theDate DayOfWeek ]) - 1).
control do:
[
theLine~textOp write:(theDate Day) &paddingLeft:3 &with:" ".
theDate := theDate add &Days:1.
]
&until:[(theDate Month != theMonth)or:[theDate DayOfWeek == 1]].
].
#var aLength := theLine length.
(aLength < 21)
? [ theLine~textOp write:" " &length:(21 - aLength). ].
theRow += 1.
^ theRow < 7.
]
#method enumerator =
{
set &index:anIndex [ self firstLine:(anIndex + 1) ]
next [ ^ self nextLine. ]
get = self.
}.
#method printTitleTo : anOutput
[
anOutput~textOp write:(MonthNames @(theMonth - 1)) &padding:21 &with:" ".
]
#method printTo : anOutput
[
anOutput write:(theLine literal).
]
}
 
#class Calendar
{
#field theYear.
#field theRowLength.
#constructor new : aYear
[
theYear := aYear int.
theRowLength := 3.
]
#method printTo:anOutput
[
anOutput~textOp write:"[SNOOPY]" &padding:(theRowLength * 25) &with:" " writeLine.
anOutput~textOp write:theYear &padding:(theRowLength * 25) &with:" " writeLine writeLine.
#var aRowCount := 12 / theRowLength.
#var Months := matrixControl new &m:aRowCount &n:theRowLength &each: (:i:j) [ CalendarMonthPrinter new &Year:theYear &Month:(i * theRowLength + j + 1) ].
control foreach:Months &do: aRow
[
control foreach:aRow &do: aMonth
[
aMonth printTitleTo:anOutput.
anOutput write:" ".
].
anOutput writeLine.
controlEx for:(ParallelEnumerator new:aRow) &do: aLine
[
control foreach:aLine &do: aPrinter
[
aPrinter printTo:anOutput.
anOutput write:" ".
].
anOutput writeLine.
].
].
]
}
 
#symbol program =
[
#var aCalender := Calendar new:1969.
aCalender printTo:console.
].
</lang>
 
=={{header|Icon}} and {{header|Unicon}}==
Anonymous user