1. Ben Bangert
  2. WebHelpers
Issue #17 new

Alternate distance_of_time_in_words

Mike Orr
created an issue

My one request would be to have a more sensible version of webhelpers.date.distance_of_time_in_words helper.

Namely, I like what John Resig did in Javascript, which I ported to Python:

http://gist.github.com/240045 (you're more than welcome to use it if you like).

I submit that the current implementation is more granular and flexible, but the code that's required to run it is complex, overwhelming and hard to understand. I think this approach (which Django has a similar one for) covers more than 80% of the use cases in less than 20% of the complexity.

I've always seen webhelpers as a relatively minimal and concise collection of tools that help cut that 80/20 utility/effort ratio. I think this addition or modification would be a good candidate.

  • shazow

P.S. It's possible to do a wrapper to give this default behaviour on top of the current implementation but the underlying complexity of the code to achieve that seems overkill and makes me feel dirty.

Comments (1)

  1. Mike Orr reporter

    Those nested and's and or's are way too complex. Use short expressions and if's if you want to get this into WebHelpers.

    Also, it should probably be called time_ago_in_words2 because that's what it is. It's not a pretty_date function, if that means formatting a date for display. This doesn't format a date, it calculates "X time ago". So calling it pretty_date would be misleading.

    Also, does it work properly with future dates?

  2. Log in to comment