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
=== modified file 'core/DateRange.vala'
--- core/DateRange.vala 2014-12-27 19:24:57 +0000
+++ core/DateRange.vala 2016-04-24 03:55:32 +0000
@@ -84,7 +84,6 @@
84 }84 }
8585
86 public DateRange (DateTime first, DateTime last) {86 public DateRange (DateTime first, DateTime last) {
87 assert (first.compare(last)<=0);
88 this.first = first;87 this.first = first;
89 this.last = last;88 this.last = last;
90 }89 }
9190
=== modified file 'core/Utils.vala'
--- core/Utils.vala 2016-01-18 23:25:24 +0000
+++ core/Utils.vala 2016-04-24 03:55:32 +0000
@@ -123,7 +123,7 @@
123 if (end == null) end = start;123 if (end == null) end = start;
124124
125 // All days events are stored in UTC time and should only being shown at one day.125 // All days events are stored in UTC time and should only being shown at one day.
126 bool allday = is_the_all_day (start, end);126 bool allday = is_all_day (start, end);
127 if (allday) {127 if (allday) {
128 end = end.add_days (-1);128 end = end.add_days (-1);
129 var interval = (new DateTime.now_local ()).get_utc_offset ();129 var interval = (new DateTime.now_local ()).get_utc_offset ();
@@ -131,8 +131,8 @@
131 end = end.add (-interval);131 end = end.add (-interval);
132 }132 }
133133
134 start = strip_time (start.to_timezone (new TimeZone.local ()));134 start = strip_time (start);
135 end = strip_time (end.to_timezone (new TimeZone.local ()));135 end = strip_time (end);
136 dateranges.add (new Util.DateRange (start, end));136 dateranges.add (new Util.DateRange (start, end));
137137
138 // Search for recursive events.138 // Search for recursive events.
@@ -255,10 +255,14 @@
255 }255 }
256 } else {256 } else {
257 int i = 1;257 int i = 1;
258 int n = i*rrule.interval;
259 bool is_null_time = rrule.until.is_null_time () == 1;258 bool is_null_time = rrule.until.is_null_time () == 1;
260 var start_ical_day = get_date_from_ical_day (start.add_months (n), rrule.by_day[k]);259 bool is_last = (rrule.by_day[k] < 0);
261 int week_of_month = (int)GLib.Math.ceil ((double)start.get_day_of_month () / 7);260 var start_ical_day = start;
261 var end_ical_day = end;
262 var days = end.get_day_of_month () - start.get_day_of_month ();
263 int start_week = (int)GLib.Math.ceil ((double)start.get_day_of_month () / 7);
264
265 // Loop through each individual month from the start and test to see if our event is in the month or not
262 while (view_range.last.compare (start_ical_day) > 0) {266 while (view_range.last.compare (start_ical_day) > 0) {
263 if (is_null_time == false) {267 if (is_null_time == false) {
264 if (start_ical_day.get_year () > rrule.until.year)268 if (start_ical_day.get_year () > rrule.until.year)
@@ -267,24 +271,37 @@
267 break;271 break;
268 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)272 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)
269 break;273 break;
274 }
275
276 var start_ical_day_new = get_date_from_ical_day (start.add_months (i), rrule.by_day[k]);
277 int month = start.add_months (i).get_month ();
278 int week = start_week;
279
280 // If event repeats on a last day of the month, take us back a week if we move into a new month
281 if (is_last && start_ical_day_new.get_month () != month) {
282 start_ical_day_new = start_ical_day_new.add_weeks (-1);
283 }
270 284
271 }285 else if (!is_last) {
272286 if (start_ical_day_new.get_day_of_month () <= 7 && start_ical_day_new.add_weeks (-1).get_month () == month) {
273 // Set it at the right weekday287 week = 2;
274 int interval = start_ical_day.get_day_of_month () - start.get_day_of_month ();288 }
275 var start_daterange_date = start_ical_day;289 else {
276 var end_daterange_date = end.add_months (n).add_days (interval);290 week = (int)GLib.Math.ceil ((double)start_ical_day_new.get_day_of_month () / 7);
277 var new_week_of_month = (int)GLib.Math.ceil ((double)start_daterange_date.get_day_of_month () / 7);291 }
278 // Set it at the right week292 }
279 if (week_of_month != new_week_of_month) {293
280 start_daterange_date = start_daterange_date.add_weeks (week_of_month - new_week_of_month);294 start_ical_day_new = start_ical_day_new.add_weeks (start_week - week);
281 end_daterange_date = end_daterange_date.add_weeks (week_of_month - new_week_of_month);295 if (start_ical_day_new.get_month () != month) {
282 }296 start_ical_day = start.add_months (i);
283297 }
284 dateranges.add (new Util.DateRange (start_daterange_date, end_daterange_date));298 else {
299 start_ical_day = start_ical_day_new;
300 end_ical_day = start_ical_day.add_days (days);
301 dateranges.add (new Util.DateRange (start_ical_day, end_ical_day));
302 }
303
285 i++;304 i++;
286 n = i*rrule.interval;
287 start_ical_day = get_date_from_ical_day (start.add_months (n), rrule.by_day[k]);
288 }305 }
289 }306 }
290 } else {307 } else {
@@ -401,7 +418,7 @@
401 start= start.to_timezone (new TimeZone.utc ());418 start= start.to_timezone (new TimeZone.utc ());
402 end = end.to_timezone (new TimeZone.utc ());419 end = end.to_timezone (new TimeZone.utc ());
403420
404 bool allday = is_the_all_day (start, end);421 bool allday = is_all_day (start, end);
405 if (allday)422 if (allday)
406 end = end.add_days (-1);423 end = end.add_days (-1);
407424
@@ -414,7 +431,7 @@
414 /**431 /**
415 * Say if an event lasts all day.432 * Say if an event lasts all day.
416 */433 */
417 public bool is_the_all_day (DateTime dtstart, DateTime dtend) {434 public bool is_all_day (DateTime dtstart, DateTime dtend) {
418 var UTC_start = dtstart.to_timezone (new TimeZone.utc ());435 var UTC_start = dtstart.to_timezone (new TimeZone.utc ());
419 var timespan = dtend.difference (dtstart);436 var timespan = dtend.difference (dtstart);
420 if (timespan % GLib.TimeSpan.DAY == 0 && UTC_start.get_hour() == 0) {437 if (timespan % GLib.TimeSpan.DAY == 0 && UTC_start.get_hour() == 0) {
@@ -449,29 +466,8 @@
449 day_to_add = 6 - date.get_day_of_week ();466 day_to_add = 6 - date.get_day_of_week ();
450 break;467 break;
451 }468 }
452 if (date.add_days (day_to_add).get_month () < date.get_month ())469
453 day_to_add = day_to_add + 7;470 return date.add_days (day_to_add);
454
455 if (date.add_days (day_to_add).get_month () > date.get_month ())
456 day_to_add = day_to_add - 7;
457
458 switch (iCal.RecurrenceType.day_position (day)) {
459 case 1:
460 int n = (int)GLib.Math.trunc ((date.get_day_of_month () + day_to_add) / 7);
461 return date.add_days (day_to_add - n * 7);
462 case 2:
463 int n = (int)GLib.Math.trunc ((date.get_day_of_month () + day_to_add - 7) / 7);
464 return date.add_days (day_to_add - n * 7);
465 case 3:
466 int n = (int)GLib.Math.trunc ((date.get_day_of_month () + day_to_add - 14) / 7);
467 return date.add_days (day_to_add - n * 7);
468 case 4:
469 int n = (int)GLib.Math.trunc ((date.get_day_of_month () + day_to_add - 21) / 7);
470 return date.add_days (day_to_add - n * 7);
471 default:
472 int n = (int)GLib.Math.trunc ((date.get_day_of_month () + day_to_add - 28) / 7);
473 return date.add_days (day_to_add - n * 7);
474 }
475 }471 }
476472
477 public DateTime get_start_of_month (owned DateTime? date = null) {473 public DateTime get_start_of_month (owned DateTime? date = null) {
478474
=== modified file 'src/AgendaView.vala'
--- src/AgendaView.vala 2015-01-17 00:43:05 +0000
+++ src/AgendaView.vala 2016-04-24 03:55:32 +0000
@@ -113,9 +113,10 @@
113 return false;113 return false;
114114
115 unowned iCal.Component comp = event_row.calevent.get_icalcomponent ();115 unowned iCal.Component comp = event_row.calevent.get_icalcomponent ();
116 var stripped_time = Util.strip_time (selected_date);116 var stripped_time = Util.strip_time (selected_date.to_timezone (new TimeZone.utc ()));
117 foreach (var dt_range in Util.event_date_ranges (comp, new Util.DateRange (stripped_time, stripped_time.add_days (1)))) {117 var range = new Util.DateRange (stripped_time, stripped_time.add_days (1));
118 if (dt_range.contains (selected_date))118 foreach (var dt_range in Util.event_date_ranges (comp, range)) {
119 if (dt_range.contains (stripped_time))
119 return true;120 return true;
120 }121 }
121122
@@ -359,7 +360,7 @@
359360
360 DateTime start_date, end_date;361 DateTime start_date, end_date;
361 Util.get_local_datetimes_from_icalcomponent (ical_event, out start_date, out end_date);362 Util.get_local_datetimes_from_icalcomponent (ical_event, out start_date, out end_date);
362 if (Util.is_the_all_day (start_date, end_date) == true) {363 if (Util.is_all_day (start_date, end_date) == true) {
363 is_allday = true;364 is_allday = true;
364 hour_label.hide ();365 hour_label.hide ();
365 hour_label.no_show_all = true;366 hour_label.no_show_all = true;
366367
=== modified file 'src/EventEdition/InfoPanel.vala'
--- src/EventEdition/InfoPanel.vala 2015-11-29 22:36:14 +0000
+++ src/EventEdition/InfoPanel.vala 2016-04-24 03:55:32 +0000
@@ -237,7 +237,7 @@
237 }237 }
238238
239 // Is this all day239 // Is this all day
240 bool allday = Util.is_the_all_day(from_date, to_date);240 bool allday = Util.is_all_day(from_date, to_date);
241241
242 if (dt_end.year != 0) {242 if (dt_end.year != 0) {
243 // If it's an all day event, subtract 1 from the end date243 // If it's an all day event, subtract 1 from the end date

Subscribers

People subscribed via source and target branches