Skip to content

Commit 05f51ec

Browse files
committed
Adding compatibility for Ruby on Rails date formatted like: 2011-07-20T23:59:00-07:00
1 parent d6db368 commit 05f51ec

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

OSReflectionKit/AZReflection.m

+11-3
Original file line numberDiff line numberDiff line change
@@ -249,14 +249,22 @@ - (BOOL)assignValue:(id)value instance:(id)instance key:(NSString *)key property
249249

250250
[instance setValue:date forKey:key];
251251
}
252-
else
252+
else if ([value isKindOfClass:[NSString class]])
253253
{
254+
NSString *dateString = value;
255+
254256
if ([value length] == 10)
255257
[formatter setDateFormat:@"yyyy-MM-dd"];
256-
else
258+
else if ([value length] <= 19)
257259
[formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
260+
else
261+
{
262+
// Ruby on Rails compatibility for date formatted like: 2011-07-20T23:59:00-07:00
263+
dateString = [value stringByReplacingOccurrencesOfString:@":" withString:@""];
264+
[formatter setDateFormat:@"yyyy-MM-dd'T'HHmmssZZ"];
265+
}
258266

259-
[instance setValue:[formatter dateFromString:value] forKey:key];
267+
[instance setValue:[formatter dateFromString:dateString] forKey:key];
260268
}
261269

262270
}

0 commit comments

Comments
 (0)