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

dateWithString:format: returning nil #113

Closed
evanrobertson opened this issue Oct 13, 2015 · 1 comment
Closed

dateWithString:format: returning nil #113

evanrobertson opened this issue Oct 13, 2015 · 1 comment

Comments

@evanrobertson
Copy link

If I try and create a date from a format string every so often it will return nil, whilst using dateWithYear:month:day: with the same parameters will return the correct value.

Unsure if this is a bug with the library, looking at the method it seems like it might be something I am doing wrong, however I would like to know what I may be doing wrong.

NSNumber *year = @(2015);
NSNumber *month = @(10);

NSString *dateString = [NSString stringWithFormat:@"01/%@/%@", month, year];
NSDate *key = [NSDate dateWithString:dateString formatString:@"dd/MM/yyyy"]; // Sometimes nil
NSDate *key2 = [NSDate dateWithYear:year month:month day:1]; // Always successful
@evanrobertson
Copy link
Author

To answer my own question,
NSDateFormatter is thread-unsafe

As is NSCalendar, so I guess my next question is about thread safety in DateTools, can we make improvements to allow us to work with dates on multiple threads?

So it turns out that NSDateFormatter is thread safe as of iOS 7, however it seems that you shouldn't be changing values on it from different thread, i.e. format string and time zone

What should we do to handle the scenario here where we are explicitly changing those values and it could be across threads?

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

1 participant