Hi Massimo,

I had to deal with this in an application I have been working on but it 
does not run on web2py, it is a service process under the web interface 
part of the application which is web2py based. There is a slight problem 
with making it a session variable which is a form of caching because twice 
a year in locations that use daylight time the offset moves by the amount 
of the time change. I ended up storing UTC which is invariant no matter 
what timezone or whether daylight time is in effect or not and then getting 
the system interpretation of the time on the client whenever I needed it to 
present the local time to the user.

Ron

On Sunday, 17 March 2013 19:31:24 UTC-7, Massimo Di Pierro wrote:
>
> I was looking at code to detect the user timezone and store dates 
> consistently in UTC format.
> I made some changes in trunk to handle this. I could use some help testing.
>
> 1) In the header of your layout.html add:
>
>  {{if not session.timezone:}}
>   <script>
>     
> jQuery(function(){jQuery.post('{{=URL('default','set_timezone')}}',{timezone:(new
>  
> Date()).getTimezoneOffset()});});
>   </script>
> {{pass}}
>
> 2) in the default controller:
>
> def set_timezone():
>     session.timezone = int(request.vars.timezone)/60
>
> 3) Use the new timezone attribute of validators in trunk:
>
>    Field('birthday','datetime',requires = 
> IS_DATETIME(timezone=session.timezone)
>
> Does it work for you? Suggestions for improvement?
>
> Massimo
>

-- 

--- 
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/groups/opt_out.


Reply via email to