Skip to content

Commit

Permalink
Improved date parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
soffes committed Nov 11, 2010
1 parent d8d92e8 commit f89fd9d
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions SSToolkit/NSDate+SSToolkitAdditions.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,18 @@ + (NSDate *)dateFromISO8601String:(NSString *)string {
return nil;
}

NSDate* date = nil;
NSDateFormatter* dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
NSString* adjustedString = string;
if([string characterAtIndex:string.length - 1] == 'Z') {
adjustedString = [NSString stringWithFormat:@"%@ +0000", [string substringToIndex:(string.length - 1)]];
NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
if ([string characterAtIndex:string.length - 1] == 'Z') {
string = [NSString stringWithFormat:@"%@ +0000", [string substringToIndex:(string.length - 1)]];
}

[dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZ"];
date = [dateFormatter dateFromString:adjustedString];
return date;
return [dateFormatter dateFromString:string];
}


- (NSString *)ISO8601String {
NSDateFormatter* dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
[dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZ"];
return [dateFormatter stringFromDate:self];
}
Expand Down

0 comments on commit f89fd9d

Please sign in to comment.