mirror of
https://github.com/zhigang1992/RestKit.git
synced 2026-01-13 09:30:46 +08:00
Add support for mapping of numeric dates encoded in strings via NSNumberFormatter. closes #815
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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];
|
||||
|
||||
3
Vendor/iso8601parser/ISO8601DateFormatter.m
vendored
3
Vendor/iso8601parser/ISO8601DateFormatter.m
vendored
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user