
do_mysql inserts incorrect time if using time zone other than local
Reported by siplux | January 28th, 2009 @ 04:46 PM
In MySQL, datetime columns do not retain any time-zone information unlike for example, PostGreSQL which saves the TZ. MySQL instead assumes that the time is local and adjusts it to UTC before inserting (http://tinyurl.com/d9syqn). This will causes a problem if you're working exclusively with UTC timezones rather than local. MySQL, with no concept of TZ, will attempt to convert an a UTC timestamp to UTC which will obviously end up writing the wrong datetime.
Date(times) are always set to the current time zone while maintaining the date information in the database, this results in an incorrect time (UTC elements with a local time zone).
class Article ... property :created_at, Time end %irb% Article.create(:created_at => Time.now.utc - 1.hour) Article.all(:created_at.lte => Time.now.utc) -> [#<Article id=1 created_at=Thu Jan 29 01:30:54 -0700 2009>] Article.all.find_all {|a| a.created_at <= Time.now.utc} -> [] Article.first.created_at < Time.now.utc -> false (Time.utc *Article.first.created_at.to_a) < Time.now.utc -> true
Comments and changes to this ticket
-
siplux January 28th, 2009 @ 04:49 PM
I guess it would be important to decide whether or not this is a MySQL problem or a DataMapper problem by way of trying to mitigate differences in DBs.
-
Dan Kubb (dkubb) February 1st, 2009 @ 02:56 PM
- Assigned user set to Dirkjan Bussink
-
Dan Kubb (dkubb) September 10th, 2009 @ 03:49 PM
- State changed from unconfirmed to hold
Any progress on this Dirkjan? Is this a duplicate of other tickets? Marking this as on-hold for now.
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »