Re: [web2py] Re: how to adjust timezone for request.now ?
I was thinking of the values you would ultimately store in the database and what you might use them for eventually. If you want to use these times in a SQL expression in the WHERE clause through direct SQL or through DAL expressions and search across multiple users for something created between time X and Y then they should all be resolved and then stored to the same time zone not different ones. In that case you would want to work in UTC on the server and then convert using Javascript in the user's browser since the user's workstation should have the proper setting for the time zone they are in which will trickle down through the browser and the Javascript code to convert between UTC and local time for each particular user. However, since there is no real background for what you want to do with the time values from the application perspective it is difficult to advise you without some speculation. :-) Massimo's comment is spot on. The default in the server is to generate the time as the local time of the server when the request comes in which again would be consistent if all your servers are in the same timezone. To get UTC just assign request.now = datetime.utcnow() and use the value consistently. If you never intend to use the times for comparison across multiple users then you can store in the user's local time but I think you will also need to store the user's timezone as well to be able to render it back out to the user later for display.
Re: [web2py] Re: how to adjust timezone for request.now ?
2011/5/21 pbreit pbreitenb...@gmail.com: This is the best answer I've seen: http://stackoverflow.com/questions/117514/how-do-i-use-timezones-with-a-datetime-object-in-python It can get complicated so make sure you need it. i thought i would be easy when I read massimo saying something about it massimo@ https://mail.google.com/mail/?shva=1#search/timezone/12b3890a88661c83 I think you just need to re-assign the value of request.now to the date you want at the top of your model and then use request.now consistently.
[web2py] Re: how to adjust timezone for request.now ?
2011/5/19 danto web2py.n...@gmail.com: I'm setting the created_on field in a database table with request.now but i need to adjust the result to my timezone with the application (it's a shared server). Can you tell me how can I achieve this? thank you in advance kind regards sorry, it's the answer so obviuous?emp
[web2py] Re: how to adjust timezone for request.now ?
Actually it isn't that obvious. In Python the datetime class by default is not time zone aware. If you have users coming from multiple time zones the best universal way to handle this is store the time in UTC which the datetime class has a method for datetime.utcnow(). This is how UNIX does it internally and then warps the time to the local time of the user based on their environment variable setting. If you don't do this then time comparisons across users become a real bear to deal with. If you have all the users on one server it will be the server time that is used to fill the database fields if you use datetime.now() instead so you might be able to manage it that way. The browser client through Javascript knows the timezone of the client and without being specific I believe there is a way to get from UTC to local time in Javascript. So again it comes back to using UTC on the server for the least effort over all. Hope that helps Ron
[web2py] Re: how to adjust timezone for request.now ?
This is the best answer I've seen: http://stackoverflow.com/questions/117514/how-do-i-use-timezones-with-a-datetime-object-in-python It can get complicated so make sure you need it.