Squeak
  links to this page:    
View this PageEdit this PageUploads to this PageHistory of this PageTop of the SwikiRecent ChangesSearch the SwikiHelp Guide
CalendarTable
Last updated at 4:24 pm UTC on 17 January 2006
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: '<table border=1>'; cr. curDay _ from copy. "Write headers" res nextPutAll: '<tr>'. dayArray do: [:d | res nextPutAll: '<th>',d printString,'</th>'.]. res nextPutAll: '</tr>'. "Write date cells" [curDay <= toDate] whileTrue: [(day _ dayArray indexOf: (curDay weekday)) > 0 ifTrue: [(day = 1) ifTrue: [res nextPutAll: '<tr>'.]. res nextPutAll: '<td>',curDay printString,': </td>'. (day = dayArray size) ifTrue: [res nextPutAll: '</tr>';cr]. ]. curDay _ curDay addDays: 1.]. res nextPutAll: '</table>'. ^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: '<table border=1>'; cr. curDay _ from copy. "Write headers" res nextPutAll: '<tr>'. dayArray do: [:d | res nextPutAll: '<th>',d printString,''.]. res nextPutAll: '</tr>';cr. "Write date cells" "Generally want to start a new row, but position of first cell is a problem not addressed here." res nextPutAll: '<tr>'. [curDay <= toDate] whileTrue: [(day _ dayArray indexOf: (curDay weekday)) > 0 ifTrue: [(day = 1) ifTrue: [res nextPutAll: '<tr>'.]. res nextPutAll: '<td>',curDay printString,': '. (day = dayArray size) ifTrue: [res nextPutAll: '</tr>';cr]. ]. curDay _ curDay addDays: 1.]. res nextPutAll: '</table>';cr. ^res contents ! !