Anyone know a good function for calculate time passed?

For instance, you feed it a unix timestamp

and it returns any other following (depending on date):

1 minute ago
10 minutes ago
1 hour ago
5 hours ago
3 days ago
1 month ago
6 months ago
1 year ago