aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/core_ext
diff options
context:
space:
mode:
authorShay Davidson <shay.h.davidson@gmail.com>2013-08-30 12:05:25 +0300
committerShay Davidson <shay.h.davidson@gmail.com>2013-08-30 12:21:34 +0300
commitb2ae07f0b218b7e92be1e8d7c23f9f9fb7aae56e (patch)
treec785f3f381c0e9645b80847d836abb0fe67ee00b /activesupport/test/core_ext
parentf90aa722fad2b33a95c85319070891d1eab352f5 (diff)
downloadrails-b2ae07f0b218b7e92be1e8d7c23f9f9fb7aae56e.tar.gz
rails-b2ae07f0b218b7e92be1e8d7c23f9f9fb7aae56e.tar.bz2
rails-b2ae07f0b218b7e92be1e8d7c23f9f9fb7aae56e.zip
Added partial days support to `DateTime`'s `advance` method.
You can now add partial days (e.g. 2.5.days) to `DateTime` with the advance method. This was acheived by mimicing the `advance` implementation in `Time`.
Diffstat (limited to 'activesupport/test/core_ext')
-rw-r--r--activesupport/test/core_ext/date_time_ext_test.rb6
1 files changed, 6 insertions, 0 deletions
diff --git a/activesupport/test/core_ext/date_time_ext_test.rb b/activesupport/test/core_ext/date_time_ext_test.rb
index 0a40aeb96c..224172e39f 100644
--- a/activesupport/test/core_ext/date_time_ext_test.rb
+++ b/activesupport/test/core_ext/date_time_ext_test.rb
@@ -162,6 +162,12 @@ class DateTimeExtCalculationsTest < ActiveSupport::TestCase
assert_equal DateTime.civil(2013,10,17,20,22,19), DateTime.civil(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_partial_days
+ assert_equal DateTime.civil(2012,9,29,13,15,10), DateTime.civil(2012,9,28,1,15,10).advance(:days => 1.5)
+ assert_equal DateTime.civil(2012,9,28,13,15,10), DateTime.civil(2012,9,28,1,15,10).advance(:days => 0.5)
+ assert_equal DateTime.civil(2012,10,29,13,15,10), DateTime.civil(2012,9,28,1,15,10).advance(:days => 1.5, :months => 1)
+ end
+
def test_advanced_processes_first_the_date_deltas_and_then_the_time_deltas
# If the time deltas were processed first, the following datetimes would be advanced to 2010/04/01 instead.
assert_equal DateTime.civil(2010, 3, 29), DateTime.civil(2010, 2, 28, 23, 59, 59).advance(:months => 1, :seconds => 1)