Skip to content

Commit

Permalink
🐛 Fix RecurrenceRule#setByPart, fixes #127 (#128)
Browse files Browse the repository at this point in the history
  • Loading branch information
janusvm authored Nov 15, 2023
1 parent d59e866 commit 001095f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/main/java/org/dmfs/rfc5545/recur/RecurrenceRule.java
Original file line number Diff line number Diff line change
Expand Up @@ -1960,8 +1960,10 @@ public void setByDayPart(List<WeekdayNum> value)
{
mParts.remove(Part.BYDAY);
}

mParts.put(Part.BYDAY, value);
else
{
mParts.put(Part.BYDAY, value);
}
}


Expand Down
30 changes: 30 additions & 0 deletions src/test/java/org/dmfs/rfc5545/recur/RecurrenceRuleTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import org.dmfs.rfc5545.Weekday;
import org.junit.jupiter.api.Test;

import java.util.Collections;

import static org.dmfs.jems2.hamcrest.matchers.LambdaMatcher.having;
import static org.dmfs.jems2.hamcrest.matchers.fragile.BrokenFragileMatcher.throwing;
import static org.dmfs.jems2.hamcrest.matchers.single.SingleMatcher.hasValue;
Expand Down Expand Up @@ -157,4 +159,32 @@ void testAllDayUntilAndDateTimeStart() throws InvalidRecurrenceRuleException
is(having(
r -> () -> r.iterator(DateTime.parse("20230301T000000")), is(throwing(IllegalArgumentException.class)))));
}

/**
* see https://github.com/dmfs/lib-recur/issues/127
*/
@Test
public void testSetByDayPart() throws InvalidRecurrenceRuleException {
RecurrenceRule rrule = new RecurrenceRule("FREQ=MONTHLY;BYMONTHDAY=31;COUNT=3");
rrule.setByDayPart(Collections.emptyList());

assertThat(rrule,
allOf(validRule(DateTime.parse("20230501T000000"),
walking(),
results(3)),
generates("20230501T000000",
"20230531T000000",
"20230731T000000",
"20230831T000000")));

rrule.setByPart(null);
assertThat(rrule,
allOf(validRule(DateTime.parse("20230501T000000"),
walking(),
results(3)),
generates("20230501T000000",
"20230531T000000",
"20230731T000000",
"20230831T000000")));
}
}

0 comments on commit 001095f

Please sign in to comment.