C. E.
C. E.

Reputation: 10607

What's wrong with this iCal calendar?

I've written a script to generate an iCal calendar from events in my database. Here's a sample output:

BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//hacksw/handcal//NONSGML v1.0//EN
BEGIN:VEVENT
ORGANIZER;CN=Blodgruppen
DTSTART:20130128T173000Z
DTEND: 20130128T193000Z
SUMMARY: Su-möte
END:VEVENT
BEGIN:VEVENT
ORGANIZER;CN=F-styret
DTSTART:20130128T173000Z
DTEND: 20130128T193000Z
SUMMARY: Su-möte
END:VEVENT
BEGIN:VEVENT
ORGANIZER;CN=Blodgruppen
DTSTART:20130412T100000Z
DTEND: 20130414T180000Z
SUMMARY: KTH
END:VEVENT
BEGIN:VEVENT
ORGANIZER;CN=F-styret
DTSTART:20130412T100000Z
DTEND: 20130414T180000Z
SUMMARY: KTH
END:VEVENT
END:VCALENDAR

When I try to subscribe to this in iCal it says that the file is invalid. Does anyone know why?

Also, does anyone know if I will run into problem somewhere because the ending of my file is .php and not .ics?

(In case it helps, I constructed the above by looking at the example on Wikipedia: http://en.wikipedia.org/wiki/ICalendar#Core_object )

Upvotes: 3

Views: 5649

Answers (4)

Paulb
Paulb

Reputation: 1531

For future use, here are some online icalendar validators:

icalendar.org reported these errors on your sample:

Errors

Missing DTSTAMP property near line # 4Reference: RFC 5545 3.6.1. Event Component
Missing UID property near line # 4Reference: RFC 5545 3.6.1. Event Component
Invalid DTEND value, must be a date or date-time value near line # 4Reference: 3.3.5. Date-Time
Missing DTSTAMP property near line # 10Reference: RFC 5545 3.6.1. Event Component
Missing UID property near line # 10Reference: RFC 5545 3.6.1. Event Component
Invalid DTEND value, must be a date or date-time value near line # 10Reference: 3.3.5. Date-Time
Missing DTSTAMP property near line # 16Reference: RFC 5545 3.6.1. Event Component
Missing UID property near line # 16Reference: RFC 5545 3.6.1. Event Component
Invalid DTEND value, must be a date or date-time value near line # 16Reference: 3.3.5. Date-Time
Missing DTSTAMP property near line # 22Reference: RFC 5545 3.6.1. Event Component
Missing UID property near line # 22Reference: RFC 5545 3.6.1. Event Component
Invalid DTEND value, must be a date or date-time value near line # 22Reference: 3.3.5. Date-Time

Upvotes: 4

holmes2136
holmes2136

Reputation: 487

you can import the ics file into google calendar for test,

you will find the one of the excuse is , you should have UID property in each event ,

and then,you can easily throw these event into google calendar

Upvotes: 0

Stuart Wakefield
Stuart Wakefield

Reputation: 6414

Going back to the basics a bit you cannot upload your PHP script, some calendar clients allow you to subscribe to a URL to pick up an iCal feed, make sure this is what you are doing and that you are not trying to upload the PHP script file.

If that is OK, then we can look at the definition. According to the documentation the ORGANIZER parameter is optional, if it is included it has to have a colon : and a cal-address which must be a URI. Your ORGANIZER fields look like this:

ORGANIZER;CN=Blodgruppen

They should look like this:

ORGANIZER;CN=Blodgruppen:URI

Where URI doesn't necessarily have to be a mailto, here are some examples. For convenience an email address can be added like this...

ORGANIZER;CN=Blodgruppen:MAILTO:[email protected]

Or a phone number...

ORGANIZER;CN=Blodgruppen:TEL:+49-01234-56789

You can include a web of ftp URLs as well as some other less used things. Alternatively the parameter is not required, so you can simply remove it.

Also it appears that the VEVENT is missing a UID and a DTSTAMP which are required properties.

UID can be an identifier of your choosing but it should be globally unique. I'll take the moment to explain what is meant by globally unique by describing the implications of the UID parameter. The calendar client will use this to identify the event, if you use an id of an event that already exists in the calendar it will update that event thinking you mean for it to do that, therefore it must not match the id of an existing event. If you think of adding events to lots of different calendar clients that may also contain events, this is why it must by "globally" unique. There is a uniqid() function you can use in PHP which might help create your own globally unique identifiers.

DTSTAMP is the time the event was created or last updated.

The white-space in your definition is inconsistent, the documentation does not discuss white-space between parameters and values but all examples are shown without whitespace so you might also want to strip any non-essential whitespace...

DTEND: 20130128T193000Z

To become...

DTEND:20130128T193000Z

It might not hurt but there is the possibility. I would also start off with trying one event with the bare minimum of parameters just to check it is the iCal definition causing the issue.

BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//hacksw/handcal//NONSGML v1.0//EN
BEGIN:VEVENT
UID:20121229T212000Z-test-1
DTSTAMP:20121229T212000Z
DTSTART:20130128T173000Z
DTEND:20130128T193000Z
END:VEVENT
END:VCALENDAR

You might want to check your PHP script is using the correct mime-type as well text/calendar. If it isn't you can add the Content-Type header to the response using the header function:

 header("Content-Type: text/calendar");

I hope this helps...

Upvotes: 4

Max Hamulyák
Max Hamulyák

Reputation: 268

iCal doesn't support PHP files at the moment, but as you can read here there is a handy conversion tool Importing iCal calendar into MySQL database

Upvotes: 0

Related Questions