Files
kimai2/src/Timesheet/Rounding/FloorRounding.php
Kevin Papst 3ff46e06c0 code improvements (#1423)
* removed unused mapping information
* added support for further field types
* fixed changing date objects for begin and end
* added more project fields as invoice variables
* theme update and asset rebuild
2020-01-31 17:07:14 +01:00

88 lines
1.8 KiB
PHP

<?php
/*
* This file is part of the Kimai time-tracking app.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Timesheet\Rounding;
use App\Entity\Timesheet;
final class FloorRounding implements RoundingInterface
{
public function getId(): string
{
return 'floor';
}
/**
* @param Timesheet $record
* @param int $minutes
*/
public function roundBegin(Timesheet $record, $minutes)
{
if ($minutes <= 0) {
return;
}
$timestamp = $record->getBegin()->getTimestamp();
$seconds = $minutes * 60;
$diff = $timestamp % $seconds;
if (0 === $diff) {
return;
}
$newBegin = clone $record->getBegin();
$newBegin->setTimestamp($timestamp - $diff);
$record->setBegin($newBegin);
}
/**
* @param Timesheet $record
* @param int $minutes
*/
public function roundEnd(Timesheet $record, $minutes)
{
if ($minutes <= 0) {
return;
}
$timestamp = $record->getEnd()->getTimestamp();
$seconds = $minutes * 60;
$diff = $timestamp % $seconds;
if (0 === $diff) {
return;
}
$newEnd = clone $record->getEnd();
$newEnd->setTimestamp($timestamp - $diff);
$record->setEnd($newEnd);
}
/**
* @param Timesheet $record
* @param int $minutes
*/
public function roundDuration(Timesheet $record, $minutes)
{
if ($minutes <= 0) {
return;
}
$timestamp = $record->getDuration();
$seconds = $minutes * 60;
$diff = $timestamp % $seconds;
if (0 === $diff) {
return;
}
$record->setDuration($timestamp - $diff);
}
}