From 63a45ad4a3f4c6bb1dc6c6ff36f52f9c5551395e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Barto=C5=A1?= Date: Sun, 7 Apr 2024 22:49:34 +0200 Subject: [PATCH] PlannedJobInfo: getTimeZone() --- CHANGELOG.md | 2 ++ src/ManagedScheduler.php | 1 + src/Status/PlannedJobInfo.php | 12 +++++++++++- tests/Unit/Status/PlannedJobInfoTest.php | 11 ++++++++--- tests/Unit/Status/RunInfoTest.php | 6 +++--- 5 files changed, 25 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1285b4f..1959aca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - `JobInfo` - `getTimeZone()` returns timezone job should run in - `isForcedRun()`returns whether job was run via $scheduler->runJob() or scheduler:run-job command, ignoring the cron expression +- `PlannedJobInfo` + - `getTimeZone()` ### Changed diff --git a/src/ManagedScheduler.php b/src/ManagedScheduler.php index 5e5d87c..b1bb141 100644 --- a/src/ManagedScheduler.php +++ b/src/ManagedScheduler.php @@ -204,6 +204,7 @@ private function getBeforeRunCallback(DateTimeImmutable $runStart, array $jobSch $jobSchedule->getExpression()->getExpression(), $jobSchedule->getRepeatAfterSeconds(), $jobStart, + $timezone, ); } diff --git a/src/Status/PlannedJobInfo.php b/src/Status/PlannedJobInfo.php index d7fee76..a5fdc2b 100644 --- a/src/Status/PlannedJobInfo.php +++ b/src/Status/PlannedJobInfo.php @@ -3,6 +3,7 @@ namespace Orisai\Scheduler\Status; use DateTimeImmutable; +use DateTimeZone; use function assert; final class PlannedJobInfo @@ -25,6 +26,8 @@ final class PlannedJobInfo /** @var non-empty-list|null */ private ?array $estimatedStartTimes = null; + private ?DateTimeZone $timeZone; + /** * @param string|int $id * @param int<0, 30> $repeatAfterSeconds @@ -34,7 +37,8 @@ public function __construct( string $name, string $expression, int $repeatAfterSeconds, - DateTimeImmutable $runStart + DateTimeImmutable $runStart, + ?DateTimeZone $timeZone ) { $this->id = $id; @@ -42,6 +46,7 @@ public function __construct( $this->expression = $expression; $this->repeatAfterSeconds = $repeatAfterSeconds; $this->runStart = $runStart; + $this->timeZone = $timeZone; } /** @@ -116,4 +121,9 @@ public function getRunsCountPerMinute(): int return $this->runsCountPerMinute = $count; } + public function getTimeZone(): ?DateTimeZone + { + return $this->timeZone; + } + } diff --git a/tests/Unit/Status/PlannedJobInfoTest.php b/tests/Unit/Status/PlannedJobInfoTest.php index 68f3a29..14498df 100644 --- a/tests/Unit/Status/PlannedJobInfoTest.php +++ b/tests/Unit/Status/PlannedJobInfoTest.php @@ -3,6 +3,7 @@ namespace Tests\Orisai\Scheduler\Unit\Status; use DateTimeImmutable; +use DateTimeZone; use Generator; use Orisai\Scheduler\Status\PlannedJobInfo; use PHPUnit\Framework\TestCase; @@ -22,16 +23,18 @@ public function testBasic( string $expression, int $seconds, string $extendedExpression, - DateTimeImmutable $start + DateTimeImmutable $start, + ?DateTimeZone $timeZone ): void { - $info = new PlannedJobInfo($id, $name, $expression, $seconds, $start); + $info = new PlannedJobInfo($id, $name, $expression, $seconds, $start, $timeZone); self::assertSame($id, $info->getId()); self::assertSame($name, $info->getName()); self::assertSame($expression, $info->getExpression()); self::assertSame($seconds, $info->getRepeatAfterSeconds()); self::assertSame($extendedExpression, $info->getExtendedExpression()); + self::assertSame($timeZone, $info->getTimeZone()); } public function provideBasic(): Generator @@ -43,6 +46,7 @@ public function provideBasic(): Generator 5, '* * * * * / 5', new DateTimeImmutable(), + null, ]; yield [ @@ -52,6 +56,7 @@ public function provideBasic(): Generator 10, '1 1 1 1 1 / 10', new DateTimeImmutable('1 month ago'), + new DateTimeZone('Europe/Prague'), ]; } @@ -68,7 +73,7 @@ public function testEstimatedStartTimes( array $estimatedTimes ): void { - $info = new PlannedJobInfo('id', 'name', '* * * * *', $seconds, $start); + $info = new PlannedJobInfo('id', 'name', '* * * * *', $seconds, $start, null); self::assertSame($runsCount, $info->getRunsCountPerMinute()); self::assertEquals($estimatedTimes, $info->getEstimatedStartTimes()); diff --git a/tests/Unit/Status/RunInfoTest.php b/tests/Unit/Status/RunInfoTest.php index 2060fdb..65c6662 100644 --- a/tests/Unit/Status/RunInfoTest.php +++ b/tests/Unit/Status/RunInfoTest.php @@ -29,15 +29,15 @@ public function provide(): Generator yield [ new DateTimeImmutable(), [ - new PlannedJobInfo('id', 'name', '* * * * *', 0, new DateTimeImmutable()), + new PlannedJobInfo('id', 'name', '* * * * *', 0, new DateTimeImmutable(), null), ], ]; yield [ new DateTimeImmutable('1 month ago'), [ - new PlannedJobInfo('id', 'name', '* * * * *', 0, new DateTimeImmutable()), - new PlannedJobInfo('id', 'name', '* * * * *', 0, new DateTimeImmutable()), + new PlannedJobInfo('id', 'name', '* * * * *', 0, new DateTimeImmutable(), null), + new PlannedJobInfo('id', 'name', '* * * * *', 0, new DateTimeImmutable(), null), ], ]; }