You can clone with
Timespan is really handy but often too detailed. In several projects I find myself writing stuff like this:
$tweet->timespan = strtolower(current(explode(',', timespan(strtotime($tweet->created_at))))).' ago';
This produces "4 hours ago" or "1 week ago" which is a bit more in line with how Twitter does it.
Obviously I could write a new function, but I am a bit lazy with things like this. I'm also not sure if it could be added into the existing function as a 3rd param, or what the name of a new function should be. Whatdyathink?
This is a function I keep adding to my projects, too. I always use time_ago() as function name.
Could you post it up here?
Here is one I used in the past - https://gist.github.com/1173330
It's not as nice as yours and involves as bunch of switch statements. I round all quantities lower than 2 to 1 (so 119 seconds would become 'a minute ago').
If I am not mistaken mine came from zack @ forrest. Not sure where he found it.
I actually forgot about timespan. :) I would also like to see the ability to do this with future dates.
That could be beneficial for scheduling items such as blog posts in a cms. "Publish in 1 day 5 mins".
Yeah, using that in the Future would be awesome... :)
This is a function i wrote in 2008 and does the calculations for dates in the past and future (it needs to be cleaned up a bit ) thought it might give people a idea - https://gist.github.com/1173418
I have a Date library that I've been using for a while now that has lots of useful methods in it. It would need some serious code review but it works for me really well (some method names would need to be changed and maybe a few removed since there are similar one already in the Date helper). What are you guys' feelings on adding a new Date library to the core (not that I'm suggest the file I'm linking to by any means...)?
My input: https://gist.github.com/1173514
Edit: Another file below the original which lists the plural words in an array instead for easier localization.
@marcoscoelho your point with that link is?
@marcoscoelho, that feature is only available in PHP >= 5.3 which would alienate a lot of people. It could be incorporated but would have to have checks in place to make sure it was there first.
Sorry, not sure if I'm aware of this talk - maybe due to my poor interpretation, but the function of php does it. But really @kylefarris as you said, is incompatible with CI that still does not encourage the php upgrade.. i'm thinking as php, that said in their latest release that the ideal would be to think now >= 5.3.
We're not upgrading the requirements to PHP 5.3 any time soon, especially not for such a trivial issue. I just want a little bit of fuzzy time. Let's not go mad! :)
@marcoscoelho, my bad actually. I thought it was the link to the date function :) Shoot me!
Anyway my suggestion is still https://gist.github.com/1173514
@DennisRas, haha, when I read the first thing you said to marco, I thought to myself... @DennisRas is kind of a jerk. Honest mistake, though... I forgive you.
UPDATE: By the way, I think your function is perfect.
@DennisRas your suggestion looks more sexy ... sorry all my equivocal. ;p
I've also written one a while ago, this is what I use. I've saved it as a helper.
How about this one: #1165
Which one does everyone suggest using?
@philsturgeon Pull request was accepted for #1165 this has been resolved; Close :)?