From 269381321c9d2c055119dab33e5075fccfe7b3a9 Mon Sep 17 00:00:00 2001 From: Wes Smith Date: Wed, 29 Apr 2015 16:57:32 -0400 Subject: [PATCH 1/2] serialize dates as time interval since reference date --- DeepLinkSDK/Categories/NSObject+DPLJSONObject.h | 1 + DeepLinkSDK/Categories/NSObject+DPLJSONObject.m | 9 +++++++++ Tests/Categories/NSObject_DPLJSONObjectSpec.m | 6 ++++++ 3 files changed, 16 insertions(+) diff --git a/DeepLinkSDK/Categories/NSObject+DPLJSONObject.h b/DeepLinkSDK/Categories/NSObject+DPLJSONObject.h index f5e501e..2924184 100644 --- a/DeepLinkSDK/Categories/NSObject+DPLJSONObject.h +++ b/DeepLinkSDK/Categories/NSObject+DPLJSONObject.h @@ -10,6 +10,7 @@ - NSDictionary and NSArray will call `DPLJSONObject' on all of their items. - Objects in an NSDictionary not keyed by an NSString will be removed. - NSNumbers that are NaN or Inf will be represented by a string. + - NSDate objects will be represented as `timeIntervalSinceReferenceDate'. - JSON incompatible objects will return their description. - All NSNulls will be removed because who wants an NSNull. diff --git a/DeepLinkSDK/Categories/NSObject+DPLJSONObject.m b/DeepLinkSDK/Categories/NSObject+DPLJSONObject.m index 61e76ec..89858b7 100644 --- a/DeepLinkSDK/Categories/NSObject+DPLJSONObject.m +++ b/DeepLinkSDK/Categories/NSObject+DPLJSONObject.m @@ -32,6 +32,15 @@ - (id)DPL_JSONObject { @end +@implementation NSDate (DPLJSONObject) + +- (id)DPL_JSONObject { + return @([self timeIntervalSinceReferenceDate]); +} + +@end + + @implementation NSArray (DPLJSONObject) - (id)DPL_JSONObject { diff --git a/Tests/Categories/NSObject_DPLJSONObjectSpec.m b/Tests/Categories/NSObject_DPLJSONObjectSpec.m index 1b064f2..25591af 100644 --- a/Tests/Categories/NSObject_DPLJSONObjectSpec.m +++ b/Tests/Categories/NSObject_DPLJSONObjectSpec.m @@ -62,6 +62,12 @@ expect(obj).to.equal(@{ @"inf": @"inf", @"nan": @"nan" }); }); + it(@"converts date objects to timeIntervalSinceReferenceDate", ^{ + NSDate *someDate = [NSDate date]; + id obj = [someDate DPL_JSONObject]; + expect([obj doubleValue]).to.equal([someDate timeIntervalSinceReferenceDate]); + }); + it(@"removes non-string keys from dictionaries", ^{ NSDictionary *dict = @{ testURL: @"foo", @"bar": @"baz" }; id obj = [dict DPL_JSONObject]; From 0cd987fea660d1a23e0304f12226fa558846df65 Mon Sep 17 00:00:00 2001 From: Wes Smith Date: Tue, 5 May 2015 15:40:31 -0400 Subject: [PATCH 2/2] bump cocoapods version --- Podfile.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Podfile.lock b/Podfile.lock index 5b55f0a..501022d 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -16,7 +16,7 @@ DEPENDENCIES: EXTERNAL SOURCES: DeepLinkSDK: - :path: "." + :path: . SPEC CHECKSUMS: DeepLinkSDK: 82f36ed1bbf8fb549bb0dfb14b21852219c95384 @@ -25,4 +25,4 @@ SPEC CHECKSUMS: OCMock: a10ea9f0a6e921651f96f78b6faee95ebc813b92 Specta: e5ad38f1b2227a23bc63d0b5a3b41c5e628f2851 -COCOAPODS: 0.36.4 +COCOAPODS: 0.37.0