This project is archived and is in readonly mode.
ActiveRecord UTC support on find with :conditions
-
Gabriel Medina
- Tag changed from :conditions, activerecord, find, utc to :conditions, activerecord, connection, date, datetime, find, quote, quote_bound_value, time, utc
Hi, can't reproduce error ...
SQLite3
Loading development environment (Rails 2.2.0) >> time_str = "2008-07-30T09:44:28+02:00" => "2008-07-30T09:44:28+02:00" >> time = Time.parse time_str => Wed Jul 30 01:44:28 -0600 2008 >> Post.connection.quote(time) => "'2008-07-30 01:44:28'" >>
MySQL
Loading development environment (Rails 2.1.1) >> time_str = "2008-07-30T09:44:28+02:00" => "2008-07-30T09:44:28+02:00" >> time = Time.parse time_str => Wed Jul 30 01:44:28 -0600 2008 >> Post.connection.quote(time) => "'2008-07-30 01:44:28'" >>
Post is a model I made in both MySQL and SQLite3.
This value is handled by quote_bound_value in activerecord/lib/active_record/base.rb as follows ...
def quote_bound_value(value) #:nodoc:
if value.respond_to?(:map) && !value.acts_like?(:string) if value.respond_to?(:empty?) && value.empty? connection.quote(nil) else value.map { |v| connection.quote(v) }.join(',') end else connection.quote(value) endend
This is equivalent to Post.connection.quote(something).
Can anybody else confirm or deny this?
Thanks,
Gabriel Medina.
-
Pratik
- Assigned user set to Michael Koziarski
-
Geoff Buesing
ActiveRecord conditions don't do automatic UTC conversions on Time objects passed in as arguments, so the fact that this query:
XXX.find_all_by_YYY('yyy', :conditions => ["created_at >= ?", Time.now])is not equivalent to this query:
XXX.find_all_by_YYY('yyy', :conditions => ["created_at >= ?", Time.now.utc])is expected behavior.
If ActiveRecord did automatically coerce Time objects in conditions to ActiveRecord::Base.default_timezone, that could potentially be handy behavior, but it would likely break apps that wouldn't be expecting this.
-
Pratik
- State changed from new to wontfix
- Assigned user changed from Michael Koziarski to Geoff Buesing