Permalink
Browse files

Removing ISO8601DateFormatter dependency

  • Loading branch information...
1 parent c8e10e5 commit 71bfbb2fc173f3a873404fde5effb11e3f536cd3 @mattt mattt committed Nov 2, 2012
View
@@ -1,6 +1,3 @@
[submodule "AFNetworking"]
path = AFNetworking
- url = git://github.com/AFNetworking/AFNetworking.git
-[submodule "ISO8601DateFormatter"]
- path = ISO8601DateFormatter
- url = https://github.com/AFNetworking/ISO8601DateFormatter.git
+ url = git://github.com/AFNetworking/AFNetworking.git
@@ -17,5 +17,4 @@ Pod::Spec.new do |s|
s.requires_arc = true
s.dependency 'AFNetworking', '>= 0.9.0'
- s.dependency 'ISO8601DateFormatter'
end
@@ -22,7 +22,6 @@
#import "AFIncrementalStore.h"
#import "AFHTTPClient.h"
-#import "ISO8601DateFormatter.h"
#import <objc/runtime.h>
NSString * const AFIncrementalStoreUnimplementedMethodException = @"com.alamofire.incremental-store.exceptions.unimplemented-method";
@@ -35,27 +34,31 @@
NSString * const AFIncrementalStorePersistentStoreRequestKey = @"AFIncrementalStorePersistentStoreRequest";
NSString * const AFIncrementalStoreFetchedObjectsKey = @"AFIncrementalStoreFetchedObjectsKey";
+static char kAFResourceIdentifierObjectKey;
+
static NSString * const kAFIncrementalStoreResourceIdentifierAttributeName = @"__af_resourceIdentifier";
static NSString * const kAFIncrementalStoreLastModifiedAttributeName = @"__af_lastModified";
-static char kAFResourceIdentifierObjectKey;
+static NSString * const kAFReferenceObjectPrefix = @"__af_";
static NSDate * AFLastModifiedDateFromHTTPHeaders(NSDictionary *headers) {
if ([headers valueForKey:@"Last-Modified"]) {
- static ISO8601DateFormatter * _iso8601DateFormatter = nil;
+ static NSString * const _RFC1123Format = @"EEE',' dd MMM yyyy HH':'mm':'ss z";
+ static NSDateFormatter *_RFC1123DateFormatter = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
- _iso8601DateFormatter = [[ISO8601DateFormatter alloc] init];
+ _RFC1123DateFormatter = [[NSDateFormatter alloc] init];
+ _RFC1123DateFormatter.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"];
+ _RFC1123DateFormatter.timeZone = [NSTimeZone timeZoneWithAbbreviation:@"GMT"];
+ _RFC1123DateFormatter.dateFormat = _RFC1123Format;
});
- return [_iso8601DateFormatter dateFromString:[headers valueForKey:@"last-modified"]];
+ return [_RFC1123DateFormatter dateFromString:[headers valueForKey:@"last-modified"]];
}
return nil;
}
-static NSString * const kAFReferenceObjectPrefix = @"__af_";
-
inline NSString * AFReferenceObjectFromResourceIdentifier(NSString *resourceIdentifier) {
if (!resourceIdentifier) {
return nil;
@@ -65,3 +65,12 @@
forObject:(NSManagedObject *)object;
@end
+
+///----------------
+/// @name Functions
+///----------------
+
+/**
+
+ */
+extern NSDate * AFDateFromISO8601String(NSString *ISO8601String);
@@ -21,7 +21,67 @@
// THE SOFTWARE.
#import "AFRESTClient.h"
-#import "ISO8601DateFormatter.h"
+#include <time.h>
+#include <xlocale.h>
+
+#define AF_ISO8601_MAX_LENGTH 25
+
+// Adopted from SSToolkit NSDate+SSToolkitAdditions
+// Created by Sam Soffes
+// Copyright (c) 2008-2012 Sam Soffes
+// https://github.com/soffes/sstoolkit/
+NSDate * AFDateFromISO8601String(NSString *ISO8601String) {
+ if (!ISO8601String) {
+ return nil;
+ }
+
+ const char *str = [ISO8601String cStringUsingEncoding:NSUTF8StringEncoding];
+ char newStr[AF_ISO8601_MAX_LENGTH];
+ bzero(newStr, AF_ISO8601_MAX_LENGTH);
+
+ size_t len = strlen(str);
+ if (len == 0) {
+ return nil;
+ }
+
+ // UTC dates ending with Z
+ if (len == 20 && str[len - 1] == 'Z') {
+ memcpy(newStr, str, len - 1);
+ strncpy(newStr + len - 1, "+0000\0", 6);
+ }
+
+ // Timezone includes a semicolon (not supported by strptime)
+ else if (len == 25 && str[22] == ':') {
+ memcpy(newStr, str, 22);
+ memcpy(newStr + 22, str + 23, 2);
+ }
+
+ // Fallback: date was already well-formatted OR any other case (bad-formatted)
+ else {
+ memcpy(newStr, str, len > AF_ISO8601_MAX_LENGTH - 1 ? AF_ISO8601_MAX_LENGTH - 1 : len);
+ }
+
+ // Add null terminator
+ newStr[sizeof(newStr) - 1] = 0;
+
+ struct tm tm = {
+ .tm_sec = 0,
+ .tm_min = 0,
+ .tm_hour = 0,
+ .tm_mday = 0,
+ .tm_mon = 0,
+ .tm_year = 0,
+ .tm_wday = 0,
+ .tm_yday = 0,
+ .tm_isdst = -1,
+ };
+
+ if (strptime_l(newStr, "%FT%T%z", &tm, NULL) == NULL) {
+ return nil;
+ }
+
+ return [NSDate dateWithTimeIntervalSince1970:mktime(&tm)];
+}
static NSString * AFPluralizedString(NSString *string) {
if ([string hasSuffix:@"ss"] || [string hasSuffix:@"se"] || [string hasSuffix:@"sh"] || [string hasSuffix:@"ch"]) {
@@ -121,12 +181,6 @@ - (NSDictionary *)attributesForRepresentation:(NSDictionary *)representation
ofEntity:(NSEntityDescription *)entity
fromResponse:(NSHTTPURLResponse *)response
{
- static ISO8601DateFormatter *_iso8601DateFormatter = nil;
- static dispatch_once_t onceToken;
- dispatch_once(&onceToken, ^{
- _iso8601DateFormatter = [[ISO8601DateFormatter alloc] init];
- });
-
if ([representation isEqual:[NSNull null]]) {
return nil;
}
@@ -147,7 +201,7 @@ - (NSDictionary *)attributesForRepresentation:(NSDictionary *)representation
if ([(NSAttributeDescription *)obj attributeType] == NSDateAttributeType) {
id value = [mutableAttributes valueForKey:key];
if (value && ![value isEqual:[NSNull null]]) {
- [mutableAttributes setValue:[_iso8601DateFormatter dateFromString:value] forKey:key];
+ [mutableAttributes setValue:AFDateFromISO8601String(value) forKey:key];
}
}
}];
@@ -31,7 +31,6 @@
F8AFAFB415AB4F28003FE5BB /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F8AFAFB315AB4F28003FE5BB /* Foundation.framework */; };
F8AFAFB615AB4F28003FE5BB /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F8AFAFB515AB4F28003FE5BB /* CoreGraphics.framework */; };
F8AFAFB815AB4F28003FE5BB /* CoreData.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F8AFAFB715AB4F28003FE5BB /* CoreData.framework */; };
- F8B77D95161E403F00A88B7F /* ISO8601DateFormatter.m in Sources */ = {isa = PBXBuildFile; fileRef = F8B77D94161E403F00A88B7F /* ISO8601DateFormatter.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; };
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
@@ -81,8 +80,6 @@
F8AFAFB315AB4F28003FE5BB /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
F8AFAFB515AB4F28003FE5BB /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; };
F8AFAFB715AB4F28003FE5BB /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = System/Library/Frameworks/CoreData.framework; sourceTree = SDKROOT; };
- F8B77D93161E403F00A88B7F /* ISO8601DateFormatter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ISO8601DateFormatter.h; path = ../../ISO8601DateFormatter/ISO8601DateFormatter.h; sourceTree = "<group>"; };
- F8B77D94161E403F00A88B7F /* ISO8601DateFormatter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = ISO8601DateFormatter.m; path = ../../ISO8601DateFormatter/ISO8601DateFormatter.m; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@@ -220,22 +217,12 @@
F8AFB07215AB5010003FE5BB /* Vendor */ = {
isa = PBXGroup;
children = (
- F8B77D91161E401F00A88B7F /* ISO8601DateFormatter */,
F8AD92E215D9A0BB00402FE9 /* AFIncrementalStore */,
F8AD92C215D9A0B400402FE9 /* AFNetworking */,
);
name = Vendor;
sourceTree = "<group>";
};
- F8B77D91161E401F00A88B7F /* ISO8601DateFormatter */ = {
- isa = PBXGroup;
- children = (
- F8B77D93161E403F00A88B7F /* ISO8601DateFormatter.h */,
- F8B77D94161E403F00A88B7F /* ISO8601DateFormatter.m */,
- );
- name = ISO8601DateFormatter;
- sourceTree = "<group>";
- };
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
@@ -317,7 +304,6 @@
F8AD92E115D9A0B400402FE9 /* UIImageView+AFNetworking.m in Sources */,
F8AD92E715D9A0BB00402FE9 /* AFIncrementalStore.m in Sources */,
F8AD92E815D9A0BB00402FE9 /* AFRESTClient.m in Sources */,
- F8B77D95161E403F00A88B7F /* ISO8601DateFormatter.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -29,7 +29,6 @@
F8B77D77161E178D00A88B7F /* AFXMLRequestOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = F8B77D6D161E178D00A88B7F /* AFXMLRequestOperation.m */; };
F8B77D78161E178D00A88B7F /* UIImageView+AFNetworking.m in Sources */ = {isa = PBXBuildFile; fileRef = F8B77D6F161E178D00A88B7F /* UIImageView+AFNetworking.m */; };
F8B77D7B161E17AF00A88B7F /* CheckIns.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = F8B77D79161E17AF00A88B7F /* CheckIns.xcdatamodeld */; };
- F8B77D7E161E220B00A88B7F /* ISO8601DateFormatter.m in Sources */ = {isa = PBXBuildFile; fileRef = F8B77D7D161E220B00A88B7F /* ISO8601DateFormatter.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; };
F8B77D98161E43EC00A88B7F /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F8B77D97161E43EC00A88B7F /* SystemConfiguration.framework */; };
/* End PBXBuildFile section */
@@ -79,8 +78,6 @@
F8B77D6E161E178D00A88B7F /* UIImageView+AFNetworking.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIImageView+AFNetworking.h"; sourceTree = "<group>"; };
F8B77D6F161E178D00A88B7F /* UIImageView+AFNetworking.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIImageView+AFNetworking.m"; sourceTree = "<group>"; };
F8B77D7A161E17AF00A88B7F /* CheckIns.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = CheckIns.xcdatamodel; sourceTree = "<group>"; };
- F8B77D7C161E220B00A88B7F /* ISO8601DateFormatter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ISO8601DateFormatter.h; path = ../../ISO8601DateFormatter/ISO8601DateFormatter.h; sourceTree = "<group>"; };
- F8B77D7D161E220B00A88B7F /* ISO8601DateFormatter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = ISO8601DateFormatter.m; path = ../../ISO8601DateFormatter/ISO8601DateFormatter.m; sourceTree = "<group>"; };
F8B77D97161E43EC00A88B7F /* SystemConfiguration.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SystemConfiguration.framework; path = System/Library/Frameworks/SystemConfiguration.framework; sourceTree = SDKROOT; };
/* End PBXFileReference section */
@@ -185,7 +182,6 @@
children = (
F8B77D55161E178600A88B7F /* AFIncrementalStore */,
F8B77D5C161E178D00A88B7F /* AFNetworking */,
- F8B77D7F161E220F00A88B7F /* ISO8601DateFormatter */,
);
name = Vendor;
sourceTree = "<group>";
@@ -229,15 +225,6 @@
path = ../../AFNetworking/AFNetworking;
sourceTree = "<group>";
};
- F8B77D7F161E220F00A88B7F /* ISO8601DateFormatter */ = {
- isa = PBXGroup;
- children = (
- F8B77D7C161E220B00A88B7F /* ISO8601DateFormatter.h */,
- F8B77D7D161E220B00A88B7F /* ISO8601DateFormatter.m */,
- );
- name = ISO8601DateFormatter;
- sourceTree = "<group>";
- };
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
@@ -317,7 +304,6 @@
F8B77D77161E178D00A88B7F /* AFXMLRequestOperation.m in Sources */,
F8B77D78161E178D00A88B7F /* UIImageView+AFNetworking.m in Sources */,
F8B77D7B161E17AF00A88B7F /* CheckIns.xcdatamodeld in Sources */,
- F8B77D7E161E220B00A88B7F /* ISO8601DateFormatter.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -33,7 +33,6 @@
F8AFAFB415AB4F28003FE5BB /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F8AFAFB315AB4F28003FE5BB /* Foundation.framework */; };
F8AFAFB615AB4F28003FE5BB /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F8AFAFB515AB4F28003FE5BB /* CoreGraphics.framework */; };
F8AFAFB815AB4F28003FE5BB /* CoreData.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F8AFAFB715AB4F28003FE5BB /* CoreData.framework */; };
- F8B77D8E161E3F5400A88B7F /* ISO8601DateFormatter.m in Sources */ = {isa = PBXBuildFile; fileRef = F8B77D8D161E3F5400A88B7F /* ISO8601DateFormatter.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; };
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
@@ -85,8 +84,6 @@
F8AFAFB315AB4F28003FE5BB /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
F8AFAFB515AB4F28003FE5BB /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; };
F8AFAFB715AB4F28003FE5BB /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = System/Library/Frameworks/CoreData.framework; sourceTree = SDKROOT; };
- F8B77D8C161E3F5400A88B7F /* ISO8601DateFormatter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ISO8601DateFormatter.h; path = ../../ISO8601DateFormatter/ISO8601DateFormatter.h; sourceTree = "<group>"; };
- F8B77D8D161E3F5400A88B7F /* ISO8601DateFormatter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = ISO8601DateFormatter.m; path = ../../ISO8601DateFormatter/ISO8601DateFormatter.m; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@@ -251,22 +248,12 @@
F8AFB07215AB5010003FE5BB /* Vendor */ = {
isa = PBXGroup;
children = (
- F8B77D90161E3F5900A88B7F /* ISO8601DateFormatter */,
F8AD92E215D9A0BB00402FE9 /* AFIncrementalStore */,
F8AD92C215D9A0B400402FE9 /* AFNetworking */,
);
name = Vendor;
sourceTree = "<group>";
};
- F8B77D90161E3F5900A88B7F /* ISO8601DateFormatter */ = {
- isa = PBXGroup;
- children = (
- F8B77D8C161E3F5400A88B7F /* ISO8601DateFormatter.h */,
- F8B77D8D161E3F5400A88B7F /* ISO8601DateFormatter.m */,
- );
- name = ISO8601DateFormatter;
- sourceTree = "<group>";
- };
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
@@ -350,7 +337,6 @@
F8AD92F815D9A2DB00402FE9 /* Post.m in Sources */,
F8AD92FB15D9A2E500402FE9 /* User.m in Sources */,
F87CD18E15DAB2B200E4C166 /* PostTableViewCell.m in Sources */,
- F8B77D8E161E3F5400A88B7F /* ISO8601DateFormatter.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -72,6 +72,7 @@ - (NSDictionary *)attributesForRepresentation:(NSDictionary *)representation
NSMutableDictionary *mutablePropertyValues = [[super attributesForRepresentation:representation ofEntity:entity fromResponse:response] mutableCopy];
if ([entity.name isEqualToString:@"Post"]) {
[mutablePropertyValues setValue:[NSNumber numberWithInteger:[[representation valueForKey:@"id"] integerValue]] forKey:@"postID"];
+ [mutablePropertyValues setValue:AFDateFromISO8601String([representation valueForKey:@"created_at"]) forKey:@"createdAt"];
} else if ([entity.name isEqualToString:@"User"]) {
[mutablePropertyValues setValue:[NSNumber numberWithInteger:[[representation valueForKey:@"id"] integerValue]] forKey:@"userID"];
[mutablePropertyValues setValue:[representation valueForKey:@"username"] forKey:@"username"];
Submodule ISO8601DateFormatter deleted from 35f424

0 comments on commit 71bfbb2

Please sign in to comment.