From 09a2b6ddd46f9794168cfb6555c7b663e990fc6b Mon Sep 17 00:00:00 2001 From: Marten Gajda Date: Sun, 6 Nov 2022 21:46:40 +0100 Subject: [PATCH] Add test case for #75 Looks like there is nothing to do because it's already handled correctly, at elast when using `RecurrenceSet`. closes #75 --- .../instanceiterable/RuleInstances.java | 10 +++--- .../rfc5545/iterable/RecurrenceSetTest.java | 35 +++++++++++++++++++ 2 files changed, 39 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/dmfs/rfc5545/iterable/instanceiterable/RuleInstances.java b/src/main/java/org/dmfs/rfc5545/iterable/instanceiterable/RuleInstances.java index 1edf3a2..024cc32 100644 --- a/src/main/java/org/dmfs/rfc5545/iterable/instanceiterable/RuleInstances.java +++ b/src/main/java/org/dmfs/rfc5545/iterable/instanceiterable/RuleInstances.java @@ -53,29 +53,27 @@ public RuleInstances(RecurrenceRule rule) public InstanceIterator iterator(DateTime firstInstance) { RecurrenceRuleIterator iterator = mRrule.iterator(firstInstance); + return new InstanceIterator() { - private final RecurrenceRuleIterator mIterator = iterator; - - @Override public boolean hasNext() { - return mIterator.hasNext(); + return iterator.hasNext(); } @Override public long next() { - return mIterator.nextMillis(); + return iterator.nextMillis(); } @Override public void fastForward(long until) { - mIterator.fastForward(until); + iterator.fastForward(until); } }; } diff --git a/src/test/java/org/dmfs/rfc5545/iterable/RecurrenceSetTest.java b/src/test/java/org/dmfs/rfc5545/iterable/RecurrenceSetTest.java index b090bb3..7f9a371 100644 --- a/src/test/java/org/dmfs/rfc5545/iterable/RecurrenceSetTest.java +++ b/src/test/java/org/dmfs/rfc5545/iterable/RecurrenceSetTest.java @@ -161,4 +161,39 @@ void testWithDuplicates() throws InvalidRecurrenceRuleException DateTime.parse("20220125") )); } + + + // see https://github.com/dmfs/lib-recur/issues/75 + @Test + void testBySetPosWithOutOfSyncFirst() throws InvalidRecurrenceRuleException + { + assertThat(new RecurrenceSet(DateTime.parse("20220101"), + new FirstAndRuleInstances(new RecurrenceRule("FREQ=MONTHLY;BYDAY=MO,FR;BYSETPOS=1,2,3;COUNT=6") + )), + iteratesTo( + DateTime.parse("20220101"), + DateTime.parse("20220103"), + DateTime.parse("20220107"), + DateTime.parse("20220204"), + DateTime.parse("20220207"), + DateTime.parse("20220211"))); + } + + + // see https://github.com/dmfs/lib-recur/issues/75 + @Test + void testBySetPosWithSyncedFirst() throws InvalidRecurrenceRuleException + { + assertThat(new RecurrenceSet(DateTime.parse("20220101"), + new RuleInstances(new RecurrenceRule("FREQ=MONTHLY;BYDAY=MO,FR;BYSETPOS=1,2,3;COUNT=6") + )), + iteratesTo( + DateTime.parse("20220103"), + DateTime.parse("20220107"), + DateTime.parse("20220110"), + DateTime.parse("20220204"), + DateTime.parse("20220207"), + DateTime.parse("20220211") + )); + } }