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

Commit

Permalink
[kcalcore] Make MemoryCalendar::rawEvents(QDate, QDate) works for ope…
Browse files Browse the repository at this point in the history
…n bounds

This is upstream commit 9995c9de with adaptation for KDateTime.
  • Loading branch information
dcaliste committed Oct 13, 2020
1 parent e780f92 commit d3d28ed
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 6 deletions.
12 changes: 6 additions & 6 deletions kcalcore/memorycalendar.cpp
Expand Up @@ -648,19 +648,19 @@ Event::List MemoryCalendar::rawEvents( const QDate &start,
i.next();
event = i.value().staticCast<Event>();
KDateTime rStart = event->dtStart();
if ( nd < rStart ) {
if ( nd.isValid() && nd < rStart ) {
continue;
}
if ( inclusive && rStart < st ) {
if ( inclusive && st.isValid() && rStart < st ) {
continue;
}

if ( !event->recurs() ) { // non-recurring events
KDateTime rEnd = event->dtEnd();
if ( rEnd < st ) {
if ( st.isValid() && rEnd < st ) {
continue;
}
if ( inclusive && nd < rEnd ) {
if ( inclusive && nd.isValid() && nd < rEnd ) {
continue;
}
} else { // recurring events
Expand All @@ -676,10 +676,10 @@ Event::List MemoryCalendar::rawEvents( const QDate &start,
if ( !rEnd.isValid() ) {
continue;
}
if ( rEnd < st ) {
if ( st.isValid() && rEnd < st ) {
continue;
}
if ( inclusive && nd < rEnd ) {
if ( inclusive && nd.isValid() && nd < rEnd ) {
continue;
}
break;
Expand Down
49 changes: 49 additions & 0 deletions kcalcore/tests/testmemorycalendar.cpp
Expand Up @@ -174,6 +174,55 @@ void MemoryCalendarTest::testRelationsCrash()
cal->close();
}

void MemoryCalendarTest::testRawEvents()
{
MemoryCalendar::Ptr cal(new MemoryCalendar(KDateTime::UTC));

Event::Ptr event = Event::Ptr(new Event());
// This event span in 20201011T2330Z - 20201012T2330Z
event->setDtStart(KDateTime(QDate(2020, 10, 12), QTime(1, 30),
KSystemTimeZones::zone("Europe/Paris")));
event->setDtEnd(KDateTime(QDate(2020, 10, 13), QTime(1, 30),
KSystemTimeZones::zone("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), KSystemTimeZones::zone("Europe/Paris")).count(), 0);
QCOMPARE(cal->rawEvents(QDate(2020, 10, 12), QDate(2020, 10, 12), KSystemTimeZones::zone("Europe/Paris")).count(), 1);
QCOMPARE(cal->rawEvents(QDate(2020, 10, 13), QDate(2020, 10, 13), KSystemTimeZones::zone("Europe/Paris")).count(), 1);
QCOMPARE(cal->rawEvents(QDate(2020, 10, 14), QDate(2020, 10, 31), KSystemTimeZones::zone("Europe/Paris")).count(), 0);
QCOMPARE(cal->rawEvents(QDate(), QDate(2020, 10, 11), KSystemTimeZones::zone("Europe/Paris")).count(), 0);
QCOMPARE(cal->rawEvents(QDate(), QDate(2020, 10, 12), KSystemTimeZones::zone("Europe/Paris")).count(), 1);
QCOMPARE(cal->rawEvents(QDate(2020, 10, 14), QDate(), KSystemTimeZones::zone("Europe/Paris")).count(), 0);
QCOMPARE(cal->rawEvents(QDate(2020, 10, 13), QDate(), KSystemTimeZones::zone("Europe/Paris")).count(), 1);

// Full event must be in the span.
QCOMPARE(cal->rawEvents(QDate(2020, 10, 1), QDate(2020, 10, 10), KDateTime::Spec(), true).count(), 0);
QCOMPARE(cal->rawEvents(QDate(2020, 10, 11), QDate(2020, 10, 11), KDateTime::Spec(), true).count(), 0);
QCOMPARE(cal->rawEvents(QDate(2020, 10, 12), QDate(2020, 10, 12), KDateTime::Spec(), true).count(), 0);
QCOMPARE(cal->rawEvents(QDate(2020, 10, 11), QDate(2020, 10, 12), KDateTime::Spec(), true).count(), 1);
QCOMPARE(cal->rawEvents(QDate(2020, 10, 13), QDate(2020, 10, 31), KDateTime::Spec(), true).count(), 0);
QCOMPARE(cal->rawEvents(QDate(), QDate(2020, 10, 10), KDateTime::Spec(), true).count(), 0);
QCOMPARE(cal->rawEvents(QDate(), QDate(2020, 10, 11), KDateTime::Spec(), true).count(), 0);
QCOMPARE(cal->rawEvents(QDate(), QDate(2020, 10, 12), KDateTime::Spec(), true).count(), 1);
QCOMPARE(cal->rawEvents(QDate(2020, 10, 13), QDate(), KDateTime::Spec(), true).count(), 0);
QCOMPARE(cal->rawEvents(QDate(2020, 10, 12), QDate(), KDateTime::Spec(), true).count(), 0);
QCOMPARE(cal->rawEvents(QDate(2020, 10, 11), QDate(), KDateTime::Spec(), true).count(), 1);

cal->close();
}

void MemoryCalendarTest::testRawEventsForDate()
{
// We're checking that events at a date in a given time zone
Expand Down
1 change: 1 addition & 0 deletions kcalcore/tests/testmemorycalendar.h
Expand Up @@ -32,6 +32,7 @@ class MemoryCalendarTest : public QObject
void testEvents();
void testIncidences();
void testRelationsCrash();
void testRawEvents();
void testRawEventsForDate();
};

Expand Down

0 comments on commit d3d28ed

Please sign in to comment.