diff --git a/kcalcore/occurrenceiterator.cpp b/kcalcore/occurrenceiterator.cpp --- a/kcalcore/occurrenceiterator.cpp +++ b/kcalcore/occurrenceiterator.cpp @@ -109,17 +109,27 @@ continue; } if (inc->recurs()) { + Incidence::Ptr incidence(inc), lastInc(inc); + qint64 offset(0), lastOffset(0); + KDateTime occurrenceStartDate; + QHash recurrenceIds; KDateTime incidenceRecStart = inc->dateTime(Incidence::RoleRecurrenceStart); foreach(const Incidence::Ptr &exception, calendar.instances(inc)) { if (incidenceRecStart.isValid()) recurrenceIds.insert(exception->recurrenceId().toTimeSpec(incidenceRecStart.timeSpec()), exception); + + // For exceptions with thisAndFuture we need to store this as incidence, if the exception has already happend + // We don't have a sorted list of exception, that's why we have to test the current recurrenceId against the stored + if (exception->thisAndFuture() && start >= exception->recurrenceId() + && (!incidence->recurrenceId().isValid() || incidence->recurrenceId() < exception->recurrenceId())) { + incidence = exception; + occurrenceStartDate = incidence->dtStart(); + offset = incidence->recurrenceId().secsTo_long(incidence->dtStart()); + } } const bool isAllDay = inc->allDay(); const DateTimeList occurrences = inc->recurrence()->timesInInterval(start, end); - Incidence::Ptr incidence(inc), lastInc(inc); - qint64 offset(0), lastOffset(0); - KDateTime occurrenceStartDate; foreach(KDateTime recurrenceId, occurrences) { //krazy:exclude=foreach //timesInInterval generates always date-times, //which is not what we want for all-day events