Commit 5fd0c382 authored by Damien Caliste's avatar Damien Caliste

Check that by day recurrences do not precede dtStart.

parent f61314ea
......@@ -254,3 +254,45 @@ void TimesInIntervalTest::testLocalTimeHandlingAllDay()
}
QCOMPARE(timesInInterval.size(), expectedDays.size());
}
//Test that the recurrence dtStart is used for calculation and not the interval start date
void TimesInIntervalTest::testByDayRecurrence()
{
const int days = 7;
const QDateTime start(QDate(2020, 11, 6), QTime(2, 0, 0), Qt::UTC);
const QDateTime intervalEnd = start.addDays(days);
const QDateTime intervalStart = start.addDays(-days);
Event::Ptr event(new Event());
event->setDtStart(start);
event->setDtEnd(start.addSecs(3600));
RecurrenceRule * const rule = new RecurrenceRule();
rule->setRecurrenceType(RecurrenceRule::rWeekly);
rule->setStartDt(event->dtStart()); // the start day is a Friday
rule->setFrequency(1);
rule->setByDays(QList<RecurrenceRule::WDayPos>()
<< RecurrenceRule::WDayPos(0, 2) // Tuesday
<< RecurrenceRule::WDayPos(0, 3) // Wednesday
<< RecurrenceRule::WDayPos(0, 4) // Thursday
<< RecurrenceRule::WDayPos(0, 5)); // Friday
event->recurrence()->addRRule(rule);
QList<QDateTime> expectedEventOccurrences;
for (int i = 0; i <= days; ++i) {
const QDateTime dt = start.addDays(i);
if (dt.date().dayOfWeek() < 6 && dt.date().dayOfWeek() > 1) {
expectedEventOccurrences << dt;
}
}
QCOMPARE(event->recurrence()->getNextDateTime(intervalStart), start);
QCOMPARE(event->recurrence()->getNextDateTime(start.addDays(1)), start.addDays(4));
const QList<QDateTime> timesInInterval = event->recurrence()->timesInInterval(intervalStart, intervalEnd);
for (const QDateTime &dt : timesInInterval) {
QCOMPARE(expectedEventOccurrences.removeAll(dt), 1);
}
QCOMPARE(expectedEventOccurrences.size(), 0);
}
......@@ -22,6 +22,7 @@ private Q_SLOTS:
void testSubDailyRecurrenceIntervalLimits();
void testLocalTimeHandlingNonAllDay();
void testLocalTimeHandlingAllDay();
void testByDayRecurrence();
};
#endif
......@@ -1772,7 +1772,7 @@ QList<QDateTime> RecurrenceRule::timesInInterval(const QDateTime &dtStart,
return result;
}
QDateTime st = start;
QDateTime st = start < d->mDateStart ? d->mDateStart : start;
bool done = false;
if (d->mDuration > 0) {
if (!d->mCached) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment