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.

DateTime:to_s(:db) does not convert to UTC

#2925

ActiveRecord saves datetime fields in UTC, but in prepared statements (for select queries), the quote method does not perform the same conversion. So, for example:

(using US Eastern Time) Shift.create(:starts_at => DateTime.now - 100.minutes, :ends_at => DateTime.now - 50.minutes)
Shift.find(:conditions => ['ends_at < ?',DateTime.now])
=> [] Shift.find(:conditions => ['ends_at < ?',DateTime.now.utc])
=> Shift(Shift id: 1, starts_at: ...)

This doesn't seem the right behavior to me. Shouldn't quote automatically convert to UTC since that's the zone in which the database stores times? Could be done in the to_s(:db) formatter perhaps?

Reported by Ari Epstein · July 20th, 2009 @ 05:31 PM

State: duplicate
Milestone: 2.x
Assigned to: nobody
Importance: none

Activity

  1. Geoff Buesing
    Geoff Buesing
    • State changed from new to duplicate

    I agree the current behavior is confusing. Please see this ticket, which addresses this issue: https://rails.lighthouseapp.com/projects/8994/tickets/2946-quoted_d...

    July 24th, 2009 @ 04:31 AM