return nil;
if (aValue == null)
return aValue;
-
- // Check if we need conversion; we use is kind of because
- // a string is not a NSString but some concrete class, so is NSData,
- // NSNumber and may be other classes
+
+ // Check if we need conversion; we use is kind of because
+ // a string is not a NSString but some concrete class, so is NSData,
+ // NSNumber and may be other classes
if ([aValue isKindOfClass:aClass])
return aValue;
- // We have to convert the aValue
-
- // Try EOCustomValues
+ // We have to convert the aValue
+
+ // Try EOCustomValues
if ([aValue respondsToSelector:@selector(stringForType:)]) {
// Special case if aClass is NSNumber
if (aClass == [NSNumber class]) {
- return [NSNumber
- numberWithString:[aValue stringForType:_type]
- type:_type];
+ return [NSNumber numberWithString:[aValue stringForType:_type]
+ type:_type];
}
// Even more Special case if aClass is NSCalendar date
if (aClass == [NSCalendarDate class]) {
- id format, date;
-
+ /* we enter this section even if the value is a NSDate object, or
+ NSCFDate on Cocoa */
+ NSCalendarDate *date;
+ NSString *format;
+
format = [self calendarFormat];
if (format == nil)
format = [EOAttribute defaultCalendarFormat];
- date = [NSCalendarDate
- dateWithString:[aValue stringForType:_type]
- calendarFormat:format];
+
+ if ([aValue isKindOfClass:[NSDate class]]) {
+ // TBD: this does not catch NSCFDate?!
+ date = [NSCalendarDate dateWithTimeIntervalSince1970:
+ [(NSDate *)aValue timeIntervalSince1970]];
+ }
+ else {
+ date = [NSCalendarDate dateWithString:[aValue stringForType:_type]
+ calendarFormat:format];
+ if (date == nil) {
+ NSLog(@"WARN: could not create NSCalendarDate using format %@ "
+ @"from value: %@", format, aValue);
+ }
+ }
+
[date setCalendarFormat:format];
return date;
}
- (id)convertValueToModel:(id)aValue {
id aValueClassName;
Class aValueClass;
-
+
// Check value class from attribute
aValueClassName = [self valueClassName];
aValueClass = NSClassFromString(aValueClassName);
NSEnumerator *enumerator;
NSString *key;
- dict = [NSMutableDictionary dictionary];
+ dict = [NSMutableDictionary dictionaryWithCapacity:[aRow count]];
enumerator = [aRow keyEnumerator];
while ((key = [enumerator nextObject]) != nil) {
id old = [aRow objectForKey:key];
id new = [[self attributeNamed:key] convertValueToModel:old];
-
+
if (new != nil) [dict setObject:new forKey:key];
}
-
+
return [dict count] > 0 ? dict : (NSMutableDictionary *)nil;
}