Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Recurrence rule in ICal4j

I'm trying to create an .ics file using ICal4j.
But when I try to add a recurrence it fails, throwing a ValidationException:

net.fortuna.ical4j.model.ValidationException: Invalid property: RRULE at
        net.fortuna.ical4j.model.Calendar.validate(Calendar.java:297) at  
        net.fortuna.ical4j.model.Calendar.validate(Calendar.java:257) at 
        net.fortuna.ical4j.data.CalendarOutputter.output(CalendarOutputter.java:96) at 
        net.fortuna.ical4j.data.CalendarOutputter.output(CalendarOutputter.java:83)

My code to add the recurrence is:

Recur recur = new Recur(Recur.WEEKLY,null);
recur.setUntil( new DateTime(dateTo.getTime()) );

RRule rule = new RRule(recur);
cal.getProperties().add(rule);

Without this rule it works fine, but I want to add this event every monday
until 12 December 2011 (the date returned by dateTo). Any ideas?

like image 800
user970183 Avatar asked Oct 09 '22 18:10

user970183


1 Answers

A reccurrence rule (RRULE) property must be added to a specific event (VEVENT) in the calendar, not the calendar itself. e.g.

myEvent.getProperties().add(rule);

Also if you want the event to occur on a Monday you should probably use a rule like this:

FREQ=WEEKLY;BYDAY=MO;UNTIL=<date>

This is off the top of my head, so best to check the RFC to be sure:

https://www.rfc-editor.org/rfc/rfc5545#section-3.3.10

like image 176
fortuna Avatar answered Oct 13 '22 11:10

fortuna