From ead665de85e2202dbde926c316cbba927d38dfa7 Mon Sep 17 00:00:00 2001 From: Ludovic Marcotte Date: Mon, 29 Dec 2014 16:19:10 -0500 Subject: [PATCH] fix tz issue when the user one was different from the system one with EAS --- ActiveSync/NSString+ActiveSync.m | 11 +++++++--- ActiveSync/iCalEvent+ActiveSync.m | 34 ++++++++++--------------------- ActiveSync/iCalToDo+ActiveSync.m | 12 ----------- NEWS | 1 + 4 files changed, 20 insertions(+), 38 deletions(-) diff --git a/ActiveSync/NSString+ActiveSync.m b/ActiveSync/NSString+ActiveSync.m index 8317f8fe9..01f593352 100644 --- a/ActiveSync/NSString+ActiveSync.m +++ b/ActiveSync/NSString+ActiveSync.m @@ -33,6 +33,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include #include +#include #include #include @@ -127,13 +128,17 @@ static NSArray *easCommandParameters = nil; // - (NSCalendarDate *) calendarDate { + NSString *s; id o; - o = [NSCalendarDate dateWithString: self calendarFormat: @"%Y%m%dT%H%M%SZ"]; + // We force parsing in the GMT timezone. If we don't do that, the date will be parsed + // in the default timezone. + s = [NSString stringWithFormat: @"%@ GMT", self]; + o = [NSCalendarDate dateWithString: s calendarFormat: @"%Y%m%dT%H%M%SZ %Z"]; if (!o) - o = [NSCalendarDate dateWithString: self calendarFormat: @"%Y-%m-%dT%H:%M:%S.%FZ"]; - + o = [NSCalendarDate dateWithString: s calendarFormat: @"%Y-%m-%dT%H:%M:%S.%FZ %Z"]; + return o; } diff --git a/ActiveSync/iCalEvent+ActiveSync.m b/ActiveSync/iCalEvent+ActiveSync.m index dc996f381..d1a4b6f8a 100644 --- a/ActiveSync/iCalEvent+ActiveSync.m +++ b/ActiveSync/iCalEvent+ActiveSync.m @@ -332,7 +332,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. iCalTimeZone *tz; id o; - NSInteger tzOffset; BOOL isAllDay; if ((o = [theValues objectForKey: @"UID"])) @@ -384,10 +383,15 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // Some Windows devices don't send during event updates. //if ((o = [theValues objectForKey: @"TimeZone"])) // { - userTimeZone = [[[context activeUser] userDefaults] timeZone]; - tz = [iCalTimeZone timeZoneForName: [userTimeZone name]]; - [(iCalCalendar *) parent addTimeZone: tz]; - //} + // } + //else + { + // We haven't received a timezone, let's use the user's timezone + // specified in SOGo for now. + userTimeZone = [[[context activeUser] userDefaults] timeZone]; + tz = [iCalTimeZone timeZoneForName: [userTimeZone name]]; + [(iCalCalendar *) parent addTimeZone: tz]; + } // FIXME: merge with iCalToDo if ((o = [[theValues objectForKey: @"Body"] objectForKey: @"Data"])) @@ -402,21 +406,13 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. start = (iCalDateTime *) [self uniqueChildWithTag: @"dtstart"]; [start setTimeZone: tz]; - if (isAllDay) - { - tzOffset = [userTimeZone secondsFromGMTForDate: o]; - o = [o dateByAddingYears: 0 months: 0 days: 0 - hours: 0 minutes: 0 - seconds: tzOffset]; + if (isAllDay) + { [start setDate: o]; [start setTimeZone: nil]; } else { - tzOffset = [userTimeZone secondsFromGMTForDate: o]; - o = [o dateByAddingYears: 0 months: 0 days: 0 - hours: 0 minutes: 0 - seconds: tzOffset]; [start setDateTime: o]; } } @@ -429,19 +425,11 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. if (isAllDay) { - tzOffset = [userTimeZone secondsFromGMTForDate: o]; - o = [o dateByAddingYears: 0 months: 0 days: 0 - hours: 0 minutes: 0 - seconds: tzOffset]; [end setDate: o]; [end setTimeZone: nil]; } else { - tzOffset = [userTimeZone secondsFromGMTForDate: o]; - o = [o dateByAddingYears: 0 months: 0 days: 0 - hours: 0 minutes: 0 - seconds: tzOffset]; [end setDateTime: o]; } } diff --git a/ActiveSync/iCalToDo+ActiveSync.m b/ActiveSync/iCalToDo+ActiveSync.m index 58b0d4c04..5f237a31b 100644 --- a/ActiveSync/iCalToDo+ActiveSync.m +++ b/ActiveSync/iCalToDo+ActiveSync.m @@ -143,8 +143,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. iCalTimeZone *tz; id o; - NSInteger tzOffset; - userTimeZone = [[[context activeUser] userDefaults] timeZone]; tz = [iCalTimeZone timeZoneForName: [userTimeZone name]]; [(iCalCalendar *) parent addTimeZone: tz]; @@ -165,10 +163,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. o = [o calendarDate]; completed = (iCalDateTime *) [self uniqueChildWithTag: @"completed"]; - //tzOffset = [[o timeZone] secondsFromGMTForDate: o]; - //o = [o dateByAddingYears: 0 months: 0 days: 0 - // hours: 0 minutes: 0 - // seconds: -tzOffset]; [completed setDate: o]; [self setStatus: @"COMPLETED"]; } @@ -177,15 +171,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. { iCalDateTime *due; - o = [o calendarDate]; due = (iCalDateTime *) [self uniqueChildWithTag: @"due"]; [due setTimeZone: tz]; - - tzOffset = [userTimeZone secondsFromGMTForDate: o]; - o = [o dateByAddingYears: 0 months: 0 days: 0 - hours: 0 minutes: 0 - seconds: tzOffset]; [due setDateTime: o]; } diff --git a/NEWS b/NEWS index fc7a69502..e3f181db7 100644 --- a/NEWS +++ b/NEWS @@ -4,6 +4,7 @@ Bug fixes - fix contact description truncation on WP8 phones (#3028) - fix freebusy information not always returned + - fix tz issue when the user one was different from the system one with EAS Enhancements - initial support for empty sync request/response for EAS