I'm not sure of all the pros and cons of using the different methods to 
format a datetime field.

A datetime fields gets a default IS_DATETIME validator and uses the 
calendar widget in forms which uses the language translation files to 
format the field.

You can also specify a format parameter, which the book recommends, in the 
validator, e.g., IS_DATETIME(format=T("%m/%d/%Y %H:%M:%S")).  Would you 
ever need this since the field gets the same function by default?

Those appear to behave the same way (although the first allows empty 
fields).

You can also specify a represent function for the Field.

The language translation for the datetime validator works in grids and 
forms.

The represent function only works in the grids (which can be an advantage 
when trying to display the timezone since the widget does not support %Z 
format element).

In my case, it's further complicated by formatting for timezones which can 
be done with:

Field('dt_field', 'datetime', default=request.utcnow,
    requires=IS_DATETIME(timezone=pytz.timezone("America/New_York"), 
format=('%x %I:%M %p %Z')))

or

db.sometable. dt_field.represent = lambda value, row:
    
value.replace(tzinfo=pytz.timezone('UTC')).astimezone(pytz.timezone("America/New_York")).strftime('%x
 
%I:%M %p %Z')

What do you think is the preferred method?

Maybe the best method is to use both:

Field('dt_field', 'datetime', default=request.utcnow,
    requires=IS_DATETIME(timezone=pytz.timezone("America/New_York"))

db.sometable. dt_field.represent = lambda value, row:
    value..strftime('%x %I:%M %p %Z')

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to