2 // AILogDateFormatter.m
5 // Created by Evan Schoenberg on 7/30/06.
8 #import "AILogDateFormatter.h"
9 #import "AICalendarDate.h"
10 #import <AIUtilities/AIApplicationAdditions.h>
12 @implementation AILogDateFormatter
14 static BOOL isOnLeopardOrBetter = NO;
18 if (self == [AILogDateFormatter class]) {
19 isOnLeopardOrBetter = [[NSApplication sharedApplication] isOnLeopardOrBetter];
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];
48 returnValue = [mutableString autorelease];
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
56 [self setTimeStyle:NSDateFormatterNoStyle];
57 returnValue = [super stringForObjectValue:date];
58 [self setTimeStyle:timeStyle];
63 if (![returnValue length]) returnValue = [super stringForObjectValue:date];
64 if (![returnValue length]) returnValue = [date description];