Skip to content

Commit

Permalink
Merge pull request #22 from jallen/master
Browse files Browse the repository at this point in the history
Added MCJSONDateTransformerStyleDateTimeMillisecond
  • Loading branch information
matthewcheok committed Jan 9, 2015
2 parents 031b357 + 02607d8 commit 1b951aa
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Realm+JSON/MCJSONDateTransformer.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
#import <Foundation/Foundation.h>

extern NSString* const MCJSONDateTimeTransformerName;
extern NSString* const MCJSONDateTimeMillisecondTransformerName;
extern NSString* const MCJSONDateOnlyTransformerName;

typedef NS_ENUM(NSInteger, MCJSONDateTransformerStyle) {
MCJSONDateTransformerStyleDateTime = 0,
MCJSONDateTransformerStyleDateTimeMillisecond,
MCJSONDateTransformerStyleDateOnly
};

Expand Down
8 changes: 7 additions & 1 deletion Realm+JSON/MCJSONDateTransformer.m
Original file line number Diff line number Diff line change
Expand Up @@ -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 ()
Expand All @@ -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];
}

Expand All @@ -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;
Expand Down

0 comments on commit 1b951aa

Please sign in to comment.