Skip to content

Commit 09fa947

Browse files
committed
Update Time-related specs to not overflow hours and days
1 parent 8950315 commit 09fa947

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
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: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,9 @@ def zone.utc_to_local(t)
170170
it "raises ArgumentError if difference between argument and result is too large" do
171171
zone = Object.new
172172
def zone.utc_to_local(t)
173-
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)
174176
end
175177

176178
-> {

0 commit comments

Comments
 (0)