Skip to content

Commit

Permalink
Merge pull request #25 from gammadia/fix-plus-duration-in-localdatetime
Browse files Browse the repository at this point in the history
Fix method plusDuration to take into account the current time.
  • Loading branch information
BenMorel authored Jul 30, 2020
2 parents 0213d78 + 6c9c671 commit 174680c
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/LocalDateTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ public function plusDuration(Duration $duration) : LocalDateTime
return $this;
}

$days = Math::floorDiv($duration->getSeconds(), LocalTime::SECONDS_PER_DAY);
$days = Math::floorDiv($this->time->toSecondOfDay() + $duration->getSeconds(), LocalTime::SECONDS_PER_DAY);

return new LocalDateTime($this->date->plusDays($days), $this->time->plusDuration($duration));
}
Expand Down
1 change: 1 addition & 0 deletions tests/LocalDateTimeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,7 @@ public function testMinusDuration(int $ds, int $dn, int $y, int $m, int $d, int
public function providerDuration() : array
{
return [
[71692, 2000000000, 2001, 2, 4, 0, 0, 0, 123456789],
[123456, 2000000000, 2001, 2, 4, 14, 22, 44, 123456789],
[7654321, 1999999999, 2001, 5, 2, 18, 17, 9, 123456788],
[-654321, -987654321, 2001, 1, 26, 14, 19, 44, 135802468],
Expand Down

0 comments on commit 174680c

Please sign in to comment.