/** * Returns a copy of this `LocalDateTime` with the specified period added. * * @param integer $hours The hours to add, validated as an integer. May be negative. * @param integer $minutes The minutes to add, validated as an integer. May be negative. * @param integer $seconds The seconds to add, validated as an integer. May be negative. * @param integer $nanos The nanos to add, validated as an integer. May be negative. * @param integer $sign The sign, validated as an integer of value `1` to add or `-1` to subtract. * * @return LocalDateTime The combined result. */ private function plusWithOverflow($hours, $minutes, $seconds, $nanos, $sign) { $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); $newTime = $newSoD === $curSoD ? $this->time : LocalTime::ofSecondOfDay($newSoD, $newNano); return $this->with($this->date->plusDays($totDays), $newTime); }
/** * @param integer $hour The expected hour. * @param integer $minute The expected minute. * @param integer $second The expected second. * @param integer $nano The expected nano-of-second. * @param LocalTime $time The local time to test. */ protected function assertLocalTimeIs($hour, $minute, $second, $nano, LocalTime $time) { $this->compare([$hour, $minute, $second, $nano], [$time->getHour(), $time->getMinute(), $time->getSecond(), $time->getNano()]); }