Release 2.31 (#5372)
* simplify translation * bump version * deprecate translations * pass date-range as argument to export and timesheet filter URL from monthly overview report * added class for use in responsive screens * show technical role name * simplify multi-update title * more statistic models * bump composer packages
This commit is contained in:
54
src/Model/Statistic/DateRange.php
Normal file
54
src/Model/Statistic/DateRange.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?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\Model\Statistic;
|
||||
|
||||
final class DateRange
|
||||
{
|
||||
/**
|
||||
* @var array<string, StatisticDate>
|
||||
*/
|
||||
private array $days = [];
|
||||
|
||||
public function __construct(\DateTimeInterface $begin, \DateTimeInterface $end)
|
||||
{
|
||||
if ($end < $begin) {
|
||||
throw new \InvalidArgumentException('End must be later than begin');
|
||||
}
|
||||
|
||||
$begin = \DateTimeImmutable::createFromInterface($begin);
|
||||
$begin = $begin->setTime(0, 0, 0);
|
||||
|
||||
$end = \DateTimeImmutable::createFromInterface($end);
|
||||
$end = $end->setTime(23, 59, 59);
|
||||
|
||||
do {
|
||||
$this->days[$begin->format('Y-m-d')] = new StatisticDate($begin);
|
||||
$begin = $begin->modify('+1 day');
|
||||
} while ($begin <= $end);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<StatisticDate>
|
||||
*/
|
||||
public function getDays(): array
|
||||
{
|
||||
return array_values($this->days);
|
||||
}
|
||||
|
||||
public function setDate(StatisticDate $date): void
|
||||
{
|
||||
$key = $date->getDate()->format('Y-m-d');
|
||||
if (!\array_key_exists($key, $this->days)) {
|
||||
throw new \InvalidArgumentException('Unknown date given');
|
||||
}
|
||||
|
||||
$this->days[$key] = $date;
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,7 @@ final class StatisticDate extends Timesheet
|
||||
private \DateTimeInterface $date;
|
||||
private int $billableDuration = 0;
|
||||
private float $billableRate = 0.00;
|
||||
private int $amount = 0;
|
||||
|
||||
public function __construct(\DateTimeInterface $date)
|
||||
{
|
||||
@@ -44,4 +45,14 @@ final class StatisticDate extends Timesheet
|
||||
{
|
||||
$this->billableRate = $billableRate;
|
||||
}
|
||||
|
||||
public function getAmount(): int
|
||||
{
|
||||
return $this->amount;
|
||||
}
|
||||
|
||||
public function setAmount(int $amount): void
|
||||
{
|
||||
$this->amount = $amount;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user