diff options
author | Ari Pollak <ajp@aripollak.com> | 2012-08-14 16:33:06 -0400 |
---|---|---|
committer | Ari Pollak <ajp@aripollak.com> | 2012-08-15 13:21:57 -0400 |
commit | 53ca22f2e11cd3050d75385bc31b6bb5055a2738 (patch) | |
tree | fd60e0bb75247880fb2cb734d68b404644f80c93 /activerecord/lib | |
parent | ebb4a3d5becd535074502a4bf1b61a5b18e30917 (diff) | |
download | rails-53ca22f2e11cd3050d75385bc31b6bb5055a2738.tar.gz rails-53ca22f2e11cd3050d75385bc31b6bb5055a2738.tar.bz2 rails-53ca22f2e11cd3050d75385bc31b6bb5055a2738.zip |
Fix occasional microsecond conversion inaccuracy
ActiveRecord::ConnectionAdapters::Column#microseconds did an unnecessary
conversion to from Rational to float when calculating the integer number
of microseconds. Some terminating decimal numbers in base10 are
repeating decimal numbers in base2 (the format of float), and
occasionally this causes a rounding error.
Patch & explanation originally from Logan Bowers.
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/column.rb | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/column.rb b/activerecord/lib/active_record/connection_adapters/column.rb index b9045cf1e7..1445bb3b2f 100644 --- a/activerecord/lib/active_record/connection_adapters/column.rb +++ b/activerecord/lib/active_record/connection_adapters/column.rb @@ -208,7 +208,7 @@ module ActiveRecord # '0.123456' -> 123456 # '1.123456' -> 123456 def microseconds(time) - ((time[:sec_fraction].to_f % 1) * 1_000_000).to_i + time[:sec_fraction] ? (time[:sec_fraction] * 1_000_000).to_i : 0 end def new_date(year, mon, mday) @@ -233,7 +233,7 @@ module ActiveRecord # Doesn't handle time zones. def fast_string_to_time(string) if string =~ Format::ISO_DATETIME - microsec = ($7.to_f * 1_000_000).to_i + 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 |