May 16, 2006, 1:26 p.m.

iCal does not like Outlook in South Africa

I had this problem since long ago when I started using Mac OS X 10.2 - iCal imports .ics files from Outlook just fine - however the entry always gets saved with the wrong time. In specific - it is always moved out by 2 hours. Needless to say this can be detrimental to punctuality. Here is how I fixed the issue...

The first attempt was to google for the issue. However it seemed that I was the only one in the world with this particular problem. Cul de sac.

So I started investigating myself. The fact that the appointments are out by exactly 2 hours implied to me it has something to do with timezone issues, since in South Africa we are at GMT+0200 - also known as SAST. So I opened up the .ics file in TextWrangler and started analyzing it.

The relevant line was this one:

DTSTART;TZID="(GMT+02.00) Harare/Pretoria":20060515T120000

Reading up on the ICS Specification, I recognised the time format to mean "FORM #3: DATE WITH LOCAL TIME AND TIME ZONE REFERENCE". Which means that date and time in the example above implies 15 May 2006 at 12:00 noon SAST (South African Standard Time). However iCal imported it as 14:00 SAST.

Now I started playing around. My time zone in Mac OS X is set to "Africa/Johannesburg". In principle that should not make a difference since it is the same as "Harare/Pretoria". However I decided to test something - I changed "(GMT+02.00) Harare/Pretoria" to "Africa/Johannesburg" and reimported it. Voila - it imported just fine and with the correct time.

I have no authoritative answer on this, but my guess is that iCal does not understand the timezone "(GMT+02.00) Harare/Pretoria" since it is neither in GMT format nor in country format, therefore it defaults it to Africa/Abijan (which happens to be GMT). Thus the offset error.

Now to automate this... I need to have the least amount of inconvenience to get my .ics files into iCal and with the correct time.

I started playing with Automater and an AppleScript - however it is too much effort to copy the attachment out of, right click on it and select the automator action. So I created a new Folder on my desktop, enabled folder actions on it and attached this script to it:

property extension_list : {"ics"}

on adding folder items to this_folder after receiving input
    repeat with i in input
                    set text item delimiters to ":"
                    set fileNameOnly to last text item of (i as text)
                    set text item delimiters to ""
            on error
                    set text item delimiters to ""
            end try

            set the item_info to info for i
            if (the name extension of the item_info is not in the extension_list) then
            end if

            set fixedMacFileName to (":private:tmp:" & fileNameOnly & ".fixed.ics")
            set fileName to (quoted form of POSIX path of (i as string))
            set fixedFileName to (quoted form of POSIX path of fixedMacFileName)
            do shell script "sed -e 's@(GMT+02.00) Harare/Pretoria@Africa/Johannesburg@g' " & fileName & " > " & fixedFileName

            tell application "iCal"
                    open file fixedMacFileName
            end tell

            tell application "Finder"
                            delete file (i as string)
                            delete file (fixedMacFileName as string) of startup disk
                    on error the errormessage
                            display dialog errormessage
                    end try
            end tell

            tell application "iCal"
            end tell
    end repeat
    return input
end adding folder items to

Now I simply drag the .ics file from onto the folder and it gets imported into iCal just fine.