Ical (.ics) feed from Matrix Calendar Event assets?


(Andrew Harris) #1

I want to create an ical/ics event feed from our collection of 'Single Calendar Event' assets.

I am sooo close, but the final 5% looks like taking way longer than I'd like, so, I'm looking for the lazy option - stealing - I mean, building upon, someone else's work!

 

So, the first question is: has anyone got a kick-a** example they'd be willing to share? :-)

Failing that, has anyone got some ideas to help me with these issues.

 

My first problem is devising a method of altering the output of the VEVENT depending on whether:

  • it is a full day event, or a specific timed event
  • an end date, or time has been specified

The ical format is quite picky about this stuff, so it'd be nice to get it right.

 

As an alternative to DTEND, I'd really like to use the DURATION: attribute based on the %event_duration% keyword, but I can't find the keyword modifiers I need to make that work. Any ideas there? I could go into some massive regex I suppose, but ewww! I'll probably end up using conditional keywords in a paint layout unless someone has a better idea.

 

My next problem is timezones! Why, oh why are my events getting advanced 10 hours?

DTSTART;TZID="Canberra, Melbourne, Sydney":%event_start_date^date_format:Ymd%T%event_start_time_24h^date_format:His%

on an event with no time specified (eg: an all day event) is becoming an event at 10am…

DTSTART;TZID="Canberra, Melbourne, Sydney":20160223T100000

Events with times specified are coming in correctly.

 

Just to pre-empt the inevitable "why not just use %event_start_date_ical%?". That keyword doesn't include a time unless one is specified, so, most calendar clients won't process the feed without an extra attribute for the DTSTART, even then, I've had difficulties. I'd need to do the conditional stuff some other way if I used that.

 
Again, it's probably going to be a conditional keyword in a paint layout - puzzling though.
 
Any help/ideas greatly appreciated!
 
Cheers,
Andrew H

(Nic Hubbard) #2

I have done something similar, and worked through a lot of your issues. Like you said, a Paint Layout has been applied since we need to do some conditional checks. Here is the Conditional Keywords configurations:

 

 

 

Type Format for Single Calendar Event:

BEGIN:VEVENTUID:%globals_random_1_600%%asset_assetid%%globals_random_1_600%
TZID:America/Los_Angeles
%begin_has_start_time%
DTSTART:%event_start_time_ical%
%else_has_start_time%
DTSTART;VALUE=DATE:%event_start_time_ical%
%end_has_start_time%
%begin_has_end_time%
DTEND:%event_end_time_ical%
%else_has_end_time%
DTEND;VALUE=DATE:%event_end_time_ical%
%end_has_end_time%
URL;VALUE=URI:%asset_url%
DTSTAMP:%asset_created_ical%
SUMMARY:%asset_name^json_encode^replace:;:%
LOCATION:%asset_metadata_event_location_key^json_encode^replace:;:%
END:VEVENT

Hope this helps.


(Andrew Harris) #3

Nic,

thanks - that's where I'm heading - very helpful.

 

One thing that's come up, and I don't know if you've noticed this, is that there's a huge problem with all day events (events without times).

 

Matrix defines an all day event as finishing on the inclusive date (the last day of the event) - but ical defines the end of an all day event as the beginning of the next day.

So, If your .ics format uses start_time, and end_time keywords, the event appears to be one day shorter than it really is. Single day events just vanish.

 

Rather distressing ;-)

 

Cheers,

Andrew H


(Nic Hubbard) #4

Matrix defines an all day event as finishing on the inclusive date (the last day of the event) - but ical defines the end of an all day event as the beginning of the next day.

So, If your .ics format uses start_time, and end_time keywords, the event appears to be one day shorter than it really is. Single day events just vanish.

 

I have not noticed this, our events seem to work fine. Take a look at our calendar: http://www.puc.edu/calendar

 

You can subscribe on the left side. When I subscribe, I see all our all-day events (events with no time) and events with time correctly.


(Andrew Harris) #5

Nic,

oh, that's an interesting solution - you don't use DTEND.

 

So, your all-day events are assumed (by the ical standard) to be the whole of a day, but your timed events don't have a duration.

 

Works well enough that it gives me a clue about how to write my conditional keywords ;-)

 

Cheers,

Andrew H


(Nic Hubbard) #6

oh, that's an interesting solution - you don't use DTEND.

 

So, your all-day events are assumed (by the ical standard) to be the whole of a day, but your timed events don't have a duration.

 

Works well enough that it gives me a clue about how to write my conditional keywords ;-)

 

We do use DTEND, but it changes based on if there is a time component or not.

%begin_has_end_time%
DTEND:%event_end_time_ical%
%else_has_end_time%
DTEND;VALUE=DATE:%event_end_time_ical%
%end_has_end_time%

(Andrew Harris) #7

Nic,

I see that in your code, but your .ics file contains no DTEND attributes.

The keyword appears to not be firing at all.

 

Cheers, A


(Nic Hubbard) #8

I see that in your code, but your .ics file contains no DTEND attributes.

The keyword appears to not be firing at all.

 

Ha! You are right. Realized I was giving you the code of our old .ics asset listing. I moved it over to use a Rolling Calendar Page instead with no Paint Layout. Here is what I am using for the type format:

BEGIN:VEVENTUID:%globals_random_1_600%%asset_assetid%%globals_random_1_600%
TZID:America/Los_Angeles
DTSTART%asset_attribute_start_date^contains:--^replace:3:;VALUE=DATE^replace:0:%:%event_start_time_ical%
URL;VALUE=URI:%asset_url%
DTSTAMP:%asset_created_ical%
SUMMARY:%asset_attribute_name%
LOCATION:%asset_metadata_location%
END:VEVENT

Sorry about that mixup!


(Andrew Harris) #9

Nic,

this has been an interesting little journey!

In the end, I'm using an asset listing with a paint layout. The Calendar listing assets are a bit too limiting.

 

I also went with DURATION instead of DTEND. I want items to show their true duration in a calendar, and using duration also ensure they don't get shortened by a day.

I have a simple regular expression which converts something like "4 days" to P4D. I have yet to tackle hours and minutes, as I'm sure that'll come up at some point in the future!

 

BEGIN:VEVENT
UID:%asset_assetid%-unimelb-edu-au
TZID:Canberra, Melbourne, Sydney
DTSTAMP:%asset_created_ical%
%begin_has_start_time%
DTSTART:%event_start_time_ical%
%else_has_start_time%
DTSTART;VALUE=DATE:%event_start_time_ical%
%end_has_start_time%
%begin_has_end_date%DURATION:%event_duration^preg_replace:1786095%
%else_has_end_date%DURATION:P1D
%end_has_end_date%
SUMMARY:%asset_name^unescapehtml%
DESCRIPTION:%asset_attribute_description^striphtml^trim%
URL;VALUE=URI:%asset_url%
TRANSP:TRANSPARENT
END:VEVENT
Thanks for your time :-)

(Andrew Harris) #10

Nic,

just added something to squizmap that would make this sort of stuff soooo much easier! ;-)

https://squizmap.squiz.net/matrix/8807

 

Cheers,

Andrew


(Nic Hubbard) #11

Nic,

just added something to squizmap that would make this sort of stuff soooo much easier! ;-)

https://squizmap.squiz.net/matrix/8807

 

Great idea. Thanks!