/** * @test */ public function I_can_convert_bonus_to_value() { $timeTable = new TimeTable(); self::assertSame(1, $timeTable->toTime(new TimeBonus(0, $timeTable))->getRounds()->getValue()); self::assertSame(1, $timeTable->toTime(new TimeBonus(3, $timeTable))->getRounds()->getValue()); self::assertSame(number_format(1.1, 5), number_format($timeTable->toTime(new TimeBonus(17, $timeTable))->getMinutes()->getValue(), 5)); self::assertSame(28.0, $timeTable->toTime(new TimeBonus(45, $timeTable))->getMinutes()->getValue()); self::assertSame(0.5, $timeTable->toTime(new TimeBonus(45, $timeTable))->getHours()->getValue()); self::assertSame(2.5, $timeTable->toTime(new TimeBonus(59, $timeTable))->getHours()->getValue()); self::assertSame(1.0, $timeTable->toTime(new TimeBonus(73, $timeTable))->getDays()->getValue()); self::assertSame(1.0, $timeTable->toTime(new TimeBonus(102, $timeTable))->getMonths()->getValue()); self::assertSame(1.0, $timeTable->toTime(new TimeBonus(124, $timeTable))->getYears()->getValue()); }
/** * @param string $unit * @return Time|null */ public function findIn($unit) { if ($unit === $this->getUnit()) { return clone $this; } $bonus = $this->timeTable->toBonus($this); return $this->timeTable->hasTimeFor($bonus, $unit) ? $this->timeTable->toTime($bonus, $unit) : null; }
/** * @param string|null $wantedUnit * @return Time|null */ public function findTime($wantedUnit = null) { /** @noinspection ExceptionsAnnotatingAndHandlingInspection */ return $this->timeTable->hasTimeFor($this, $wantedUnit) ? $this->timeTable->toTime($this, $wantedUnit) : null; }