To keep things simple on the database side; how about making all times UTC?
Then use JavaScript to impose timezone on the client-side. On Wed, Feb 13, 2013 at 2:20 PM, Michael Beller <[email protected]> wrote: > this stores dates in UTC but displays date in alternate timezone. You can > set the represent property based on a timezone stored in the users profile > or derived from locale settings ... > > from pytz import timezone > import pytz > > db.define_table('t_date', > Field('f_name'), > Field('f_datetime', type='datetime', default=request.utcnow), > Field('f_utcdatetime', type='datetime', default=request.utcnow), > migrate=True) > > db.t_date.f_datetime.represent = lambda value, row : > pytz.UTC.localize(value).astimezone(timezone('US/Eastern')) > > > I used information in the following two pages for help ... > > http://stackoverflow.com/questions/7065164/how-to-make-an-unaware-datetime-timezone-aware-in-python?lq=1 > http://pypi.python.org/pypi/pytz/ > > On Tuesday, February 12, 2013 7:40:59 AM UTC-5, Michael Beller wrote: >> >> I've also been researching and experimenting ... >> >> I've come to the conclusion to only store utc dates (e.g., using utcnow) >> in the data base and then use .represent or other means to convert for >> display. >> >> Most notably, use the putz python library ... >> >> >> On Tuesday, February 12, 2013 1:58:26 AM UTC-5, rochacbruno wrote: >>> >>> I am on mobile now and I cant ellaborate a good code example, but I can >>> give you a hint. >>> >>> db.table.datefield.represent = lambda value, row : >>> value.strftime("%Y/%m/%d") >>> >>> grid = SQLFORM.grid(db.table) >>> >>> so grid will use the represent callback to display the data. >>> >>> following this example you can do >>> >>> def set_timezone(value, row): >>> return value. #do the calculation >>> >>> db.table.field.represent = set_timezone >>> >>> Em 12/02/2013 04:44, "newbie" <[email protected]> escreveu: >>>> >>>> >>>> On Tuesday, 12 February 2013 11:06:00 UTC+5:30, newbie wrote: >>>>> >>>>> Hi, >>>>> I have a table x, with fields name,place,timezone_offset.And >>>>> another table y ,having field 'servertime',which stores the current time >>>>> of >>>>> the server its fetching the values from. >>>>> >>>>> >>>>> db.define_table('x',Field('name'),Field('place'),Field('timezone_offset')) >>>>> db.define_table('y',Field('name'),Field('servertime')) >>>> >>>> >>>> User will set the timezone offset in table x, for a particular name. >>>> There is one thread continuously running in background in the server which >>>> will save the servertime as local time using datetime.datetime.now() in >>>> table y for the name. >>>> >>>> And finally this data displayed by using SQLFORM.grid on the UI. >>>> >>>> Problem facing: >>>> We have to convert the local time saved for the name field as per saved >>>> timezone_offset in x table and display on the grid without modifying >>>> anything on database level. >>>> It means suppose for name ='Alex' timezone_offset was being saved as -5 >>>> in x table and suppose server running on different timezone lets say on >>>> +5.30 so for name Alex server will save the servertime in +5.30 format as >>>> it >>>> is the local time for the server but when it will be displayed on the grid >>>> servertime should first get converted to Alex timezone_offset which is set >>>> as -5 and then display on the grid. >>>> >>>> Can anyone please suggest me how can I achieved in web2py? Is there any >>>> way to achieve it using SQLFORM.grid()? >>>> >>>> Thanks. >>>> >>>> >>>> >>>>> >>>>> >>>> >>>> -- >>>> >>>> --- >>>> 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 [email protected]. >>>> For more options, visit https://groups.google.com/groups/opt_out. >>>> >>>> > > -- > > --- > 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 [email protected]. > For more options, visit https://groups.google.com/groups/opt_out. > > -- --- 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 [email protected]. For more options, visit https://groups.google.com/groups/opt_out.

