Skip to content
This repository has been archived by the owner on Nov 11, 2021. It is now read-only.

Commit

Permalink
[kcalcore] Check that interval-constrained recurrences do not precede…
Browse files Browse the repository at this point in the history
… dtStart. Contributes to JB#43708
  • Loading branch information
Chris Adams committed Oct 17, 2019
1 parent a965fab commit 6fa6ee8
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
5 changes: 5 additions & 0 deletions kcalcore/recurrencerule.cpp
Expand Up @@ -2008,6 +2008,11 @@ DateTimeList RecurrenceRule::Private::datesForInterval( const Constraint &interv
// We have a valid constraint, so get all datetimes that match it andd
// append it to all date/times of this interval
QList<KDateTime> lstnew = merged.dateTimes( type );
lstnew.erase(std::remove_if(lstnew.begin(), lstnew.end(),
[this](const KDateTime &dt) {
return dt < mDateStart;
}),
lstnew.end());
lst += lstnew;
}
}
Expand Down
30 changes: 30 additions & 0 deletions kcalcore/tests/testtimesininterval.cpp
Expand Up @@ -153,3 +153,33 @@ void TimesInIntervalTest::testSubDailyRecurrenceIntervalLimits()
}
QCOMPARE(expectedEventOccurrences.size(), 0);
}

//Test that the recurrence dtStart is used for calculation and not the interval start date
void TimesInIntervalTest::testDailyRecurrenceDtStart()
{
const int days = 7;
const KDateTime start(QDate(2013, 03, 10), QTime(0, 0, 0), KDateTime::ClockTime);
const KDateTime intervalEnd = start.addDays(days);
const KDateTime intervalStart = start.addDays(-days);

KCalCore::Event::Ptr event(new KCalCore::Event());
event->setUid("event");
event->setDtStart(start);
event->setDtEnd( start.addDays( 1 ) );
event->setAllDay( true );
event->setSummary( "Event2 Summary" );

event->recurrence()->setDaily( 1 );

QList<KDateTime> expectedEventOccurrences;
for (int i = 0; i < days; ++i) {
expectedEventOccurrences << start.addDays(i);
}

const DateTimeList timesInInterval = event->recurrence()->timesInInterval(intervalStart, intervalEnd);
foreach (const KDateTime &dt, timesInInterval) {
QCOMPARE(expectedEventOccurrences.removeAll(dt), 1);
}

QCOMPARE(expectedEventOccurrences.size(), 0);
}
1 change: 1 addition & 0 deletions kcalcore/tests/testtimesininterval.h
Expand Up @@ -33,6 +33,7 @@ class TimesInIntervalTest : public QObject
void testSubDailyRecurrenceIntervalInclusive();
void testSubDailyRecurrence2();
void testSubDailyRecurrenceIntervalLimits();
void testDailyRecurrenceDtStart();
};

#endif

0 comments on commit 6fa6ee8

Please sign in to comment.