Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

convertToDate - handling 2 different date types #7

Open
ParthaGudivada opened this issue Jul 27, 2013 · 4 comments
Open

convertToDate - handling 2 different date types #7

ParthaGudivada opened this issue Jul 27, 2013 · 4 comments

Comments

@ParthaGudivada
Copy link

If the json object has two date string objects (say, 2013-03-02, 2013-03-02 10:15), can't the convertToDate message handle these formats.

JAGPropertyConverter *converter = [[JAGPropertyConverter alloc] initWithOutputType:kJAGJSONOutput] ;

[converter setConvertToDate:^(id d1)
{
return [NSDate convertFromStringDate:d1 usingFormatterString:DT_yyyy_MM_dd_HH_mm_ss];
} ];

    [converter setConvertToDate:^(id d2)
     {
         return [NSDate convertFromStringDate:d12 usingFormatterString:DT_yyyy_MM_dd];

     }];

I have written a custom method on NSDate to convert different string date formats. What I am seeing is that, I can use only one at any point of time.
Commenting either of the above works fine for the individual date string objects. However if uncomment both of the above, only one gets converted. This lead me to believe that I can convert only one date string object ? Am I missing something. Thanks in advance for your reply.

@jagill
Copy link
Owner

jagill commented Jul 31, 2013

How would you like the converter to decide between which of the formats it should use?

@ParthaGudivada
Copy link
Author

Can the following rules be included :
a) if the convert block has specific reference to the attribute name, allow the specific format.
b) Otherwise, switch to the default one.

@jagill
Copy link
Owner

jagill commented Jul 31, 2013

Could you give me a code example of the API you'd like? Perhaps a general solution would be something like an NSSDictionary of property names to ConvertBlocks, so we'd first check if a property has a particular convert block, and if so use that?

[converter forPropertyName: @"firstDate" setConvertBlock:^(id d1)
  {
    return [NSDate convertFromStringDate:d1 usingFormatterString:@"DT_yyyy_MM_dd_HH_mm_ss"];
  }
];

@ParthaGudivada
Copy link
Author

It makes sense to follow the approach suggested.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants