an annual calendar somewhere?

Richard Gaskin ambassador at fourthworld.com
Fri Feb 26 08:21:50 CST 2010


FWIW, here's a a function I pulled out of my archives which is a sort of 
variant of Cal in native RevTalk, making a single month from a date 
passed to it.  I'll leave it as an exercise to the user to make a year 
out of it if needed.

One of the nice things about RevTalk is that the weekDayNames and 
monthNames functions return values in the current system's local 
language, so this is localized without having to do anything.

Interestingly, without the overhead involved in going to shell it's 
about 20 times faster on my machine than calling shell("cal").


function Cal pDate
   -- Returns a plain-text calendar representation of
   -- the month the date specified in pDate is in.
   -- If no month is provided it uses the current
   -- month. Month and day names use the user's current
   -- system settings.
   --
   -- Use current date as default:
   if pDate is empty then put the date into pDate
   -- Verify date is valid:
   convert pDate to dateitems
   if the result is not empty then return "Error: "& the result
   --
   put empty into tCal
   --
   -- Make month/year header:
   put item 1 of pDate into tYear
   put line (item 2 of pDate) of the monthNames into tMonth
   put tMonth && tYear into tHeader
   -- Center it:
   repeat for ( (20 - len(tHeader)) div 2)
     put " " after tCal
   end repeat
   put tHeader &cr after tCal
   --
   -- Make day names header:
   put the abbr weekdayNames into tWeekdayNames
   repeat for each line tDay in tWeekdayNames
     put char 1 to 2 of tDay &" " after tCal
   end repeat
   put cr after tCal
   --
   -- Pad beginning with empty days:
   put tMonth && "1"&& tYear into tStartDay
   convert tStartDay to dateitems
   repeat for (last item of tStartDay - 1)
     put "   " after tCal
   end repeat
   --
   -- Walk through 31 days, stopping when we reach a
   -- number not valid for the month we're doing:
   repeat with i = 1 to 31
     -- Get day number:
     put tMonth &&i&& tYear into tDate
     convert tDate to dateitems
     if the result is not empty then exit repeat
     put item 3 of tDate into tDayNum
     --
     -- Pad it and add it:
     if len(i) = 1 then put " " before i
     put i &" " after tCal
     --
     -- Go to next line if we're at the end of the week:
     if last item of tDate = 7 then put cr after tCal
   end repeat
   --
   -- Pad empty lines at end for uniform appearance
   -- when using multiple calendars in a field:
   repeat for (8-the number of lines of tCal)
     put cr after tCal
   end repeat
   --
   -- Send it to the caller:
   return tCal
end Cal



--
  Richard Gaskin
  Fourth World
  Rev training and consulting: http://www.fourthworld.com
  Webzine for Rev developers: http://www.revjournal.com
  revJournal blog: http://revjournal.com/blog.irv



More information about the use-livecode mailing list