mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-29 05:26:13 +00:00
Convert Rolling date using the clock instead of the built-in pivot date
This commit is contained in:
parent
10f66afdcd
commit
128d365a72
@ -15,11 +15,7 @@ use Symfony\Component\Clock\ClockInterface;
|
|||||||
|
|
||||||
final readonly class RollingDateConverter implements RollingDateConverterInterface
|
final readonly class RollingDateConverter implements RollingDateConverterInterface
|
||||||
{
|
{
|
||||||
|
public function __construct(private readonly ClockInterface $clock) {}
|
||||||
function __construct(private readonly ClockInterface $clock)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public function convert(?RollingDate $rollingDate): ?\DateTimeImmutable
|
public function convert(?RollingDate $rollingDate): ?\DateTimeImmutable
|
||||||
{
|
{
|
||||||
@ -38,7 +34,7 @@ final readonly class RollingDateConverter implements RollingDateConverterInterfa
|
|||||||
return $this->toBeginOfMonth(($rollingDate->getPivotDate() ?? $this->clock->now())->sub(new \DateInterval('P1M')));
|
return $this->toBeginOfMonth(($rollingDate->getPivotDate() ?? $this->clock->now())->sub(new \DateInterval('P1M')));
|
||||||
|
|
||||||
case RollingDate::T_QUARTER_CURRENT_START:
|
case RollingDate::T_QUARTER_CURRENT_START:
|
||||||
return $this->toBeginOfQuarter($rollingDate->getPivotDate()?? $this->clock->now());
|
return $this->toBeginOfQuarter($rollingDate->getPivotDate() ?? $this->clock->now());
|
||||||
|
|
||||||
case RollingDate::T_QUARTER_NEXT_START:
|
case RollingDate::T_QUARTER_NEXT_START:
|
||||||
return $this->toBeginOfQuarter(($rollingDate->getPivotDate() ?? $this->clock->now())->add(new \DateInterval('P3M')));
|
return $this->toBeginOfQuarter(($rollingDate->getPivotDate() ?? $this->clock->now())->add(new \DateInterval('P3M')));
|
||||||
|
@ -42,5 +42,4 @@ class RollingDateTest extends TestCase
|
|||||||
self::assertEquals($fixed, $actual->getFixedDate());
|
self::assertEquals($fixed, $actual->getFixedDate());
|
||||||
self::assertEquals($date->getPivotDate()?->getTimestamp(), $actual->getPivotDate()?->getTimestamp());
|
self::assertEquals($date->getPivotDate()?->getTimestamp(), $actual->getPivotDate()?->getTimestamp());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user