aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/model/Calendar.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/traccar/model/Calendar.java')
-rw-r--r--src/main/java/org/traccar/model/Calendar.java24
1 files changed, 8 insertions, 16 deletions
diff --git a/src/main/java/org/traccar/model/Calendar.java b/src/main/java/org/traccar/model/Calendar.java
index 76c9a2cc1..c1a570037 100644
--- a/src/main/java/org/traccar/model/Calendar.java
+++ b/src/main/java/org/traccar/model/Calendar.java
@@ -19,9 +19,6 @@ package org.traccar.model;
import com.fasterxml.jackson.annotation.JsonIgnore;
import net.fortuna.ical4j.data.CalendarBuilder;
import net.fortuna.ical4j.data.ParserException;
-import net.fortuna.ical4j.filter.Filter;
-import net.fortuna.ical4j.filter.predicate.PeriodRule;
-import net.fortuna.ical4j.model.DateTime;
import net.fortuna.ical4j.model.Period;
import net.fortuna.ical4j.model.component.CalendarComponent;
import net.fortuna.ical4j.model.component.VEvent;
@@ -31,9 +28,8 @@ import org.traccar.storage.StorageName;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.time.Duration;
-import java.util.Collection;
+import java.time.Instant;
import java.util.Date;
-import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
@@ -70,23 +66,19 @@ public class Calendar extends ExtendedModel {
return calendar;
}
- private Collection<VEvent> findEvents(Date date) {
+ public Set<Period<Instant>> findPeriods(Date date) {
if (calendar != null) {
- var filter = new Filter<VEvent>(new PeriodRule<>(new Period(new DateTime(date), Duration.ZERO)));
- return filter.filter(calendar.getComponents(CalendarComponent.VEVENT));
+ var period = new Period<>(date.toInstant(), Duration.ZERO);
+ return calendar.<VEvent>getComponents(CalendarComponent.VEVENT).stream()
+ .flatMap(c -> c.<Instant>calculateRecurrenceSet(period).stream())
+ .collect(Collectors.toUnmodifiableSet());
} else {
- return List.of();
+ return Set.of();
}
}
- public Set<Period> findPeriods(Date date) {
- return findEvents(date).stream()
- .flatMap((e) -> e.calculateRecurrenceSet(new Period(new DateTime(date), Duration.ZERO)).stream())
- .collect(Collectors.toSet());
- }
-
public boolean checkMoment(Date date) {
- return !findEvents(date).isEmpty();
+ return !findPeriods(date).isEmpty();
}
}