[california/wip/732930-explain] Enforce preconditions when explaining various RRULEs
- From: Jim Nelson <jnelson src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [california/wip/732930-explain] Enforce preconditions when explaining various RRULEs
- Date: Fri, 5 Sep 2014 22:40:28 +0000 (UTC)
commit 1ff34543c335bf9d3ed3f2eddbdc8c7bce629fad
Author: Jim Nelson <jim yorba org>
Date: Fri Sep 5 15:34:23 2014 -0700
Enforce preconditions when explaining various RRULEs
src/component/component-recurrence-rule.vala | 31 ++++++++++++++++++-------
1 files changed, 22 insertions(+), 9 deletions(-)
---
diff --git a/src/component/component-recurrence-rule.vala b/src/component/component-recurrence-rule.vala
index 5428ffb..0a9286c 100644
--- a/src/component/component-recurrence-rule.vala
+++ b/src/component/component-recurrence-rule.vala
@@ -600,12 +600,12 @@ public class RecurrenceRule : BaseObject {
return explain_weekly(ngettext("week", "%d weeks", interval).printf(interval));
case iCal.icalrecurrencetype_frequency.MONTHLY_RECURRENCE:
- Gee.Set<ByRule> active = get_active_by_rules();
- bool has_byday = active.contains(ByRule.DAY);
- bool has_bymonthday = active.contains(ByRule.MONTH_DAY);
+ Gee.Set<ByRule> byrules = get_active_by_rules();
+ bool has_byday = byrules.contains(ByRule.DAY);
+ bool has_bymonthday = byrules.contains(ByRule.MONTH_DAY);
// requires one and only one
- if (has_byday == has_bymonthday || active.size > 1)
+ if (has_byday == has_bymonthday || byrules.size != 1)
return null;
string unit = ngettext("month", "%d months", interval).printf(interval);
@@ -624,7 +624,11 @@ public class RecurrenceRule : BaseObject {
}
- private string explain_daily(string units) {
+ private string? explain_daily(string units) {
+ // only explain basic DAILY RRULEs
+ if (get_active_by_rules().size != 0)
+ return null;
+
if (count > 0) {
// As in, "Repeats every day, 2 times"
return _("Repeats every %s, %s").printf(units,
@@ -699,9 +703,9 @@ public class RecurrenceRule : BaseObject {
}
private string? explain_weekly(string units) {
- // can only explain BYDAY rules
- Gee.Set<ByRule> active = get_active_by_rules();
- if (!active.contains(ByRule.DAY) || active.size == 0)
+ // can only explain WEEKLY BYDAY rules
+ Gee.Set<ByRule> byrules = get_active_by_rules();
+ if (byrules.size != 1 || !byrules.contains(ByRule.DAY))
return null;
string? days_of_the_week = explain_days_of_the_week();
@@ -812,6 +816,11 @@ public class RecurrenceRule : BaseObject {
}
private string? explain_monthly_bymonthday(string units) {
+ // only MONTHLY BYDAY RRULEs
+ Gee.Set<int> byrules = get_active_by_rules();
+ if (byrules.size != 1 || !byrules.contains(ByRule.MONTH_DAY))
+ return null;
+
// currently only support one monthday (generally, the same as DTSTART)
Gee.Set<int> monthdays = get_by_rule(ByRule.MONTH_DAY);
if (monthdays.size != 1)
@@ -846,7 +855,11 @@ public class RecurrenceRule : BaseObject {
return _("Repeats every %s on %s").printf(units, day);
}
- private string explain_yearly(string units, Calendar.Date start_date) {
+ private string? explain_yearly(string units, Calendar.Date start_date) {
+ // only explain basic YEARLY RRULEs
+ if (get_active_by_rules().size != 0)
+ return null;
+
string date = start_date.to_pretty_string(
Calendar.Date.PrettyFlag.NO_DAY_OF_WEEK
| Calendar.Date.PrettyFlag.NO_TODAY
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]