Recurring Dates Script
Sarah Reichelt
sarahr at genesearch.com.au
Sun Jan 18 20:44:21 EST 2004
Hi Jim,
Coincidentally, I needed exactly the same sort of thing myself last
week, so here is a script to get you started:
Here are some usage examples:
put relativeDate("Mon", 3, 1, 2004)
-- 3rd Monday in January 2004
put relativeDate("Fri", -1, 2, 2004)
-- last Friday in February 2004
put relativeDate("Tue", "First", 11, 2004)
-- 1st Tuesday in November - for the Aussies out there :-)
-- pDay is the abbreviated system day name (Mon, Tue, Wed)
-- pIndex is First, Second, Third, Fourth, Last
-- or 1, 2, 3, 4 for 1st, 2nd, 3rd & 4th and -1 for last
-- pMonth & pYear must be numeric
--
function relativeDate pDay, pIndex, pMonth, pYear
-- convert the day name to a number
put the abbrev system weekDayNames into tDayList
get lineOffset(pDay, tDayList)
if it = 0 then return empty
put it into tDayNum
-- find first whatever day in the month
put pMonth & "/1/" & pYear into firstDate
convert firstDate from short English date to dateItems
put last item of firstDate into firstDayNum
put tDayNum - firstDayNum into dayDiff
if dayDiff < 0 then add 7 to dayDiff
add dayDiff to item 3 of firstDate
convert firstDate to seconds
convert firstDate to dateItems
-- add weeks as necessary
switch pIndex
case "First"
case "1"
break
case "Second"
case "2"
add 7 to item 3 of firstDate
break
case "Third"
case "3"
add 14 to item 3 of firstDate
break
case "Fourth"
case "4"
add 21 to item 3 of firstDate
break
case "Fifth"
case "5"
add 28 to item 3 of firstDate
break
case "Last"
case "-1"
-- try week 5 and if that doesn't work, use week 4
put firstDate into testDate
add 28 to item 3 of testDate
convert testDate to seconds
convert testDate to dateItems
if item 2 of testDate = pMonth then
put testDate into firstDate
else
add 21 to item 3 of firstDate
end if
break
end switch
-- firstDate is now in dateItems format
convert firstDate to short system date
return firstDate
end relativeDate
Cheers,
Sarah
sarahr at genesearch.com.au
http://www.troz.net/Rev/
On 12 Jan 2004, at 1:04 pm, Jim Carwardine wrote:
> Thanks, Sarah. I'm familiar with dateItems from HC. Even with
> dateItems,
> checking on things like the second Tuesday of every month is tricky.
> I was
> hoping that somebody might have done some of that... Jim
>
> on 1/11/04 6:21 PM, Sarah Reichelt wrote:
>
>> Hi Jim,
>>
>> I don't know exactly what sort of recurring dates you are planning,
>> but
>> you will find that using the dateItems format works really well for
>> date calculations:
>>
>> Try something like this:
>> put the seconds into theDate
>> convert theDate to dateItems
>> -- 2004,1,12,8,16,46,2
>> -- see the docs for dateItems to check what each item is.
>>
>> Now you can edit any of these items WITHOUT having to worry about
>> whether it results in a correct date. When you convert it back, the
>> engine will make it into a real date.
>>
>> add 18 to item 2 of theDate -- item 2 = month, so move 18 months
>> forward
>> -- 2004,19,12,8,18,26,2
>> convert theDate to long date
>> -- Tuesday, July 12, 2005
>>
>> Hope this helps,
>> Sarah
>>
>> On 12 Jan 2004, at 1:59 am, Jim Carwardine wrote:
>>
>>> Has anyone written a script that handles recurring dates like Outlook
>>> or
>>> Entourage do? Jim
>>> --
>>>
>>> OYF is... Highly resourceful people working together.
>>> <http://www.OwnYourFuture-net.com>
>>>
>>> Own Your Future Consulting Services Limited,
>>> 1959 Upper Water Street, Suite 407, Halifax, Nova Scotia. B3J 3N2
>>> Info Line: 902-823-2477, Phone: 902-823-2339. Fax: 902-823-2139
>>>
>>>
>>>
>>>
>>> _______________________________________________
>>> use-revolution mailing list
>>> use-revolution at lists.runrev.com
>>> http://lists.runrev.com/mailman/listinfo/use-revolution
>>>
>>>
>>>
>>
>> _______________________________________________
>> use-revolution mailing list
>> use-revolution at lists.runrev.com
>> http://lists.runrev.com/mailman/listinfo/use-revolution
>
> --
>
> OYF is... Highly resourceful people working together.
> <http://www.OwnYourFuture-net.com>
>
> Own Your Future Consulting Services Limited,
> 1959 Upper Water Street, Suite 407, Halifax, Nova Scotia. B3J 3N2
> Info Line: 902-823-2477, Phone: 902-823-2339. Fax: 902-823-2139
>
>
>
> _______________________________________________
> use-revolution mailing list
> use-revolution at lists.runrev.com
> http://lists.runrev.com/mailman/listinfo/use-revolution
>
>
>
More information about the use-livecode
mailing list