src/LocalDateTime.php
private function plusWithOverflow(int $hours, int $minutes, int $seconds, int $nanos, int $sign) : LocalDateTime
    {
        $totDays =
            \intdiv($hours, LocalTime::HOURS_PER_DAY) +
            \intdiv($minutes, LocalTime::MINUTES_PER_DAY) +
            \intdiv($seconds, LocalTime::SECONDS_PER_DAY);
        $totDays *= $sign;

        $totSeconds =
            ($seconds % LocalTime::SECONDS_PER_DAY) +
            ($minutes % LocalTime::MINUTES_PER_DAY) * LocalTime::SECONDS_PER_MINUTE +
            ($hours % LocalTime::HOURS_PER_DAY) * LocalTime::SECONDS_PER_HOUR;

        $curSoD = $this->time->toSecondOfDay();
        $totSeconds = $totSeconds * $sign + $curSoD;

        $totNanos = $nanos * $sign + $this->time->getNano();
        $totSeconds += Math::floorDiv($totNanos, LocalTime::NANOS_PER_SECOND);
        $newNano = Math::floorMod($totNanos, LocalTime::NANOS_PER_SECOND);

        $totDays += Math::floorDiv($totSeconds, LocalTime::SECONDS_PER_DAY);
        $newSoD = Math::floorMod($totSeconds, LocalTime::SECONDS_PER_DAY);

        $newDate = $this->date->plusDays($totDays);
        $newTime = ($newSoD === $curSoD ? $this->time : LocalTime::ofSecondOfDay($newSoD, $newNano));

        return new LocalDateTime($newDate, $newTime);
    }
private function plusWithOverflow(int $hours, int $minutes, int $seconds, int $nanos, int $sign) : LocalDateTime
    {
        $totDays =
            \intdiv($hours, LocalTime::HOURS_PER_DAY) +
            \intdiv($minutes, LocalTime::MINUTES_PER_DAY) +
            \intdiv($seconds, LocalTime::SECONDS_PER_DAY);
        $totDays *= $sign;

        $totSeconds =
            ($seconds % LocalTime::SECONDS_PER_DAY) +
            ($minutes % LocalTime::MINUTES_PER_DAY) * LocalTime::SECONDS_PER_MINUTE +
            ($hours % LocalTime::HOURS_PER_DAY) * LocalTime::SECONDS_PER_HOUR;

        $curSoD = $this->time->toSecondOfDay();
        $totSeconds = $totSeconds * $sign + $curSoD;

        $totNanos = $nanos * $sign + $this->time->getNano();
        $totSeconds += Math::floorDiv($totNanos, LocalTime::NANOS_PER_SECOND);
        $newNano = Math::floorMod($totNanos, LocalTime::NANOS_PER_SECOND);

        $totDays += Math::floorDiv($totSeconds, LocalTime::SECONDS_PER_DAY);
        $newSoD = Math::floorMod($totSeconds, LocalTime::SECONDS_PER_DAY);

        $newDate = $this->date->plusDays($totDays);
        $newTime = ($newSoD === $curSoD ? $this->time : LocalTime::ofSecondOfDay($newSoD, $newNano));

        return new LocalDateTime($newDate, $newTime);
    }
private function plusWithOverflow ( int $ hours , int $ minutes , int $ seconds , int $ nanos , int $ sign ) : LocalDateTime { $ totDays = \ intdiv ( $ hours , LocalTime :: HOURS_PER_DAY ) + \ intdiv ( $ minutes , LocalTime :: MINUTES_PER_DAY ) + \ intdiv ( $ seconds , LocalTime :: SECONDS_PER_DAY ) ; $ totDays *= $ sign ; $ totSeconds = ( $ seconds % LocalTime :: SECONDS_PER_DAY ) + ( $ minutes % LocalTime :: MINUTES_PER_DAY ) * LocalTime :: SECONDS_PER_MINUTE + ( $ hours % LocalTime :: HOURS_PER_DAY ) * LocalTime :: SECONDS_PER_HOUR ; $ curSoD = $ this -> time -> toSecondOfDay ( ) ; $ totSeconds = $ totSeconds * $ sign + $ curSoD ; $ totNanos = $ nanos * $ sign + $ this -> time -> getNano ( ) ; $ totSeconds += Math :: floorDiv ( $ totNanos , LocalTime :: NANOS_PER_SECOND ) ; $ newNano = Math :: floorMod ( $ totNanos , LocalTime :: NANOS_PER_SECOND ) ; $ totDays += Math :: floorDiv ( $ totSeconds , LocalTime :: SECONDS_PER_DAY ) ; $ newSoD = Math :: floorMod ( $ totSeconds , LocalTime :: SECONDS_PER_DAY ) ; $ newDate = $ this -> date -> plusDays ( $ totDays ) ; $ newTime = ( $ newSoD === $ curSoD ? $ this -> time : LocalTime :: ofSecondOfDay ( $ newSoD , $ newNano ) ) ; return new LocalDateTime ( $ newDate , $ newTime ) ; }
Returns a copy of this `LocalDateTime` with the specified period added.

@param int $hours   The hours to add. May be negative.
@param int $minutes The minutes to add. May be negative.
@param int $seconds The seconds to add. May be negative.
@param int $nanos   The nanos to add. May be negative.
@param int $sign    The sign, validated as `1` to add or `-1` to subtract.

@return LocalDateTime The combined result.
Returns a copy of this LocalDateTime with the specified period added .