/* : a simple calendar tag for the REXXTAGS tutorial, v 1 */ /* */ /* Parameters: */ /* (none) */ /* */ /* Version: 1.0 */ /* */ /* Author: (c) Jose Maria Blasco */ /* */ /* This software is subject to the terms of the Common Public License. You */ /* must accept the terms of this license to use this software. Refer to */ /* the license at the following URL for more information: */ /* http://oss.software.ibm.com/developerworks/opensource/CPLv1.0.htm */ /* */ /* Description: Please refer to the REXXTAGS tutorial, page 5 */ /* (http://www.rexxtags.org/tutorial/page05.html) for details */ /* */ /* Modifications: */ /* */ /* Date Author Description */ /* ---------- ----------- --------------------------------------------------- */ /* 2003/05/28 J.M.Blasco v1.0 Initial release */ Parse arg verb If verb = 'START' Then Signal StartTag If verb = 'END' Then Return '' Return 0 StartTag: Parse value date('u') with m2'/'.'/'a2 /* Get the date in mm/dd/yy */ m = m2 + 0 /* Normalize month number */ a = a2 + 2000 /* Normalize year */ /* Month names */ m.1 = "January"; m.2 = "February"; m.3 = "March"; m.4 = "April" m.5 = "May"; m.6 = "June"; m.7 = "July"; m.8 = "August" m.9 = "September"; m.10 = "October"; m.11 = "November"; m.12 = "December" /* Day abbrevs */ d.1 = 'Mo'; d.2 = 'Tu'; d.3 = 'We'; d.4 = 'Th'; d.5 = 'Fr'; d.6 = 'Sa'; d.7 = 'Su' nl = '00'x /* Newline is '00'x */ r = '' /* 'r' will hold the result */ day1 = DayOfWeekOfDay1(m'/1/'a) maxday = LastDayInMonth(m'/1/'a) r = r||nl'' /* We now produce a header with the month name and year */ r = r||nl||'' r = r||nl|| '' r = r||nl||'' /* Write the weekday header */ r = r||nl||'' Do i = 1 to 7 r = r||'' End r = r||'' /* We now iterate over all days of the month */ k = 0 day = 0 Do l = 1 to 6 r = r||nl||'' Do d = 1 To 7 k = k + 1 If ((l == 1) & (d < day1)) | (day >= maxday) Then Do If (d < 6) Then r = r||nl||'' Else r = r||nl||'' End Else Do day = day + 1 If (d > 5) Then r = r||nl||'' End End r = r||nl||'' End r = r||nl||'
' r = r||nl|| '' r = r||nl|| '' r = r||nl|| '' r = r||nl|| '' r = r||nl|| '' r = r||nl|| '
  'm.m'
'a'  
' r = r||nl|| '
'd.i'
  'day'
' Return r /* Calculates the day-of-week number of day 1 for a given month */ DayOfWeekOfDay1: Procedure Parse Arg mm'/'.'/'yy Return (mmddyy2b(mm'/1/'yy) // 7) + 1 LastDayInMonth: Procedure Parse Arg mm'/'.'/'yy mm = mm + 1 If mm > 12 Then Do yy = yy + 1 mm = 1 End Parse Value b2mmddyy(mmddyy2b(mm'/1/'yy)-1) With '/' lastday '/' Return lastday /* The two following routines are from Rex Swain, www.rexswain.com */ B2MMDDYY: Parse Arg rd z = rd + 307 h = 100*z - 25 a = h % 3652425 b = a - a%4 year = (100*b + h) % 36525 c = b + z - 365*year - year%4 month = (5*c + 456) % 153 day = c - word('0 31 61 92 122 153 184 214 245 275 306 337',month-2) If month > 12 Then Do year = year + 1 month = month - 12 End If length(year) < 4 Then year = Right(year,4,'0') Return Right(month,2,'0') || '/' || Right(day,2,'0') || '/' || year MMDDYY2B: Procedure Parse Arg args args = Translate(args,' ','/-') Parse Var args m d y If 2 = Length(Strip(y)) Then y = y + 100 * (Date('S') % 1000000) z = y + (m-14) % 12 f = Word('306 337 0 31 61 92 122 153 184 214 245 275',m) Return d + f + 365*z + z%4 - z%100 + z%400 - 307