adium-1.4 2670:480c348d8629: Fix a few date formatter issues. Fi...

commits at adium.im commits at adium.im
Wed Oct 28 18:27:50 UTC 2009


details:	http://hg.adium.im/adium-1.4/rev/480c348d8629
revision:	2670:480c348d8629
author:		Zachary West <zacw at adium.im>
date:		Wed Oct 28 14:27:46 2009 -0400

Fix a few date formatter issues. Fixes #11981. Fixes #12545.

Previously, the "!sec && !ampm" date formatter was mixed with the "!sec && ampm" date formatter; this was bad. Now we separate these two cases into their own. As well, when removing
 AMPM, we commit the format change to the date formatter so that it actually will use the correct format. This fixes the trailing space problem by trimming whitespace, which also tackles the removal of AMPM causing display differences (remember that "ampm" doesn't _necessarily_ come last in a localized date format).

diffs (87 lines):

diff -r aa2b8878166d -r 480c348d8629 Frameworks/AIUtilities Framework/Source/AIDateFormatterAdditions.m
--- a/Frameworks/AIUtilities Framework/Source/AIDateFormatterAdditions.m	Wed Oct 28 13:50:22 2009 -0400
+++ b/Frameworks/AIUtilities Framework/Source/AIDateFormatterAdditions.m	Wed Oct 28 14:27:46 2009 -0400
@@ -35,6 +35,7 @@
 	NSDateFormatter *localizedDateFormatterShowingSecondsAndAMPM;
 	NSDateFormatter *localizedDateFormatterShowingAMPM;
 	NSDateFormatter *localizedDateFormatterShowingSeconds;
+	NSDateFormatter *localizedDateFormatterShowingNoSecondsOrAMPM;
 }
 
 + (AIDateFormatterCache *)sharedInstance;
@@ -71,9 +72,12 @@
 {
 	if (sec && ampm)
 		return &localizedDateFormatterShowingSecondsAndAMPM;
-	if (sec)
+	else if (sec && !ampm)
 		return &localizedDateFormatterShowingSeconds;
-	return &localizedDateFormatterShowingAMPM;
+	else if (!sec && ampm)
+		return &localizedDateFormatterShowingAMPM;
+	else // if (!sec && !ampm)
+		return &localizedDateFormatterShowingNoSecondsOrAMPM;
 }
 
 - (NSDateFormatter **)formatter
@@ -94,6 +98,7 @@
 	[localizedDateFormatterShowingSecondsAndAMPM release];
 	[localizedDateFormatterShowingAMPM release];
 	[localizedDateFormatterShowingSeconds release];
+	[localizedDateFormatterShowingNoSecondsOrAMPM release];
 	[super dealloc];
 }
 @end
@@ -147,27 +152,35 @@
 	
 	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"
+		[newFormat replaceOccurrencesOfString:@"a"
 								   withString:@""
 									  options:NSBackwardsSearch | NSLiteralSearch
 										range:NSMakeRange(0,[newFormat length])];
-		formatString = [newFormat copy];
+		
+		formatString = [newFormat stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
 		[newFormat release];
+		
+		if (setFormat)
+			[*cachePointer setDateFormat:formatString];
 	} else {
-		formatString = [[*cachePointer dateFormat] retain];
+		formatString = [*cachePointer dateFormat];
 	}
 	
-	return [formatString autorelease];
+	return formatString;
 }
 
 + (NSString *)stringForTimeIntervalSinceDate:(NSDate *)inDate
diff -r aa2b8878166d -r 480c348d8629 Plugins/WebKit Message View/AIWebkitMessageViewStyle.m
--- a/Plugins/WebKit Message View/AIWebkitMessageViewStyle.m	Wed Oct 28 13:50:22 2009 -0400
+++ b/Plugins/WebKit Message View/AIWebkitMessageViewStyle.m	Wed Oct 28 14:27:46 2009 -0400
@@ -731,9 +731,6 @@
 				  withString:(date ? [timeStampFormatter stringFromDate:date] : @"")];
 
 	NSString *shortTimeString = (date ? [[NSDateFormatter localizedDateFormatterShowingSeconds:NO showingAMorPM:NO] stringFromDate:date] : @"");
-#warning working around http://trac.adium.im/ticket/11981
-	if ([shortTimeString hasSuffix:@" "])
-		shortTimeString = [shortTimeString substringToIndex:shortTimeString.length - 1];
 	[inString replaceKeyword:@"%shortTime%"
 				  withString:shortTimeString];
 




More information about the commits mailing list