Skip to content

Commit

Permalink
PlannedJobInfo: getTimeZone()
Browse files Browse the repository at this point in the history
  • Loading branch information
mabar committed Apr 7, 2024
1 parent 5ea942a commit 63a45ad
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions src/ManagedScheduler.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ private function getBeforeRunCallback(DateTimeImmutable $runStart, array $jobSch
$jobSchedule->getExpression()->getExpression(),
$jobSchedule->getRepeatAfterSeconds(),
$jobStart,
$timezone,
);
}

Expand Down
12 changes: 11 additions & 1 deletion src/Status/PlannedJobInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Orisai\Scheduler\Status;

use DateTimeImmutable;
use DateTimeZone;
use function assert;

final class PlannedJobInfo
Expand All @@ -25,6 +26,8 @@ final class PlannedJobInfo
/** @var non-empty-list<DateTimeImmutable>|null */
private ?array $estimatedStartTimes = null;

private ?DateTimeZone $timeZone;

/**
* @param string|int $id
* @param int<0, 30> $repeatAfterSeconds
Expand All @@ -34,14 +37,16 @@ public function __construct(
string $name,
string $expression,
int $repeatAfterSeconds,
DateTimeImmutable $runStart
DateTimeImmutable $runStart,
?DateTimeZone $timeZone
)
{
$this->id = $id;
$this->name = $name;
$this->expression = $expression;
$this->repeatAfterSeconds = $repeatAfterSeconds;
$this->runStart = $runStart;
$this->timeZone = $timeZone;
}

/**
Expand Down Expand Up @@ -116,4 +121,9 @@ public function getRunsCountPerMinute(): int
return $this->runsCountPerMinute = $count;
}

public function getTimeZone(): ?DateTimeZone
{
return $this->timeZone;
}

}
11 changes: 8 additions & 3 deletions tests/Unit/Status/PlannedJobInfoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -43,6 +46,7 @@ public function provideBasic(): Generator
5,
'* * * * * / 5',
new DateTimeImmutable(),
null,
];

yield [
Expand All @@ -52,6 +56,7 @@ public function provideBasic(): Generator
10,
'1 1 1 1 1 / 10',
new DateTimeImmutable('1 month ago'),
new DateTimeZone('Europe/Prague'),
];
}

Expand All @@ -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());
Expand Down
6 changes: 3 additions & 3 deletions tests/Unit/Status/RunInfoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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),
],
];
}
Expand Down

0 comments on commit 63a45ad

Please sign in to comment.