adium 4358:020d20c23e1e: Run +localizedDateFormatStringShowingSe...
commits at adium.im
commits at adium.im
Fri Dec 9 00:04:33 UTC 2011
details: http://hg.adium.im/adium/rev/020d20c23e1e
revision: 4358:020d20c23e1e
branch: (none)
author: Thijs Alkemade <thijsalkemade at gmail.com>
date: Fri Dec 09 01:04:24 2011 +0100
Run +localizedDateFormatStringShowingSeconds:showingAMorPM: on the queue too, don't just assert it.
diffs (83 lines):
diff -r 180df1384f88 -r 020d20c23e1e Frameworks/AIUtilities Framework/Source/AIDateFormatterAdditions.m
--- a/Frameworks/AIUtilities Framework/Source/AIDateFormatterAdditions.m Fri Dec 09 00:30:12 2011 +0100
+++ b/Frameworks/AIUtilities Framework/Source/AIDateFormatterAdditions.m Fri Dec 09 01:04:24 2011 +0100
@@ -208,41 +208,47 @@
+ (NSString *)localizedDateFormatStringShowingSeconds:(BOOL)seconds showingAMorPM:(BOOL)showAmPm
{
- NSAssert(dispatch_get_current_queue() == [self localizedFormatterQueue], @"Wrong queue");
+ dispatch_queue_t localizedFormatterQueue = [self localizedFormatterQueue];
+ __block NSString *formatString;
- NSString *formatString;
+ dispatch_sync(localizedFormatterQueue, ^{
+
+ NSDateFormatter **cachePointer = [[AIDateFormatterCache sharedInstance] formatterShowingSeconds:seconds showingAMorPM:showAmPm];
+
+ BOOL setFormat = NO;
+
+ if (!(*cachePointer)) {
+ // Get the current time format string
+ *cachePointer = [[NSDateFormatter alloc] init];
+ [*cachePointer setFormatterBehavior:NSDateFormatterBehavior10_4];
+ [*cachePointer setDateStyle:NSDateFormatterNoStyle];
+ [*cachePointer setTimeStyle:(seconds) ? NSDateFormatterMediumStyle : NSDateFormatterShortStyle];
+
+ setFormat = YES;
+ }
+
+ if(!showAmPm) {
+ NSMutableString *newFormat = [[NSMutableString alloc] initWithString:[*cachePointer dateFormat]];
+ [newFormat replaceOccurrencesOfString:@"a"
+ withString:@""
+ options:NSBackwardsSearch | NSLiteralSearch
+ range:NSMakeRange(0,[newFormat length])];
+
+ formatString = [newFormat autorelease];
+ } else {
+ formatString = [*cachePointer dateFormat];
+ }
+
+ formatString = [formatString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
+
+ if (setFormat)
+ [*cachePointer setDateFormat:formatString];
+
+ [formatString retain];
+ });
- NSDateFormatter **cachePointer = [[AIDateFormatterCache sharedInstance] formatterShowingSeconds:seconds showingAMorPM:showAmPm];
-
- BOOL setFormat = NO;
-
- if (!(*cachePointer)) {
- // Get the current time format string
- *cachePointer = [[NSDateFormatter alloc] init];
- [*cachePointer setFormatterBehavior:NSDateFormatterBehavior10_4];
- [*cachePointer setDateStyle:NSDateFormatterNoStyle];
- [*cachePointer setTimeStyle:(seconds) ? NSDateFormatterMediumStyle : NSDateFormatterShortStyle];
+ [formatString autorelease];
- setFormat = YES;
- }
-
- if(!showAmPm) {
- NSMutableString *newFormat = [[NSMutableString alloc] initWithString:[*cachePointer dateFormat]];
- [newFormat replaceOccurrencesOfString:@"a"
- withString:@""
- options:NSBackwardsSearch | NSLiteralSearch
- range:NSMakeRange(0,[newFormat length])];
-
- formatString = [newFormat autorelease];
- } else {
- formatString = [*cachePointer dateFormat];
- }
-
- formatString = [formatString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
-
- if (setFormat)
- [*cachePointer setDateFormat:formatString];
-
return formatString;
}
More information about the commits
mailing list