Re: Natural language date DISPLAY
Re: Natural language date DISPLAY
- Subject: Re: Natural language date DISPLAY
- From: Jon Hull <email@hidden>
- Date: Tue, 22 Jun 2004 16:34:48 -0700
>
I want my newly-bindings-compliant table to show 'pretty' dates
>
like Mail and Finder. "Today", "Yesterday", or the normal date stamp.
>
I know that the NSDateFormatter accepts natural language input, but
>
can't figure out how to make it use natural language for its
>
*display*. The reverse of "+dateWithNaturalLanguageString:"
I just finished writing something like this... well actually something
a little more complicated which allows various degrees of "Natural
Language" based on preferences. Anyway, all you need to do is put
something like this in a subclass of NSDateFormatter. Warning: I
copied and pasted this together in Mail, so the brackets and such may
be off. You may also want to stash the "Today" type strings in iVars
for a little extra speed.
-(NSString *)stringForObjectValue:(id)obj
{
if(![obj isKindOfClass: [NSDate class]])
return nil;
NSCalendarDate *inDate=obj;
if(![obj isKindOfClass: [NSCalendarDate class]])//if not calendarDate,
then convert
inDate=[obj dateWithCalendarFormat:nil timeZone:nil];
NSUserDefaults *theDefault=[NSUserDefaults standardUserDefaults];
int today=[[NSCalendarDate calendarDate]dayOfCommonEra];
int dateDay=[inDate dayOfCommonEra];
if(dateDay==today)
return [[[theDefault stringArrayForKey:@"NSThisDayDesignations"]
objectAtIndex:0];
if(dateDay==(today+1))
return [[[theDefault stringArrayForKey:@"NSNextDayDesignations"]
objectAtIndex:0] capitalizedString];
if(dateDay==(today-1))
return [[[theDefault stringArrayForKey:@"NSPriorDayDesignations"]
objectAtIndex:0] capitalizedString];
return [super stringForObjectValue:obj];
}
As an aside... What do you guys think is a fair price to charge for an
IBPalette/Framework including a fully user-tested and very flexible
calendarView (that is a view for picking dates) which works in several
different languages (Most countries do not have "SMTWTFS" at the top of
their calendar)... as well as the above mentioned dateFormatter, with
many extra features (again it works with several different languages).
I was thinking about charging different rates based on use:
free for freeware
onetime fixed rate for unlimited shareware use
per project fixed rate for commercial use
Thanks,
Jon
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.