From 04a444094c3df48f19e0f728bf0ae333ee65da3d Mon Sep 17 00:00:00 2001
From: root <root@example.com>
Date: Wed, 26 Mar 2014 21:22:23 +0100
Subject: [PATCH] all day events

---
 ActiveSync/iCalEvent+ActiveSync.m |   25 ++++++++++++++++++++-----
 1 file changed, 20 insertions(+), 5 deletions(-)

diff --git a/ActiveSync/iCalEvent+ActiveSync.m b/ActiveSync/iCalEvent+ActiveSync.m
index 05f18a3..1eeeb20 100644
--- a/ActiveSync/iCalEvent+ActiveSync.m
+++ b/ActiveSync/iCalEvent+ActiveSync.m
@@ -83,6 +83,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
   int v;
 
+  NSTimeZone *userTimeZone;
+  userTimeZone = [[[context activeUser] userDefaults] timeZone];
+
   s = [NSMutableString string];
   
   [s appendFormat: @"<AllDayEvent xmlns=\"Calendar:\">%d</AllDayEvent>", ([self isAllDay] ? 1 : 0)];
@@ -95,17 +98,21 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   
   // StartTime -- http://msdn.microsoft.com/en-us/library/ee157132(v=exchg.80).aspx
   if ([self startDate])
-    [s appendFormat: @"<StartTime xmlns=\"Calendar:\">%@</StartTime>", [[self startDate] activeSyncRepresentationWithoutSeparatorsInContext: context]];
-  
+     [self isAllDay]
+          ? [s appendFormat: @"<StartTime xmlns=\"Calendar:\">%@</StartTime>", [[[self startDate] dateByAddingYears: 0 months: 0 days: 0  hours: 0 minutes: 0 seconds:  ([userTimeZone secondsFromGMTForDate: [self startDate]])*-1] activeSyncRepresentationWithoutSeparatorsInContext: context]]
+          : [s appendFormat: @"<StartTime xmlns=\"Calendar:\">%@</StartTime>", [[self startDate] activeSyncRepresentationWithoutSeparatorsInContext: context]];
+
   // EndTime -- http://msdn.microsoft.com/en-us/library/ee157945(v=exchg.80).aspx
   if ([self endDate])
-    [s appendFormat: @"<EndTime xmlns=\"Calendar:\">%@</EndTime>", [[self endDate] activeSyncRepresentationWithoutSeparatorsInContext: context]];
-  
+     [self isAllDay]
+          ? [s appendFormat: @"<EndTime xmlns=\"Calendar:\">%@</EndTime>", [[[self endDate] dateByAddingYears: 0 months: 0 days: 0  hours: 0 minutes: 0 seconds:  ([userTimeZone secondsFromGMTForDate: [self endDate]])*-1] activeSyncRepresentationWithoutSeparatorsInContext: context]]
+          : [s appendFormat: @"<EndTime xmlns=\"Calendar:\">%@</EndTime>", [[self endDate] activeSyncRepresentationWithoutSeparatorsInContext: context]];
+
   // Timezone
   tz = [(iCalDateTime *)[self firstChildWithTag: @"dtstart"] timeZone];
 
   if (!tz)
-    tz = [iCalTimeZone timeZoneForName: @"Europe/London"];
+    tz = [iCalTimeZone timeZoneForName: [userTimeZone timeZoneName]];
 
   [s appendFormat: @"<TimeZone xmlns=\"Calendar:\">%@</TimeZone>", [tz activeSyncRepresentationInContext: context]];
   
@@ -356,6 +363,10 @@ 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];
           [start setDate: o];
           [start setTimeZone: nil];
         }
@@ -377,6 +388,10 @@ 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];
         }
-- 
1.7.9.5

