Commit b0d38456 authored by Damien Caliste's avatar Damien Caliste

Make MemoryCalendar::rawEvents(QDate, QDate) works for open bounds

MemoryCalendar::rawTodos() can already use open bounds, but
rawEvents() cannot. This patch is fixing this and is adding
a non-regression test for events.
parent 1ca24c0e
...@@ -326,3 +326,52 @@ void MemoryCalendarTest::testVisibility() ...@@ -326,3 +326,52 @@ void MemoryCalendarTest::testVisibility()
QVERIFY(!cal->isVisible(notebook)); QVERIFY(!cal->isVisible(notebook));
QVERIFY(!cal->isVisible(event)); QVERIFY(!cal->isVisible(event));
} }
void MemoryCalendarTest::testRawEvents()
{
MemoryCalendar::Ptr cal(new MemoryCalendar(QTimeZone::utc()));
Event::Ptr event = Event::Ptr(new Event());
// This event span in 20201011T2330Z - 20201012T2330Z
event->setDtStart(QDateTime(QDate(2020, 10, 12), QTime(1, 30),
QTimeZone("Europe/Paris")));
event->setDtEnd(QDateTime(QDate(2020, 10, 13), QTime(1, 30),
QTimeZone("Europe/Paris")));
QVERIFY(cal->addEvent(event));
// Not full-event inclusive by default, UTC timezone.
QCOMPARE(cal->rawEvents(QDate(2020, 10, 1), QDate(2020, 10, 10)).count(), 0);
QCOMPARE(cal->rawEvents(QDate(2020, 10, 11), QDate(2020, 10, 11)).count(), 1);
QCOMPARE(cal->rawEvents(QDate(2020, 10, 12), QDate(2020, 10, 12)).count(), 1);
QCOMPARE(cal->rawEvents(QDate(2020, 10, 13), QDate(2020, 10, 31)).count(), 0);
QCOMPARE(cal->rawEvents(QDate(), QDate(2020, 10, 10)).count(), 0);
QCOMPARE(cal->rawEvents(QDate(), QDate(2020, 10, 11)).count(), 1);
QCOMPARE(cal->rawEvents(QDate(2020, 10, 13), QDate()).count(), 0);
QCOMPARE(cal->rawEvents(QDate(2020, 10, 12), QDate()).count(), 1);
// Changing the time zone we are considering the dates in.
QCOMPARE(cal->rawEvents(QDate(2020, 10, 1), QDate(2020, 10, 11), QTimeZone("Europe/Paris")).count(), 0);
QCOMPARE(cal->rawEvents(QDate(2020, 10, 12), QDate(2020, 10, 12), QTimeZone("Europe/Paris")).count(), 1);
QCOMPARE(cal->rawEvents(QDate(2020, 10, 13), QDate(2020, 10, 13), QTimeZone("Europe/Paris")).count(), 1);
QCOMPARE(cal->rawEvents(QDate(2020, 10, 14), QDate(2020, 10, 31), QTimeZone("Europe/Paris")).count(), 0);
QCOMPARE(cal->rawEvents(QDate(), QDate(2020, 10, 11), QTimeZone("Europe/Paris")).count(), 0);
QCOMPARE(cal->rawEvents(QDate(), QDate(2020, 10, 12), QTimeZone("Europe/Paris")).count(), 1);
QCOMPARE(cal->rawEvents(QDate(2020, 10, 14), QDate(), QTimeZone("Europe/Paris")).count(), 0);
QCOMPARE(cal->rawEvents(QDate(2020, 10, 13), QDate(), QTimeZone("Europe/Paris")).count(), 1);
// Full event must be in the span.
QCOMPARE(cal->rawEvents(QDate(2020, 10, 1), QDate(2020, 10, 10), QTimeZone(), true).count(), 0);
QCOMPARE(cal->rawEvents(QDate(2020, 10, 11), QDate(2020, 10, 11), QTimeZone(), true).count(), 0);
QCOMPARE(cal->rawEvents(QDate(2020, 10, 12), QDate(2020, 10, 12), QTimeZone(), true).count(), 0);
QCOMPARE(cal->rawEvents(QDate(2020, 10, 11), QDate(2020, 10, 12), QTimeZone(), true).count(), 1);
QCOMPARE(cal->rawEvents(QDate(2020, 10, 13), QDate(2020, 10, 31), QTimeZone(), true).count(), 0);
QCOMPARE(cal->rawEvents(QDate(), QDate(2020, 10, 10), QTimeZone(), true).count(), 0);
QCOMPARE(cal->rawEvents(QDate(), QDate(2020, 10, 11), QTimeZone(), true).count(), 0);
QCOMPARE(cal->rawEvents(QDate(), QDate(2020, 10, 12), QTimeZone(), true).count(), 1);
QCOMPARE(cal->rawEvents(QDate(2020, 10, 13), QDate(), QTimeZone(), true).count(), 0);
QCOMPARE(cal->rawEvents(QDate(2020, 10, 12), QDate(), QTimeZone(), true).count(), 0);
QCOMPARE(cal->rawEvents(QDate(2020, 10, 11), QDate(), QTimeZone(), true).count(), 1);
cal->close();
}
...@@ -22,6 +22,7 @@ private Q_SLOTS: ...@@ -22,6 +22,7 @@ private Q_SLOTS:
void testRelationsCrash(); void testRelationsCrash();
void testRecurrenceExceptions(); void testRecurrenceExceptions();
void testChangeRecurId(); void testChangeRecurId();
void testRawEvents();
void testRawEventsForDate(); void testRawEventsForDate();
void testVisibility(); void testVisibility();
}; };
......
...@@ -620,19 +620,19 @@ Event::List MemoryCalendar::rawEvents(const QDate &start, ...@@ -620,19 +620,19 @@ Event::List MemoryCalendar::rawEvents(const QDate &start,
for (const auto &e: d->mIncidences[Incidence::TypeEvent]) { for (const auto &e: d->mIncidences[Incidence::TypeEvent]) {
const auto event = e.staticCast<Event>(); const auto event = e.staticCast<Event>();
QDateTime rStart = event->dtStart(); QDateTime rStart = event->dtStart();
if (nd < rStart) { if (nd.isValid() && nd < rStart) {
continue; continue;
} }
if (inclusive && rStart < st) { if (inclusive && st.isValid() && rStart < st) {
continue; continue;
} }
if (!event->recurs()) { // non-recurring events if (!event->recurs()) { // non-recurring events
QDateTime rEnd = event->dtEnd(); QDateTime rEnd = event->dtEnd();
if (rEnd < st) { if (st.isValid() && rEnd < st) {
continue; continue;
} }
if (inclusive && nd < rEnd) { if (inclusive && nd.isValid() && nd < rEnd) {
continue; continue;
} }
} else { // recurring events } else { // recurring events
...@@ -648,10 +648,10 @@ Event::List MemoryCalendar::rawEvents(const QDate &start, ...@@ -648,10 +648,10 @@ Event::List MemoryCalendar::rawEvents(const QDate &start,
if (!rEnd.isValid()) { if (!rEnd.isValid()) {
continue; continue;
} }
if (rEnd < st) { if (st.isValid() && rEnd < st) {
continue; continue;
} }
if (inclusive && nd < rEnd) { if (inclusive && nd.isValid() && nd < rEnd) {
continue; continue;
} }
break; break;
......
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