question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can ical4j identify exceptions to recurring calendar events?

See original GitHub issue

I get an iCalendar file from an external source, over which I have no control, and in that file there are entries like these:

BEGIN:VEVENT
DTSTART;TZID=Europe/Zurich:20130511T051500
DTEND;TZID=Europe/Zurich:20130511T171559
DTSTAMP:20150822T121746Z
UID:06984C6F68C24922B235F7C4D5DDA98D00000000000000000000000000000000
RECURRENCE-ID;VALUE=DATE:20130511
CREATED:20120117T180152Z
DESCRIPTION:Event info particular to this occurrence
LAST-MODIFIED:20150516T235258Z
LOCATION:
SEQUENCE:3
STATUS:CONFIRMED
SUMMARY:A recurring event
TRANSP:OPAQUE
END:VEVENT
BEGIN:VEVENT
DTSTART;VALUE=DATE:20150509
DTEND;VALUE=DATE:20150510
DTSTAMP:20150822T121746Z
UID:06984C6F68C24922B235F7C4D5DDA98D00000000000000000000000000000000
RECURRENCE-ID;VALUE=DATE:20150509
CREATED:20120117T180152Z
DESCRIPTION:Other event info particular to this occurrence
LAST-MODIFIED:20150509T093901Z
LOCATION:
SEQUENCE:2
STATUS:CONFIRMED
SUMMARY:A different summary for this occurrence
TRANSP:OPAQUE
BEGIN:VALARM
ACTION:AUDIO
TRIGGER:-PT15H
X-WR-ALARMUID:85257BF6-4591-4522-A479-706130730C65
UID:85257BF6-4591-4522-A479-706130730C65
ATTACH;VALUE=URI:Basso
X-APPLE-DEFAULT-ALARM:TRUE
ACKNOWLEDGED:20150509T093901Z
END:VALARM
END:VEVENT
BEGIN:VEVENT
DTSTART;VALUE=DATE:20120512
DTEND;VALUE=DATE:20120513
RRULE:FREQ=MONTHLY;INTERVAL=12;BYDAY=2SA
EXDATE;VALUE=DATE:20140510
DTSTAMP:20150822T121746Z
UID:06984C6F68C24922B235F7C4D5DDA98D00000000000000000000000000000000
CREATED:20120117T180152Z
DESCRIPTION:
LAST-MODIFIED:20150508T180631Z
LOCATION:
SEQUENCE:2
STATUS:CONFIRMED
SUMMARY:A recurring event
TRANSP:OPAQUE
CATEGORIES:http://schemas.google.com/g/2005#event
BEGIN:VALARM
ACTION:AUDIO
TRIGGER:-PT15H
X-WR-ALARMUID:16016C31-EE77-4551-8161-274745B1B7F8
UID:16016C31-EE77-4551-8161-274745B1B7F8
X-APPLE-DEFAULT-ALARM:TRUE
ATTACH;VALUE=URI:Basso
END:VALARM
END:VEVENT

So there is one VEVENT entry for a recurring event that happens year after year (this iCalendar file is old, and has accumulated a lot of cruft over the years) but from time to time someone has entered another VEVENT with exceptions to the DESCRIPTION or the SUMMARY of a particular occurrence of this recurring event.

Now I’m using ical4j to parse this file and produce a list of events, like this:

2015

  • May 9: “Other event info particular to this occurrence”

At the moment, I’m doing this with a simple loop over all the VEVENT entries:

for (VEvent event : (Iterable<VEvent>) calendar.getComponents(Component.VEVENT)) {
    for (Period period : (Iterable<Period>) event.calculateRecurrenceSet(year)) {
    // ...

That works pretty well, except for in the case of the VEVENT entries listed above, which then show up duplicated, one item for the original recurring event and one other item on that same day for the event with the exceptions. (Software like Google Calendar, on the other hand, will notice that the entries have the same UID and only show the one with the exception.)

This leads to these two questions, to which I’ve not been able to figure out answers on my own:

  • Is there any way in which I could use ical4j to identify these and resolve duplicates?
  • If not, would this not be a reasonable feature request?

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
benfortunacommented, Dec 24, 2015

Currently ical4j doesn’t de-dup components with the same UID, however I think that would be a valid feature request.

0reactions
benfortunacommented, Aug 1, 2017

I’ve just added a new class: ComponentGroup. The idea is that Components with the same UID can be grouped together and treated like a single component.

Currently this requires explicit grouping like so (using above example):

for (VEvent event : (Iterable<VEvent>) calendar.getComponents(Component.VEVENT)) {
    ComponentGroup group = new ComponentGroup(calendar.getComponents(), event.getUid());
    for (Period period : (Iterable<Period>) group.calculateRecurrenceSet(year)) {
    // ...

PR is here: #167 Feedback would be appreciated, thanks.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Specifying exceptions to recurring calendar events - Jon Udell
To do that in a standard way, that capability would have to be part of the iCalendar standard. And sure enough, it is:...
Read more >
Recurring events are not expanded from Yahoo with caldav4j
I have one problem with loading expanded events from Yahoo using caldav4j. I have one recurring event that occurs every Monday starting from ......
Read more >
Java calendar library with support for recurring events ...
I am looking for a calendar module/library that I could use in my simulation. My idea is to fill such calendar with events,...
Read more >
Calendar APIs: iCalendar best practices and known issues
It may be difficult to determine the RECURRENCE-IDs that represent instances identified in an RRULE. For the first instance, this is the DTSTART....
Read more >
RFC 2445: Internet Calendaring and Scheduling Core Object ...
This MIME media type provides a standard content type for capturing calendar event, to-do and journal entry information. It also can be used...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found