diff options
author | Iván Ávalos <avalos@disroot.org> | 2024-08-03 20:52:00 -0600 |
---|---|---|
committer | Iván Ávalos <avalos@disroot.org> | 2024-08-03 20:52:00 -0600 |
commit | 55f6d92c09a5b1d8566b53633d07be3d31010d3b (patch) | |
tree | b86bed801b0bbadb72c7e839296dae1d28b12bbb /src/main/java/org/traccar/model/Calendar.java | |
parent | c04ad7d48331253c095fc123ded1b00f6ff871d3 (diff) | |
parent | 2788174193def918a3a1a5be3bbed24c9613323f (diff) | |
download | trackermap-server-55f6d92c09a5b1d8566b53633d07be3d31010d3b.tar.gz trackermap-server-55f6d92c09a5b1d8566b53633d07be3d31010d3b.tar.bz2 trackermap-server-55f6d92c09a5b1d8566b53633d07be3d31010d3b.zip |
Merge tag 'tags/v6.3'
Diffstat (limited to 'src/main/java/org/traccar/model/Calendar.java')
-rw-r--r-- | src/main/java/org/traccar/model/Calendar.java | 24 |
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(); } } |