mirror of
https://github.com/shlinkio/shlink.git
synced 2026-03-07 15:53:13 +08:00
34 lines
919 B
PHP
34 lines
919 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Shlinkio\Shlink\Core\Spec;
|
|
|
|
use Happyr\DoctrineSpecification\Spec;
|
|
use Happyr\DoctrineSpecification\Specification\BaseSpecification;
|
|
use Happyr\DoctrineSpecification\Specification\Specification;
|
|
use Shlinkio\Shlink\Common\Util\DateRange;
|
|
|
|
class InDateRange extends BaseSpecification
|
|
{
|
|
public function __construct(private ?DateRange $dateRange, private string $field = 'date')
|
|
{
|
|
parent::__construct();
|
|
}
|
|
|
|
protected function getSpec(): Specification
|
|
{
|
|
$criteria = [];
|
|
|
|
if ($this->dateRange?->startDate !== null) {
|
|
$criteria[] = Spec::gte($this->field, $this->dateRange->startDate->toDateTimeString());
|
|
}
|
|
|
|
if ($this->dateRange?->endDate !== null) {
|
|
$criteria[] = Spec::lte($this->field, $this->dateRange->endDate->toDateTimeString());
|
|
}
|
|
|
|
return Spec::andX(...$criteria);
|
|
}
|
|
}
|