diff --git a/spec/std/time/time_spec.cr b/spec/std/time/time_spec.cr index ee95e03edd06..ac1cc85d7cd1 100644 --- a/spec/std/time/time_spec.cr +++ b/spec/std/time/time_spec.cr @@ -429,6 +429,12 @@ describe Time do time = Time.local(location) (time + 5.minutes).location.should eq location end + + it "covers date boundaries with zone offset (#8741)" do + zone = Time::Location.fixed(7 * 3600) + + Time.local(2020, 2, 5, 0, 13, location: zone).shift(months: 3).should eq Time.local(2020, 5, 5, 0, 13, location: zone) + end end it "#time_of_day" do diff --git a/src/time.cr b/src/time.cr index 0f955381f659..89906f395bd5 100644 --- a/src/time.cr +++ b/src/time.cr @@ -719,7 +719,8 @@ struct Time end seconds += Time.absolute_days(year, month, day).to_i64 * SECONDS_PER_DAY - seconds += offset_seconds % SECONDS_PER_DAY + seconds += @seconds % SECONDS_PER_DAY + seconds += offset end # FIXME: These operations currently don't have overflow checks applied.