Showing
4 changed files
with
28 additions
and
11 deletions
| @@ -21,7 +21,7 @@ | @@ -21,7 +21,7 @@ | ||
| 21 | #import "ASIInputStream.h" | 21 | #import "ASIInputStream.h" |
| 22 | 22 | ||
| 23 | // Automatically set on build | 23 | // Automatically set on build |
| 24 | -NSString *ASIHTTPRequestVersion = @"v1.5-18 2010-01-14"; | 24 | +NSString *ASIHTTPRequestVersion = @"v1.5-19 2010-01-14"; |
| 25 | 25 | ||
| 26 | NSString* const NetworkRequestErrorDomain = @"ASIHTTPRequestErrorDomain"; | 26 | NSString* const NetworkRequestErrorDomain = @"ASIHTTPRequestErrorDomain"; |
| 27 | 27 |
| @@ -81,11 +81,12 @@ static NSString *rackspaceCloudAuthURL = @"https://auth.api.rackspacecloud.com/v | @@ -81,11 +81,12 @@ static NSString *rackspaceCloudAuthURL = @"https://auth.api.rackspacecloud.com/v | ||
| 81 | #pragma mark Date Parser | 81 | #pragma mark Date Parser |
| 82 | 82 | ||
| 83 | -(NSDate *)dateFromString:(NSString *)dateString { | 83 | -(NSDate *)dateFromString:(NSString *)dateString { |
| 84 | - NSDateFormatter *format = [[NSDateFormatter alloc] init]; | 84 | + NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; |
| 85 | + [dateFormatter setLocale:[[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"] autorelease]]; | ||
| 85 | // example: 2009-11-04T19:46:20.192723 | 86 | // example: 2009-11-04T19:46:20.192723 |
| 86 | - [format setDateFormat:@"yyyy-MM-dd'T'H:mm:ss"]; | 87 | + [dateFormatter setDateFormat:@"yyyy-MM-dd'T'H:mm:ss.SSSSSS"]; |
| 87 | - NSDate *date = [format dateFromString:dateString]; | 88 | + NSDate *date = [dateFormatter dateFromString:dateString]; |
| 88 | - [format release]; | 89 | + [dateFormatter release]; |
| 89 | 90 | ||
| 90 | return date; | 91 | return date; |
| 91 | } | 92 | } |
| @@ -42,12 +42,28 @@ static NSString *apiKey = @""; | @@ -42,12 +42,28 @@ static NSString *apiKey = @""; | ||
| 42 | } | 42 | } |
| 43 | 43 | ||
| 44 | - (void)testDateParser { | 44 | - (void)testDateParser { |
| 45 | - ASICloudFilesRequest *request = [[ASICloudFilesRequest alloc] init]; | 45 | + ASICloudFilesRequest *request = [[[ASICloudFilesRequest alloc] init] autorelease]; |
| 46 | - NSDate *date = [request dateFromString:@"2009-11-04T19:46:20.192723"]; | 46 | + |
| 47 | - GHAssertNotNil(date, @"Failed to parse date string"); | 47 | + NSDate *date = [request dateFromString:@"invalid date string"]; |
| 48 | - date = [request dateFromString:@"invalid date string"]; | 48 | + GHAssertNil(date, @"Should have failed to parse an invalid date string"); |
| 49 | - GHAssertNil(date, @"Failed to not parse with invalid date string"); | 49 | + |
| 50 | - [request release]; | 50 | + date = [request dateFromString:@"2009-11-04T19:46:20.192723"]; |
| 51 | + GHAssertNotNil(date, @"Failed to parse date string"); | ||
| 52 | + | ||
| 53 | + NSDateComponents *components = [[[NSDateComponents alloc] init] autorelease]; | ||
| 54 | + [components setYear:2009]; | ||
| 55 | + [components setMonth:11]; | ||
| 56 | + [components setDay:4]; | ||
| 57 | + [components setHour:19]; | ||
| 58 | + [components setMinute:46]; | ||
| 59 | + [components setSecond:20]; | ||
| 60 | + NSCalendar *calendar = [[[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar] autorelease]; | ||
| 61 | + NSDate *referenceDate = [calendar dateFromComponents:components]; | ||
| 62 | + | ||
| 63 | + // NSDateComponents has seconds as the smallest value, so we'll just check the created date is less than 1 second different from what we expect | ||
| 64 | + NSTimeInterval timeDifference = [date timeIntervalSinceDate:referenceDate]; | ||
| 65 | + BOOL success = (timeDifference < 1.0); | ||
| 66 | + GHAssertTrue(success, @"Parsed date incorrectly"); | ||
| 51 | } | 67 | } |
| 52 | 68 | ||
| 53 | // ASICloudFilesContainerRequest | 69 | // ASICloudFilesContainerRequest |
This diff was suppressed by a .gitattributes entry.
-
Please register or login to post a comment