Permalink
Browse files

Issue 39. Fix BYMONTH calculation to not break the FREQ constraint

  • Loading branch information...
voronaam committed Sep 23, 2015
1 parent 5bfa8e3 commit a2e3c4de21b2c05edf3b4c61d548ae821fc3fdd9
@@ -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()));
}
}
@@ -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;
}

0 comments on commit a2e3c4d

Please sign in to comment.