diff options
author | Andrew White <andyw@pixeltrix.co.uk> | 2013-02-25 02:11:46 -0800 |
---|---|---|
committer | Andrew White <andyw@pixeltrix.co.uk> | 2013-02-25 02:11:46 -0800 |
commit | d5141f208e10378ebe3195fa7a9ff523a1296461 (patch) | |
tree | 5054663374c12305ffb1f0e46bb088596fbb39ff | |
parent | f80a6a5a39e2ec135bc0ddbdaec23979b84ef22d (diff) | |
parent | fa891a2b9dd5548d17ce3609d64142b6e31d2410 (diff) | |
download | rails-d5141f208e10378ebe3195fa7a9ff523a1296461.tar.gz rails-d5141f208e10378ebe3195fa7a9ff523a1296461.tar.bz2 rails-d5141f208e10378ebe3195fa7a9ff523a1296461.zip |
Merge pull request #9390 from chris-baynes/datetime_sec_fraction
Keep second fraction when DateTime#change is called.
-rw-r--r-- | activesupport/CHANGELOG.md | 5 | ||||
-rw-r--r-- | activesupport/lib/active_support/core_ext/date_time/calculations.rb | 2 | ||||
-rw-r--r-- | activesupport/test/core_ext/date_time_ext_test.rb | 3 |
3 files changed, 9 insertions, 1 deletions
diff --git a/activesupport/CHANGELOG.md b/activesupport/CHANGELOG.md index 2515d378fd..b07ab749a3 100644 --- a/activesupport/CHANGELOG.md +++ b/activesupport/CHANGELOG.md @@ -1,5 +1,10 @@ ## Rails 4.0.0 (unreleased) ## +* Prevent `DateTime#change` from truncating the second fraction, when seconds + do not need to be changed. + + *Chris Baynes* + * Added `ActiveSupport::TimeWithZone#to_r` for `Time#at` compatibility. Before this change: diff --git a/activesupport/lib/active_support/core_ext/date_time/calculations.rb b/activesupport/lib/active_support/core_ext/date_time/calculations.rb index 97aad008f5..9f0864d9bb 100644 --- a/activesupport/lib/active_support/core_ext/date_time/calculations.rb +++ b/activesupport/lib/active_support/core_ext/date_time/calculations.rb @@ -59,7 +59,7 @@ class DateTime options.fetch(:day, day), options.fetch(:hour, hour), options.fetch(:min, options[:hour] ? 0 : min), - options.fetch(:sec, (options[:hour] || options[:min]) ? 0 : sec), + options.fetch(:sec, (options[:hour] || options[:min]) ? 0 : sec + sec_fraction), options.fetch(:offset, offset), options.fetch(:start, start) ) diff --git a/activesupport/test/core_ext/date_time_ext_test.rb b/activesupport/test/core_ext/date_time_ext_test.rb index 59ca2a4059..7be578599b 100644 --- a/activesupport/test/core_ext/date_time_ext_test.rb +++ b/activesupport/test/core_ext/date_time_ext_test.rb @@ -129,6 +129,9 @@ class DateTimeExtCalculationsTest < ActiveSupport::TestCase assert_equal DateTime.civil(2005,2,22,16), DateTime.civil(2005,2,22,15,15,10).change(:hour => 16) assert_equal DateTime.civil(2005,2,22,16,45), DateTime.civil(2005,2,22,15,15,10).change(:hour => 16, :min => 45) assert_equal DateTime.civil(2005,2,22,15,45), DateTime.civil(2005,2,22,15,15,10).change(:min => 45) + + # datetime with fractions of a second + assert_equal DateTime.civil(2005,2,1,15,15,10.7), DateTime.civil(2005,2,22,15,15,10.7).change(:day => 1) end def test_advance |