Allow to define midnight or now for todays dates

This commit is contained in:
Daniel Siepmann 2022-05-16 13:24:39 +02:00
parent 4d79220444
commit 58d602c153
5 changed files with 65 additions and 3 deletions

View file

@ -61,6 +61,11 @@ class DateDemand
*/
protected $end = null;
/**
* @var bool
*/
protected $useMidnight = true;
/**
* @var string
*/
@ -272,6 +277,25 @@ class DateDemand
$this->end = $end;
}
public function setUseMidnight(bool $useMidnight): void
{
$this->useMidnight = $useMidnight;
}
public function shouldShowFromNow(): bool
{
return $this->getStart() === null
&& $this->getEnd() === null
&& $this->useMidnight === false;
}
public function shouldShowFromMidnight(): bool
{
return $this->getStart() === null
&& $this->getEnd() === null
&& $this->useMidnight === true;
}
public function getConsiderDate(): bool
{
return $this->considerDate;

View file

@ -73,6 +73,9 @@ class DateDemandFactory
if (!empty($settings['end'])) {
$demand->setEnd((int)$settings['end']);
}
if (isset($settings['useMidnight'])) {
$demand->setUseMidnight((bool)$settings['useMidnight']);
}
if (!empty($settings['limit'])) {
$demand->setLimit($settings['limit']);
}

View file

@ -94,7 +94,7 @@ class DateRepository extends Repository
]);
}
if ($demand->getStart() === null && $demand->getEnd() === null) {
if ($demand->shouldShowFromNow() || $demand->shouldShowFromMidnight()) {
$now = $this->context->getPropertyFromAspect(
'date',
'full',
@ -106,7 +106,13 @@ class DateRepository extends Repository
1639382648
);
}
$now = $now->modify('midnight');
$now = $now->setTimezone(new \DateTimeZone(date_default_timezone_get()));
if ($demand->shouldShowFromMidnight()) {
$now = $now->modify('midnight');
}
$constraints['nowAndFuture'] = $query->logicalOr([
$query->greaterThanOrEqual('start', $now),
$query->greaterThanOrEqual('end', $now)

View file

@ -0,0 +1,29 @@
2.3.0
=====
Breaking
--------
Nothing
Features
--------
* New Option `useMidnight = 0` is available.
This allows to explicitly show dates from now instead of midnight which is kept as
default.
Fixes
-----
Nothing
Tasks
-----
Nothing
Deprecation
-----------
Nothing

View file

@ -9,7 +9,7 @@ $EM_CONF['events'] = [
'state' => 'alpha',
'createDirs' => '',
'clearCacheOnLoad' => 0,
'version' => '2.3.3',
'version' => '2.4.0',
'constraints' => [
'depends' => [
'typo3' => '10.4.00-10.4.99',