title: NSTimezone problem using EventKit
body: <p>I need to make entries in the iPhone calendar, using EventKit framework.</p>
  
  <p>Since my app should be international, I need to take care of differnt timezones.
  What I am doing right now:</p>
  
  <p>An event should start at 6:00 am.
  Therefore I am creating a NSDate object with this code:</p>
  
  <pre><code>[NSDate dateWithString:[NSString stringWithFormat:@"%d-%d-%d %d:%d:00 +0000",year,month,day,hour,minute]];
  </code></pre>
  
  <p>What I get is a NSDate object with 06:00 am and timezone GMT.</p>
  
  <p>When using this NSDate as startDate of the event, I want to use the systems timezone, to make sure that the event is really shown as 06:00 am in the calendar.</p>
  
  <p>Therefore I use this code:</p>
  
  <pre><code>+(NSDate*) convertToSystemTimezone:(NSDate*)sourceDate
  {   
      NSTimeZone* sourceTimeZone = [NSTimeZone timeZoneWithAbbreviation:@"GMT"];
      NSTimeZone* destinationTimeZone = [NSTimeZone systemTimeZone];  
      NSInteger sourceGMTOffset = [sourceTimeZone secondsFromGMTForDate:sourceDate];
      NSInteger destinationGMTOffset = [destinationTimeZone secondsFromGMTForDate:sourceDate];
      NSTimeInterval interval = destinationGMTOffset - sourceGMTOffset;   
      NSDate* destinationDate = [[[NSDate alloc] initWithTimeInterval:interval sinceDate:sourceDate] autorelease];         
      return destinationDate; 
  }
  </code></pre>
  
  <p>As example, I change my devices timezone to NEW YORK. If I debug into the code, It correctly recognizes the timezone and an offset of -14400 seconds.
  So my start and end NSDate objects seems to be correct.</p>
  
  <p>If I look into the calendar, the app created an event, that does not start at 06:00 am, but at 04:00 am.</p>
  
  <p>What am I doing wrong ??</p>
  
  <p><strong>EDIT: My code to create the event:</strong></p>
  
  <p>Example for creating an event from 06:00 am to 08:00 am</p>
  
  <pre><code>int year=2011;
  int month=6;
  int day=26;
  int hour=6;
  int minute=0;
  
  NSDate *startDate = [NSDate dateWithString:[NSString stringWithFormat:@"%d-%d-%d %d:%d:00 +0000",year,month,day,hour, minute];  
  startDate=[self convertToSystemTimezone:startDate];
  
  NSDate *endDate = [NSDate dateWithString:[NSString stringWithFormat:@"%d-%d-%d %d:%d:00 +0000",year,month,day,8, minute];   
  endDate=[self convertToSystemTimezone:endDate];     
  
  EKEventStore *eventDB = [[EKEventStore alloc] init];
  EKEvent *myEvent  = [EKEvent eventWithEventStore:eventDB];      
  myEvent.title  = @"Testevent";
  myEvent.startDate = startDate;
  myEvent.endDate   = endDate;
  myEvent.allDay = NO;
  [myEvent setCalendar:[eventDB defaultCalendarForNewEvents]];
  NSError *err;                   
  [eventDB saveEvent:myEvent span:EKSpanThisEvent error:&amp;err];
  [eventDB release];
  </code></pre>
  
  <p>The deletion of the existing events is not shown, but this is tested and works. </p>