This project is archived and is in readonly mode.
DateTime:to_s(:db) does not convert to UTC
Reported by Ari Epstein | July 20th, 2009 @ 05:31 PM | in 2.x
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?
Comments and changes to this ticket
-
Geoff Buesing July 24th, 2009 @ 04:31 AM
- 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...
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>