Add support for mapping of numeric dates encoded in strings via NSNumberFormatter. closes #815

This commit is contained in:
Blake Watters
2012-09-25 21:18:03 -04:00
parent 618b1e094c
commit e56754cb65
3 changed files with 6 additions and 1 deletions

View File

@@ -116,6 +116,9 @@ extern NSString * const RKObjectMappingNestingAttributeKeyName;
if ([dateFormatter isKindOfClass:[NSDateFormatter class]]) {
RKLogTrace(@"Successfully parsed string '%@' with format string '%@' and time zone '%@' and turned into date '%@'",
string, [(NSDateFormatter *)dateFormatter dateFormat], [(NSDateFormatter *)dateFormatter timeZone], date);
} else if ([dateFormatter isKindOfClass:[NSNumberFormatter class]]) {
NSNumber *formattedNumber = (NSNumber *)date;
date = [NSDate dateWithTimeIntervalSince1970:[formattedNumber doubleValue]];
}
break;

View File

@@ -353,6 +353,7 @@ static NSDateFormatter *preferredDateFormatter = nil;
[self addDefaultDateFormatter:numberFormatter];
ISO8601DateFormatter *isoFormatter = [[ISO8601DateFormatter alloc] init];
isoFormatter.parsesStrictly = YES;
[self addDefaultDateFormatter:isoFormatter];
[self addDefaultDateFormatterForString:@"MM/dd/yyyy" inTimeZone:nil];

View File

@@ -613,7 +613,7 @@ static BOOL is_leap_year(NSUInteger year);
*outTimeZone = timeZone;
}
return components;
return isValidDate ? components : nil;
}
- (NSDate *) dateFromString:(NSString *)string {
@@ -625,6 +625,7 @@ static BOOL is_leap_year(NSUInteger year);
- (NSDate *)dateFromString:(NSString *)string timeZone:(out NSTimeZone **)outTimeZone range:(out NSRange *)outRange {
NSTimeZone *timeZone = nil;
NSDateComponents *components = [self dateComponentsFromString:string timeZone:&timeZone range:outRange];
if (! components) return nil;
if (outTimeZone)
*outTimeZone = timeZone;
parsingCalendar.timeZone = timeZone;