Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Helping iCal understand vCalendars' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Helping iCal understand vCalendars
Authored by: lx on Jan 29, '03 08:19:59AM
The hint I submitted suggests a way in which you can help Mail.app (1.2.3 v551) recognize and process a vCalendar request. It turns out that you will probably need to give iCal (1.0.2 v452) some help understanding the vCalendar standard which it does not seem to be well-versed in yet. iCal has two problems in replying to non-iCal vCalendar requests. First, it does not grok TZID's so any invite that doesn't specify times using built-in TZID's (like "US/Pacific") could end up at the wrong local time. Second, even when iCal gets a request using TZID's it understands, the RSVP dialog doesn't localize the time it indicates for the invitation (at least, that's what happens for me). I've attached some more AppleScript pieces that you can use with the script in the hint to help iCal get the time right.

To use this addition, add the lines:
--localize the calendar
if thisCal contains "BEGIN:VTIMEZONE" then ¬
set thisCal to my localized(thisCal)Add these lines just before the -- save vCalendar to file line. Also add the line:
property daylight : {startondate:date ¬
"Sunday, April 6, 2003 12:00:00 AM", ¬
endbeforedate:date "Sunday, October 26, 2003 12:00:00 AM"}
to the top of the script (if it is no longer 2003, you will need to update this line with the current daylight savings time interval).

Warning! The localization works for the vCalendar invites that I receive which all contain a single VTIMEZONE definition (with daylight and standard variations) for a single TZID. Your context may be different and the localization may not work. You will want to check that the "localized" time ends up in your iCal calendar correctly. As always, use at your own risk!
-- Handlers for Localization
on localized(theCal)
--choose daylight or standard variant
if (current date) >= startondate of daylight and ¬
(current date) < endbeforedate of daylight then
set theTZ to text from (offset of "BEGIN:DAYLIGHT" in theCal) to ¬
(offset of "END:DAYLIGHT" in theCal) of theCal
else
set theTZ to text from (offset of "BEGIN:STANDARD" in theCal) to ¬
(offset of "END:STANDARD" in theCal) of theCal
end if

--get time zone offset
set tzTag to "TZOFFSETTO:"
set tzStart to (offset of tzTag in theTZ) + (length of tzTag)
set theTimeShift to ((time to GMT) / 3600) ¬
- (text from tzStart to (tzStart + 2) of theTZ as number)

-- localize calendar
set newCal to ""
repeat with thisLine in paragraphs of theCal
set theOffset to the offset of "TZID=" in thisLine
if theOffset > 0 then
set theTime to decodeDT(text from character -15 to ¬
character -1 of thisLine)
set theTime to theTime + theTimeShift * hours
set thisLine to insert(thisLine, encodeDT(theTime), ¬
theOffset, length of thisLine)
end if
set newCal to newCal & thisLine & return
end repeat

return newCal
end localized

on insert(theString, theInsert, theStart, theEnd)
if (theStart - 1) >= 1 then
set theResult to text from character 1 ¬
to character (theStart - 1) of theString
else
set theResult to ""
end if

set theResult to theResult & theInsert

if theEnd <= length of theString then
set theResult to theResult ¬
& text from character theEnd to last character of theString
end if

return theResult
end insert

on decodeDT(theTimeString)
set theYear to text from character 1 to character 4 of theTimeString
set theMonth to text from character 5 to character 6 of theTimeString
set theDay to text from character 7 to character 8 of theTimeString
set theHours to text from character 10 to character 11 of theTimeString
set theMinutes to text from character 12 to character 13 of theTimeString
set theSeconds to text from character 14 to character 15 of theTimeString
return date (theMonth & "/" & theDay & "/" & theYear & ¬
", " & theHours & ":" & theMinutes & ":" & theSeconds)
end decodeDT

on encodeDT(theDate)
-- month number
set theMonth to 1
repeat until (month of theDate) is equal to item theMonth of ¬
{January, February, March, April, May, June, July, ¬
August, September, October, November, December}
set theMonth to theMonth + 1
end repeat

--time components
set theHours to (time of theDate) div 3600
set theMinutes to ((time of theDate) - theHours * 3600) div 60
set theSeconds to ((time of theDate) - theHours * 3600 - theMinutes * 60)

--vCal time encoding
return (year of theDate as text) ¬
& zeropadded(theMonth, 2) ¬
& zeropadded(day of theDate, 2) ¬
& "T" & zeropadded(theHours, 2) ¬
& zeropadded(theMinutes, 2) ¬
& zeropadded(theSeconds, 2)
end encodeDT

on zeropadded(theNumber, thePadding)
set theResult to theNumber as string
repeat while the length of theResult is ¬
less than thePadding
set theResult to "0" & theResult
end repeat
return theResult
end zeropadded
As before, my hope is that you will not need these hacks for very long.

[ Reply to This | # ]
Helping iCal understand vCalendars
Authored by: raydeeoh on Jun 18, '03 08:48:56PM

Where exactly do you insert this Time Zone script? Thanks!



[ Reply to This | # ]