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);
}
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;
}
Aggregations