[web2py] Re: how to display date and time nicely?

2010-02-18 Thread Iceberg
IMHO, the example's code is good, but not cool enough to be put in the book. Every programmer saw those ordinary if...elif...elif...else cliche in their first program language book before. People can probably write their own if...elif...else in less time, than STFW or RTFM to find our

[web2py] Re: how to display date and time nicely?

2010-02-18 Thread mdipierro
the one in gluon tools does prettydate(request.now,T) On Feb 18, 7:49 am, Iceberg iceb...@21cn.com wrote: IMHO, the example's code is good, but not cool enough to be put in the book. Every programmer saw those ordinary if...elif...elif...else cliche in their first program language book

[web2py] Re: how to display date and time nicely?

2010-02-15 Thread Richard
added a few more cases: def prettydate(d): try: dt = datetime.now() - d except: return '' if dt.days = 2*365: return '%d years ago' % int(dt.days / 365) elif dt.days = 365: return '1 year ago' elif dt.days = 60: return '%d months ago' %

[web2py] Re: how to display date and time nicely?

2010-02-15 Thread mdipierro
for lack of a better option I put it in tools for now. On Feb 15, 5:56 pm, Richard richar...@gmail.com wrote: added a few more cases: def prettydate(d):     try:         dt = datetime.now() - d     except:         return ''     if dt.days = 2*365:         return '%d years ago' %

Re: [web2py] Re: how to display date and time nicely?

2010-02-15 Thread Jason Brower
These examples would be a very good edition to the book -- J On Mon, 2010-02-15 at 16:19 -0800, mdipierro wrote: for lack of a better option I put it in tools for now. On Feb 15, 5:56 pm, Richard richar...@gmail.com wrote: added a few more cases: def prettydate(d): try:

[web2py] Re: how to display date and time nicely?

2010-02-14 Thread mdipierro
Put this in a model def prettydate(d): try: dt = request.now - d except: return '' if dt.days=365*2: return '%s years ago' % int(dt.days/365) elif dt.days=365: return '1 years ago' elif dt.days=60: return '%s months ago' %

[web2py] Re: how to display date and time nicely?

2010-02-14 Thread selecta
:) On Feb 15, 12:54 am, mdipierro mdipie...@cs.depaul.edu wrote: Put this in a model def prettydate(d):     try:         dt = request.now - d     except:         return ''     if dt.days=365*2:         return '%s years ago' % int(dt.days/365)     elif dt.days=365:         return '1