an annual calendar somewhere? (done)
Andre.Bisseret
Andre.Bisseret at inria.fr
Tue Mar 2 10:10:40 EST 2010
Bonjour,
Thanks a lot to Robert, Zrypt, Richard, Bernd who provided very
helpful material and the others who chimed in helping to push along :-)
I have now an annual calendar with 12 lines, one for each month.
The days of weeks are in a separate field at the top of the display
(not repeated for each month)
The months are also in a separate field on the left of the main field
which displays the day numbers.
The year is in a separate field too at the top left.
So it is easy to select any range of days either from a single month
or across two (or more) months.
Oh! happy day ;-))
Best regards from Grenoble
André
---- the script -------
-- 03/2010
-- first script from Richard Gaskin, completed and improved by Zryip
theSlug. (comments are from them)
-- I only adapted it to my needs (months in lines instead of tables;
several fields instead of a single one)
on mouseUp
set useSystemDate to true
put empty into fld "calendar field"
put empty into fld "chMonths"
put empty into fld "weekDayNames"
createLineOfDays
ask "Quelle année ?" with last word of the abbrev system date
put it into yearToMake
put yearToMake into fld "theYear"
put createDate(yearToMake,1,1) into tStartDate -- Create the
January, 1 2010 in your local language system
repeat with tMonthNumber = 0 to 11 -- Create months for January
(1) to December (12)
put Cal(addToDate(tStartDate,0,tMonthNumber,0),"Monday") & cr
after fld "calendar field"
end repeat
end mouseUp
on createLineOfDays --to be put in a separate field at the top
-- Make day names header: -- in AWEEK
put "Monday" into pFirstDayWeek
put weekdayNamesList(pFirstDayWeek) into tWeekdayNames
put empty into aWeek
put empty into fourWeeks
repeat for each line tDay in tWeekdayNames
put char 1 to 2 of tDay &" " after aWeek --after tCal
end repeat
-- Make 5 weeks + lu ma
repeat 5
put aWeek & tab after fourWeeks
end repeat
put fourWeeks & "lu ma" into fld "weekDayNames"
end createLineOfDays
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
--put tHeader & cr after fld "chMonths"
put tMonth & cr after fld "chMonths" -- in an extra field on the
left
--
-- Pad beginning with empty days:
put createDate(tYear,tMonthNumber,1) into tStartDay
convert tStartDay to dateitems
get last item of tStartDay
if (pFirstDayWeek is "Monday") then
if (it = 1) then
put 6 into tPad -- fix the case that the day is Sunday
(value1) - 2 = - 1
else
put (it - 2) into tPad
end if
else
put (it - 1) into tPad
end if
repeat for tPad
put " " after tCal
end repeat
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
tab after tCal --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
More information about the use-livecode
mailing list