Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

* Add support for time zones in the Search class when type casting to…

… Time objects.
  • Loading branch information...
commit 3060eaa71db0804ddd2ea5ec7c77d5d9caad2ed6 1 parent 7b6c64f
@binarylogic authored
View
4 CHANGELOG.rdoc
@@ -1,3 +1,7 @@
+== 2.1.7
+
+* Add support for time zones in the Search class when type casting to Time objects.
+
== 2.1.6 released 2009-07-13
* Fix bug when trying to set conditions on conflicting column names with associations. Ex: User.has_many :orders, User.order_count_gt(10) would raise an exception because it was trying to set conditions on the count column for the orders table.
View
3  lib/searchlogic/search.rb
@@ -143,7 +143,8 @@ def type_cast(value, type)
# with the other models.
column_for_type_cast = ActiveRecord::ConnectionAdapters::Column.new("", nil)
column_for_type_cast.instance_variable_set(:@type, type)
- column_for_type_cast.type_cast(value)
+ value = column_for_type_cast.type_cast(value)
+ Time.zone && value.is_a?(Time) ? value.in_time_zone : value
end
end
end
View
7 spec/search_spec.rb
@@ -226,6 +226,13 @@
search.created_at_after.should == Time.parse("Jan 1, 2009 9:33AM")
end
+ it "should convert the time to the current zone" do
+ search = Order.search
+ now = Time.now
+ search.created_at_after = now
+ search.created_at_after.should == now.in_time_zone
+ end
+
it "should be an Array and cast it's values given ['1', '2', '3']" do
search = Order.search
search.id_equals_any = ["1", "2", "3"]
View
3  spec/spec_helper.rb
@@ -3,6 +3,9 @@
require 'ruby-debug'
require 'activerecord'
+ENV['TZ'] = 'UTC'
+Time.zone = 'Eastern Time (US & Canada)'
+
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :dbfile => ":memory:")
ActiveRecord::Base.configurations = true
Please sign in to comment.
Something went wrong with that request. Please try again.