Permalink
Browse files

Add a few Time edge cases

  • Loading branch information...
Evan Phoenix
Evan Phoenix committed Feb 12, 2010
1 parent 4b2580a commit 9b20270d005b9bd7eef32d5f7c25ea2f44cc610e
Showing with 20 additions and 0 deletions.
  1. +6 −0 spec/ruby/core/time/minus_spec.rb
  2. +6 −0 spec/ruby/core/time/plus_spec.rb
  3. +8 −0 spec/ruby/core/time/shared/local.rb
@@ -14,6 +14,12 @@
(Time.at(1.1) - 0.2).should == Time.at(0.9)
end
it "understands negative subtractions" do
t = Time.at(100) - -1.3
t.usec.should == 300000
t.to_i.should == 101
end
it "accepts arguments that can be coerced into Float" do
(obj = mock('9.5')).should_receive(:to_f).and_return(9.5)
(Time.at(100) - obj).should == Time.at(90.5)
@@ -10,6 +10,12 @@
(Time.at(1.1) + 0.9).should == Time.at(0.9) + 1.1
end
it "understands negative additions" do
t = Time.at(100) + -1.3
t.usec.should == 700000
t.to_i.should == 98
end
it "rounds micro seconds rather than truncates" do
# The use of 8.9999999 is intentional. This is because
# Time treats the fractional part as the number of micro seconds.
@@ -13,6 +13,14 @@
time.inspect.should == "Sat Jan 01 20:15:01 -0800 2000"
end
end
it "respects rare old timezones" do
with_timezone("Europe/Amsterdam") do
time = Time.send(@method, 1910, 1, 1)
time.to_i.should == -1893457172
time.inspect.should == "Sat Jan 01 00:00:00 +0019 1910"
end
end
end
ruby_version_is "1.9" do

0 comments on commit 9b20270

Please sign in to comment.