summaryrefslogtreecommitdiffstats
path: root/kalarm/recurrenceedit.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'kalarm/recurrenceedit.cpp')
-rw-r--r--kalarm/recurrenceedit.cpp93
1 files changed, 93 insertions, 0 deletions
diff --git a/kalarm/recurrenceedit.cpp b/kalarm/recurrenceedit.cpp
index 4a39022e4..1389f54e4 100644
--- a/kalarm/recurrenceedit.cpp
+++ b/kalarm/recurrenceedit.cpp
@@ -531,6 +531,99 @@ void RecurrenceEdit::activateSubRepetition()
}
/******************************************************************************
+* For weekly, monthly and yearly recurrence, checks that the specified date
+* matches the days allowed. For the other recurrence simply return true.
+*/
+bool RecurrenceEdit::validateDate(const DateTime &date) const
+{
+ if (mRuleButtonType == RecurrenceEdit::DAILY)
+ {
+ TQBitArray selectedDays = mDailyRule->days();
+ if (!selectedDays[date.date().dayOfWeek()-1])
+ return false;
+ }
+ else if (mRuleButtonType == RecurrenceEdit::WEEKLY)
+ {
+ TQBitArray selectedDays = mWeeklyRule->days();
+ if (!selectedDays[date.date().dayOfWeek()-1])
+ return false;
+ }
+ else if (mRuleButtonType == RecurrenceEdit::MONTHLY)
+ {
+ if (mMonthlyRule->type() == MonthYearRule::DATE)
+ {
+ // on the nth day of the month
+ int comboDate = mMonthlyRule->date();
+ if ((comboDate > 0 && date.date().day() != comboDate) ||
+ (comboDate <=0 && date.date().day() != date.date().daysInMonth()))
+ return false;
+ }
+ else
+ {
+ // on the nth weekday (i.e. Monday) of the month
+ if (date.date().dayOfWeek() != mMonthlyRule->dayOfWeek())
+ return false;
+
+ int monthDay = date.date().day();
+ int weekNum = mMonthlyRule->week();
+ int minDay = 0, maxDay = 0;
+ if (weekNum > 0 )
+ {
+ minDay = (weekNum-1) * 7;
+ maxDay = weekNum * 7;
+ }
+ else if (weekNum < 0)
+ {
+ int dim = date.date().daysInMonth();
+ minDay = dim + weekNum * 7;
+ maxDay = dim + (weekNum+1) * 7;
+ }
+ if (monthDay <= minDay || monthDay > maxDay)
+ return false;
+ }
+ }
+ else if (mRuleButtonType == RecurrenceEdit::ANNUAL)
+ {
+ TQValueList<int> months = mYearlyRule->months();
+ if (!months.contains(date.date().month()))
+ return false;
+
+ if (mYearlyRule->type() == MonthYearRule::DATE)
+ {
+ // on the nth day of the month
+ int comboDate = mYearlyRule->date();
+ if ((comboDate > 0 && date.date().day() != comboDate) ||
+ (comboDate <=0 && date.date().day() != date.date().daysInMonth()))
+ return false;
+ }
+ else
+ {
+ // on the nth weekday (i.e. Monday) of the month
+ if (date.date().dayOfWeek() != mYearlyRule->dayOfWeek())
+ return false;
+
+ int monthDay = date.date().day();
+ int weekNum = mYearlyRule->week();
+ int minDay = 0, maxDay = 0;
+ if (weekNum > 0 )
+ {
+ minDay = (weekNum-1) * 7;
+ maxDay = weekNum * 7;
+ }
+ else if (weekNum < 0)
+ {
+ int dim = date.date().daysInMonth();
+ minDay = dim + weekNum * 7;
+ maxDay = dim + (weekNum+1) * 7;
+ }
+ if (monthDay <= minDay || monthDay > maxDay)
+ return false;
+ }
+ }
+ return true;
+}
+
+/******************************************************************************
* Called when the value of the repeat count field changes, to reset the
* minimum value to 1 if the value was 0.
*/