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

24-hour time problem in Parsing receipt date #57

Closed
joeltay17 opened this issue Feb 26, 2014 · 3 comments
Closed

24-hour time problem in Parsing receipt date #57

joeltay17 opened this issue Feb 26, 2014 · 3 comments
Labels

Comments

@joeltay17
Copy link
Contributor

In RMAppReceipt.m file, the +(NSDate)formatRFC3339String:(NSString)string method

the dateFormat is incompatible with certain settings, example:

If the phone region format setting (General > International > Region Format) is changed to United Kingdom, and the 24-Hour Time Switch is turned off (General > Date & Time).

Because of this, I'm able to get my purchased products' bundle ID, but I cannot get the proper return of NSDate values from [RMAppReceiptIAP originalPurchaseDate], [RMAppReceiptIAP subscriptionExpirationDate], and basically anything that returns a date. It will return me a null value (basically dateformatter failed).

The string before parsing the date looks like this: "2014-02-20T04:27:04Z" without quotes.
And the dateFormat is this: "yyyy-MM-dd'T'HH:mm:ssZ" without quotes.
Changing HH to hh fixes the specfic setting described above (Region Format and 24 hour switch), but I'm not sure if it breaks the other combinations of settings (Different region formats with different 24 hour settings).

Hope you guys can fix this asap :)

@joeltay17
Copy link
Contributor Author

Ahhhh. the fix is simple. sorry to bother.

static NSDateFormatter *formatter;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
formatter = [[NSDateFormatter alloc] init];
[formatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"]];
formatter.dateFormat = @"yyyy-MM-dd'T'HH:mm:ssZ";
});
NSDate *date = [formatter dateFromString:string];
return date;

explicitly setting locale.

@hpique hpique reopened this Mar 4, 2014
@hpique
Copy link
Member

hpique commented Mar 4, 2014

Nice catch! I believe this is related to this Apple bug/feature: http://stackoverflow.com/questions/6613110/what-is-the-best-way-to-deal-with-the-nsdateformatter-locale-feature.

Would you mind submitting a pull request with the fix? I can do it myself, but I'd rather have you appear in the list of contributors. :)

@hpique hpique added the bug label Mar 4, 2014
@joeltay17
Copy link
Contributor Author

Ahhh, that's very nice of you! I'm honored! 😄

@hpique hpique closed this as completed in cb3a4c5 Mar 6, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants