add yearly repeating mode

This commit is contained in:
Simon Stürz 2016-04-07 13:33:13 +02:00 committed by Michael Zanetti
parent b4d7bff139
commit 9a85864343
5 changed files with 35 additions and 31 deletions

View File

@ -93,9 +93,11 @@ void CalendarItem::setRepeatingOption(const RepeatingOption &repeatingOption)
*/
bool CalendarItem::isValid() const
{
// A dateTime AND a repeating option would not make sense
// If dateTime AND a repeating option definend...
if (m_dateTime.isValid() && !repeatingOption().isEmtpy())
return false;
// ...only yearly repeating mode is allowed
if (repeatingOption().mode() != RepeatingOption::RepeatingModeYearly)
return false;
return (!m_startTime.isValid() != !m_dateTime.isValid()) && m_duration > 0;
}
@ -103,12 +105,6 @@ bool CalendarItem::isValid() const
/*! Returns true, if the given \a dateTime matches this \l{CalendarItem}. */
bool CalendarItem::evaluate(const QDateTime &dateTime) const
{
if (!isValid())
return false;
if (!repeatingOption().isValid())
return false;
if (m_startTime.isValid()) {
switch (m_repeatingOption.mode()) {
case RepeatingOption::RepeatingModeNone:
@ -122,6 +118,8 @@ bool CalendarItem::evaluate(const QDateTime &dateTime) const
return evaluateWeekly(dateTime);
case RepeatingOption::RepeatingModeMonthly:
return evaluateMonthly(dateTime);
case RepeatingOption::RepeatingModeYearly:
return evaluateYearly(dateTime);
default:
return false;
}
@ -185,16 +183,14 @@ bool CalendarItem::evaluateWeekly(const QDateTime &dateTime) const
QDateTime startDateTime = weekStartDateTime.addDays(weekDay);
QDateTime endDateTime = startDateTime.addSecs(duration() * 60);
// Check if already matches for this week
if (dateTime >= startDateTime && dateTime < endDateTime)
// Return true if the current time is between start
// and end of this calendar item
return true;
// Check if this calendar item overlaps a week
bool overlapping = startDateTime.date().weekNumber() != endDateTime.date().weekNumber();
if (overlapping) {
// Check if already matches for this week
if (dateTime >= startDateTime && dateTime < endDateTime)
// Return true if the current time is between start
// and end of this calendar item
return true;
if (startDateTime.date().weekNumber() != endDateTime.date().weekNumber()) {
// Jump one week into the past
QDateTime startDateTimePreviouseWeek = startDateTime.addDays(-7);
QDateTime endDateTimePreviouseWeek = startDateTimePreviouseWeek.addSecs(duration() * 60);
@ -204,10 +200,6 @@ bool CalendarItem::evaluateWeekly(const QDateTime &dateTime) const
// and end of this calendar item from the previouse week
return true;
} else if (dateTime >= startDateTime && dateTime < endDateTime) {
// Return true if the current time is between start
// and end of this calendar item
return true;
}
}
@ -221,5 +213,12 @@ bool CalendarItem::evaluateMonthly(const QDateTime &dateTime) const
return false;
}
bool CalendarItem::evaluateYearly(const QDateTime &dateTime) const
{
Q_UNUSED(dateTime)
return false;
}
}

View File

@ -59,6 +59,7 @@ private:
bool evaluateDaily(const QDateTime &dateTime) const;
bool evaluateWeekly(const QDateTime &dateTime) const;
bool evaluateMonthly(const QDateTime &dateTime) const;
bool evaluateYearly(const QDateTime &dateTime) const;
};

View File

@ -64,15 +64,17 @@
\value RepeatingModeNone
There is no special repeating mode. The \l{RuleEngine} will assume a daily repeating.
\value RepeatingModeHourly
The time item should be repeated hourly.
The time item should be repeated hourly. The \l{monthDays()} and \l{weekDays()} list has to be empty.
\value RepeatingModeDaily
The time item should be repeated daily.
The time item should be repeated daily. The \l{monthDays()} and \l{weekDays()} list has to be empty.
\value RepeatingModeWeekly
The time item should be repeated weekly. A week starts at Monday. This mode needs a list of \l{weekDays()}.
The \l{monthDays()} list will be ignored.
The \l{monthDays()} list has to empty.
\value RepeatingModeMonthly
The time item should be repeated monthly. This mode needs a list of \l{monthDays()}.
The \l{monthDays()} list will be ignored.
The time item should be repeated every month. This mode needs a list of \l{monthDays()}.
The \l{monthDays()} list has to be empty.
\value RepeatingModeYearly
The time item should be repeated every year. The \l{monthDays()} and \l{weekDays()} list has to be empty.
*/
@ -154,9 +156,11 @@ bool RepeatingOption::isValid() const
return !m_weekDays.isEmpty() && m_monthDays.isEmpty();
case RepeatingModeMonthly:
return m_weekDays.isEmpty() && !m_monthDays.isEmpty();
case RepeatingModeYearly:
return m_weekDays.isEmpty() && m_monthDays.isEmpty();
default:
return false;
}
return false;
}
/*! Returns true if the week day of the given \a dateTime matches this \l{RepeatingOption}. */

View File

@ -39,7 +39,8 @@ public:
RepeatingModeHourly,
RepeatingModeDaily,
RepeatingModeWeekly,
RepeatingModeMonthly
RepeatingModeMonthly,
RepeatingModeYearly
};
RepeatingOption();

View File

@ -412,7 +412,6 @@ void TestTimeManager::testCalendarItemHourly()
// One hour "Back to the future"
future = future.addSecs(3*60*60);
}
}
cleanupMockHistory();
@ -536,7 +535,7 @@ void TestTimeManager::testCalendarItemWeekly_data()
QTest::addColumn<bool>("overlapping");
QTest::newRow("weekly") << createTimeDescriptorCalendar(createCalendarItem("06:55", 10, repeatingOptionWeekly)) << repeatingOptionWeekly << "06:55" << false;
QTest::newRow("weekly - always") << createTimeDescriptorCalendar(createCalendarItem("06:55", 10080)) << QVariantMap() << "06:55" << false;
QTest::newRow("weekly - always") << createTimeDescriptorCalendar(createCalendarItem("22:34", 10080)) << QVariantMap() << "22:34" << false;
QTest::newRow("weekly - overlapping") << createTimeDescriptorCalendar(createCalendarItem("08:00", 2880, repeatingOptionWeeklyOverlapping)) << repeatingOptionWeeklyOverlapping << "08:00" << true;
}