aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2012-08-18 12:06:25 -0300
committerRafael Mendonça França <rafaelmfranca@gmail.com>2012-08-18 12:06:25 -0300
commit3c61642b35a8afbd06af0dc8ccb030504a8563cb (patch)
tree4c239f4a7ad9f43952bab046b41b05464f18e622 /activerecord
parentd6dbd7fbbcb38c7d34a0928bde2bfc7ce21618f0 (diff)
downloadrails-3c61642b35a8afbd06af0dc8ccb030504a8563cb.tar.gz
rails-3c61642b35a8afbd06af0dc8ccb030504a8563cb.tar.bz2
rails-3c61642b35a8afbd06af0dc8ccb030504a8563cb.zip
Ruby 1.8 doesn't have to_r defined to NilClass and Float.
Use round to get the right conversion
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/connection_adapters/column.rb19
1 files changed, 14 insertions, 5 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/column.rb b/activerecord/lib/active_record/connection_adapters/column.rb
index 3c5249bca8..393a3b623a 100644
--- a/activerecord/lib/active_record/connection_adapters/column.rb
+++ b/activerecord/lib/active_record/connection_adapters/column.rb
@@ -202,11 +202,20 @@ module ActiveRecord
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