Permalink
Browse files

Ruby 1.8 doesn't have to_r defined to NilClass and Float.

Use round to get the right conversion
  • Loading branch information...
1 parent d6dbd7f commit 3c61642b35a8afbd06af0dc8ccb030504a8563cb @rafaelfranca rafaelfranca committed Aug 18, 2012
Showing with 14 additions and 5 deletions.
  1. +14 −5 activerecord/lib/active_record/connection_adapters/column.rb
@@ -202,11 +202,20 @@ def fast_string_to_date(string)
end
end
- # Doesn't handle time zones.
- def fast_string_to_time(string)
- if string =~ Format::ISO_DATETIME
- microsec = ($7.to_r * 1_000_000).to_i
- new_time $1.to_i, $2.to_i, $3.to_i, $4.to_i, $5.to_i, $6.to_i, microsec
+ if RUBY_VERSION >= '1.9'
+ # Doesn't handle time zones.
+ def fast_string_to_time(string)
+ if string =~ Format::ISO_DATETIME
+ microsec = ($7.to_r * 1_000_000).to_i
+ new_time $1.to_i, $2.to_i, $3.to_i, $4.to_i, $5.to_i, $6.to_i, microsec
+ end
+ end
+ else
+ def fast_string_to_time(string)
+ if string =~ Format::ISO_DATETIME
+ microsec = ($7.to_f * 1_000_000).round.to_i
+ new_time $1.to_i, $2.to_i, $3.to_i, $4.to_i, $5.to_i, $6.to_i, microsec
+ end
end
end

0 comments on commit 3c61642

Please sign in to comment.