Nicer fuzzy time than timespan() #309

Closed
philsturgeon opened this Issue Aug 26, 2011 · 23 comments

Comments

Projects
None yet
Contributor

philsturgeon commented Aug 26, 2011

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?

Contributor

joelcox commented Aug 26, 2011

This is a function I keep adding to my projects, too. I always use time_ago() as function name.

Contributor

philsturgeon commented Aug 26, 2011

Could you post it up here?

Contributor

ericbarnes commented Aug 26, 2011

Here is one I used in the past - https://gist.github.com/1173330

Contributor

joelcox commented Aug 26, 2011

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').

See gist

Contributor

ericbarnes commented Aug 26, 2011

If I am not mistaken mine came from zack @ forrest. Not sure where he found it.

Contributor

ericbarnes commented Aug 26, 2011

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".

Contributor

joelcox commented Aug 26, 2011

Yea, I agree about including future dates.

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".

Reply to this email directly or view it on GitHub:
EllisLab#309 (comment)

Contributor

mpmont commented Aug 26, 2011

Yeah, using that in the Future would be awesome... :)

taftse commented Aug 26, 2011

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

Contributor

kylefarris commented Aug 26, 2011

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...)?

https://gist.github.com/1173470

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?

Contributor

kylefarris commented Aug 26, 2011

@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.

Contributor

marcoscoelho commented Aug 26, 2011

@DennisRas
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.

Contributor

philsturgeon commented Aug 26, 2011

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

Contributor

kylefarris commented Aug 26, 2011

@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.

Contributor

marcoscoelho commented Aug 26, 2011

@DennisRas your suggestion looks more sexy 👍 ... sorry all my equivocal. ;p

psugand commented Sep 1, 2011

I've also written one a while ago, this is what I use. I've saved it as a helper.

https://gist.github.com/1185750

Contributor

narfbg commented Mar 27, 2012

How about this one: EllisLab#1165

Contributor

daparky commented Aug 25, 2012

Which one does everyone suggest using?

Contributor

ckdarby commented Sep 18, 2012

@philsturgeon Pull request was accepted for #1165 this has been resolved; Close :)?

@narfbg narfbg closed this Sep 19, 2012

Dentxinho pushed a commit to Dentxinho/CodeIgniter that referenced this issue Sep 28, 2012

Merge pull request #309 from Dentxinho/cache_users_groups
Fixed little mistake that causes an error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment