aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2012-01-05 09:08:30 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2012-01-05 09:08:30 -0800
commit1dbbe7b663f55c72023a06fbb97f379de6e6916f (patch)
treed3502763df4b08c0bf35efbcd14bf331fec9bfd0 /activesupport
parent3040940ab5576d8ceb17fa3cc83223815371be7c (diff)
parentc766f3e4b013cf4bcc4ad9ba64636bbf944b320c (diff)
downloadrails-1dbbe7b663f55c72023a06fbb97f379de6e6916f.tar.gz
rails-1dbbe7b663f55c72023a06fbb97f379de6e6916f.tar.bz2
rails-1dbbe7b663f55c72023a06fbb97f379de6e6916f.zip
Merge pull request #4316 from wrozka/time_advance_nsec
Time advance nsec bug
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/lib/active_support/core_ext/time/calculations.rb2
-rw-r--r--activesupport/test/core_ext/time_ext_test.rb5
2 files changed, 6 insertions, 1 deletions
diff --git a/activesupport/lib/active_support/core_ext/time/calculations.rb b/activesupport/lib/active_support/core_ext/time/calculations.rb
index f3235d11bb..5e433f5dd9 100644
--- a/activesupport/lib/active_support/core_ext/time/calculations.rb
+++ b/activesupport/lib/active_support/core_ext/time/calculations.rb
@@ -78,7 +78,7 @@ class Time
options[:hour] || hour,
options[:min] || (options[:hour] ? 0 : min),
options[:sec] || ((options[:hour] || options[:min]) ? 0 : sec),
- options[:usec] || ((options[:hour] || options[:min] || options[:sec]) ? 0 : usec)
+ options[:usec] || ((options[:hour] || options[:min] || options[:sec]) ? 0 : Rational(nsec, 1000))
)
end
diff --git a/activesupport/test/core_ext/time_ext_test.rb b/activesupport/test/core_ext/time_ext_test.rb
index 6cc63851e9..1c22a79d75 100644
--- a/activesupport/test/core_ext/time_ext_test.rb
+++ b/activesupport/test/core_ext/time_ext_test.rb
@@ -491,6 +491,11 @@ class TimeExtCalculationsTest < ActiveSupport::TestCase
assert_equal Time.utc(2013,10,17,20,22,19), Time.utc(2005,2,28,15,15,10).advance(:years => 7, :months => 19, :weeks => 2, :days => 5, :hours => 5, :minutes => 7, :seconds => 9)
end
+ def test_advance_with_nsec
+ t = Time.at(0, Rational(108635108, 1000))
+ assert_equal t, t.advance(:months => 0)
+ end
+
def test_prev_week
with_env_tz 'US/Eastern' do
assert_equal Time.local(2005,2,21), Time.local(2005,3,1,15,15,10).prev_week