diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2012-08-18 12:06:25 -0300 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2012-08-18 12:06:25 -0300 |
commit | 3c61642b35a8afbd06af0dc8ccb030504a8563cb (patch) | |
tree | 4c239f4a7ad9f43952bab046b41b05464f18e622 /activerecord/lib/active_record/connection_adapters | |
parent | d6dbd7fbbcb38c7d34a0928bde2bfc7ce21618f0 (diff) | |
download | rails-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/lib/active_record/connection_adapters')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/column.rb | 19 |
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 |