Our application presents a list of events the user may be interested in. When they select an event, we let them add it to their calendar by presenting it with a EKEventEditViewController
calendar sheet.
Generally, users will pick an event that's close to them. However, they might pick an event and travel to it or watch a distant event on TV. In the code snippet below, the hard-coded values all come from the server. My mock event is in Denver, CO @ 9AM to 2PM MDT. The user could be anywhere and may or may not travel.
Question #1: Should I set the timeZone of the event to the location where the event takes place? I should not set it to nil because I do not have a floating event. However, should I omit setting it so it takes the current timezone or set it to the event's timezone? The event's start date/time appears correct whether I set this or not. If I set the event's timezone to MDT but create the event in Boston (EDT). Will it still be correct if I fly to Colorado?
Question #2: Should I set the calendar's timezone as well? Will the user in NYC expect to see 9AM to 2PM (which is when the event takes place in Denver) and freak out when they see 11AM to 4PM appear? OR will user say "ah, I see what you did there."? Sorry to "ask and answer" but the 9AM event is 11AM in NY if I want to watch it on TV and if I don't set this value the DATE object has the 'incorrect' time. I just worry that users will be confused and/or my overall combination of timezone settings is not correct.
The code:
EKEvent *event = [EKEvent eventWithEventStore:store];
event.title = @"My event title";
event.notes = @"Some event notes";
event.location = @"Denver, CO";
event.timeZone = [NSTimeZone timeZoneWithAbbreviation:@"MDT"]; // <-- Q1
event.calendar = [store defaultCalendarForNewEvents];
NSCalendar *calendar = [NSCalendar currentCalendar];
[calendar setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"MDT"]]; // <-- Q2
NSDateComponents *components = [[NSDateComponents alloc] init];
components.year = 2014;
components.month = 5;
components.day = 5;
components.hour = 9;
components.minute = 0;
event.startDate = [calendar dateFromComponents:components];
components.year = 2014;
components.month = 5;
components.day = 5;
components.hour = 14;
components.minute = 0;
event.endDate = [calendar dateFromComponents:components];
If both event & calendar timeZones set to MDT, NYC user sees 11AM-4PM, here's the event obj:
EKEvent <0xd45b530> {
title = My event title;
location = Denver, CO;
calendar = EKCalendar <0xceef2a0> {title = Calendar; type = Local; allowsModify = YES; color = #1BADF8;};
alarms = (null);
URL = (null);
lastModified = (null);
timeZone = America/Denver (MDT) offset -21600 (Daylight)
};
location = Denver, CO;
startDate = 2014-03-22 15:00:00 +0000;
endDate = 2014-03-22 20:00:00 +0000;
allDay = 0;
floating = 0;
recurrence = (null);
attendees = (null)
};
If event timeZone set to MDT, but not set calendar timezone, NYC user sees 9AM-2PM
EKEvent <0xce3d740>
{ title = My event title;
location = Denver, CO;
calendar = EKCalendar <0xdcb1340> {title = Calendar; type = Local; allowsModify = YES; color = #1BADF8;};
alarms = (null);
URL = (null);
lastModified = (null);
timeZone = America/Denver (MDT) offset -21600 (Daylight)
};
location = Denver, CO;
startDate = 2014-03-22 13:00:00 +0000;
endDate = 2014-03-22 18:00:00 +0000;
allDay = 0;
floating = 0;
recurrence = (null);
attendees = (null)
};
It seems I must set BOTH event and calendar timezones to match the location of the event, but would appreciate feedback from those who have been down this path before as I don't want to get it wrong for people who create an event in one location then travel to see it.
Many thanks!