Skip to content

Commit b2a1986

Browse files
andrykonchinfniephaus
authored andcommitted
[GR-62586] Fix transient Time.new specs
PullRequest: truffleruby/4486
2 parents 87fe4ae + 09fa947 commit b2a1986

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

spec/ruby/core/time/new_spec.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,8 @@ def zone.local_to_utc(time)
243243
it "could be Time instance" do
244244
zone = Object.new
245245
def zone.local_to_utc(t)
246-
Time.utc(t.year, t.mon, t.day, t.hour - 1, t.min, t.sec)
246+
time = Time.utc(t.year, t.mon, t.day, t.hour, t.min, t.sec)
247+
time - 60 * 60 # - 1 hour
247248
end
248249

249250
Time.new(2000, 1, 1, 12, 0, 0, zone).should be_kind_of(Time)
@@ -253,7 +254,9 @@ def zone.local_to_utc(t)
253254
it "could be Time subclass instance" do
254255
zone = Object.new
255256
def zone.local_to_utc(t)
256-
Class.new(Time).utc(t.year, t.mon, t.day, t.hour - 1, t.min, t.sec)
257+
time = Time.utc(t.year, t.mon, t.day, t.hour, t.min, t.sec)
258+
time -= 60 * 60 # - 1 hour
259+
Class.new(Time).utc(time.year, time.mon, time.day, time.hour, t.min, t.sec)
257260
end
258261

259262
Time.new(2000, 1, 1, 12, 0, 0, zone).should be_kind_of(Time)

spec/ruby/core/time/now_spec.rb

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ def zone.utc_to_local(time)
114114
it "could be Time instance" do
115115
zone = Object.new
116116
def zone.utc_to_local(t)
117-
Time.new(t.year, t.mon, t.day, t.hour + 1, t.min, t.sec, t.utc_offset)
117+
time = Time.new(t.year, t.mon, t.day, t.hour, t.min, t.sec, t.utc_offset)
118+
time + 60 * 60 # + 1 hour
118119
end
119120

120121
Time.now(in: zone).should be_kind_of(Time)
@@ -124,7 +125,10 @@ def zone.utc_to_local(t)
124125
it "could be Time subclass instance" do
125126
zone = Object.new
126127
def zone.utc_to_local(t)
127-
Class.new(Time).new(t.year, t.mon, t.day, t.hour + 1, t.min, t.sec, t.utc_offset)
128+
time = Time.new(t.year, t.mon, t.day, t.hour, t.min, t.sec, t.utc_offset)
129+
time += 60 * 60 # + 1 hour
130+
131+
Class.new(Time).new(time.year, time.mon, time.day, time.hour, time.min, time.sec, time.utc_offset)
128132
end
129133

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

172178
-> {

0 commit comments

Comments
 (0)