Post

Replies

Boosts

Views

Activity

Value of [NSTimeZone localTimeZone] differs between iOS10 and iOS11 GM
We're currently looking into moving our app to iOS 11 when we discovered a portion of our legacy code used to convert UTC date times to localized date time strings is returning differing values between iOS 10 and iOS 11. When running a fresh install of our app on simulators (after resetting content and settings) we see the following output:10.3.1:(lldb) po [NSTimeZone localTimeZone]Local Time Zone (America/Toronto (EDT) offset -14400 (Daylight))11.0:(lldb) po [NSTimeZone localTimeZone]Local Time Zone (America/Los_Angeles (PDT) offset -25200 (Daylight))I created a fresh project and have the same results when I run the following snippit highlighting the issue:- (void)logLocalizedDate { // Setup: Create a UTC date time NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss zzz"]; NSDate *utcDate = [dateFormatter dateFromString: @"2017-08-18 00:00:00 UTC"]; [NSTimeZone setDefaultTimeZone:[NSTimeZone timeZoneWithName:@"UTC"]]; // Now convert it to a local time zone string NSString *localizedDateString = [self computeLocalTimeZoneDayStringFromDate:utcDate]; NSLog(@"Computed Date String: %@", localizedDateString); } -(NSString *)computeLocalTimeZoneDayStringFromDate:(NSDate *)dateToCompute { // Create a localized date formatter NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en"]]; [dateFormatter setDateFormat:@"yyyy-MM-dd"]; // This call differs between iOS10 and iOS 11 dateFormatter.timeZone = [NSTimeZone localTimeZone]; NSString *date = [dateFormatter stringFromDate:dateToCompute]; return date; }Anything wrong here? We've never had an issue in the past and similar code in our app has been ported from iOS 8 -> 9 -> 10 with no issues. In fact it hasn't changed since 2014.Thanks
14
0
12k
Sep ’17