REXXTAGS.org :: | Samples: Sample calendar tag, 1 |
Home Samples
File: rexxtags.cal1.tag [download
(.tag file, 6 KB)]
Author: José María
Blasco<jm@jmblasco.com>
Contributed on: 2003-05-28
Description: This REXX tag is used in page
5 of the REXXTAGS tutorial and generates a calendar
for the current month.
Example: Here's the XML code:
1:<rexxtags:cal1/>
2:
and here's the generated output:
|
Mo | Tu | We | Th | Fr | Sa | Su |
|
|
|
|
|
|
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 |
|
|
|
|
|
Program code:
1:/* <rexxtags:cal1>: a simple calendar tag for the REXXTAGS tutorial, v 1 */
2:/* */
3:/* Parameters: */
4:/* (none) */
5:/* */
6:/* Version: 1.0 */
7:/* */
8:/* Author: (c) Jose Maria Blasco <jm@jmblasco.com> */
9:/* */
10:/* This software is subject to the terms of the Common Public License. You */
11:/* must accept the terms of this license to use this software. Refer to */
12:/* the license at the following URL for more information: */
13:/* http://oss.software.ibm.com/developerworks/opensource/CPLv1.0.htm */
14:/* */
15:/* Description: Please refer to the REXXTAGS tutorial, page 5 */
16:/* (http://www.rexxtags.org/tutorial/page05.html) for details */
17:/* */
18:/* Modifications: */
19:/* */
20:/* Date Author Description */
21:/* ---------- ----------- --------------------------------------------------- */
22:/* 2003/05/28 J.M.Blasco v1.0 Initial release */
23:
24:Parse arg verb
25:
26: If verb = 'START' Then Signal StartTag
27: If verb = 'END' Then Return ''
28:
29:Return 0
30:
31:StartTag:
32:
33: Parse value date('u') with m2'/'.'/'a2 /* Get the date in mm/dd/yy */
34:
35: m = m2 + 0 /* Normalize month number */
36: a = a2 + 2000 /* Normalize year */
37:
38: /* Month names */
39: m.1 = "January"; m.2 = "February"; m.3 = "March"; m.4 = "April"
40: m.5 = "May"; m.6 = "June"; m.7 = "July"; m.8 = "August"
41: m.9 = "September"; m.10 = "October"; m.11 = "November"; m.12 = "December"
42:
43: /* Day abbrevs */
44: d.1 = 'Mo'; d.2 = 'Tu'; d.3 = 'We'; d.4 = 'Th'; d.5 = 'Fr'; d.6 = 'Sa'; d.7 = 'Su'
45:
46: nl = '00'x /* Newline is '00'x */
47:
48: r = '' /* 'r' will hold the result */
49:
50: day1 = DayOfWeekOfDay1(m'/1/'a)
51: maxday = LastDayInMonth(m'/1/'a)
52:
53: r = r||nl'<table border="0" cellspacing="1" cellpadding="0" align="center">'
54:
55: /* We now produce a header with the month name and year */
56:
57: r = r||nl||'<tr>'
58: r = r||nl|| '<td colspan="7" bgcolor="#9999ff">'
59: r = r||nl|| '<table width="100%" border="0" cellspacing="0" cellpadding="0">'
60: r = r||nl|| '<tr>'
61: r = r||nl|| '<td><font color="#FFFFFF" size="2"><b> 'm.m'</b></font></td>'
62: r = r||nl|| '<td><div align="right"><font color="#FFFFFF" size="2"><b>'a' </b></font></div></td>'
63: r = r||nl|| '</tr>'
64: r = r||nl|| '</table>'
65: r = r||nl|| '</td>'
66: r = r||nl||'</tr>'
67:
68: /* Write the weekday header */
69:
70: r = r||nl||'<tr bgcolor="#999999">'
71: Do i = 1 to 7
72: r = r||'<td align="center"><font color="#ffffff">'d.i'</font></td>'
73: End
74: r = r||'</tr>'
75:
76: /* We now iterate over all days of the month */
77:
78: k = 0
79: day = 0
80: Do l = 1 to 6
81: r = r||nl||'<tr>'
82: Do d = 1 To 7
83: k = k + 1
84: If ((l == 1) & (d < day1)) | (day >= maxday) Then Do
85: If (d < 6) Then r = r||nl||'<td width="30" bgcolor="#eeeeee"> </td>'
86: Else r = r||nl||'<td width="30" bgcolor="#ffdddd"> </td>'
87: End
88: Else Do
89: day = day + 1
90: If (d > 5) Then r = r||nl||'<td width="30" bgcolor="#ffdddd" align="center"'
91: Else r = r||nl||'<td width="30" align="center" bgcolor="#eeeeee"'
92: r = r'><b><font color="#666666">'day'</font></b></td>'
93: End
94: End
95: r = r||nl||'</tr>'
96: End
97: r = r||nl||'</table>'
98:
99:Return r
100:
101:/* Calculates the day-of-week number of day 1 for a given month */
102:
103:DayOfWeekOfDay1: Procedure
104: Parse Arg mm'/'.'/'yy
105:Return (mmddyy2b(mm'/1/'yy) // 7) + 1
106:
107:LastDayInMonth: Procedure
108: Parse Arg mm'/'.'/'yy
109: mm = mm + 1
110: If mm > 12 Then Do
111: yy = yy + 1
112: mm = 1
113: End
114: Parse Value b2mmddyy(mmddyy2b(mm'/1/'yy)-1) With '/' lastday '/'
115:Return lastday
116:
117:/* The two following routines are from Rex Swain, www.rexswain.com */
118:
119:B2MMDDYY: Procedure
120: Parse Arg rd
121: z = rd + 307
122: h = 100*z - 25
123: a = h % 3652425
124: b = a - a%4
125: year = (100*b + h) % 36525
126: c = b + z - 365*year - year%4
127: month = (5*c + 456) % 153
128: day = c - Word('0 31 61 92 122 153 184 214 245 275 306 337',month-2)
129: If month > 12 Then Do
130: year = year + 1
131: month = month - 12
132: End
133: If Length(year) < 4 Then year = Right(year,4,'0')
134:Return Right(month,2,'0') || '/' || Right(day,2,'0') || '/' || year
135:
136:MMDDYY2B: Procedure
137: Parse Arg args
138: args = Translate(args,' ','/-')
139: Parse Var args m d y
140: If 2 = Length(Strip(y)) Then y = y + 100 * (Date('S') % 1000000)
141: z = y + (m-14) % 12
142: f = Word('306 337 0 31 61 92 122 153 184 214 245 275',m)
143:Return d + f + 365*z + z%4 - z%100 + z%400 - 307
144:
/samples/rexxtags.cal1.html
Last update: 29/05/03 at 11:54
|
|
|