diff --git a/lib/validates_timeliness/active_record/attribute_methods.rb b/lib/validates_timeliness/active_record/attribute_methods.rb index 5fb04b5..6ee1905 100644 --- a/lib/validates_timeliness/active_record/attribute_methods.rb +++ b/lib/validates_timeliness/active_record/attribute_methods.rb @@ -48,7 +48,7 @@ module ValidatesTimeliness def write_date_time_attribute(attr_name, value, type, time_zone_aware) new = self.class.parse_date_time(value, type) - if new.acts_like?(:time) + if new && type != :date new = new.to_time new = new.in_time_zone if time_zone_aware end diff --git a/spec/active_record/attribute_methods_spec.rb b/spec/active_record/attribute_methods_spec.rb index 5defacd..5aba593 100644 --- a/spec/active_record/attribute_methods_spec.rb +++ b/spec/active_record/attribute_methods_spec.rb @@ -69,6 +69,11 @@ describe ValidatesTimeliness::ActiveRecord::AttributeMethods do @person.birth_date_and_time.should be_kind_of(Time) end + it "should return Time object for datetime attribute read method when assigned Date object" do + @person.birth_date_and_time = Date.today + @person.birth_date_and_time.should be_kind_of(Time) + end + it "should return Time object for datetime attribute read method when assigned string" do @person.birth_date_and_time = "2000-01-01 02:03:04" @person.birth_date_and_time.should be_kind_of(Time)