use of org.openremote.model.calendar.RecurrenceRule in project openremote by openremote.
the class AssetStorageService method calendarEventActiveOn.
protected static boolean calendarEventActiveOn(CalendarEvent calendarEvent, Date when) {
if (calendarEvent.getRecurrence() == null) {
return (!when.before(calendarEvent.getStart()) && !when.after(calendarEvent.getEnd()));
}
RecurrenceRule recurrenceRule = calendarEvent.getRecurrence();
Recur recurrence;
if (recurrenceRule.getCount() != null) {
recurrence = new Recur(recurrenceRule.getFrequency().name(), recurrenceRule.getCount());
} else if (recurrenceRule.getUntil() != null) {
recurrence = new Recur(recurrenceRule.getFrequency().name(), new net.fortuna.ical4j.model.Date(recurrenceRule.getUntil()));
} else {
recurrence = new Recur(recurrenceRule.getFrequency().name(), null);
}
if (recurrenceRule.getInterval() != null) {
recurrence.setInterval(recurrenceRule.getInterval());
}
RRule rRule = new RRule(recurrence);
VEvent vEvent = new VEvent(new DateTime(calendarEvent.getStart()), new DateTime(calendarEvent.getEnd()), "");
vEvent.getProperties().add(rRule);
Period period = new Period(new DateTime(when), new Dur(0, 0, 1, 0));
PeriodRule periodRule = new PeriodRule(period);
return periodRule.evaluate(vEvent);
}
Aggregations