Skip to content

Commit

Permalink
Issue 39. Fix BYMONTH calculation to not break the FREQ constraint
Browse files Browse the repository at this point in the history
  • Loading branch information
voronaam committed Sep 23, 2015
1 parent 5bfa8e3 commit a2e3c4d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/main/java/net/fortuna/ical4j/model/Recur.java
Expand Up @@ -859,10 +859,15 @@ private DateList getMonthVariants(final DateList dates) {
final DateList monthlyDates = getDateListInstance(dates);
for (final Date date : dates) {
final Calendar cal = getCalendarInstance(date, true);
final Calendar freqEnd = getCalendarInstance(date, true);
increment(freqEnd);
for (final Integer month : getMonthList()) {
// Java months are zero-based..
// cal.set(Calendar.MONTH, month.intValue() - 1);
cal.roll(Calendar.MONTH, (month - 1) - cal.get(Calendar.MONTH));
if (cal.after(freqEnd)) {
break; // Do not break out of the FREQ-defined boundary
}
monthlyDates.add(Dates.getInstance(cal.getTime(), monthlyDates.getType()));
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/test/java/net/fortuna/ical4j/model/RecurTest.java
Expand Up @@ -840,6 +840,11 @@ public static TestSuite suite() throws ParseException {
new DateTime("20160101T000000Z"), new DateTime("20160201T000000Z"), Value.DATE, 1));
suite.addTest(new RecurTest(recur, new DateTime("20150917T000000Z"),
new DateTime("20160201T000000Z"), new DateTime("20160301T000000Z"), Value.DATE, 0));

// rrule with bymonth, byday and bysetpos. Issue #39
recur = new Recur("FREQ=MONTHLY;WKST=MO;INTERVAL=1;BYMONTH=2,3,9,10;BYMONTHDAY=28,29,30,31;BYSETPOS=-1");
suite.addTest(new RecurTest(recur, new DateTime("20150701T000000"),
new DateTime("20150701T000000"), new DateTime("20150930T000000")));

return suite;
}
Expand Down

0 comments on commit a2e3c4d

Please sign in to comment.