/** * Warning! Only activity with unlimited maximal time can get bonus by slowing down, other activities can get only malus by speeding up. * @param Time $originalActivityTime * @param int $hoursPerDay * @param bool $activityIsNotLimitedByTime = false * @return Time * @throws \DrdPlus\Tables\Measurements\Time\Exceptions\CanNotProlongActivityPerDayWithLimitedTime * @throws \DrdPlus\Tables\Measurements\Time\Exceptions\NotApplicableOnShorterThanDay * @throws \DrdPlus\Tables\Measurements\Time\Exceptions\UnexpectedHoursPerDayForTimeBonusAdjustment * @throws \DrdPlus\Tables\Partials\Exceptions\RequiredColumnNotFound * @throws \Granam\Integer\Tools\Exceptions\WrongParameterType * @throws \Granam\Integer\Tools\Exceptions\ValueLostOnCast */ public function adjustBy(Time $originalActivityTime, $hoursPerDay, $activityIsNotLimitedByTime = false) { $inDays = $originalActivityTime->findDays(); if ($inDays !== null && $inDays->getValue() < 1 || $inDays === null && $originalActivityTime->findMonths() === null && $originalActivityTime->findYears() === null) { throw new Exceptions\NotApplicableOnShorterThanDay('Only at least one day of activity can be adjusted by change of hours of such activity, got ' . $originalActivityTime->getValue() . ' ' . $originalActivityTime->getUnit() . '(s)'); } if (!$activityIsNotLimitedByTime && $hoursPerDay > Time::HOURS_PER_DAY) { throw new Exceptions\CanNotProlongActivityPerDayWithLimitedTime('Got request to prolong activity by ' . $hoursPerDay . ' hours per day with original activity time ' . $originalActivityTime->getValue() . ' ' . $originalActivityTime->getUnit() . '(s)'); } $bonusAdjustment = $this->getBonusAdjustmentForHoursPerDay($hoursPerDay); $finalBonusValue = $originalActivityTime->getBonus()->getValue() + $bonusAdjustment; $finalBonus = new TimeBonus($finalBonusValue, $this->timeTable); $finalTime = $finalBonus->findTime($originalActivityTime->getUnit()); if ($finalTime !== null) { return $finalTime; } return $finalBonus->getTime(); }