From 09fa947e8319a821738ccd0b987a020b393d40af Mon Sep 17 00:00:00 2001 From: Andrew Konchin Date: Wed, 26 Feb 2025 13:41:15 +0200 Subject: [PATCH] Update Time-related specs to not overflow hours and days --- spec/ruby/core/time/new_spec.rb | 7 +++++-- spec/ruby/core/time/now_spec.rb | 4 +++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/spec/ruby/core/time/new_spec.rb b/spec/ruby/core/time/new_spec.rb index 59b13216ad9..47c8dd2444a 100644 --- a/spec/ruby/core/time/new_spec.rb +++ b/spec/ruby/core/time/new_spec.rb @@ -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) @@ -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) diff --git a/spec/ruby/core/time/now_spec.rb b/spec/ruby/core/time/now_spec.rb index 3db5bf46a68..fd0f60b5ccc 100644 --- a/spec/ruby/core/time/now_spec.rb +++ b/spec/ruby/core/time/now_spec.rb @@ -170,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 -> {