summaryrefslogtreecommitdiff
path: root/spec/ruby/library/datetime
diff options
context:
space:
mode:
authoreregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-12-29 00:22:52 +0000
committereregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-12-29 00:22:52 +0000
commit2076c2c3c401d9ab9324468818bbc46d4e4b870a (patch)
tree1697bf7d3f434e49cafd8a8c1579f2d065a7de56 /spec/ruby/library/datetime
parent548defb608847973e78462a38c8418f90dce9911 (diff)
Update to ruby/spec@944ea57
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66622 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'spec/ruby/library/datetime')
-rw-r--r--spec/ruby/library/datetime/add_spec.rb2
-rw-r--r--spec/ruby/library/datetime/subtract_spec.rb12
2 files changed, 12 insertions, 2 deletions
diff --git a/spec/ruby/library/datetime/add_spec.rb b/spec/ruby/library/datetime/add_spec.rb
index a6d9891..20288e2 100644
--- a/spec/ruby/library/datetime/add_spec.rb
+++ b/spec/ruby/library/datetime/add_spec.rb
@@ -4,6 +4,6 @@ require 'date'
describe "DateTime#+" do
it "is able to add sub-millisecond precision values" do
datetime = DateTime.new(2017)
- (datetime + 0.00001).to_time.usec.should == 864000
+ (datetime + 0.00001001).to_time.usec.should == 864864
end
end
diff --git a/spec/ruby/library/datetime/subtract_spec.rb b/spec/ruby/library/datetime/subtract_spec.rb
index ed88533..ba01f4e 100644
--- a/spec/ruby/library/datetime/subtract_spec.rb
+++ b/spec/ruby/library/datetime/subtract_spec.rb
@@ -4,6 +4,16 @@ require 'date'
describe "DateTime#-" do
it "is able to subtract sub-millisecond precision values" do
date = DateTime.new(2017)
- ((date + 0.00001) - date).should == Rational(1, 100000)
+ diff = Rational(123456789, 24*60*60*1000*1000)
+ ((date + diff) - date).should == diff
+ (date - (date + diff)).should == -diff
+ (date - (date - diff)).should == diff
+ ((date - diff) - date).should == -diff
+ end
+
+ it "correctly calculates sub-millisecond time differences" do #5493
+ dt1 = DateTime.new(2018, 1, 1, 0, 0, 30)
+ dt2 = DateTime.new(2018, 1, 1, 0, 1, 29.000001)
+ ((dt2 - dt1) * 24 * 60 * 60).should == 59.000001
end
end