Make typecasting more consistent with how typecasting works in ActiveRec...

...ord. Empty strings for numeric fields should be casted to nil, nil should be casted to nil. Invalid DateTime values should be handled the same way as invalid Date values are handled, i.e. they should be casted to nil.