From 02607d865b496e28ba8e3669dd22d2a49863d73c Mon Sep 17 00:00:00 2001 From: Jared Allen Date: Thu, 8 Jan 2015 16:24:41 -0600 Subject: [PATCH] Added MCJSONDateTransformerStyleDateTimeMillisecond to support date formats will milliseconds. --- Realm+JSON/MCJSONDateTransformer.h | 2 ++ Realm+JSON/MCJSONDateTransformer.m | 8 +++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Realm+JSON/MCJSONDateTransformer.h b/Realm+JSON/MCJSONDateTransformer.h index 38ae784..eae924a 100644 --- a/Realm+JSON/MCJSONDateTransformer.h +++ b/Realm+JSON/MCJSONDateTransformer.h @@ -9,10 +9,12 @@ #import extern NSString* const MCJSONDateTimeTransformerName; +extern NSString* const MCJSONDateTimeMillisecondTransformerName; extern NSString* const MCJSONDateOnlyTransformerName; typedef NS_ENUM(NSInteger, MCJSONDateTransformerStyle) { MCJSONDateTransformerStyleDateTime = 0, + MCJSONDateTransformerStyleDateTimeMillisecond, MCJSONDateTransformerStyleDateOnly }; diff --git a/Realm+JSON/MCJSONDateTransformer.m b/Realm+JSON/MCJSONDateTransformer.m index 50f765f..69336c3 100644 --- a/Realm+JSON/MCJSONDateTransformer.m +++ b/Realm+JSON/MCJSONDateTransformer.m @@ -9,8 +9,10 @@ #import "MCJSONDateTransformer.h" NSString* const MCJSONDateTimeTransformerName = @"MCJSONDateTimeTransformerName"; +NSString* const MCJSONDateTimeMillisecondTransformerName = @"MCJSONDateTimeMillisecondTransformerName"; NSString* const MCJSONDateOnlyTransformerName = @"MCJSONDateOnlyTransformerName"; static NSString *const kDateFormatDateTime = @"yyyy-MM-dd'T'HH:mm:ssZZZZZ"; +static NSString *const kDateFormatDateTimeMillisecond = @"yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ"; static NSString *const kDateFormatDateOnly = @"yyyy-MM-dd"; @interface MCJSONDateTransformer () @@ -23,6 +25,7 @@ @implementation MCJSONDateTransformer + (void)load { [NSValueTransformer setValueTransformer:[[self alloc] initWithDateStyle:MCJSONDateTransformerStyleDateTime] forName:MCJSONDateTimeTransformerName]; + [NSValueTransformer setValueTransformer:[[self alloc] initWithDateStyle:MCJSONDateTransformerStyleDateTimeMillisecond] forName:MCJSONDateTimeMillisecondTransformerName]; [NSValueTransformer setValueTransformer:[[self alloc] initWithDateStyle:MCJSONDateTransformerStyleDateOnly] forName:MCJSONDateOnlyTransformerName]; } @@ -40,7 +43,10 @@ - (instancetype)initWithDateStyle:(MCJSONDateTransformerStyle)style { case MCJSONDateTransformerStyleDateOnly: self.formatter.dateFormat = kDateFormatDateOnly; break; - + case MCJSONDateTransformerStyleDateTimeMillisecond: + self.formatter.dateFormat = kDateFormatDateTimeMillisecond; + break; + default: self.formatter.dateFormat = kDateFormatDateTime; break;