Skip to content

Commit

Permalink
fix: Fix without extend schedule
Browse files Browse the repository at this point in the history
It did not extend the calendar for recur date time and schedule end, add
the extend related from original.

Log: Fix without extend schedule issue.
  • Loading branch information
re2zero committed Nov 26, 2024
1 parent e47a5db commit d5a92cf
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
26 changes: 22 additions & 4 deletions calendar-common/src/dschedule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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点
Expand All @@ -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<int>(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)) {
Expand Down Expand Up @@ -457,11 +465,21 @@ QMap<QDate, DSchedule::List> DSchedule::convertSchedules(const DScheduleQueryPar
if (schedule->dtStart() != recurDateTime) {
newSchedule->setRecurrenceId(recurDateTime);
}
scheduleMap[recurDateTime.date()].append(newSchedule);

if (extend) {
//需要扩展的天数
int extenddays = static_cast<int>(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 {
//普通日程
Expand Down
2 changes: 1 addition & 1 deletion calendar-common/src/dschedule.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class DSchedule : public KCalendarCore::Event
static QPair<QString, DSchedule::List> 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<QDate, DSchedule::List> convertSchedules(const DScheduleQueryPar::Ptr &queryPar, const DSchedule::List &scheduleList);
static QMap<QDate, DSchedule::List> fromQueryResult(const QString &query);

Expand Down

0 comments on commit d5a92cf

Please sign in to comment.