aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/org/traccar/model/Calendar.java24
-rw-r--r--src/main/java/org/traccar/schedule/TaskReports.java8
2 files changed, 13 insertions, 19 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();
}
}
diff --git a/src/main/java/org/traccar/schedule/TaskReports.java b/src/main/java/org/traccar/schedule/TaskReports.java
index 1b9b15749..32f6fea87 100644
--- a/src/main/java/org/traccar/schedule/TaskReports.java
+++ b/src/main/java/org/traccar/schedule/TaskReports.java
@@ -41,6 +41,8 @@ import org.traccar.storage.query.Condition;
import org.traccar.storage.query.Request;
import jakarta.inject.Inject;
+
+import java.time.Instant;
import java.util.Collections;
import java.util.Date;
import java.util.HashSet;
@@ -83,12 +85,12 @@ public class TaskReports extends SingleScheduleTask {
var lastEvents = calendar.findPeriods(lastCheck);
var currentEvents = calendar.findPeriods(currentCheck);
- Set<Period> finishedEvents = new HashSet<>(lastEvents);
+ Set<Period<Instant>> finishedEvents = new HashSet<>(lastEvents);
finishedEvents.removeAll(currentEvents);
- for (Period period : finishedEvents) {
+ for (Period<Instant> period : finishedEvents) {
RequestScoper scope = ServletScopes.scopeRequest(Collections.emptyMap());
try (RequestScoper.CloseableScope ignored = scope.open()) {
- executeReport(report, period.getStart(), period.getEnd());
+ executeReport(report, Date.from(period.getStart()), Date.from(period.getEnd()));
}
}
}