an annual calendar somewhere?

Andre.Bisseret Andre.Bisseret at inria.fr
Sat Feb 27 11:05:23 CST 2010


Bonjour Zryip,

Starting from your very nice script, I am modifying it so that I  
obtain one month per line.
I managed to get the days of weeks repeated five times separated by  
tab in the first line of the field (with tab stops in it)
  I suppressed carriage returns and I added "tab" between weeks.
Not too difficult up to now :-)
Not completed yet (currently I am getting one month nearly as I  
expected.

While doing trials, I just noticed that, when pFirstDayWeek is  
"Monday", if the first day of a month is actually "sunday" then there  
is a flaw: the "1" is set up under "monday" instead of "sunday" while  
"2" is at its right place (second line).

I got that for example when trying "1/0810" (August 2010)

This does not happen with pFirstDayWeek = "Sunday" (I tried for months  
beginning a saturday).

I must confess that I did not study your script deeply
(I just made few local modifications to quicky obtain a month with an  
aligned format instead of a table.

So you likely will see faster than me how to fix that issue ;-))

Anyway, thanks a lot for your improvement of the Richard'script; I  
particularly appreciate the possibililty to choose between Sunday and  
Monday as the first day of week. Thanks to your script I am sure I  
will get the format I am expecting.

Best regards from Grenoble

André




Le 27 févr. 10 à 01:12, zryip theSlug a écrit :

> 2010/2/26 Richard Gaskin <ambassador at fourthworld.com>:
>> 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.
>
> I confess that I have missed these two valuables functions.
>
>> Interestingly, without the overhead involved in going to shell it's  
>> about 20
>> times faster on my machine than calling shell("cal").
>
> It's instant on my machine. So with your script I could back in  
> time? 8-)
>
>
> However as far I have understood it seems that the property
> useSystemDate set to true is necessary to obtain values according with
> the local language.
> Plus, a second difficulty exists: the week don't starts necessary a
> Sunday but a Monday.
>
> So I try to improve the Richard's solution like this:
>
> function Cal pDate, pFirstDayWeek
>   set useSystemDate to true
>    -- 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
>   if pFirstDayWeek is empty then put "Sunday" into pFirstDayWeek
>    -- 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 item 2 of pDate into tMonthNumber
>   put line (tMonthNumber) 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 weekdayNamesList(pFirstDayWeek) 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 createDate(tYear,tMonthNumber,1) into tStartDay -- create a
> date in the system's local language
>   convert tStartDay to dateitems
>   if (pFirstDayWeek is "Monday") then
>      repeat for (last item of tStartDay - 2)
>            put "   " after tCal
>       end repeat
>   else
>       repeat for (last item of tStartDay - 1)
>            put "   " after tCal
>       end repeat
>   end if
>
>   put createDate(tYear,tMonthNumber,1) into tStartDay -- create a
> date in the system's local language
>
>    -- Walk through 31 days, stopping when we reach a
>    -- number not valid for the month we're doing:
>
>    repeat with i = 1 to dayOf(addToDate(tStartDay,0,1,-1))
>         -- the end value is the number of days in the month. To
> obtain the last date of a month, add 1 month and subtract one
>         -- day to the first day of a month
>         -- Get day number:
>      put createDate(tYear,tMonthNumber,i) 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 = lastDayOfWeek(pFirstDayWeek) 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
>
> function weekdayNamesList pFirstDay
>   set useSystemDate to true
>   put the abbr weekdayNames into tWeekdayNames
>   if pFirstDay is "Monday" then
>      put cr&first line of tWeekdayNames after tWeekdayNames
>      delete first line of tWeekdayNames
>   end if
>   return tWeekdayNames
> end weekdayNamesList
>
> function lastDayOfWeek pFirstDay
>   if pFirstDay is "Monday" then
>      return 1
>   else
>      return 7
>   end if
> end lastDayOfWeek
>
> function firstDayInMonth pStartDate
>   -- Return the first day in a month
>   set useSystemDate to true
>   convert pStartDate to dateitems
>   put 1 into item 3 of pStartDate
>   convert pStartDate to short date
>   return pStartDate
> end firstDayInMonth
>
> function createDate pTheYear,pTheMonth,pTheDay
>   local tDateItems
>
>   set useSystemDate to true
>   put pTheYear,pTheMonth,pTheDay,0,0,0,0 into tDateItems
>   convert tDateItems from dateItems to short date
>   return tDateItems
> end createDate
>
> function addToDate pStartDate,pAddToYear,pAddToMonth,pAddToDay
>   -- Allows you to manipulate a date in a single pass
>   set useSystemDate to true
>   convert pStartDate to dateitems
>   add pAddToYear to item 1 of pStartDate
>   add pAddToMonth to item 2 of pStartDate
>   add pAddToDay to item 3 of pStartDate
>   convert pStartDate to short date
>   return pStartDate
> end addToDate
>
> function dayOf pStartDate
>   set useSystemDate to true
>   convert pStartDate to dateitems
>   return item 3 of pStartDate
> end dayOf
>
>
> If some members of the list could validate this script in their own
> language? 8-)
>
>
> -> If your weeks starts a Monday call the function like this:
>
> set useSystemDate to true
> put cal(the date,"Monday") into fld "myField"
>
> -> If your weeks starts a Sunday simply use:
>
> set useSystemDate to true
> put cal() into fld "myField"
>
>
> Regards,
> -- 
> -Zryip TheSlug- wish you the best! 8)
> http://www.aslugontheroad.co.cc
> _______________________________________________
> use-revolution mailing list
> use-revolution at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your  
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-revolution






More information about the use-livecode mailing list