Search in sources :

Example 1 with PeriodRule

use of net.fortuna.ical4j.filter.PeriodRule 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)

Example 2 with PeriodRule

use of net.fortuna.ical4j.filter.PeriodRule in project traccar by tananaev.

the class Calendar method checkMoment.

public boolean checkMoment(Date date) {
    if (calendar != null) {
        Period period = new Period(new DateTime(date), new Dur(0, 0, 0, 0));
        Predicate<CalendarComponent> periodRule = new PeriodRule<>(period);
        Filter<CalendarComponent> filter = new Filter<>(new Predicate[] { periodRule }, Filter.MATCH_ANY);
        Collection<CalendarComponent> events = filter.filter(calendar.getComponents(CalendarComponent.VEVENT));
        if (events != null && !events.isEmpty()) {
            return true;
        }
    }
    return false;
}
Also used : Dur(net.fortuna.ical4j.model.Dur) PeriodRule(net.fortuna.ical4j.filter.PeriodRule) CalendarComponent(net.fortuna.ical4j.model.component.CalendarComponent) Filter(net.fortuna.ical4j.filter.Filter) Period(net.fortuna.ical4j.model.Period) DateTime(net.fortuna.ical4j.model.DateTime)

Aggregations

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