Skip to content

Commit

Permalink
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 4 additions & 0 deletions spec/std/time/time_spec.cr
Original file line number Diff line number Diff line change
@@ -151,6 +151,10 @@ describe Time do
t = Time.new 2014, 10, 31, 21, 18, 13
t2 = t - 1.month
t2.to_s.should eq("2014-09-30 21:18:13")

t = Time.new 2014, 10, 31, 21, 18, 13
t2 = t + 6.month
t2.to_s.should eq("2015-04-30 21:18:13")
end

it "add years" do
2 changes: 1 addition & 1 deletion src/time.cr
Original file line number Diff line number Diff line change
@@ -179,7 +179,7 @@ struct Time

private def add_months(months)
day = self.day
month = self.month + months.remainder(2)
month = self.month + months.remainder(12)
year = self.year + months.tdiv(12)

if month < 1

0 comments on commit 4b02fe5

Please sign in to comment.