Skip to content

Commit

Permalink
Merge pull request #84 from mreinsch/month-subtraction-fix
Browse files Browse the repository at this point in the history
fix for month subtraction
  • Loading branch information
jmettraux authored Jan 19, 2023
2 parents 9b1c6b1 + 88d0a6d commit 8072982
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/fugit/duration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ def add_to_time(t)
n, m = at[1] / 12, at[1] % 12
at[0], at[1] = at[0] + n, m
elsif at[1] < 1
n, m = -at[1] / 12, -at[1] % 12
n, m = (-at[1]) / 12 + 1, (11+at[1]) % 12 + 1
at[0], at[1] = at[0] - n, m
end

Expand Down
2 changes: 2 additions & 0 deletions spec/duration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,8 @@
[ '1Y1m17s', '2016-12-30 17:00:00', '2017-12-30 17:01:17' ],
[ '1Y1M17s', '2016-12-30 17:00:00', '2018-01-30 17:00:17' ],
[ '1M', '2016-02-02', '2016-03-02' ],
[ '-2M', '2016-02-02', '2015-12-02' ],
[ '-15M', '2016-02-02', '2014-11-02' ],
].each do |d, t, tt|

it "adding #{t.inspect} to #{d.inspect} yields #{tt.inspect}" do
Expand Down

0 comments on commit 8072982

Please sign in to comment.