Calendar - for "REAL" programmers: Difference between revisions

Line 497:
#define extensions'math.
#define extensions'routines.
 
// --- calendar ---
 
#symbol MonthNames = ("JANUARY","FEBRUARY","MARCH","APRIL","MAY","JUNE","JULY","AUGUST","SEPTEMBER","OCTOBER","NOVEMBER","DECEMBER").
Line 523 ⟶ 521:
theRow << 0.
theDate := Date new &year:(theYear int) &month:(theMonth int) &day:1.
controlDayNames run:DayNames &forEacheach: aName
[ theLine writewriteLiteral:" " write:aName ].
]
Line 533 ⟶ 531:
(theDate month == theMonth)
? [
theLine::stringOp write:" " &length:(((theDate dayOfWeek) => 0 ? [ 7 ] ! [ theDate dayOfWeek ]) subtract:- 1 int).
control do:
[
theLine::stringOp write:(theDate day literal) &paddingLeft:3 &with:" "#32.
theDate := theDate add &days:1.
Line 546 ⟶ 544:
#var(type:int) aLength := theLine length.
(aLength < 21)
? [ theLine::stringOp write:" " &length:(21 - aLength). ].
theRow += 1.
Line 555 ⟶ 553:
available = theRow < 7.
 
readreadIndex &out'indexvint:anIndex [ anIndex :=<< theRow int. ]
 
write &index:anIndex
Line 571 ⟶ 569:
#method printTitleTo : anOutput
[
anOutput::stringOp write:(MonthNames @(theMonth - 1)) &padding:21 &with:" "#32.
]
Line 593 ⟶ 591:
#method printTo:anOutput
[
anOutput::stringOp write:"[SNOOPY]" &padding:(theRowLength * 25) &with:" "#32.
anOutput writeLine.
anOutput::stringOp write:(theYear literal) &padding:(theRowLength * 25) &with:" "#32.
anOutput writeLine writeLine.
#var(type:int) aRowCount := 12 / theRowLength.
#var Months := MatrixArray new &nlength:aRowCount set &mevery:theRowLength (&every_ijindex: i)
(&index:i &index:j) [ CalendarMonthPrinterArray new &yearlength:(theYeartheRowLength int)set &monthevery:((i * theRowLength + &index:j + 1) int) ].
[ CalendarMonthPrinter new &year:(theYear int) &month:((i * theRowLength + j + 1) int) ]].
 
controlMonths run:Months &forEacheach: aRow
[
controlaRow run:aRow &forEacheach: aMonth
[
aMonth printTitleTo:anOutput.
Line 613 ⟶ 612:
anOutput writeLine.
control run:(ParallelEnumerator new:aRow) run &forEacheach: aLine
[
controlaLine run:aLine &forEacheach: aPrinter
[
aPrinter printTo:anOutput.
Line 630 ⟶ 629:
#symbol program =
[
#var aCalender := Calendar new:(consoleExconsole write:"ENTER THE YEAR:" readLine:(Integer new)).
aCalender printTo:consoleExconsole.
consoleExconsole readChar.
].</lang>
{{out}}
<pre>
ENTER THE YEAR:1969
[SNOOPY]
1969
 
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
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
30
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
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
</pre>
 
=={{header|Fortran}}==
Anonymous user