Skip to content
Mike Angstadt edited this page Feb 23, 2017 · 4 revisions

How do I create an all-day event?

Set the DTSTART property to a date value and do not specify an end date (see: RFC 5546 Section 4.1.5).

VEvent event = new VEvent();
Date start = ...
event.setDateStart(start, false);

How do I cancel an existing event?

(see: RFC 5546 Section 4.1.3)

ICalendar ical = new ICalendar();
ical.setMethod("CANCEL");
VEvent event = new VEvent();
event.setOrganizer("[email protected]"); //the organizer of the existing event
event.setUid(...); //the UID of the existing event
event.setSequence(2); //increment the sequence number of the existing event
event.addComment(...); //optional: describe why it was cancelled
ical.addEvent(event);

How do I parse an RRULE string?

RecurrenceRuleScribe scribe = new RecurrenceRuleScribe();
ParseContext context = new ParseContext();
context.setVersion(ICalVersion.V2_0);
RecurrenceRule rrule = scribe.parseText("FREQ=WEEKLY;INTERVAL=2", null, new ICalParameters(), context);
Recurrence recur = rrule.getValue();

Date start = ...
TimeZone timezone = ...
DateIterator it = rrule.getDateIterator(start, timezone);
while (it.hasNext()) {
    System.out.println(it.next());
}

How do I generate an RRULE string?

Recurrence recur = new Recurrence.Builder(Frequency.WEEKLY).interval(2).build();
RecurrenceRule rrule = new RecurrenceRule(recur);
WriteContext context = new WriteContext(ICalVersion.V2_0, new TimezoneInfo(), null);
RecurrenceRuleScribe scribe = new RecurrenceRuleScribe();
System.out.println(scribe.writeText(rrule, context));
//prints: FREQ=WEEKLY;INTERVAL=2