thybag / JavaScript-Ical-Parser

Proof of concept Javascript ical (.ics) parser
39 stars 19 forks source link

Apple iCalendar compatibility #5

Open adrianmihalko opened 7 years ago

adrianmihalko commented 7 years ago

Hi Carl,

Unfortunately I can't get any output when I am using Apple iCalendar's .ics file. Do you have any time check it? I know that this is an old project, but it would be good to get it to work.

Regards, Adrian

thybag commented 7 years ago

Do u have a copy (or redacted copy) of the file you are attempting to parse at all? I can possibly try and have a look. Not actually looked at this in years :p

May also be worth double checking if https://github.com/thybag/JavaScript-Ical-Parser/pull/3 fixes anything, as it seems to include a few fixes.

adrianmihalko commented 7 years ago

Thanks for the quick answer. :) Yes I already checked #3, but still not working.

Of course I have a sample file:

apple.ics.txt

I hope there are no sensitive informations. :) I delete the attachment later. I compared to Google ics file, but I think they are similar.

There is a test event for tomorrow:

BEGIN:VEVENT
CREATED:20170428T064712Z
UID:144A5D4A-2B01-4D83-BAA0-DD0D43B1FA90
DTEND;TZID=Europe/Budapest:20170429T100000
SUMMARY:hello
DTSTART;TZID=Europe/Budapest:20170429T090000
DTSTAMP:20170428T064714Z
SEQUENCE:0
END:VEVENT
BEGIN:VEVENT

One more question, but I think you have no time to fix this: there are public calendars on Google, like Namedays:

https://calendar.google.com/calendar/ical/5koqucna65ibl7ftp9kep76gko%40group.calendar.google.com/public/basic.ics

BEGIN:VEVENT
DTSTART;VALUE=DATE:20060912
DTEND;VALUE=DATE:20060913
RRULE:FREQ=YEARLY
DTSTAMP:20170428T101950Z
UID:ac1amgufojlogjqkcrm729mhp4@google.com
CREATED:20060416T124210Z
DESCRIPTION:
LAST-MODIFIED:20150706T152130Z
LOCATION:
SEQUENCE:1
STATUS:CONFIRMED
SUMMARY:Mária
TRANSP:TRANSPARENT
END:VEVENT

As you see DTSTART is in the past when creators created this calendar, but If am not wrong current version of your parser didn't parse RRULE:FREQ=YEARLY line. It is very hard to add support for this one?

p.s: We are using your parser in a Domoticz theme: https://www.domoticz.com/forum/viewtopic.php?f=8&t=16526

adrianmihalko commented 7 years ago

For the first problem I think I've found the problem:

Apple uses TZID=xy which stops the script working:

DTSTART;TZID=Europe/Budapest:20170429T090000
DTEND;TZID=Europe/Budapest:20170429T100000

Edit: fix released:

//Chech for ; in DTSTART (Apple Calendar use TZID after DTSART)
            if (ln.indexOf(';') >= 0) {
                //Split the item based on the first ":"
                idx = ln.indexOf(':');

                //Apply trimming to values to reduce risks of badly formatted ical files.
                type = ln.substr(0,idx).replace(/^\s\s*/, '').replace(/\s\s*$/, '');//Trim

                //Split the item based on the first ";"
                idx2 = type.indexOf(';');
                //Get DTSTART
                type = ln.substr(0,idx2);

                val = ln.substr(idx+1).replace(/^\s\s*/, '').replace(/\s\s*$/, '');

            } else {
                //Split the item based on the first ":"
                idx = ln.indexOf(':');

                //Apply trimming to values to reduce risks of badly formatted ical files.
                type = ln.substr(0,idx).replace(/^\s\s*/, '').replace(/\s\s*$/, '');//Trim

                val = ln.substr(idx+1).replace(/^\s\s*/, '').replace(/\s\s*$/, '');

            }

I created pull request, but it's based on #3 .

Now the hard part: RRULE:FREQ=YEARLY -> I have no idea where to start. :)