This project is archived and is in readonly mode.
ActiveRecord timezone issues
-
Eugene Pimenov
sorry, it's already fixed
-
Eugene Pimenov
okay, hash conditions works, but string do not.
edge rails, installed via rake rails:freeze:edge today (20 jun 2008)
-
Jeremy Kemper
- Milestone set to 2.1.1
- Assigned user set to Geoff Buesing
- State changed from new to open
-
Geoff Buesing
Time#to_s(:db) ignores Time#zone -- example:
>> Time.mktime(2008, 06, 20, 0, 31, 7).to_s(:db) => "2008-06-20 00:31:07" >> Time.utc(2008, 06, 20, 0, 31, 7).to_s(:db) => "2008-06-20 00:31:07"...therefore, AR will treat Time.mktime values as if they were Time.utc values.
>> Comment.find(:all, :conditions => {:created_at => Time.local(2008,1,1)}) June 19, 2008 21:18 -- Comment Load (0.001406) SELECT * FROM "comments" WHERE ("comments"."created_at" = '2008-01-01 00:00:00')However, if you're setting config.time_zone, you should be able to specify a local time with Time.zone.local() for :conditions, and the correct time value will be sent to the db:
>> Comment.find(:all, :conditions => ['created_at > ?', Time.zone.local(2008,1,1)]) June 19, 2008 21:23 -- Comment Load (0.001179) SELECT * FROM "comments" WHERE (created_at > '2008-01-01 06:00:00') -
Eugene Pimenov
I'm setting config.time_zone…
I think you should consider automatic conversation to UTC…
Because of midnight (and similar) functions. It simply do not point to midnight.
Of course if there're some issues with it, simply close this ticket…
-
Jeremy Kemper
- State changed from open to invalid
-
Richie Vos
- Tag set to activerecord, bug
Jeremy, I know it's been awhile, but can you explain why this is invalid?
It seems like an inconsistent api that the following doesn't work:
@@@ ruby { time = Time.mktime(2000, 1, 1)
Model.create!(:occurred_at => time)
Model.find(:first, :conditions => { :occurred_at => time)
} -
Richie Vos
I am confident I will never properly format a lighthouse post.
-
Richie Vos
- Tag changed from activerecord, bug to activerecord, bug, timezone
Sorry, for 3 separate comments, but I think I should clarify, since I had too much timezone info in my brain and didn't properly say it (will be quite happy when lighthouse gets that edit/preview button).
My environment has my local box's timezone as Central. In my environment.rb I have:
config.time_zone = "Eastern Time (US & Canada)"So when I do
time = Time.mktime(2000, 1, 1) model = Model.create!(:occurred_at => time) model = Model.find(model.id) # just to get it clean from the AR/DB point of viewI end up with a model in the db with the time as
model.occurred_at.to_s: "2000-01-01 01:00:00 -0500"
model.occurred_at_before_type_cast: "2000-01-01 06:00:00"This makes complete sense, since my time was created with an implicit timezone and AR respected that. However, right after doing that, if I do my find, AR doesn't do a conversion, leading to the find not finding anything.
Model.first(:conditions => { :occurred_at => model.occurred_at }) != Model.first(:conditions => { :occurred_at => time })That seems really confusing to me. I can't really think of a reason why that'd be desired behavior.
So I'm thinking I'm misunderstanding something, and would appreciate some clarification.
-
Ryan Bigg
Automatic cleanup of spam.
-
Allan Wake
Great post helped me a lot...
-
booamd
Almost instantly the Trianon became synonymous with gracious travelling and elegant travellers.http://www.vswatches.com
-
marusca91
good site games http://www.jocurifotball.org helped me a lot...
-
semiramida
I found many valuable things to learn in this article. Please keep on posting such quality articles. search here
-
Alexa VIDEOS
Thanks gyus! you helped me a lot!