libpurple.framework 2.3.1 as before but with HAVE_OPENSSL defined, which enables...
[adiumx.git] / Source / AILogDateFormatter.m
blob8e6591524f5b26e8f7165a0bf6a4dc5837597e3a
1 //
2 //  AILogDateFormatter.m
3 //  Adium
4 //
5 //  Created by Evan Schoenberg on 7/30/06.
6 //
8 #import "AILogDateFormatter.h"
9 #import "AICalendarDate.h"
10 #import <AIUtilities/AIApplicationAdditions.h>
12 @implementation AILogDateFormatter
14 static BOOL isOnLeopardOrBetter = NO;
16 + (void)initialize
18         if (self == [AILogDateFormatter class]) {
19                 isOnLeopardOrBetter = [[NSApplication sharedApplication] isOnLeopardOrBetter];
20         }
23 - (NSString *)stringForObjectValue:(NSDate *)date
25         NSString *returnValue = nil;
27         if ([self respondsToSelector:@selector(timeStyle)] && [date isKindOfClass:[AICalendarDate class]]) {
28                 int today = [[NSCalendarDate calendarDate] dayOfCommonEra];
29                 int dateDay = [(AICalendarDate *)date dayOfCommonEra];
30                 NSDateFormatterStyle timeStyle = [self timeStyle];
32                 if ((dateDay == today) || (dateDay == (today - 1))) {
33                         NSString                        *dayString = (isOnLeopardOrBetter ?
34                                                         ((dateDay == today) ? AILocalizedString(@"Today", "Day designation for the current day") : AILocalizedString(@"Yesterday", "Day designation for the previous day")) :
35                                                         [[[[NSUserDefaults standardUserDefaults] stringArrayForKey:((dateDay == today) ? NSThisDayDesignations : NSPriorDayDesignations)] objectAtIndex:0] capitalizedString]);
37                         if ((timeStyle != NSDateFormatterNoStyle) &&
38                                 ([(AICalendarDate *)date granularity] == AISecondGranularity)) {
39                                 //Supposed to show time, and the date has sufficient granularity to show it
40                                 NSDateFormatterStyle dateStyle = [self dateStyle];
41                                 NSMutableString *mutableString = [dayString mutableCopy];
43                                 [self setDateStyle:NSDateFormatterNoStyle];
44                                 [mutableString appendString:@" "];
45                                 [mutableString appendString:[super stringForObjectValue:date]];
46                                 [self setDateStyle:dateStyle];
47         
48                                 returnValue = [mutableString autorelease];
49                         }
51                 } else {
52                         if ((timeStyle != NSDateFormatterNoStyle) &&
53                                 ([(AICalendarDate *)date granularity] == AIDayGranularity)) {
54                                 //Currently supposed to show time, but the date does not have that level of granularity
55                                 
56                                 [self setTimeStyle:NSDateFormatterNoStyle];
57                                 returnValue = [super stringForObjectValue:date];
58                                 [self setTimeStyle:timeStyle];
59                         }
60                 }
61         }
63         if (![returnValue length]) returnValue = [super stringForObjectValue:date];
64         if (![returnValue length]) returnValue = [date description];
66         return returnValue;
69 @end