REXXTAGS.org :: Tutorial - 5: Writing a simple calendar tag
Home Tutorial << Prev

Let's try to write a tag which is more complicated (and useful) than in the preceding sections. We will learn of to write a tag which creates calendars. For example, here's a calendar for the current month:

  January
2017  
MoTuWeThFrSaSu
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31          

Here's the code used to create the calendar:

  1: <rexxtags:cal1/>


We'll need to write a rexxtags.cal1.tag tag procedure (we call it 'cal1' because we'll build more sophisticated versions of this tag later). The tag doesn't need any parameter, and we only need to produce output for the start tag call. The main routine will thus be:

  1:Parse arg verb
  2:
  3:  If verb = 'START' Then Signal StartTag
  4:  If verb = 'END' Then Return ''
  5:
  6:Return 0
  7:


and we'll put all the code in 'StartTag'. If we want our tag to work properly in most versions of Rexx (including old versions of OS/2 Warp 3.0 and 4.0 or WSeB without fixpacks), we can't count on having date arithmetic built-in. We'll use Rex Swain's B2MMDDYY and MMDDYY2B and copy them into the code for our tag.

Next we'll need a routine to calculate what's the weekday for day 1 of a given month:

  1:DayOfWeekOfDay1: Procedure
  2:  Parse Arg mm'/'.'/'yy
  3:Return (mmddyy2b(mm'/1/'yy) // 7) + 1
  4:


And another one to calculate what's the last day in the month:

  1:LastDayInMonth: Procedure
  2:  Parse Arg mm'/'.'/'yy
  3:  mm = mm + 1
  4:  If mm > 12 Then Do
  5:    yy = yy + 1
  6:    mm = 1
  7:  End
  8:  Parse Value b2mmddyy(mmddyy2b(mm'/1/'yy)-1) With '/' lastday '/'
  9:Return lastday
 10:


Now the 'StartTag' part is standard REXX. You can find the tag code in the samples section.

  View the XML code for this page

/tutorial/page05.html
Last update: 29/05/03 at 11:59
 Comments
Valid XHTML 1.0! Valid CSS!