How Soon Is Now? [Too Soon, Apparently]

Jul 31st — 12:10 PM

> Foo.create 
# => #<Foo id: 1, created_at: "2008-07-31 11:37:02", updated_at: "2008-07-31 11:37:02">
> Foo.find :all, :conditions => {:created_at => 1.day.ago..Time.now}
# => []
> Foo.find :all, :conditions => {:created_at => 1.day.ago..Time.zone.now}
# => [#<Foo id: 1, created_at: "2008-07-31 11:37:02", updated_at: "2008-07-31 11:37:02">]

If it’s not obvious why that first find didn’t work, it’s because I’m using UTC on my timestamps and Time.now is 4 hours behind that where I live at this time of year. Swaddling it with time zone action fixes it right up though.

Filed under: stunt ruby, rails

2 comments

  • blj said
    I remember something weird going on like this in production. I did not even know I had the problem in my development, as it was ahead of UTC and the deployment was not. I later figured out the timezone was the problem. Good to know about the Time.zone.now. Thanks.
  • blj said
    May be you are interested in this http://blog.7thcross.com/?p=24

Leave a Comment

Lucky Sneaks is designed and managed by Lucky Sneaks
All content © Lucky Sneaks 2008
Lucky Sneaks is Lucky Sneaks