Created
December 8, 2009 01:39
-
-
Save ejknapp/251336 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Handling Flak dates | |
| NSDateFormatter* dateFormatter; | |
| ... | |
| @property (nonatomic, retain) NSDateFormatter *dateFormatter; | |
| //In the init method of something | |
| self.dateFormatter = [[NSDateFormatter alloc] init]; | |
| self.dateFormatter.dateFormat = @"yyyy-MM-dd'T'HH:mm:ss'Z'"; | |
| - (NSDate *) createLocalDate:(NSDictionary *)messageDictionary forKey:(NSString *)key { | |
| NSDate *sourceDate; | |
| NSTimeZone *sourceTimeZone; | |
| NSTimeZone *destinationTimeZone; | |
| NSInteger sourceGMTOffset; | |
| NSInteger destinationGMTOffset; | |
| NSTimeInterval interval; | |
| NSDate *destinationDate; | |
| // The create date of the message returned by the Flak server | |
| sourceDate = [self.dateFormatter dateFromString:[messageDictionary objectForKey:key]]; | |
| sourceTimeZone = [NSTimeZone timeZoneWithAbbreviation:@"GMT"]; | |
| destinationTimeZone = [NSTimeZone systemTimeZone]; | |
| sourceGMTOffset = [sourceTimeZone secondsFromGMTForDate:sourceDate]; | |
| destinationGMTOffset = [destinationTimeZone secondsFromGMTForDate:sourceDate]; | |
| interval = destinationGMTOffset - sourceGMTOffset; | |
| destinationDate = [[[NSDate alloc] initWithTimeInterval:interval sinceDate:sourceDate] autorelease]; | |
| return destinationDate; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment