Open PongPong opened 12 years ago
// Process date NSString *RFC3339String = [[NSString stringWithString:dateString] uppercaseString]; RFC3339String = [RFC3339String stringByReplacingOccurrencesOfString:@"Z" withString:@"-0000"]; // Remove colon in timezone as it breaks NSDateFormatter in iOS 4+. // - see https://devforums.apple.com/thread/45837 if (RFC3339String.length > 20) { RFC3339String = [RFC3339String stringByReplacingOccurrencesOfString:@":" withString:@"" options:0 range:NSMakeRange(20, RFC3339String.length-20)]; } if (!date) { // 1996-12-19T16:39:57-0800 [dateFormatter setDateFormat:@"yyyy'-'MM'-'dd'T'HH':'mm':'ssZZZ"]; date = [dateFormatter dateFromString:RFC3339String]; } if (!date) { // 1937-01-01T12:00:27.87+0020 [dateFormatter setDateFormat:@"yyyy'-'MM'-'dd'T'HH':'mm':'ss.SSSZZZ"]; date = [dateFormatter dateFromString:RFC3339String]; } if (!date) { // 1937-01-01T12:00:27 [dateFormatter setDateFormat:@"yyyy'-'MM'-'dd'T'HH':'mm':'ss"]; date = [dateFormatter dateFromString:RFC3339String]; } if (!date) NSLog(@"Could not parse RFC3339 date: \"%@\" Possible invalid format.", dateString);
Could you send a pull request? Adding tests might be nice :P