adium 4359:e857285aa973: Doh. This can of course be called from ...
commits at adium.im
commits at adium.im
Fri Dec 9 01:01:56 UTC 2011
details: http://hg.adium.im/adium/rev/e857285aa973
revision: 4359:e857285aa973
branch: (none)
author: Thijs Alkemade <thijsalkemade at gmail.com>
date: Fri Dec 09 02:01:26 2011 +0100
Doh. This can of course be called from one of the other functions already on the queue. Make sure that's handled.
diffs (117 lines):
diff -r 020d20c23e1e -r e857285aa973 Frameworks/AIUtilities Framework/Source/AIDateFormatterAdditions.m
--- a/Frameworks/AIUtilities Framework/Source/AIDateFormatterAdditions.m Fri Dec 09 01:04:24 2011 +0100
+++ b/Frameworks/AIUtilities Framework/Source/AIDateFormatterAdditions.m Fri Dec 09 02:01:26 2011 +0100
@@ -30,6 +30,13 @@
#define ONE_SECOND AILocalizedStringFromTableInBundle(@"1 second", nil, [NSBundle bundleWithIdentifier:AIUTILITIES_BUNDLE_ID], nil)
#define MULTIPLE_SECONDS AILocalizedStringFromTableInBundle(@"%1.0lf seconds", nil, [NSBundle bundleWithIdentifier:AIUTILITIES_BUNDLE_ID], nil)
+ at interface NSDateFormatter (PRIVATE)
++ (NSDateFormatter *)localizedDateFormatter;
++ (NSDateFormatter *)localizedShortDateFormatter;
++ (NSDateFormatter *)localizedDateFormatterShowingSeconds:(BOOL)seconds showingAMorPM:(BOOL)showAmPm;
++ (dispatch_queue_t)localizedFormatterQueue;
+ at end
+
typedef enum {
NONE,
SECONDS,
@@ -72,6 +79,8 @@
+ (AIDateFormatterCache *)sharedInstance
{
+ NSAssert(dispatch_get_current_queue() == [NSDateFormatter localizedFormatterQueue], @"Wrong queue");
+
if (!sharedFormatterCache)
sharedFormatterCache = [[AIDateFormatterCache alloc] init];
return sharedFormatterCache;
@@ -112,12 +121,6 @@
}
@end
- at interface NSDateFormatter (PRIVATE)
-+ (NSDateFormatter *)localizedDateFormatter;
-+ (NSDateFormatter *)localizedShortDateFormatter;
-+ (NSDateFormatter *)localizedDateFormatterShowingSeconds:(BOOL)seconds showingAMorPM:(BOOL)showAmPm;
- at end
-
@implementation NSDateFormatter (AIDateFormatterAdditions)
+ (dispatch_queue_t)localizedFormatterQueue
@@ -211,43 +214,43 @@
dispatch_queue_t localizedFormatterQueue = [self localizedFormatterQueue];
__block NSString *formatString;
- dispatch_sync(localizedFormatterQueue, ^{
+ if (dispatch_get_current_queue() != localizedFormatterQueue) {
+ dispatch_sync(localizedFormatterQueue, ^{
+ formatString = [[self localizedDateFormatStringShowingSeconds:YES showingAMorPM:NO] retain];
+ });
+ return [formatString autorelease];
+ }
+
+ 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];
- NSDateFormatter **cachePointer = [[AIDateFormatterCache sharedInstance] formatterShowingSeconds:seconds showingAMorPM:showAmPm];
+ setFormat = YES;
+ }
+
+ if(!showAmPm) {
+ NSMutableString *newFormat = [[NSMutableString alloc] initWithString:[*cachePointer dateFormat]];
+ [newFormat replaceOccurrencesOfString:@"a"
+ withString:@""
+ options:NSBackwardsSearch | NSLiteralSearch
+ range:NSMakeRange(0,[newFormat length])];
- 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];
- });
+ formatString = [newFormat autorelease];
+ } else {
+ formatString = [*cachePointer dateFormat];
+ }
- [formatString autorelease];
+ formatString = [formatString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
+
+ if (setFormat)
+ [*cachePointer setDateFormat:formatString];
return formatString;
}
More information about the commits
mailing list