=== Top of the Swiki === Attachments ===

CalendarTable

I needed to generate a calendar in the form of a table for my class
schedule, so I created the below. In case it's useful to anyone.

Mark

'From Squeak 2.2beta of Sept 16, 1998 on 22 September 1998 at 2:36:52 pm'!

HTMLformatter class methodsFor: 'formatting' stamp: 'mjg 9/22/1998 14:36'!

dateTable: from to: toDate withDays: dayArray
"Return an HTML table of dates between the given dates.
HTMLformatter dateTable: (Date today) to: (Date readFrom: (ReadStream on:
'12/4/98')) withDays: #(Tuesday Wednesday Thursday)"

| curDay day res |
res _ WriteStream on: String new.
res nextPutAll: ''; cr.
curDay _ from copy.
"Write headers"
res nextPutAll: ''.
dayArray do: [:d |
res nextPutAll: ''.].
res nextPutAll: ''.
"Write date cells"
[curDay = toDate] whileTrue:
[(day _ dayArray indexOf: (curDay weekday)) > 0
ifTrue: [(day = 1) ifTrue: [res nextPutAll: ''.].
res nextPutAll: ''.
(day = dayArray size) ifTrue: [res
nextPutAll: '';cr].
].
curDay _ curDay addDays: 1.].
res nextPutAll: '
',d printString,'
',curDay
printString,':
'.
^res contents
! !


Dan Shafer Tweaks 10/10/98

I know this isn't designed to be a full-blown calendar table, but I had some fun poking around in it and in the process cleaned up the HTML formatting just a bit, so I figured I'd share the results. (Note that there's some kind of formatting problem near the end of this fileOut. I don't understand it yet but don't try to just file this code in.)

'From Squeak 2.2 of Sept 23, 1998 on 10 October 1998 at 4:27:46 pm'!

HTMLformatter class methodsFor: 'formatting' stamp: 'DGS 10/10/1998 16:17'!

dateTable: from to: toDate withDays: dayArray
"Return an HTML table of dates between the given dates.
HTMLformatter dateTable: (Date today) to: (Date readFrom: (ReadStream on:
'12/4/98')) withDays: #(Tuesday Wednesday Thursday)"

curDay day res
res _ WriteStream on: String new.
res nextPutAll: ''; cr.
curDay _ from copy.
"Write headers"
res nextPutAll: ''.
dayArray do: [:d |
res nextPutAll: '';cr.
"Write date cells"
"Generally want to start a new row, but position of first cell is a problem not addressed here."
res nextPutAll: ''.
[curDay <= toDate] whileTrue: [(day _ dayArray indexOf: (curDay weekday)) > 0
ifTrue: [(day = 1) ifTrue: [res nextPutAll: ''.].
res nextPutAll: '';cr].
].
curDay _ curDay addDays: 1.].
res nextPutAll: '
',d printString,''.].
res nextPutAll: '
',curDay
printString,': '.
(day = dayArray size) ifTrue: [res
nextPutAll: '
';cr.
^res contents

!