diff --git a/calendar-common/src/dschedule.cpp b/calendar-common/src/dschedule.cpp index e7a11d59..882ab946 100644 --- a/calendar-common/src/dschedule.cpp +++ b/calendar-common/src/dschedule.cpp @@ -391,7 +391,7 @@ QString DSchedule::toListString(const QString &query, const DSchedule::List &sch return QString::fromUtf8(jsonDoc.toJson(QJsonDocument::Compact)); } -void DSchedule::expendRecurrence(DSchedule::Map &scheduleMap, const DSchedule::Ptr &schedule, const QDateTime &dtStart, const QDateTime &dtEnd) +void DSchedule::expendRecurrence(DSchedule::Map &scheduleMap, const DSchedule::Ptr &schedule, const QDateTime &dtStart, const QDateTime &dtEnd, bool extend) { QDateTime queryDtStart = dtStart; //如果日程为全天日程,则查询的开始时间设置为0点,因为全天日程的开始和结束时间都是0点 @@ -412,7 +412,15 @@ void DSchedule::expendRecurrence(DSchedule::Map &scheduleMap, const DSchedule::P if (schedule->dtStart() != dt) { newSchedule->setRecurrenceId(dt); } - scheduleMap[dt.date()].append(newSchedule); + if (extend) { + //需要扩展的天数 + int extenddays = static_cast(dt.daysTo(scheduleDtEnd)); + for (int i = 0; i <= extenddays; ++i) { + scheduleMap[dt.date().addDays(i)].append(newSchedule); + } + } else { + scheduleMap[dt.date()].append(newSchedule); + } } } else { if (!(schedule->dtStart() > dtEnd || schedule->dtEnd() < queryDtStart)) { @@ -457,11 +465,21 @@ QMap DSchedule::convertSchedules(const DScheduleQueryPar if (schedule->dtStart() != recurDateTime) { newSchedule->setRecurrenceId(recurDateTime); } - scheduleMap[recurDateTime.date()].append(newSchedule); + + if (extend) { + //需要扩展的天数 + int extenddays = static_cast(recurDateTime.daysTo(copyEnd)); + for (int i = 0; i <= extenddays; ++i) { + scheduleMap[recurDateTime.date().addDays(i)].append(newSchedule); + } + + } else { + scheduleMap[recurDateTime.date()].append(newSchedule); + } } } else { //非农历日程 - expendRecurrence(scheduleMap, schedule, dtStart, dtEnd); + expendRecurrence(scheduleMap, schedule, dtStart, dtEnd, extend); } } else { //普通日程 diff --git a/calendar-common/src/dschedule.h b/calendar-common/src/dschedule.h index d47c5f9b..1cb44d9a 100644 --- a/calendar-common/src/dschedule.h +++ b/calendar-common/src/dschedule.h @@ -96,7 +96,7 @@ class DSchedule : public KCalendarCore::Event static QPair fromListString(const QString &json); static QString toListString(const QString &query, const DSchedule::List &scheduleList); - static void expendRecurrence(DSchedule::Map &scheduleMap, const DSchedule::Ptr &schedule, const QDateTime &dtStart, const QDateTime &dtEnd); + static void expendRecurrence(DSchedule::Map &scheduleMap, const DSchedule::Ptr &schedule, const QDateTime &dtStart, const QDateTime &dtEnd, bool extend); static QMap convertSchedules(const DScheduleQueryPar::Ptr &queryPar, const DSchedule::List &scheduleList); static QMap fromQueryResult(const QString &query);