Skip to content

Commit

Permalink
Fix fast forwarding InstanceLists, fixes #125 (#126)
Browse files Browse the repository at this point in the history
  • Loading branch information
dmfs authored Nov 14, 2023
1 parent 8ce5766 commit d59e866
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,7 @@ public FastForwarded(long timeStamp, InstanceIterable delegate)
public InstanceIterator iterator(DateTime firstInstance)
{
InstanceIterator iterator = mDelegate.iterator(firstInstance);
if (firstInstance.getTimestamp() < mTimeStamp)
{
iterator.fastForward(mTimeStamp);
}
iterator.fastForward(mTimeStamp);
return iterator;
}
}
49 changes: 49 additions & 0 deletions src/test/java/org/dmfs/rfc5545/iterable/RecurrenceSetTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import java.util.TimeZone;

import static org.dmfs.jems2.hamcrest.matchers.iterable.IterableMatcher.iteratesTo;
import static org.dmfs.rfc5545.recur.Freq.MONTHLY;
import static org.dmfs.rfc5545.recur.RecurrenceRule.Part.BYMONTHDAY;
import static org.hamcrest.MatcherAssert.assertThat;


Expand Down Expand Up @@ -161,4 +163,51 @@ void testWithDuplicates() throws InvalidRecurrenceRuleException
DateTime.parse("20220125")
));
}


@Test
void testFastForwardedWithInstanceList() throws InvalidRecurrenceRuleException
{
assertThat(new RecurrenceSet(DateTime.parse("20220101"),
new FastForwarded(DateTime.parse("20220111"),
new InstanceList("20220110,20220118", DateTime.UTC),
new RuleInstances(new RecurrenceRule("FREQ=WEEKLY;BYDAY=SA;COUNT=5"))
)
),
iteratesTo(
DateTime.parse("20220115"),
DateTime.parse("20220118"),
DateTime.parse("20220122"),
DateTime.parse("20220129")
));
}

/**
* https://github.com/dmfs/lib-recur/issues/125
*/
@Test
void testIssue125() throws InvalidRecurrenceRuleException
{

RecurrenceRule rrule = new RecurrenceRule(MONTHLY);
rrule.setByPart(BYMONTHDAY, 10);
rrule.setCount(5);

long[] rdates = new long[] { 1689379200000L, 1692057600000L }; // 2023-07-15, 2023-08-15


assertThat(
new RecurrenceSet(new DateTime(2023, 7, 1), // 2023-08-01
new FastForwarded(new DateTime(2023, 7, 1), // 2023-08-01
new InstanceList(rdates),
new RuleInstances(rrule))),
iteratesTo(
DateTime.parse("20230810"),
DateTime.parse("20230815"),
DateTime.parse("20230910"),
DateTime.parse("20231010"),
DateTime.parse("20231110"),
DateTime.parse("20231210")
));
}
}

0 comments on commit d59e866

Please sign in to comment.