Skip to content
Open
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
20 changes: 18 additions & 2 deletions KeyValueObjectMapping/DCNSDateConverter.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
@interface DCNSDateConverter()
@property(nonatomic, strong) NSString *pattern;
- (BOOL) validDouble: (NSString *) doubleValue;
- (NSDateFormatter *)dateFormatter;
@end

@implementation DCNSDateConverter
Expand All @@ -32,8 +33,7 @@ - (id)transformValue:(id)value forDynamicAttribute:(DCDynamicAttribute *)attribu
if(validDouble){
return [NSDate dateWithTimeIntervalSince1970:[value doubleValue]];
}else{
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
formatter.dateFormat = self.pattern;
NSDateFormatter *formatter = [self dateFormatter];
return [formatter dateFromString:value];
}
}
Expand All @@ -48,4 +48,20 @@ - (BOOL) canTransformValueForClass: (Class) class {
- (BOOL) validDouble: (NSString *) doubleValue {
return [[[NSNumberFormatter alloc] init] numberFromString:doubleValue] != nil;
}


#pragma mark - Private Methods

- (NSDateFormatter *)dateFormatter {

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
NSLocale *enUSPOSIXLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"];

[dateFormatter setLocale:enUSPOSIXLocale];
[dateFormatter setDateFormat:self.pattern];
[dateFormatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]];

return dateFormatter;
}

@end