From 001095f65da9f444b432ec419da46e947d2c8368 Mon Sep 17 00:00:00 2001 From: Janus Valberg-Madsen Date: Wed, 15 Nov 2023 23:30:16 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20RecurrenceRule#setByPart,?= =?UTF-8?q?=20fixes=20#127=20(#128)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dmfs/rfc5545/recur/RecurrenceRule.java | 6 ++-- .../rfc5545/recur/RecurrenceRuleTest.java | 30 +++++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/dmfs/rfc5545/recur/RecurrenceRule.java b/src/main/java/org/dmfs/rfc5545/recur/RecurrenceRule.java index d1445a8..fcad9f2 100644 --- a/src/main/java/org/dmfs/rfc5545/recur/RecurrenceRule.java +++ b/src/main/java/org/dmfs/rfc5545/recur/RecurrenceRule.java @@ -1960,8 +1960,10 @@ public void setByDayPart(List value) { mParts.remove(Part.BYDAY); } - - mParts.put(Part.BYDAY, value); + else + { + mParts.put(Part.BYDAY, value); + } } diff --git a/src/test/java/org/dmfs/rfc5545/recur/RecurrenceRuleTest.java b/src/test/java/org/dmfs/rfc5545/recur/RecurrenceRuleTest.java index 68da10c..dee0f83 100644 --- a/src/test/java/org/dmfs/rfc5545/recur/RecurrenceRuleTest.java +++ b/src/test/java/org/dmfs/rfc5545/recur/RecurrenceRuleTest.java @@ -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; @@ -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"))); + } }