Skip to content

Commit

Permalink
[GR-62586] Fix transient Time.new specs
Browse files Browse the repository at this point in the history
PullRequest: truffleruby/4486
  • Loading branch information
andrykonchin authored and fniephaus committed Mar 1, 2025
2 parents 87fe4ae + 09fa947 commit b2a1986
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
7 changes: 5 additions & 2 deletions spec/ruby/core/time/new_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,8 @@ def zone.local_to_utc(time)
it "could be Time instance" do
zone = Object.new
def zone.local_to_utc(t)
Time.utc(t.year, t.mon, t.day, t.hour - 1, t.min, t.sec)
time = Time.utc(t.year, t.mon, t.day, t.hour, t.min, t.sec)
time - 60 * 60 # - 1 hour
end

Time.new(2000, 1, 1, 12, 0, 0, zone).should be_kind_of(Time)
Expand All @@ -253,7 +254,9 @@ def zone.local_to_utc(t)
it "could be Time subclass instance" do
zone = Object.new
def zone.local_to_utc(t)
Class.new(Time).utc(t.year, t.mon, t.day, t.hour - 1, t.min, t.sec)
time = Time.utc(t.year, t.mon, t.day, t.hour, t.min, t.sec)
time -= 60 * 60 # - 1 hour
Class.new(Time).utc(time.year, time.mon, time.day, time.hour, t.min, t.sec)
end

Time.new(2000, 1, 1, 12, 0, 0, zone).should be_kind_of(Time)
Expand Down
12 changes: 9 additions & 3 deletions spec/ruby/core/time/now_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ def zone.utc_to_local(time)
it "could be Time instance" do
zone = Object.new
def zone.utc_to_local(t)
Time.new(t.year, t.mon, t.day, t.hour + 1, t.min, t.sec, t.utc_offset)
time = Time.new(t.year, t.mon, t.day, t.hour, t.min, t.sec, t.utc_offset)
time + 60 * 60 # + 1 hour
end

Time.now(in: zone).should be_kind_of(Time)
Expand All @@ -124,7 +125,10 @@ def zone.utc_to_local(t)
it "could be Time subclass instance" do
zone = Object.new
def zone.utc_to_local(t)
Class.new(Time).new(t.year, t.mon, t.day, t.hour + 1, t.min, t.sec, t.utc_offset)
time = Time.new(t.year, t.mon, t.day, t.hour, t.min, t.sec, t.utc_offset)
time += 60 * 60 # + 1 hour

Class.new(Time).new(time.year, time.mon, time.day, time.hour, time.min, time.sec, time.utc_offset)
end

Time.now(in: zone).should be_kind_of(Time)
Expand Down Expand Up @@ -166,7 +170,9 @@ def zone.utc_to_local(t)
it "raises ArgumentError if difference between argument and result is too large" do
zone = Object.new
def zone.utc_to_local(t)
Time.utc(t.year, t.mon, t.day - 1, t.hour, t.min, t.sec, t.utc_offset)
time = Time.utc(t.year, t.mon, t.day, t.hour, t.min, t.sec, t.utc_offset)
time -= 24 * 60 * 60 # - 1 day
Time.utc(time.year, time.mon, time.day, time.hour, time.min, time.sec, time.utc_offset)
end

-> {
Expand Down

0 comments on commit b2a1986

Please sign in to comment.