views:

121

answers:

3

What I am searching for is a Cocoa (or third party) class that can display time intervals in natural language, e.g.:

  • 10 seconds ago
  • 1 hour ago
  • 2 days ago

Do you know anything that could help me to achieve this task without writing it by myself and melting in if-else hell?

+4  A: 

Here is Time ago in words for Cocoa, a bit older and I haven't tried it.

I know I've see something more recent but I can't remember where.

stefanB
Thanks, this is exactly what I was looking for.
Rafael
+1  A: 

See -[NSDateFormatter setDoesRelativeDateFormatting:].

Ken
that only offers very limited options
stefanB
Mm, well, recall that you have the rest of the NSDateFormatter API to work with as well.The main limitation I see is that it always formats with respect to the current date.
Ken
+1  A: 

Your question for Cocoa is the same as this question for Cocoa Touch, and the answer to that one will work for you as well, because it uses Foundation, which is in both Cocoa and Cocoa Touch.

Peter Hosey
You don’t really answer my question. All of the proposed solutions in the thread you mention still have to deal with a couple of if-else statements.But thanks for pointing out the thread anyway.
Rafael
The `if (component != 0) /*add component to string*/` statements have to be *somewhere* anyway; how is that a problem? If that's not what you're talking about, then what if statements are you talking about?
Peter Hosey
I just searched for third party stuff that does this for me, so I don’t have to.
Rafael