Skip to content

Commit

Permalink
#299: sync SchedulerUtils to StudyManager Backend
Browse files Browse the repository at this point in the history
  • Loading branch information
drtyyj committed Jun 4, 2024
1 parent 5cc966a commit a51f210
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ private static Instant toInstant(RelativeDate date, Instant start) {
public static List<Pair<Instant, Instant>> parseToObservationSchedulesForEvent(Event event, Instant start, Instant end) {
List<Pair<Instant, Instant>> observationSchedules = new ArrayList<>();
if(event.getDateStart() != null && event.getDateEnd() != null) {
VEvent iCalEvent = parseToICalEvent(event);
VEvent iCalEvent = parseToICalEvent(event, end);
long eventDuration = getEventTime(event);
DateIterator it = iCalEvent.getDateIterator(TimeZone.getDefault());
while (it.hasNext()) {
Expand Down Expand Up @@ -111,15 +111,15 @@ private static long getEventTime(Event event) {
return Duration.between(event.getDateStart(), event.getDateEnd()).getSeconds();
}

private static VEvent parseToICalEvent(Event event) {
private static VEvent parseToICalEvent(Event event, Instant fallBackEnd) {
VEvent iCalEvent = new VEvent();
iCalEvent.setDateStart(Date.from(event.getDateStart()));
iCalEvent.setDateEnd(Date.from(event.getDateEnd()));

RecurrenceRule eventRecurrence = event.getRRule();
if (event.getRRule() != null) {
if (eventRecurrence != null) {
Recurrence.Builder recurBuilder = new Recurrence.Builder(Frequency.valueOf(eventRecurrence.getFreq()));
setUntil(recurBuilder, eventRecurrence.getUntil());
setUntil(recurBuilder, Objects.requireNonNullElse(eventRecurrence.getUntil(), fallBackEnd));
setCount(recurBuilder, eventRecurrence.getCount());
setInterval(recurBuilder, eventRecurrence.getInterval());
setByDay(recurBuilder, eventRecurrence.getByDay(), eventRecurrence.getBySetPos());
Expand Down

0 comments on commit a51f210

Please sign in to comment.