Skip to content

Commit

Permalink
Specify a locale of en_US_POSIX to avoid localization problems in cer…
Browse files Browse the repository at this point in the history
…tain situations, documented by Apple at https://developer.apple.com/library/ios/qa/qa1480/_index.html .  This was seen in testing with iOS, when using a British English current locale and choosing a 12-hour date preference in Settings.  NSDateFormatter actually rewrote the format to output "hh a" despite the request to print out "HH".  Using the POSIX locale ensures the output is not subject to user preferences, which is desired when printint out an ISO6801 compliant format.
  • Loading branch information
boredzo committed Sep 4, 2013
2 parents 6aef760 + 7c9907f commit 738a614
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion ISO8601DateFormatter.m
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,7 @@ - (NSString *) stringFromDate:(NSDate *)date formatString:(NSString *)dateFormat
unparsingFormatter.formatterBehavior = NSDateFormatterBehavior10_4;
unparsingFormatter.dateFormat = dateFormat;
unparsingFormatter.calendar = unparsingCalendar;
unparsingFormatter.locale = [[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"] autorelease];
unparsingFormatter.locale = [[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"] autorelease];
}

unparsingCalendar.timeZone = timeZone;
Expand Down Expand Up @@ -812,6 +812,7 @@ - (NSString *) weekDateStringForDate:(NSDate *)date timeZone:(NSTimeZone *)timeZ
unichar timeSep = self.timeSeparator;
if (!timeSep) timeSep = ISO8601DefaultTimeSeparatorCharacter;
formatter.dateFormat = [self replaceColonsInString:ISO_TIME_WITH_TIMEZONE_FORMAT withTimeSeparator:timeSep];
formatter.locale = [[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"] autorelease];

timeString = [formatter stringForObjectValue:date];

Expand Down

0 comments on commit 738a614

Please sign in to comment.