diff options
Diffstat (limited to 'spec/ruby/core/time/at_spec.rb')
-rw-r--r-- | spec/ruby/core/time/at_spec.rb | 102 |
1 files changed, 57 insertions, 45 deletions
diff --git a/spec/ruby/core/time/at_spec.rb b/spec/ruby/core/time/at_spec.rb index ff43537dcc..48fb3c6f52 100644 --- a/spec/ruby/core/time/at_spec.rb +++ b/spec/ruby/core/time/at_spec.rb @@ -32,13 +32,6 @@ describe "Time.at" do t2.nsec.should == t.nsec end - describe "passed BigDecimal" do - it "doesn't round input value" do - require 'bigdecimal' - Time.at(BigDecimal('1.1')).to_f.should == 1.1 - end - end - describe "passed Rational" do it "returns Time with correct microseconds" do t = Time.at(Rational(1_486_570_508_539_759, 1_000_000)) @@ -203,7 +196,7 @@ describe "Time.at" do end it "does not try to convert format to Symbol with #to_sym" do - format = "usec" + format = +"usec" format.should_not_receive(:to_sym) -> { Time.at(0, 123456, format) }.should raise_error(ArgumentError) end @@ -218,55 +211,74 @@ describe "Time.at" do end end - ruby_version_is "2.6" do - describe ":in keyword argument" do - before do - @epoch_time = Time.now.to_i - end + describe ":in keyword argument" do + before do + @epoch_time = Time.now.to_i + end - it "could be UTC offset as a String in '+HH:MM or '-HH:MM' format" do - time = Time.at(@epoch_time, in: "+05:00") + it "could be UTC offset as a String in '+HH:MM or '-HH:MM' format" do + time = Time.at(@epoch_time, in: "+05:00") - time.utc_offset.should == 5*60*60 - time.zone.should == nil - time.to_i.should == @epoch_time + time.utc_offset.should == 5*60*60 + time.zone.should == nil + time.to_i.should == @epoch_time - time = Time.at(@epoch_time, in: "-09:00") + time = Time.at(@epoch_time, in: "-09:00") - time.utc_offset.should == -9*60*60 - time.zone.should == nil - time.to_i.should == @epoch_time - end + time.utc_offset.should == -9*60*60 + time.zone.should == nil + time.to_i.should == @epoch_time + end - it "could be UTC offset as a number of seconds" do - time = Time.at(@epoch_time, in: 5*60*60) + it "could be UTC offset as a number of seconds" do + time = Time.at(@epoch_time, in: 5*60*60) - time.utc_offset.should == 5*60*60 - time.zone.should == nil - time.to_i.should == @epoch_time + time.utc_offset.should == 5*60*60 + time.zone.should == nil + time.to_i.should == @epoch_time - time = Time.at(@epoch_time, in: -9*60*60) + time = Time.at(@epoch_time, in: -9*60*60) - time.utc_offset.should == -9*60*60 - time.zone.should == nil - time.to_i.should == @epoch_time - end + time.utc_offset.should == -9*60*60 + time.zone.should == nil + time.to_i.should == @epoch_time + end - it "could be a timezone object" do - zone = TimeSpecs::TimezoneWithName.new(name: "Asia/Colombo") - time = Time.at(@epoch_time, in: zone) + it "could be UTC offset as a 'UTC' String" do + time = Time.at(@epoch_time, in: "UTC") - time.utc_offset.should == 5*3600+30*60 - time.zone.should == zone - time.to_i.should == @epoch_time + time.utc_offset.should == 0 + time.zone.should == "UTC" + time.to_i.should == @epoch_time + end - zone = TimeSpecs::TimezoneWithName.new(name: "PST") - time = Time.at(@epoch_time, in: zone) + it "could be UTC offset as a military zone A-Z" do + time = Time.at(@epoch_time, in: "B") - time.utc_offset.should == -9*60*60 - time.zone.should == zone - time.to_i.should == @epoch_time - end + time.utc_offset.should == 3600 * 2 + time.zone.should == nil + time.to_i.should == @epoch_time + end + + it "could be a timezone object" do + zone = TimeSpecs::TimezoneWithName.new(name: "Asia/Colombo") + time = Time.at(@epoch_time, in: zone) + + time.utc_offset.should == 5*3600+30*60 + time.zone.should == zone + time.to_i.should == @epoch_time + + zone = TimeSpecs::TimezoneWithName.new(name: "PST") + time = Time.at(@epoch_time, in: zone) + + time.utc_offset.should == -9*60*60 + time.zone.should == zone + time.to_i.should == @epoch_time + end + + it "raises ArgumentError if format is invalid" do + -> { Time.at(@epoch_time, in: "+09:99") }.should raise_error(ArgumentError) + -> { Time.at(@epoch_time, in: "ABC") }.should raise_error(ArgumentError) end end end |