Created
February 15, 2013 15:30
-
-
Save nataliepo/4961073 to your computer and use it in GitHub Desktop.
NSDateFormatter bug
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// dateString expected format: "2012-08-08 17:31:01 Etc/GMT" | |
// This value comes from our receipt-verification service, | |
// so it's independent of any of the user's settings | |
+(NSDate*)translateExpirePurchaseStringToDate: (NSString*)dateString { | |
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; | |
// strip the ending | |
NSString *purchaseDateString = [dateString stringByReplacingOccurrencesOfString:@" Etc/GMT" withString:@""]; | |
// set the gmt timezone just in case | |
[dateFormatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]]; | |
// -- Here was my bug: | |
// The purchaseDate value assignment below is nil when the user's | |
// preferences are: UK Calendar, London timezone with 24-hour time OFF. | |
// | |
// Having the user turn 24-hour time on in their phone's preferences | |
// yielded an NSDate just fine. | |
// | |
// It wasn't what I'd expected, since the input value is totally | |
// independent of the user's settings. :'( | |
// | |
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"]; | |
NSDate *purchaseDate = [dateFormatter dateFromString:purchaseDateString]; | |
// | |
// ... do some other unrelated things | |
// | |
return purchaseDate; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment