Permalink
Browse files

Fixed timezone calculation error when local time it not UTC (because …

…NSDate defaults to local timezone for some reason)
  • Loading branch information...
1 parent 16d7d06 commit f6b97c86714f5a91f7a298d2f8b9a094a1356c58 @magicmonkey magicmonkey committed with magicmonkey Mar 30, 2010
Showing with 6 additions and 8 deletions.
  1. +4 −1 joindinapp/Classes/TalkDetailModel.m
  2. +2 −7 joindinapp/Classes/TalkDetailViewController.m
@@ -47,8 +47,10 @@ -(NSComparisonResult)comparator:(TalkDetailModel *)otherModel {
- (NSDate *)getAdjustedDateGiven:(EventDetailModel *)event {
NSTimeZone *sourceTZ;
NSTimeZone *destTZ;
+ NSTimeZone *localTZ;
sourceTZ = [NSTimeZone timeZoneWithName:@"UTC"];
+ localTZ = [NSTimeZone systemTimeZone];
NSUserDefaults *userPrefs = [NSUserDefaults standardUserDefaults];
if ([userPrefs stringForKey:@"timezonedisplay"] == nil) {
@@ -68,7 +70,8 @@ - (NSDate *)getAdjustedDateGiven:(EventDetailModel *)event {
NSInteger sourceGMTOffset = [sourceTZ secondsFromGMTForDate:self.given];
NSInteger destinationGMTOffset = [destTZ secondsFromGMTForDate:self.given];
- NSTimeInterval interval = destinationGMTOffset - sourceGMTOffset;
+ NSInteger localGMTOffset = [localTZ secondsFromGMTForDate:self.given];
+ NSTimeInterval interval = destinationGMTOffset - sourceGMTOffset - localGMTOffset;
//NSLog(@"Dest offset [%d] Source offset [%d]", destinationGMTOffset, sourceGMTOffset);
@@ -61,16 +61,11 @@ -(void)setupScreen:(BOOL)withExtraInfo {
self.uiTitle.text = self.talk.title;
self.uiSpeaker.text = self.talk.speaker;
- NSDateFormatter *outputFormatter = [[NSDateFormatter alloc] init];
- [outputFormatter setDateFormat:@"d MMM yyyy"];
- NSString *dateGiven = [outputFormatter stringFromDate:self.talk.given];
-
- [outputFormatter setDateFormat:@"h:mma"];
- NSString *timeGiven = [[outputFormatter stringFromDate:self.talk.given] lowercaseString];
+ NSString *dateGiven = [self.talk getDateString:self.event];
+ NSString *timeGiven = [self.talk getTimeString:self.event];
if (![timeGiven isEqualToString:@"12:00am"]) {
dateGiven = [NSString stringWithFormat:@"%@ %@", dateGiven, timeGiven];
}
- [outputFormatter release];
self.uiDate.text = dateGiven;
self.uiDesc.text = self.talk.desc;

0 comments on commit f6b97c8

Please sign in to comment.