mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Keep second fraction when DateTime#change is called.
This commit is contained in:
parent
f80a6a5a39
commit
fa891a2b9d
3 changed files with 9 additions and 1 deletions
|
@ -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:
|
||||
|
|
|
@ -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)
|
||||
)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue