Parsing Unbounded iCal events

62 views
Skip to first unread message

David Renz

unread,
Mar 26, 2011, 7:47:44 PM3/26/11
to RiCal
Hello,

I'm using ri_cal to parse ical entries for events and some of those
events are unbound.

Is it possible to parse these ical strings with ri_cal? One
alternative that I've considered is adding an artificial end to the
entry.

Is there a recommended way to handle this issue?

Thanks,

Dve

Rick DeNatale

unread,
Mar 26, 2011, 8:24:50 PM3/26/11
to rica...@googlegroups.com
On Sat, Mar 26, 2011 at 7:47 PM, David Renz <da...@qlabs.com> wrote:
> Hello,
>
> I'm using ri_cal to parse ical entries for events and some of those
> events are unbound.

I'm not sure what you mean by and event being unbounded.

If an event has a dtstart and no dtend or duration, it is still
bounded. The effective dtend depend on whether dtstart is a datatime
or a date. If it's a datetime then the event ends at the same date
and time and effectively marks a point in time. If dtstart is a date
then the event is considered an anniversary event and it starts at the
beginning of that day, and ends at the end of that day.

You may be talking about an unbounded recurring event for example,
every 1st Sunday, with no limit of count or end (the UNTIL part of a
recurrence rule)


>
> Is it possible to parse these ical strings with ri_cal?  One
> alternative that I've considered is adding an artificial end to the
> entry.

Parsing should be no problem.


>
> Is there a recommended way to handle this issue?

You do need to be careful if you try to enumerate the occurrences of
an event which may be unbounded. From the README

To get an array of occurrences, Use the
RiCal::OccurrenceEnumerator#occurrences method:

event.occurrences

This method may fail with an argument error, if the component has an
unbounded recurrence definition. This happens
when one or more of its RRULES don't have a COUNT, or UNTIL part.
This may be tested by using the RiCal::OccurrenceEnumerator#bounded?
method.

In the case of unbounded components, you must either use the :count,
or :before options of the RiCal::OccurrenceEnumerator#occurrences
method:

event.occurrences(:count => 10)

or

event.occurrences(:before => Date.today >> 1)

Another option on the occurrences method is the :overlapping option,
which takes an array of two Dates, Times or DateTimes which are
expected to be in chronological order. Only events which occur either
partially or fully within the range given by the :overlapping option
will be enumerated.

Alternately, you can use the RiCal::OccurrenceEnumerator#each method,
or another Enumerable method (RiCal::OccurrenceEnumerator includes
Enumerable), and terminate when you wish by breaking out of the block.

event.each do |event|
break if some_termination_condition
#....
end


--
Rick DeNatale

Blog: http://talklikeaduck.denhaven2.com/
Github: http://github.com/rubyredrick
Twitter: @RickDeNatale
WWR: http://www.workingwithrails.com/person/9021-rick-denatale
LinkedIn: http://www.linkedin.com/in/rickdenatale

Reply all
Reply to author
Forward
0 new messages