Skip to content

Commit

Permalink
[nemo-qml-plugin-calendar] Separate monthly recurrence on 4th or 5th …
Browse files Browse the repository at this point in the history
…week with the last week.
  • Loading branch information
dcaliste committed Jun 6, 2020
1 parent be3e948 commit a74f6d9
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/calendarevent.h
Expand Up @@ -78,6 +78,7 @@ class CalendarEvent : public QObject
RecurWeeklyByDays,
RecurMonthly,
RecurMonthlyByDayOfWeek,
RecurMonthlyByLastDayOfWeek,
RecurYearly,
RecurCustom
};
Expand Down
8 changes: 5 additions & 3 deletions src/calendarutils.cpp
Expand Up @@ -78,9 +78,11 @@ CalendarEvent::Recur CalendarUtils::convertRecurrence(const KCalCore::Event::Ptr
const QList<KCalCore::RecurrenceRule::WDayPos> monthPositions = event->recurrence()->monthPositions();
if (monthPositions.length() == 1
&& monthPositions.first().day() == event->dtStart().date().dayOfWeek()) {
return CalendarEvent::RecurMonthlyByDayOfWeek;
} else {
return CalendarEvent::RecurCustom;
if (monthPositions.first().pos() > 0) {
return CalendarEvent::RecurMonthlyByDayOfWeek;
} else if (monthPositions.first().pos() == -1) {
return CalendarEvent::RecurMonthlyByLastDayOfWeek;
}
}
} else if (rt == KCalCore::Recurrence::rYearlyMonth && freq == 1) {
return CalendarEvent::RecurYearly;
Expand Down
13 changes: 8 additions & 5 deletions src/calendarworker.cpp
Expand Up @@ -348,6 +348,7 @@ bool CalendarWorker::setRecurrence(KCalCore::Event::Ptr &event, CalendarEvent::R

if (oldRecur != recur
|| recur == CalendarEvent::RecurMonthlyByDayOfWeek
|| recur == CalendarEvent::RecurMonthlyByLastDayOfWeek
|| recur == CalendarEvent::RecurWeeklyByDays) {
switch (recur) {
case CalendarEvent::RecurOnce:
Expand Down Expand Up @@ -379,11 +380,13 @@ bool CalendarWorker::setRecurrence(KCalCore::Event::Ptr &event, CalendarEvent::R
case CalendarEvent::RecurMonthlyByDayOfWeek: {
event->recurrence()->setMonthly(1);
const QDate at(event->dtStart().date());
if (at.addDays(7).month() == at.month()) {
event->recurrence()->addMonthlyPos((at.day() - 1) / 7 + 1, at.dayOfWeek());
} else {
event->recurrence()->addMonthlyPos(-1, at.dayOfWeek());
}
event->recurrence()->addMonthlyPos((at.day() - 1) / 7 + 1, at.dayOfWeek());
break;
}
case CalendarEvent::RecurMonthlyByLastDayOfWeek: {
event->recurrence()->setMonthly(1);
const QDate at(event->dtStart().date());
event->recurrence()->addMonthlyPos(-1, at.dayOfWeek());
break;
}
case CalendarEvent::RecurYearly:
Expand Down
1 change: 1 addition & 0 deletions tests/tst_calendarevent/tst_calendarevent.cpp
Expand Up @@ -435,6 +435,7 @@ void tst_CalendarEvent::testRecurrence_data()
QTest::newRow("Every two weeks") << CalendarEvent::RecurBiweekly;
QTest::newRow("Every month") << CalendarEvent::RecurMonthly;
QTest::newRow("Every month on same day of week") << CalendarEvent::RecurMonthlyByDayOfWeek;
QTest::newRow("Every month on last day of week") << CalendarEvent::RecurMonthlyByLastDayOfWeek;
QTest::newRow("Every year") << CalendarEvent::RecurYearly;
}

Expand Down

0 comments on commit a74f6d9

Please sign in to comment.