Skip to content

Commit

Permalink
Fix Time#shift over date boundaries with zone offset (#8742)
Browse files Browse the repository at this point in the history
  • Loading branch information
straight-shoota authored Feb 6, 2020
1 parent 37d6047 commit 5905aa5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
6 changes: 6 additions & 0 deletions spec/std/time/time_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/time.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 5905aa5

Please sign in to comment.