DateList recurDates = getRecurringsInPeriod(periodStart, periodEnd, kEvent);
return (recurDates != null && !recurDates.isEmpty());
}
private DateList getRecurringsInPeriod(Date periodStart, Date periodEnd, KalendarEvent kEvent) {
DateList recurDates = null;
String recurrenceRule = kEvent.getRecurrenceRule();
if(recurrenceRule != null && !recurrenceRule.equals("")) {
try {
Recur recur = new Recur(recurrenceRule);
net.fortuna.ical4j.model.Date periodStartDate = new net.fortuna.ical4j.model.Date(periodStart);
net.fortuna.ical4j.model.Date periodEndDate = new net.fortuna.ical4j.model.Date(periodEnd);
net.fortuna.ical4j.model.Date eventStartDate = new net.fortuna.ical4j.model.Date(kEvent.getBegin());
recurDates = recur.getDates(eventStartDate, periodStartDate, periodEndDate, Value.DATE);
} catch (ParseException e) {
Tracing.createLoggerFor(getClass()).error("cannot restore recurrence rule: " + recurrenceRule, e);
}
String recurrenceExc = kEvent.getRecurrenceExc();
if(recurrenceExc != null && !recurrenceExc.equals("")) {
try {
ExDate exdate = new ExDate();
// expected date+time format:
// 20100730T100000
// unexpected all-day format:
// 20100730
// see OLAT-5645
if (recurrenceExc.length()>8) {
exdate.setValue(recurrenceExc);
} else {
exdate.getParameters().replace(Value.DATE);
exdate.setValue(recurrenceExc);
}
for( Object date : exdate.getDates() ) {
if(recurDates.contains(date)) recurDates.remove(date);
}
} catch (ParseException e) {
Tracing.createLoggerFor(getClass()).error("cannot restore excluded dates for this recurrence: " + recurrenceExc, e);
}
}