Merge lp:~kjtehprogrammer/maya/bug-1441262 into lp:~elementary-apps/maya/trunk

Proposed by KJ Lawrence
Status: Merged
Approved by: Corentin Noël
Approved revision: 898
Merged at revision: 899
Proposed branch: lp:~kjtehprogrammer/maya/bug-1441262
Merge into: lp:~elementary-apps/maya/trunk
Diff against target: 197 lines (+49/-53)
4 files modified
core/DateRange.vala (+0/-1)
core/Utils.vala (+43/-47)
src/AgendaView.vala (+5/-4)
src/EventEdition/InfoPanel.vala (+1/-1)
To merge this branch: bzr merge lp:~kjtehprogrammer/maya/bug-1441262
Reviewer Review Type Date Requested Status
Corentin Noël Approve
Review via email: mp+292721@code.launchpad.net

Commit message

Fixes recurring events

Description of the change

Updated my original commit of this bug for the recent changes to Maya.

Not quite sure what all I originally did. I believe I fixed the loops that were done to calculate the days recurring events would appear on.

To post a comment you must log in.
Revision history for this message
Corentin Noël (tintou) wrote :

It's indeed a better way to calculate the repeating events

Revision history for this message
Corentin Noël (tintou) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'core/DateRange.vala'
2--- core/DateRange.vala 2014-12-27 19:24:57 +0000
3+++ core/DateRange.vala 2016-04-24 03:55:32 +0000
4@@ -84,7 +84,6 @@
5 }
6
7 public DateRange (DateTime first, DateTime last) {
8- assert (first.compare(last)<=0);
9 this.first = first;
10 this.last = last;
11 }
12
13=== modified file 'core/Utils.vala'
14--- core/Utils.vala 2016-01-18 23:25:24 +0000
15+++ core/Utils.vala 2016-04-24 03:55:32 +0000
16@@ -123,7 +123,7 @@
17 if (end == null) end = start;
18
19 // All days events are stored in UTC time and should only being shown at one day.
20- bool allday = is_the_all_day (start, end);
21+ bool allday = is_all_day (start, end);
22 if (allday) {
23 end = end.add_days (-1);
24 var interval = (new DateTime.now_local ()).get_utc_offset ();
25@@ -131,8 +131,8 @@
26 end = end.add (-interval);
27 }
28
29- start = strip_time (start.to_timezone (new TimeZone.local ()));
30- end = strip_time (end.to_timezone (new TimeZone.local ()));
31+ start = strip_time (start);
32+ end = strip_time (end);
33 dateranges.add (new Util.DateRange (start, end));
34
35 // Search for recursive events.
36@@ -255,10 +255,14 @@
37 }
38 } else {
39 int i = 1;
40- int n = i*rrule.interval;
41 bool is_null_time = rrule.until.is_null_time () == 1;
42- var start_ical_day = get_date_from_ical_day (start.add_months (n), rrule.by_day[k]);
43- int week_of_month = (int)GLib.Math.ceil ((double)start.get_day_of_month () / 7);
44+ bool is_last = (rrule.by_day[k] < 0);
45+ var start_ical_day = start;
46+ var end_ical_day = end;
47+ var days = end.get_day_of_month () - start.get_day_of_month ();
48+ int start_week = (int)GLib.Math.ceil ((double)start.get_day_of_month () / 7);
49+
50+ // Loop through each individual month from the start and test to see if our event is in the month or not
51 while (view_range.last.compare (start_ical_day) > 0) {
52 if (is_null_time == false) {
53 if (start_ical_day.get_year () > rrule.until.year)
54@@ -267,24 +271,37 @@
55 break;
56 else if (start_ical_day.get_year () == rrule.until.year && start_ical_day.get_month () == rrule.until.month && start_ical_day.get_day_of_month () > rrule.until.day)
57 break;
58+ }
59+
60+ var start_ical_day_new = get_date_from_ical_day (start.add_months (i), rrule.by_day[k]);
61+ int month = start.add_months (i).get_month ();
62+ int week = start_week;
63+
64+ // If event repeats on a last day of the month, take us back a week if we move into a new month
65+ if (is_last && start_ical_day_new.get_month () != month) {
66+ start_ical_day_new = start_ical_day_new.add_weeks (-1);
67+ }
68
69- }
70-
71- // Set it at the right weekday
72- int interval = start_ical_day.get_day_of_month () - start.get_day_of_month ();
73- var start_daterange_date = start_ical_day;
74- var end_daterange_date = end.add_months (n).add_days (interval);
75- var new_week_of_month = (int)GLib.Math.ceil ((double)start_daterange_date.get_day_of_month () / 7);
76- // Set it at the right week
77- if (week_of_month != new_week_of_month) {
78- start_daterange_date = start_daterange_date.add_weeks (week_of_month - new_week_of_month);
79- end_daterange_date = end_daterange_date.add_weeks (week_of_month - new_week_of_month);
80- }
81-
82- dateranges.add (new Util.DateRange (start_daterange_date, end_daterange_date));
83+ else if (!is_last) {
84+ if (start_ical_day_new.get_day_of_month () <= 7 && start_ical_day_new.add_weeks (-1).get_month () == month) {
85+ week = 2;
86+ }
87+ else {
88+ week = (int)GLib.Math.ceil ((double)start_ical_day_new.get_day_of_month () / 7);
89+ }
90+ }
91+
92+ start_ical_day_new = start_ical_day_new.add_weeks (start_week - week);
93+ if (start_ical_day_new.get_month () != month) {
94+ start_ical_day = start.add_months (i);
95+ }
96+ else {
97+ start_ical_day = start_ical_day_new;
98+ end_ical_day = start_ical_day.add_days (days);
99+ dateranges.add (new Util.DateRange (start_ical_day, end_ical_day));
100+ }
101+
102 i++;
103- n = i*rrule.interval;
104- start_ical_day = get_date_from_ical_day (start.add_months (n), rrule.by_day[k]);
105 }
106 }
107 } else {
108@@ -401,7 +418,7 @@
109 start= start.to_timezone (new TimeZone.utc ());
110 end = end.to_timezone (new TimeZone.utc ());
111
112- bool allday = is_the_all_day (start, end);
113+ bool allday = is_all_day (start, end);
114 if (allday)
115 end = end.add_days (-1);
116
117@@ -414,7 +431,7 @@
118 /**
119 * Say if an event lasts all day.
120 */
121- public bool is_the_all_day (DateTime dtstart, DateTime dtend) {
122+ public bool is_all_day (DateTime dtstart, DateTime dtend) {
123 var UTC_start = dtstart.to_timezone (new TimeZone.utc ());
124 var timespan = dtend.difference (dtstart);
125 if (timespan % GLib.TimeSpan.DAY == 0 && UTC_start.get_hour() == 0) {
126@@ -449,29 +466,8 @@
127 day_to_add = 6 - date.get_day_of_week ();
128 break;
129 }
130- if (date.add_days (day_to_add).get_month () < date.get_month ())
131- day_to_add = day_to_add + 7;
132-
133- if (date.add_days (day_to_add).get_month () > date.get_month ())
134- day_to_add = day_to_add - 7;
135-
136- switch (iCal.RecurrenceType.day_position (day)) {
137- case 1:
138- int n = (int)GLib.Math.trunc ((date.get_day_of_month () + day_to_add) / 7);
139- return date.add_days (day_to_add - n * 7);
140- case 2:
141- int n = (int)GLib.Math.trunc ((date.get_day_of_month () + day_to_add - 7) / 7);
142- return date.add_days (day_to_add - n * 7);
143- case 3:
144- int n = (int)GLib.Math.trunc ((date.get_day_of_month () + day_to_add - 14) / 7);
145- return date.add_days (day_to_add - n * 7);
146- case 4:
147- int n = (int)GLib.Math.trunc ((date.get_day_of_month () + day_to_add - 21) / 7);
148- return date.add_days (day_to_add - n * 7);
149- default:
150- int n = (int)GLib.Math.trunc ((date.get_day_of_month () + day_to_add - 28) / 7);
151- return date.add_days (day_to_add - n * 7);
152- }
153+
154+ return date.add_days (day_to_add);
155 }
156
157 public DateTime get_start_of_month (owned DateTime? date = null) {
158
159=== modified file 'src/AgendaView.vala'
160--- src/AgendaView.vala 2015-01-17 00:43:05 +0000
161+++ src/AgendaView.vala 2016-04-24 03:55:32 +0000
162@@ -113,9 +113,10 @@
163 return false;
164
165 unowned iCal.Component comp = event_row.calevent.get_icalcomponent ();
166- var stripped_time = Util.strip_time (selected_date);
167- foreach (var dt_range in Util.event_date_ranges (comp, new Util.DateRange (stripped_time, stripped_time.add_days (1)))) {
168- if (dt_range.contains (selected_date))
169+ var stripped_time = Util.strip_time (selected_date.to_timezone (new TimeZone.utc ()));
170+ var range = new Util.DateRange (stripped_time, stripped_time.add_days (1));
171+ foreach (var dt_range in Util.event_date_ranges (comp, range)) {
172+ if (dt_range.contains (stripped_time))
173 return true;
174 }
175
176@@ -359,7 +360,7 @@
177
178 DateTime start_date, end_date;
179 Util.get_local_datetimes_from_icalcomponent (ical_event, out start_date, out end_date);
180- if (Util.is_the_all_day (start_date, end_date) == true) {
181+ if (Util.is_all_day (start_date, end_date) == true) {
182 is_allday = true;
183 hour_label.hide ();
184 hour_label.no_show_all = true;
185
186=== modified file 'src/EventEdition/InfoPanel.vala'
187--- src/EventEdition/InfoPanel.vala 2015-11-29 22:36:14 +0000
188+++ src/EventEdition/InfoPanel.vala 2016-04-24 03:55:32 +0000
189@@ -237,7 +237,7 @@
190 }
191
192 // Is this all day
193- bool allday = Util.is_the_all_day(from_date, to_date);
194+ bool allday = Util.is_all_day(from_date, to_date);
195
196 if (dt_end.year != 0) {
197 // If it's an all day event, subtract 1 from the end date

Subscribers

People subscribed via source and target branches