Natural language date DISPLAY

  • List:

      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 searched the archives awhile using combinations of
    "NSDateFormatter", "NSCalendarDate", "natural language", etc. in an
    attempt to answer what I feel is a fairly basic question. I found a few
    people asking the same question, but no accompanying answers.

      It's starting to sink in slowly that I will probably need to write my
    own value transformer or something similar but I'm hoping there's a
    handy Cocoa trick that I'm missing ... Or perhaps I just don't know
    what term to search for in the archives or what part of the
    documentation I should be concentrating on.

      Can anybody give me a bump in the right direction? I'm almost sure
    I'll need to roll my own solution and probably could do so in the time
    it'll take for this to post and get a response. It'd be good practice
    ... but I'm a lazy, lazy man. ;-)

      - J

    "Dislikes reinventing the wheel."
    _______________________________________________
    cocoa-dev mailing list | <cocoa-dev...>
    Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    Do not post admin requests to the list. They will be ignored.
  • > 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 | <cocoa-dev...>
    Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    Do not post admin requests to the list. They will be ignored.
previous month june 2004 next month
MTWTFSS
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30        
Go to today