Skip to content

Commit

Permalink
Remove matching recurrence instances where a recurrence-id (override)…
Browse files Browse the repository at this point in the history
… is applied
  • Loading branch information
benfortuna committed Dec 15, 2020
1 parent d4e2159 commit d0e113d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
10 changes: 4 additions & 6 deletions src/main/java/net/fortuna/ical4j/model/ComponentGroup.java
Expand Up @@ -9,7 +9,6 @@
import java.util.Collections;
import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Collectors;

/**
* Support for operations applicable to a group of components. Typically this class is used to manage
Expand Down Expand Up @@ -99,11 +98,10 @@ public PeriodList calculateRecurrenceSet(final Period period) {
PeriodList finalPeriods = periods;
replacements.forEach(component -> {
RecurrenceId recurrenceId = component.getProperty(Property.RECURRENCE_ID);
List<Period> match = finalPeriods.stream().filter(p -> p.getStart().equals(recurrenceId.getDate()))
.collect(Collectors.toList());
finalPeriods.removeAll(match);

finalPeriods.addAll(component.calculateRecurrenceSet(period));
finalPeriods.removeIf(p -> p.getStart().equals(recurrenceId.getDate()));
component.calculateRecurrenceSet(period).stream()
.filter(p -> p.getStart().equals(recurrenceId.getDate()))
.forEach(finalPeriods::add);
});

return periods;
Expand Down
Expand Up @@ -78,7 +78,7 @@ class ComponentGroupTest extends Specification {
}

def "CalculateRecurrenceSet"() {
given: 'an event with 2 revisions'
given: 'an event with a revision'
def components = new ComponentList<VEvent>([event, rev1])

when: 'recurrence instances are calculated'
Expand All @@ -90,14 +90,14 @@ class ComponentGroupTest extends Specification {
}

def "CalculateRecurrenceSetWithException"() {
given: 'an event with 2 revisions'
given: 'an event with 2 revisions and instance override'
def components = new ComponentList<VEvent>([event, rev1, rev2, rev3])

when: 'recurrence instances are calculated'
Period period = ['20101113T120000/P3W']
def recurrences = new ComponentGroup(components, uid).calculateRecurrenceSet(period)

then: 'the expected number of recurrences are returned'
recurrences.size() == event.calculateRecurrenceSet(period).normalise().size()
then: 'the instance override is removed from the recurrence set'
recurrences.size() == event.calculateRecurrenceSet(period).normalise().size() - 1
}
}

0 comments on commit d0e113d

Please sign in to comment.