diff options
author | Anton Tananaev <anton@traccar.org> | 2023-04-22 09:11:06 -0700 |
---|---|---|
committer | Anton Tananaev <anton@traccar.org> | 2023-04-22 09:11:06 -0700 |
commit | c2637180549e69fc302f91f4685036e2697ae7bf (patch) | |
tree | da7066ae24501623863d86995689736b36a4702b /src/main/java/org/traccar/model | |
parent | f92bde2088001c34186eb3897cece90171a319d1 (diff) | |
download | trackermap-server-c2637180549e69fc302f91f4685036e2697ae7bf.tar.gz trackermap-server-c2637180549e69fc302f91f4685036e2697ae7bf.tar.bz2 trackermap-server-c2637180549e69fc302f91f4685036e2697ae7bf.zip |
Fix report scheduling
Diffstat (limited to 'src/main/java/org/traccar/model')
-rw-r--r-- | src/main/java/org/traccar/model/Calendar.java | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/src/main/java/org/traccar/model/Calendar.java b/src/main/java/org/traccar/model/Calendar.java index 62c51cc4a..03f1995ba 100644 --- a/src/main/java/org/traccar/model/Calendar.java +++ b/src/main/java/org/traccar/model/Calendar.java @@ -34,6 +34,7 @@ import java.time.Duration; import java.util.Collection; import java.util.Date; import java.util.List; +import java.util.stream.Collectors; @StorageName("tc_calendars") public class Calendar extends ExtendedModel { @@ -68,16 +69,22 @@ public class Calendar extends ExtendedModel { return calendar; } - public Collection<VEvent> findEvents(Date date) { + private Collection<VEvent> findEvents(Date date) { if (calendar != null) { - Period period = new Period(new DateTime(date), Duration.ZERO); - Filter<VEvent> filter = new Filter<>(new PeriodRule<>(period)); + var filter = new Filter<VEvent>(new PeriodRule<>(new Period(new DateTime(date), Duration.ZERO))); return filter.filter(calendar.getComponents(CalendarComponent.VEVENT)); } else { return List.of(); } } + public Collection<Period> findPeriods(Date date) { + var calendarDate = new net.fortuna.ical4j.model.Date(date); + return findEvents(date).stream() + .flatMap((event) -> event.getConsumedTime(calendarDate, calendarDate).stream()) + .collect(Collectors.toSet()); + } + public boolean checkMoment(Date date) { return !findEvents(date).isEmpty(); } |