Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #9137 (new defect)

Opened 1 year ago

Last modified 1 year ago

[PATCH] Column.string_to_dummy_time should return nil on invalid input

Reported by: bmihelac Assigned to: core
Priority: normal Milestone: 2.x
Component: ActiveRecord Version: edge
Severity: normal Keywords: tiny
Cc:

Description

Method string_to_dummy_time returns nil if value is empty string, but returns "Sat Jan 01 00:00:00 CET 2000" if invalid string is passed:

>> ActiveRecord::ConnectionAdapters::Column.string_to_dummy_time("bla")
=> Sat Jan 01 00:00:00 CET 2000
>> ActiveRecord::ConnectionAdapters::Column.string_to_time("bla")
=> nil

I think that string_to_dummy_time should return nil instead of setting time to 00:00:00 so typecasting of invalid string would not put valid time in database.

Attachments

dummy_time_parser_returns_nil.diff (1.2 kB) - added by kampers on 07/30/07 15:25:02.

Change History

07/30/07 15:24:29 changed by kampers

  • keywords set to tiny.
  • summary changed from Column.string_to_dummy_time should return nil for :time type if parsed string does not contain any time information to [PATCH] Column.string_to_dummy_time should return nil on invalid input.

OK, I can verify this behavior. It does seem like it would be better to have it return nil--that it doesn't, compared to string_to_time, is just an artifact of the implementation.

Here's a one-liner for the implementation, plus some docs. Anybody have input on where the best place would be to put the tests? I don't see anything for any methods in schema_definitions.rb. Time to create a new test file?

Nice catch, bmihelac.

07/30/07 15:25:02 changed by kampers

  • attachment dummy_time_parser_returns_nil.diff added.