Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Date column bug

#6581

Hello.

create_table :downloads do |t|
  t.date :downloaded_at
  t.integer :count, :default => 0
end

Download.create(:downloaded_at => Time.now)
d = Download.first # => #<Download id: 1, downloaded_at: "2011-03-15", count: 0>
Download.where(:downloaded_at => d.downloaded_at) # => []

Database Mysql, SQLite, rails 3.0.5

if I use Download.create(:downloaded_at => Date.current), I find it after.

Maybe it's not a Bug, but intuitively, it seems that Time.now is correct.

Reported by Jan Bernacki · March 15th, 2011 @ 09:23 AM

State: invalid
Milestone: none
Assigned to: nobody
Importance: Low

Activity

  1. Josh Kalderimis
    Josh Kalderimis
    • State changed from new to invalid
    • Importance changed from to Low

    Hi Releu,

    The difference between Time.now and Date.current is that Time.now has a higher precision.

    When you create a Download using Time.now it is cast to a Date, thus losing its precision. But when you query for a Download using Time.now that precision is not cast but instead just passed to your DB. You can check this for yourself by looking at the logs.

    I will close this issue as it is not a bug.

    Thanks

    Josh

    March 15th, 2011 @ 12:53 PM

  2. Jan Bernacki
    Jan Bernacki

    Hello Josh,

    Thanks for the explanation.

    Yan

    March 15th, 2011 @ 01:07 PM