Be aware of the bug in Rails ActiveSupport String.to_time method

(rdb:1) "2009-09-10 24:00:00".to_time - "2009-09-10 00:00:00".to_time
TypeError Exception: expected numeric or date
(rdb:1) "2009-09-10 24:00:00".to_time.to_time - "2009-09-10 00:00:00".to_time
86400.0
(rdb:1) p "2009-09-10 24:00:00".to_time.class
DateTime
(rdb:1) p "2009-09-10 00:00:00".to_time.class
Time
(rdb:1) 

Source in File vendor/rails/activesupport/lib/active_support/core_ext/time/calculations.rb

def time_with_datetime_fallback(utc_or_local, year, month=1, day=1, hour=0, min=0, sec=0, usec=0)
  ::Time.send(utc_or_local, year, month, day, hour, min, sec, usec)
rescue
  offset = utc_or_local.to_sym == :local ? ::DateTime.local_offset : 0
  ::DateTime.civil(year, month, day, hour, min, sec, offset)
end

Should be enforcing Time casting

def time_with_datetime_fallback(utc_or_local, year, month=1, day=1, hour=0, min=0, sec=0, usec=0)
  ::Time.send(utc_or_local, year, month, day, hour, min, sec, usec)
rescue
  offset = utc_or_local.to_sym == :local ? ::DateTime.local_offset : 0
  ::DateTime.civil(year, month, day, hour, min, sec, offset).to_time
end