Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion KeyValueObjectMapping/DCGenericConverter.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ - (id)initWithConfiguration:(DCParserConfiguration *) configuration {
if (self) {
_configuration = configuration;
_parsers = [NSArray arrayWithObjects:
[DCNSDateConverter dateConverterForPattern:self.configuration.datePattern],
[DCNSDateConverter dateConverterForPattern:self.configuration.datePattern locale:self.configuration.dateLocale],
[DCNSURLConverter urlConverter],
[DCNSArrayConverter arrayConverterForConfiguration: self.configuration],
[DCNSSetConverter setConverterForConfiguration: self.configuration], nil];
Expand Down
2 changes: 1 addition & 1 deletion KeyValueObjectMapping/DCNSDateConverter.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
#import "DCValueConverter.h"
@interface DCNSDateConverter : NSObject <DCValueConverter>

+ (DCNSDateConverter *) dateConverterForPattern: (NSString *) pattern;
+ (DCNSDateConverter *) dateConverterForPattern: (NSString *) pattern locale:(NSLocale *)locale;

@end
16 changes: 12 additions & 4 deletions KeyValueObjectMapping/DCNSDateConverter.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,23 @@

@interface DCNSDateConverter()
@property(nonatomic, strong) NSString *pattern;
@property(nonatomic, strong) NSLocale *locale;
- (BOOL) validDouble: (NSString *) doubleValue;
@end

@implementation DCNSDateConverter
@synthesize pattern = _pattern;


+ (DCNSDateConverter *) dateConverterForPattern: (NSString *) pattern{
return [[self alloc] initWithDatePattern: pattern];
+ (DCNSDateConverter *) dateConverterForPattern: (NSString *) pattern locale:(NSLocale *)locale {
return [[self alloc] initWithDatePattern: pattern locale:locale];
}

- (id) initWithDatePattern: (NSString *) pattern {
- (id) initWithDatePattern: (NSString *) pattern locale:(NSLocale *)locale {
self = [super init];
if (self) {
_pattern = pattern;
_locale = locale;
}
return self;
}
Expand All @@ -37,13 +39,19 @@ - (id)transformValue:(id)value forDynamicAttribute:(DCDynamicAttribute *)attribu
}else{
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
formatter.dateFormat = self.pattern;
if (self.locale) {
formatter.locale = self.locale;
}
return [formatter dateFromString:value];
}
}
- (id)serializeValue:(id)value forDynamicAttribute:(DCDynamicAttribute *)attribute {
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
formatter.dateFormat = self.pattern;
return [formatter stringFromDate:value];
if (self.locale) {
formatter.locale = self.locale;
}
return [formatter stringFromDate:value];
}
- (BOOL)canTransformValueForClass: (Class) cls {
return [cls isSubclassOfClass:[NSDate class]];
Expand Down
1 change: 1 addition & 0 deletions KeyValueObjectMapping/DCParserConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
@interface DCParserConfiguration : NSObject

@property(nonatomic, strong) NSString *datePattern;
@property(nonatomic, strong) NSLocale *dateLocale;
@property(nonatomic, strong) NSString *splitToken;
@property(nonatomic, strong) NSString *nestedPrepertiesSplitToken;
@property(nonatomic, readonly) NSMutableArray *objectMappers;
Expand Down
2 changes: 1 addition & 1 deletion KeyValueObjectMappingTests/DCNSDateConverterTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ - (BOOL) validDouble: (NSString *) doubleValue;
@implementation DCNSDateConverterTests

- (void) testValidDouble {
DCNSDateConverter *convertor = [DCNSDateConverter dateConverterForPattern:@"yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z'"];
DCNSDateConverter *convertor = [DCNSDateConverter dateConverterForPattern:@"yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z'" locale:nil];
STAssertTrue([convertor validDouble:@"10"], @"Should recognize '10' as a valid double");
STAssertTrue([convertor validDouble:@"10.0"], @"Should recognize '10.0' as a valid double");
[@[ @"Monday, April 17, 2006", @"Monday, April 17, 2006 2:22:48 PM", @"4/17/2006 2:22:48 PM", @"Mon, 17 Apr 2006 21:22:48 GMT", @"2006-04-17 21:22:48Z", @"2006-04-17T14:22:48.2698750-07:00" ]
Expand Down
2 changes: 1 addition & 1 deletion KeyValueObjectMappingTests/KeyValueObjectMappingTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ -(void) testValidJsonToTweet {
STAssertEqualObjects(tweet.text, @"@pedroh96 cara, comecei uma lib pra iOS, se puder dar uma olhada e/ou contribuir :D KeyValue Parse for Objective-C https://t.co/NWMMc60v", @"Should have same text");
STAssertEqualObjects(tweet.source, @"<a href=\"http://www.osfoora.com/mac\" rel=\"nofollow\">Osfoora for Mac</a>", @"Should have same source");
STAssertNil(tweet.inReplyToStatusIdStr, @"inRepryToStatusIdStr should be null");
STAssertEquals(tweet.retweetCount, [NSNumber numberWithInt: 0], @"RetweetCount should be equals to 0");
STAssertEquals(tweet.retweetCount, [NSNumber numberWithInteger:0], @"RetweetCount should be equals to 0");
STAssertFalse(tweet.favorited, @"favorited should be false");
STAssertFalse(tweet.retweeted, @"favorited should be false");
STAssertEqualObjects(tweet.createdAt, data, @"CreatedAt should be equals");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ -(void) testValidJsonToTweet {
STAssertEqualObjects(tweet.text, @"@pedroh96 cara, comecei uma lib pra iOS, se puder dar uma olhada e/ou contribuir :D KeyValue Parse for Objective-C https://t.co/NWMMc60v", @"Should have same text");
STAssertEqualObjects(tweet.source, @"<a href=\"http://www.osfoora.com/mac\" rel=\"nofollow\">Osfoora for Mac</a>", @"Should have same source");
STAssertNil(tweet.inReplyToStatusIdStr, @"inRepryToStatusIdStr should be null");
STAssertEquals(tweet.retweetCount, [NSNumber numberWithInt: 0], @"RetweetCount should be equals to 0");
STAssertEquals(tweet.retweetCount, [NSNumber numberWithInteger:0], @"RetweetCount should be equals to 0");
STAssertFalse(tweet.favorited, @"favorited should be false");
STAssertFalse(tweet.retweeted, @"favorited should be false");
STAssertEqualObjects(tweet.createdAt, data, @"CreatedAt should be equals");
Expand Down