diff --git a/src/LocalDateTime.php b/src/LocalDateTime.php index a9ad6b99..927910b1 100644 --- a/src/LocalDateTime.php +++ b/src/LocalDateTime.php @@ -426,7 +426,10 @@ public function plusDuration(Duration $duration): LocalDateTime return $this; } - $days = Math::floorDiv($this->time->toSecondOfDay() + $duration->getSeconds(), LocalTime::SECONDS_PER_DAY); + $seconds = $this->time->toSecondOfDay() + $duration->getSeconds() + + intdiv($this->time->getNano() + $duration->getNanos(), LocalTime::NANOS_PER_SECOND); + + $days = Math::floorDiv($seconds, LocalTime::SECONDS_PER_DAY); return new LocalDateTime($this->date->plusDays($days), $this->time->plusDuration($duration)); } diff --git a/tests/LocalDateTimeTest.php b/tests/LocalDateTimeTest.php index 8eedf007..4c1c4716 100644 --- a/tests/LocalDateTimeTest.php +++ b/tests/LocalDateTimeTest.php @@ -701,6 +701,8 @@ public static function providerDuration(): array [7654321, 1999999999, 2001, 5, 2, 18, 17, 9, 123456788], [-654321, -987654321, 2001, 1, 26, 14, 19, 44, 135802468], [-7654321, 2013456789, 2000, 11, 6, 13, 53, 7, 136913578], + [71693, 900000000, 2001, 2, 4, 0, 0, 0, 23456789], + [-14707, 900000000, 2001, 2, 3, 0, 0, 0, 23456789], ]; }