Is there a reason string_to_time discards timezone information? (See 
activerecord/lib/active_record/
connection_adapters/abstract/schema_definitions.rb.)

def self.string_to_time(string)
  return string unless string.is_a?(String)
  time_array = ParseDate.parsedate(string)[0..5]
  # treat 0000-00-00 00:00:00 as nil
  Time.send(Base.default_timezone, *time_array) rescue nil
end 

I would have suggested using Time.parse, but when the supplied string doesn't
have a timezone, it interprets the datetime as local, which is not always what
we want.

It might be worth overriding the parse (or make_time) method in Time to support
defaulting to either :local or :utc. This would make timezone support in
string_to_time as easy as:

def self.string_to_time(string)
  return string unless string.is_a?(String)
  # treat 0000-00-00 00:00:00 as nil
  Time.parse(string, Time.now, Base.default_timezone) rescue nil
end 

-- Josh

_______________________________________________
Rails-core mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails-core

Reply via email to