-
Type: Task
-
Resolution: Done
-
Affects Version/s: None
-
Component/s: None
-
None
When parsing strings as time the ActiveSupport::TimeZone.parse was returning nil on malformed Time strings and then converting into a float of 0.0 and becoming a Time. However the Time.parse throws the expected ArgumentError which mongoid throws back to the user.
When using Time with zone:
ruby Mongoid.use_activesupport_time_zone = true class TestDateTimeField include Mongoid::Document field :dt, type: DateTime end test = TestDateTimeField.new test.dt = "not a time" test.dt #=> Thu, 01 Jan 1970 01:00:00 +0100 test.dt = "" test.dt #=> nil test.dt = 1234567 test.dt #=> Thu, 15 Jan 1970 07:56:07 +0100 test.dt = "1234567" test.dt #=> Sun, 01 Jan 1234 00:00:00 -0001
When using just Time
ruby Mongoid.use_activesupport_time_zone = false test.dt = "not a time" test.dt #=> Mongoid::Errors::InvalidTime: 'not a time' is not a valid Time. test.dt = "" test.dt #=> nil test.dt = 1234567 test.dt #=> Thu, 15 Jan 1970 07:56:07 +0100 test.dt = "1234567" test.dt #=> Sun, 01 Jan 1234 00:00:00 +0100
`