From 1e0883847221beb631b7ca3e5ad6f1f7f4d2978e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20St=C3=BCrz?= Date: Thu, 7 Apr 2016 13:52:32 +0200 Subject: [PATCH] bump api version --- guh.pri | 2 +- server/time/calendaritem.cpp | 33 +++++++++++++++++++++++++++++---- tests/auto/api.json | 3 ++- 3 files changed, 32 insertions(+), 6 deletions(-) diff --git a/guh.pri b/guh.pri index 663370c0..2c91214f 100644 --- a/guh.pri +++ b/guh.pri @@ -2,7 +2,7 @@ GUH_VERSION_STRING=$$system('dpkg-parsechangelog | sed -n -e "s/^Version: //p"') # define protocol versions -JSON_PROTOCOL_VERSION=39 +JSON_PROTOCOL_VERSION=40 REST_API_VERSION=1 DEFINES += GUH_VERSION_STRING=\\\"$${GUH_VERSION_STRING}\\\" \ diff --git a/server/time/calendaritem.cpp b/server/time/calendaritem.cpp index 051d3985..28939847 100644 --- a/server/time/calendaritem.cpp +++ b/server/time/calendaritem.cpp @@ -183,15 +183,15 @@ 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 + // Check if dateTime 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 + // Check if this calendar item overlaps a week... if (startDateTime.date().weekNumber() != endDateTime.date().weekNumber()) { - // Jump one week into the past + // ...jump one week back in to the past QDateTime startDateTimePreviouseWeek = startDateTime.addDays(-7); QDateTime endDateTimePreviouseWeek = startDateTimePreviouseWeek.addSecs(duration() * 60); @@ -208,7 +208,32 @@ bool CalendarItem::evaluateWeekly(const QDateTime &dateTime) const bool CalendarItem::evaluateMonthly(const QDateTime &dateTime) const { - Q_UNUSED(dateTime) + // Get the first day of this month with the correct start time + QDateTime monthStartDateTime = QDateTime(QDate(dateTime.date().year(), dateTime.date().month(), 1), m_startTime); + + // Check each week day in the list + foreach (const int &monthDay, repeatingOption().monthDays()) { + QDateTime startDateTime = monthStartDateTime.addDays(monthDay - 1); + QDateTime endDateTime = startDateTime.addSecs(duration() * 60); + + // Check if dateTime already matches for this month + 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 month... + if (startDateTime.date().month() != endDateTime.date().month()) { + // ...jump one month back in to the past + QDateTime startDateTimePreviouseMonth = startDateTime.addMonths(-1); + QDateTime endDateTimePreviouseMonth = startDateTimePreviouseMonth.addSecs(duration() * 60); + + if (dateTime >= startDateTimePreviouseMonth && dateTime < endDateTimePreviouseMonth) + // Return true if the current time is between start + // and end of this calendar item from the previouse month + return true; + } + } return false; } diff --git a/tests/auto/api.json b/tests/auto/api.json index 8743d850..8f62dfbc 100644 --- a/tests/auto/api.json +++ b/tests/auto/api.json @@ -804,7 +804,8 @@ "RepeatingModeHourly", "RepeatingModeDaily", "RepeatingModeWeekly", - "RepeatingModeMonthly" + "RepeatingModeMonthly", + "RepeatingModeYearly" ], "RepeatingOption": { "mode": "$ref:RepeatingMode",