plainblack.com
Username Password
search
Bookmark and Share

    

database timezone

User martink
Date 12/29/2009 10:50 am
Views 372
Rating 0    Rate [
|
]
Previous · Next
User Message
martink
Hi,

I ran into a bug where the dateOfPurchase field of transaction and the
lastUpdated of transactionItems differ by an hour. I traced this back to
the fact that dateOfPurchase is pouplated with the NOW() mysql function
while the lastUpdated field get its value from
WebGUI::DateTime->new($session,time())->toDatabase. The latter will
alwys be in UTC but the NOW() function uses the timezone of the
database, which in my case is UTC+1.

At first glance, the solution seems to be to replace the NOW() call with
the WebGUI::DateTime version, but then again, the db still inserts those
date as if they are in the db's time zone, which is wrong. However
storing data in anything else than UTC seems like a bad idea as well so
NOW() is a wrong option as well.

So myquestion is, what's the pollicy in this case? Methinks webgui
should set the session TZ for the db when opening the connection, by
issuing a 'SET time_zone = timezone;' command after connecting. After
that dates can be safely inserted in UTC time zone.


Martin*|/||/|*


Back to Top
Rate [
|
]
 
 
martink
Any ideas on this?

Martin

martin@oqapi.nl wrote:
> martink wrote:
>
> Hi,
>
> I ran into a bug where the dateOfPurchase field of transaction and the
> lastUpdated of transactionItems differ by an hour. I traced this back to
> the fact that dateOfPurchase is pouplated with the NOW() mysql function
> while the lastUpdated field get its value from
> WebGUI::DateTime->new($session,time())->toDatabase. The latter will
> alwys be in UTC but the NOW() function uses the timezone of the
> database, which in my case is UTC+1.
>
> At first glance, the solution seems to be to replace the NOW() call with
> the WebGUI::DateTime version, but then again, the db still inserts those
> date as if they are in the db's time zone, which is wrong. However
> storing data in anything else than UTC seems like a bad idea as well so
> NOW() is a wrong option as well.
>
> So myquestion is, what's the pollicy in this case? Methinks webgui
> should set the session TZ for the db when opening the connection, by
> issuing a 'SET time_zone = timezone;' command after connecting. After
> that dates can be safely inserted in UTC time zone.
>
>
> Martin*|/||/|*
>
>
> http://www.webgui.org/forums/dev/database-timezone
> ------------------------------------------------------------------------
>
>
>
>  



Back to Top
Rate [
|
]
 
 
    



© 2012 Plain Black Corporation | All Rights Reserved