How Soon Is Now? [Too Soon, Apparently]
> 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.
2 comments
Leave a Comment