From 4ff1007052ad59520af625228eaad07290eaace2 Mon Sep 17 00:00:00 2001 From: Francis Lachapelle Date: Thu, 9 Jun 2016 15:33:55 -0400 Subject: [PATCH] Fix all-day events covering a timezone change Fixes #3457 --- UI/Scheduler/UIxAppointmentEditor.m | 44 ++++++++++++++--------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/UI/Scheduler/UIxAppointmentEditor.m b/UI/Scheduler/UIxAppointmentEditor.m index 314ee66813..a6cdd165f8 100644 --- a/UI/Scheduler/UIxAppointmentEditor.m +++ b/UI/Scheduler/UIxAppointmentEditor.m @@ -315,6 +315,7 @@ - (NSCalendarDate *) newStartDate offset = [timeZone secondsFromGMTForDate: startDate]; startDate = [startDate dateByAddingYears:0 months:0 days:0 hours:0 minutes:0 seconds:-offset]; + offset = [timeZone secondsFromGMTForDate: endDate]; endDate = [endDate dateByAddingYears:0 months:0 days:0 hours:0 minutes:0 seconds:-offset]; } @@ -717,16 +718,27 @@ - (void) takeValuesFromRequest: (WORequest *) _rq if (isAllDay) { - nbrDays = ((float) abs ([aptEndDate timeIntervalSinceDate: aptStartDate]) - / 86400) + 1; - // Convert all-day start date to GMT (floating date) - ud = [[context activeUser] userDefaults]; - timeZone = [ud timeZone]; - offset = [timeZone secondsFromGMTForDate: aptStartDate]; - allDayStartDate = [aptStartDate dateByAddingYears:0 months:0 days:0 hours:0 minutes:0 - seconds:offset]; - [event setAllDayWithStartDate: allDayStartDate - duration: nbrDays]; + if ([aptStartDate earlierDate: aptEndDate] == aptStartDate) + { + // Remove the vTimeZone when dealing with an all-day event. + startDate = (iCalDateTime *)[event uniqueChildWithTag: @"dtstart"]; + tz = [startDate timeZone]; + if (tz) + { + [startDate setTimeZone: nil]; + [(iCalDateTime *)[event uniqueChildWithTag: @"dtend"] setTimeZone: nil]; + [[event parent] removeChild: tz]; + } + + nbrDays = round ([aptEndDate timeIntervalSinceDate: aptStartDate] / 86400) + 1; + // Convert all-day start date to GMT (floating date) + timeZone = [aptStartDate timeZone]; + offset = [timeZone secondsFromGMTForDate: aptStartDate]; + allDayStartDate = [aptStartDate dateByAddingYears:0 months:0 days:0 hours:0 minutes:0 + seconds:offset]; + [event setAllDayWithStartDate: allDayStartDate + duration: nbrDays]; + } } else { @@ -750,18 +762,6 @@ - (void) takeValuesFromRequest: (WORequest *) _rq } } } - else if (![[self clientObject] isNew]) - { - // Remove the vTimeZone when dealing with an all-day event. - startDate = (iCalDateTime *)[event uniqueChildWithTag: @"dtstart"]; - tz = [startDate timeZone]; - if (tz) - { - [startDate setTimeZone: nil]; - [(iCalDateTime *)[event uniqueChildWithTag: @"dtend"] setTimeZone: nil]; - [[event parent] removeChild: tz]; - } - } [event setTransparency: (isTransparent? @"TRANSPARENT" : @"OPAQUE")];