For seconds and days/weeks it works very well now, 18 seconds ago, 2 hours ago, 2 days ago, 2 weeks ago...
The problem is when it starts to calculate months, for example: 2012-01-01 becomes "one month ago" and it is "one month and 22 days ago" or "One and a half month ago" when it passes 15th day. I like the idea of having an extra parameter for precision. for my needs it needs to be: "now" - when < 10 seconds ago "x seconds ago" - when < 1 minute "x minutes ago" - when < 1 hour "x hours ago" - when < 24 hours (here I dont need the minutes and seconds) "1 day ago" - when < 48 hours "2 days ago" - when < 72 hours .... "7 days ago"- when < 1 week "x weeks ago" - when < 1 month from here I need it to be more precise, because months are a large amount of time "1 month ago" - when < 1 month and 15 days "1 and a half month ago" - when < 2 months or "1 month and x days ago" - when < 2 months The same for years, I did not tested if it calculate years now. "1 year and 2 months ago" - in this case we cant be fuzzy because years are very large amount of time I've found this module[1] which can help with this. [1] Python Date Util - http://labix.org/python-dateutil On Wed, Feb 22, 2012 at 3:23 PM, Michele Comitini < michele.comit...@gmail.com> wrote: > Il 22 febbraio 2012 15:17, Massimo Di Pierro > <massimo.dipie...@gmail.com> ha scritto: > > I did. I can improve it. The goal was to approximate the time, not be > > accurate. How precise does it need to be? > That is a question for an additional arg: > > prettydate(date, precision) > > precision in ['year', 'month', 'week', 'day', 'hour'] or 'auto' > > 'auto' gets the largest unit of time <= now - date > > mic > -- Bruno Rocha [http://rochacbruno.com.br]