Search in sources :

Example 1 with RecurrenceRule

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);
}
Also used : RecurrenceRule(org.openremote.model.calendar.RecurrenceRule) VEvent(net.fortuna.ical4j.model.component.VEvent) Dur(net.fortuna.ical4j.model.Dur) RRule(net.fortuna.ical4j.model.property.RRule) PeriodRule(net.fortuna.ical4j.filter.PeriodRule) Period(net.fortuna.ical4j.model.Period) DateTime(net.fortuna.ical4j.model.DateTime) Recur(net.fortuna.ical4j.model.Recur)

Aggregations

PeriodRule (net.fortuna.ical4j.filter.PeriodRule)1 DateTime (net.fortuna.ical4j.model.DateTime)1 Dur (net.fortuna.ical4j.model.Dur)1 Period (net.fortuna.ical4j.model.Period)1 Recur (net.fortuna.ical4j.model.Recur)1 VEvent (net.fortuna.ical4j.model.component.VEvent)1 RRule (net.fortuna.ical4j.model.property.RRule)1 RecurrenceRule (org.openremote.model.calendar.RecurrenceRule)1